From 2e835550b70894e3e74750ff5eb4543f6127c6d1 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 24 Apr 2023 14:13:36 +0200 Subject: [PATCH] Added trexio write for nuclei --- docs/gaussian_integrals.html | 10 +- docs/particles.html | 191 ++++++++++++++++++---------------- docs/top.html | 10 +- gaussian_integrals/README.org | 2 + particles/README.org | 2 + particles/lib/dune | 3 +- particles/lib/mass.ml | 2 +- particles/lib/nuclei.ml | 37 ++++++- particles/lib/nuclei.mli | 5 +- particles/nuclei.org | 50 ++++++++- particles/test/dune | 1 + 11 files changed, 208 insertions(+), 105 deletions(-) diff --git a/docs/gaussian_integrals.html b/docs/gaussian_integrals.html index 0cd8018..d518fd2 100644 --- a/docs/gaussian_integrals.html +++ b/docs/gaussian_integrals.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Gaussian integrals @@ -250,18 +250,18 @@ org_html_manager.setup(); // activate after the parameters are set

Table of Contents

-
-

1 Summary

+
+

1 Summary

Author: Anthony Scemama

-

Created: 2021-10-19 Tue 16:20

+

Created: 2023-04-24 Mon 13:50

Validate

diff --git a/docs/particles.html b/docs/particles.html index f05cf38..f4e96e4 100644 --- a/docs/particles.html +++ b/docs/particles.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Common @@ -272,75 +272,75 @@ org_html_manager.setup(); // activate after the parameters are set

Table of Contents

-
-

1 Summary

+
+

1 Summary

-
-

2 Electrons

+
+

2 Electrons

Data structure which contains the number of α and β electrons.

-
-

2.1 Type

+
+

2.1 Type

-
type t 
+
type t 
 
-
-

2.2 Creation

+
+

2.2 Creation

open Common
@@ -372,15 +372,15 @@ Data structure which contains the number of α and β electrons.
 
 
 of_atoms
-Creates the data relative to electrons for a molecular system described by Nuclei.t for a given total charge and spin multiplicity.
+Creates the data relative to electrons for a molecular system described by Nuclei.t for a given total charge and spin multiplicity.
 
 
 
 
-
-

2.3 Access

+
+

2.3 Access

val charge       : t -> Charge.t
@@ -429,8 +429,8 @@ Data structure which contains the number of α and β electrons.
 
-
-

2.4 Printers

+
+

2.4 Printers

val pp : Format.formatter -> t -> unit
@@ -439,24 +439,24 @@ Data structure which contains the number of α and β electrons.
 
-
-

2.5 Tests

+
+

2.5 Tests

-
-

3 Element

+
+

3 Element

Chemical elements.

-
-

3.1 Type

+
+

3.1 Type

-
type t =
+
type t =
   |X
   |H                                                 |He
   |Li|Be                              |B |C |N |O |F |Ne
@@ -473,8 +473,8 @@ Chemical elements.
 
-
-

3.2 Conversion

+
+

3.2 Conversion

val of_string      : string -> t
@@ -535,7 +535,7 @@ Chemical elements.
 
 
 
-
+
 Element.of_string "Fe" ;;
 - : Element.t = Particles.Element.Fe
 
@@ -554,8 +554,8 @@ Element.(to_string Fe);;
 
-
-

3.3 Database information

+
+

3.3 Database information

val covalent_radius : t -> Non_negative_float.t
@@ -604,8 +604,8 @@ Element.(to_string Fe);;
 
-
-

3.4 Printers

+
+

3.4 Printers

val pp      : Format.formatter -> t -> unit
@@ -616,34 +616,34 @@ Element.(to_string Fe);;
 
-
-

4 Atomic mass

+
+

4 Atomic mass

Atomic mass, a non-negative float.

-
include module type of Common.Non_negative_float
+
include module type of Common.Non_negative_float
 
-
-

5 Nuclei

+
+

