10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-29 16:34:50 +02:00

Corrected bugs in ocaml

This commit is contained in:
Anthony Scemama 2014-10-23 14:42:14 +02:00
parent 9100309e12
commit 6f745a6e25
14 changed files with 49 additions and 56 deletions

View File

@ -1,7 +1,7 @@
open Core.Std;; open Core.Std;;
open Qptypes;; 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 *) (** Read all the basis functions of an element *)
let read in_channel at_number = let read in_channel at_number =
@ -37,7 +37,7 @@ let read_element in_channel at_number element =
let to_string b = let to_string b =
List.map ~f:(fun (g,n) -> 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 (Int.to_string n)^":"^(Gto.to_string g)) b
|> String.concat ~sep:"\n" |> String.concat ~sep:"\n"
;; ;;

View File

@ -1,17 +1,17 @@
open Qptypes;; 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 (** Read all the basis functions of an element and set the number of the
* atom *) * 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 *) (** Find an element in the basis set file *)
val find : in_channel -> Element.t -> Element.t val find : in_channel -> Element.t -> Element.t
(** Read the basis of an element from the file *) (** Read the basis of an element from the file *)
val read_element : 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 *) (** 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

View File

@ -53,7 +53,7 @@ let read_one in_channel =
| [ j ; expo ; coef ] -> | [ j ; expo ; coef ] ->
begin begin
let p = { Primitive.sym = sym ; let p = { Primitive.sym = sym ;
Primitive.expo = Positive_float.of_float Primitive.expo = AO_expo.of_float
(Float.of_string expo) (Float.of_string expo)
} }
and c = AO_coef.of_float (Float.of_string coef) in and c = AO_coef.of_float (Float.of_string coef) in

View File

@ -1,7 +1,7 @@
open Core.Std;; open Core.Std;;
open Qptypes;; 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 of_basis b =
let rec do_work accu = function let rec do_work accu = function
@ -22,7 +22,7 @@ let of_basis b =
let to_string b = let to_string b =
List.map ~f:(fun (x,y,z) -> 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) (Symmetry.Xyz.to_string x)^" "^(Gto.to_string y)
) b ) b
|> String.concat ~sep:"\n" |> String.concat ~sep:"\n"

View File

@ -5,12 +5,12 @@ open Qptypes;;
* all the D orbitals are converted to xx, xy, xz, yy, yx * all the D orbitals are converted to xx, xy, xz, yy, yx
* etc * 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 *) (** Transform a basis to a long basis *)
val of_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 *) (** Convert the basis into its string representation *)
val to_string : val to_string :
(Symmetry.Xyz.t * Gto.t * Atom_number.t) list -> string (Symmetry.Xyz.t * Gto.t * Nucl_number.t) list -> string

View File

@ -5,12 +5,13 @@ exception MultiplicityError of string;;
type t = { type t = {
nuclei : Atom.t list ; nuclei : Atom.t list ;
elec_alpha : Positive_int.t ; elec_alpha : Elec_alpha_number.t ;
elec_beta : Positive_int.t ; elec_beta : Elec_beta_number.t ;
} }
let get_charge { nuclei ; elec_alpha ; elec_beta } = 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 let rec nucl_charge = function
| a::rest -> (Charge.to_float a.Atom.charge) +. nucl_charge rest | a::rest -> (Charge.to_float a.Atom.charge) +. nucl_charge rest
| [] -> 0. | [] -> 0.
@ -19,14 +20,12 @@ let get_charge { nuclei ; elec_alpha ; elec_beta } =
;; ;;
let get_multiplicity m = let get_multiplicity m =
let elec_alpha = m.elec_alpha let elec_alpha = m.elec_alpha in
|> Positive_int.to_int
|> Strictly_positive_int.of_int in
Multiplicity.of_alpha_beta elec_alpha m.elec_beta Multiplicity.of_alpha_beta elec_alpha m.elec_beta
;; ;;
let get_nucl_num m = 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 = let name m =
@ -88,22 +87,22 @@ let of_xyz_string
in in
let ne = ( get_charge { let ne = ( get_charge {
nuclei=l ; nuclei=l ;
elec_alpha=(Positive_int.of_int 0) ; elec_alpha=(Elec_alpha_number.of_int 1) ;
elec_beta=(Positive_int.of_int 0) } elec_beta=(Elec_beta_number.of_int 0) }
|> Charge.to_int |> Charge.to_int
) - charge ) - 1 - charge
|> Positive_int.of_int |> Elec_number.of_int
in in
let (na,nb) = Multiplicity.to_alpha_beta ne multiplicity in let (na,nb) = Multiplicity.to_alpha_beta ne multiplicity in
let result = let result =
{ nuclei = l ; { nuclei = l ;
elec_alpha = (Positive_int.of_int na) ; elec_alpha = na ;
elec_beta = (Positive_int.of_int nb) } elec_beta = nb }
in in
if ((get_multiplicity result) <> multiplicity) then if ((get_multiplicity result) <> multiplicity) then
let msg = Printf.sprintf let msg = Printf.sprintf
"With %d electrons multiplicity %d is impossible" "With %d electrons multiplicity %d is impossible"
(Positive_int.to_int ne) (Elec_number.to_int ne)
(Multiplicity.to_int multiplicity) (Multiplicity.to_int multiplicity)
in in
raise (MultiplicityError msg); raise (MultiplicityError msg);

View File

