10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-19 04:22:32 +01:00

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

2
configure vendored
View File

@ -60,7 +60,7 @@ function execute () {
}
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
case "$1" in

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -62,7 +62,7 @@ let name m =
try
let i = List.assoc e accu in
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
| [] -> accu
in

View File

@ -50,3 +50,6 @@ let input_lines ic =
Bytes.to_string s
|> 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 =
try Some (TasksMap.find task_id q.tasks)
with Caml.Not_found -> None
with Not_found -> None
in new_q, Some task_id, found
| [] -> q, None, None
@ -104,7 +104,7 @@ let end_task ~task_id ~client_id q =
let () =
let client_id_check =
try RunningMap.find task_id running with
Caml.Not_found -> failwith "Task already finished"
Not_found -> failwith "Task already finished"
in
assert (client_id_check = client_id)
in

View File

@ -102,6 +102,15 @@ let to_list s =
|> 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 =
to_list s
|> 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
false: profile
<*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
try
Basis.read_element (basis_channel key) i e
with Caml.Not_found ->
with Not_found ->
let key =
Element x.Atom.element
in
try
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)
(Element.to_string x.Atom.element) )
with

View File

@ -556,7 +556,7 @@ def create_ocaml_input(dict_ezfio_cfg, module_lower):
template += ["open Qptypes;;",
"open Qputils;;",
"open Core;;",
"open Sexplib.Std;;",
"",
"module {0} : sig".format(module_lower.capitalize())]
@ -611,7 +611,16 @@ def create_ocaml_input(dict_ezfio_cfg, module_lower):
"",
"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):

View File

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

View File

@ -4,7 +4,7 @@
open Qputils
open Qptypes
open Core
open Sexplib.Std
(** Interactive editing of the input.
@ -53,7 +53,7 @@ Editing file `%s`
let make_header kw =
let s = keyword_to_string kw 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] *)
let set str s =
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 -> ()
| Some idx ->
begin
let index_begin = idx + (String.length header) in
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
| Some i -> i
| None -> String.length str
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
in
let write (of_rst,w) s =
@ -132,11 +132,11 @@ let set str s =
let create_temp_file ezfio_filename fields =
let temp_filename = Filename.temp_file "qp_edit_" ".rst" in
begin
Out_channel.with_file temp_filename ~f:(fun out_channel ->
(file_header ezfio_filename) :: (List.map ~f:get fields)
|> String.concat ~sep:"\n"
|> Out_channel.output_string out_channel
);
let oc = open_out temp_filename in
(file_header ezfio_filename) :: (List.map get fields)
|> String.concat "\n"
|> Printf.fprintf oc "%s";
close_out oc;
at_exit (fun () -> Sys.remove temp_filename);
temp_filename
end
@ -155,20 +155,19 @@ let run check_only ?ndet ?state ezfio_filename =
in
(* 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");
Ezfio.set_file ezfio_filename;
(* Clean qp_stop status *)
[ "qpstop" ; "qpkill" ]
|> List.iter ~f:(fun f ->
|> List.iter (fun f ->
let stopfile =
Filename.concat (Qpackage.ezfio_work ezfio_filename) f
in
match Sys.file_exists stopfile with
| `Yes -> Sys.remove stopfile
| _ -> ()
if Sys.file_exists stopfile then
Sys.remove stopfile
);
(* Reorder basis set *)
@ -180,7 +179,7 @@ let run check_only ?ndet ?state ezfio_filename =
in
let ordering = Input.Ao_basis.ordering aos in
let test = Array.copy ordering in
Array.sort ~compare test ;
Array.sort compare test ;
if test <> ordering then
begin
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) :: (
List.map ~f:get [
List.map get [
Ao_basis ;
Mo_basis ;
])
@ -238,24 +237,28 @@ let run check_only ?ndet ?state ezfio_filename =
(* Open the temp file with external editor *)
let editor =
match Sys.getenv "EDITOR" with
| Some editor -> editor
| None -> "vi"
try Sys.getenv "EDITOR"
with Not_found -> "vi"
in
match check_only with
| true -> ()
| false ->
Printf.sprintf "%s %s" editor temp_filename
|> Sys.command_exn
|> Sys.command |> ignore
;
(* Re-read the temp file *)
let temp_string =
In_channel.with_file temp_filename ~f:(fun in_channel ->
In_channel.input_all in_channel)
let ic = open_in temp_filename in
let result =
input_lines ic
|> String.concat "\n"
in
close_in ic;
result
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)
"
ezfio_filename ezfio_filename backup_filename
|> Sys.command_exn
|> Sys.command
|> ignore
with _ -> ()
@ -290,10 +294,10 @@ let restore_backup ezfio_filename =
let filename =
Printf.sprintf "%s/work/backup.tar" ezfio_filename
in
if Sys.file_exists_exn filename then
if Sys.file_exists filename then
begin
Printf.sprintf "tar -xf %s" filename
|> Sys.command_exn;
|> Sys.command |> ignore;
remove_backup ezfio_filename
end