mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-13 17:43:41 +01:00
Zmatrix example
This commit is contained in:
parent
81fdc05a5c
commit
a4582ffb67
@ -1,3 +1,3 @@
|
||||
(* [[file:../mass.org::*Atomic mass][Atomic mass:2]] *)
|
||||
(* [[file:~/QCaml/particles/mass.org::*Atomic%20mass][Atomic mass:2]] *)
|
||||
include Common.Non_negative_float
|
||||
(* Atomic mass:2 ends here *)
|
||||
|
@ -7,6 +7,6 @@
|
||||
*
|
||||
* #+NAME: types *)
|
||||
|
||||
(* [[file:../mass.org::types][types]] *)
|
||||
(* [[file:~/QCaml/particles/mass.org::types][types]] *)
|
||||
include module type of Common.Non_negative_float
|
||||
(* types ends here *)
|
||||
|
@ -1,4 +1,4 @@
|
||||
(* [[file:../zmatrix.org::*Type][Type:2]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::*Type][Type:2]] *)
|
||||
module StringMap = Map.Make(String)
|
||||
|
||||
type atom_id = int
|
||||
@ -18,12 +18,55 @@ type t = (line array * float StringMap.t)
|
||||
|
||||
|
||||
|
||||
(* | ~of_string~ | Reads a z-matrix from a string |
|
||||
* | ~to_xyz~ | Converts to xyz format, as in the ~Nuclei~ module |
|
||||
* | ~to_xyz_string~ | Converts to xyz format, as a string | *)
|
||||
(* | ~of_string~ | Reads a z-matrix from a string |
|
||||
* | ~to_xyz~ | Converts to xyz format, as in the ~Nuclei~ module |
|
||||
* | ~to_xyz_string~ | Converts to xyz format, as a string |
|
||||
*
|
||||
* #+begin_example
|
||||
* let zmt = Zmatrix.of_string "
|
||||
* n
|
||||
* n 1 nn
|
||||
* h 1 hn 2 hnn
|
||||
* h 2 hn 1 hnn 3 dih4
|
||||
* h 1 hn 2 hnn 4 dih5
|
||||
* h 2 hn 1 hnn 3 dih5
|
||||
*
|
||||
* nn 1.446
|
||||
* hn 1.016
|
||||
* hnn 106.0
|
||||
* dih4 -54.38
|
||||
* dih5 54.38
|
||||
* " ;;
|
||||
* - : Zmatrix.t = N
|
||||
* N 1 1.446000
|
||||
* H 1 1.016000 2 106.000000
|
||||
* H 2 1.016000 1 106.000000 3 -54.380000
|
||||
* H 1 1.016000 2 106.000000 4 54.380000
|
||||
* H 2 1.016000 1 106.000000 3 54.380000
|
||||
*
|
||||
*
|
||||
* Zmatrix.to_xyz zmt ;;
|
||||
* - : (Element.t * float * float * float) array =
|
||||
* [|(N, 0., 0., 0.); (N, 0., 0., 1.446);
|
||||
* (H, -0.976641883073332107, 0., -0.280047553510071046);
|
||||
* (H, -0.568802835186988709, 0.793909757123734683, 1.726047553510071);
|
||||
* (H, 0.314092649983635563, 0.924756819385119, -0.280047553510071101);
|
||||
* (H, -0.568802835186988709, -0.793909757123734683, 1.726047553510071)|]
|
||||
*
|
||||
*
|
||||
* Zmatrix.to_xyz_string zmt ;;
|
||||
* - : string =
|
||||
* "N 0.000000 0.000000 0.000000
|
||||
* N 0.000000 0.000000 1.446000
|
||||
* H -0.976642 0.000000 -0.280048
|
||||
* H -0.568803 0.793910 1.726048
|
||||
* H 0.314093 0.924757 -0.280048
|
||||
* H -0.568803 -0.793910 1.726048"
|
||||
* #+end_example *)
|
||||
|
||||
|
||||
|
||||
(* [[file:../zmatrix.org::*Conversion][Conversion:2]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::*Conversion][Conversion:2]] *)
|
||||
let pi = Common.Constants.pi
|
||||
let to_radian = pi /. 180.
|
||||
|
||||
@ -301,12 +344,12 @@ let to_xyz_string (l,map) =
|
||||
String.concat "\n"
|
||||
( to_xyz (l,map)
|
||||
|> Array.map (fun (e,x,y,z) ->
|
||||
Printf.sprintf "%s %f %f %f\n" (Element.to_string e) x y z)
|
||||
Printf.sprintf "%s %f %f %f" (Element.to_string e) x y z)
|
||||
|> Array.to_list
|
||||
)
|
||||
(* Conversion:2 ends here *)
|
||||
|
||||
(* [[file:../zmatrix.org::*Printers][Printers:2]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::*Printers][Printers:2]] *)
|
||||
let pp ppf (a, map) =
|
||||
let f = string_of_line map in
|
||||
Format.fprintf ppf "@[";
|
||||
|
@ -2,14 +2,14 @@
|
||||
*
|
||||
* #+NAME: types *)
|
||||
|
||||
(* [[file:../zmatrix.org::types][types]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::types][types]] *)
|
||||
type t
|
||||
(* types ends here *)
|
||||
|
||||
(* Conversion *)
|
||||
|
||||
|
||||
(* [[file:../zmatrix.org::*Conversion][Conversion:1]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::*Conversion][Conversion:1]] *)
|
||||
val of_string : string -> t
|
||||
val to_xyz : t -> (Element.t * float * float * float) array
|
||||
val to_xyz_string : t -> string
|
||||
@ -18,6 +18,6 @@ val to_xyz_string : t -> string
|
||||
(* Printers *)
|
||||
|
||||
|
||||
(* [[file:../zmatrix.org::*Printers][Printers:1]] *)
|
||||
(* [[file:~/QCaml/particles/zmatrix.org::*Printers][Printers:1]] *)
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(* Printers:1 ends here *)
|
||||
|
@ -53,6 +53,49 @@ val to_xyz_string : t -> string
|
||||
| ~to_xyz~ | Converts to xyz format, as in the ~Nuclei~ module |
|
||||
| ~to_xyz_string~ | Converts to xyz format, as a string |
|
||||
|
||||
#+begin_example
|
||||
let zmt = Zmatrix.of_string "
|
||||
n
|
||||
n 1 nn
|
||||
h 1 hn 2 hnn
|
||||
h 2 hn 1 hnn 3 dih4
|
||||
h 1 hn 2 hnn 4 dih5
|
||||
h 2 hn 1 hnn 3 dih5
|
||||
|
||||
nn 1.446
|
||||
hn 1.016
|
||||
hnn 106.0
|
||||
dih4 -54.38
|
||||
dih5 54.38
|
||||
" ;;
|
||||
- : Zmatrix.t = N
|
||||
N 1 1.446000
|
||||
H 1 1.016000 2 106.000000
|
||||
H 2 1.016000 1 106.000000 3 -54.380000
|
||||
H 1 1.016000 2 106.000000 4 54.380000
|
||||
H 2 1.016000 1 106.000000 3 54.380000
|
||||
|
||||
|
||||
Zmatrix.to_xyz zmt ;;
|
||||
- : (Element.t * float * float * float) array =
|
||||
[|(N, 0., 0., 0.); (N, 0., 0., 1.446);
|
||||
(H, -0.976641883073332107, 0., -0.280047553510071046);
|
||||
(H, -0.568802835186988709, 0.793909757123734683, 1.726047553510071);
|
||||
(H, 0.314092649983635563, 0.924756819385119, -0.280047553510071101);
|
||||
(H, -0.568802835186988709, -0.793909757123734683, 1.726047553510071)|]
|
||||
|
||||
|
||||
Zmatrix.to_xyz_string zmt ;;
|
||||
- : string =
|
||||
"N 0.000000 0.000000 0.000000
|
||||
N 0.000000 0.000000 1.446000
|
||||
H -0.976642 0.000000 -0.280048
|
||||
H -0.568803 0.793910 1.726048
|
||||
H 0.314093 0.924757 -0.280048
|
||||
H -0.568803 -0.793910 1.726048"
|
||||
#+end_example
|
||||
|
||||
|
||||
#+begin_src ocaml :tangle (eval ml) :exports none
|
||||
let pi = Common.Constants.pi
|
||||
let to_radian = pi /. 180.
|
||||
@ -331,7 +374,7 @@ let to_xyz_string (l,map) =
|
||||
String.concat "\n"
|
||||
( to_xyz (l,map)
|
||||
|> Array.map (fun (e,x,y,z) ->
|
||||
Printf.sprintf "%s %f %f %f\n" (Element.to_string e) x y z)
|
||||
Printf.sprintf "%s %f %f %f" (Element.to_string e) x y z)
|
||||
|> Array.to_list
|
||||
)
|
||||
#+end_src
|
||||
|
Loading…
Reference in New Issue
Block a user