10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-25 22:52:15 +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 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"
;;

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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);

View File

@ -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)
;;

View File

@ -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)
;;

View File

@ -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

View File

@ -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

View File

@ -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 ()));

View File

@ -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

View File

@ -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 () =

View File

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