10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-18 11:15:28 +02:00

Added s-expressions (sexplib)

This commit is contained in:
Anthony Scemama 2014-10-25 21:24:21 +02:00
parent 1d5b072775
commit 0a9de3c23a
31 changed files with 144 additions and 67 deletions

View File

@ -6,7 +6,7 @@ type t =
{ element : Element.t ;
charge : Charge.t ;
coord : Point3d.t ;
}
} with sexp
(** Read xyz coordinates of the atom with unit u *)
let of_string u s =

View File

@ -1,7 +1,7 @@
open Core.Std;;
open Qptypes;;
type t = (Gto.t * Nucl_number.t) list;;
type t = (Gto.t * Nucl_number.t) list with sexp;;
(** Read all the basis functions of an element *)
let read in_channel at_number =

View File

@ -1,3 +1,4 @@
open Core.Std;;
(*
Type for bits
@ -10,6 +11,7 @@ Zero | One
type bit =
| One
| Zero
with sexp
let to_string = function
| Zero -> "0"

View File

@ -1,11 +1,12 @@
open Core.Std;;
type t = float
type t = float with sexp;;
let of_float x = x
let of_int i = Float.of_int i
let of_string s = Float.of_string s
let to_float x = x
let to_int x = Float.to_int x
let to_string x =

View File

@ -1,4 +1,4 @@
type t = float
type t = float with sexp
val to_float : t -> float
val to_int : t -> int

View File

@ -8,7 +8,7 @@ type t =
|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;;
let of_string x =
match (String.capitalize (String.lowercase x)) with

View File

@ -2,21 +2,21 @@ open Core.Std;;
open Qptypes;;
module Hole : sig
type t
type t with sexp
val to_mo_class : t -> MO_class.t
val of_mo_class : MO_class.t -> t
end = struct
type t = MO_class.t
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
type t with sexp
val to_mo_class : t -> MO_class.t
val of_mo_class : MO_class.t -> t
end = struct
type t = MO_class.t
type t = MO_class.t with sexp
let of_mo_class x = x
let to_mo_class x = x
end
@ -24,7 +24,7 @@ end
type t =
| Single of Hole.t*Particle.t
| Double of Hole.t*Particle.t*Hole.t*Particle.t
;;
with sexp;;
let failwith s = raise (Failure s)
;;

View File

@ -7,7 +7,7 @@ exception End_Of_Basis
type t =
{ sym : Symmetry.t ;
lc : ((Primitive.t * AO_coef.t) list)
}
} with sexp
;;
let of_prim_coef_list pc =
@ -62,6 +62,7 @@ let read_one in_channel =
| _ -> raise (GTO_Read_Failure line_buffer)
end
in read_lines [] n
|> List.rev
|> of_prim_coef_list
;;
@ -70,6 +71,6 @@ let read_one in_channel =
let to_string { sym = sym ; lc = lc } =
let f (p,c) = Printf.sprintf "( %s, %f )" (Primitive.to_string p) (AO_coef.to_float c)
in
Printf.sprintf "[ %s : %s ]" (Symmetry.to_string sym)
Printf.sprintf "( %s, %s )" (Symmetry.to_string sym)
(String.concat (List.map ~f:f lc) ~sep:", ")
;;

View File

