diff --git a/ocaml/Input.ml b/ocaml/Input.ml index df14af68..6b3932bc 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -13,5 +13,6 @@ include Input_electrons;; include Input_full_ci;; include Input_hartree_fock;; include Input_mo_basis;; +include Input_nuclei;; diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml new file mode 100644 index 00000000..c4139edb --- /dev/null +++ b/ocaml/Input_nuclei.ml @@ -0,0 +1,85 @@ +open Qptypes;; +open Qputils;; +open Core.Std;; + +module Nuclei : sig + type t = + { nucl_num : Nucl_number.t ; + nucl_label : Element.t array; + nucl_charge : Charge.t array; + nucl_coord : Point3d.t array; + } + ;; + val read : unit -> t + val to_string : t -> string +end = struct + type t = + { nucl_num : Nucl_number.t ; + nucl_label : Element.t array; + nucl_charge : Charge.t array; + nucl_coord : Point3d.t array; + } + ;; + + let get_default = Qpackage.get_ezfio_default "nuclei";; + + let read_nucl_num () = + Ezfio.get_nuclei_nucl_num () + |> Nucl_number.of_int + ;; + + let read_nucl_label () = + (Ezfio.get_nuclei_nucl_label ()).Ezfio.data + |> Ezfio.flattened_ezfio_data + |> Array.map ~f:Element.of_string + ;; + + let read_nucl_charge () = + (Ezfio.get_nuclei_nucl_charge () ).Ezfio.data + |> Ezfio.flattened_ezfio_data + |> Array.map ~f:Charge.of_float + ;; + + let read_nucl_coord () = + let nucl_num = Nucl_number.to_int (read_nucl_num ()) in + let raw_data = + (Ezfio.get_nuclei_nucl_coord() ).Ezfio.data + |> Ezfio.flattened_ezfio_data + in + let zero = Point3d.of_string Units.Bohr "0. 0. 0." in + let result = Array.create nucl_num zero in + for i=0 to (nucl_num-1) + do + result.(i) <- Point3d.({ x=raw_data.(i); + y=raw_data.(nucl_num+i); + z=raw_data.(2*nucl_num+i); }); + done; + result + ;; + + let read () = + { nucl_num = read_nucl_num (); + nucl_label = read_nucl_label () ; + nucl_charge = read_nucl_charge (); + nucl_coord = read_nucl_coord (); + } + ;; + + let to_string b = + Printf.sprintf " +nucl_num = %s +nucl_label = %s +nucl_charge = %s +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:", " ) + (b.nucl_charge |> Array.to_list |> List.map + ~f:(Charge.to_string) |> String.concat ~sep:", " ) + (b.nucl_coord |> Array.to_list |> List.map + ~f:(Point3d.to_string Units.Bohr) |> String.concat ~sep:"\n" ) + +end + + diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 6b02f02e..917ced2a 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -68,6 +68,13 @@ let test_mo () = print_endline (Input.Mo_basis.to_string b); ;; +let test_nucl () = + Ezfio.set_file "F2.ezfio" ; + let b = Input.Nuclei.read () + in + print_endline (Input.Nuclei.to_string b); +;; + (* test_hf ();; test_ao ();; @@ -76,5 +83,6 @@ test_bitmasks (); test_cis (); test_dets (); test_cisd_sc2 (); -*) test_mo ();; +*) +test_nucl ();