From 61c380f31e19049c88ae7df313106111c1a0aac7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 25 Feb 2019 14:36:59 +0100 Subject: [PATCH] Added Command_line module --- _tags | 2 +- run_hartree_fock.ml | 77 ++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/_tags b/_tags index c7598f6..0f8a66a 100644 --- a/_tags +++ b/_tags @@ -1,4 +1,4 @@ -true: package(str,unix,bigarray,lacaml,alcotest,zarith) +true: package(str,unix,bigarray,lacaml,alcotest,zarith,getopt) <*.byte> : linkdep(Utils/math_functions.o), custom <*.native>: linkdep(Utils/math_functions.o) : not_hygienic diff --git a/run_hartree_fock.ml b/run_hartree_fock.ml index d378bc7..7f8fe77 100644 --- a/run_hartree_fock.ml +++ b/run_hartree_fock.ml @@ -1,38 +1,50 @@ -let out_file : string option ref = ref None -let basis_file : string option ref = ref None -let nuclei_file : string option ref = ref None -let charge : int ref = ref 0 -let multiplicity: int ref = ref 1 +let () = + let open Command_line in + begin + set_header_doc (Sys.argv.(0) ^ " - QCaml command"); + set_description_doc "Runs a Hartree-Fock calculation"; + set_specs + [ { short='b' ; long="basis" ; opt=Mandatory; + arg=With_arg ""; + doc="Name of the file containing the basis set"; } ; + { short='x' ; long="xyz" ; opt=Mandatory; + arg=With_arg ""; + doc="Name of the file containing the nuclear coordinates in xyz format"; } ; -let speclist = [ - ( "-b" , Arg.String (fun x -> basis_file := Some x), - "File containing the atomic basis set") ; - ( "-c" , Arg.String (fun x -> nuclei_file := Some x), - "File containing the nuclear coordinates") ; - ( "-o" , Arg.String (fun x -> out_file := Some x) , - "Output file") ; - ( "-charge" , Arg.Int (fun x -> charge := x), - "Charge of the system") ; - ( "-mult" , Arg.Int (fun x -> multiplicity := x), - "Spin multiplicity of the system") ; -] + { short='m' ; long="multiplicity" ; opt=Optional; + arg=With_arg ""; + doc="Spin multiplicity (2S+1). Default is singlet"; } ; -let run ~out = - (* - let gc = Gc.get () in - Gc.set { gc with minor_heap_size=(262144 / 16) }; - *) - let basis_file = - match !basis_file with - | None -> raise (Invalid_argument "Basis set file should be specified with -b") + { short='c' ; long="charge" ; opt=Optional; + arg=With_arg ""; + doc="Total charge of the molecule. Default is 0"; } ; + ] + end; + + (* Handle options *) + let basis_file = + match Command_line.get "basis" with | Some x -> x - and nuclei_file = - match !nuclei_file with - | None -> raise (Invalid_argument "Coordinate file should be specified with -c") + | None -> assert false + in + + let nuclei_file = + match Command_line.get "xyz" with | Some x -> x - and charge = !charge - and multiplicity = !multiplicity + | None -> assert false + in + + let charge = + match Command_line.get "charge" with + | Some x -> 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 s = @@ -44,8 +56,3 @@ let run ~out = |> print_endline -let () = - let usage_msg = "Available options:" in - Arg.parse speclist (fun _ -> ()) usage_msg; - run ~out:!out_file -