diff --git a/ocaml/Atom.ml b/ocaml/Atom.ml index ac9b73e7..3b34951c 100644 --- a/ocaml/Atom.ml +++ b/ocaml/Atom.ml @@ -23,7 +23,7 @@ let of_string u s = | [ name; x; y; z ] -> let e = Element.of_string name in { element = e ; - charge = Charge.of_int (Element.to_charge e); + charge = Element.to_charge e; coord = Point3d.of_string u (String.concat [x; y; z] ~sep:" ") } | _ -> raise (AtomError s) diff --git a/ocaml/Atom.mli b/ocaml/Atom.mli new file mode 100644 index 00000000..93f7d885 --- /dev/null +++ b/ocaml/Atom.mli @@ -0,0 +1,9 @@ +exception AtomError of string + +type t = { element : Element.t; charge : Charge.t; coord : Point3d.t; } + +val t_of_sexp : Sexplib.Sexp.t -> t +val sexp_of_t : t -> Sexplib.Sexp.t + +val of_string : Units.units -> string -> t +val to_string : Units.units -> t -> string diff --git a/ocaml/Basis.ml b/ocaml/Basis.ml index 51e81142..941f7bcc 100644 --- a/ocaml/Basis.ml +++ b/ocaml/Basis.ml @@ -56,10 +56,8 @@ let to_string b = do_work [new_nucleus 1] 1 b |> String.concat ~sep:"\n" ;; -(* - List.map ~f:(fun (g,n) -> - let n = Nucl_number.to_int n in - (Int.to_string n)^":"^(Gto.to_string g)) b -;; -*) + +include To_md5;; +let to_md5 = to_md5 sexp_of_t +;; diff --git a/ocaml/Basis.mli b/ocaml/Basis.mli index 276578f4..4da99266 100644 --- a/ocaml/Basis.mli +++ b/ocaml/Basis.mli @@ -15,3 +15,6 @@ val read_element : (** Convert the basis to a string *) val to_string : (Gto.t * Nucl_number.t) list -> string + +(** Convert the basis to an MD5 hash *) +val to_md5 : (Gto.t * Nucl_number.t) list -> MD5.t diff --git a/ocaml/Bit.ml b/ocaml/Bit.ml index 91482ef9..28b8dac9 100644 --- a/ocaml/Bit.ml +++ b/ocaml/Bit.ml @@ -8,9 +8,9 @@ Zero | One *) -type bit = - | One - | Zero +type t = +| One +| Zero with sexp let to_string = function diff --git a/ocaml/Bit.mli b/ocaml/Bit.mli new file mode 100644 index 00000000..6dd5abdd --- /dev/null +++ b/ocaml/Bit.mli @@ -0,0 +1,10 @@ +type t = One | Zero with sexp + +(** String conversions for printing *) +val to_string : t -> string + +(** Logical operations *) +val and_operator : t -> t -> t +val or_operator : t -> t -> t +val xor_operator : t -> t -> t +val not_operator : t -> t diff --git a/ocaml/Bitlist.ml b/ocaml/Bitlist.ml index d197c42b..7e2d774e 100644 --- a/ocaml/Bitlist.ml +++ b/ocaml/Bitlist.ml @@ -7,7 +7,7 @@ Type for bits strings list of Bits *) -type bit_list = Bit.bit list +type t = Bit.t list (* String representation *) let to_string b = diff --git a/ocaml/Bitlist.mli b/ocaml/Bitlist.mli new file mode 100644 index 00000000..b8d87c7c --- /dev/null +++ b/ocaml/Bitlist.mli @@ -0,0 +1,32 @@ +type t = Bit.t list + +(** The zero bit list *) +val zero : Qptypes.N_int_number.t -> t + +(** Convert to a string for printing *) +val to_string : t -> string + +(** int64 conversion functions *) + +val of_int64 : int64 -> t +val to_int64 : t -> int64 + +val of_int64_list : int64 list -> t +val to_int64_list : t -> int64 list + +(** Get the number of needed int64 elements to encode the bit list *) +val n_int_of_mo_tot_num : int -> Qptypes.N_int_number.t + +(** Conversion to MO numbers *) +val to_mo_number_list : t -> Qptypes.MO_number.t list +val of_mo_number_list : + Qptypes.N_int_number.t -> Qptypes.MO_number.t list -> t + +(** Logical operators *) +val and_operator : t -> t -> t +val xor_operator : t -> t -> t +val or_operator : t -> t -> t +val not_operator : t -> t + +(** Count the number of bits set to one *) +val popcnt : t -> int diff --git a/ocaml/Charge.mli b/ocaml/Charge.mli index 753de281..07685531 100644 --- a/ocaml/Charge.mli +++ b/ocaml/Charge.mli @@ -1,8 +1,13 @@ type t = float with sexp +(** Float conversion functions *) val to_float : t -> float -val to_int : t -> int -val to_string: t -> string val of_float : float -> t + +(** Int conversion functions *) +val to_int : t -> int val of_int : int -> t + +(** String conversion functions *) +val to_string: t -> string val of_string: string -> t diff --git a/ocaml/Element.ml b/ocaml/Element.ml index c1048b79..d282340b 100644 --- a/ocaml/Element.ml +++ b/ocaml/Element.ml @@ -132,47 +132,49 @@ let to_long_string = function | Kr -> "Krypton" ;; -let to_charge = function -| X -> 0 -| H -> 1 -| He -> 2 -| Li -> 3 -| Be -> 4 -| B -> 5 -| C -> 6 -| N -> 7 -| O -> 8 -| F -> 9 -| Ne -> 10 -| Na -> 11 -| Mg -> 12 -| Al -> 13 -| Si -> 14 -| P -> 15 -| S -> 16 -| Cl -> 17 -| Ar -> 18 -| K -> 19 -| Ca -> 20 -| Sc -> 21 -| Ti -> 22 -| V -> 23 -| Cr -> 24 -| Mn -> 25 -| Fe -> 26 -| Co -> 27 -| Ni -> 28 -| Cu -> 29 -| Zn -> 30 -| Ga -> 31 -| Ge -> 32 -| As -> 33 -| Se -> 34 -| Br -> 35 -| Kr -> 36 +let to_charge c = + let result = match c with + | X -> 0 + | H -> 1 + | He -> 2 + | Li -> 3 + | Be -> 4 + | B -> 5 + | C -> 6 + | N -> 7 + | O -> 8 + | F -> 9 + | Ne -> 10 + | Na -> 11 + | Mg -> 12 + | Al -> 13 + | Si -> 14 + | P -> 15 + | S -> 16 + | Cl -> 17 + | Ar -> 18 + | K -> 19 + | Ca -> 20 + | Sc -> 21 + | Ti -> 22 + | V -> 23 + | Cr -> 24 + | Mn -> 25 + | Fe -> 26 + | Co -> 27 + | Ni -> 28 + | Cu -> 29 + | Zn -> 30 + | Ga -> 31 + | Ge -> 32 + | As -> 33 + | Se -> 34 + | Br -> 35 + | Kr -> 36 + in Charge.of_int result ;; -let of_charge = function +let of_charge c = match (Charge.to_int c) with | 0 -> X | 1 -> H | 2 -> He diff --git a/ocaml/Element.mli b/ocaml/Element.mli new file mode 100644 index 00000000..48bd3c61 --- /dev/null +++ b/ocaml/Element.mli @@ -0,0 +1,18 @@ +exception ElementError of string + +type t = +|X +|H |He +|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 + +(** String conversion functions *) +val of_string : string -> t +val to_string : t -> string +val to_long_string : t -> string + +(** get the positive charge *) +val to_charge : t -> Charge.t +val of_charge : Charge.t -> t diff --git a/ocaml/Excitation.ml b/ocaml/Excitation.ml index 877c5387..d58c3093 100644 --- a/ocaml/Excitation.ml +++ b/ocaml/Excitation.ml @@ -1,21 +1,13 @@ open Core.Std;; open Qptypes;; -module Hole : sig - type t with sexp - val to_mo_class : t -> MO_class.t - val of_mo_class : MO_class.t -> t -end = struct +module Hole = struct 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 with sexp - val to_mo_class : t -> MO_class.t - val of_mo_class : MO_class.t -> t -end = struct +module Particle = struct type t = MO_class.t with sexp let of_mo_class x = x let to_mo_class x = x @@ -26,9 +18,6 @@ type t = | Double of Hole.t*Particle.t*Hole.t*Particle.t with sexp;; -let failwith s = raise (Failure s) -;; - let create_single ~hole ~particle = MO_class.( match (hole,particle) with diff --git a/ocaml/Excitation.mli b/ocaml/Excitation.mli new file mode 100644 index 00000000..982cfd0e --- /dev/null +++ b/ocaml/Excitation.mli @@ -0,0 +1,30 @@ +module Hole : + sig + type t + val to_mo_class : t -> MO_class.t + val of_mo_class : MO_class.t -> t + val t_of_sexp : Sexplib.Sexp.t -> t + val sexp_of_t : t -> Sexplib.Sexp.t + end +module Particle : + sig + type t + val to_mo_class : t -> MO_class.t + val of_mo_class : MO_class.t -> t + val t_of_sexp : Sexplib.Sexp.t -> t + val sexp_of_t : t -> Sexplib.Sexp.t + end + +type t = + | Single of Hole.t * Particle.t + | Double of Hole.t * Particle.t * Hole.t * Particle.t +with sexp + +val create_single : hole:MO_class.t -> particle:MO_class.t -> t + +val double_of_singles : t -> t -> t + +val create_double : hole1:MO_class.t -> particle1:MO_class.t -> + hole2:MO_class.t -> particle2:MO_class.t -> t + +val to_string : t -> string diff --git a/ocaml/Gto.mli b/ocaml/Gto.mli new file mode 100644 index 00000000..fad133a3 --- /dev/null +++ b/ocaml/Gto.mli @@ -0,0 +1,16 @@ +exception GTO_Read_Failure of string +exception End_Of_Basis +type t = + { sym : Symmetry.t ; + lc : (Primitive.t * Qptypes.AO_coef.t) list; + } with sexp + +(** Create from a list of Primitive.t * Qptypes.AO_coef.t *) +val of_prim_coef_list : + (Primitive.t * Qptypes.AO_coef.t) list -> t + +(** Read from a file *) +val read_one : in_channel -> t + +(** Convert to string for printing *) +val to_string : t -> string diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 4049bb65..a96993f2 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -16,6 +16,7 @@ module Ao_basis : sig ;; val read : unit -> t val to_string : t -> string + val to_md5 : t -> MD5.t val debug : t -> string end = struct type t = @@ -103,8 +104,8 @@ end = struct ao_expo = read_ao_expo () ; } ;; - - let to_string b = + + let to_long_basis 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 -> @@ -121,27 +122,35 @@ end = struct 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 - let short_basis = - Long_basis.to_basis 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) + ;; + + let to_basis b = + to_long_basis b + |> Long_basis.to_basis + ;; + + let to_string b = + let short_basis = to_basis b in Printf.sprintf "Basis name : %s\n\n%s" b.ao_basis (Basis.to_string short_basis) ;; + + let to_md5 b = + let short_basis = to_basis b in + Basis.to_md5 short_basis + ;; - let debug b = Printf.sprintf " ao_basis = %s @@ -152,6 +161,7 @@ ao_nucl = %s ao_power = %s ao_coef = %s ao_expo = %s +md5 = %s " b.ao_basis (AO_number.to_string b.ao_num) @@ -166,6 +176,7 @@ ao_expo = %s |> String.concat ~sep:", ") (b.ao_expo |> Array.to_list |> List.map ~f:AO_expo.to_string |> String.concat ~sep:", ") + (to_md5 b |> MD5.to_string ) ;; end diff --git a/ocaml/Long_basis.ml b/ocaml/Long_basis.ml index 93f1b79b..38091079 100644 --- a/ocaml/Long_basis.ml +++ b/ocaml/Long_basis.ml @@ -47,3 +47,8 @@ let to_string b = |> String.concat ~sep:",\n" in "("^middle^")" ;; + +include To_md5;; +let to_md5 = to_md5 sexp_of_t +;; + diff --git a/ocaml/MO_class.mli b/ocaml/MO_class.mli new file mode 100644 index 00000000..057d4b20 --- /dev/null +++ b/ocaml/MO_class.mli @@ -0,0 +1,21 @@ +type t = + | Core of Qptypes.MO_number.t list + | Inactive of Qptypes.MO_number.t list + | Active of Qptypes.MO_number.t list + | Virtual of Qptypes.MO_number.t list + | Deleted of Qptypes.MO_number.t list +with sexp + + +(** Create different excitation classes *) +val create_core : string -> t +val create_inactive : string -> t +val create_active : string -> t +val create_virtual : string -> t +val create_deleted : string -> t + +(** Convert to a Bitlist.t *) +val to_bitlist : Qptypes.N_int_number.t -> t -> Bitlist.t + +(** Convert to string for printing *) +val to_string : t -> string diff --git a/ocaml/Molecule.ml b/ocaml/Molecule.ml index 0bef0bc4..48c28997 100644 --- a/ocaml/Molecule.ml +++ b/ocaml/Molecule.ml @@ -78,7 +78,7 @@ let to_string m = ;; let of_xyz_string - ?(charge=0) ?(multiplicity=(Multiplicity.of_int 1)) + ?(charge=(Charge.of_int 0)) ?(multiplicity=(Multiplicity.of_int 1)) ?(units=Units.Angstrom) s = let l = String.split s ~on:'\n' @@ -90,7 +90,7 @@ let of_xyz_string elec_alpha=(Elec_alpha_number.of_int 1) ; elec_beta=(Elec_beta_number.of_int 0) } |> Charge.to_int - ) + 1 - charge + ) + 1 - (Charge.to_int charge) |> Elec_number.of_int in let (na,nb) = Multiplicity.to_alpha_beta ne multiplicity in @@ -112,10 +112,16 @@ let of_xyz_string let of_xyz_file - ?(charge=0) ?(multiplicity=(Multiplicity.of_int 1)) + ?(charge=(Charge.of_int 0)) ?(multiplicity=(Multiplicity.of_int 1)) + ?(units=Units.Angstrom) filename = let (_,buffer) = In_channel.read_all filename |> String.lsplit2_exn ~on:'\n' in let (_,buffer) = String.lsplit2_exn buffer ~on:'\n' in - of_xyz_string ~charge:charge ~multiplicity:multiplicity buffer + of_xyz_string ~charge:charge ~multiplicity:multiplicity + ~units:units buffer +;; + +include To_md5;; +let to_md5 = to_md5 sexp_of_t ;; diff --git a/ocaml/Molecule.mli b/ocaml/Molecule.mli new file mode 100644 index 00000000..176441d4 --- /dev/null +++ b/ocaml/Molecule.mli @@ -0,0 +1,38 @@ +exception MultiplicityError of string + +type t = { + nuclei : Atom.t list; + elec_alpha : Qptypes.Elec_alpha_number.t; + elec_beta : Qptypes.Elec_beta_number.t; +} with sexp + +(** Returns the charge of the molecule *) +val get_charge : t -> Charge.t + +(** Returns the multiplicity of the molecule *) +val get_multiplicity : t -> Multiplicity.t + +(** Returns the number of nuclei *) +val get_nucl_num : t -> Qptypes.Nucl_number.t + +(** The name of the molecule *) +val name : t -> string + +(** Conversion for printing *) +val to_string : t -> string + + +(** Creates a molecule from an xyz file *) +val of_xyz_file : + ?charge:Charge.t -> + ?multiplicity:Multiplicity.t -> + ?units:Units.units -> string -> t + +(** Creates a molecule from an xyz file in a string *) +val of_xyz_string : + ?charge:Charge.t -> + ?multiplicity:Multiplicity.t -> + ?units:Units.units -> string -> t + +(** Computes the MD5 hash *) +val to_md5 : t -> Qptypes.MD5.t diff --git a/ocaml/Multiplicity.mli b/ocaml/Multiplicity.mli new file mode 100644 index 00000000..c6f8c6bf --- /dev/null +++ b/ocaml/Multiplicity.mli @@ -0,0 +1,19 @@ +type t = Qptypes.Strictly_positive_int.t with sexp + +(** Conversion from int *) +val of_int : int -> t +val to_int : t -> int + +(** Computation from the number of alpha and beta electrons *) +val of_alpha_beta : + Qptypes.Elec_alpha_number.t -> + Qptypes.Elec_beta_number.t -> t + +(** Generation of the number of alpha and beta electrons *) +val to_alpha_beta : + Qptypes.Elec_number.t -> t -> + Qptypes.Elec_alpha_number.t * Qptypes.Elec_beta_number.t + +(** Conversion to string for printing *) +val to_string : t-> string + diff --git a/ocaml/Point3d.mli b/ocaml/Point3d.mli new file mode 100644 index 00000000..066a4514 --- /dev/null +++ b/ocaml/Point3d.mli @@ -0,0 +1,17 @@ +type t = +{ x : float; + y : float; + z : float; +} with sexp + +(** Create from an xyz string *) +val of_string : Units.units -> string -> t + +(** Convert to a string for printing *) +val to_string : Units.units -> t -> string + +(** Computes the squared distance between 2 points *) +val distance2 : t -> t -> Qptypes.Positive_float.t + +(** Computes the distance between 2 points *) +val distance : t -> t -> float diff --git a/ocaml/_tags b/ocaml/_tags index 7432848a..980f3392 100644 --- a/ocaml/_tags +++ b/ocaml/_tags @@ -1,3 +1,3 @@ -true: package(core,sexplib.syntax) +true: package(core,sexplib.syntax,cryptokit) true: thread diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index d35cb42b..e4110268 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -26,8 +26,8 @@ let run ?o b c m xyz_file = (* Read molecule *) let molecule = - Molecule.of_xyz_file xyz_file ~charge:c - ~multiplicity:(Multiplicity.of_int m) + (Molecule.of_xyz_file xyz_file ~charge:(Charge.of_int c) + ~multiplicity:(Multiplicity.of_int m) ) in (* Build EZFIO File name *) diff --git a/ocaml/qp_print.ml b/ocaml/qp_print.ml index 6734b00a..9c2a5715 100644 --- a/ocaml/qp_print.ml +++ b/ocaml/qp_print.ml @@ -59,6 +59,7 @@ let run_i ~action ezfio_filename = and n_beta = input.Input.Electrons.elec_beta_num |> Elec_beta_number.to_int in Array.fold ~init:(-n_alpha-n_beta) ~f:(fun x y -> x+y) nucl_charge + |> Charge.of_int in let compute_multiplicity () = @@ -80,7 +81,7 @@ let run_i ~action ezfio_filename = Ezfio.((get_nuclei_nucl_label ()).data) |> Ezfio.flattened_ezfio_data else Array.map ~f:(fun x-> x - |> Float.to_int + |> Charge.of_float |> Element.of_charge |> Element.to_string ) nucl_charge in diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index 008bf565..68455d97 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -121,6 +121,8 @@ let input_data = " * Elec_number : int assert (x > 0) ; +* MD5 : string + assert ((String.length x) = 32); " ;; diff --git a/ocaml/test_basis.ml b/ocaml/test_basis.ml index e148bf0c..79492101 100644 --- a/ocaml/test_basis.ml +++ b/ocaml/test_basis.ml @@ -35,6 +35,7 @@ let test_module () = ; print_string "Short basis\n===========\n"; print_endline (Basis.to_string basis); + print_endline ("MD5: "^(Basis.to_md5 basis |> MD5.to_string)); ;; test_module (); diff --git a/ocaml/test_elements.ml b/ocaml/test_elements.ml index ef650e1e..119be84b 100644 --- a/ocaml/test_elements.ml +++ b/ocaml/test_elements.ml @@ -1,6 +1,6 @@ let test_module () = let atom = Element.of_string "Cobalt" in - Printf.printf "%s %d\n" (Element.to_string atom) (Element.to_charge atom) + Printf.printf "%s %d\n" (Element.to_string atom) (Charge.to_int (Element.to_charge atom)) ;; test_module ();; diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index f3fe9920..2781aaf6 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -95,5 +95,5 @@ test_hf ();; test_mo ();; test_nucl (); *) -test_bielec_intergals ();; +test_ao ();; diff --git a/ocaml/test_molecule.ml b/ocaml/test_molecule.ml index 7cd7e838..3abd7e9a 100644 --- a/ocaml/test_molecule.ml +++ b/ocaml/test_molecule.ml @@ -21,7 +21,7 @@ H 1.0 0.54386314 0.00000000 -0.92559535 print_string "---\n"; let m = Molecule.of_xyz_string xyz in print_endline (Molecule.name m) ; - let m = Molecule.of_xyz_string xyz ~charge:1 ~multiplicity:(Multiplicity.of_int 2) + let m = Molecule.of_xyz_string xyz ~charge:(Charge.of_int 1) ~multiplicity:(Multiplicity.of_int 2) in print_endline (Molecule.name m) ; let xyz = @@ -31,7 +31,7 @@ O 1.65102147 0.00000000 -2.35602344 H 0.54386314 0.00000000 -0.92559535 " in - let m = Molecule.of_xyz_string xyz ~charge:(-2) + let m = Molecule.of_xyz_string xyz ~charge:(Charge.of_int (-2)) in print_endline (Molecule.name m) ; print_endline (Molecule.to_string m); print_string "---------\n"; diff --git a/scripts/install_ocaml.sh b/scripts/install_ocaml.sh index 19dbc55b..72a6909a 100755 --- a/scripts/install_ocaml.sh +++ b/scripts/install_ocaml.sh @@ -4,6 +4,7 @@ # Thu Oct 23 21:58:40 CEST 2014 QPACKAGE_ROOT=${PWD} +PACKAGES="core cryptokit" make -C ocaml Qptypes.ml &> /dev/null if [[ $? -ne 0 ]] @@ -13,7 +14,7 @@ then cat < ocamlbrew-install.sh | env OCAMLBREW_FLAGS="-r" bash | tee ocamlbrew_install.log grep "source " ocamlbrew_install.log | grep "etc/ocamlbrew.bashrc" >> quantum_package.rc source quantum_package.rc - echo Y | opam install core + echo Y | opam install ${PACKAGES} fi make -C ocaml Qptypes.ml