-
Notifications
You must be signed in to change notification settings - Fork 8
/
production.py
executable file
·253 lines (213 loc) · 11.1 KB
/
production.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env python
"""
This program will launch a minimization job to the local PBS server. The
convention followed is to strip the suffix from the topology file and use
that as the prefix for all other output files. This program will append
".prod.xxxxx" for each file name, respectively. All trajectories are NetCDF
"""
from pbsjob import PBS_Script
import amber_simulations as am_sim
from optparse import OptionParser, OptionGroup
import os, sys
class ProductionError(Exception): pass
usage = '%prog [options] <prmtop> <inpcrd> [<cpin>]'
parser = OptionParser(usage=usage)
group = OptionGroup(parser, 'Timing Options',
'These options control how long the simulation is run')
group.add_option('--nstlim', dest='nstlim', default=50000, type='int',
help='Number of MD steps to run. Default 50000')
group.add_option('--print-frequency', dest='print_frequency', default=1000,
type='int', help='How frequently to print energies to ' +
'mdout, coordinates to trajectory, and 1/10th of the ' +
'frequency to print a restart file. Default 1000')
group.add_option('--dt', dest='dt', default=0.002, type='float',
help='Time step in fs. Default %default')
group.add_option('--cuda', dest='cuda', default=False, action='store_true',
help='Run this on pmemd.CUDA')
parser.add_option_group(group)
group = OptionGroup(parser, 'Temperature/Pressure Control',
'These options control the barostat and thermostat options')
group.add_option('--temp', dest='temp0', type='float', default=300.0,
help='Final target temperature. Default 300.0')
group.add_option('--thermostat', dest='thermostat', default='berendsen',
help="Thermostat to use. Allowed values are 'berendsen' " +
"and 'langevin'. Default 'berendsen'.")
group.add_option('--t-couple', dest='t_couple', default=10.0, type='float',
help='Temperature coupling parameter (tautp for berendsen, ' +
'gamma_ln for langevin). Default 10.0')
group.add_option('--barostat', dest='barostat', default='none',
help="Barostat to use. Allowed values are 'berendsen' and " +
"'none'. Default 'none'.")
group.add_option('--p-couple', dest='p_couple', default=10.0, type='float',
help='Pressure coupling parameter (taup). Default 10.0')
parser.add_option_group(group)
group = OptionGroup(parser, 'Implicit Solvent Options',
'These are the implicit solvation options')
group.add_option('--igb', dest='igb', default=5, type='int',
help='GB model to run for non-periodic systems. Must be ' +
'1, 2, 5, 7, or 8. Default 5')
parser.add_option_group(group)
group = OptionGroup(parser, 'Restraint Options',
'These options control cartesian restraints to be applied')
group.add_option('--restrain', dest='rst_wt', default=0, type='float',
help='Restraint weight to put on restraint mask. 0 means ' +
'no restraint. Default 0.')
group.add_option('--restraint-mask', dest='rst_mask', default='@CA,C,O,N',
help='Restraint mask for restrained minimization. Default ' +
'"@CA,C,O,N"')
parser.add_option_group(group)
group = OptionGroup(parser, 'Constant pH Options', 'These options control ' +
'the constant pH MD settings if a CPIN is provided')
group.add_option('--constpH', dest='solvph', default=7.0, type='float',
help='pH value to run constant pH simulation. Default 7.0.')
group.add_option('--ntcnstph', dest='ntcnstph', default=5, type='int',
help='Frequency of protonation change attempts. Default ' +
'every 5 time steps.')
group.add_option('--ntrelax', dest='ntrelax', default=500, type='int',
help='The number of steps to relax explicit solvent after ' +
'a protonation change. Default 500.')
parser.add_option_group(group)
group = OptionGroup(parser, 'File Naming Options', 'These options control ' +
'the file names generated by the simulation')
group.add_option('--label', dest='label', default='prod',
help='Label to apply after the prefix to output files. ' +
'Default "prod".')
parser.add_option_group(group)
group = OptionGroup(parser, 'PBS Options', 'These are the options given to ' +
'the scheduler when the job is submitted or the jobfile ' +
'is written')
group.add_option('--nproc', dest='nproc', default='1',
help='Number of processors to use. Fields are ,-delimited ' +
'and must fit into the processor-count format required by ' +
'the local PBS configuration')
group.add_option('--walltime', dest='walltime', default='30:00',
help='How long to ask PBS for resources. Default 30:00')
group.add_option('--name', dest='job_name', default=None,
help='Name to give to PBS job. None will give a random ' +
'Final Fantasy character name.')
group.add_option('--delay', dest='jobid', default=None,
help='If present, will delay the present job until after ' +
'the give job ID is complete successfully')
group.add_option('--force', dest='ask', default=True, action='store_false',
help='Do not ask confirmation before submitting.')
group.add_option('--ask', dest='ask', action='store_true',
help='Ask confirmation before submitting. Overrides ' +
'previous --force. Default behavior.')
group.add_option('--print-jobfile', dest='jobfile', default=None,
help='Print the PBS jobfile instead of submitting it ' +
'directly to the queue. Providing no name will bypass this ' +
'step.')
group.add_option('--pbs-nproc', dest='pbs_nproc', default=None,
help='In the case that --nproc is not applicable to allowed' +
' resource requests, this will be used for PBS instead.')
group.add_option('--queue', dest='pbs_queue', default=None,
help='To override the default queue in ~/.pbsdefaults')
group.add_option('--pbs-template', dest='pbs_template',
default=os.path.join(os.getenv('HOME'), '.pbsdefaults'),
help='PBS template file to use for job. Defaults to ' +
'~/.pbsdefaults')
group.add_option('--no-pbs', dest='pbs', default=True, action='store_false',
help='Just run using os.system(), not via PBS')
parser.add_option_group(group)
(opt, args) = parser.parse_args()
if not len(args) in [2,3]:
print >> sys.stderr, 'Bad command-line arguments!'
parser.print_help()
sys.exit(1)
amsys = am_sim.AmberSystem(args[0], args[1])
if not amsys.periodic() and not opt.igb in [1,2,5,7,8]:
raise ProductionError('Bad igb value (%d)' % opt.igb)
if opt.nstlim < 0:
raise ProductionError('Bad nstlim value (%d)' % opt.nstlim)
if len(args) == 2:
prod_input = am_sim.Production(amsys, nstlim=opt.nstlim, igb=opt.igb,
restrained=bool(opt.rst_wt),rst_wt=opt.rst_wt,
rst_mask=opt.rst_mask, temp0=opt.temp0,
thermostat=opt.thermostat,
thermostat_param=opt.t_couple,
barostat=opt.barostat,
barostat_param=opt.p_couple,
ntpr=opt.print_frequency,
ntwx=opt.print_frequency,
ntwr=opt.print_frequency * 10, dt=opt.dt)
else:
prod_input = am_sim.ConstantpH(amsys, nstlim=opt.nstlim, igb=opt.igb,
restrained=bool(opt.rst_wt),rst_wt=opt.rst_wt,
rst_mask=opt.rst_mask, temp0=opt.temp0,
thermostat=opt.thermostat,
thermostat_param=opt.t_couple,
barostat=opt.barostat,
barostat_param=opt.p_couple,
ntpr=opt.print_frequency,
ntwx=opt.print_frequency,
ntwr=opt.print_frequency * 10,
ntcnstph=opt.ntcnstph, ntrelax=opt.ntrelax,
solvph=opt.solvph, dt=opt.dt)
# Get the prefix
prefix = os.path.splitext(args[0])[0]
# Print the mdin file
prod_input.write_mdin('%s.%s.mdin' % (prefix, opt.label))
# Get the MPI command (mpiexec -n $NPROC, for example)
mpi_cmd = am_sim.get_mpi_cmd()
# Determine if we're doing parallel simulations
nproc = opt.nproc.split(',')
nproc = [int(i) for i in nproc]
parallel = False
for n in nproc:
if n > 1: parallel = True
# Set up the command string
if parallel:
if len(args) == 2:
if opt.cuda: prog_str = '%s pmemd.cuda.MPI -O' % mpi_cmd
else: prog_str = '%s pmemd.MPI -O ' % mpi_cmd
else: prog_str = '%s sander.MPI -O ' % mpi_cmd
else:
if len(args) == 2:
if opt.cuda: 'pmemd.cuda -O'
else: prog_str = 'pmemd -O '
else: prog_str = 'sander -O'
if opt.pbs:
# Make the PBS_Script instance
pbs_job = PBS_Script(template=opt.pbs_template)
# Change the queue if desired
if opt.pbs_queue: pbs_job.queue = opt.pbs_queue
# Set the PBS job name
pbs_job.set_name(opt.job_name)
# Determine processor count
nproc = opt.nproc.split(',')
nproc = [int(i) for i in nproc]
if not opt.pbs_nproc: pbs_nproc = nproc[:]
else:
pbs_nproc = opt.pbs_nproc.split(',')
pbs_nproc = [int(i) for i in pbs_nproc]
pbs_job.set_proc_count(pbs_nproc)
# Set walltime
pbs_job.set_walltime(opt.walltime)
cmd_str = ("%s -i %s.%s.mdin -p %s -c %s -r %s.%s.rst7 -o %s.%s." +
"mdout -inf %s.%s.mdinfo -x %s.%s.nc -suffix %s") % (prog_str,
prefix, opt.label, args[0], args[1], prefix, opt.label, prefix,
opt.label, prefix, opt.label, prefix, opt.label, prefix)
if opt.rst_wt:
cmd_str += " -ref %s" % args[1]
if len(args) == 3:
cmd_str += " -cpin %s -cpout %s.%s.cpout -cprestrt %s.%s.cpin" % (args[2],
prefix, opt.label, prefix, opt.label)
pbs_job.add_command(cmd_str)
# If we just want to print the jobfile
if opt.jobfile:
pbs_job.print_submit(opt.jobfile)
elif opt.ask:
pbs_job.submit_ask(after_job=opt.jobid)
else:
pbs_job.submit(after_job=opt.jobid)
else:
cmd_str = ("%s -i %s.%s.mdin -p %s -c %s -r %s.%s.rst7 -o %s.%s." +
"mdout -inf %s.%s.mdinfo -x %s.%s.nc -suffix %s") % (prog_str,
prefix, opt.label, args[0], args[1], prefix, opt.label, prefix,
opt.label, prefix, opt.label, prefix, opt.label, prefix)
if opt.rst_wt:
cmd_str += " -ref %s" % args[1]
if len(args) == 3:
cmd_str += " -cpin %s -cpout %s.%s.cpout -cprestrt %s.%s.cpin" % (args[2],
prefix, opt.label, prefix, opt.label)
os.system(cmd_str)