Added lots of mli files for better error messages

This commit is contained in:
Anthony Scemama 2014-10-26 17:29:11 +01:00
parent 6998c27b6e
commit 3fd80125e4
30 changed files with 330 additions and 96 deletions

View File

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

9
ocaml/Atom.mli Normal file
View File

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

View File

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

View File

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

View File

@ -8,9 +8,9 @@ Zero | One
*)
type bit =
| One
| Zero
type t =
| One
| Zero
with sexp
let to_string = function

10
ocaml/Bit.mli Normal file
View File

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

View File

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

32
ocaml/Bitlist.mli Normal file
View File

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

View File

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

View File

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

18
ocaml/Element.mli Normal file
View File

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

View File

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

30
ocaml/Excitation.mli Normal file
View File

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

16
ocaml/Gto.mli Normal file
View File

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

View File

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

View File

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

21
ocaml/MO_class.mli Normal file
View File

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

View File

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

38
ocaml/Molecule.mli Normal file
View File

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

19
ocaml/Multiplicity.mli Normal file
View File

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

17
ocaml/Point3d.mli Normal file
View File

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

View File

@ -1,3 +1,3 @@
true: package(core,sexplib.syntax)
true: package(core,sexplib.syntax,cryptokit)
true: thread

View File

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

View File

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

View File

@ -121,6 +121,8 @@ let input_data = "
* Elec_number : int
assert (x > 0) ;
* MD5 : string
assert ((String.length x) = 32);
"
;;

View File

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

View File

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

View File

@ -95,5 +95,5 @@ test_hf ();;
test_mo ();;
test_nucl ();
*)
test_bielec_intergals ();;
test_ao ();;

View File

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

View File

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