10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-22 18:57:31 +02:00

Improved qp_edit

This commit is contained in:
Anthony Scemama 2014-11-27 23:05:26 +01:00
parent a6fa9b1fb6
commit 0b40cf663a
15 changed files with 206 additions and 129 deletions

View File

@ -18,7 +18,7 @@ cis_dressed
determinants determinants
n_states 1 n_states 1
n_states_diag determinants_n_states n_states_diag determinants_n_states
n_det_max_jacobi 5000 n_det_max_jacobi 1000
threshold_generators 0.99 threshold_generators 0.99
threshold_selectors 0.999 threshold_selectors 0.999
read_wf False read_wf False

View File

@ -14,7 +14,7 @@ module Ao_basis : sig
ao_expo : AO_expo.t array; ao_expo : AO_expo.t array;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val to_string : t -> string val to_string : t -> string
val to_md5 : t -> MD5.t val to_md5 : t -> MD5.t
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -93,6 +93,8 @@ end = struct
;; ;;
let read () = let read () =
if (Ezfio.has_ao_basis_ao_basis ()) then
Some
{ ao_basis = read_ao_basis (); { ao_basis = read_ao_basis ();
ao_num = read_ao_num () ; ao_num = read_ao_num () ;
ao_prim_num = read_ao_prim_num (); ao_prim_num = read_ao_prim_num ();
@ -102,6 +104,8 @@ end = struct
ao_coef = read_ao_coef () ; ao_coef = read_ao_coef () ;
ao_expo = read_ao_expo () ; ao_expo = read_ao_expo () ;
} }
else
None
;; ;;
let to_long_basis b = let to_long_basis b =

View File

@ -13,7 +13,7 @@ module Bielec_integrals : sig
direct : bool; direct : bool;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -150,7 +150,7 @@ end = struct
if (result.read_mo_integrals && if (result.read_mo_integrals &&
result.write_mo_integrals) then result.write_mo_integrals) then
failwith "Read and Write MO integrals are both true."; failwith "Read and Write MO integrals are both true.";
result Some result
;; ;;
let write b = let write b =

View File

@ -10,7 +10,7 @@ module Bitmasks : sig
generators : int64 array; generators : int64 array;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val to_string : t -> string val to_string : t -> string
end = struct end = struct
type t = type t =
@ -77,11 +77,15 @@ end = struct
;; ;;
let read () = let read () =
if (Ezfio.has_mo_basis_mo_tot_num ()) then
Some
{ n_int = read_n_int (); { n_int = read_n_int ();
bit_kind = read_bit_kind (); bit_kind = read_bit_kind ();
n_mask_gen = read_n_mask_gen (); n_mask_gen = read_n_mask_gen ();
generators = read_generators (); generators = read_generators ();
} }
else
None
;; ;;
let to_string b = let to_string b =

View File

