10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-03 20:54:00 +01:00

Added Input_electrons.ml

This commit is contained in:
Anthony Scemama 2014-10-21 23:23:37 +02:00
parent c1cbf80080
commit 64022d88d7
7 changed files with 90 additions and 11 deletions

View File

@ -9,5 +9,6 @@ include Input_bitmasks;;
include Input_cis;;
include Input_cisd_sc2;;
include Input_determinants;;
include Input_electrons;;

60
ocaml/Input_electrons.ml Normal file
View File

@ -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

View File

@ -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 =

View File

@ -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);

View File

@ -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)
| _ -> ()
)
;;

View File

@ -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"

View File

@ -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();;