|
34 | 34 | from __future__ import print_function |
35 | 35 |
|
36 | 36 | import os.path |
37 | | -import argparse |
38 | 37 | import logging |
39 | 38 |
|
40 | 39 | # Before importing any RMG modules, check Python version |
|
43 | 42 |
|
44 | 43 | import rmgpy |
45 | 44 | from rmgpy.rmg.main import RMG, initialize_log, process_profile_stats, make_profile_graph |
46 | | - |
| 45 | +from rmgpy.util import parse_command_line_arguments |
47 | 46 |
|
48 | 47 | ################################################################################ |
49 | 48 |
|
50 | 49 |
|
51 | | -def parse_command_line_arguments(command_line_args=None): |
52 | | - """ |
53 | | - Parse the command-line arguments being passed to RMG Py. This uses the |
54 | | - :mod:`argparse` module, which ensures that the command-line arguments are |
55 | | - sensible, parses them, and returns them. |
56 | | - """ |
57 | | - |
58 | | - parser = argparse.ArgumentParser(description='Reaction Mechanism Generator (RMG) is an automatic chemical reaction ' |
59 | | - 'mechanism generator that constructs kinetic models composed of ' |
60 | | - 'elementary chemical reaction steps using a general understanding of ' |
61 | | - 'how molecules react.') |
62 | | - |
63 | | - parser.add_argument('file', metavar='FILE', type=str, nargs=1, |
64 | | - help='a file describing the job to execute') |
65 | | - |
66 | | - # Options for controlling the amount of information printed to the console |
67 | | - # By default a moderate level of information is printed; you can either |
68 | | - # ask for less (quiet), more (verbose), or much more (debug) |
69 | | - group = parser.add_mutually_exclusive_group() |
70 | | - group.add_argument('-q', '--quiet', action='store_true', help='only print warnings and errors') |
71 | | - group.add_argument('-v', '--verbose', action='store_true', help='print more verbose output') |
72 | | - group.add_argument('-d', '--debug', action='store_true', help='print debug information') |
73 | | - |
74 | | - # Add options for controlling what directories files are written to |
75 | | - parser.add_argument('-o', '--output-directory', type=str, nargs=1, default='', |
76 | | - metavar='DIR', help='use DIR as output directory') |
77 | | - |
78 | | - # Add restart option |
79 | | - parser.add_argument('-r', '--restart', type=str, nargs=1, metavar='path/to/seed/', help='restart RMG from a seed', |
80 | | - default='') |
81 | | - |
82 | | - parser.add_argument('-p', '--profile', action='store_true', |
83 | | - help='run under cProfile to gather profiling statistics, and postprocess them if job completes') |
84 | | - parser.add_argument('-P', '--postprocess', action='store_true', |
85 | | - help='postprocess profiling statistics from previous [failed] run; does not run the simulation') |
86 | | - |
87 | | - parser.add_argument('-t', '--walltime', type=str, nargs=1, default='00:00:00:00', |
88 | | - metavar='DD:HH:MM:SS', help='set the maximum execution time') |
89 | | - |
90 | | - # Add option to select max number of processes for reaction generation |
91 | | - parser.add_argument('-n', '--maxproc', type=int, nargs=1, default=1, |
92 | | - help='max number of processes used during reaction generation') |
93 | | - |
94 | | - # Add option to output a folder that stores the details of each kinetic database entry source |
95 | | - parser.add_argument('-k', '--kineticsdatastore', action='store_true', |
96 | | - help='output a folder, kinetics_database, that contains a .txt file for each reaction family ' |
97 | | - 'listing the source(s) for each entry') |
98 | | - |
99 | | - args = parser.parse_args(command_line_args) |
100 | | - |
101 | | - # Process args to set correct default values and format |
102 | | - |
103 | | - # For output and scratch directories, if they are empty strings, set them |
104 | | - # to match the input file location |
105 | | - args.file = args.file[0] |
106 | | - |
107 | | - # If walltime was specified, retrieve this string from the element 1 list |
108 | | - if args.walltime != '00:00:00:00': |
109 | | - args.walltime = args.walltime[0] |
110 | | - |
111 | | - if args.restart: |
112 | | - args.restart = args.restart[0] |
113 | | - |
114 | | - if args.maxproc != 1: |
115 | | - args.maxproc = args.maxproc[0] |
116 | | - |
117 | | - # Set directories |
118 | | - input_directory = os.path.abspath(os.path.dirname(args.file)) |
119 | | - |
120 | | - if args.output_directory == '': |
121 | | - args.output_directory = input_directory |
122 | | - # If output directory was specified, retrieve this string from the element 1 list |
123 | | - else: |
124 | | - args.output_directory = args.output_directory[0] |
125 | | - |
126 | | - if args.postprocess: |
127 | | - args.profile = True |
128 | | - |
129 | | - return args |
130 | | - |
131 | | - |
132 | 50 | def main(): |
133 | 51 | # Parse the command-line arguments (requires the argparse module) |
134 | 52 | args = parse_command_line_arguments() |
|
0 commit comments