4Opens two omd files, one with a solute structure and one with a
5solvent structure. Viable with solvents containing both rigid and
6non-rigid atoms, with the stipulation that no atoms overlap.
7Produces a new combined omd file. The output omd file must be
8edited to run properly in OpenMD. Note that the two boxes must
9have identical box geometries (specified on the Hmat line).
14 -h, --help show this help
15 -u, --solute=... use specified OpenMD (.omd) file as the solute
16 -v, --solvent=... use specified OpenMD (.omd) file as the solvent
17 -o, --output-file=... use specified output (.omd) file
21 omdCombined -u solute.omd -v solvent.omd -o combined.omd
25__author__ = "Sydney Shavalier (sshavali@nd.edu)"
26__version__ = "$Revision$"
28__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
39_haveOutputFileName = 0
68def readFile1(mdFileName):
69 mdFile = open(mdFileName, 'r')
70 # Find OpenMD version info first
71 line = mdFile.readline()
73 if '<OpenMD version=' in line or '<OOPSE version=' in line:
76 line = mdFile.readline()
81 line = mdFile.readline()
83 print("reading solute MetaData")
85 if '<MetaData>' in line:
87 line = mdFile.readline()
88 if 'molecule' in line:
89 while not 'component' in line:
90 componentLines.append(line)
91 line = mdFile.readline()
92 componentLines.append("\n")
93 if 'component' in line:
94 while not '}' in line:
95 componentLines.append(line)
96 line = mdFile.readline()
97 componentLines.append("}\n\n")
98 if 'ensemble' in line:
99 while not '</MetaData>' in line:
100 ensembleLines.append(line)
101 line = mdFile.readline()
102 metaData1.append(line)
104 if '</MetaData>' in line:
105 metaData1.append(line)
108 line = mdFile.readline()
112 print("reading solute Snapshot")
113 line = mdFile.readline()
115 if '<Snapshot>' in line:
116 line = mdFile.readline()
118 print("reading solute FrameData")
119 if '<FrameData>' in line:
121 frameData1.append(line)
124 Hxx = float(L[2].strip(','))
125 Hxy = float(L[3].strip(','))
126 Hxz = float(L[4].strip(','))
127 Hyx = float(L[7].strip(','))
128 Hyy = float(L[8].strip(','))
129 Hyz = float(L[9].strip(','))
130 Hzx = float(L[12].strip(','))
131 Hzy = float(L[13].strip(','))
132 Hzz = float(L[14].strip(','))
133 Hmat1.append([Hxx, Hxy, Hxz])
134 Hmat1.append([Hyx, Hyy, Hyz])
135 Hmat1.append([Hzx, Hzy, Hzz])
136 BoxInv1.append(1.0/Hxx)
137 BoxInv1.append(1.0/Hyy)
138 BoxInv1.append(1.0/Hzz)
139 line = mdFile.readline()
140 if '</FrameData>' in line:
141 frameData1.append(line)
145 line = mdFile.readline()
147 if '<StuntDoubles>' in line:
148 line = mdFile.readline()
152 indices1.append(myIndex)
157 positions1.append([x, y, z])
161 velocities1.append([vx, vy, vz])
167 quaternions1.append([qw, qx, qy, qz])
171 angVels1.append([jx, jy, jz])
173 quaternions1.append([0.0, 0.0, 0.0, 0.0])
174 angVels1.append([0.0, 0.0, 0.0])
176 line = mdFile.readline()
177 if '</StuntDoubles>' in line:
180 line = mdFile.readline()
185def readFile2(mdFileName):
186 mdFile = open(mdFileName, 'r')
187 # Find OpenMD version info first
188 line = mdFile.readline()
190 if '<OpenMD version=' in line or '<OOPSE version=':
193 line = mdFile.readline()
197 line = mdFile.readline()
199 print("reading solvent MetaData")
201 if '<MetaData>' in line:
203 line = mdFile.readline()
204 if 'molecule' in line:
205 while not 'component' in line:
206 componentLines.append(line)
207 line = mdFile.readline()
208 componentLines.append("\n")
209 if 'component' in line:
210 while not '}' in line:
211 componentLines.append(line)
212 line = mdFile.readline()
213 componentLines.append("}\n\n")
214 metaData2.append(line)
215 if '</MetaData>' in line:
216 metaData2.append(line)
219 line = mdFile.readline()
223 print("reading solvent Snapshot")
224 line = mdFile.readline()
226 if '<Snapshot>' in line:
227 line = mdFile.readline()
229 print("reading solvent FrameData")
230 if '<FrameData>' in line:
232 frameData2.append(line)
235 Hxx = float(L[2].strip(','))
236 Hxy = float(L[3].strip(','))
237 Hxz = float(L[4].strip(','))
238 Hyx = float(L[7].strip(','))
239 Hyy = float(L[8].strip(','))
240 Hyz = float(L[9].strip(','))
241 Hzx = float(L[12].strip(','))
242 Hzy = float(L[13].strip(','))
243 Hzz = float(L[14].strip(','))
244 Hmat2.append([Hxx, Hxy, Hxz])
245 Hmat2.append([Hyx, Hyy, Hyz])
246 Hmat2.append([Hzx, Hzy, Hzz])
247 BoxInv2.append(1.0/Hxx)
248 BoxInv2.append(1.0/Hyy)
249 BoxInv2.append(1.0/Hzz)
250 line = mdFile.readline()
251 if '</FrameData>' in line:
252 frameData2.append(line)
256 line = mdFile.readline()
258 if '<StuntDoubles>' in line:
259 line = mdFile.readline()
263 indices2.append(myIndex)
268 positions2.append([x, y, z])
272 velocities2.append([vx, vy, vz])
278 quaternions2.append([qw, qx, qy, qz])
282 angVels2.append([jx, jy, jz])
284 quaternions2.append([0.0, 0.0, 0.0, 0.0])
285 angVels1.append([0.0, 0.0, 0.0])
287 line = mdFile.readline()
288 if '</StuntDoubles>' in line:
291 line = mdFile.readline()
296def writeFile(outputFileName):
297 outputFile = open(outputFileName, 'w')
299 outputFile.write("<OpenMD version=1>\n")
300 outputFile.write(" <MetaData>\n")
301 for componentLine in componentLines:
302 outputFile.write(componentLine)
303 for ensembleLine in ensembleLines:
304 outputFile.write(ensembleLine)
305 outputFile.write("\n")
306 outputFile.write(" </MetaData>\n")
307 outputFile.write(" <Snapshot>\n")
308 for frameline in frameData1:
309 outputFile.write(frameline)
310 outputFile.write(" <StuntDoubles>\n")
314 for i in range(len(indices1)):
315 if (pvqj1[i] == 'pv'):
316 outputFile.write("%10d %7s %18.10g %18.10g %18.10g %14e %13e %13e\n" % (newIndex, pvqj1[i], positions1[i][0], positions1[i][1], positions1[i][2], velocities1[i][0], velocities1[i][1], velocities1[i][2]))
317 elif(pvqj1[i] == 'pvqj'):
318 outputFile.write("%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e %13e %13e %13e %13e %13e %13e %13e\n" % (newIndex, pvqj1[i], positions1[i][0], positions1[i][1], positions1[i][2], velocities1[i][0], velocities1[i][1], velocities1[i][2], quaternions1[i][0], quaternions1[i][1], quaternions1[i][2], quaternions1[i][3], angVels1[i][0], angVels1[i][1], angVels1[i][2]))
322 newIndexAlt = newIndex
323 for j in range(len(indices2)):
324 if (pvqj2[j] == 'pv'):
325 outputFile.write("%10d %7s %18.10g %18.10g %18.10g %14e %13e %13e\n" % (newIndexAlt, pvqj2[j], positions2[j][0], positions2[j][1], positions2[j][2], velocities2[j][0], velocities2[j][1], velocities2[j][2]))
326 elif(pvqj2[j] == 'pvqj'):
327 outputFile.write("%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e %13e %13e %13e %13e %13e %13e %13e\n" % (newIndexAlt, pvqj2[j], positions2[j][0], positions2[j][1], positions2[j][2], velocities2[j][0], velocities2[j][1], velocities2[j][2], quaternions2[j][0], quaternions2[j][1], quaternions2[j][2], quaternions2[j][3], angVels2[j][0], angVels2[j][1], angVels2[j][2]))
331 outputFile.write(" </StuntDoubles>\n")
332 outputFile.write(" </Snapshot>\n")
333 outputFile.write("</OpenMD>\n")
338 boxTolerance = 1.0e-3
342 diff = math.fabs( Hmat1[i][j] - Hmat2[i][j])
345 if (maxDiff > boxTolerance):
346 print("The solute and solvent boxes have different geometries:")
347 print(" Solute | Solvent")
348 print(" -------------------------------------|------------------------------------")
350 print(( "| %10.4g %10.4g %10.4g | %10.4g %10.4g %10.4g |" % (Hmat1[i][0], Hmat1[i][1], Hmat1[i][2], Hmat2[i][0], Hmat2[i][1], Hmat2[i][2])))
352 print(" -------------------------------------|------------------------------------")
355def checkOverlap(sd1_index,sd2_index): #checks to see if solute and solvent atoms overlap (within 1 Angstrom of each other)
356 overlapTolerance = 1.0
360 delta.append(positions1[sd1_index][i] - positions2[sd2_index][i])
362 diff = delta[0]**2 + delta[1]**2 + delta[2]**2
363 diff = math.sqrt(diff)
364 if (diff < overlapTolerance):
365 print("Warning: Solute and solvent atoms overlap! No output file was created.")
371 return math.floor(x + 0.5)
373 return math.ceil(x - 0.5)
375def frange(start,stop,step=1.0):
381def wrapVector(myVect):
382 scaled = [0.0, 0.0, 0.0]
384 scaled[i] = myVect[i] * BoxInv1[i]
385 scaled[i] = scaled[i] - roundMe(scaled[i])
386 myVect[i] = scaled[i] * Hmat1[i][i]
392 opts, args = getopt.getopt(argv, "hu:v:o:", ["help", "solute=", "solvent=", "output-file="])
393 except getopt.GetoptError:
396 for opt, arg in opts:
397 if opt in ("-h", "--help"):
400 elif opt in ("-u", "--solute"):
402 global _haveMDFileName1
404 elif opt in ("-v", "--solvent"):
406 global _haveMDFileName2
408 elif opt in ("-o", "--output-file"):
410 global _haveOutputFileName
411 _haveOutputFileName = 1
413 if (_haveMDFileName1 != 1):
415 print("No OpenMD (omd) file was specified for the solute")
418 if (_haveMDFileName2 != 1):
420 print("No OpenMD (omd) file was specified for the solvent")
423 if (_haveOutputFileName != 1):
425 print("No output file was specified")
428 readFile1(mdFileName1)
429 readFile2(mdFileName2)
431 for sd1 in range(len(indices1)):
432 for sd2 in range(len(indices2)):
433 checkOverlap(sd1,sd2)
434 writeFile(outputFileName)
436if __name__ == "__main__":
437 if len(sys.argv) == 1: