2 |
|
"""MetaData file remapper |
3 |
|
|
4 |
|
Takes a MetaData file and maps all StuntDoubles back to the periodic box. |
5 |
< |
Will optionally replicate the system in the three box directions, and |
6 |
< |
then writes out a new MetaData file. |
5 |
> |
Will optionally replicate the system in the three box directions, or |
6 |
> |
translate every object in the box and before writing out a new MetaData file. |
7 |
|
|
8 |
|
Usage: md2md |
9 |
|
|
10 |
|
Options: |
11 |
< |
-h, --help show this help |
12 |
< |
-m, --meta-data=... use specified meta-data (.md, .eor) file |
13 |
< |
-o, --output-file=... use specified output file |
14 |
< |
-x, --repeatX=... make the system repeat in the x direction |
15 |
< |
-y, --repeatY=... make the system repeat in the y direction |
16 |
< |
-z, --repeatZ=... make the system repeat in the z direction |
11 |
> |
-h, --help show this help |
12 |
> |
-m, --meta-data=... use specified meta-data (.md, .eor) file |
13 |
> |
-o, --output-file=... use specified output file |
14 |
> |
-x, --repeatX=... make the system repeat in the x direction |
15 |
> |
-y, --repeatY=... make the system repeat in the y direction |
16 |
> |
-z, --repeatZ=... make the system repeat in the z direction |
17 |
> |
-t, --translateX=... translate all x coordinates by some amount |
18 |
> |
-u, --translateY=... translate all y coordinates by some amount |
19 |
> |
-v, --translateZ=... translate all z coordinates by some amount |
20 |
|
|
18 |
– |
|
21 |
|
Example: |
22 |
< |
md2md -m lipidSystem.md -o bigLipidSystem.md -x 2 -y 2 -z 1 |
22 |
> |
md2md -m lipidSystem.md -o bigLipidSystem.md -x 2 -y 2 -z 1 -v 35.0 |
23 |
|
|
24 |
|
""" |
25 |
|
|
26 |
|
__author__ = "Dan Gezelter (gezelter@nd.edu)" |
27 |
< |
__version__ = "$Revision: 1.2 $" |
28 |
< |
__date__ = "$Date: 2008-05-14 20:49:17 $" |
29 |
< |
__copyright__ = "Copyright (c) 2008 by the University of Notre Dame" |
27 |
> |
__version__ = "$Revision: 1.4 $" |
28 |
> |
__date__ = "$Date: 2009-10-22 19:12:14 $" |
29 |
> |
__copyright__ = "Copyright (c) 2009 by the University of Notre Dame" |
30 |
|
__license__ = "OOPSE" |
31 |
|
|
32 |
|
import sys |
36 |
|
import random |
37 |
|
from sets import * |
38 |
|
|
37 |
– |
_haveMDFileName = 0 |
38 |
– |
_haveOutputFileName = 0 |
39 |
– |
|
40 |
– |
repeatX = 1 |
41 |
– |
repeatY = 1 |
42 |
– |
repeatZ = 1 |
43 |
– |
|
39 |
|
metaData = [] |
40 |
|
frameData = [] |
41 |
|
indices = [] |
150 |
|
|
151 |
|
mdFile.close() |
152 |
|
|
153 |
< |
def writeFile(outputFileName): |
153 |
> |
def writeFile(outputFileName,repeatX,repeatY,repeatZ): |
154 |
|
outputFile = open(outputFileName, 'w') |
155 |
|
|
156 |
|
outputFile.write("<OOPSE version=4>\n"); |
181 |
|
|
182 |
|
print "writing StuntDoubles" |
183 |
|
outputFile.write(" <StuntDoubles>\n") |
189 |
– |
whichSD = 0 |
184 |
|
|
185 |
|
print repeatX, repeatY, repeatZ |
186 |
|
|
187 |
< |
for i in range(len(indices)): |
187 |
> |
deco = [ (index, i) for i, index in enumerate(indices) ] |
188 |
> |
deco.sort() |
189 |
> |
whichSD = 0 |
190 |
> |
for index in range(len(deco)): |
191 |
> |
(index,i) = deco[index] |
192 |
> |
print i |
193 |
|
for ii in range(repeatX): |
194 |
|
for jj in range(repeatY): |
195 |
< |
for kk in range(repeatZ): |
197 |
< |
|
195 |
> |
for kk in range(repeatZ): |
196 |
|
myP = [] |
197 |
|
myP.append(p[i][0] + ii*Hmat[0][0] + jj*Hmat[1][0] + kk*Hmat[2][0]) |
198 |
|
myP.append(p[i][1] + ii*Hmat[0][1] + jj*Hmat[1][1] + kk*Hmat[2][1]) |
199 |
|
myP.append(p[i][2] + ii*Hmat[0][2] + jj*Hmat[1][2] + kk*Hmat[2][2]) |
200 |
< |
|
200 |
> |
|
201 |
|
if (pvqj[i] == 'pv'): |
202 |
|
outputFile.write("%10d %7s %18.10g %18.10g %18.10g %14e %13e %13e\n" % (whichSD, pvqj[i], myP[0], myP[1], myP[2], v[i][0], v[i][1], v[i][2])) |
203 |
|
elif (pvqj[i] == 'pvqj'): |
204 |
|
outputFile.write("%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e %13e %13e %13e %13e %13e %13e %13e\n" % (whichSD, pvqj[i], myP[0], myP[1], myP[2], v[i][0], v[i][1], v[i][2], q[i][0], q[i][1], q[i][2], q[i][3], j[i][0], j[i][1], j[i][2])) |
207 |
– |
|
205 |
|
whichSD = whichSD + 1 |
206 |
|
|
207 |
|
outputFile.write(" </StuntDoubles>\n") |
245 |
|
L3[2] = L1[0]*L2[1] - L1[1]*L2[0] |
246 |
|
return L3 |
247 |
|
|
248 |
< |
def mapToBox(): |
248 |
> |
def mapToBox(translateX, translateY, translateZ): |
249 |
> |
print "translating by %f\t%f\t%f" % (translateX, translateY, translateZ) |
250 |
|
for i in range(len(indices)): |
251 |
< |
dpos = p[i] |
251 |
> |
dpos = [] |
252 |
> |
dpos.append(p[i][0] + translateX) |
253 |
> |
dpos.append(p[i][1] + translateY) |
254 |
> |
dpos.append(p[i][2] + translateZ) |
255 |
|
p[i] = wrapVector(dpos) |
256 |
|
|
256 |
– |
|
257 |
|
def main(argv): |
258 |
+ |
repeatX = 1 |
259 |
+ |
repeatY = 1 |
260 |
+ |
repeatZ = 1 |
261 |
+ |
translateX = 0.0 |
262 |
+ |
translateY = 0.0 |
263 |
+ |
translateZ = 0.0 |
264 |
+ |
_haveMDFileName = 0 |
265 |
+ |
_haveOutputFileName = 0 |
266 |
|
try: |
267 |
< |
opts, args = getopt.getopt(argv, "hm:o:x:y:z:", ["help", "meta-data=", "output-file=", "repeatX=", "repeatY=", "repeatZ="]) |
267 |
> |
opts, args = getopt.getopt(argv, "hm:o:x:y:z:t:u:v:", ["help", "meta-data=", "output-file=", "repeatX=", "repeatY=", "repeatZ=","translateX=","translateY=","translateZ="]) |
268 |
|
except getopt.GetoptError: |
269 |
|
usage() |
270 |
|
sys.exit(2) |
274 |
|
sys.exit() |
275 |
|
elif opt in ("-m", "--meta-data"): |
276 |
|
mdFileName = arg |
269 |
– |
global _haveMDFileName |
277 |
|
_haveMDFileName = 1 |
278 |
|
elif opt in ("-o", "--output-file"): |
279 |
|
outputFileName = arg |
273 |
– |
global _haveOutputFileName |
280 |
|
_haveOutputFileName = 1 |
281 |
|
elif opt in ("-x", "--repeatX"): |
276 |
– |
global repeatX |
282 |
|
repeatX = int(arg) |
283 |
|
elif opt in ("-y", "--repeatY"): |
279 |
– |
global repeatY |
284 |
|
repeatY = int(arg) |
285 |
|
elif opt in ("-z", "--repeatZ"): |
282 |
– |
global repeatZ |
286 |
|
repeatZ = int(arg) |
287 |
+ |
elif opt in ("-t", "--translateX"): |
288 |
+ |
translateX = float(arg) |
289 |
+ |
elif opt in ("-u", "--translateY"): |
290 |
+ |
translateY = float(arg) |
291 |
+ |
elif opt in ("-v", "--translateZ"): |
292 |
+ |
translateZ = float(arg) |
293 |
|
if (_haveMDFileName != 1): |
294 |
|
usage() |
295 |
|
print "No meta-data file was specified" |
298 |
|
usage() |
299 |
|
print "No output file was specified" |
300 |
|
sys.exit() |
301 |
+ |
|
302 |
|
readFile(mdFileName) |
303 |
< |
mapToBox() |
304 |
< |
writeFile(outputFileName) |
303 |
> |
mapToBox(translateX, translateY, translateZ) |
304 |
> |
writeFile(outputFileName, repeatX, repeatY, repeatZ) |
305 |
|
|
306 |
|
if __name__ == "__main__": |
307 |
|
if len(sys.argv) == 1: |