1 |
#!/usr/bin/env python |
2 |
"""Dump File Converter |
3 |
|
4 |
Converts old-style OOPSE md and dump files into new-style |
5 |
combined files |
6 |
|
7 |
Usage: dumpConverter |
8 |
|
9 |
Options: |
10 |
-h, --help show this help |
11 |
-m, --meta-data=... use specified meta-data (.md) file |
12 |
-c, --config-file=... use specified configuration (.in, .eor, .dump) file |
13 |
-o, --output-file=... use specified output (.oop) file |
14 |
|
15 |
|
16 |
Example: |
17 |
dumpConverter -m Ar.md -c Ar.dump -o Ar.oop |
18 |
|
19 |
""" |
20 |
|
21 |
__author__ = "Dan Gezelter (gezelter@nd.edu)" |
22 |
__version__ = "$Revision: 1.1 $" |
23 |
__date__ = "$Date: 2006-07-27 19:05:16 $" |
24 |
__copyright__ = "Copyright (c) 2006 by the University of Notre Dame" |
25 |
__license__ = "OOPSE" |
26 |
|
27 |
import sys |
28 |
import getopt |
29 |
import string |
30 |
|
31 |
_haveMDFileName = 0 |
32 |
_haveConfFileName = 0 |
33 |
_haveOutputFileName = 0 |
34 |
|
35 |
def usage(): |
36 |
print __doc__ |
37 |
|
38 |
|
39 |
def convertFiles(mdFileName, configFileName, outputFileName): |
40 |
mdFile = open(mdFileName, 'r') |
41 |
outputFile = open(outputFileName, 'w') |
42 |
|
43 |
outputFile.write("<OOPSE version=4>\n"); |
44 |
outputFile.write(" <MetaData>\n") |
45 |
|
46 |
mdLines = mdFile.readlines() |
47 |
for l in mdLines: |
48 |
outputFile.write(l) |
49 |
|
50 |
outputFile.write(" </MetaData>\n") |
51 |
mdFile.close() |
52 |
|
53 |
framePos = 0 |
54 |
configFile = open(configFileName, 'r') |
55 |
for line in configFile.readlines(): |
56 |
framePos = framePos + 1 |
57 |
print framePos |
58 |
if (framePos == 1): |
59 |
L = line.split() |
60 |
nStuntDoubles = int(L[0]) |
61 |
whichSD = 0 |
62 |
outputFile.write(" <Snapshot>\n") |
63 |
continue |
64 |
elif (framePos == 2): |
65 |
L = line.split() |
66 |
time = float(L[0].split(';')[0]) |
67 |
outputFile.write(" <FrameData>\n"); |
68 |
outputFile.write(" Time: %g\n" % (time)) |
69 |
Hxx = float(L[1]) |
70 |
Hxy = float(L[2]) |
71 |
Hxz = float(L[3].split(';')[0]) |
72 |
Hyx = float(L[4]) |
73 |
Hyy = float(L[5]) |
74 |
Hyz = float(L[6].split(';')[0]) |
75 |
Hzx = float(L[7]) |
76 |
Hzy = float(L[8]) |
77 |
Hzz = float(L[9].split(';')[0]) |
78 |
outputFile.write(" Hmat: {{ %g, %g, %g }, { %g, %g, %g }, { %g, %g, %g }}\n" % (Hxx, Hxy, Hxz, Hyx, Hyy, Hyz, Hzx, Hzy, Hzz)) |
79 |
chi = float(L[10]) |
80 |
if (L[11][-1] == ';'): |
81 |
integChi = float(L[11].split(';')[0]) |
82 |
else: |
83 |
integChi = float(L[11]) |
84 |
outputFile.write(" Thermostat: %g , %g\n" % (chi, integChi)) |
85 |
if (L[12][0] == ';'): |
86 |
Nxx = float(L[12].split(';')[1]) |
87 |
else: |
88 |
Nxx = float(L[12]) |
89 |
Nxy = float(L[13]) |
90 |
Nxz = float(L[14].split(';')[0]) |
91 |
Nyx = float(L[15]) |
92 |
Nyy = float(L[16]) |
93 |
Nyz = float(L[17].split(';')[0]) |
94 |
Nzx = float(L[18]) |
95 |
Nzy = float(L[19]) |
96 |
Nzz = float(L[20].split(';')[0]) |
97 |
outputFile.write(" Barostat: {{ %g, %g, %g }, { %g, %g, %g }, { %g, %g, %g }}\n" % (Nxx, Nxy, Nxz, Nyx, Nyy, Nyz, Nzx, Nzy, Nzz)) |
98 |
outputFile.write(" </FrameData>\n") |
99 |
outputFile.write(" <StuntDoubles>\n") |
100 |
else: |
101 |
whichSD = whichSD + 1 |
102 |
L = line.split() |
103 |
x = float(L[1]) |
104 |
y = float(L[2]) |
105 |
z = float(L[3]) |
106 |
vx = float(L[4]) |
107 |
vy = float(L[5]) |
108 |
vz = float(L[6]) |
109 |
sdFormat = 'pv' |
110 |
if (len(L) == 14): |
111 |
qw = float(L[7]) |
112 |
qx = float(L[8]) |
113 |
qy = float(L[9]) |
114 |
qz = float(L[10]) |
115 |
jx = float(L[11]) |
116 |
jy = float(L[12]) |
117 |
jz = float(L[13]) |
118 |
if (qw == 0.0 and qx == 0.0 and qy == 0.0 and qz == 0.0): |
119 |
sdFormat = 'pv' |
120 |
else: |
121 |
sdFormat = 'pvqj' |
122 |
if (len(L) == 20): |
123 |
fx = float(L[14]) |
124 |
fy = float(L[15]) |
125 |
fz = float(L[16]) |
126 |
tx = float(L[17]) |
127 |
ty = float(L[18]) |
128 |
tz = float(L[19]) |
129 |
sdFormat = 'pvqjft' |
130 |
if (sdFormat == 'pv'): |
131 |
outputFile.write("%d\t%s\t%g\t%g\t%g\t%g\t%g\t%g\n" % (whichSD, sdFormat, x, y, z, vx, vy, vz)) |
132 |
elif (sdFormat == 'pvqj'): |
133 |
outputFile.write("%d\t%s\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n" % (whichSD, sdFormat, x, y, z, vx, vy, vz, qw, qx, qy, qz, jx, jy, jz)) |
134 |
elif (sdFormat == 'pvqjft'): |
135 |
outputFile.write("%d\t%s\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n" % (whichSD, sdFormat, x, y, z, vx, vy, vz, qw, qx, qy, qz, jx, jy, jz, fx, fy, fz, tx, ty, tz)) |
136 |
if (whichSD == nStuntDoubles): |
137 |
outputFile.write(" </StuntDoubles>\n") |
138 |
outputFile.write(" </Snapshot>\n") |
139 |
framePos = 0 |
140 |
|
141 |
|
142 |
configFile.close() |
143 |
outputFile.write("</OOPSE>\n") |
144 |
outputFile.close() |
145 |
|
146 |
|
147 |
def main(argv): |
148 |
try: |
149 |
opts, args = getopt.getopt(argv, "hm:c:o:", ["help", "meta-data=", "config-file=", "output-file="]) |
150 |
except getopt.GetoptError: |
151 |
usage() |
152 |
sys.exit(2) |
153 |
for opt, arg in opts: |
154 |
if opt in ("-h", "--help"): |
155 |
usage() |
156 |
sys.exit() |
157 |
elif opt in ("-m", "--meta-data"): |
158 |
mdFileName = arg |
159 |
global _haveMDFileName |
160 |
_haveMDFileName = 1 |
161 |
elif opt in ("-c", "--config-file"): |
162 |
configFileName = arg |
163 |
global _haveConfFileName |
164 |
_haveConfFileName = 1 |
165 |
elif opt in ("-o", "--output-file"): |
166 |
outputFileName = arg |
167 |
global _haveOutputFileName |
168 |
_haveOutputFileName = 1 |
169 |
if (_haveMDFileName != 1): |
170 |
usage() |
171 |
print "No meta-data file was specified" |
172 |
sys.exit() |
173 |
if (_haveConfFileName != 1): |
174 |
usage() |
175 |
print "No configuration file was specified" |
176 |
sys.exit() |
177 |
if (_haveOutputFileName != 1): |
178 |
usage() |
179 |
print "No output file was specified" |
180 |
sys.exit() |
181 |
convertFiles(mdFileName, configFileName, outputFileName); |
182 |
|
183 |
if __name__ == "__main__": |
184 |
if len(sys.argv) == 1: |
185 |
usage() |
186 |
sys.exit() |
187 |
main(sys.argv[1:]) |
188 |
|