@ -1,3 +1,4 @@
open Core.Std;;
open Qptypes ;; open Qptypes ;;
type t = Strictly_positive_int.t;; type t = Strictly_positive_int.t;;
@ -19,17 +20,16 @@ let to_string m =
;; ;;
let of_alpha_beta a b = let of_alpha_beta a b =
let a = Strictly_positive_int.to_int a let a = Elec_alpha_number.to_int a
and b = Positive_int.to_int b and b = Elec_beta_number.to_int b
in in
assert (a >= b); assert (a >= b);
of_int (1 + a - b) of_int (1 + a - b)
;; ;;
let to_alpha_beta ne m = 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 nb = (ne-(to_int m)+1)/2 in
let na = ne - nb in let na = ne - nb in
assert (na >= nb) ; (Elec_alpha_number.of_int na, Elec_beta_number.of_int nb)
(na,nb)
;; ;;

View File

@ -3,13 +3,13 @@ open Core.Std;;
type t = type t =
{ sym : Symmetry.t ; { sym : Symmetry.t ;
expo : Positive_float.t ; expo : AO_expo.t ;
} }
let to_string p = let to_string p =
let { sym = s ; expo = e } = p in let { sym = s ; expo = e } = p in
Printf.sprintf "(%s, %f)" Printf.sprintf "(%s, %f)"
(Symmetry.to_string s) (Symmetry.to_string s)
(Positive_float.to_float e) (AO_expo.to_float e)
;; ;;

View File

@ -48,9 +48,9 @@ let run ?o b c m xyz_file =
Ezfio.set_file ezfio_file; Ezfio.set_file ezfio_file;
(* Write Electrons *) (* 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 ) ; 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 ) ; molecule.Molecule.elec_beta ) ;
(* Write Nuclei *) (* Write Nuclei *)
@ -74,9 +74,9 @@ let run ?o b c m xyz_file =
(* Write Basis set *) (* Write Basis set *)
let basis = 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 | [] -> 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 do_work new_accu (n+1) tail
in in
do_work [] 1 nuclei 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_num ao_num;
Ezfio.set_ao_basis_ao_basis b; Ezfio.set_ao_basis_ao_basis b;
let ao_prim_num = List.map long_basis ~f:(fun (_,g,_) -> List.length g.Gto.lc) 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= and ao_power=
let l = List.map long_basis ~f:(fun (x,_,_) -> x) in 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)) )@ (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-> | `Coefs -> List.map gtos ~f:(fun x->
List.map x.Gto.lc ~f:(fun (_,coef) -> AO_coef.to_float coef) ) List.map x.Gto.lc ~f:(fun (_,coef) -> AO_coef.to_float coef) )
| `Expos -> List.map gtos ~f:(fun x-> | `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) ) prim.Primitive.expo) )
end end
in in

View File

@ -55,9 +55,9 @@ let run_i ~action ezfio_filename =
let nucl_charge = Ezfio.((get_nuclei_nucl_charge ()).data) let nucl_charge = Ezfio.((get_nuclei_nucl_charge ()).data)
|> Ezfio.flattened_ezfio_data |> Array.map ~f:(Float.to_int) |> Ezfio.flattened_ezfio_data |> Array.map ~f:(Float.to_int)
and n_alpha = input.Input.Electrons.elec_alpha_num 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 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 Array.fold ~init:(-n_alpha-n_beta) ~f:(fun x y -> x+y) nucl_charge
in in

View File

@ -36,13 +36,6 @@ let input_data = "
* Non_empty_string : string * Non_empty_string : string
assert (x <> \"\") ; 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 * MO_number : int
assert (x > 0) ; assert (x > 0) ;
if (x > 1000) then if (x > 1000) then
@ -60,7 +53,7 @@ let input_data = "
* Nucl_number : int * Nucl_number : int
assert (x > 0) ; assert (x > 0) ;
if (x > 1000) then if (x > 1000) then
warning \"More than 1000 Atoms\"; warning \"More than 1000 atoms\";
if (Ezfio.has_nuclei_nucl_num ()) then if (Ezfio.has_nuclei_nucl_num ()) then
assert (x <= (Ezfio.get_nuclei_nucl_num ())); assert (x <= (Ezfio.get_nuclei_nucl_num ()));

View File

@ -17,8 +17,8 @@ let test_module () =
let nuclei = molecule.Molecule.nuclei in let nuclei = molecule.Molecule.nuclei in
let basis = let basis =
(Basis.read_element basis_channel (Atom_number.of_int 1) Element.F) @ (Basis.read_element basis_channel (Nucl_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 2) Element.F)
in in
Long_basis.of_basis basis Long_basis.of_basis basis

View File

@ -4,7 +4,7 @@ open Qptypes;;
let test_prim () = let test_prim () =
let p = let p =
{ Primitive.sym = Symmetry.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 Primitive.to_string p
|> print_string |> print_string
;; ;;
@ -23,14 +23,14 @@ let test_gto_1 () =
let test_gto_2 () = let test_gto_2 () =
let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pvdz" in let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pvdz" in
ignore (input_line in_channel); ignore (input_line in_channel);
let basis = Basis.read in_channel (Atom_number.of_int 1) in let basis = Basis.read in_channel (Nucl_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)) 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 test_gto () =
let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pvdz" in 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 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" (Atom_number.to_int n) (Gto.to_string x)) List.iter basis ~f:(fun (x,n)-> Printf.printf "%d:%s\n" (Nucl_number.to_int n) (Gto.to_string x))
;; ;;
let test_module () = let test_module () =

View File

@ -41,6 +41,7 @@ then
fi fi
# Ocaml installation # Ocaml installation
# Check if m4 and curl are OK
make -C ocaml Qptypes.ml make -C ocaml Qptypes.ml
if [[ $? -ne 0 ]] if [[ $? -ne 0 ]]
then then