Removed core

This commit is contained in:
Anthony Scemama 2019-03-13 15:49:57 +01:00
parent a145334269
commit 09eab3db06
20 changed files with 247 additions and 459 deletions

View File

@ -291,7 +291,7 @@ OCaml
.. code:: bash .. code:: bash
opam install ocamlbuild cryptokit zmq core sexplib ppx_sexp_conv ppx_deriving getopt opam install ocamlbuild cryptokit zmq sexplib ppx_sexp_conv ppx_deriving getopt
EZFIO EZFIO

2
configure vendored
View File

@ -60,7 +60,7 @@ function execute () {
} }
PACKAGES="" PACKAGES=""
OCAML_PACKAGES="ocamlbuild cryptokit zmq core.v0.11.3 sexplib ppx_sexp_conv ppx_deriving getopt" OCAML_PACKAGES="ocamlbuild cryptokit zmq sexplib ppx_sexp_conv ppx_deriving getopt"
while true ; do while true ; do
case "$1" in case "$1" in

View File

@ -80,14 +80,14 @@ let read_until_found f tries =
begin begin
try try
Some (read_mos x f) Some (read_mos x f)
with Caml.Not_found -> with Not_found ->
None None
end end
) None tries ) None tries
in in
match result with match result with
| Some mos -> mos | Some mos -> mos
| None -> raise Caml.Not_found | None -> raise Not_found
let read_natural_mos f = let read_natural_mos f =
let tries = [ let tries = [
@ -431,7 +431,7 @@ let create_cas_input ?(vecfile="") ~guess ~nstate s n_e n_a =
in in
try try
string_of_guess (Natural (norb, vecfile)) string_of_guess (Natural (norb, vecfile))
with Caml.Not_found -> with Not_found ->
string_of_guess (Canonical (norb, vecfile)) string_of_guess (Canonical (norb, vecfile))
end end
; ;

View File

@ -1,6 +1,5 @@
open Qputils;; open Qputils;;
open Qptypes;; open Qptypes;;
open Core;;
include Input_ao_basis;; include Input_ao_basis;;
include Input_bitmasks;; include Input_bitmasks;;

View File

@ -1,6 +1,6 @@
open Qptypes;; open Qptypes;;
open Qputils;; open Qputils;;
open Core;; open Sexplib.Std;;
module Ao_basis : sig module Ao_basis : sig
type t = type t =
@ -52,13 +52,13 @@ end = struct
let read_ao_prim_num () = let read_ao_prim_num () =
Ezfio.get_ao_basis_ao_prim_num () Ezfio.get_ao_basis_ao_prim_num ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:AO_prim_number.of_int |> Array.map AO_prim_number.of_int
;; ;;
let read_ao_prim_num_max () = let read_ao_prim_num_max () =
Ezfio.get_ao_basis_ao_prim_num () Ezfio.get_ao_basis_ao_prim_num ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.fold ~f:(fun x y -> if x>y then x else y) ~init:0 |> Array.fold_left (fun x y -> if x>y then x else y) 0
|> AO_prim_number.of_int |> AO_prim_number.of_int
;; ;;
@ -66,42 +66,42 @@ end = struct
let nmax = Nucl_number.get_max () in let nmax = Nucl_number.get_max () in
Ezfio.get_ao_basis_ao_nucl () Ezfio.get_ao_basis_ao_nucl ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:(fun x-> Nucl_number.of_int ~max:nmax x) |> Array.map (fun x-> Nucl_number.of_int ~max:nmax x)
;; ;;
let read_ao_power () = let read_ao_power () =
let x = Ezfio.get_ao_basis_ao_power () in let x = Ezfio.get_ao_basis_ao_power () in
let dim = x.Ezfio.dim.(0) in let dim = x.Ezfio.dim.(0) in
let data = Ezfio.flattened_ezfio x in let data = Ezfio.flattened_ezfio x in
let result = Array.init dim ~f:(fun x -> "") in let result = Array.init dim (fun x -> "") in
for i=1 to dim for i=1 to dim
do do
if (data.(i-1) > 0) then if (data.(i-1) > 0) then
result.(i-1) <- result.(i-1)^"x"^(Int.to_string data.(i-1)); result.(i-1) <- result.(i-1)^"x"^(string_of_int data.(i-1));
if (data.(dim+i-1) > 0) then if (data.(dim+i-1) > 0) then
result.(i-1) <- result.(i-1)^"y"^(Int.to_string data.(dim+i-1)); result.(i-1) <- result.(i-1)^"y"^(string_of_int data.(dim+i-1));
if (data.(2*dim+i-1) > 0) then if (data.(2*dim+i-1) > 0) then
result.(i-1) <- result.(i-1)^"z"^(Int.to_string data.(2*dim+i-1)); result.(i-1) <- result.(i-1)^"z"^(string_of_int data.(2*dim+i-1));
done; done;
Array.map ~f:Symmetry.Xyz.of_string result Array.map Symmetry.Xyz.of_string result
;; ;;
let read_ao_coef () = let read_ao_coef () =
Ezfio.get_ao_basis_ao_coef () Ezfio.get_ao_basis_ao_coef ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:AO_coef.of_float |> Array.map AO_coef.of_float
;; ;;
let read_ao_expo () = let read_ao_expo () =
Ezfio.get_ao_basis_ao_expo () Ezfio.get_ao_basis_ao_expo ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:AO_expo.of_float |> Array.map AO_expo.of_float
;; ;;
let read_ao_cartesian () = let read_ao_cartesian () =
if not (Ezfio.has_ao_basis_ao_cartesian ()) then if not (Ezfio.has_ao_basis_ao_cartesian ()) then
get_default "ao_cartesian" get_default "ao_cartesian"
|> Bool.of_string |> bool_of_string
|> Ezfio.set_ao_basis_ao_cartesian |> Ezfio.set_ao_basis_ao_cartesian
; ;
Ezfio.get_ao_basis_ao_cartesian () Ezfio.get_ao_basis_ao_cartesian ()
@ -110,10 +110,10 @@ end = struct
let to_long_basis b = let to_long_basis b =
let ao_num = AO_number.to_int b.ao_num in let ao_num = AO_number.to_int b.ao_num in
let gto_array = Array.init (AO_number.to_int b.ao_num) let gto_array = Array.init (AO_number.to_int b.ao_num)
~f:(fun i -> (fun i ->
let s = Symmetry.Xyz.to_symmetry b.ao_power.(i) in 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 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 prims = List.init ao_prim_num (fun j ->
let prim = { GaussianPrimitive.sym = s ; let prim = { GaussianPrimitive.sym = s ;
GaussianPrimitive.expo = b.ao_expo.(ao_num*j+i) GaussianPrimitive.expo = b.ao_expo.(ao_num*j+i)
} }
@ -178,14 +178,14 @@ end = struct
in in
let ao_prim_num = let ao_prim_num =
Array.to_list ao_prim_num Array.to_list ao_prim_num
|> List.map ~f:AO_prim_number.to_int |> List.map AO_prim_number.to_int
in in
Ezfio.set_ao_basis_ao_prim_num (Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_prim_num (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| ao_num |] ~data:ao_prim_num) ; ~rank:1 ~dim:[| ao_num |] ~data:ao_prim_num) ;
let ao_nucl = let ao_nucl =
Array.to_list ao_nucl Array.to_list ao_nucl
|> List.map ~f:Nucl_number.to_int |> List.map Nucl_number.to_int
in in
Ezfio.set_ao_basis_ao_nucl(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_nucl(Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| ao_num |] ~data:ao_nucl) ; ~rank:1 ~dim:[| ao_num |] ~data:ao_nucl) ;
@ -193,9 +193,9 @@ end = struct
let ao_power = let ao_power =
let l = Array.to_list ao_power in let l = Array.to_list ao_power in
List.concat [ List.concat [
(List.map ~f:(fun a -> Positive_int.to_int a.Symmetry.Xyz.x) l) ; (List.map (fun a -> Positive_int.to_int a.Symmetry.Xyz.x) l) ;
(List.map ~f:(fun a -> Positive_int.to_int a.Symmetry.Xyz.y) l) ; (List.map (fun a -> Positive_int.to_int a.Symmetry.Xyz.y) l) ;
(List.map ~f:(fun a -> Positive_int.to_int a.Symmetry.Xyz.z) l) ] (List.map (fun a -> Positive_int.to_int a.Symmetry.Xyz.z) l) ]
in in
Ezfio.set_ao_basis_ao_power(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_power(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; 3 |] ~data:ao_power) ; ~rank:2 ~dim:[| ao_num ; 3 |] ~data:ao_power) ;
@ -204,14 +204,14 @@ end = struct
let ao_coef = let ao_coef =
Array.to_list ao_coef Array.to_list ao_coef
|> List.map ~f:AO_coef.to_float |> List.map AO_coef.to_float
in in
Ezfio.set_ao_basis_ao_coef(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_coef(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_coef) ; ~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_coef) ;
let ao_expo = let ao_expo =
Array.to_list ao_expo Array.to_list ao_expo
|> List.map ~f:AO_expo.to_float |> List.map AO_expo.to_float
in in
Ezfio.set_ao_basis_ao_expo(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_expo(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_expo) ; ~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_expo) ;
@ -271,58 +271,56 @@ end = struct
| Some (s', g', n') -> | Some (s', g', n') ->
if s <> s' || n <> n' then find2 (s,g,n) a (i+1) if s <> s' || n <> n' then find2 (s,g,n) a (i+1)
else else
let lc = List.map ~f:(fun (prim, _) -> prim) g.Gto.lc let lc = List.map (fun (prim, _) -> prim) g.Gto.lc
and lc' = List.map ~f:(fun (prim, _) -> prim) g'.Gto.lc and lc' = List.map (fun (prim, _) -> prim) g'.Gto.lc
in in
if lc <> lc' then find2 (s,g,n) a (i+1) else (a.(i) <- None ; i) if lc <> lc' then find2 (s,g,n) a (i+1) else (a.(i) <- None ; i)
in in
find x a 0 find x a 0
in in
let search_array = Array.map ~f:(fun i -> Some i) unordered_basis in let search_array = Array.map (fun i -> Some i) unordered_basis in
Array.map ~f:(fun x -> find x search_array) ordered_basis Array.map (fun x -> find x search_array) ordered_basis
;; ;;
let of_long_basis long_basis name ao_cartesian = let of_long_basis long_basis name ao_cartesian =
let ao_num = List.length long_basis |> AO_number.of_int in let ao_num = List.length long_basis |> AO_number.of_int in
let ao_prim_num = let ao_prim_num =
List.map long_basis ~f:(fun (_,g,_) -> List.length g.Gto.lc List.map (fun (_,g,_) -> List.length g.Gto.lc
|> AO_prim_number.of_int ) |> AO_prim_number.of_int ) long_basis
|> Array.of_list |> Array.of_list
and ao_nucl = and ao_nucl =
List.map long_basis ~f:(fun (_,_,n) -> n) List.map (fun (_,_,n) -> n) long_basis
|> Array.of_list |> Array.of_list
and ao_power = and ao_power =
List.map ~f:(fun (x,_,_) -> x) long_basis List.map (fun (x,_,_) -> x) long_basis
|> Array.of_list |> Array.of_list
in in
let ao_prim_num_max = Array.fold ~init:0 ~f:(fun s x -> let ao_prim_num_max = Array.fold_left (fun s x ->
if AO_prim_number.to_int x > s then AO_prim_number.to_int x else s) if AO_prim_number.to_int x > s then AO_prim_number.to_int x else s) 0
ao_prim_num ao_prim_num
|> AO_prim_number.of_int |> AO_prim_number.of_int
in in
let gtos = let gtos =
List.map long_basis ~f:(fun (_,x,_) -> x) List.map (fun (_,x,_) -> x) long_basis
in in
let create_expo_coef ec = let create_expo_coef ec =
let coefs = let coefs =
begin match ec with begin match ec with
| `Coefs -> List.map gtos ~f:(fun x-> | `Coefs -> List.map (fun x->
List.map x.Gto.lc ~f:(fun (_,coef) -> AO_coef.to_float coef) ) List.map (fun (_,coef) -> AO_coef.to_float coef) x.Gto.lc ) gtos
| `Expos -> List.map gtos ~f:(fun x-> | `Expos -> List.map (fun x->
List.map x.Gto.lc ~f:(fun (prim,_) -> AO_expo.to_float List.map (fun (prim,_) -> AO_expo.to_float
prim.GaussianPrimitive.expo) ) prim.GaussianPrimitive.expo) x.Gto.lc ) gtos
end end
in in
let rec get_n n accu = function let rec get_n n accu = function
| [] -> List.rev accu | [] -> List.rev accu
| h::tail -> | h::tail ->
let y = let y =
begin match List.nth h n with try List.nth h n
| Some x -> x with _ -> 0.
| None -> 0.
end
in in
get_n n (y::accu) tail get_n n (y::accu) tail
in in
@ -335,10 +333,10 @@ end = struct
let ao_coef = create_expo_coef `Coefs let ao_coef = create_expo_coef `Coefs
|> Array.of_list |> Array.of_list
|> Array.map ~f:AO_coef.of_float |> Array.map AO_coef.of_float
and ao_expo = create_expo_coef `Expos and ao_expo = create_expo_coef `Expos
|> Array.of_list |> Array.of_list
|> Array.map ~f:AO_expo.of_float |> Array.map AO_expo.of_float
in in
{ ao_basis = name ; { ao_basis = name ;
ao_num ; ao_prim_num ; ao_prim_num_max ; ao_nucl ; ao_num ; ao_prim_num ; ao_prim_num_max ; ao_nucl ;
@ -347,17 +345,17 @@ end = struct
let reorder b = let reorder b =
let order = ordering b in let order = ordering b in
let f a = Array.init (Array.length a) ~f:(fun i -> a.(order.(i))) in let f a = Array.init (Array.length a) (fun i -> a.(order.(i))) in
let ao_prim_num_max = AO_prim_number.to_int b.ao_prim_num_max let ao_prim_num_max = AO_prim_number.to_int b.ao_prim_num_max
and ao_num = AO_number.to_int b.ao_num in and ao_num = AO_number.to_int b.ao_num in
let ao_coef = let ao_coef =
Array.init ao_prim_num_max ~f:(fun i -> Array.init ao_prim_num_max (fun i ->
f @@ Array.init ao_num ~f:(fun j -> b.ao_coef.(i*ao_num + j) ) f @@ Array.init ao_num (fun j -> b.ao_coef.(i*ao_num + j) )
) |> Array.to_list |> Array.concat ) |> Array.to_list |> Array.concat
in in
let ao_expo = let ao_expo =
Array.init ao_prim_num_max ~f:(fun i -> Array.init ao_prim_num_max (fun i ->
f @@ Array.init ao_num ~f:(fun j -> b.ao_expo.(i*ao_num + j) ) f @@ Array.init ao_num (fun j -> b.ao_expo.(i*ao_num + j) )
) |> Array.to_list |> Array.concat ) |> Array.to_list |> Array.concat
in in
{ b with { b with
@ -373,7 +371,7 @@ end = struct
let to_rst b = let to_rst b =
let print_sym = let print_sym =
let l = List.init (Array.length b.ao_power) ~f:( let l = List.init (Array.length b.ao_power) (
fun i -> ( (i+1),b.ao_nucl.(i),b.ao_power.(i) ) ) fun i -> ( (i+1),b.ao_nucl.(i),b.ao_power.(i) ) )
in in
let rec do_work = function let rec do_work = function
@ -383,7 +381,7 @@ end = struct
(Symmetry.Xyz.to_string x) (Symmetry.Xyz.to_string x)
)::(do_work tail) )::(do_work tail)
in do_work l in do_work l
|> String.concat |> String.concat ""
in in
let short_basis = to_basis b in let short_basis = to_basis b in
@ -408,11 +406,11 @@ Basis set (read-only) ::
======= ========= =========== ======= ========= ===========
" (AO_basis_name.to_string b.ao_basis) " (AO_basis_name.to_string b.ao_basis)
(Bool.to_string b.ao_cartesian) (string_of_bool b.ao_cartesian)
(Basis.to_string short_basis (Basis.to_string short_basis
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
|> List.map ~f:(fun x-> " "^x) |> List.map (fun x-> " "^x)
|> String.concat ~sep:"\n" |> String.concat "\n"
) print_sym ) print_sym
|> Rst_string.of_string |> Rst_string.of_string
@ -420,14 +418,14 @@ Basis set (read-only) ::
let read_rst s = let read_rst s =
let s = Rst_string.to_string s let s = Rst_string.to_string s
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
in in
let rec extract_basis = function let rec extract_basis = function
| [] -> failwith "Error in basis set" | [] -> failwith "Error in basis set"
| line :: tail -> | line :: tail ->
let line = String.strip line in let line = String.trim line in
if line = "Basis set (read-only) ::" then if line = "Basis set (read-only) ::" then
String.concat tail ~sep:"\n" String.concat "\n" tail
else else
extract_basis tail extract_basis tail
in in
@ -450,17 +448,17 @@ md5 = %s
(AO_basis_name.to_string b.ao_basis) (AO_basis_name.to_string b.ao_basis)
(AO_number.to_string b.ao_num) (AO_number.to_string b.ao_num)
(b.ao_prim_num |> Array.to_list |> List.map (b.ao_prim_num |> Array.to_list |> List.map
~f:(AO_prim_number.to_string) |> String.concat ~sep:", " ) (AO_prim_number.to_string) |> String.concat ", " )
(AO_prim_number.to_string b.ao_prim_num_max) (AO_prim_number.to_string b.ao_prim_num_max)
(b.ao_nucl |> Array.to_list |> List.map ~f:Nucl_number.to_string |> (b.ao_nucl |> Array.to_list |> List.map Nucl_number.to_string |>
String.concat ~sep:", ") String.concat ", ")
(b.ao_power |> Array.to_list |> List.map ~f:(fun x-> (b.ao_power |> Array.to_list |> List.map (fun x->
"("^(Symmetry.Xyz.to_string x)^")" )|> String.concat ~sep:", ") "("^(Symmetry.Xyz.to_string x)^")" )|> String.concat ", ")
(b.ao_coef |> Array.to_list |> List.map ~f:AO_coef.to_string (b.ao_coef |> Array.to_list |> List.map AO_coef.to_string
|> String.concat ~sep:", ") |> String.concat ", ")
(b.ao_expo |> Array.to_list |> List.map ~f:AO_expo.to_string (b.ao_expo |> Array.to_list |> List.map AO_expo.to_string
|> String.concat ~sep:", ") |> String.concat ", ")
(b.ao_cartesian |> Bool.to_string) (b.ao_cartesian |> string_of_bool)
(to_md5 b |> MD5.to_string ) (to_md5 b |> MD5.to_string )
;; ;;

View File

@ -1,228 +0,0 @@
open Qptypes;;
open Qputils;;
open Core;;
module Bielec_integrals : sig
type t =
{ read_ao_integrals : bool;
read_mo_integrals : bool;
write_ao_integrals : bool;
write_mo_integrals : bool;
threshold_ao : Threshold.t;
threshold_mo : Threshold.t;
direct : bool;
} [@@deriving sexp]
;;
val read : unit -> t option
val write : t -> unit
val to_string : t -> string
val to_rst : t -> Rst_string.t
val of_rst : Rst_string.t -> t option
end = struct
type t =
{ read_ao_integrals : bool;
read_mo_integrals : bool;
write_ao_integrals : bool;
write_mo_integrals : bool;
threshold_ao : Threshold.t;
threshold_mo : Threshold.t;
direct : bool;
} [@@deriving sexp]
;;
let get_default = Qpackage.get_ezfio_default "bielec_integrals";;
let read_read_ao_integrals () =
if not (Ezfio.has_bielec_integrals_read_ao_integrals ()) then
get_default "read_ao_integrals"
|> Bool.of_string
|> Ezfio.set_bielec_integrals_read_ao_integrals
;
Ezfio.get_bielec_integrals_read_ao_integrals ()
;;
let write_read_ao_integrals =
Ezfio.set_bielec_integrals_read_ao_integrals
;;
let read_read_mo_integrals () =
if not (Ezfio.has_bielec_integrals_read_mo_integrals ()) then
get_default "read_mo_integrals"
|> Bool.of_string
|> Ezfio.set_bielec_integrals_read_mo_integrals
;
Ezfio.get_bielec_integrals_read_mo_integrals ()
;;
let write_read_mo_integrals =
Ezfio.set_bielec_integrals_read_mo_integrals
;;
let read_write_ao_integrals () =
if not (Ezfio.has_bielec_integrals_write_ao_integrals ()) then
get_default "write_ao_integrals"
|> Bool.of_string
|> Ezfio.set_bielec_integrals_write_ao_integrals
;
Ezfio.get_bielec_integrals_write_ao_integrals ()
;;
let write_write_ao_integrals =
Ezfio.set_bielec_integrals_write_ao_integrals
;;
let read_write_mo_integrals () =
if not (Ezfio.has_bielec_integrals_write_mo_integrals ()) then
get_default "write_mo_integrals"
|> Bool.of_string
|> Ezfio.set_bielec_integrals_write_mo_integrals
;
Ezfio.get_bielec_integrals_write_mo_integrals ()
;;
let write_write_mo_integrals =
Ezfio.set_bielec_integrals_write_mo_integrals
;;
let read_direct () =
if not (Ezfio.has_bielec_integrals_direct ()) then
get_default "direct"
|> Bool.of_string
|> Ezfio.set_bielec_integrals_direct
;
Ezfio.get_bielec_integrals_direct ()
;;
let write_direct =
Ezfio.set_bielec_integrals_direct
;;
let read_threshold_ao () =
if not (Ezfio.has_bielec_integrals_threshold_ao ()) then
get_default "threshold_ao"
|> Float.of_string
|> Ezfio.set_bielec_integrals_threshold_ao
;
Ezfio.get_bielec_integrals_threshold_ao ()
|> Threshold.of_float
;;
let write_threshold_ao t =
Threshold.to_float t
|> Ezfio.set_bielec_integrals_threshold_ao
;;
let read_threshold_mo () =
if not (Ezfio.has_bielec_integrals_threshold_mo ()) then
get_default "threshold_mo"
|> Float.of_string
|> Ezfio.set_bielec_integrals_threshold_mo
;
Ezfio.get_bielec_integrals_threshold_mo ()
|> Threshold.of_float
;;
let write_threshold_mo t =
Threshold.to_float t
|> Ezfio.set_bielec_integrals_threshold_mo
;;
let read ()=
let result =
{ read_ao_integrals = read_read_ao_integrals();
read_mo_integrals = read_read_mo_integrals () ;
write_ao_integrals = read_write_ao_integrals ();
write_mo_integrals = read_write_mo_integrals ();
threshold_ao = read_threshold_ao ();
threshold_mo = read_threshold_mo ();
direct = read_direct () ;
} in
if (result.read_ao_integrals &&
result.write_ao_integrals) then
failwith "Read and Write AO integrals are both true.";
if (result.read_mo_integrals &&
result.write_mo_integrals) then
failwith "Read and Write MO integrals are both true.";
Some result
;;
let write b =
if (b.read_ao_integrals &&
b.write_ao_integrals) then
failwith "Read and Write AO integrals are both true.";
if (b.read_mo_integrals &&
b.write_mo_integrals) then
failwith "Read and Write MO integrals are both true.";
write_read_ao_integrals b.read_ao_integrals;
write_read_mo_integrals b.read_mo_integrals;
write_write_ao_integrals b.write_ao_integrals ;
write_write_mo_integrals b.write_mo_integrals ;
write_threshold_ao b.threshold_ao;
write_threshold_mo b.threshold_mo;
write_direct b.direct;
;;
let to_string b =
Printf.sprintf "
read_ao_integrals = %s
read_mo_integrals = %s
write_ao_integrals = %s
write_mo_integrals = %s
threshold_ao = %s
threshold_mo = %s
direct = %s
"
(Bool.to_string b.read_ao_integrals)
(Bool.to_string b.read_mo_integrals)
(Bool.to_string b.write_ao_integrals)
(Bool.to_string b.write_mo_integrals)
(Threshold.to_string b.threshold_ao)
(Threshold.to_string b.threshold_mo)
(Bool.to_string b.direct)
;;
let to_rst b =
Printf.sprintf "
Read AO/MO integrals from disk ::
read_ao_integrals = %s
read_mo_integrals = %s
Write AO/MO integrals to disk ::
write_ao_integrals = %s
write_mo_integrals = %s
Thresholds on integrals ::
threshold_ao = %s
threshold_mo = %s
Direct calculation of integrals ::
direct = %s
"
(Bool.to_string b.read_ao_integrals)
(Bool.to_string b.read_mo_integrals)
(Bool.to_string b.write_ao_integrals)
(Bool.to_string b.write_mo_integrals)
(Threshold.to_string b.threshold_ao)
(Threshold.to_string b.threshold_mo)
(Bool.to_string b.direct)
|> Rst_string.of_string
;;
include Generic_input_of_rst;;
let of_rst = of_rst t_of_sexp;;
end

View File

@ -1,6 +1,6 @@
open Qptypes;; open Qptypes
open Qputils;; open Qputils
open Core;; open Sexplib.Std
module Bitmasks : sig module Bitmasks : sig
type t = type t =
@ -59,7 +59,7 @@ end = struct
let full_mask n_int = let full_mask n_int =
let range = "[1-"^ let range = "[1-"^
(Int.to_string (Ezfio.get_mo_basis_mo_num ()))^"]" (string_of_int (Ezfio.get_mo_basis_mo_num ()))^"]"
in in
MO_class.create_active range MO_class.create_active range
|> MO_class.to_bitlist n_int |> MO_class.to_bitlist n_int
@ -75,7 +75,7 @@ end = struct
full_mask n_int full_mask n_int
in in
let result = [ act ; act ; act ; act ; act ; act ] let result = [ act ; act ; act ; act ; act ; act ]
|> List.map ~f:(fun x -> |> List.map (fun x ->
let y = Bitlist.to_int64_list x in y@y ) let y = Bitlist.to_int64_list x in y@y )
|> List.concat |> List.concat
in in
@ -107,7 +107,7 @@ end = struct
full_mask n_int full_mask n_int
in in
let result = [ act ; act ] let result = [ act ; act ]
|> List.map ~f:(fun x -> |> List.map (fun x ->
let y = Bitlist.to_int64_list x in y@y ) let y = Bitlist.to_int64_list x in y@y )
|> List.concat |> List.concat
in in
@ -147,12 +147,12 @@ cas = %s
(Bit_kind.to_string b.bit_kind) (Bit_kind.to_string b.bit_kind)
(Bitmask_number.to_string b.n_mask_gen) (Bitmask_number.to_string b.n_mask_gen)
(Array.to_list b.generators (Array.to_list b.generators
|> List.map ~f:(fun x-> Int64.to_string x) |> List.map (fun x-> Int64.to_string x)
|> String.concat ~sep:", ") |> String.concat ", ")
(Bitmask_number.to_string b.n_mask_cas) (Bitmask_number.to_string b.n_mask_cas)
(Array.to_list b.cas (Array.to_list b.cas
|> List.map ~f:(fun x-> Int64.to_string x) |> List.map (fun x-> Int64.to_string x)
|> String.concat ~sep:", ") |> String.concat ", ")
end end

View File

@ -1,6 +1,6 @@
open Qptypes;; open Qptypes;;
open Qputils;; open Qputils;;
open Core;; open Sexplib.Std;;
module Determinants_by_hand : sig module Determinants_by_hand : sig
type t = type t =
@ -112,7 +112,7 @@ end = struct
begin begin
Ezfio.set_determinants_n_states n_states; Ezfio.set_determinants_n_states n_states;
let data = let data =
Array.create n_states 1. Array.make n_states 1.
|> Array.to_list |> Array.to_list
in in
Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data
@ -126,7 +126,7 @@ end = struct
|> States_number.to_int |> States_number.to_int
in in
let data = let data =
Array.map ~f:Positive_float.to_float data Array.map Positive_float.to_float data
|> Array.to_list |> Array.to_list
in in
Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data
@ -142,21 +142,21 @@ end = struct
begin begin
let data = let data =
Array.init n_states (fun _ -> 1./.(float_of_int n_states)) Array.init n_states (fun _ -> 1./.(float_of_int n_states))
|> Array.map ~f:Positive_float.of_float |> Array.map Positive_float.of_float
in in
write_state_average_weight data write_state_average_weight data
end; end;
let result = let result =
Ezfio.get_determinants_state_average_weight () Ezfio.get_determinants_state_average_weight ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:Positive_float.of_float |> Array.map Positive_float.of_float
in in
if Array.length result = n_states then if Array.length result = n_states then
result result
else else
let data = let data =
Array.init n_states (fun _ -> 1./.(float_of_int n_states)) Array.init n_states (fun _ -> 1./.(float_of_int n_states))
|> Array.map ~f:Positive_float.of_float |> Array.map Positive_float.of_float
in in
(write_state_average_weight data; data) (write_state_average_weight data; data)
;; ;;
@ -189,18 +189,18 @@ end = struct
|> States_number.to_int |> States_number.to_int
in in
Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| 1 ; n_states |] Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| 1 ; n_states |]
~data:(List.init n_states ~f:(fun i -> if (i=0) then 1. else 0. )) ~data:(List.init n_states (fun i -> if (i=0) then 1. else 0. ))
|> Ezfio.set_determinants_psi_coef |> Ezfio.set_determinants_psi_coef
end; end;
Ezfio.get_determinants_psi_coef () Ezfio.get_determinants_psi_coef ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:Det_coef.of_float |> Array.map Det_coef.of_float
;; ;;
let write_psi_coef ~n_det ~n_states c = let write_psi_coef ~n_det ~n_states c =
let n_det = Det_number.to_int n_det let n_det = Det_number.to_int n_det
and c = Array.to_list c and c = Array.to_list c
|> List.map ~f:Det_coef.to_float |> List.map Det_coef.to_float
and n_states = and n_states =
States_number.to_int n_states States_number.to_int n_states
in in
@ -242,9 +242,9 @@ end = struct
assert (n_int = dim.(0)); assert (n_int = dim.(0));
assert (dim.(1) = 2); assert (dim.(1) = 2);
assert (dim.(2) = (Det_number.to_int (read_n_det ()))); assert (dim.(2) = (Det_number.to_int (read_n_det ())));
List.init dim.(2) ~f:(fun i -> List.init dim.(2) (fun i ->
Array.sub ~pos:(2*n_int*i) ~len:(2*n_int) data) Array.sub data (2*n_int*i) (2*n_int) )
|> List.map ~f:(Determinant.of_int64_array |> List.map (Determinant.of_int64_array
~n_int:(N_int_number.of_int n_int) ~n_int:(N_int_number.of_int n_int)
~alpha:n_alpha ~beta:n_beta ) ~alpha:n_alpha ~beta:n_beta )
|> Array.of_list |> Array.of_list
@ -332,18 +332,19 @@ end = struct
else else
"0." "0."
) )
|> String.concat_array ~sep:"\t" |> Array.to_list |> String.concat "\t"
in in
Array.init ndet ~f:(fun i -> Array.init ndet (fun i ->
Printf.sprintf " %s\n%s\n" Printf.sprintf " %s\n%s\n"
(coefs_string i) (coefs_string i)
(Determinant.to_string ~mo_num:mo_num b.psi_det.(i) (Determinant.to_string ~mo_num:mo_num b.psi_det.(i)
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
|> List.map ~f:(fun x -> " "^x) |> List.map (fun x -> " "^x)
|> String.concat ~sep:"\n" |> String.concat "\n"
) )
) )
|> String.concat_array ~sep:"\n" |> Array.to_list
|> String.concat "\n"
in in
Printf.sprintf " Printf.sprintf "
Force the selected wave function to be an eigenfunction of S^2. Force the selected wave function to be an eigenfunction of S^2.
@ -365,7 +366,7 @@ Determinants ::
" "
(b.expected_s2 |> Positive_float.to_string) (b.expected_s2 |> Positive_float.to_string)
(b.n_det |> Det_number.to_string) (b.n_det |> Det_number.to_string)
(b.state_average_weight |> Array.to_list |> List.map ~f:Positive_float.to_string |> String.concat ~sep:"\t") (b.state_average_weight |> Array.to_list |> List.map Positive_float.to_string |> String.concat "\t")
det_text det_text
|> Rst_string.of_string |> Rst_string.of_string
;; ;;
@ -388,11 +389,11 @@ psi_det = %s
(b.n_det |> Det_number.to_string) (b.n_det |> Det_number.to_string)
(b.n_states |> States_number.to_string) (b.n_states |> States_number.to_string)
(b.expected_s2 |> Positive_float.to_string) (b.expected_s2 |> Positive_float.to_string)
(b.state_average_weight |> Array.to_list |> List.map ~f:Positive_float.to_string |> String.concat ~sep:",") (b.state_average_weight |> Array.to_list |> List.map Positive_float.to_string |> String.concat ",")
(b.psi_coef |> Array.to_list |> List.map ~f:Det_coef.to_string (b.psi_coef |> Array.to_list |> List.map Det_coef.to_string
|> String.concat ~sep:", ") |> String.concat ", ")
(b.psi_det |> Array.to_list |> List.map ~f:(Determinant.to_string (b.psi_det |> Array.to_list |> List.map (Determinant.to_string
~mo_num) |> String.concat ~sep:"\n\n") ~mo_num) |> String.concat "\n\n")
;; ;;
let of_rst r = let of_rst r =
@ -400,33 +401,36 @@ psi_det = %s
in in
(* Split into header and determinants data *) (* Split into header and determinants data *)
let idx = String.substr_index_exn r ~pos:0 ~pattern:"\nDeterminants" let idx =
match String_ext.substr_index r ~pos:0 ~pattern:"\nDeterminants" with
| Some x -> x
| None -> assert false
in in
let (header, dets) = let (header, dets) =
(String.prefix r idx, String.suffix r ((String.length r)-idx) ) (String.sub r 0 idx, String.sub r idx (String.length r - idx) )
in in
(* Handle header *) (* Handle header *)
let header = r let header = r
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
|> List.filter ~f:(fun line -> |> List.filter (fun line ->
if (line = "") then if (line = "") then
false false
else else
( (String.contains line '=') && (line.[0] = ' ') ) ( (String.contains line '=') && (line.[0] = ' ') )
) )
|> List.map ~f:(fun line -> |> List.map (fun line ->
"("^( "("^(
String.tr line ~target:'=' ~replacement:' ' String_ext.tr line ~target:'=' ~replacement:' '
|> String.strip |> String.trim
)^")" ) )^")" )
|> String.concat |> String.concat ""
in in
(* Handle determinant coefs *) (* Handle determinant coefs *)
let dets = match ( dets let dets = match ( dets
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
|> List.map ~f:(String.strip) |> List.map String.trim
) with ) with
| _::lines -> lines | _::lines -> lines
| _ -> failwith "Error in determinants" | _ -> failwith "Error in determinants"
@ -438,8 +442,8 @@ psi_det = %s
| ""::""::tail -> read_coefs accu tail | ""::""::tail -> read_coefs accu tail
| ""::c::tail -> | ""::c::tail ->
let c = let c =
String.split ~on:'\t' c String_ext.split ~on:'\t' c
|> List.map ~f:(fun x -> Det_coef.of_float (Float.of_string x)) |> List.map (fun x -> Det_coef.of_float (Float.of_string x))
|> Array.of_list |> Array.of_list
in in
read_coefs (c::accu) tail read_coefs (c::accu) tail
@ -450,15 +454,15 @@ psi_det = %s
read_coefs [] dets read_coefs [] dets
in in
let nstates = let nstates =
List.hd_exn buffer List.hd buffer
|> Array.length |> Array.length
in in
let extract_state i = let extract_state i =
let i = let i =
i-1 i-1
in in
List.map ~f:(fun x -> Det_coef.to_string x.(i)) buffer List.map (fun x -> Det_coef.to_string x.(i)) buffer
|> String.concat ~sep:" " |> String.concat " "
in in
let rec build_result = function let rec build_result = function
| 1 -> extract_state 1 | 1 -> extract_state 1
@ -492,21 +496,12 @@ psi_det = %s
| _::tail -> read_dets accu tail | _::tail -> read_dets accu tail
in in
let dets = let dets =
List.map ~f:String.rev dets List.map String_ext.rev dets
in in
let sze =
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) dets
in
let control =
Gc.get ()
in
Gc.tune ~minor_heap_size:(sze) ~space_overhead:(sze/10)
~max_overhead:100000 ~major_heap_increment:(sze/10) ();
let a = let a =
read_dets [] dets read_dets [] dets
|> String.concat |> String.concat ""
in in
Gc.set control;
"(psi_det ("^a^"))" "(psi_det ("^a^"))"
in in
@ -520,7 +515,7 @@ psi_det = %s
Printf.sprintf "(n_states %d)" (States_number.to_int @@ read_n_states ()) Printf.sprintf "(n_states %d)" (States_number.to_int @@ read_n_states ())
in in
let s = let s =
String.concat [ header ; bitkind ; n_int ; n_states ; psi_coef ; psi_det] String.concat "" [ header ; bitkind ; n_int ; n_states ; psi_coef ; psi_det]
in in
@ -603,16 +598,16 @@ psi_det = %s
States_number.to_int det.n_states States_number.to_int det.n_states
in in
Range.to_int_list range Range.to_int_list range
|> List.iter ~f:(fun istate -> |> List.iter (fun istate ->
if istate > n_states then if istate > n_states then
failwith "State to extract should not be greater than n_states") failwith "State to extract should not be greater than n_states")
; ;
let sorted_list = let sorted_list =
Range.to_int_list range Range.to_int_list range
|> List.sort ~compare |> List.sort compare
in in
let state_shift = ref 0 in let state_shift = ref 0 in
List.iter ~f:(fun istate -> List.iter (fun istate ->
let j = let j =
istate - 1 istate - 1
in in

View File

@ -1,6 +1,6 @@
open Qptypes;; open Qptypes
open Qputils;; open Qputils
open Core;; open Sexplib.Std
module Electrons : sig module Electrons : sig
type t = type t =

View File

@ -1,6 +1,6 @@
open Qptypes open Qptypes
open Qputils open Qputils
open Core open Sexplib.Std
module Mo_basis : sig module Mo_basis : sig
@ -38,9 +38,10 @@ end = struct
let reorder b ordering = let reorder b ordering =
{ b with mo_coef = { b with mo_coef =
Array.map ~f:(fun mo -> Array.map (fun mo ->
Array.init ~f:(fun i -> mo.(ordering.(i))) (Array.length mo) ) Array.init (Array.length mo)
b.mo_coef (fun i -> mo.(ordering.(i)))
) b.mo_coef
} }
let read_ao_md5 () = let read_ao_md5 () =
@ -73,7 +74,7 @@ end = struct
begin begin
let mo_num = MO_number.to_int (read_mo_num ()) in let mo_num = MO_number.to_int (read_mo_num ()) in
let data = let data =
Array.init mo_num ~f:(fun _ -> MO_class.(to_string (Active []))) Array.init mo_num (fun _ -> MO_class.(to_string (Active [])))
|> Array.to_list |> Array.to_list
in in
Ezfio.ezfio_array_of_list ~rank:1 Ezfio.ezfio_array_of_list ~rank:1
@ -81,7 +82,7 @@ end = struct
|> Ezfio.set_mo_basis_mo_class |> Ezfio.set_mo_basis_mo_class
end; end;
Ezfio.flattened_ezfio (Ezfio.get_mo_basis_mo_class () ) Ezfio.flattened_ezfio (Ezfio.get_mo_basis_mo_class () )
|> Array.map ~f:MO_class.of_string |> Array.map MO_class.of_string
let read_mo_occ () = let read_mo_occ () =
@ -90,7 +91,7 @@ end = struct
let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num () let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num ()
and elec_beta_num = Ezfio.get_electrons_elec_beta_num () and elec_beta_num = Ezfio.get_electrons_elec_beta_num ()
and mo_num = MO_number.to_int (read_mo_num ()) in and mo_num = MO_number.to_int (read_mo_num ()) in
let data = Array.init mo_num ~f:(fun i -> let data = Array.init mo_num (fun i ->
if (i<elec_beta_num) then 2. if (i<elec_beta_num) then 2.
else if (i < elec_alpha_num) then 1. else if (i < elec_alpha_num) then 1.
else 0.) |> Array.to_list in else 0.) |> Array.to_list in
@ -99,18 +100,18 @@ end = struct
|> Ezfio.set_mo_basis_mo_occ |> Ezfio.set_mo_basis_mo_occ
end; end;
Ezfio.flattened_ezfio (Ezfio.get_mo_basis_mo_occ () ) Ezfio.flattened_ezfio (Ezfio.get_mo_basis_mo_occ () )
|> Array.map ~f:MO_occ.of_float |> Array.map MO_occ.of_float
let read_mo_coef () = let read_mo_coef () =
let a = Ezfio.get_mo_basis_mo_coef () let a = Ezfio.get_mo_basis_mo_coef ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:MO_coef.of_float |> Array.map MO_coef.of_float
in in
let mo_num = read_mo_num () |> MO_number.to_int in let mo_num = read_mo_num () |> MO_number.to_int in
let ao_num = (Array.length a)/mo_num in let ao_num = (Array.length a)/mo_num in
Array.init mo_num ~f:(fun j -> Array.init mo_num (fun j ->
Array.sub ~pos:(j*ao_num) ~len:(ao_num) a Array.sub a (j*ao_num) (ao_num)
) )
@ -136,14 +137,14 @@ end = struct
| 1 -> | 1 ->
let header = [ Printf.sprintf " #%15d" (imin+1) ; ] in let header = [ Printf.sprintf " #%15d" (imin+1) ; ] in
let new_lines = let new_lines =
List.init ao_num ~f:(fun i -> List.init ao_num (fun i ->
Printf.sprintf " %3d %15.10f " (i+1) Printf.sprintf " %3d %15.10f " (i+1)
(MO_coef.to_float mo_coef.(imin ).(i)) ) (MO_coef.to_float mo_coef.(imin ).(i)) )
in header @ new_lines in header @ new_lines
| 2 -> | 2 ->
let header = [ Printf.sprintf " #%15d %15d" (imin+1) (imin+2) ; ] in let header = [ Printf.sprintf " #%15d %15d" (imin+1) (imin+2) ; ] in
let new_lines = let new_lines =
List.init ao_num ~f:(fun i -> List.init ao_num (fun i ->
Printf.sprintf " %3d %15.10f %15.10f" (i+1) Printf.sprintf " %3d %15.10f %15.10f" (i+1)
(MO_coef.to_float mo_coef.(imin ).(i)) (MO_coef.to_float mo_coef.(imin ).(i))
(MO_coef.to_float mo_coef.(imin+1).(i)) ) (MO_coef.to_float mo_coef.(imin+1).(i)) )
@ -152,7 +153,7 @@ end = struct
let header = [ Printf.sprintf " #%15d %15d %15d" let header = [ Printf.sprintf " #%15d %15d %15d"
(imin+1) (imin+2) (imin+3); ] in (imin+1) (imin+2) (imin+3); ] in
let new_lines = let new_lines =
List.init ao_num ~f:(fun i -> List.init ao_num (fun i ->
Printf.sprintf " %3d %15.10f %15.10f %15.10f" (i+1) Printf.sprintf " %3d %15.10f %15.10f %15.10f" (i+1)
(MO_coef.to_float mo_coef.(imin ).(i)) (MO_coef.to_float mo_coef.(imin ).(i))
(MO_coef.to_float mo_coef.(imin+1).(i)) (MO_coef.to_float mo_coef.(imin+1).(i))
@ -162,7 +163,7 @@ end = struct
let header = [ Printf.sprintf " #%15d %15d %15d %15d" let header = [ Printf.sprintf " #%15d %15d %15d %15d"
(imin+1) (imin+2) (imin+3) (imin+4) ; ] in (imin+1) (imin+2) (imin+3) (imin+4) ; ] in
let new_lines = let new_lines =
List.init ao_num ~f:(fun i -> List.init ao_num (fun i ->
Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f" (i+1) Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f" (i+1)
(MO_coef.to_float mo_coef.(imin ).(i)) (MO_coef.to_float mo_coef.(imin ).(i))
(MO_coef.to_float mo_coef.(imin+1).(i)) (MO_coef.to_float mo_coef.(imin+1).(i))
@ -173,7 +174,7 @@ end = struct
let header = [ Printf.sprintf " #%15d %15d %15d %15d %15d" let header = [ Printf.sprintf " #%15d %15d %15d %15d %15d"
(imin+1) (imin+2) (imin+3) (imin+4) (imin+5) ; ] in (imin+1) (imin+2) (imin+3) (imin+4) (imin+5) ; ] in
let new_lines = let new_lines =
List.init ao_num ~f:(fun i -> List.init ao_num (fun i ->
Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f %15.10f" (i+1) Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f %15.10f" (i+1)
(MO_coef.to_float mo_coef.(imin ).(i)) (MO_coef.to_float mo_coef.(imin ).(i))
(MO_coef.to_float mo_coef.(imin+1).(i)) (MO_coef.to_float mo_coef.(imin+1).(i))
@ -185,11 +186,11 @@ end = struct
in in
let rec create_list accu i = let rec create_list accu i =
if (i+4 < mo_num) then if (i+4 < mo_num) then
create_list ( (print_five i (i+3) |> String.concat ~sep:"\n")::accu ) (i+4) create_list ( (print_five i (i+3) |> String.concat "\n")::accu ) (i+4)
else else
(print_five i (mo_num-1) |> String.concat ~sep:"\n")::accu |> List.rev (print_five i (mo_num-1) |> String.concat "\n")::accu |> List.rev
in in
create_list [] 0 |> String.concat ~sep:"\n\n" create_list [] 0 |> String.concat "\n\n"
let to_rst b = let to_rst b =
@ -224,13 +225,13 @@ mo_coef = %s
(MO_label.to_string b.mo_label) (MO_label.to_string b.mo_label)
(MO_number.to_string b.mo_num) (MO_number.to_string b.mo_num)
(b.mo_class |> Array.to_list |> List.map (b.mo_class |> Array.to_list |> List.map
~f:(MO_class.to_string) |> String.concat ~sep:", " ) (MO_class.to_string) |> String.concat ", " )
(b.mo_occ |> Array.to_list |> List.map (b.mo_occ |> Array.to_list |> List.map
~f:(MO_occ.to_string) |> String.concat ~sep:", " ) (MO_occ.to_string) |> String.concat ", " )
(b.mo_coef |> Array.map (b.mo_coef |> Array.map
~f:(fun x-> Array.map ~f:MO_coef.to_string x |> String.concat_array (fun x-> Array.map MO_coef.to_string x |>
~sep:"," ) |> Array.to_list |> String.concat "," ) |>
String.concat_array ~sep:"\n" ) Array.to_list |> String.concat "\n" )
let write_mo_num n = let write_mo_num n =
@ -245,7 +246,7 @@ mo_coef = %s
let write_mo_class a = let write_mo_class a =
let mo_num = Array.length a in let mo_num = Array.length a in
let data = Array.map ~f:MO_class.to_string a let data = Array.map MO_class.to_string a
|> Array.to_list |> Array.to_list
in Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| mo_num |] ~data in Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| mo_num |] ~data
|> Ezfio.set_mo_basis_mo_class |> Ezfio.set_mo_basis_mo_class
@ -253,7 +254,7 @@ mo_coef = %s
let write_mo_occ a = let write_mo_occ a =
let mo_num = Array.length a in let mo_num = Array.length a in
let data = Array.map ~f:MO_occ.to_float a let data = Array.map MO_occ.to_float a
|> Array.to_list |> Array.to_list
in Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| mo_num |] ~data in Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| mo_num |] ~data
|> Ezfio.set_mo_basis_mo_occ |> Ezfio.set_mo_basis_mo_occ
@ -268,7 +269,7 @@ mo_coef = %s
let mo_num = Array.length a in let mo_num = Array.length a in
let ao_num = Array.length a.(0) in let ao_num = Array.length a.(0) in
let data = let data =
Array.map ~f:(fun mo -> Array.map ~f:MO_coef.to_float mo Array.map (fun mo -> Array.map MO_coef.to_float mo
|> Array.to_list) a |> Array.to_list) a
|> Array.to_list |> Array.to_list
|> List.concat |> List.concat

View File

@ -1,6 +1,6 @@
open Qptypes;; open Qptypes;;
open Qputils;; open Qputils;;
open Core;; open Sexplib.Std;;
module Nuclei_by_hand : sig module Nuclei_by_hand : sig
type t = type t =
@ -41,7 +41,7 @@ end = struct
let read_nucl_label () = let read_nucl_label () =
Ezfio.get_nuclei_nucl_label () Ezfio.get_nuclei_nucl_label ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:Element.of_string |> Array.map Element.of_string
;; ;;
let write_nucl_label ~nucl_num labels = let write_nucl_label ~nucl_num labels =
@ -50,7 +50,7 @@ end = struct
in in
let labels = let labels =
Array.to_list labels Array.to_list labels
|> List.map ~f:Element.to_string |> List.map Element.to_string
in in
Ezfio.ezfio_array_of_list ~rank:1 Ezfio.ezfio_array_of_list ~rank:1
~dim:[| nucl_num |] ~data:labels ~dim:[| nucl_num |] ~data:labels
@ -61,7 +61,7 @@ end = struct
let read_nucl_charge () = let read_nucl_charge () =
Ezfio.get_nuclei_nucl_charge () Ezfio.get_nuclei_nucl_charge ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:Charge.of_float |> Array.map Charge.of_float
;; ;;
let write_nucl_charge ~nucl_num charges = let write_nucl_charge ~nucl_num charges =
@ -70,7 +70,7 @@ end = struct
in in
let charges = let charges =
Array.to_list charges Array.to_list charges
|> List.map ~f:Charge.to_float |> List.map Charge.to_float
in in
Ezfio.ezfio_array_of_list ~rank:1 Ezfio.ezfio_array_of_list ~rank:1
~dim:[| nucl_num |] ~data:charges ~dim:[| nucl_num |] ~data:charges
@ -85,7 +85,7 @@ end = struct
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
in in
let zero = Point3d.of_string Units.Bohr "0. 0. 0." in let zero = Point3d.of_string Units.Bohr "0. 0. 0." in
let result = Array.create nucl_num zero in let result = Array.make nucl_num zero in
for i=0 to (nucl_num-1) for i=0 to (nucl_num-1)
do do
result.(i) <- Point3d.({ x=raw_data.(i); result.(i) <- Point3d.({ x=raw_data.(i);
@ -101,9 +101,9 @@ end = struct
in in
let coord = Array.to_list coord in let coord = Array.to_list coord in
let coord = let coord =
(List.map ~f:(fun x-> x.Point3d.x) coord) @ (List.map (fun x-> x.Point3d.x) coord) @
(List.map ~f:(fun x-> x.Point3d.y) coord) @ (List.map (fun x-> x.Point3d.y) coord) @
(List.map ~f:(fun x-> x.Point3d.z) coord) (List.map (fun x-> x.Point3d.z) coord)
in in
Ezfio.ezfio_array_of_list ~rank:2 Ezfio.ezfio_array_of_list ~rank:2
~dim:[| nucl_num ; 3 |] ~data:coord ~dim:[| nucl_num ; 3 |] ~data:coord
@ -160,11 +160,11 @@ nucl_coord = %s
" "
(Nucl_number.to_string b.nucl_num) (Nucl_number.to_string b.nucl_num)
(b.nucl_label |> Array.to_list |> List.map (b.nucl_label |> Array.to_list |> List.map
~f:(Element.to_string) |> String.concat ~sep:", " ) (Element.to_string) |> String.concat ", " )
(b.nucl_charge |> Array.to_list |> List.map (b.nucl_charge |> Array.to_list |> List.map
~f:(Charge.to_string) |> String.concat ~sep:", " ) (Charge.to_string) |> String.concat ", " )
(b.nucl_coord |> Array.to_list |> List.map (b.nucl_coord |> Array.to_list |> List.map
~f:(Point3d.to_string ~units:Units.Bohr) |> String.concat ~sep:"\n" ) (Point3d.to_string ~units:Units.Bohr) |> String.concat "\n" )
;; ;;
@ -174,12 +174,12 @@ nucl_coord = %s
( Printf.sprintf " %d\n " ( Printf.sprintf " %d\n "
nucl_num nucl_num
) :: ( ) :: (
List.init nucl_num ~f:(fun i-> List.init nucl_num (fun i->
Printf.sprintf " %-3s %d %s" Printf.sprintf " %-3s %d %s"
(b.nucl_label.(i) |> Element.to_string) (b.nucl_label.(i) |> Element.to_string)
(b.nucl_charge.(i) |> Charge.to_int ) (b.nucl_charge.(i) |> Charge.to_int )
(b.nucl_coord.(i) |> Point3d.to_string ~units:Units.Angstrom) ) (b.nucl_coord.(i) |> Point3d.to_string ~units:Units.Angstrom) )
) |> String.concat ~sep:"\n" ) |> String.concat "\n"
in in
Printf.sprintf " Printf.sprintf "
Nuclear coordinates in xyz format (Angstroms) :: Nuclear coordinates in xyz format (Angstroms) ::
@ -192,16 +192,15 @@ Nuclear coordinates in xyz format (Angstroms) ::
let of_rst s = let of_rst s =
let l = Rst_string.to_string s let l = Rst_string.to_string s
|> String.split ~on:'\n' |> String_ext.split ~on:'\n'
in in
(* Find lines containing the xyz data *) (* Find lines containing the xyz data *)
let rec extract_begin = function let rec extract_begin = function
| [] -> raise Caml.Not_found | [] -> raise Not_found
| line::tail -> | line::tail ->
let line = String.strip line in let line = String.trim line in
if (String.length line > 3) && if (String.length line > 3) &&
(String.sub line ~pos:((String.length line)-2) (String.sub line ((String.length line)-2) 2 = "::") then
~len:2 = "::") then
tail tail
else else
extract_begin tail extract_begin tail
@ -213,12 +212,12 @@ Nuclear coordinates in xyz format (Angstroms) ::
| _ :: nucl_num :: title :: lines -> | _ :: nucl_num :: title :: lines ->
begin begin
let nucl_num = nucl_num let nucl_num = nucl_num
|> String.strip |> String.trim
|> Int.of_string |> int_of_string
|> Nucl_number.of_int ~max:nmax |> Nucl_number.of_int ~max:nmax
and lines = Array.of_list lines and lines = Array.of_list lines
in in
List.init (Nucl_number.to_int nucl_num) ~f:(fun i -> List.init (Nucl_number.to_int nucl_num) (fun i ->
Atom.of_string Units.Angstrom lines.(i)) Atom.of_string Units.Angstrom lines.(i))
end end
| _ -> failwith "Error in xyz format" | _ -> failwith "Error in xyz format"
@ -227,12 +226,12 @@ Nuclear coordinates in xyz format (Angstroms) ::
let result = let result =
{ nucl_num = List.length atom_list { nucl_num = List.length atom_list
|> Nucl_number.of_int ~max:nmax; |> Nucl_number.of_int ~max:nmax;
nucl_label = List.map atom_list ~f:(fun x -> nucl_label = List.map (fun x ->
x.Atom.element) |> Array.of_list ; x.Atom.element) atom_list |> Array.of_list ;
nucl_charge = List.map atom_list ~f:(fun x -> nucl_charge = List.map (fun x ->
x.Atom.charge ) |> Array.of_list ; x.Atom.charge ) atom_list |> Array.of_list ;
nucl_coord = List.map atom_list ~f:(fun x -> nucl_coord = List.map (fun x ->
x.Atom.coord ) |> Array.of_list ; x.Atom.coord ) atom_list |> Array.of_list ;
} }
in Some result in Some result
;; ;;

View File

@ -62,7 +62,7 @@ let name m =
try try
let i = List.assoc e accu in let i = List.assoc e accu in
build_list ( (e,i+1)::(List.remove_assoc e accu) ) rest build_list ( (e,i+1)::(List.remove_assoc e accu) ) rest
with Caml.Not_found -> build_list ( (e,1)::accu ) rest with Not_found -> build_list ( (e,1)::accu ) rest
end end
| [] -> accu | [] -> accu
in in

View File

@ -50,3 +50,6 @@ let input_lines ic =
Bytes.to_string s Bytes.to_string s
|> String_ext.split ~on:'\n' |> String_ext.split ~on:'\n'
let string_of_string s = s

View File

@ -83,7 +83,7 @@ let pop_task ~client_id q =
} }
and found = and found =
try Some (TasksMap.find task_id q.tasks) try Some (TasksMap.find task_id q.tasks)
with Caml.Not_found -> None with Not_found -> None
in new_q, Some task_id, found in new_q, Some task_id, found
| [] -> q, None, None | [] -> q, None, None
@ -104,7 +104,7 @@ let end_task ~task_id ~client_id q =
let () = let () =
let client_id_check = let client_id_check =
try RunningMap.find task_id running with try RunningMap.find task_id running with
Caml.Not_found -> failwith "Task already finished" Not_found -> failwith "Task already finished"
in in
assert (client_id_check = client_id) assert (client_id_check = client_id)
in in

View File

@ -102,6 +102,15 @@ let to_list s =
|> Array.to_list |> Array.to_list
let of_list l =
let a = Array.of_list l in
String.init (Array.length a) (fun i -> a.(i))
let rev s =
to_list s
|> List.rev
|> of_list
let fold ~init ~f s = let fold ~init ~f s =
to_list s to_list s
|> List.fold_left f init |> List.fold_left f init

View File

@ -1,4 +1,4 @@
true: package(core,cryptokit,zmq,str,ppx_sexp_conv,ppx_deriving,getopt) true: package(cryptokit,zmq,str,sexplib,ppx_sexp_conv,ppx_deriving,getopt)
true: thread true: thread
false: profile false: profile
<*byte> : linkdep(c_bindings.o), custom <*byte> : linkdep(c_bindings.o), custom

View File

@ -510,13 +510,13 @@ let run ?o b au c d m p cart xyz_file =
in in
try try
Basis.read_element (basis_channel key) i e Basis.read_element (basis_channel key) i e
with Caml.Not_found -> with Not_found ->
let key = let key =
Element x.Atom.element Element x.Atom.element
in in
try try
Basis.read_element (basis_channel key) i e Basis.read_element (basis_channel key) i e
with Caml.Not_found -> with Not_found ->
failwith (Printf.sprintf "Basis not found for atom %d (%s)" (Nucl_number.to_int i) failwith (Printf.sprintf "Basis not found for atom %d (%s)" (Nucl_number.to_int i)
(Element.to_string x.Atom.element) ) (Element.to_string x.Atom.element) )
with with

View File

@ -556,7 +556,7 @@ def create_ocaml_input(dict_ezfio_cfg, module_lower):
template += ["open Qptypes;;", template += ["open Qptypes;;",
"open Qputils;;", "open Qputils;;",
"open Core;;", "open Sexplib.Std;;",
"", "",
"module {0} : sig".format(module_lower.capitalize())] "module {0} : sig".format(module_lower.capitalize())]
@ -611,7 +611,16 @@ def create_ocaml_input(dict_ezfio_cfg, module_lower):
"", "",
"end"] "end"]
return "\n".join(template) result = "\n".join(template)
result = result.replace("String.of_string","string_of_string")
result = result.replace("String.to_string","string_of_string")
result = result.replace("Int.of_string","int_of_string")
result = result.replace("Int.to_string","string_of_int")
result = result.replace("Float.of_string","float_of_string")
result = result.replace("Float.to_string","string_of_float")
result = result.replace("Bool.of_string","bool_of_string")
result = result.replace("Bool.to_string","string_of_bool")
return result
def save_ocaml_input(module_lower, str_ocaml_input): def save_ocaml_input(module_lower, str_ocaml_input):

View File

@ -352,7 +352,6 @@ class EZFIO_ocaml(object):
l_template = ['open Qputils;;', l_template = ['open Qputils;;',
'open Qptypes;;', 'open Qptypes;;',
'open Core;;',
''] '']
for m in self.l_module_lower: for m in self.l_module_lower:

View File

@ -4,7 +4,7 @@
open Qputils open Qputils
open Qptypes open Qptypes
open Core open Sexplib.Std
(** Interactive editing of the input. (** Interactive editing of the input.
@ -53,7 +53,7 @@ Editing file `%s`
let make_header kw = let make_header kw =
let s = keyword_to_string kw in let s = keyword_to_string kw in
let l = String.length s in let l = String.length s in
"\n\n"^s^"\n"^(String.init l ~f:(fun _ -> '='))^"\n\n" "\n\n"^s^"\n"^(String.init l (fun _ -> '='))^"\n\n"
@ -92,19 +92,19 @@ let get s =
(** Applies the changes from the string [str] corresponding to section [s] *) (** Applies the changes from the string [str] corresponding to section [s] *)
let set str s = let set str s =
let header = (make_header s) in let header = (make_header s) in
match String.substr_index ~pos:0 ~pattern:header str with match String_ext.substr_index ~pos:0 ~pattern:header str with
| None -> () | None -> ()
| Some idx -> | Some idx ->
begin begin
let index_begin = idx + (String.length header) in let index_begin = idx + (String.length header) in
let index_end = let index_end =
match ( String.substr_index ~pos:(index_begin+(String.length header)+1) match ( String_ext.substr_index ~pos:(index_begin+(String.length header)+1)
~pattern:"==" str) with ~pattern:"==" str) with
| Some i -> i | Some i -> i
| None -> String.length str | None -> String.length str
in in
let l = index_end - index_begin in let l = index_end - index_begin in
let str = String.sub ~pos:index_begin ~len:l str let str = String.sub str index_begin l
|> Rst_string.of_string |> Rst_string.of_string
in in
let write (of_rst,w) s = let write (of_rst,w) s =
@ -132,11 +132,11 @@ let set str s =
let create_temp_file ezfio_filename fields = let create_temp_file ezfio_filename fields =
let temp_filename = Filename.temp_file "qp_edit_" ".rst" in let temp_filename = Filename.temp_file "qp_edit_" ".rst" in
begin begin
Out_channel.with_file temp_filename ~f:(fun out_channel -> let oc = open_out temp_filename in
(file_header ezfio_filename) :: (List.map ~f:get fields) (file_header ezfio_filename) :: (List.map get fields)
|> String.concat ~sep:"\n" |> String.concat "\n"
|> Out_channel.output_string out_channel |> Printf.fprintf oc "%s";
); close_out oc;
at_exit (fun () -> Sys.remove temp_filename); at_exit (fun () -> Sys.remove temp_filename);
temp_filename temp_filename
end end
@ -155,20 +155,19 @@ let run check_only ?ndet ?state ezfio_filename =
in in
(* Open EZFIO *) (* Open EZFIO *)
if (not (Sys.file_exists_exn ezfio_filename)) then if (not (Sys.file_exists ezfio_filename)) then
failwith (ezfio_filename^" does not exists"); failwith (ezfio_filename^" does not exists");
Ezfio.set_file ezfio_filename; Ezfio.set_file ezfio_filename;
(* Clean qp_stop status *) (* Clean qp_stop status *)
[ "qpstop" ; "qpkill" ] [ "qpstop" ; "qpkill" ]
|> List.iter ~f:(fun f -> |> List.iter (fun f ->
let stopfile = let stopfile =
Filename.concat (Qpackage.ezfio_work ezfio_filename) f Filename.concat (Qpackage.ezfio_work ezfio_filename) f
in in
match Sys.file_exists stopfile with if Sys.file_exists stopfile then
| `Yes -> Sys.remove stopfile Sys.remove stopfile
| _ -> ()
); );
(* Reorder basis set *) (* Reorder basis set *)
@ -180,7 +179,7 @@ let run check_only ?ndet ?state ezfio_filename =
in in
let ordering = Input.Ao_basis.ordering aos in let ordering = Input.Ao_basis.ordering aos in
let test = Array.copy ordering in let test = Array.copy ordering in
Array.sort ~compare test ; Array.sort compare test ;
if test <> ordering then if test <> ordering then
begin begin
Printf.eprintf "Warning: Basis set is not properly ordered. Redordering.\n"; Printf.eprintf "Warning: Basis set is not properly ordered. Redordering.\n";
@ -212,7 +211,7 @@ let run check_only ?ndet ?state ezfio_filename =
(* (*
let output = (file_header ezfio_filename) :: ( let output = (file_header ezfio_filename) :: (
List.map ~f:get [ List.map get [
Ao_basis ; Ao_basis ;
Mo_basis ; Mo_basis ;
]) ])
@ -238,24 +237,28 @@ let run check_only ?ndet ?state ezfio_filename =
(* Open the temp file with external editor *) (* Open the temp file with external editor *)
let editor = let editor =
match Sys.getenv "EDITOR" with try Sys.getenv "EDITOR"
| Some editor -> editor with Not_found -> "vi"
| None -> "vi"
in in
match check_only with match check_only with
| true -> () | true -> ()
| false -> | false ->
Printf.sprintf "%s %s" editor temp_filename Printf.sprintf "%s %s" editor temp_filename
|> Sys.command_exn |> Sys.command |> ignore
; ;
(* Re-read the temp file *) (* Re-read the temp file *)
let temp_string = let temp_string =
In_channel.with_file temp_filename ~f:(fun in_channel -> let ic = open_in temp_filename in
In_channel.input_all in_channel) let result =
input_lines ic
|> String.concat "\n"
in
close_in ic;
result
in in
List.iter ~f:(fun x -> set temp_string x) tasks List.iter (fun x -> set temp_string x) tasks
@ -281,7 +284,8 @@ let create_backup ezfio_filename =
tar -cf .backup.tar --exclude=\"work/*\" %s && (mv .backup.tar %s || rm .backup.tar) tar -cf .backup.tar --exclude=\"work/*\" %s && (mv .backup.tar %s || rm .backup.tar)
" "
ezfio_filename ezfio_filename backup_filename ezfio_filename ezfio_filename backup_filename
|> Sys.command_exn |> Sys.command
|> ignore
with _ -> () with _ -> ()
@ -290,10 +294,10 @@ let restore_backup ezfio_filename =
let filename = let filename =
Printf.sprintf "%s/work/backup.tar" ezfio_filename Printf.sprintf "%s/work/backup.tar" ezfio_filename
in in
if Sys.file_exists_exn filename then if Sys.file_exists filename then
begin begin
Printf.sprintf "tar -xf %s" filename Printf.sprintf "tar -xf %s" filename
|> Sys.command_exn; |> Sys.command |> ignore;
remove_backup ezfio_filename remove_backup ezfio_filename
end end