From 6f745a6e25927583afcfeae2d66ef527949da37b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 23 Oct 2014 14:42:14 +0200 Subject: [PATCH] Corrected bugs in ocaml --- ocaml/Basis.ml | 4 ++-- ocaml/Basis.mli | 8 ++++---- ocaml/Gto.ml | 2 +- ocaml/Long_basis.ml | 4 ++-- ocaml/Long_basis.mli | 6 +++--- ocaml/Molecule.ml | 27 +++++++++++++-------------- ocaml/Multiplicity.ml | 10 +++++----- ocaml/Primitive.ml | 4 ++-- ocaml/qp_create_ezfio_from_xyz.ml | 12 ++++++------ ocaml/qp_print.ml | 4 ++-- ocaml/qptypes_generator.ml | 9 +-------- ocaml/test_basis.ml | 4 ++-- ocaml/test_gto.ml | 10 +++++----- setup_environment.sh | 1 + 14 files changed, 49 insertions(+), 56 deletions(-) diff --git a/ocaml/Basis.ml b/ocaml/Basis.ml index ba575761..844269ed 100644 --- a/ocaml/Basis.ml +++ b/ocaml/Basis.ml @@ -1,7 +1,7 @@ open Core.Std;; open Qptypes;; -type t = (Gto.t * Atom_number.t) list;; +type t = (Gto.t * Nucl_number.t) list;; (** Read all the basis functions of an element *) let read in_channel at_number = @@ -37,7 +37,7 @@ let read_element in_channel at_number element = let to_string b = List.map ~f:(fun (g,n) -> - let n = Atom_number.to_int n in + let n = Nucl_number.to_int n in (Int.to_string n)^":"^(Gto.to_string g)) b |> String.concat ~sep:"\n" ;; diff --git a/ocaml/Basis.mli b/ocaml/Basis.mli index b9465d8c..276578f4 100644 --- a/ocaml/Basis.mli +++ b/ocaml/Basis.mli @@ -1,17 +1,17 @@ open Qptypes;; -type t = (Gto.t * Atom_number.t) list +type t = (Gto.t * Nucl_number.t) list (** Read all the basis functions of an element and set the number of the * atom *) -val read : in_channel -> Atom_number.t -> (Gto.t * Atom_number.t) list +val read : in_channel -> Nucl_number.t -> (Gto.t * Nucl_number.t) list (** Find an element in the basis set file *) val find : in_channel -> Element.t -> Element.t (** Read the basis of an element from the file *) val read_element : - in_channel -> Atom_number.t -> Element.t -> (Gto.t * Atom_number.t) list + in_channel -> Nucl_number.t -> Element.t -> (Gto.t * Nucl_number.t) list (** Convert the basis to a string *) -val to_string : (Gto.t * Atom_number.t) list -> string +val to_string : (Gto.t * Nucl_number.t) list -> string diff --git a/ocaml/Gto.ml b/ocaml/Gto.ml index 8abc3837..fc1953b2 100644 --- a/ocaml/Gto.ml +++ b/ocaml/Gto.ml @@ -53,7 +53,7 @@ let read_one in_channel = | [ j ; expo ; coef ] -> begin let p = { Primitive.sym = sym ; - Primitive.expo = Positive_float.of_float + Primitive.expo = AO_expo.of_float (Float.of_string expo) } and c = AO_coef.of_float (Float.of_string coef) in diff --git a/ocaml/Long_basis.ml b/ocaml/Long_basis.ml index b5a600f9..c59a628a 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 * Atom_number.t ) list;; +type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t ) list;; let of_basis b = let rec do_work accu = function @@ -22,7 +22,7 @@ let of_basis b = let to_string b = List.map ~f:(fun (x,y,z) -> - (Int.to_string (Atom_number.to_int z))^":"^ + (Int.to_string (Nucl_number.to_int z))^":"^ (Symmetry.Xyz.to_string x)^" "^(Gto.to_string y) ) b |> String.concat ~sep:"\n" diff --git a/ocaml/Long_basis.mli b/ocaml/Long_basis.mli index 934505eb..6c9c8db3 100644 --- a/ocaml/Long_basis.mli +++ b/ocaml/Long_basis.mli @@ -5,12 +5,12 @@ open Qptypes;; * all the D orbitals are converted to xx, xy, xz, yy, yx * etc *) -type t = (Symmetry.Xyz.t * Gto.t * Atom_number.t) list +type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t) list (** Transform a basis to a long basis *) val of_basis : - (Gto.t * Atom_number.t) list -> (Symmetry.Xyz.t * Gto.t * Atom_number.t) list + (Gto.t * Nucl_number.t) list -> (Symmetry.Xyz.t * Gto.t * Nucl_number.t) list (** Convert the basis into its string representation *) val to_string : - (Symmetry.Xyz.t * Gto.t * Atom_number.t) list -> string + (Symmetry.Xyz.t * Gto.t * Nucl_number.t) list -> string diff --git a/ocaml/Molecule.ml b/ocaml/Molecule.ml index 7e467ffb..5454d8db 100644 --- a/ocaml/Molecule.ml +++ b/ocaml/Molecule.ml @@ -5,12 +5,13 @@ exception MultiplicityError of string;; type t = { nuclei : Atom.t list ; - elec_alpha : Positive_int.t ; - elec_beta : Positive_int.t ; + elec_alpha : Elec_alpha_number.t ; + elec_beta : Elec_beta_number.t ; } let get_charge { nuclei ; elec_alpha ; elec_beta } = - let result = Positive_int.(to_int elec_alpha + to_int elec_beta) in + let result = (Elec_alpha_number.to_int elec_alpha) + + (Elec_beta_number.to_int elec_beta) in let rec nucl_charge = function | a::rest -> (Charge.to_float a.Atom.charge) +. nucl_charge rest | [] -> 0. @@ -19,14 +20,12 @@ let get_charge { nuclei ; elec_alpha ; elec_beta } = ;; let get_multiplicity m = - let elec_alpha = m.elec_alpha - |> Positive_int.to_int - |> Strictly_positive_int.of_int in + let elec_alpha = m.elec_alpha in Multiplicity.of_alpha_beta elec_alpha m.elec_beta ;; let get_nucl_num m = - Strictly_positive_int.of_int (List.length m.nuclei) + Nucl_number.of_int (List.length m.nuclei) ;; let name m = @@ -88,22 +87,22 @@ let of_xyz_string in let ne = ( get_charge { nuclei=l ; - elec_alpha=(Positive_int.of_int 0) ; - elec_beta=(Positive_int.of_int 0) } + elec_alpha=(Elec_alpha_number.of_int 1) ; + elec_beta=(Elec_beta_number.of_int 0) } |> Charge.to_int - ) - charge - |> Positive_int.of_int + ) - 1 - charge + |> Elec_number.of_int in let (na,nb) = Multiplicity.to_alpha_beta ne multiplicity in let result = { nuclei = l ; - elec_alpha = (Positive_int.of_int na) ; - elec_beta = (Positive_int.of_int nb) } + elec_alpha = na ; + elec_beta = nb } in if ((get_multiplicity result) <> multiplicity) then let msg = Printf.sprintf "With %d electrons multiplicity %d is impossible" - (Positive_int.to_int ne) + (Elec_number.to_int ne) (Multiplicity.to_int multiplicity) in raise (MultiplicityError msg); diff --git a/ocaml/Multiplicity.ml b/ocaml/Multiplicity.ml index a50d38ef..a66233a8 100644 --- a/ocaml/Multiplicity.ml +++ b/ocaml/Multiplicity.ml @@ -1,3 +1,4 @@ +open Core.Std;; open Qptypes ;; type t = Strictly_positive_int.t;; @@ -19,17 +20,16 @@ let to_string m = ;; let of_alpha_beta a b = - let a = Strictly_positive_int.to_int a - and b = Positive_int.to_int b + let a = Elec_alpha_number.to_int a + and b = Elec_beta_number.to_int b in assert (a >= b); of_int (1 + a - b) ;; let to_alpha_beta ne m = - let ne = Positive_int.to_int ne in + let ne = Elec_number.to_int ne in let nb = (ne-(to_int m)+1)/2 in let na = ne - nb in - assert (na >= nb) ; - (na,nb) + (Elec_alpha_number.of_int na, Elec_beta_number.of_int nb) ;; diff --git a/ocaml/Primitive.ml b/ocaml/Primitive.ml index 1f52b0d9..82a94fa4 100644 --- a/ocaml/Primitive.ml +++ b/ocaml/Primitive.ml @@ -3,13 +3,13 @@ open Core.Std;; type t = { sym : Symmetry.t ; - expo : Positive_float.t ; + expo : AO_expo.t ; } let to_string p = let { sym = s ; expo = e } = p in Printf.sprintf "(%s, %f)" (Symmetry.to_string s) - (Positive_float.to_float e) + (AO_expo.to_float e) ;; diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index c5512354..d35cb42b 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -48,9 +48,9 @@ let run ?o b c m xyz_file = Ezfio.set_file ezfio_file; (* Write Electrons *) - Ezfio.set_electrons_elec_alpha_num ( Positive_int.to_int + Ezfio.set_electrons_elec_alpha_num ( Elec_alpha_number.to_int molecule.Molecule.elec_alpha ) ; - Ezfio.set_electrons_elec_beta_num ( Positive_int.to_int + Ezfio.set_electrons_elec_beta_num ( Elec_beta_number.to_int molecule.Molecule.elec_beta ) ; (* Write Nuclei *) @@ -74,9 +74,9 @@ let run ?o b c m xyz_file = (* Write Basis set *) let basis = - let rec do_work (accu:(Atom.t*Atom_number.t) list) (n:int) = function + let rec do_work (accu:(Atom.t*Nucl_number.t) list) (n:int) = function | [] -> accu - | e::tail -> let new_accu = (e,(Atom_number.of_int n))::accu in + | e::tail -> let new_accu = (e,(Nucl_number.of_int n))::accu in do_work new_accu (n+1) tail in do_work [] 1 nuclei @@ -90,7 +90,7 @@ let run ?o b c m xyz_file = Ezfio.set_ao_basis_ao_num ao_num; Ezfio.set_ao_basis_ao_basis b; let ao_prim_num = List.map long_basis ~f:(fun (_,g,_) -> List.length g.Gto.lc) - and ao_nucl = List.map long_basis ~f:(fun (_,_,n) -> Atom_number.to_int n) + and ao_nucl = List.map long_basis ~f:(fun (_,_,n) -> Nucl_number.to_int n) and ao_power= let l = List.map long_basis ~f:(fun (x,_,_) -> x) in (List.map l ~f:(fun t -> Positive_int.to_int Symmetry.Xyz.(t.x)) )@ @@ -109,7 +109,7 @@ let run ?o b c m xyz_file = | `Coefs -> List.map gtos ~f:(fun x-> List.map x.Gto.lc ~f:(fun (_,coef) -> AO_coef.to_float coef) ) | `Expos -> List.map gtos ~f:(fun x-> - List.map x.Gto.lc ~f:(fun (prim,_) -> Positive_float.to_float + List.map x.Gto.lc ~f:(fun (prim,_) -> AO_expo.to_float prim.Primitive.expo) ) end in diff --git a/ocaml/qp_print.ml b/ocaml/qp_print.ml index 0053b441..6734b00a 100644 --- a/ocaml/qp_print.ml +++ b/ocaml/qp_print.ml @@ -55,9 +55,9 @@ let run_i ~action ezfio_filename = let nucl_charge = Ezfio.((get_nuclei_nucl_charge ()).data) |> Ezfio.flattened_ezfio_data |> Array.map ~f:(Float.to_int) and n_alpha = input.Input.Electrons.elec_alpha_num - |> Strictly_positive_int.to_int + |> Elec_alpha_number.to_int and n_beta = input.Input.Electrons.elec_beta_num - |> Positive_int.to_int + |> Elec_beta_number.to_int in Array.fold ~init:(-n_alpha-n_beta) ~f:(fun x y -> x+y) nucl_charge in diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index 8ab5b5cf..fa3bbdd5 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -36,13 +36,6 @@ let input_data = " * Non_empty_string : string assert (x <> \"\") ; -* Atom_number : int - assert (x > 0) ; - if (x > 1000) then - warning \"More than 1000 atoms\"; - if (Ezfio.has_nuclei_nucl_num ()) then - assert (x <= (Ezfio.get_nuclei_nucl_num ())); - * MO_number : int assert (x > 0) ; if (x > 1000) then @@ -60,7 +53,7 @@ let input_data = " * Nucl_number : int assert (x > 0) ; if (x > 1000) then - warning \"More than 1000 Atoms\"; + warning \"More than 1000 atoms\"; if (Ezfio.has_nuclei_nucl_num ()) then assert (x <= (Ezfio.get_nuclei_nucl_num ())); diff --git a/ocaml/test_basis.ml b/ocaml/test_basis.ml index 8fb18ffe..1f029bf6 100644 --- a/ocaml/test_basis.ml +++ b/ocaml/test_basis.ml @@ -17,8 +17,8 @@ let test_module () = let nuclei = molecule.Molecule.nuclei in let basis = - (Basis.read_element basis_channel (Atom_number.of_int 1) Element.F) @ - (Basis.read_element basis_channel (Atom_number.of_int 2) Element.F) + (Basis.read_element basis_channel (Nucl_number.of_int 1) Element.F) @ + (Basis.read_element basis_channel (Nucl_number.of_int 2) Element.F) in Long_basis.of_basis basis diff --git a/ocaml/test_gto.ml b/ocaml/test_gto.ml index a39de97e..3675f501 100644 --- a/ocaml/test_gto.ml +++ b/ocaml/test_gto.ml @@ -4,7 +4,7 @@ open Qptypes;; let test_prim () = let p = { Primitive.sym = Symmetry.P ; - Primitive.expo = Positive_float.of_float 0.15} in + Primitive.expo = AO_expo.of_float 0.15} in Primitive.to_string p |> print_string ;; @@ -23,14 +23,14 @@ let test_gto_1 () = let test_gto_2 () = let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pvdz" in ignore (input_line in_channel); - let basis = Basis.read in_channel (Atom_number.of_int 1) in - List.iter basis ~f:(fun (x,n)-> Printf.printf "%d:%s\n" (Atom_number.to_int n) (Gto.to_string x)) + let basis = Basis.read in_channel (Nucl_number.of_int 1) in + List.iter basis ~f:(fun (x,n)-> Printf.printf "%d:%s\n" (Nucl_number.to_int n) (Gto.to_string x)) ;; let test_gto () = let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pvdz" in - let basis = Basis.read_element in_channel (Atom_number.of_int 1) Element.C in - List.iter basis ~f:(fun (x,n)-> Printf.printf "%d:%s\n" (Atom_number.to_int n) (Gto.to_string x)) + let basis = Basis.read_element in_channel (Nucl_number.of_int 1) Element.C in + List.iter basis ~f:(fun (x,n)-> Printf.printf "%d:%s\n" (Nucl_number.to_int n) (Gto.to_string x)) ;; let test_module () = diff --git a/setup_environment.sh b/setup_environment.sh index 085cef6a..e462b317 100755 --- a/setup_environment.sh +++ b/setup_environment.sh @@ -41,6 +41,7 @@ then fi # Ocaml installation +# Check if m4 and curl are OK make -C ocaml Qptypes.ml if [[ $? -ne 0 ]] then