diff --git a/ocaml/Input.ml b/ocaml/Input.ml index 9d5f6b7f..df14af68 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -12,5 +12,6 @@ include Input_determinants;; include Input_electrons;; include Input_full_ci;; include Input_hartree_fock;; +include Input_mo_basis;; diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml new file mode 100644 index 00000000..fab7810a --- /dev/null +++ b/ocaml/Input_mo_basis.ml @@ -0,0 +1,88 @@ +open Qptypes;; +open Qputils;; +open Core.Std;; + +module Mo_basis : sig + type t = + { mo_tot_num : MO_number.t ; + mo_label : Non_empty_string.t; + mo_occ : Positive_float.t array; + mo_coef : MO_coef.t array; + } + ;; + val read : unit -> t + val to_string : t -> string +end = struct + type t = + { mo_tot_num : MO_number.t ; + mo_label : Non_empty_string.t; + mo_occ : Positive_float.t array; + mo_coef : MO_coef.t array; + } + ;; + + let get_default = Qpackage.get_ezfio_default "mo_basis";; + + let read_mo_label () = + if not (Ezfio.has_mo_basis_mo_label ()) then + Ezfio.set_mo_basis_mo_label "Unknown" + ; + Ezfio.get_mo_basis_mo_label () + |> Non_empty_string.of_string + ;; + + let read_mo_tot_num () = + Ezfio.get_mo_basis_mo_tot_num () + |> MO_number.of_int + ;; + + let read_mo_occ () = + if not (Ezfio.has_mo_basis_mo_label ()) then + begin + let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num () + and elec_beta_num = Ezfio.get_electrons_elec_beta_num () + and mo_tot_num = MO_number.to_int (read_mo_tot_num ()) in + let data = Array.init mo_tot_num ~f:(fun i -> + if (i Array.to_list in + Ezfio.ezfio_array_of_list ~rank:1 + ~dim:[| mo_tot_num |] ~data:data + |> Ezfio.set_mo_basis_mo_occ + end; + (Ezfio.get_mo_basis_mo_occ () ).Ezfio.data + |> Ezfio.flattened_ezfio_data + |> Array.map ~f:Positive_float.of_float + ;; + + let read_mo_coef () = + (Ezfio.get_mo_basis_mo_coef () ).Ezfio.data + |> Ezfio.flattened_ezfio_data + |> Array.map ~f:MO_coef.of_float + ;; + + let read () = + { mo_tot_num = read_mo_tot_num (); + mo_label = read_mo_label () ; + mo_occ = read_mo_occ (); + mo_coef = read_mo_coef (); + } + ;; + + let to_string b = + Printf.sprintf " +mo_label = %s +mo_tot_num = \"%s\" +mo_occ = %s +mo_coef = %s +" + (Non_empty_string.to_string b.mo_label) + (MO_number.to_string b.mo_tot_num) + (b.mo_occ |> Array.to_list |> List.map + ~f:(Positive_float.to_string) |> String.concat ~sep:", " ) + (b.mo_coef |> Array.to_list |> List.map + ~f:(MO_coef.to_string) |> String.concat ~sep:", " ) + +end + + diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index b88cd37c..6b02f02e 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -61,6 +61,13 @@ let test_hf () = print_endline (Input.Hartree_fock.to_string b); ;; +let test_mo () = + Ezfio.set_file "F2.ezfio" ; + let b = Input.Mo_basis.read () + in + print_endline (Input.Mo_basis.to_string b); +;; + (* test_hf ();; test_ao ();; @@ -68,5 +75,6 @@ test_bielec_intergals ();; test_bitmasks (); test_cis (); test_dets (); -*) test_cisd_sc2 (); +*) +test_mo ();;