-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathminimization.py
executable file
·171 lines (135 loc) · 6.55 KB
/
minimization.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
#!/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
".min.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 MinimizationError(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('--maxcyc', dest='maxcyc', default=1000, type='int',
help='Number of minimization steps to run. Default 1000.')
parser.add_option_group(group)
group = OptionGroup(parser, 'Implicit Solvent Options',
'If the system does not have periodic boundaries, ' +
'these options control the implicit solvation 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, '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 MinimizationError('Bad igb value (%d)' % opt.igb)
if opt.maxcyc < 0:
raise MinimizationError('Bad maxcyc value (%d)' % opt.maxcyc)
min_input = am_sim.Minimization(amsys, num_steps=opt.maxcyc, igb=opt.igb,
restrained=bool(opt.rst_wt), rst_wt=opt.rst_wt,
rst_mask=opt.rst_mask)
# Get the prefix
prefix = os.path.splitext(args[0])[0]
# Print the mdin file
min_input.write_mdin('%s.min.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.min.mdin -p %s -c %s -r %s.min.rst7 -o %s.min.mdout " +
"-inf %s.min.mdinfo -suffix %s") % (prog_str, prefix, args[0],
args[1], 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.min.mdin -p %s -c %s -r %s.min.rst7 -o %s.min.mdout " +
"-inf %s.min.mdinfo -suffix %s") % (prog_str, prefix, args[0],
args[1], prefix, prefix, prefix, prefix)
if opt.rst_wt:
cmd_str += " -ref %s" % args[1]
os.system(cmd_str)