1 """ inputgen class
2
3 Create an APBS input file using psize data
4
5 Written by Todd Dolinsky based on original sed script by Nathan Baker
6
7 ----------------------------
8
9 PDB2PQR -- An automated pipeline for the setup, execution, and analysis of
10 Poisson-Boltzmann electrostatics calculations
11
12 Nathan A. Baker (baker@biochem.wustl.edu)
13 Todd Dolinsky (todd@ccb.wustl.edu)
14 Dept. of Biochemistry and Molecular Biophysics
15 Center for Computational Biology
16 Washington University in St. Louis
17
18 Jens Nielsen (Jens.Nielsen@ucd.ie)
19 University College Dublin
20
21 Additional contributing authors listed in documentation and supporting
22 package licenses.
23
24 Copyright (c) 2003-2007. Washington University in St. Louis.
25 All Rights Reserved.
26
27 This file is part of PDB2PQR.
28
29 PDB2PQR is free software; you can redistribute it and/or modify
30 it under the terms of the GNU General Public License as published by
31 the Free Software Foundation; either version 2 of the License, or
32 (at your option) any later version.
33
34 PDB2PQR is distributed in the hope that it will be useful,
35 but WITHOUT ANY WARRANTY; without even the implied warranty of
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 GNU General Public License for more details.
38
39 You should have received a copy of the GNU General Public License
40 along with PDB2PQR; if not, write to the Free Software
41 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42
43 ----------------------------
44 """
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 import string, sys
64 import psize
65
67 """
68 An object for the ELEC section of an APBS input file
69 """
70 - def __init__(self, size, method, asyncflag):
71 """
72 Initialize the variables that can be set in this object
73 Users can modify any of these variables (that's why
74 they're here!)
75 """
76
77
78
79
80 self.dime = size.getFineGridPoints()
81 gmem = 200.0 * self.dime[0] * self.dime[1] * self.dime[2] / 1024.0 / 1024.0
82 if method == "":
83 if gmem > size.getConstant("GMEMCEIL"): method = "mg-para"
84 else: method = "mg-auto"
85
86 if method == "mg-para":
87 self.dime = size.getSmallest()
88
89 self.method = method
90 self.glen = size.getCoarseGridDims()
91 self.cglen = size.getCoarseGridDims()
92 self.fglen = size.getFineGridDims()
93 self.pdime = size.getProcGrid()
94
95 self.label = ""
96 self.nlev = 4
97 self.ofrac = 0.1
98 self.async = 0
99 self.asyncflag = asyncflag
100 self.cgcent = "mol 1"
101 self.fgcent = "mol 1"
102 self.gcent = "mol 1"
103 self.mol = 1
104 self.lpbe = 1
105 self.npbe = 0
106 self.bcfl = "sdh"
107 self.ion = []
108 self.pdie = 2.0
109 self.sdie = 78.54
110 self.srfm = "smol"
111 self.chgm = "spl2"
112 self.sdens = 10.0
113 self.srad = 1.4
114 self.swin = 0.3
115 self.temp = 298.15
116 self.gamma = 0.105
117 self.calcenergy = "total"
118 self.calcforce = "no"
119 self.write = []
120
122 """
123 Return the elec statement as a string. Check the method
124 to see which keywords to use.
125 """
126 text = "elec %s\n" % self.label
127 text += " %s\n" % self.method
128 text += " dime %i %i %i\n" % (self.dime[0], self.dime[1], self.dime[2])
129 if self.method == "mg-manual":
130 text += " nlev %i\n" % self.nlev
131 text += " glen %.3f %.3f %.3f\n" % (self.glen[0], self.glen[1], self.glen[2])
132 text += " gcent %s\n" % self.gcent
133 elif self.method == "mg-auto":
134 text += " cglen %.4f %.4f %.4f\n" % (self.cglen[0], self.cglen[1], self.cglen[2])
135 text += " fglen %.4f %.4f %.4f\n" % (self.fglen[0], self.fglen[1], self.fglen[2])
136 text += " cgcent %s\n" % self.cgcent
137 text += " fgcent %s\n" % self.fgcent
138 elif self.method == "mg-para":
139 text += " pdime %i %i %i\n" % (self.pdime[0], self.pdime[1], self.pdime[2])
140 text += " ofrac %.1f\n" % self.ofrac
141 text += " cglen %.4f %.4f %.4f\n" % (self.cglen[0], self.cglen[1], self.cglen[2])
142 text += " fglen %.4f %.4f %.4f\n" % (self.fglen[0], self.fglen[1], self.fglen[2])
143 text += " cgcent %s\n" % self.cgcent
144 text += " fgcent %s\n" % self.fgcent
145 if self.asyncflag == 1:
146 text += " async %i\n" % self.async
147 text += " mol %i\n" % self.mol
148 if self.lpbe: text += " lpbe\n"
149 else: text += " npbe\n"
150 text += " bcfl %s\n" % self.bcfl
151 for ion in self.ion:
152 text += " ion %.2f %.3f %.2f\n" % (ion[0], ion[1], ion[2])
153 text += " pdie %.4f\n" % self.pdie
154 text += " sdie %.4f\n" % self.sdie
155 text += " srfm %s\n" % self.srfm
156 text += " chgm %s\n" % self.chgm
157 text += " sdens %.2f\n" % self.sdens
158 text += " srad %.2f\n" % self.srad
159 text += " swin %.2f\n" % self.swin
160 text += " temp %.2f\n" % self.temp
161 text += " gamma %.3f\n" % self.gamma
162 text += " calcenergy %s\n" % self.calcenergy
163 text += " calcforce %s\n" % self.calcforce
164 for write in self.write:
165 text += " write %s %s %s\n" % (write[0], write[1], write[2])
166 text += "end\n"
167 return text
168
262
295
297 """
298 Display the usage information for this script
299 """
300 size = psize.Psize()
301 usage = "\n"
302 usage = usage + "Use this script to generate new APBS input files or split an existing\n"
303 usage = usage + "parallel input file into multiple async files.\n\n"
304 usage = usage + "Usage: inputgen.py [opts] <filename>\n"
305 usage = usage + "Optional Arguments:\n"
306 usage = usage + " --help : Display this text\n"
307 usage = usage + " --split : Split an existing parallel input file to multiple\n"
308 usage = usage + " async input files.\n"
309 usage = usage + " --METHOD=<value> : Force output file to write a specific APBS ELEC\n"
310 usage = usage + " method. Options are para (parallel), auto\n"
311 usage = usage + " (automatic), manual (manual), or async (asynchronous).\n"
312 usage = usage + " solve. async will result in multiple input files.\n"
313 usage = usage + " --CFAC=<value> : Factor by which to expand molecular dimensions to\n"
314 usage = usage + " get coarse grid dimensions.\n"
315 usage = usage + " [default = %g]\n" % size.getConstant("CFAC")
316 usage = usage + " --FADD=<value> : Amount to add to molecular dimensions to get fine\n"
317 usage = usage + " grid dimensions.\n"
318 usage = usage + " [default = %g]\n" % size.getConstant("FADD")
319 usage = usage + " --SPACE=<value> : Desired fine mesh resolution\n"
320 usage = usage + " [default = %g]\n" % size.getConstant("SPACE")
321 usage = usage + " --GMEMFAC=<value> : Number of bytes per grid point required\n"
322 usage = usage + " for sequential MG calculation\n"
323 usage = usage + " [default = %g]\n" % size.getConstant("GMEMFAC")
324 usage = usage + " --GMEMCEIL=<value> : Max MB allowed for sequential MG\n"
325 usage = usage + " calculation. Adjust this to force the\n"
326 usage = usage + " script to perform faster calculations (which\n"
327 usage = usage + " require more parallelism).\n"
328 usage = usage + " [default = %g]\n" % size.getConstant("GMEMCEIL")
329 usage = usage + " --OFAC=<value> : Overlap factor between mesh partitions\n"
330 usage = usage + " [default = %g]\n" % size.getConstant("OFAC")
331 usage = usage + " --REDFAC=<value> : The maximum factor by which a domain\n"
332 usage = usage + " dimension can be reduced during focusing\n"
333 usage = usage + " [default = %g]\n" % size.getConstant("REDFAC")
334 sys.stderr.write(usage)
335 sys.exit(2)
336
338
339 import getopt
340 filename = ""
341 shortOptList = ""
342 longOptList = ["help","split","METHOD=","CFAC=","SPACE=","GMEMCEIL=","GMEMFAC=","OFAC=","REDFAC="]
343
344 try:
345 opts, args = getopt.getopt(sys.argv[1:], shortOptList, longOptList)
346 except getopt.GetoptError, details:
347 sys.stderr.write("Option error (%s)!\n" % details)
348 usage()
349
350 if len(args) != 1:
351 sys.stderr.write("Invalid argument list!\n")
352 usage()
353 else:
354 filename = args[0]
355
356 method = ""
357 size = psize.Psize()
358 async = 0
359 split = 0
360
361 for o, a in opts:
362 if o == "--help":
363 usage()
364 if o == "--split": split = 1
365 if o == "--METHOD":
366 if a == "para":
367 sys.stdout.write("Forcing a parallel calculation\n")
368 method = "mg-para"
369 elif a == "auto":
370 sys.stdout.write("Forcing a sequential calculation\n")
371 method = "mg-auto"
372 elif a == "async":
373 sys.stdout.write("Forcing an asynchronous calculation\n")
374 method = "mg-para"
375 async = 1
376 elif a == "manual":
377 sys.stdout.write("Forcing a manual calculation\n")
378 method = "mg-manual"
379 else:
380 sys.stdout.write("Incorrect method argument: %s\n" % a)
381 sys.stdout.write("Defaulting to memory dependent result\n")
382 if o == "--CFAC":
383 size.setConstant("CFAC", float(a))
384 if o == "--SPACE":
385 size.setConstant("SPACE", float(a))
386 if o == "--GMEMFAC":
387 size.setConstant("GMEMFAC", int(a))
388 if o == "--GMEMCEIL":
389 size.setConstant("GMEMCEIL", int(a))
390 if o == "--OFAC":
391 size.setConstant("OFAC", float(a))
392 if o == "--REDFAC":
393 size.setConstant("REDFAC", float(a))
394
395 if split == 1:
396 splitInput(filename)
397 else:
398 size.runPsize(filename)
399 input = Input(filename, size, method, async)
400 input.printInputFiles()
401
402 if __name__ == "__main__": main()
403