-
Notifications
You must be signed in to change notification settings - Fork 8
/
rpmdrate.py
191 lines (158 loc) · 8.81 KB
/
rpmdrate.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python
# encoding: utf-8
################################################################################
#
# RPMDrate - Bimolecular reaction rates via ring polymer molecular dynamics
#
# Copyright (c) 2012 by Joshua W. Allen (jwallen@mit.edu)
# William H. Green (whgreen@mit.edu)
# Yury V. Suleimanov (ysuleyma@mit.edu, ysuleyma@princeton.edu)
#
# 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.
#
################################################################################
"""
This is the main execution script for RPMD, a tool for using ring polymer
molecular dynamics simulations to compute properties of chemical systems,
including, but not limited to, chemical reaction rates. To use, simply pass the
path to an RPMD input file on the command line, e.g. ::
$ python rpmdrate.py examples/H+CH4/input.py 1000 1
You can also explicitly set the number of processors to use using the ``-p``
flag, e.g. ::
$ python rpmdrate.py examples/H+CH4/input.py 1000 1 -p 8
Only one processor is used by default.
"""
import os.path
import sys
import time
import argparse
import logging
################################################################################
def parseCommandLineArguments():
parser = argparse.ArgumentParser()
parser.add_argument('file', metavar='FILE', type=str, nargs=1, help='a file describing the job to execute')
parser.add_argument('T', metavar='TEMP', type=float, nargs=1, help='the temperature in K')
parser.add_argument('Nbeads', metavar='BEADS', type=int, nargs=1, help='the number of beads')
parser.add_argument('-p', '--processes', metavar='PROC', type=int, nargs=1, default=[1], help='the number of processors to use')
# Options for controlling the amount of information printed to the console
# By default a moderate level of information is printed; you can either
# ask for less (quiet), more (verbose), or much more (debug)
group = parser.add_mutually_exclusive_group()
group.add_argument('-q', '--quiet', action='store_const', const=logging.WARNING, default=logging.INFO, dest='verbose', help='only print warnings and errors')
group.add_argument('-v', '--verbose', action='store_const', const=logging.DEBUG, default=logging.INFO, dest='verbose', help='print more verbose output')
group.add_argument('-d', '--debug', action='store_const', const=0, default=logging.INFO, dest='verbose', help='print debug information')
return parser.parse_args()
################################################################################
def initializeLog(verbose, logFile=None):
"""
Set up a logger for PyRate to use to print output to stdout. The
`verbose` parameter is an integer specifying the amount of log text seen
at the console; the levels correspond to those of the :data:`logging` module.
"""
# Create logger
logger = logging.getLogger()
logger.setLevel(verbose)
# Use custom level names for cleaner log output
logging.addLevelName(logging.CRITICAL, 'Critical: ')
logging.addLevelName(logging.ERROR, 'Error: ')
logging.addLevelName(logging.WARNING, 'Warning: ')
logging.addLevelName(logging.INFO, '')
logging.addLevelName(logging.DEBUG, '')
logging.addLevelName(0, '')
# Create formatter and add to handlers
formatter = logging.Formatter('%(levelname)s%(message)s')
# Remove old handlers before adding ours
while logger.handlers:
logger.removeHandler(logger.handlers[0])
# Create console handler; send everything to stdout rather than stderr
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(verbose)
ch.setFormatter(formatter)
logger.addHandler(ch)
# Create file handler; always be at least verbose in the file
if logFile:
fh = logging.FileHandler(filename=logFile)
fh.setLevel(min(logging.DEBUG,verbose))
fh.setFormatter(formatter)
logger.addHandler(fh)
################################################################################
def logHeader(level=logging.INFO):
"""
Output a header containing identifying information about RPMDrate to the
log.
"""
logging.log(level, 'RPMDrate execution initiated at {0}'.format(time.asctime()))
logging.log(level, '')
logging.log(level, '###############################################################')
logging.log(level, '# #')
logging.log(level, '# ******** #')
logging.log(level, '# RPMDrate #')
logging.log(level, '# ******** #')
logging.log(level, '# #')
logging.log(level, '# Version: 0.1.0 (15 Jun 2012) #')
logging.log(level, '# #')
logging.log(level, '# Authors: Joshua W. Allen <jwallen@mit.edu> #')
logging.log(level, '# William H. Green <whgreen@mit.edu> #')
logging.log(level, '# Yury V. Suleimanov <ysuleyma@mit.edu> #')
logging.log(level, '# <ysuleyma@princeton.edu> #')
logging.log(level, '# #')
logging.log(level, '# Website: http://github.com/GreenGroup/RPMDrate #')
logging.log(level, '# #')
logging.log(level, '###############################################################')
logging.log(level, '')
################################################################################
def logFooter(level=logging.INFO):
"""
Output a footer to the log.
"""
logging.log(level, '')
logging.log(level, 'RPMDrate execution terminated at {0}'.format(time.asctime()))
################################################################################
if __name__ == '__main__':
# Parse the command-line arguments (requires the argparse module)
args = parseCommandLineArguments()
# Determine the output directory
outputDirectory = os.path.dirname(os.path.abspath(args.file[0]))
# Initialize the logging system (both to the console and to a file in the
# output directory)
initializeLog(args.verbose, os.path.join(outputDirectory, 'pyrate.log'))
# Print some information to the beginning of the log
logHeader()
# Load the input file for the job
from rpmdrate.input import loadInputFile
system, jobList = loadInputFile(args.file[0], args.T[0], args.Nbeads[0], args.processes[0])
logging.info('')
# Run the requested jobs
for job, params in jobList:
if job == 'configurations':
dt, evolutionTime, xi_list, kforce = params
system.generateUmbrellaConfigurations(dt, evolutionTime, xi_list, kforce)
elif job == 'umbrella':
dt, windows, saveTrajectories = params
system.conductUmbrellaSampling(dt, windows, saveTrajectories)
elif job == 'PMF':
windows, xi_min, xi_max, bins = params
system.computePotentialOfMeanForce(windows, xi_min, xi_max, bins)
elif job == 'recrossing':
dt, equilibrationTime, childTrajectories, childSamplingTime, childrenPerSampling, childEvolutionTime, xi_current, saveParentTrajectory, saveChildTrajectories = params
system.computeRecrossingFactor(dt, equilibrationTime, childTrajectories, childSamplingTime, childrenPerSampling, childEvolutionTime, xi_current, saveParentTrajectory, saveChildTrajectories)
elif job == 'rate':
system.computeRateCoefficient()
# Print some information to the end of the log
logFooter()