@ -12,10 +12,11 @@ module Ao_basis : sig
ao_power : Symmetry.Xyz.t array;
ao_coef : AO_coef.t array;
ao_expo : AO_expo.t array;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
val debug : t -> string
end = struct
type t =
{ ao_basis : string ;
@ -26,7 +27,7 @@ end = struct
ao_power : Symmetry.Xyz.t array;
ao_coef : AO_coef.t array;
ao_expo : AO_expo.t array;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "ao_basis";;
@ -104,16 +105,56 @@ end = struct
;;
let to_string 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 ->
let s = Symmetry.Xyz.to_symmetry b.ao_power.(i) in
let ao_prim_num = AO_prim_number.to_int b.ao_prim_num.(i) in
let prims = List.init ao_prim_num ~f:(fun j ->
let prim = { Primitive.sym = s ;
Primitive.expo = b.ao_expo.(ao_num*j+i)
}
in
let coef = b.ao_coef.(ao_num*j+i) in
(prim,coef)
) in
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
Printf.sprintf "
ao_basis = \"%s\"
ao_num = %s
ao_prim_num = %s
ao_prim_num_max = %s
ao_nucl = %s
ao_power = %s
ao_coef = %s
ao_expo = %s
"
# AO Basis
# ========
%s" (Long_basis.to_string long_basis)
;;
let debug b =
Printf.sprintf "
# AO Basis
# ========
#
# ao_basis = %s
# ao_num = %s
# ao_prim_num = %s
# ao_prim_num_max = %s
# ao_nucl = %s
# ao_power = %s
# ao_coef = %s
# ao_expo = %s
#"
b.ao_basis
(AO_number.to_string b.ao_num)
(b.ao_prim_num |> Array.to_list |> List.map
@ -128,6 +169,6 @@ ao_expo = %s
(b.ao_expo |> Array.to_list |> List.map ~f:AO_expo.to_string
|> String.concat ~sep:", ")
;;
end

View File

@ -11,7 +11,7 @@ module Bielec_integrals : sig
threshold_ao : Threshold.t;
threshold_mo : Threshold.t;
direct : bool;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -24,7 +24,7 @@ end = struct
threshold_ao : Threshold.t;
threshold_mo : Threshold.t;
direct : bool;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "bielec_integrals";;

View File

@ -8,7 +8,7 @@ module Bitmasks : sig
bit_kind : Bit_kind.t;
n_mask_gen : Bitmask_number.t;
generators : int64 array;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -18,7 +18,7 @@ end = struct
bit_kind : Bit_kind.t;
n_mask_gen : Bitmask_number.t;
generators : int64 array;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "bitmasks";;

View File

@ -10,7 +10,7 @@ module Cis_dressed : sig
mp2_dressing : bool;
standard_doubles : bool;
en_2_2 : bool;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -22,7 +22,7 @@ end = struct
mp2_dressing : bool;
standard_doubles : bool;
en_2_2 : bool;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "cis_dressed";;

View File

@ -7,7 +7,7 @@ module Cisd_sc2 : sig
{ n_det_max_cisd_sc2 : Det_number.t;
pt2_max : PT2_energy.t;
do_pt2_end : bool;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -16,7 +16,7 @@ end = struct
{ n_det_max_cisd_sc2 : Det_number.t;
pt2_max : PT2_energy.t;
do_pt2_end : bool;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "cisd_sc2_selected";;

View File

@ -18,7 +18,7 @@ module Determinants : sig
s2_eig : bool;
psi_coef : Det_coef.t array;
psi_det : Determinant.t array;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -38,7 +38,7 @@ end = struct
s2_eig : bool;
psi_coef : Det_coef.t array;
psi_det : Determinant.t array;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "determinants";;

View File

@ -7,7 +7,7 @@ module Electrons : sig
{ elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t;
elec_num : Elec_number.t;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -16,7 +16,7 @@ end = struct
{ elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t;
elec_num : Elec_number.t;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "electrons";;

View File

@ -7,7 +7,7 @@ module Full_ci : sig
{ n_det_max_fci : Det_number.t;
pt2_max : PT2_energy.t;
do_pt2_end : bool;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -16,7 +16,7 @@ end = struct
{ n_det_max_fci : Det_number.t;
pt2_max : PT2_energy.t;
do_pt2_end : bool;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "full_ci";;

View File

@ -6,7 +6,7 @@ module Hartree_fock : sig
type t =
{ n_it_scf_max : Strictly_positive_int.t;
thresh_scf : Threshold.t;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -14,7 +14,7 @@ end = struct
type t =
{ n_it_scf_max : Strictly_positive_int.t;
thresh_scf : Threshold.t;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "hartree_fock";;

View File

@ -8,7 +8,7 @@ module Mo_basis : sig
mo_label : Non_empty_string.t;
mo_occ : Positive_float.t array;
mo_coef : MO_coef.t array;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -18,7 +18,7 @@ end = struct
mo_label : Non_empty_string.t;
mo_occ : Positive_float.t array;
mo_coef : MO_coef.t array;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "mo_basis";;

View File

@ -8,7 +8,7 @@ module Nuclei : sig
nucl_label : Element.t array;
nucl_charge : Charge.t array;
nucl_coord : Point3d.t array;
}
} with sexp
;;
val read : unit -> t
val to_string : t -> string
@ -18,7 +18,7 @@ end = struct
nucl_label : Element.t array;
nucl_charge : Charge.t array;
nucl_coord : Point3d.t array;
}
} with sexp
;;
let get_default = Qpackage.get_ezfio_default "nuclei";;

View File

@ -1,7 +1,7 @@
open Core.Std;;
open Qptypes;;
type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t ) list;;
type t = (Symmetry.Xyz.t * Gto.t * Nucl_number.t ) list with sexp
let of_basis b =
let rec do_work accu = function
@ -21,9 +21,15 @@ let of_basis b =
let to_string b =
List.map ~f:(fun (x,y,z) ->
(Int.to_string (Nucl_number.to_int z))^":"^
(Symmetry.Xyz.to_string x)^" "^(Gto.to_string y)
) b
|> String.concat ~sep:"\n"
Sexp.to_string (sexp_of_t b)
;;
(*
let middle = List.map ~f:(fun (x,y,z) ->
"( "^((Int.to_string (Nucl_number.to_int z)))^", "^
(Symmetry.Xyz.to_string x)^", "^(Gto.to_string y)
^" )"
) b
|> String.concat ~sep:",\n"
in "("^middle^")"
;;
*)

View File

@ -7,7 +7,7 @@ type t =
| Active of MO_number.t list
| Virtual of MO_number.t list
| Deleted of MO_number.t list
;;
with sexp
let to_string x =

View File

@ -13,7 +13,7 @@ endif
LIBS=
PKGS=
OCAMLCFLAGS=-g
OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags -g
OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags -g
MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml
MLIFILES=$(wildcard *.mli)
ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml))

View File

@ -7,7 +7,7 @@ type t = {
nuclei : Atom.t list ;
elec_alpha : Elec_alpha_number.t ;
elec_beta : Elec_beta_number.t ;
}
} with sexp
let get_charge { nuclei ; elec_alpha ; elec_beta } =
let result = (Elec_alpha_number.to_int elec_alpha) +

View File

@ -1,7 +1,8 @@
open Core.Std;;
open Qptypes ;;
type t = Strictly_positive_int.t;;
type t = Strictly_positive_int.t with sexp
let of_int = Strictly_positive_int.of_int ;;
let to_int = Strictly_positive_int.to_int ;;

View File

@ -4,7 +4,7 @@ type t = {
x : float ;
y : float ;
z : float ;
}
} with sexp
(** Read x y z coordinates in string s with units u *)
let of_string u s =

View File

@ -4,7 +4,7 @@ open Core.Std;;
type t =
{ sym : Symmetry.t ;
expo : AO_expo.t ;
}
} with sexp
let to_string p =
let { sym = s ; expo = e } = p in