5 Nuclei

-
-

5.1 Type

+
+

5.1 Type

-Nuclei.t +Nuclei.t

-
open Common
+
open Common
 
 type t = (Element.t * Coordinate.t) array
 
@@ -651,12 +651,12 @@ Atomic mass, a non-negative float.
-
-

5.2 xyz file lexer/parser

+
+

5.2 xyz file lexer/parser

-
-

5.2.1 Lexer

+
+

5.2.1 Lexer

nuclei_lexer.mll contains the description of the lexemes used in @@ -709,8 +709,8 @@ rule read_all = parse

-
-

5.2.2 Parser

+
+

5.2.2 Parser

xyz_parser.mly parses nuclear coordinates in xyz format. @@ -829,8 +829,8 @@ an xyz_file data structure.

-
-

5.3 Conversion

+
+

5.3 Conversion

val of_xyz_string : string -> t
@@ -843,6 +843,9 @@ an xyz_file data structure.
 val to_string      : t -> string
 
 val of_filename : string -> t
+
+val of_trexio : Trexio.trexio_file -> t
+val to_trexio : Trexio.trexio_file -> t -> unit
 
@@ -884,13 +887,23 @@ an xyz_file data structure. of_filename Detects the type of file (xyz, z-matrix) and reads the file + + +of_trexio +Reads the geometry from a TREXIO file + + + +to_trexio +Writes the geometry in a TREXIO file +
-
-

5.4 TODO Query

+
+

5.4 Query

val formula    : t -> string
@@ -939,8 +952,8 @@ an xyz_file data structure.
 
-
-

5.5 Printers

+
+

5.5 Printers

val pp : Format.formatter -> t -> unit
@@ -949,31 +962,31 @@ an xyz_file data structure.
 
-
-

5.6 Tests

+
+

5.6 Tests

-
-

6 Z-matrix

+
+

6 Z-matrix

Z-matrix representation of nuclear coordinates.

-
-

6.1 Type

+
+

6.1 Type

-
type t 
+
type t 
 
-
-

6.2 Conversion

+
+

6.2 Conversion

val of_string      : string -> t
@@ -1008,7 +1021,7 @@ Z-matrix representation of nuclear coordinates.
 
 
 
-
+
 let zmt = Zmatrix.of_string "
  n
  n    1 nn
@@ -1053,8 +1066,8 @@ H -0.568803 -0.793910 1.726048"
 
-
-

6.3 Printers

+
+

6.3 Printers

val pp : Format.formatter -> t -> unit
@@ -1066,7 +1079,7 @@ H -0.568803 -0.793910 1.726048"
 

Author: Anthony Scemama

-

Created: 2021-10-19 Tue 16:20

+

Created: 2023-04-24 Mon 14:13

Validate

diff --git a/docs/top.html b/docs/top.html index 5bf78f4..54a8721 100644 --- a/docs/top.html +++ b/docs/top.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Top-level @@ -250,18 +250,18 @@ org_html_manager.setup(); // activate after the parameters are set

Table of Contents

-
-

1 Summary

+
+

1 Summary

Author: Anthony Scemama

-

Created: 2023-04-24 Mon 12:58

+

Created: 2023-04-24 Mon 14:13

Validate

