diff --git a/ocaml/Atom.ml b/ocaml/Atom.ml index 7fd94ac4..ac9b73e7 100644 --- a/ocaml/Atom.ml +++ b/ocaml/Atom.ml @@ -6,7 +6,7 @@ type t = { element : Element.t ; charge : Charge.t ; coord : Point3d.t ; -} +} with sexp (** Read xyz coordinates of the atom with unit u *) let of_string u s = diff --git a/ocaml/Basis.ml b/ocaml/Basis.ml index 844269ed..9c88aa24 100644 --- a/ocaml/Basis.ml +++ b/ocaml/Basis.ml @@ -1,7 +1,7 @@ open Core.Std;; open Qptypes;; -type t = (Gto.t * Nucl_number.t) list;; +type t = (Gto.t * Nucl_number.t) list with sexp;; (** Read all the basis functions of an element *) let read in_channel at_number = diff --git a/ocaml/Bit.ml b/ocaml/Bit.ml index c9c8abdc..91482ef9 100644 --- a/ocaml/Bit.ml +++ b/ocaml/Bit.ml @@ -1,3 +1,4 @@ +open Core.Std;; (* Type for bits @@ -10,6 +11,7 @@ Zero | One type bit = | One | Zero +with sexp let to_string = function | Zero -> "0" diff --git a/ocaml/Charge.ml b/ocaml/Charge.ml index 6b58065a..b40469d2 100644 --- a/ocaml/Charge.ml +++ b/ocaml/Charge.ml @@ -1,11 +1,12 @@ open Core.Std;; -type t = float +type t = float with sexp;; let of_float x = x let of_int i = Float.of_int i let of_string s = Float.of_string s + let to_float x = x let to_int x = Float.to_int x let to_string x = diff --git a/ocaml/Charge.mli b/ocaml/Charge.mli index 027c2fad..753de281 100644 --- a/ocaml/Charge.mli +++ b/ocaml/Charge.mli @@ -1,4 +1,4 @@ -type t = float +type t = float with sexp val to_float : t -> float val to_int : t -> int diff --git a/ocaml/Element.ml b/ocaml/Element.ml index c6ab549e..c1048b79 100644 --- a/ocaml/Element.ml +++ b/ocaml/Element.ml @@ -8,7 +8,7 @@ type t = |Li|Be |B |C |N |O |F |Ne |Na|Mg |Al|Si|P |S |Cl|Ar |K |Ca|Sc|Ti|V |Cr|Mn|Fe|Co|Ni|Cu|Zn|Ga|Ge|As|Se|Br|Kr -;; +with sexp;; let of_string x = match (String.capitalize (String.lowercase x)) with diff --git a/ocaml/Excitation.ml b/ocaml/Excitation.ml index 89d76f1f..877c5387 100644 --- a/ocaml/Excitation.ml +++ b/ocaml/Excitation.ml @@ -2,21 +2,21 @@ open Core.Std;; open Qptypes;; module Hole : sig - type t + type t with sexp val to_mo_class : t -> MO_class.t val of_mo_class : MO_class.t -> t end = struct - type t = MO_class.t + type t = MO_class.t with sexp let of_mo_class x = x let to_mo_class x = x end module Particle : sig - type t + type t with sexp val to_mo_class : t -> MO_class.t val of_mo_class : MO_class.t -> t end = struct - type t = MO_class.t + type t = MO_class.t with sexp let of_mo_class x = x let to_mo_class x = x end @@ -24,7 +24,7 @@ end type t = | Single of Hole.t*Particle.t | Double of Hole.t*Particle.t*Hole.t*Particle.t -;; +with sexp;; let failwith s = raise (Failure s) ;; diff --git a/ocaml/Gto.ml b/ocaml/Gto.ml index fc1953b2..64596c6e 100644 --- a/ocaml/Gto.ml +++ b/ocaml/Gto.ml @@ -7,7 +7,7 @@ exception End_Of_Basis type t = { sym : Symmetry.t ; lc : ((Primitive.t * AO_coef.t) list) -} +} with sexp ;; let of_prim_coef_list pc = @@ -62,6 +62,7 @@ let read_one in_channel = | _ -> raise (GTO_Read_Failure line_buffer) end in read_lines [] n + |> List.rev |> of_prim_coef_list ;; @@ -70,6 +71,6 @@ let read_one in_channel = let to_string { sym = sym ; lc = lc } = let f (p,c) = Printf.sprintf "( %s, %f )" (Primitive.to_string p) (AO_coef.to_float c) in - Printf.sprintf "[ %s : %s ]" (Symmetry.to_string sym) + Printf.sprintf "( %s, %s )" (Symmetry.to_string sym) (String.concat (List.map ~f:f lc) ~sep:", ") ;; diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 276e4b8d..c7366409 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -12,10 +12,11 @@ module Ao_basis : sig ao_power : Symmetry.Xyz.t array; ao_coef : AO_coef.t array; ao_expo : AO_expo.t array; - } + } with sexp ;; val read : unit -> t val to_string : t -> string + val debug : t -> string end = struct type t = { ao_basis : string ; @@ -26,7 +27,7 @@ end = struct ao_power : Symmetry.Xyz.t array; ao_coef : AO_coef.t array; ao_expo : AO_expo.t array; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "ao_basis";; @@ -104,16 +105,56 @@ end = struct ;; let to_string b = + let ao_num = AO_number.to_int b.ao_num in + let gto_array = Array.init (AO_number.to_int b.ao_num) + ~f:(fun i -> + let s = Symmetry.Xyz.to_symmetry b.ao_power.(i) in + let ao_prim_num = AO_prim_number.to_int b.ao_prim_num.(i) in + let prims = List.init ao_prim_num ~f:(fun j -> + let prim = { Primitive.sym = s ; + Primitive.expo = b.ao_expo.(ao_num*j+i) + } + in + let coef = b.ao_coef.(ao_num*j+i) in + (prim,coef) + ) in + Gto.of_prim_coef_list prims + ) + in + let long_basis = + let rec do_work accu sym gto nucl = + match (sym, gto, nucl) with + | (s::srest, g::grest, n::nrest) -> + do_work ((s,g,n)::accu) srest grest nrest + | ([],[],[]) -> List.rev accu + | _ -> assert false + in + do_work [] + (Array.to_list b.ao_power) + (Array.to_list gto_array) + (Array.to_list b.ao_nucl) + in Printf.sprintf " -ao_basis = \"%s\" -ao_num = %s -ao_prim_num = %s -ao_prim_num_max = %s -ao_nucl = %s -ao_power = %s -ao_coef = %s -ao_expo = %s -" +# AO Basis +# ======== +%s" (Long_basis.to_string long_basis) + ;; + + + let debug b = + Printf.sprintf " +# AO Basis +# ======== +# +# ao_basis = %s +# ao_num = %s +# ao_prim_num = %s +# ao_prim_num_max = %s +# ao_nucl = %s +# ao_power = %s +# ao_coef = %s +# ao_expo = %s +#" b.ao_basis (AO_number.to_string b.ao_num) (b.ao_prim_num |> Array.to_list |> List.map @@ -128,6 +169,6 @@ ao_expo = %s (b.ao_expo |> Array.to_list |> List.map ~f:AO_expo.to_string |> String.concat ~sep:", ") + ;; end - diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index 3322f4c2..17fea98e 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -11,7 +11,7 @@ module Bielec_integrals : sig threshold_ao : Threshold.t; threshold_mo : Threshold.t; direct : bool; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -24,7 +24,7 @@ end = struct threshold_ao : Threshold.t; threshold_mo : Threshold.t; direct : bool; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "bielec_integrals";; diff --git a/ocaml/Input_bitmasks.ml b/ocaml/Input_bitmasks.ml index be82f603..3f413d23 100644 --- a/ocaml/Input_bitmasks.ml +++ b/ocaml/Input_bitmasks.ml @@ -8,7 +8,7 @@ module Bitmasks : sig bit_kind : Bit_kind.t; n_mask_gen : Bitmask_number.t; generators : int64 array; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -18,7 +18,7 @@ end = struct bit_kind : Bit_kind.t; n_mask_gen : Bitmask_number.t; generators : int64 array; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "bitmasks";; diff --git a/ocaml/Input_cis.ml b/ocaml/Input_cis.ml index 6b521872..d88b6075 100644 --- a/ocaml/Input_cis.ml +++ b/ocaml/Input_cis.ml @@ -10,7 +10,7 @@ module Cis_dressed : sig mp2_dressing : bool; standard_doubles : bool; en_2_2 : bool; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -22,7 +22,7 @@ end = struct mp2_dressing : bool; standard_doubles : bool; en_2_2 : bool; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "cis_dressed";; diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index 4a5461f4..b560aa65 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -7,7 +7,7 @@ module Cisd_sc2 : sig { n_det_max_cisd_sc2 : Det_number.t; pt2_max : PT2_energy.t; do_pt2_end : bool; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -16,7 +16,7 @@ end = struct { n_det_max_cisd_sc2 : Det_number.t; pt2_max : PT2_energy.t; do_pt2_end : bool; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "cisd_sc2_selected";; diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index fb2f599f..c8f1854c 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -18,7 +18,7 @@ module Determinants : sig s2_eig : bool; psi_coef : Det_coef.t array; psi_det : Determinant.t array; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -38,7 +38,7 @@ end = struct s2_eig : bool; psi_coef : Det_coef.t array; psi_det : Determinant.t array; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "determinants";; diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index 75785aea..8de68dbf 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -7,7 +7,7 @@ module Electrons : sig { elec_alpha_num : Elec_alpha_number.t; elec_beta_num : Elec_beta_number.t; elec_num : Elec_number.t; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -16,7 +16,7 @@ end = struct { elec_alpha_num : Elec_alpha_number.t; elec_beta_num : Elec_beta_number.t; elec_num : Elec_number.t; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "electrons";; diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index bcff6681..16de2a20 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -7,7 +7,7 @@ module Full_ci : sig { n_det_max_fci : Det_number.t; pt2_max : PT2_energy.t; do_pt2_end : bool; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -16,7 +16,7 @@ end = struct { n_det_max_fci : Det_number.t; pt2_max : PT2_energy.t; do_pt2_end : bool; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "full_ci";; diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index a612ae74..6f2f12b2 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -6,7 +6,7 @@ module Hartree_fock : sig type t = { n_it_scf_max : Strictly_positive_int.t; thresh_scf : Threshold.t; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -14,7 +14,7 @@ end = struct type t = { n_it_scf_max : Strictly_positive_int.t; thresh_scf : Threshold.t; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "hartree_fock";; diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index fab7810a..f2ad0888 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -8,7 +8,7 @@ module Mo_basis : sig mo_label : Non_empty_string.t; mo_occ : Positive_float.t array; mo_coef : MO_coef.t array; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -18,7 +18,7 @@ end = struct mo_label : Non_empty_string.t; mo_occ : Positive_float.t array; mo_coef : MO_coef.t array; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "mo_basis";; diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index c4139edb..3ec396ce 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -8,7 +8,7 @@ module Nuclei : sig nucl_label : Element.t array; nucl_charge : Charge.t array; nucl_coord : Point3d.t array; - } + } with sexp ;; val read : unit -> t val to_string : t -> string @@ -18,7 +18,7 @@ end = struct nucl_label : Element.t array; nucl_charge : Charge.t array; nucl_coord : Point3d.t array; - } + } with sexp ;; let get_default = Qpackage.get_ezfio_default "nuclei";; diff --git a/ocaml/Long_basis.ml b/ocaml/Long_basis.ml index c59a628a..8f6c4f57 100644 --- a/ocaml/Long_basis.ml +++ b/ocaml/Long_basis.ml @@ -1,7 +1,7 @@ open Core.Std;; open Qptypes;; -type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t ) list;; +type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t ) list with sexp let of_basis b = let rec do_work accu = function @@ -21,9 +21,15 @@ let of_basis b = let to_string b = - List.map ~f:(fun (x,y,z) -> - (Int.to_string (Nucl_number.to_int z))^":"^ - (Symmetry.Xyz.to_string x)^" "^(Gto.to_string y) - ) b - |> String.concat ~sep:"\n" + Sexp.to_string (sexp_of_t b) ;; +(* + let middle = List.map ~f:(fun (x,y,z) -> + "( "^((Int.to_string (Nucl_number.to_int z)))^", "^ + (Symmetry.Xyz.to_string x)^", "^(Gto.to_string y) + ^" )" + ) b + |> String.concat ~sep:",\n" + in "("^middle^")" +;; +*) diff --git a/ocaml/MO_class.ml b/ocaml/MO_class.ml index 93b8007b..4fc03da2 100644 --- a/ocaml/MO_class.ml +++ b/ocaml/MO_class.ml @@ -7,7 +7,7 @@ type t = | Active of MO_number.t list | Virtual of MO_number.t list | Deleted of MO_number.t list -;; +with sexp let to_string x = diff --git a/ocaml/Makefile b/ocaml/Makefile index 82838cee..c477fce6 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -13,7 +13,7 @@ endif LIBS= PKGS= OCAMLCFLAGS=-g -OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags -g +OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags -g MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml MLIFILES=$(wildcard *.mli) ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml)) diff --git a/ocaml/Molecule.ml b/ocaml/Molecule.ml index 7592b85a..0bef0bc4 100644 --- a/ocaml/Molecule.ml +++ b/ocaml/Molecule.ml @@ -7,7 +7,7 @@ type t = { nuclei : Atom.t list ; elec_alpha : Elec_alpha_number.t ; elec_beta : Elec_beta_number.t ; -} +} with sexp let get_charge { nuclei ; elec_alpha ; elec_beta } = let result = (Elec_alpha_number.to_int elec_alpha) + diff --git a/ocaml/Multiplicity.ml b/ocaml/Multiplicity.ml index a66233a8..e56341c6 100644 --- a/ocaml/Multiplicity.ml +++ b/ocaml/Multiplicity.ml @@ -1,7 +1,8 @@ open Core.Std;; open Qptypes ;; -type t = Strictly_positive_int.t;; +type t = Strictly_positive_int.t with sexp + let of_int = Strictly_positive_int.of_int ;; let to_int = Strictly_positive_int.to_int ;; diff --git a/ocaml/Point3d.ml b/ocaml/Point3d.ml index daafd139..8dce49b7 100644 --- a/ocaml/Point3d.ml +++ b/ocaml/Point3d.ml @@ -4,7 +4,7 @@ type t = { x : float ; y : float ; z : float ; -} +} with sexp (** Read x y z coordinates in string s with units u *) let of_string u s = diff --git a/ocaml/Primitive.ml b/ocaml/Primitive.ml index 82a94fa4..3d9a36d5 100644 --- a/ocaml/Primitive.ml +++ b/ocaml/Primitive.ml @@ -4,7 +4,7 @@ open Core.Std;; type t = { sym : Symmetry.t ; expo : AO_expo.t ; -} +} with sexp let to_string p = let { sym = s ; expo = e } = p in diff --git a/ocaml/Range.ml b/ocaml/Range.ml index d93be879..9607c6a3 100644 --- a/ocaml/Range.ml +++ b/ocaml/Range.ml @@ -12,7 +12,7 @@ open Core.Std;; *) -type t = int list ;; +type t = int list with sexp let expand_range r = match String.lsplit2 ~on:'-' r with diff --git a/ocaml/Symmetry.ml b/ocaml/Symmetry.ml index 828d0dfa..43358116 100644 --- a/ocaml/Symmetry.ml +++ b/ocaml/Symmetry.ml @@ -1,7 +1,7 @@ open Qptypes;; open Core.Std;; -type t = S|P|D|F|G|H|I|J|K|L +type t = S|P|D|F|G|H|I|J|K|L with sexp let to_string = function | S -> "S" @@ -53,6 +53,23 @@ let to_l = function | J -> Positive_int.of_int 7 | K -> Positive_int.of_int 8 | L -> Positive_int.of_int 9 +;; + +let of_l i = + let i = Positive_int.to_int i in + match i with + | 0 -> S + | 1 -> P + | 2 -> D + | 3 -> F + | 4 -> G + | 5 -> H + | 6 -> I + | 7 -> J + | 8 -> K + | 9 -> L + | x -> raise (Failure ("Symmetry should be S|P|D|F|G|H|I|J|K|L")) +;; type st = t ;; @@ -60,15 +77,16 @@ type st = t module Xyz : sig type t = { x: Positive_int.t ; y: Positive_int.t ; - z: Positive_int.t } + z: Positive_int.t } with sexp val of_string : string -> t val to_string : t -> string val get_l : t -> Positive_int.t val of_symmetry : st -> t list + val to_symmetry : t -> st end = struct type t = { x: Positive_int.t ; y: Positive_int.t ; - z: Positive_int.t } + z: Positive_int.t } with sexp type state_type = Null | X | Y | Z (** Builds an XYZ triplet from a string. @@ -127,7 +145,9 @@ end = struct | 1 -> "z" | i -> Printf.sprintf "z%d" i in - x^y^z + let result = (x^y^z) in + if (result = "") then "s" + else result ;; (** Returns the l quantum number from a XYZ powers triplet *) @@ -169,5 +189,7 @@ end = struct z=Positive_int.of_int 0 } ;; + let to_symmetry sym = of_l (get_l sym) + ;; end diff --git a/ocaml/_tags b/ocaml/_tags index 55cb5085..7432848a 100644 --- a/ocaml/_tags +++ b/ocaml/_tags @@ -1,3 +1,3 @@ -true: package(core) +true: package(core,sexplib.syntax) true: thread diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index fa3bbdd5..008bf565 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -126,12 +126,12 @@ let input_data = " let untouched = " module Determinant : sig - type t + type t with sexp val to_int64_array : t -> int64 array val of_int64_array : int64 array -> t val to_string : t -> string end = struct - type t = int64 array + type t = int64 array with sexp let to_int64_array x = x let of_int64_array x = if (Ezfio.has_determinants_n_int ()) then @@ -149,12 +149,12 @@ end let template = format_of_string " module %s : sig - type t + type t with sexp val to_%s : t -> %s val of_%s : %s -> t val to_string : t -> string end = struct - type t = %s + type t = %s with sexp let to_%s x = x let of_%s x = ( %s x ) let to_string x = %s.to_string x diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 917ced2a..39578028 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -2,6 +2,7 @@ let test_ao () = Ezfio.set_file "F2.ezfio" ; let b = Input.Ao_basis.read () in + print_endline (Input.Ao_basis.debug b); print_endline (Input.Ao_basis.to_string b); ;; @@ -84,5 +85,7 @@ test_cis (); test_dets (); test_cisd_sc2 (); test_mo ();; -*) test_nucl (); +*) +test_ao ();; +