10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-22 10:47:33 +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,15 +93,19 @@ end = struct
;; ;;
let read () = let read () =
{ ao_basis = read_ao_basis (); if (Ezfio.has_ao_basis_ao_basis ()) then
ao_num = read_ao_num () ; Some
ao_prim_num = read_ao_prim_num (); { ao_basis = read_ao_basis ();
ao_prim_num_max = read_ao_prim_num_max (); ao_num = read_ao_num () ;
ao_nucl = read_ao_nucl (); ao_prim_num = read_ao_prim_num ();
ao_power = read_ao_power (); ao_prim_num_max = read_ao_prim_num_max ();
ao_coef = read_ao_coef () ; ao_nucl = read_ao_nucl ();
ao_expo = read_ao_expo () ; ao_power = read_ao_power ();
} ao_coef = read_ao_coef () ;
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 () =
{ n_int = read_n_int (); if (Ezfio.has_mo_basis_mo_tot_num ()) then
bit_kind = read_bit_kind (); Some
n_mask_gen = read_n_mask_gen (); { n_int = read_n_int ();
generators = read_generators (); bit_kind = read_bit_kind ();
} n_mask_gen = read_n_mask_gen ();
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,21 +311,25 @@ end = struct
let read () = let read () =
{ n_int = read_n_int () ; if (Ezfio.has_mo_basis_mo_tot_num ()) then
bit_kind = read_bit_kind () ; Some
mo_label = read_mo_label () ; { n_int = read_n_int () ;
n_det = read_n_det () ; bit_kind = read_bit_kind () ;
n_states = read_n_states () ; mo_label = read_mo_label () ;
n_states_diag = read_n_states_diag () ; n_det = read_n_det () ;
n_det_max_jacobi = read_n_det_max_jacobi () ; n_states = read_n_states () ;
threshold_generators = read_threshold_generators () ; n_states_diag = read_n_states_diag () ;
threshold_selectors = read_threshold_selectors () ; n_det_max_jacobi = read_n_det_max_jacobi () ;
read_wf = read_read_wf () ; threshold_generators = read_threshold_generators () ;
expected_s2 = read_expected_s2 () ; threshold_selectors = read_threshold_selectors () ;
s2_eig = read_s2_eig () ; read_wf = read_read_wf () ;
psi_coef = read_psi_coef () ; expected_s2 = read_expected_s2 () ;
psi_det = read_psi_det () ; s2_eig = read_s2_eig () ;
} psi_coef = read_psi_coef () ;
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 () =
{ elec_alpha_num = read_elec_alpha_num (); if (Ezfio.has_electrons_elec_alpha_num ()) then
elec_beta_num = read_elec_beta_num (); Some
} { elec_alpha_num = read_elec_alpha_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,9 +69,10 @@ end = struct
let read () = let read () =
{ n_det_max_fci = read_n_det_max_fci (); Some
pt2_max = read_pt2_max (); { n_det_max_fci = read_n_det_max_fci ();
do_pt2_end = read_do_pt2_end (); pt2_max = read_pt2_max ();
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 () =
{ mo_tot_num = read_mo_tot_num (); if (Ezfio.has_mo_basis_mo_tot_num ()) then
mo_label = read_mo_label () ; Some
mo_occ = read_mo_occ (); { mo_tot_num = read_mo_tot_num ();
mo_coef = read_mo_coef (); mo_label = read_mo_label () ;
} mo_occ = read_mo_occ ();
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 () =
{ nucl_num = read_nucl_num (); if (Ezfio.has_nuclei_nucl_num ()) then
nucl_label = read_nucl_label () ; Some
nucl_charge = read_nucl_charge (); { nucl_num = read_nucl_num ();
nucl_coord = read_nucl_coord (); nucl_label = read_nucl_label () ;
} nucl_charge = read_nucl_charge ();
nucl_coord = read_nucl_coord ();
}
else
None
;; ;;
let write { nucl_num ; let write { nucl_num ;

View File

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