diff --git a/gaussian_integrals/README.org b/gaussian_integrals/README.org index a124315..68f2d74 100644 --- a/gaussian_integrals/README.org +++ b/gaussian_integrals/README.org @@ -48,6 +48,8 @@ with open(dunetest,'w') as f: (synopsis "Test for {name} library") (libraries alcotest + unix + trexio qcaml.{name} ) ) diff --git a/particles/README.org b/particles/README.org index 92d27ab..15f1aa8 100644 --- a/particles/README.org +++ b/particles/README.org @@ -48,6 +48,7 @@ with open(dunetest,'w') as f: (synopsis "Test for {name} library") (libraries alcotest + trexio qcaml.{name} ) ) @@ -59,6 +60,7 @@ with open(dunetest,'w') as f: #+name: dependencies #+begin_src elisp (libraries + trexio qcaml.common ) #+end_src diff --git a/particles/lib/dune b/particles/lib/dune index 7a7c994..f1aac6c 100644 --- a/particles/lib/dune +++ b/particles/lib/dune @@ -3,9 +3,10 @@ (name particles) (public_name qcaml.particles) (synopsis -"Information relative to particles (electrons and nuclei)." +"Information relative to particles (electrons and nuclei)" ) (libraries + trexio qcaml.common ) (modules_without_implementation diff --git a/particles/lib/mass.ml b/particles/lib/mass.ml index 576640d..8c27f97 100644 --- a/particles/lib/mass.ml +++ b/particles/lib/mass.ml @@ -1,3 +1,3 @@ -(* [[file:~/QCaml/particles/mass.org::*Atomic%20mass][Atomic mass:2]] *) +(* [[file:~/QCaml/particles/mass.org::*Atomic mass][Atomic mass:2]] *) include Common.Non_negative_float (* Atomic mass:2 ends here *) diff --git a/particles/lib/nuclei.ml b/particles/lib/nuclei.ml index c40fdc0..b62f966 100644 --- a/particles/lib/nuclei.ml +++ b/particles/lib/nuclei.ml @@ -12,7 +12,9 @@ open Xyz_ast * | ~of_zmt_string~ | Create from a string, in z-matrix format | * | ~of_zmt_file~ | Create from a file, in z-matrix format | * | ~to_string~ | Transform to a string, for printing | - * | ~of_filename~ | Detects the type of file (xyz, z-matrix) and reads the file | *) + * | ~of_filename~ | Detects the type of file (xyz, z-matrix) and reads the file | + * | ~of_trexio~ | Reads the geometry from a TREXIO file | + * | ~to_trexio~ | Writes the geometry in a TREXIO file | *) (* [[file:~/QCaml/particles/nuclei.org::*Conversion][Conversion:2]] *) @@ -115,6 +117,19 @@ let to_xyz_string t = ) t |> Array.to_list ) |> String.concat "\n" + + +let of_trexio f = + let num = Trexio.read_nucleus_num f in + let charge = Trexio.read_nucleus_charge f + |> Array.map Charge.of_float in + let coord = Trexio.read_nucleus_coord f in + Array.init num (fun i -> + let coord = Coordinate.{ x = coord.(3*i) ; + y = coord.(3*i+1) ; + z = coord.(3*i+2) } in + (Element.of_charge charge.(i), Coordinate.make coord) + ) (* Conversion:2 ends here *) @@ -174,6 +189,26 @@ let small_core a = let large_core a = Array.fold_left (fun accu (e,_) -> accu + (Element.large_core e)) 0 a + +let to_trexio f t = + let num = Array.length t in + Trexio.write_nucleus_num f num; + + Array.map (fun (e, _) -> Element.to_charge e |> Charge.to_float) t + |> Trexio.write_nucleus_charge f; + + Array.map (fun (e, _) -> Element.to_string e) t + |> Trexio.write_nucleus_label f; + + let coord = Array.init (num*3) (fun _ -> 0.) in + Array.iteri (fun i (_, xyz) -> + coord.(3*i) <- Coordinate.(get X xyz) ; + coord.(3*i+1) <- Coordinate.(get Y xyz) ; + coord.(3*i+2) <- Coordinate.(get Z xyz) ) t; + Trexio.write_nucleus_coord f coord; + + repulsion t + |> Trexio.write_nucleus_repulsion f (* Query:2 ends here *) (* [[file:~/QCaml/particles/nuclei.org::*Printers][Printers:2]] *) diff --git a/particles/lib/nuclei.mli b/particles/lib/nuclei.mli index 24ab6be..3c2e9a0 100644 --- a/particles/lib/nuclei.mli +++ b/particles/lib/nuclei.mli @@ -23,9 +23,12 @@ val of_zmt_file : string -> t val to_string : t -> string val of_filename : string -> t + +val of_trexio : Trexio.trexio_file -> t +val to_trexio : Trexio.trexio_file -> t -> unit (* Conversion:1 ends here *) -(* TODO Query *) +(* Query *) (* [[file:~/QCaml/particles/nuclei.org::*Query][Query:1]] *) diff --git a/particles/nuclei.org b/particles/nuclei.org index c4d7109..6aaa19c 100644 --- a/particles/nuclei.org +++ b/particles/nuclei.org @@ -204,6 +204,9 @@ val of_zmt_file : string -> t val to_string : t -> string val of_filename : string -> t + +val of_trexio : Trexio.trexio_file -> t +val to_trexio : Trexio.trexio_file -> t -> unit #+end_src | ~of_xyz_string~ | Create from a string, in xyz format | @@ -212,6 +215,8 @@ val of_filename : string -> t | ~of_zmt_file~ | Create from a file, in z-matrix format | | ~to_string~ | Transform to a string, for printing | | ~of_filename~ | Detects the type of file (xyz, z-matrix) and reads the file | + | ~of_trexio~ | Reads the geometry from a TREXIO file | + | ~to_trexio~ | Writes the geometry in a TREXIO file | #+begin_src ocaml :tangle (eval ml) :exports none let of_xyz_lexbuf lexbuf = @@ -313,9 +318,48 @@ let to_xyz_string t = ) t |> Array.to_list ) |> String.concat "\n" + + +let of_trexio f = + let num = Trexio.read_nucleus_num f in + let charge = Trexio.read_nucleus_charge f + |> Array.map Charge.of_float in + let coord = Trexio.read_nucleus_coord f in + Array.init num (fun i -> + let coord = Coordinate.{ x = coord.(3*i) ; + y = coord.(3*i+1) ; + z = coord.(3*i+2) } in + (Element.of_charge charge.(i), Coordinate.make coord) + ) + + #+end_src -** TODO Query + #+NAME: trexio_export + #+begin_src ocaml :tangle no :exports none +let to_trexio f t = + let num = Array.length t in + Trexio.write_nucleus_num f num; + + Array.map (fun (e, _) -> Element.to_charge e |> Charge.to_float) t + |> Trexio.write_nucleus_charge f; + + Array.map (fun (e, _) -> Element.to_string e) t + |> Trexio.write_nucleus_label f; + + let coord = Array.init (num*3) (fun _ -> 0.) in + Array.iteri (fun i (_, xyz) -> + coord.(3*i) <- Coordinate.(get X xyz) ; + coord.(3*i+1) <- Coordinate.(get Y xyz) ; + coord.(3*i+2) <- Coordinate.(get Z xyz) ) t; + Trexio.write_nucleus_coord f coord; + + repulsion t + |> Trexio.write_nucleus_repulsion f + + #+end_src + +** Query #+begin_src ocaml :tangle (eval mli) val formula : t -> string @@ -331,7 +375,7 @@ val large_core : t -> int | ~small_core~ | Number of core electrons in the small core model | | ~large_core~ | Number of core electrons in the large core model | - #+begin_src ocaml :tangle (eval ml) :exports none + #+begin_src ocaml :tangle (eval ml) :exports none :noweb yes let formula t = let dict = Hashtbl.create 67 in Array.iter (fun (e,_) -> @@ -379,6 +423,8 @@ let small_core a = let large_core a = Array.fold_left (fun accu (e,_) -> accu + (Element.large_core e)) 0 a + +<> #+end_src ** Printers diff --git a/particles/test/dune b/particles/test/dune index d74d00d..75f03bc 100644 --- a/particles/test/dune +++ b/particles/test/dune @@ -4,6 +4,7 @@ (synopsis "Test for particles library") (libraries alcotest + trexio qcaml.particles ) )