4
1
mirror of https://github.com/pfloos/quack synced 2024-12-23 04:43:53 +01:00

Better CLI

This commit is contained in:
Anthony Scemama 2020-10-11 22:26:37 +02:00
parent ade70d4062
commit ba958ff550
3 changed files with 125 additions and 103 deletions

View File

@ -4,7 +4,6 @@
quack_integrals quack_integrals
) )
(libraries (libraries
qcaml.common
qcaml qcaml
) )
) )

View File

@ -5,23 +5,82 @@ let quack_dir =
let quack_basis_filename = quack_dir ^ "/input/basis" let quack_basis_filename = quack_dir ^ "/input/basis"
let quack_molecule_filename = quack_dir ^ "/input/molecule" let quack_molecule_filename = quack_dir ^ "/input/molecule"
module Command_line = Qcaml.Common.Command_line
module Util = Qcaml.Common.Util
let basis_file : string option ref = ref None let () =
let nuclei_file : string option ref = ref None let open Command_line in
let charge : int option ref = ref None begin
let multiplicity : int option ref = ref None set_header_doc (Sys.argv.(0) ^ " - QuAcK command");
set_description_doc "Prepares the input data for QuAcK.
Writes $QUACK_DIR/input/basis and $QUACK_DIR/input/molecule.
If $QUACK_DIR is not set, $QUACK_DIR is replaces by the current
directory.";
set_specs
[ { short='b' ; long="basis" ; opt=Mandatory;
arg=With_arg "<string>";
doc="Name of the file containing the basis set"; } ;
{ short='x' ; long="xyz" ; opt=Mandatory;
arg=With_arg "<string>";
doc="Name of the file containing the nuclear coordinates in xyz format"; } ;
let speclist = [ { short='m' ; long="multiplicity" ; opt=Optional;
( "-b" , Arg.String (fun x -> basis_file := Some x), arg=With_arg "<int>";
"File containing the atomic basis set") ; doc="Spin multiplicity (2S+1). Default is singlet"; } ;
( "-c" , Arg.Int (fun x -> charge := Some x),
"Total charge of the system") ; { short='c' ; long="charge" ; opt=Optional;
( "-m" , Arg.Int (fun x -> multiplicity := Some x), arg=With_arg "<int>";
"Multiplicity of the system") ; doc="Total charge of the molecule. Specify negative charges with 'm' instead of the minus sign, for example m1 instead of -1. Default is 0"; } ;
( "-x" , Arg.String (fun x -> nuclei_file := Some x),
"File containing the nuclear coordinates") ; { short='f' ; long="frozen-core" ; opt=Optional;
arg=Without_arg ;
doc="Freeze core MOs. Default is false"; } ;
{ short='r' ; long="rydberg" ; opt=Optional;
arg=With_arg "<int>" ;
doc="Number of Rydberg electrons. Default is 0"; } ;
] ]
end;
(* Handle options *)
let basis_file = Util.of_some @@ Command_line.get "basis" in
let nuclei_file = Util.of_some @@ Command_line.get "xyz" in
let frozen_core = Command_line.get_bool "frozen-core" in
let charge =
match Command_line.get "charge" with
| Some x -> ( if x.[0] = 'm' then
~- (int_of_string (String.sub x 1 (String.length x - 1)))
else
int_of_string x )
| None -> 0
in
let multiplicity =
match Command_line.get "multiplicity" with
| Some x -> int_of_string x
| None -> 1
in
let rydberg =
match Command_line.get "rydberg" with
| Some x -> int_of_string x
| None -> 0
in
let nuclei =
Qcaml.Particles.Nuclei.of_xyz_file nuclei_file
in
let electrons =
Qcaml.Particles.Electrons.of_atoms ~multiplicity ~charge nuclei
in
let basis =
Qcaml.Gaussian.Basis.of_nuclei_and_basis_filename ~nuclei basis_file
in
let print_basis nuclei basis = let print_basis nuclei basis =
@ -40,7 +99,8 @@ let print_basis nuclei basis =
Format.fprintf ocf "%a" Qcaml.Gaussian.General_basis.pp_gcs x) b Format.fprintf ocf "%a" Qcaml.Gaussian.General_basis.pp_gcs x) b
) dict; ) dict;
close_out oc close_out oc
in
print_basis nuclei basis;
let print_molecule nuclei electrons = let print_molecule nuclei electrons =
@ -48,8 +108,12 @@ let print_molecule nuclei electrons =
let nat = Array.length nuclei in let nat = Array.length nuclei in
let nela = Qcaml.Particles.Electrons.n_alfa electrons in let nela = Qcaml.Particles.Electrons.n_alfa electrons in
let nelb = Qcaml.Particles.Electrons.n_beta electrons in let nelb = Qcaml.Particles.Electrons.n_beta electrons in
let ncore = Qcaml.Particles.Nuclei.small_core nuclei in let ncore =
let nryd = 0 in if frozen_core then
Qcaml.Particles.Nuclei.small_core nuclei
else 0
in
let nryd = rydberg in
Printf.fprintf oc "# nAt nEla nElb nCore nRyd\n"; Printf.fprintf oc "# nAt nEla nElb nCore nRyd\n";
Printf.fprintf oc " %4d %4d %4d %5d %4d\n" nat nela nelb ncore nryd; Printf.fprintf oc " %4d %4d %4d %5d %4d\n" nat nela nelb ncore nryd;
Printf.fprintf oc "# Znuc x y z\n"; Printf.fprintf oc "# Znuc x y z\n";
@ -60,49 +124,10 @@ let print_molecule nuclei electrons =
coord.x coord.y coord.z coord.x coord.y coord.z
) nuclei; ) nuclei;
close_out oc close_out oc
let run () =
let basis_file =
match !basis_file with
| None -> raise (Invalid_argument "Basis set file should be specified with -b")
| Some x -> x
and nuclei_file =
match !nuclei_file with
| None -> raise (Invalid_argument "Coordinate file should be specified with -x")
| Some x -> x
and charge =
match !charge with
| None -> 0
| Some c -> c
and multiplicity =
match !multiplicity with
| None -> 1
| Some m -> m
in in
let nuclei =
Qcaml.Particles.Nuclei.of_xyz_file nuclei_file
in
let electrons =
Qcaml.Particles.Electrons.of_atoms ~multiplicity ~charge nuclei
in
let basis =
Qcaml.Gaussian.Basis.of_nuclei_and_basis_filename ~nuclei basis_file
in
(* Print basis *)
print_molecule nuclei electrons; print_molecule nuclei electrons;
print_basis nuclei basis;
() ()
let () =
let usage_msg = "Available options:" in
Arg.parse speclist (fun _ -> ()) usage_msg;
run ()

