-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathheating.py
executable file
·203 lines (166 loc) · 8.58 KB
/
heating.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
#!/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
".heat.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 HeatingError(Exception): pass
parser = OptionParser(usage='%prog [options] <prmtop> <inpcrd>')
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 heating steps to run. Default 50000')
group.add_option('--dt', dest='dt', default=0.002, type='float',
help='Time step in fs. Default %default')
parser.add_option_group(group)
group = OptionGroup(parser, 'Implicit solvent options',
'These options control the Implicit Solvent model used')
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, 'Temperature Control',
'These options control the barostat and thermostat options')
group.add_option('--slow-heat', dest='slow', default=False,action='store_true',
help='Use NMR restraints to heat slowly to the target ' +
'temperature over 2/3 of the simulation. Default is no.')
group.add_option('--normal-heat', dest='slow', action='store_false',
help='Do not use NMR restraints to heat slowly. Default ' +
'behavior. Will override previous --slow-heat.')
group.add_option('--initial-temp', dest='tempi', type='float', default=10.0,
help='Temperature to begin heating from. Default 10.0')
group.add_option('--final-temp', dest='temp0', type='float', default=300.0,
help='Final target temperature. Default 300.0')
group.add_option('--thermostat', dest='thermostat', default='langevin',
help="Thermostat to use. Allowed values are 'berendsen' " +
"and 'langevin'. Default 'langevin'.")
group.add_option('--t-couple', dest='t_couple', default=5.0,
help='Temperature coupling parameter (tautp for berendsen, ' +
'gamma_ln for langevin). Default 5.0')
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')
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 len(args) != 2:
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 HeatingError('Bad igb value (%d)' % opt.igb)
if opt.nstlim < 0:
raise HeatingError('Bad nstlim value (%d)' % opt.nstlim)
heat_input = am_sim.Heating(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,
tempi=opt.tempi, slow=opt.slow,
thermostat=opt.thermostat,
thermostat_param=opt.t_couple,
ntpr=opt.print_frequency,
ntwx=opt.print_frequency,
ntwr=opt.print_frequency * 10,
dt=opt.dt)
# Get the prefix
prefix = os.path.splitext(args[0])[0]
# Print the mdin file
heat_input.write_mdin('%s.heat.mdin' % prefix)
# 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: prog_str = '%s pmemd.MPI -O ' % mpi_cmd
else: prog_str = 'pmemd -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.heat.mdin -p %s -c %s -r %s.heat.rst7 -o %s.heat." +
"mdout -inf %s.heat.mdinfo -x %s.heat.nc -suffix %s") % (prog_str,
prefix, args[0], args[1], prefix, prefix, prefix, prefix, prefix)
if opt.rst_wt:
cmd_str += " -ref %s" % args[1]
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.heat.mdin -p %s -c %s -r %s.heat.rst7 -o %s.heat." +
"mdout -inf %s.heat.mdinfo -x %s.heat.nc -suffix %s") % (prog_str,
prefix, args[0], args[1], prefix, prefix, prefix, prefix, prefix)
if opt.rst_wt:
cmd_str += " -ref %s" % args[1]
os.system(cmd_str)