diff --git a/ocaml/Input.ml b/ocaml/Input.ml index 3d89aa78..a8980459 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -9,5 +9,6 @@ include Input_bitmasks;; include Input_cis;; include Input_cisd_sc2;; include Input_determinants;; +include Input_electrons;; diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml new file mode 100644 index 00000000..af016d08 --- /dev/null +++ b/ocaml/Input_electrons.ml @@ -0,0 +1,60 @@ +open Qptypes;; +open Qputils;; +open Core.Std;; + +module Electrons : sig + type t = + { elec_alpha_num : Strictly_positive_int.t; + elec_beta_num : Positive_int.t; + elec_num : Strictly_positive_int.t; + } + ;; + val read : unit -> t + val to_string : t -> string +end = struct + type t = + { elec_alpha_num : Strictly_positive_int.t; + elec_beta_num : Positive_int.t; + elec_num : Strictly_positive_int.t; + } + ;; + + let get_default = Qpackage.get_ezfio_default "electrons";; + + let read_elec_alpha_num() = + Ezfio.get_electrons_elec_alpha_num () + |> Strictly_positive_int.of_int + ;; + + let read_elec_beta_num() = + Ezfio.get_electrons_elec_beta_num () + |> Positive_int.of_int + ;; + + let read_elec_num () = + let na = Ezfio.get_electrons_elec_alpha_num () + and nb = Ezfio.get_electrons_elec_beta_num () + in assert (na >= nb); + Strictly_positive_int.of_int (na + nb) + ;; + + + let read () = + { elec_alpha_num = read_elec_alpha_num (); + elec_beta_num = read_elec_beta_num (); + elec_num = read_elec_num (); + } + ;; + + let to_string b = + Printf.sprintf " +elec_alpha_num = %s +elec_beta_num = %s +elec_num = %s +" + (Strictly_positive_int.to_string b.elec_alpha_num) + (Positive_int.to_string b.elec_beta_num) + (Strictly_positive_int.to_string b.elec_num) +end + + diff --git a/ocaml/Molecule.ml b/ocaml/Molecule.ml index 83691cdc..7e467ffb 100644 --- a/ocaml/Molecule.ml +++ b/ocaml/Molecule.ml @@ -19,7 +19,10 @@ let get_charge { nuclei ; elec_alpha ; elec_beta } = ;; let get_multiplicity m = - Multiplicity.of_alpha_beta m.elec_alpha m.elec_beta + let elec_alpha = m.elec_alpha + |> Positive_int.to_int + |> Strictly_positive_int.of_int in + Multiplicity.of_alpha_beta elec_alpha m.elec_beta ;; let get_nucl_num m = diff --git a/ocaml/Multiplicity.ml b/ocaml/Multiplicity.ml index 89246dec..a50d38ef 100644 --- a/ocaml/Multiplicity.ml +++ b/ocaml/Multiplicity.ml @@ -19,7 +19,7 @@ let to_string m = ;; let of_alpha_beta a b = - let a = Positive_int.to_int a + let a = Strictly_positive_int.to_int a and b = Positive_int.to_int b in assert (a >= b); diff --git a/ocaml/qp_print.ml b/ocaml/qp_print.ml index 5f11d394..0053b441 100644 --- a/ocaml/qp_print.ml +++ b/ocaml/qp_print.ml @@ -51,16 +51,20 @@ let run_i ~action ezfio_filename = let compute_charge () = + let input = Input.Electrons.read () in let nucl_charge = Ezfio.((get_nuclei_nucl_charge ()).data) |> Ezfio.flattened_ezfio_data |> Array.map ~f:(Float.to_int) - and n_alpha = Ezfio.get_electrons_elec_alpha_num () - and n_beta = Ezfio.get_electrons_elec_beta_num () + and n_alpha = input.Input.Electrons.elec_alpha_num + |> Strictly_positive_int.to_int + and n_beta = input.Input.Electrons.elec_beta_num + |> Positive_int.to_int in Array.fold ~init:(-n_alpha-n_beta) ~f:(fun x y -> x+y) nucl_charge in let compute_multiplicity () = - let n_alpha = Positive_int.of_int (Ezfio.get_electrons_elec_alpha_num ()) - and n_beta = Positive_int.of_int (Ezfio.get_electrons_elec_beta_num ()) + let input = Input.Electrons.read () 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 in @@ -139,10 +143,10 @@ Prints data contained into the EZFIO file. Input data : * basis - * nuclei + * nucl * charge - * multiplicity - * electrons + * mult + * elec Output data : @@ -150,6 +154,7 @@ Output data : ") spec (fun i o ezfio_file () -> + try match (i,o) with | (Some i, None) -> run_i ~action:i ezfio_file | (None, Some o) -> run_o ~action:o ezfio_file @@ -157,6 +162,9 @@ Output data : raise (Failure "Error : please specify -i or -o but not both.") | (None, None) -> raise (Failure "Error : please specify -i or -o.") + with + | Failure msg -> print_string ("Error\n"^msg) + | _ -> () ) ;; diff --git a/ocaml/qp_run.ml b/ocaml/qp_run.ml index bbc9b625..5d860e03 100644 --- a/ocaml/qp_run.ml +++ b/ocaml/qp_run.ml @@ -77,7 +77,7 @@ let () = Command.basic ~summary: "Quantum Package command" ~readme:( fun () -> " -Executes a Quantum Package binary file among these:\ni\n" +Executes a Quantum Package binary file among these:\n\n" ^ (Lazy.force Qpackage.executables |> List.map ~f:(fun (x,_) -> Printf.sprintf " * %s" x ) |> String.concat ~sep:"\n" diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 7135dcad..bd17a1b3 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -40,4 +40,11 @@ let test_cisd_sc2 () = print_endline (Input.Cisd_sc2.to_string b); ;; -test_cisd_sc2();; +let test_electrons () = + Ezfio.set_file "F2.ezfio" ; + let b = Input.Electrons.read () + in + print_endline (Input.Electrons.to_string b); +;; + +test_electrons();;