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