@ -12,7 +12,7 @@ module Cis_dressed : sig
en_2_2 : bool; en_2_2 : bool;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
val of_rst : Rst_string.t -> t option val of_rst : Rst_string.t -> t option
@ -86,6 +86,7 @@ end = struct
;; ;;
let read () = let read () =
Some
{ n_state_cis = read_n_state_cis (); { n_state_cis = read_n_state_cis ();
n_core_cis = read_n_core_cis (); n_core_cis = read_n_core_cis ();
n_act_cis = read_n_act_cis (); n_act_cis = read_n_act_cis ();

View File

@ -9,7 +9,7 @@ module Cisd_sc2 : sig
do_pt2_end : bool; do_pt2_end : bool;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -71,6 +71,7 @@ end = struct
let read () = let read () =
Some
{ n_det_max_cisd_sc2 = read_n_det_max_cisd_sc2 (); { n_det_max_cisd_sc2 = read_n_det_max_cisd_sc2 ();
pt2_max = read_pt2_max (); pt2_max = read_pt2_max ();
do_pt2_end = read_do_pt2_end (); do_pt2_end = read_do_pt2_end ();

View File

@ -19,7 +19,7 @@ module Determinants : sig
psi_coef : Det_coef.t array; psi_coef : Det_coef.t array;
psi_det : Determinant.t array; psi_det : Determinant.t array;
} with sexp } with sexp
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -311,6 +311,8 @@ end = struct
let read () = let read () =
if (Ezfio.has_mo_basis_mo_tot_num ()) then
Some
{ n_int = read_n_int () ; { n_int = read_n_int () ;
bit_kind = read_bit_kind () ; bit_kind = read_bit_kind () ;
mo_label = read_mo_label () ; mo_label = read_mo_label () ;
@ -326,6 +328,8 @@ end = struct
psi_coef = read_psi_coef () ; psi_coef = read_psi_coef () ;
psi_det = read_psi_det () ; psi_det = read_psi_det () ;
} }
else
None
;; ;;
let write { n_int ; let write { n_int ;

View File

@ -8,7 +8,7 @@ module Electrons : sig
elec_beta_num : Elec_beta_number.t; elec_beta_num : Elec_beta_number.t;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val read_elec_num : unit -> Elec_number.t val read_elec_num : unit -> Elec_number.t
val to_string : t -> string val to_string : t -> string
@ -53,9 +53,13 @@ end = struct
let read () = let read () =
if (Ezfio.has_electrons_elec_alpha_num ()) then
Some
{ elec_alpha_num = read_elec_alpha_num (); { elec_alpha_num = read_elec_alpha_num ();
elec_beta_num = read_elec_beta_num (); elec_beta_num = read_elec_beta_num ();
} }
else
None
;; ;;
let write { elec_alpha_num ; elec_beta_num } = let write { elec_alpha_num ; elec_beta_num } =

View File

@ -9,7 +9,7 @@ module Full_ci : sig
do_pt2_end : bool; do_pt2_end : bool;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t-> unit val write : t-> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -69,6 +69,7 @@ end = struct
let read () = let read () =
Some
{ n_det_max_fci = read_n_det_max_fci (); { n_det_max_fci = read_n_det_max_fci ();
pt2_max = read_pt2_max (); pt2_max = read_pt2_max ();
do_pt2_end = read_do_pt2_end (); do_pt2_end = read_do_pt2_end ();

View File

@ -8,7 +8,7 @@ module Hartree_fock : sig
thresh_scf : Threshold.t; thresh_scf : Threshold.t;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -54,6 +54,7 @@ end = struct
let read () = let read () =
Some
{ n_it_scf_max = read_n_it_scf_max (); { n_it_scf_max = read_n_it_scf_max ();
thresh_scf = read_thresh_scf (); thresh_scf = read_thresh_scf ();
} }

View File

@ -10,7 +10,7 @@ module Mo_basis : sig
mo_coef : (MO_coef.t array) array; mo_coef : (MO_coef.t array) array;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
end = struct end = struct
@ -68,11 +68,15 @@ end = struct
;; ;;
let read () = let read () =
if (Ezfio.has_mo_basis_mo_tot_num ()) then
Some
{ mo_tot_num = read_mo_tot_num (); { mo_tot_num = read_mo_tot_num ();
mo_label = read_mo_label () ; mo_label = read_mo_label () ;
mo_occ = read_mo_occ (); mo_occ = read_mo_occ ();
mo_coef = read_mo_coef (); mo_coef = read_mo_coef ();
} }
else
None
;; ;;
let mo_coef_to_string mo_coef = let mo_coef_to_string mo_coef =

View File

@ -10,7 +10,7 @@ module Nuclei : sig
nucl_coord : Point3d.t array; nucl_coord : Point3d.t array;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t option
val write : t -> unit val write : t -> unit
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
@ -111,11 +111,15 @@ end = struct
let read () = let read () =
if (Ezfio.has_nuclei_nucl_num ()) then
Some
{ nucl_num = read_nucl_num (); { nucl_num = read_nucl_num ();
nucl_label = read_nucl_label () ; nucl_label = read_nucl_label () ;
nucl_charge = read_nucl_charge (); nucl_charge = read_nucl_charge ();
nucl_coord = read_nucl_coord (); nucl_coord = read_nucl_coord ();
} }
else
None
;; ;;
let write { nucl_num ; let write { nucl_num ;

View File

@ -43,35 +43,49 @@ let make_header kw =
;; ;;
let get s = let get s =
let header = (make_header s) let header = (make_header s) in
and rst = let open Input in let f (read,to_rst) =
match read () with
| Some text -> header ^ (Rst_string.to_string (to_rst text))
| None -> ""
in
let rst =
try
begin
let open Input in
match s with match s with
| Full_ci -> | Full_ci ->
Full_ci.(to_rst (read ())) f Full_ci.(read, to_rst)
| Hartree_fock -> | Hartree_fock ->
Hartree_fock.(to_rst (read ())) f Hartree_fock.(read, to_rst)
| Mo_basis -> | Mo_basis ->
Mo_basis.(to_rst (read ())) f Mo_basis.(read, to_rst)
| Electrons -> | Electrons ->
Electrons.(to_rst (read ())) f Electrons.(read, to_rst)
| Determinants ->
Determinants.(to_rst (read ()))
| Cisd_sc2 -> | Cisd_sc2 ->
Cisd_sc2.(to_rst (read ())) f Cisd_sc2.(read, to_rst)
| Nuclei -> | Nuclei ->
Nuclei.(to_rst (read ())) f Nuclei.(read, to_rst)
| Ao_basis -> | Ao_basis ->
Ao_basis.(to_rst (read ())) f Ao_basis.(read, to_rst)
| Bielec_integrals -> | Bielec_integrals ->
Bielec_integrals.(to_rst (read ())) f Bielec_integrals.(read, to_rst)
| Determinants ->
in header^(Rst_string.to_string rst) f Determinants.(read, to_rst)
end
with
| Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "")
in
rst
;; ;;
let set str s = let set str s =
let header = (make_header s) in let header = (make_header s) in
let index_begin = String.substr_index_exn ~pos:0 ~pattern:header str in match String.substr_index ~pos:0 ~pattern:header str with
let index_begin = index_begin + (String.length header) in | None -> ()
| Some idx ->
begin
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.substr_index ~pos:(index_begin+(String.length header)+1)
~pattern:"==" str) with ~pattern:"==" str) with
@ -82,34 +96,40 @@ let set str s =
let str = String.sub ~pos:index_begin ~len:l str let str = String.sub ~pos:index_begin ~len:l str
|> Rst_string.of_string |> Rst_string.of_string
in in
let write (of_rst,w) = let write (of_rst,w) s =
try
match of_rst str with match of_rst str with
| Some data -> w data | Some data -> w data
| None -> () | None -> ()
with
| _ -> (Printf.eprintf "Info: Read error in %s\n%!"
(keyword_to_string s))
in in
let open Input in let open Input in
match s with match s with
| Hartree_fock -> write Hartree_fock.(of_rst, write) | Hartree_fock -> write Hartree_fock.(of_rst, write) s
| Full_ci -> write Full_ci.(of_rst, write) | Full_ci -> write Full_ci.(of_rst, write) s
| Electrons -> write Electrons.(of_rst, write) | Electrons -> write Electrons.(of_rst, write) s
| Cisd_sc2 -> write Cisd_sc2.(of_rst, write) | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) s
| Bielec_integrals -> write Bielec_integrals.(of_rst, write) | Bielec_integrals -> write Bielec_integrals.(of_rst, write) s
| Determinants -> write Determinants.(of_rst, write) | Determinants -> write Determinants.(of_rst, write) s
| Nuclei -> write Nuclei.(of_rst, write) | Nuclei -> write Nuclei.(of_rst, write) s
| Ao_basis -> () (* TODO *) | Ao_basis -> () (* TODO *)
| Mo_basis -> () (* TODO *) | Mo_basis -> () (* TODO *)
end
;; ;;
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
Out_channel.with_file temp_filename ~f:(fun out_channel -> Out_channel.with_file temp_filename ~f:(fun out_channel ->
(file_header ezfio_filename) :: (List.map ~f:get fields) (file_header ezfio_filename) :: (List.map ~f:get fields)
|> String.concat ~sep:"\n" |> String.concat ~sep:"\n"
|> Out_channel.output_string out_channel |> Out_channel.output_string out_channel
); )
temp_filename end
; temp_filename
;; ;;
let run ezfio_filename = let run ezfio_filename =

View File

@ -51,7 +51,10 @@ let run_i ~action ezfio_filename =
let compute_charge () = let compute_charge () =
let input = Input.Electrons.read () in let input = match Input.Electrons.read () with
| Some x -> x
| None -> assert false
in
let nucl_charge = Ezfio.get_nuclei_nucl_charge () let nucl_charge = Ezfio.get_nuclei_nucl_charge ()
|> Ezfio.flattened_ezfio |> Array.map ~f:(Float.to_int) |> Ezfio.flattened_ezfio |> Array.map ~f:(Float.to_int)
and n_alpha = input.Input.Electrons.elec_alpha_num and n_alpha = input.Input.Electrons.elec_alpha_num
@ -63,7 +66,10 @@ let run_i ~action ezfio_filename =
in in
let compute_multiplicity () = let compute_multiplicity () =
let input = Input.Electrons.read () in let input = match Input.Electrons.read () with
| Some x -> x
| None -> assert false
in
let n_alpha = input.Input.Electrons.elec_alpha_num let n_alpha = input.Input.Electrons.elec_alpha_num
and n_beta = input.Input.Electrons.elec_beta_num and n_beta = input.Input.Electrons.elec_beta_num
in Multiplicity.of_alpha_beta n_alpha n_beta in Multiplicity.of_alpha_beta n_alpha n_beta

View File

@ -2,7 +2,9 @@ open Qptypes;;
let test_ao () = let test_ao () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Ao_basis.read () let b = match Input.Ao_basis.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Ao_basis.to_string b); print_endline (Input.Ao_basis.to_string b);
print_endline (Input.Ao_basis.to_rst b |> Rst_string.to_string); print_endline (Input.Ao_basis.to_rst b |> Rst_string.to_string);
@ -10,7 +12,9 @@ let test_ao () =
let test_bielec_intergals () = let test_bielec_intergals () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Bielec_integrals.read () let b = match Input.Bielec_integrals.read () with
| Some x -> x
| None -> assert false
in in
let output = Input.Bielec_integrals.to_string b let output = Input.Bielec_integrals.to_string b
in in
@ -28,21 +32,27 @@ let test_bielec_intergals () =
let test_bitmasks () = let test_bitmasks () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Bitmasks.read () let b = match Input.Bitmasks.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Bitmasks.to_string b); print_endline (Input.Bitmasks.to_string b);
;; ;;
let test_cis () = let test_cis () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Cis_dressed.read () let b = match Input.Cis_dressed.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Cis_dressed.to_string b); print_endline (Input.Cis_dressed.to_string b);
;; ;;
let test_dets () = let test_dets () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Determinants.read () let b = match Input.Determinants.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Determinants.to_rst b |> Rst_string.to_string ) ; print_endline (Input.Determinants.to_rst b |> Rst_string.to_string ) ;
print_endline (Input.Determinants.sexp_of_t b |> Sexplib.Sexp.to_string ) ; print_endline (Input.Determinants.sexp_of_t b |> Sexplib.Sexp.to_string ) ;
@ -59,7 +69,9 @@ let test_dets () =
let test_cisd_sc2 () = let test_cisd_sc2 () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Cisd_sc2.read () let b = match Input.Cisd_sc2.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Cisd_sc2.to_string b); print_endline (Input.Cisd_sc2.to_string b);
let rst = Input.Cisd_sc2.to_rst b in let rst = Input.Cisd_sc2.to_rst b in
@ -76,7 +88,9 @@ let test_cisd_sc2 () =
let test_electrons () = let test_electrons () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Electrons.read () let b = match Input.Electrons.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Electrons.to_string b); print_endline (Input.Electrons.to_string b);
let rst = Input.Electrons.to_rst b in let rst = Input.Electrons.to_rst b in
@ -92,7 +106,9 @@ let test_electrons () =
let test_fci () = let test_fci () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Full_ci.read () let b = match Input.Full_ci.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Full_ci.to_string b); print_endline (Input.Full_ci.to_string b);
let rst = Input.Full_ci.to_rst b in let rst = Input.Full_ci.to_rst b in
@ -109,7 +125,9 @@ let test_fci () =
let test_hf () = let test_hf () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Hartree_fock.read () let b = match Input.Hartree_fock.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Hartree_fock.to_string b); print_endline (Input.Hartree_fock.to_string b);
let rst = Input.Hartree_fock.to_rst b in let rst = Input.Hartree_fock.to_rst b in
@ -126,14 +144,19 @@ let test_hf () =
let test_mo () = let test_mo () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Mo_basis.read () let b = match Input.Mo_basis.read () with
| Some x -> x
| None -> assert false
in in
print_endline (Input.Mo_basis.to_string b); print_endline (Input.Mo_basis.to_string b);
;; ;;
let test_nucl () = let test_nucl () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Nuclei.read () in let b = match Input.Nuclei.read () with
| Some x -> x
| None -> assert false
in
let rst = Input.Nuclei.to_rst b in let rst = Input.Nuclei.to_rst b in
let b2 = match Input.Nuclei.of_rst rst with let b2 = match Input.Nuclei.of_rst rst with
| Some x -> x | Some x -> x