View File

@ -1,30 +1,32 @@
let out_file : string option ref = ref None module Command_line = Qcaml.Common.Command_line
let basis_file : string option ref = ref None module Util = Qcaml.Common.Util
let nuclei_file : string option ref = ref None
let charge : int option ref = ref None
let multiplicity : int option ref = ref None
let range_separation : float option ref = ref None
let () =
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QuAcK command");
set_description_doc "Computes the one- and two-electron integrals on the Gaussian atomic basis set.";
set_specs
[ { short='b' ; long="basis" ; opt=Mandatory;
arg=With_arg "<string>";
doc="Name of the file containing the basis set"; } ;
let speclist = [ { short='x' ; long="xyz" ; opt=Mandatory;
( "-b" , Arg.String (fun x -> basis_file := Some x), arg=With_arg "<string>";
"File containing the atomic basis set") ; doc="Name of the file containing the nuclear coordinates in xyz format"; } ;
( "-x" , Arg.String (fun x -> nuclei_file := Some x),
"File containing the nuclear coordinates") ; { short='u' ; long="range-separation" ; opt=Optional;
( "-u" , Arg.Float (fun x -> range_separation := Some x), arg=With_arg "<float>";
"Value of mu, the range separation factor") ; doc="Range-separation parameter."; } ;
] ]
end;
let run () = let basis_file = Util.of_some @@ Command_line.get "basis" in
let basis_file = let nuclei_file = Util.of_some @@ Command_line.get "xyz" in
match !basis_file with let range_separation =
| None -> raise (Invalid_argument "Basis set file should be specified with -b") match Command_line.get "range-separation" with
| Some x -> x | None -> None
and nuclei_file = | Some mu -> Some (float_of_string mu)
match !nuclei_file with
| None -> raise (Invalid_argument "Coordinate file should be specified with -x")
| Some x -> x
and range_separation = !range_separation
in in
let nuclei = let nuclei =
@ -56,8 +58,4 @@ let run () =
| None -> () | None -> ()
let () =
let usage_msg = "Available options:" in
Arg.parse speclist (fun _ -> ()) usage_msg;
run ()