View File

@ -12,7 +12,7 @@ open Core.Std;;
*)
type t = int list ;;
type t = int list with sexp
let expand_range r =
match String.lsplit2 ~on:'-' r with

View File

@ -1,7 +1,7 @@
open Qptypes;;
open Core.Std;;
type t = S|P|D|F|G|H|I|J|K|L
type t = S|P|D|F|G|H|I|J|K|L with sexp
let to_string = function
| S -> "S"
@ -53,6 +53,23 @@ let to_l = function
| J -> Positive_int.of_int 7
| K -> Positive_int.of_int 8
| L -> Positive_int.of_int 9
;;
let of_l i =
let i = Positive_int.to_int i in
match i with
| 0 -> S
| 1 -> P
| 2 -> D
| 3 -> F
| 4 -> G
| 5 -> H
| 6 -> I
| 7 -> J
| 8 -> K
| 9 -> L
| x -> raise (Failure ("Symmetry should be S|P|D|F|G|H|I|J|K|L"))
;;
type st = t
;;
@ -60,15 +77,16 @@ type st = t
module Xyz : sig
type t = { x: Positive_int.t ;
y: Positive_int.t ;
z: Positive_int.t }
z: Positive_int.t } with sexp
val of_string : string -> t
val to_string : t -> string
val get_l : t -> Positive_int.t
val of_symmetry : st -> t list
val to_symmetry : t -> st
end = struct
type t = { x: Positive_int.t ;
y: Positive_int.t ;
z: Positive_int.t }
z: Positive_int.t } with sexp
type state_type = Null | X | Y | Z
(** Builds an XYZ triplet from a string.
@ -127,7 +145,9 @@ end = struct
| 1 -> "z"
| i -> Printf.sprintf "z%d" i
in
x^y^z
let result = (x^y^z) in
if (result = "") then "s"
else result
;;
(** Returns the l quantum number from a XYZ powers triplet *)
@ -169,5 +189,7 @@ end = struct
z=Positive_int.of_int 0 }
;;
let to_symmetry sym = of_l (get_l sym)
;;
end

View File

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

View File

@ -126,12 +126,12 @@ let input_data = "
let untouched = "
module Determinant : sig
type t
type t with sexp
val to_int64_array : t -> int64 array
val of_int64_array : int64 array -> t
val to_string : t -> string
end = struct
type t = int64 array
type t = int64 array with sexp
let to_int64_array x = x
let of_int64_array x =
if (Ezfio.has_determinants_n_int ()) then
@ -149,12 +149,12 @@ end
let template = format_of_string "
module %s : sig
type t
type t with sexp
val to_%s : t -> %s
val of_%s : %s -> t
val to_string : t -> string
end = struct
type t = %s
type t = %s with sexp
let to_%s x = x
let of_%s x = ( %s x )
let to_string x = %s.to_string x

View File

@ -2,6 +2,7 @@ let test_ao () =
Ezfio.set_file "F2.ezfio" ;
let b = Input.Ao_basis.read ()
in
print_endline (Input.Ao_basis.debug b);
print_endline (Input.Ao_basis.to_string b);
;;
@ -84,5 +85,7 @@ test_cis ();
test_dets ();
test_cisd_sc2 ();
test_mo ();;
*)
test_nucl ();
*)
test_ao ();;