From cd7d0280d7b1272f88d719e7a1848af1b3417d18 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 14 Jan 2019 19:52:41 +0100 Subject: [PATCH] Fixed options --- .../qp_convert_output_to_ezfio.rst | 4 +- .../users_guide/qp_create_ezfio_from_xyz.rst | 13 +- docs/source/users_guide/qp_edit.rst | 3 +- docs/source/users_guide/qp_export_as_tgz.rst | 2 +- docs/source/users_guide/qp_plugins.rst | 6 +- docs/source/users_guide/qp_run.rst | 3 +- .../source/users_guide/qp_set_frozen_core.rst | 2 +- docs/source/users_guide/qp_set_mo_class.rst | 24 +- ocaml/Command_line.ml | 288 ++++++++++-------- ocaml/Command_line.mli | 126 ++++++++ ocaml/qp_create_ezfio_from_xyz.ml | 74 +++-- ocaml/qp_run.ml | 46 ++- ocaml/qp_set_mo_class.ml | 46 ++- scripts/get_basis | 8 +- scripts/qp_convert_output_to_ezfio | 8 +- scripts/qp_e_conv_fci | 2 +- scripts/qp_set_frozen_core | 4 +- scripts/remove_trailing_spaces | 2 +- 18 files changed, 429 insertions(+), 232 deletions(-) create mode 100644 ocaml/Command_line.mli diff --git a/docs/source/users_guide/qp_convert_output_to_ezfio.rst b/docs/source/users_guide/qp_convert_output_to_ezfio.rst index e3182e6e..24899632 100644 --- a/docs/source/users_guide/qp_convert_output_to_ezfio.rst +++ b/docs/source/users_guide/qp_convert_output_to_ezfio.rst @@ -15,12 +15,12 @@ Usage .. code:: bash - qp_convert_output_to_ezfio [-o EZFIO_DIR] + qp_convert_output_to_ezfio [-o EZFIO_DIR] FILE .. option:: -o, --output=EZFIO_DIR Renames the |EZFIO| directory. If this option is not present, the default - name fill be :file:`.ezfio` + name fill be :file:`FILE.ezfio` .. note:: All the parameters of the wave functgion need to be presente in the output diff --git a/docs/source/users_guide/qp_create_ezfio_from_xyz.rst b/docs/source/users_guide/qp_create_ezfio_from_xyz.rst index 3cf719a5..fe980704 100644 --- a/docs/source/users_guide/qp_create_ezfio_from_xyz.rst +++ b/docs/source/users_guide/qp_create_ezfio_from_xyz.rst @@ -13,14 +13,9 @@ Usage .. code:: bash - qp_create_ezfio_from_xyz [FLAGS] ( | ) + qp_create_ezfio_from_xyz [-a] -b [-c ] [-d ] + [-h] [-m ] [-o EZFIO_DIR] [-p ] [-x] [--] FILE - Flags : - [-a|--au] [-b string|--basis=string] - [-c int|--charge=int] [-d float|--dummy=float] [-h|--help] - [-m int|--multiplicity=int] [-o file|--output=file] - [-p string|--pseudo=string] [-x|--cartesian] - .. option:: -a, --au @@ -37,6 +32,10 @@ Usage -b "cc-pvtz | 1,H:sto-3g | 3,H:6-31g" By default, the basis set is obtained from the local database of the |qp|. + This option is mandatory. + + If ```` is set to ``show``, the list of all available basis sets is + displayed. .. option:: -c, --charge= diff --git a/docs/source/users_guide/qp_edit.rst b/docs/source/users_guide/qp_edit.rst index 35347feb..6a8f0c12 100644 --- a/docs/source/users_guide/qp_edit.rst +++ b/docs/source/users_guide/qp_edit.rst @@ -27,8 +27,7 @@ Usage .. code:: bash - qp_edit [-c|--check] [-h|--help] [-n |--ndet=] - [-s |--state=] [--] EZFIO_DIR + qp_edit [-c] [-h] [-n ] [-s ] [--] EZFIO_DIR .. option:: -c, --check diff --git a/docs/source/users_guide/qp_export_as_tgz.rst b/docs/source/users_guide/qp_export_as_tgz.rst index f1643d63..91d0ce79 100644 --- a/docs/source/users_guide/qp_export_as_tgz.rst +++ b/docs/source/users_guide/qp_export_as_tgz.rst @@ -24,7 +24,7 @@ Usage Prints the help message .. note:: - There can be conflicts due to the version of Glibc. The machine on which |QP| is + There can be conflicts due to the version of glibc. The machine on which |QP| is compiled should be the oldest one. diff --git a/docs/source/users_guide/qp_plugins.rst b/docs/source/users_guide/qp_plugins.rst index 320eb687..12e257cb 100644 --- a/docs/source/users_guide/qp_plugins.rst +++ b/docs/source/users_guide/qp_plugins.rst @@ -15,11 +15,11 @@ Usage .. code:: bash - qp_plugins list [ -i, --installed | -u, --uninstalled | -q, --repositories ] + qp_plugins list [-i] [-u] [-q] qp_plugins download qp_plugins install ... qp_plugins uninstall - qp_plugins create -n [-r, --repository=] [...] + qp_plugins create -n [-r ] [...] .. option:: list @@ -37,7 +37,7 @@ Usage List all the downloaded repositories. -.. option:: download URL +.. option:: download Download an external repository. The URL points to a tar.gz file or a git repository, for example: diff --git a/docs/source/users_guide/qp_run.rst b/docs/source/users_guide/qp_run.rst index 8c936148..f21e143f 100644 --- a/docs/source/users_guide/qp_run.rst +++ b/docs/source/users_guide/qp_run.rst @@ -15,8 +15,7 @@ Usage .. code:: bash - qp_run [-h|--help] [-p |--prefix=] [-s|--slave] [--] - PROGRAM EZFIO_DIR + qp_run [-h] [-p ] [-s] [--] PROGRAM EZFIO_DIR ``PROGRAM`` is the name of the |QP| program to be run, and ``EZFIO_DIR`` is the name of the |EZFIO| directory containing the data. diff --git a/docs/source/users_guide/qp_set_frozen_core.rst b/docs/source/users_guide/qp_set_frozen_core.rst index 2aea8862..05dfe991 100644 --- a/docs/source/users_guide/qp_set_frozen_core.rst +++ b/docs/source/users_guide/qp_set_frozen_core.rst @@ -21,7 +21,7 @@ Usage .. code:: bash - qp_set_frozen_core [-q] + qp_set_frozen_core [-q] EZFIO_DIR .. option:: -q diff --git a/docs/source/users_guide/qp_set_mo_class.rst b/docs/source/users_guide/qp_set_mo_class.rst index 6b942155..a0490f19 100644 --- a/docs/source/users_guide/qp_set_mo_class.rst +++ b/docs/source/users_guide/qp_set_mo_class.rst @@ -38,38 +38,32 @@ Usage .. code:: bash - qp_set_mo_class [FLAGS] - Flags: - [-act range] [-core range] [-del range] - [-inact range] [-q] [-virt range] - [-help] + qp_set_mo_class [-a ] [-c ] [-d ] [-h] [-i ] + [-q] [-v ] [--] EZFIO_DIR - -.. option:: -act +.. option:: -a, --act= Range of active orbitals -.. option:: -core +.. option:: -c, --core= Range of core orbitals -.. option:: -del +.. option:: -d, --del= Range of deleted orbitals -.. option:: -inact +.. option:: -i, --inact= Range of inactive orbitals -.. option:: -q +.. option:: -q, --query - Query: print the current masks + Print the |MO| classes -.. option:: -virt +.. option:: -v, --virt= Range of virtual orbitals -.. option:: -help, -? - diff --git a/ocaml/Command_line.ml b/ocaml/Command_line.ml index 942d29e7..1dd57892 100644 --- a/ocaml/Command_line.ml +++ b/ocaml/Command_line.ml @@ -1,161 +1,199 @@ -type argument = With_arg | Without_arg | With_opt_arg +type short_opt = char +type long_opt = string +type optional = Mandatory | Optional +type documentation = string +type argument = With_arg of string | Without_arg | With_opt_arg of string -let anon_args = ref [] +type description = { + short: short_opt ; + long : long_opt ; + opt : optional ; + doc : documentation ; + arg : argument ; + } + +let anon_args = ref [] and header_doc = ref "" +and description_doc = ref "" and footer_doc = ref "" -and specs = ref [] +and specs = ref [] let set_header_doc s = header_doc := s +let set_description_doc s = description_doc := s let set_footer_doc s = footer_doc := s -let dict = - let d = Hashtbl.create 67 in - d +(* Hash table containing all the options *) +let dict = Hashtbl.create 67 + +let get_bool x = Hashtbl.mem dict x + +let show_help () = get_bool "help" let get x = - try Some (Hashtbl.find dict x) - with Not_found -> None + try Some (Hashtbl.find dict x) + with Not_found -> None -let get_bool x = - Hashtbl.mem dict x +let anonymous name opt doc = + { short=' ' ; long=name; opt; doc; arg=Without_arg; } -let show_help () = - get_bool "help" +let output_text t = + Format.printf "@["; + begin + match Str.split (Str.regexp "\n") t with + | x :: [] -> Format.printf "@["; + Str.split (Str.regexp " ") x + |> List.iter (fun y -> Format.printf "@[%s@]@ " y) ; + Format.printf "@]" + | t -> List.iter (fun x -> + Format.printf "@["; + Str.split (Str.regexp " ") x + |> List.iter (fun y -> Format.printf "@[%s@]@ " y) ; + Format.printf "@]@;") t + end; + Format.printf "@]" +;; + + +let output_short x = + match x.short, x.opt, x.arg with + | ' ', Mandatory, _ -> Format.printf "@[%s@]" x.long + | ' ', Optional , _ -> Format.printf "@[[%s]@]" x.long + | _ , Mandatory, Without_arg -> Format.printf "@[-%c@]" x.short + | _ , Optional , Without_arg -> Format.printf "@[[-%c]@]" x.short + | _ , Mandatory, With_arg arg -> Format.printf "@[-%c %s@]" x.short arg + | _ , Optional , With_arg arg -> Format.printf "@[[-%c %s]@]" x.short arg + | _ , Mandatory, With_opt_arg arg -> Format.printf "@[-%c [%s]@]" x.short arg + | _ , Optional , With_opt_arg arg -> Format.printf "@[[-%c [%s]]@]" x.short arg + + +let output_long max_width x = + let arg = + match x.short, x.arg with + | ' ' , _ -> x.long + | _ , Without_arg -> x.long + | _ , With_arg arg -> Printf.sprintf "%s=%s" x.long arg + | _ , With_opt_arg arg -> Printf.sprintf "%s[=%s]" x.long arg + in + let long = + let l = String.length arg in + arg^(String.make (max_width-l) ' ') + in + Format.printf "@["; + begin + match x.short with + | ' ' -> Format.printf "@[%s @]" long + | short -> Format.printf "@[-%c --%s @]" short long + end; + Format.printf "@]"; + output_text x.doc -let anonymous ?(optional=false) name doc = - ( ' ', name, doc, - if optional then With_opt_arg else Without_arg - ) let help () = - Format.printf "@[%s@]@.@." !header_doc; - let get_param_from_doc doc = - match Str.split (Str.regexp "[ \n\r\x0c\t]+") doc with - | param :: doc -> param, (String.concat " " doc) - | _ -> failwith "Bad format for documentation" - in + (* Print the header *) + output_text !header_doc; + Format.printf "@.@."; - let anon = - List.filter (fun (x,_,_,_) -> x = ' ') !specs - |> List.map (fun x -> - match x with - | (_,name,doc,Without_arg) -> (name,doc,false) - | (_,name,doc,_) -> (name,doc,true) - ) - in + (* Find the anonymous arguments *) + let anon = + List.filter (fun x -> x.short = ' ') !specs + in - let options = - List.filter (fun (x,_,_,_) -> x <> ' ') !specs - |> List.sort (fun (x,_,_,_) (y,_,_,_) -> Char.compare x y) - |> List.map (fun x -> - match x with - | (short,long,doc,With_arg) -> (* with arg *) - let param, doc = get_param_from_doc doc in - (Printf.sprintf "-%c %s" short param, - Printf.sprintf "--%s=%s" long param, - doc) - | (short,long,doc,Without_arg) -> (* without arg *) - (Printf.sprintf "-%c" short, - Printf.sprintf "--%s" long, - doc) - | (short,long,doc,With_opt_arg) -> (* with or without arg *) - let param, doc = get_param_from_doc doc in - (Printf.sprintf "-%c [%s]" short param, - Printf.sprintf "--%s[=%s]" long param, - doc) - ) - in + (* Find the options *) + let options = + List.filter (fun x -> x.short <> ' ') !specs + |> List.sort (fun x y -> Char.compare x.short y.short) + in - let max_short = - List.map (fun (x,_,_) -> String.length x) options - |> List.fold_left max 0 - in - - let max_long = - List.map (fun (_,x,_) -> String.length x) options - |> List.fold_left max 0 - in - - let fmt_opt max_w o = - let l = String.length o in - o^(String.make (max_w-l) ' ') - in + (* Find column lengths *) + let max_width = + List.map (fun x -> + ( match x.arg with + | Without_arg -> String.length x.long + | With_arg arg -> String.length x.long + String.length arg + | With_opt_arg arg -> String.length x.long + String.length arg + 2 + ) + + ( if x.opt = Optional then 2 else 0) + ) !specs + |> List.fold_left max 0 + in - let output_option ?(fixed_width=false) (short, long, doc) = - if fixed_width then - Format.printf "@[%s %s@]" - (fmt_opt max_short short) (fmt_opt max_long long) - else - Format.printf "@[%s|%s@]" short long - in + (* Print usage *) + Format.printf "@[@[Usage:@,@,@[@[%s@]" Sys.argv.(0); + List.iter (fun x -> Format.printf "@ "; output_short x) options; + Format.printf "@ @[[--]@]"; + List.iter (fun x -> Format.printf "@ "; output_short x;) anon; + Format.printf "@]@,@]@,"; - let output_anon ?(fixed_width=false) (name, doc, optional) = - if optional then - Format.printf "@[[%s]@]" name - else - Format.printf "@[%s@]" name - in - Format.printf "@[@[Usage:@,@,@[@[%s@]" Sys.argv.(0); - List.iter (fun x -> - Format.printf "@ @[["; - output_option ~fixed_width:false x; - Format.printf "]@]" - ) options; - Format.printf "@ @[[--]@]"; - List.iter (fun x -> - Format.printf "@ @["; - output_anon ~fixed_width:false x; - Format.printf "@]" - ) anon; - Format.printf "@]@]@,@,"; + (* Print arguments and doc *) + Format.printf "@[Arguments:@,"; + Format.printf "@[" ; + List.iter (fun x -> Format.printf "@ "; output_long max_width x) anon; + Format.printf "@]@,@]@,"; - Format.printf "@[Arguments:@,"; - Format.printf "@[@," ; - List.iter (fun (name,doc,optional) -> - Format.printf "@["; - output_anon ~fixed_width:true (name,doc,optional); - Format.printf "@ @[%s@]@]@," doc - ) anon; - Format.printf "@]@;"; + (* Print options and doc *) + Format.printf "@[Options:@,"; - Format.printf "@[Options:@,"; + Format.printf "@[" ; + List.iter (fun x -> Format.printf "@ "; output_long max_width x) options; + Format.printf "@]@,@]@,"; + + + (* Print footer *) + if !description_doc <> "" then + begin + Format.printf "@[Description:@,@,"; + output_text !description_doc; + Format.printf "@," + end; + + (* Print footer *) + output_text !footer_doc; + Format.printf "@." - Format.printf "@[@," ; - List.iter (fun (short,long,doc) -> - Format.printf "@["; - output_option ~fixed_width:true (short,long,doc); - Format.printf "@ @[%s@]@]@," doc - ) options; - Format.printf "@]@;"; - Format.printf "@[%s@]@." !footer_doc let set_specs specs_in = - specs := ( 'h', "help", "Prints the help message", Without_arg) :: specs_in; + specs := { short='h' ; + long ="help" ; + doc ="Prints the help message." ; + arg =Without_arg ; + opt =Optional ; + } :: specs_in; - let specs = - List.filter (fun (x,_,_,_) -> x != ' ') !specs - |> List.map (fun x -> - match x with - | (short, long, doc, With_arg) -> - (short, long, None, Some (fun x -> Hashtbl.replace dict long x) ) - | (short, long, doc, Without_arg) -> - (short, long, Some (fun () -> Hashtbl.replace dict long ""), None) - | (short, long, doc, With_opt_arg) -> - (short, long, Some (fun () -> Hashtbl.replace dict long ""), - Some (fun x -> Hashtbl.replace dict long x) ) - ) - in + let cmd_specs = + List.filter (fun x -> x.short != ' ') !specs + |> List.map (fun { short ; long ; opt ; doc ; arg } -> + match arg with + | With_arg _ -> + (short, long, None, Some (fun x -> Hashtbl.replace dict long x) ) + | Without_arg -> + (short, long, Some (fun () -> Hashtbl.replace dict long ""), None) + | With_opt_arg _ -> + (short, long, Some (fun () -> Hashtbl.replace dict long ""), + Some (fun x -> Hashtbl.replace dict long x) ) + ) + in - Getopt.parse_cmdline specs (fun x -> anon_args := !anon_args @ [x]); + Getopt.parse_cmdline cmd_specs (fun x -> anon_args := !anon_args @ [x]); + + if show_help () then + (help () ; exit 0); + + (* Check that all mandatory arguments are set *) + List.filter (fun x -> x.short <> ' ' && x.opt = Mandatory) !specs + |> List.iter (fun x -> + match get x.long with + | Some _ -> () + | None -> failwith ("Error: --"^x.long^" option is missing.") + ) +;; - if show_help () then - (help () ; exit 0) let anon_args () = !anon_args + diff --git a/ocaml/Command_line.mli b/ocaml/Command_line.mli new file mode 100644 index 00000000..dde1d24e --- /dev/null +++ b/ocaml/Command_line.mli @@ -0,0 +1,126 @@ +(** Handles command-line arguments, using getopt. + +Example: + +let () = + + (* Command-line specs *) + let open Command_line in + begin + set_header_doc (Sys.argv.(0) ^ " - quantum_package command"); + + [ { short='c'; long="check"; opt=Optional; + doc="Checks the input data"; + arg=Without_arg; }; + + { short='n'; long="ndet"; opt=Optional; + doc="Truncate the wavefunction to the target number of determinants"; + arg=With_arg ""; }; + + { short='s'; long="state"; opt=Optional; + doc="Extract selected states, for example \"[1,3-5]\""; + arg=With_arg ""; }; + + anonymous "EZFIO_DIR" Mandatory "EZFIO directory"; + ] + |> set_specs ; + + set_description_doc + "Opens a text editor to edit the parameters of a EZFIO directory."; + end; + + + (* Handle options *) + let ndet = + match Command_line.get "ndet" with + | None -> None + | Some s -> (try Some (int_of_string s) + with _ -> failwith "[-n|--ndet] expects an integer") + in + let state = + match Command_line.get "state" with + | None -> None + | Some s -> (try Some (Range.of_string s) + with _ -> failwith "[-s|--state] expects a range") + in + + let c = Command_line.get_bool "check" in + + let filename = + match Command_line.anon_args () with + | [x] -> x + | _ -> (Command_line.help () ; failwith "EZFIO_DIR is missing") + in + + (* Run the program *) + run c ?ndet ?state filename + + +*) + + +type short_opt = char + +type long_opt = string + +type optional = Mandatory + | Optional + +type documentation = string + +type argument = With_arg of string + | Without_arg + | With_opt_arg of string + + +type description = +{ + short : short_opt; + long : long_opt; + opt : optional; + doc : documentation; + arg : argument; +} + + +(** Sets the header of the help message. *) +val set_header_doc : string -> unit + + +(** Sets the description of the help message. *) +val set_description_doc : string -> unit + +(** Sets the footer of the help message. *) +val set_footer_doc : string -> unit + + +(** Gets the value of an option. If the option is not set, returns [None]. If + the option is set, returns Some . *) +val get : string -> string option + + +(** Gets the value of an option with no argument. If the option is set, returns [true]. *) +val get_bool : string -> bool + + +(** True if the '-h' or "--help" option was found. *) +val show_help : unit -> bool + + +(** Creates a specification of an anonymous argument. *) +val anonymous : long_opt -> optional -> documentation -> description + + +(** Prints the help message *) +val help : unit -> unit + + +(** Sets the specification list as a list of tuples: + ( short option, long option, documentation, argument ) *) +val set_specs : description list -> unit + + +(** Returns the list of anonymous arguments *) +val anon_args : unit -> string list + + diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index 87b20fd2..17a5314f 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -69,7 +69,6 @@ let list_basis () = ) in List.sort basis_list ~compare:String.ascending - |> String.concat ~sep:"\n" (** Run the program *) @@ -648,36 +647,54 @@ let run ?o b au c d m p cart xyz_file = let () = - "=== Available basis sets === -" ^ (list_basis ()) ^ " + let open Command_line in + begin + "Creates an EZFIO directory from a standard xyz file or from a z-matrix file in Gaussian format. The basis set is defined as a single string if all the atoms are taken from the same basis set, otherwise specific elements can be defined as follows: -============================ + -b \"cc-pcvdz | H:cc-pvdz | C:6-31g\" + -b \"cc-pvtz | 1,H:sto-3g | 3,H:6-31g\" -Creates an EZFIO directory from a standard xyz file or from a z-matrix file -in Gaussian format. The basis set is defined as a single string if all the -atoms are taken from the same basis set, otherwise specific elements can be -defined as follows: +If a file with the same name as the basis set exists, this file will be read. Otherwise, the basis set is obtained from the database. +" |> set_description_doc ; + set_header_doc (Sys.argv.(0) ^ " - Quantum Package command"); - -b \"cc-pcvdz | H:cc-pvdz | C:6-31g\" - -b \"cc-pvtz | 1,H:sto-3g | 3,H:6-31g\" + [ { opt=Optional ; short='o'; long="output"; + arg=With_arg "EZFIO_DIR"; + doc="Name of the created EZFIO directory."} ; -If a file with the same name as the basis set exists, this file will be read. -Otherwise, the basis set is obtained from the database. + { opt=Mandatory; short='b'; long="basis"; + arg=With_arg ""; + doc="Name of basis set. If =show, the list of all basis sets is displayed."} ; -" |> Command_line.set_header_doc ; + { opt=Optional ; short='a'; long="au"; + arg=Without_arg; + doc="Input geometry is in atomic units."} ; - [ ( 'o', "output", " Name of the created EZFIO file.", Command_line.With_arg) ; - ( 'b', "basis", " Name of basis set.", Command_line.With_arg) ; - ( 'a', "au", "Input geometry is in atomic units.", Command_line.Without_arg) ; - ( 'c', "charge", " Total charge of the molecule. Default is 0.", Command_line.With_arg) ; - ( 'd', "dummy", " Add dummy atoms. x * (covalent radii of the atoms)", Command_line.With_arg); - ( 'm', "multiplicity", " Spin multiplicity (2S+1) of the molecule. Default is 1.", Command_line.With_arg); - ( 'p', "pseudo", " Name of the pseudopotential.", Command_line.With_arg); - ( 'x', "cartesian", "Compute AOs in the Cartesian basis set (6d, 10f, ...)", Command_line.Without_arg); - Command_line.anonymous "(xyz_file|zmt_file)" "input file in xyz format or z-matrix." - ] - |> Command_line.set_specs ; + { opt=Optional ; short='c'; long="charge"; + arg=With_arg ""; + doc="Total charge of the molecule. Default is 0."} ; + + { opt=Optional ; short='d'; long="dummy"; + arg=With_arg ""; + doc="Add dummy atoms. x * (covalent radii of the atoms)."} ; + + { opt=Optional ; short='m'; long="multiplicity"; + arg=With_arg ""; + doc="Spin multiplicity (2S+1) of the molecule. Default is 1."} ; + + { opt=Optional ; short='p'; long="pseudo"; + arg=With_arg ""; + doc="Name of the pseudopotential."} ; + + { opt=Optional ; short='x'; long="cartesian"; + arg=Without_arg; + doc="Compute AOs in the Cartesian basis set (6d, 10f, ...)."} ; + + anonymous "FILE" Mandatory "Input file in xyz format or z-matrix."; + ] + |> set_specs + end; (* Handle options *) @@ -687,7 +704,7 @@ Otherwise, the basis set is obtained from the database. let basis = match Command_line.get "basis" with - | None -> (Command_line.help () ; failwith "Error: [-b|--basis] option is missing.") + | None -> assert false | Some x -> x in @@ -721,6 +738,13 @@ Otherwise, the basis set is obtained from the database. Command_line.get_bool "cartesian" in + if basis = "show" then + begin + list_basis () + |> List.iter ~f:print_endline; + exit 0 + end; + let xyz_filename = match Command_line.anon_args () with | [x] -> x diff --git a/ocaml/qp_run.ml b/ocaml/qp_run.ml index f32b49c8..99cfa0b1 100644 --- a/ocaml/qp_run.ml +++ b/ocaml/qp_run.ml @@ -141,34 +141,32 @@ let run slave ?prefix exe ezfio_file = let () = (* Command-line specs *) - "Executes a Quantum Package binary file among these:\n\n" -^ (Lazy.force Qpackage.executables - |> List.map (fun (x,_) -> Printf.sprintf " * %s" x ) - |> String.concat "\n" - ) |> Command_line.set_header_doc; + let open Command_line in + begin + set_header_doc (Sys.argv.(0) ^ " - Quantum Package command"); + "Executes a Quantum Package binary file among these:\n\n" + ^ (Lazy.force Qpackage.executables + |> List.map (fun (x,_) -> Printf.sprintf " * %s" x ) + |> String.concat "\n") + |> set_description_doc; - [ ( 's', "slave", "Required to run slave tasks in distributed environments", - Command_line.Without_arg); - ( 'p', "prefix", " Prefix before running the program, like gdb or valgrind", - Command_line.With_arg ); - Command_line.anonymous "PROGRAM" "Name of the QP program to be run"; - Command_line.anonymous "EZFIO_DIR" "EZFIO directory"; + [ { short='s'; long="slave"; opt=Optional; + doc="Required to run slave tasks in distributed environments."; + arg=Without_arg; }; + + { short='p'; long="prefix"; opt=Optional; + doc="Prefix before running the program, like gdb or valgrind."; + arg=With_arg ""; }; + + anonymous "PROGRAM" Mandatory "Name of the QP program to be run"; + anonymous "EZFIO_DIR" Mandatory "EZFIO directory"; ] - |> Command_line.set_specs ; - + |> set_specs ; + end; (* Handle options *) - if Command_line.show_help () then - exit 0; - - let slave = - match Command_line.get "slave" with - | None -> false - | _ -> true - in - - let prefix = - Command_line.get "prefix" + let slave = Command_line.get_bool "slave" + and prefix = Command_line.get "prefix" in (* Run the program *) diff --git a/ocaml/qp_set_mo_class.ml b/ocaml/qp_set_mo_class.ml index d49288c8..fe3348d9 100644 --- a/ocaml/qp_set_mo_class.ml +++ b/ocaml/qp_set_mo_class.ml @@ -314,30 +314,50 @@ let default range = let () = - "Set the orbital classes in an EZFIO directory. -The range of MOs has the form : \"[36-53,72-107,126-131]\"." |> Command_line.set_header_doc ; + let open Command_line in + begin + "Set the orbital classes in an EZFIO directory. The range of MOs has the form : \"[36-53,72-107,126-131]\"." + |> set_footer_doc ; - [ ( 'c', "core", "range Range of core MOs", Command_line.With_opt_arg); - ( 'i', "inact", "range Range of inactive MOs", Command_line.With_opt_arg); - ( 'a', "act", "range Range of active MOs", Command_line.With_opt_arg); - ( 'v', "virt", "range Range of virtual MOs", Command_line.With_opt_arg); - ( 'd', "del", "range Range of deleted MOs", Command_line.With_opt_arg); - ( 'q', "query", "Print the current MOs classes", Command_line.Without_arg); - Command_line.anonymous "" "EZFIO directory"; - ] |> Command_line.set_specs ; + [ { opt=Optional ; short='c'; long="core"; + arg=With_arg ""; + doc="Range of core MOs." }; + + { opt=Optional ; short='i'; long="inact"; + arg=With_arg ""; + doc="Range of inactive MOs." }; + + { opt=Optional ; short='a'; long="act"; + arg=With_arg ""; + doc="Range of active MOs." }; + + { opt=Optional ; short='v'; long="virt"; + arg=With_arg ""; + doc="Range of virtual MOs." }; + + { opt=Optional ; short='d'; long="del"; + arg=With_arg ""; + doc="Range of deleted MOs." }; + + { opt=Optional ; short='q'; long="query"; + arg=Without_arg; + doc="Print the current MO classes." }; + + anonymous "EZFIO_DIR" Mandatory "EZFIO directory."; + ] |> set_specs + end; (* Handle options *) - if Command_line.show_help () then - exit 0; let core = Command_line.get "core" and inact = Command_line.get "inact" and act = Command_line.get "act" and virt = Command_line.get "virt" and del = Command_line.get "del" - and q = Command_line.get_bool "q" + and q = Command_line.get_bool "query" in + let ezfio_filename = match Command_line.anon_args () with | [x] -> x diff --git a/scripts/get_basis b/scripts/get_basis index e3687e71..84232aa4 100755 --- a/scripts/get_basis +++ b/scripts/get_basis @@ -39,10 +39,10 @@ do done if [[ $? -ne 0 ]] ; then - echo "==================================================" 1>& 2 - echo "Unable to create temporary file $tmpfile" 1>& 2 - echo "==================================================" 1>& 2 - echo "ERROR" + >&2 echo "==================================================" + >&2 echo "Unable to create temporary file $tmpfile" + >&2 echo "==================================================" + >&2 echo "ERROR" exit 1 fi diff --git a/scripts/qp_convert_output_to_ezfio b/scripts/qp_convert_output_to_ezfio index 002a5ad3..56266109 100755 --- a/scripts/qp_convert_output_to_ezfio +++ b/scripts/qp_convert_output_to_ezfio @@ -3,11 +3,11 @@ convert output of GAMESS/GAU$$IAN to ezfio Usage: - qp_convert_output_to_ezfio [-o EZFIO_DIR|--output=EZFIO_DIR] + qp_convert_output_to_ezfio [-o EZFIO_DIR] FILE Options: - -o EZFIO_DIR --output=EZFIO_DIR Produced directory - by default is file.out.ezfio + -o --output=EZFIO_DIR Produced directory + by default is FILE.ezfio """ @@ -342,7 +342,7 @@ def get_full_path(file_path): if __name__ == '__main__': ARGUMENTS = docopt(__doc__) - FILE = get_full_path(ARGUMENTS['']) + FILE = get_full_path(ARGUMENTS['FILE']) if ARGUMENTS["--output"]: EZFIO_FILE = get_full_path(ARGUMENTS["--output"]) diff --git a/scripts/qp_e_conv_fci b/scripts/qp_e_conv_fci index 4f83c807..78f05777 100755 --- a/scripts/qp_e_conv_fci +++ b/scripts/qp_e_conv_fci @@ -2,7 +2,7 @@ file=$1 if [[ -z ${QP_ROOT} ]] ; then - 2>& echo "please source quantum_package.rc" + >&2 echo "please source quantum_package.rc" exit 1 fi source ${QP_ROOT}/quantum_package.rc diff --git a/scripts/qp_set_frozen_core b/scripts/qp_set_frozen_core index 2f4c7673..ac5eab45 100755 --- a/scripts/qp_set_frozen_core +++ b/scripts/qp_set_frozen_core @@ -13,7 +13,7 @@ zero. Usage: - qp_set_frozen_core [-q|--query] + qp_set_frozen_core [-q|--query] EZFIO_DIR Options: -q --query Prints in the standard output the number of frozen MOs @@ -37,7 +37,7 @@ from ezfio import ezfio def main(arguments): """Main function""" - filename = arguments[""] + filename = arguments["EZFIO_DIR"] ezfio.set_filename(filename) n_frozen = 0 diff --git a/scripts/remove_trailing_spaces b/scripts/remove_trailing_spaces index 2d4a253c..c808c70b 100755 --- a/scripts/remove_trailing_spaces +++ b/scripts/remove_trailing_spaces @@ -10,7 +10,7 @@ if [[ -n $1 ]] ; then exec sed --in-place 's| *$||' $1 else - 2>& echo "Usage: $0 FILE" + >&2 echo "Usage: $0 FILE" exit 1 fi