diff --git a/data/ezfio_defaults b/data/ezfio_defaults index 6aba9e85..9cc29c1b 100644 --- a/data/ezfio_defaults +++ b/data/ezfio_defaults @@ -18,7 +18,7 @@ cis_dressed determinants n_states 1 n_states_diag determinants_n_states - n_det_max_jacobi 5000 + n_det_max_jacobi 1000 threshold_generators 0.99 threshold_selectors 0.999 read_wf False diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 502ab0dc..cd13fc88 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -14,7 +14,7 @@ module Ao_basis : sig ao_expo : AO_expo.t array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_md5 : t -> MD5.t val to_rst : t -> Rst_string.t @@ -93,15 +93,19 @@ end = struct ;; let read () = - { ao_basis = read_ao_basis (); - ao_num = read_ao_num () ; - ao_prim_num = read_ao_prim_num (); - ao_prim_num_max = read_ao_prim_num_max (); - ao_nucl = read_ao_nucl (); - ao_power = read_ao_power (); - ao_coef = read_ao_coef () ; - ao_expo = read_ao_expo () ; - } + if (Ezfio.has_ao_basis_ao_basis ()) then + Some + { ao_basis = read_ao_basis (); + ao_num = read_ao_num () ; + ao_prim_num = read_ao_prim_num (); + ao_prim_num_max = read_ao_prim_num_max (); + ao_nucl = read_ao_nucl (); + ao_power = read_ao_power (); + ao_coef = read_ao_coef () ; + ao_expo = read_ao_expo () ; + } + else + None ;; let to_long_basis b = diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index 2d864aca..c5fc4fe5 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -13,7 +13,7 @@ module Bielec_integrals : sig direct : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -150,7 +150,7 @@ end = struct if (result.read_mo_integrals && result.write_mo_integrals) then failwith "Read and Write MO integrals are both true."; - result + Some result ;; let write b = diff --git a/ocaml/Input_bitmasks.ml b/ocaml/Input_bitmasks.ml index 4b02a735..f374abc8 100644 --- a/ocaml/Input_bitmasks.ml +++ b/ocaml/Input_bitmasks.ml @@ -10,7 +10,7 @@ module Bitmasks : sig generators : int64 array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string end = struct type t = @@ -77,11 +77,15 @@ end = struct ;; let read () = - { n_int = read_n_int (); - bit_kind = read_bit_kind (); - n_mask_gen = read_n_mask_gen (); - generators = read_generators (); - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { n_int = read_n_int (); + bit_kind = read_bit_kind (); + n_mask_gen = read_n_mask_gen (); + generators = read_generators (); + } + else + None ;; let to_string b = diff --git a/ocaml/Input_cis.ml b/ocaml/Input_cis.ml index d5be2a6a..1094c56b 100644 --- a/ocaml/Input_cis.ml +++ b/ocaml/Input_cis.ml @@ -12,7 +12,7 @@ module Cis_dressed : sig en_2_2 : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_rst : t -> Rst_string.t val of_rst : Rst_string.t -> t option @@ -86,6 +86,7 @@ end = struct ;; let read () = + Some { n_state_cis = read_n_state_cis (); n_core_cis = read_n_core_cis (); n_act_cis = read_n_act_cis (); diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index 6870e69d..ed046d79 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -9,7 +9,7 @@ module Cisd_sc2 : sig do_pt2_end : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -71,6 +71,7 @@ end = struct let read () = + Some { n_det_max_cisd_sc2 = read_n_det_max_cisd_sc2 (); pt2_max = read_pt2_max (); do_pt2_end = read_do_pt2_end (); diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index 6c47d966..bb369ec3 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -19,7 +19,7 @@ module Determinants : sig psi_coef : Det_coef.t array; psi_det : Determinant.t array; } with sexp - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -311,21 +311,25 @@ end = struct let read () = - { n_int = read_n_int () ; - bit_kind = read_bit_kind () ; - mo_label = read_mo_label () ; - n_det = read_n_det () ; - n_states = read_n_states () ; - n_states_diag = read_n_states_diag () ; - n_det_max_jacobi = read_n_det_max_jacobi () ; - threshold_generators = read_threshold_generators () ; - threshold_selectors = read_threshold_selectors () ; - read_wf = read_read_wf () ; - expected_s2 = read_expected_s2 () ; - s2_eig = read_s2_eig () ; - psi_coef = read_psi_coef () ; - psi_det = read_psi_det () ; - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { n_int = read_n_int () ; + bit_kind = read_bit_kind () ; + mo_label = read_mo_label () ; + n_det = read_n_det () ; + n_states = read_n_states () ; + n_states_diag = read_n_states_diag () ; + n_det_max_jacobi = read_n_det_max_jacobi () ; + threshold_generators = read_threshold_generators () ; + threshold_selectors = read_threshold_selectors () ; + read_wf = read_read_wf () ; + expected_s2 = read_expected_s2 () ; + s2_eig = read_s2_eig () ; + psi_coef = read_psi_coef () ; + psi_det = read_psi_det () ; + } + else + None ;; let write { n_int ; diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index c3480d04..24d0fe00 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -8,7 +8,7 @@ module Electrons : sig elec_beta_num : Elec_beta_number.t; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val read_elec_num : unit -> Elec_number.t val to_string : t -> string @@ -53,9 +53,13 @@ end = struct let read () = - { elec_alpha_num = read_elec_alpha_num (); - elec_beta_num = read_elec_beta_num (); - } + if (Ezfio.has_electrons_elec_alpha_num ()) then + 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 } = diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 95c15232..0ee59f53 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -9,7 +9,7 @@ module Full_ci : sig do_pt2_end : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t-> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -69,9 +69,10 @@ end = struct let read () = - { n_det_max_fci = read_n_det_max_fci (); - pt2_max = read_pt2_max (); - do_pt2_end = read_do_pt2_end (); + Some + { n_det_max_fci = read_n_det_max_fci (); + pt2_max = read_pt2_max (); + do_pt2_end = read_do_pt2_end (); } ;; diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 27fd9b0e..845fb070 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -8,7 +8,7 @@ module Hartree_fock : sig thresh_scf : Threshold.t; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -54,6 +54,7 @@ end = struct let read () = + Some { n_it_scf_max = read_n_it_scf_max (); thresh_scf = read_thresh_scf (); } diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index d53e78b7..5ad982ac 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -10,7 +10,7 @@ module Mo_basis : sig mo_coef : (MO_coef.t array) array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_rst : t -> Rst_string.t end = struct @@ -68,11 +68,15 @@ end = struct ;; let read () = - { mo_tot_num = read_mo_tot_num (); - mo_label = read_mo_label () ; - mo_occ = read_mo_occ (); - mo_coef = read_mo_coef (); - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { mo_tot_num = read_mo_tot_num (); + mo_label = read_mo_label () ; + mo_occ = read_mo_occ (); + mo_coef = read_mo_coef (); + } + else + None ;; let mo_coef_to_string mo_coef = diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 3526d721..cbcb9f46 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -10,7 +10,7 @@ module Nuclei : sig nucl_coord : Point3d.t array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -111,11 +111,15 @@ end = struct let read () = - { nucl_num = read_nucl_num (); - nucl_label = read_nucl_label () ; - nucl_charge = read_nucl_charge (); - nucl_coord = read_nucl_coord (); - } + if (Ezfio.has_nuclei_nucl_num ()) then + Some + { nucl_num = read_nucl_num (); + nucl_label = read_nucl_label () ; + nucl_charge = read_nucl_charge (); + nucl_coord = read_nucl_coord (); + } + else + None ;; let write { nucl_num ; diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index a6241882..0aad8e5c 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -43,73 +43,93 @@ let make_header kw = ;; let get s = - let header = (make_header s) - and rst = let open Input in - match s with - | Full_ci -> - Full_ci.(to_rst (read ())) - | Hartree_fock -> - Hartree_fock.(to_rst (read ())) - | Mo_basis -> - Mo_basis.(to_rst (read ())) - | Electrons -> - Electrons.(to_rst (read ())) - | Determinants -> - Determinants.(to_rst (read ())) - | Cisd_sc2 -> - Cisd_sc2.(to_rst (read ())) - | Nuclei -> - Nuclei.(to_rst (read ())) - | Ao_basis -> - Ao_basis.(to_rst (read ())) - | Bielec_integrals -> - Bielec_integrals.(to_rst (read ())) - - in header^(Rst_string.to_string rst) + let header = (make_header s) 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 + | Full_ci -> + f Full_ci.(read, to_rst) + | Hartree_fock -> + f Hartree_fock.(read, to_rst) + | Mo_basis -> + f Mo_basis.(read, to_rst) + | Electrons -> + f Electrons.(read, to_rst) + | Cisd_sc2 -> + f Cisd_sc2.(read, to_rst) + | Nuclei -> + 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 header = (make_header s) in - let index_begin = String.substr_index_exn ~pos:0 ~pattern:header str in - let index_begin = index_begin + (String.length header) in - let index_end = - match ( String.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 - |> Rst_string.of_string - in - let write (of_rst,w) = - match of_rst str with - | Some data -> w data - | None -> () - in - let open Input in - match s with - | Hartree_fock -> write Hartree_fock.(of_rst, write) - | Full_ci -> write Full_ci.(of_rst, write) - | Electrons -> write Electrons.(of_rst, write) - | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) - | Bielec_integrals -> write Bielec_integrals.(of_rst, write) - | Determinants -> write Determinants.(of_rst, write) - | Nuclei -> write Nuclei.(of_rst, write) - | Ao_basis -> () (* TODO *) - | Mo_basis -> () (* TODO *) - + match String.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) + ~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 + |> Rst_string.of_string + in + let write (of_rst,w) s = + try + match of_rst str with + | Some data -> w data + | None -> () + with + | _ -> (Printf.eprintf "Info: Read error in %s\n%!" + (keyword_to_string s)) + in + let open Input in + match s with + | Hartree_fock -> write Hartree_fock.(of_rst, write) s + | 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 temp_filename = Filename.temp_file "qp_edit_" ".rst" in - 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 - ); - temp_filename + 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 + ) + end + ; temp_filename ;; let run ezfio_filename = diff --git a/ocaml/qp_print.ml b/ocaml/qp_print.ml index 6405d0ee..4edb2f8e 100644 --- a/ocaml/qp_print.ml +++ b/ocaml/qp_print.ml @@ -51,7 +51,10 @@ let run_i ~action ezfio_filename = 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 () |> Ezfio.flattened_ezfio |> Array.map ~f:(Float.to_int) and n_alpha = input.Input.Electrons.elec_alpha_num @@ -63,7 +66,10 @@ let run_i ~action ezfio_filename = in 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 and n_beta = input.Input.Electrons.elec_beta_num in Multiplicity.of_alpha_beta n_alpha n_beta diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 92469c6e..a2351321 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -2,7 +2,9 @@ open Qptypes;; let test_ao () = 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 print_endline (Input.Ao_basis.to_string b); print_endline (Input.Ao_basis.to_rst b |> Rst_string.to_string); @@ -10,7 +12,9 @@ let test_ao () = let test_bielec_intergals () = 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 let output = Input.Bielec_integrals.to_string b in @@ -28,21 +32,27 @@ let test_bielec_intergals () = let test_bitmasks () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Bitmasks.read () + let b = match Input.Bitmasks.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Bitmasks.to_string b); ;; let test_cis () = 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 print_endline (Input.Cis_dressed.to_string b); ;; let test_dets () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Determinants.read () + let b = match Input.Determinants.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Determinants.to_rst b |> Rst_string.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 () = 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 print_endline (Input.Cisd_sc2.to_string b); let rst = Input.Cisd_sc2.to_rst b in @@ -76,7 +88,9 @@ let test_cisd_sc2 () = let test_electrons () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Electrons.read () + let b = match Input.Electrons.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Electrons.to_string b); let rst = Input.Electrons.to_rst b in @@ -92,7 +106,9 @@ let test_electrons () = let test_fci () = 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 print_endline (Input.Full_ci.to_string b); let rst = Input.Full_ci.to_rst b in @@ -109,7 +125,9 @@ let test_fci () = let test_hf () = 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 print_endline (Input.Hartree_fock.to_string b); let rst = Input.Hartree_fock.to_rst b in @@ -126,14 +144,19 @@ let test_hf () = let test_mo () = 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 print_endline (Input.Mo_basis.to_string b); ;; let test_nucl () = 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 b2 = match Input.Nuclei.of_rst rst with | Some x -> x