-
Notifications
You must be signed in to change notification settings - Fork 228
/
rmg.py
118 lines (97 loc) · 4.92 KB
/
rmg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python-jl
###############################################################################
# #
# RMG - Reaction Mechanism Generator #
# #
# Copyright (c) 2002-2023 Prof. William H. Green ([email protected]), #
# Prof. Richard H. West ([email protected]) and the RMG Team ([email protected]) #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the 'Software'), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, sublicense, #
# and/or sell copies of the Software, and to permit persons to whom the #
# Software is furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
###############################################################################
"""
RMG is an automatic chemical mechanism generator. It is awesomely awesome.
"""
import os.path
import logging
# Before importing any RMG modules, check Python version
try:
import utilities
except ImportError: # This is likely the binary install version, which does not include utilities
# If this is in fact the binary version, conda has ensured that the python version is correct.
# It is okay to skip this test here
utilities = None
else:
utilities.check_python()
import rmgpy
from rmgpy.rmg.main import RMG, initialize_log, process_profile_stats, make_profile_graph
from rmgpy.util import parse_command_line_arguments
################################################################################
def main():
# Parse the command-line arguments (requires the argparse module)
args = parse_command_line_arguments()
if args.postprocess:
logging.info("Postprocessing the profiler statistics (will be appended to RMG.log)")
else:
# Initialize the logging system (resets the RMG.log file)
level = logging.INFO
if args.debug:
level = 0
elif args.verbose:
level = logging.DEBUG
elif args.quiet:
level = logging.WARNING
initialize_log(level, os.path.join(args.output_directory, 'RMG.log'))
logging.info(rmgpy.settings.report())
kwargs = {
'restart': args.restart,
'walltime': args.walltime,
'maxproc': args.maxproc,
'kineticsdatastore': args.kineticsdatastore,
'max_iterations': args.maxiter,
}
if args.profile:
import cProfile
rmg_profiler = cProfile.Profile()
stats_file = os.path.join(args.output_directory, 'RMG.profile')
global_vars = {}
local_vars = {
'inputFile': args.file,
'output_dir': args.output_directory,
'kwargs': kwargs,
'RMG': RMG,
'rmg_profiler': rmg_profiler,
}
command = """rmg = RMG(input_file=inputFile, output_directory=output_dir, profiler=rmg_profiler); rmg.execute(**kwargs)"""
print("Running under cProfile")
if not args.postprocess:
# actually run the program!
rmg_profiler.runctx(command, global_vars, local_vars)
rmg_profiler.dump_stats(stats_file)
# postprocess the stats
log_file = os.path.join(args.output_directory, 'RMG.log')
process_profile_stats(stats_file, log_file)
# Make the profile graph. Force graph generation regardless of display status if args.postprocess
make_profile_graph(stats_file, force_graph_generation=args.postprocess)
else:
rmg = RMG(input_file=args.file, output_directory=args.output_directory)
rmg.execute(**kwargs)
################################################################################
if __name__ == '__main__':
main()