4Opens two omd files, one with a solute structure and one with a
5solvent structure. Deletes any solvent molecules that overlap with
6solute molecules and produces a new combined omd file. The output omd
7file must be edited to run properly in OpenMD. Note that the two
8boxes must have identical box geometries (specified on the Hmat line).
13 -h, --help show this help
14 -u, --solute=... use specified OpenMD (.omd) file as the solute
15 -v, --solvent=... use specified OpenMD (.omd) file as the solvent
16 -r, --rcut=... specify the cutoff radius for deleting solvent
17 -o, --output-file=... use specified output (.omd) file
18 -n, --nSoluteAtoms=... Number of atoms in solute molecule,
20 -p, --nSolventAtoms=... Number of atoms in solvent molecule,
24 omd-solvator -u solute.omd -v solvent.omd -n 3 -p 3 -r 4.0 -o combined.omd
28__author__ = "Charles Vardeman (cvardema@nd.edu)"
29__version__ = "$Revision$"
31__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
43_haveOutputFileName = 0
72solventTypeLine = str()
79def readFile1(mdFileName):
80 mdFile = open(mdFileName, 'r')
81 # Find OpenMD version info first
82 line = mdFile.readline()
84 if '<OpenMD version=' in line or '<OOPSE version=' in line:
87 line = mdFile.readline()
89 # Rewind file and find start of MetaData block
92 line = mdFile.readline()
94 print("reading solute MetaData")
96 if '<MetaData>' in line:
98 metaData1.append(line)
99 line = mdFile.readline()
101 global soluteTypeLine
102 soluteTypeLine = line
106 if '</MetaData>' in line:
107 metaData1.append(line)
110 line = mdFile.readline()
113 print("reading solute Snapshot")
114 line = mdFile.readline()
116 if '<Snapshot>' in line:
117 line = mdFile.readline()
119 print("reading solute FrameData")
120 if '<FrameData>' in line:
122 frameData1.append(line)
125 Hxx = float(L[2].strip(','))
126 Hxy = float(L[3].strip(','))
127 Hxz = float(L[4].strip(','))
128 Hyx = float(L[7].strip(','))
129 Hyy = float(L[8].strip(','))
130 Hyz = float(L[9].strip(','))
131 Hzx = float(L[12].strip(','))
132 Hzy = float(L[13].strip(','))
133 Hzz = float(L[14].strip(','))
134 Hmat1.append([Hxx, Hxy, Hxz])
135 Hmat1.append([Hyx, Hyy, Hyz])
136 Hmat1.append([Hzx, Hzy, Hzz])
137 BoxInv1.append(1.0/Hxx)
138 BoxInv1.append(1.0/Hyy)
139 BoxInv1.append(1.0/Hzz)
140 line = mdFile.readline()
141 if '</FrameData>' in line:
142 frameData1.append(line)
146 line = mdFile.readline()
148 if '<StuntDoubles>' in line:
149 line = mdFile.readline()
153 indices1.append(myIndex)
158 positions1.append([x, y, z])
162 velocities1.append([vx, vy, vz])
168 quaternions1.append([qw, qx, qy, qz])
172 angVels1.append([jx, jy, jz])
174 quaternions1.append([0.0, 0.0, 0.0, 0.0])
175 angVels1.append([0.0, 0.0, 0.0])
177 line = mdFile.readline()
178 if '</StuntDoubles>' in line:
181 line = mdFile.readline()
186def readFile2(mdFileName):
187 mdFile = open(mdFileName, 'r')
188 # Find OpenMD version info first
189 line = mdFile.readline()
191 if '<OpenMD version=' in line or '<OOPSE version=':
194 line = mdFile.readline()
196 # Rewind file and find start of MetaData block
199 line = mdFile.readline()
200 print("reading solvent MetaData")
202 if '<MetaData>' in line:
205 global solventTypeLine
206 solventTypeLine = line
207 metaData2.append(line)
208 line = mdFile.readline()
209 if '</MetaData>' in line:
210 metaData2.append(line)
213 line = mdFile.readline()
216 print("reading solvent Snapshot")
217 line = mdFile.readline()
219 if '<Snapshot>' in line:
220 line = mdFile.readline()
222 print("reading solvent FrameData")
223 if '<FrameData>' in line:
225 frameData2.append(line)
228 Hxx = float(L[2].strip(','))
229 Hxy = float(L[3].strip(','))
230 Hxz = float(L[4].strip(','))
231 Hyx = float(L[7].strip(','))
232 Hyy = float(L[8].strip(','))
233 Hyz = float(L[9].strip(','))
234 Hzx = float(L[12].strip(','))
235 Hzy = float(L[13].strip(','))
236 Hzz = float(L[14].strip(','))
237 Hmat2.append([Hxx, Hxy, Hxz])
238 Hmat2.append([Hyx, Hyy, Hyz])
239 Hmat2.append([Hzx, Hzy, Hzz])
240 BoxInv2.append(1.0/Hxx)
241 BoxInv2.append(1.0/Hyy)
242 BoxInv2.append(1.0/Hzz)
243 line = mdFile.readline()
244 if '</FrameData>' in line:
245 frameData2.append(line)
249 line = mdFile.readline()
251 if '<StuntDoubles>' in line:
252 line = mdFile.readline()
256 indices2.append(myIndex)
261 positions2.append([x, y, z])
265 velocities2.append([vx, vy, vz])
271 quaternions2.append([qw, qx, qy, qz])
275 angVels2.append([jx, jy, jz])
277 quaternions2.append([0.0, 0.0, 0.0, 0.0])
278 angVels1.append([0.0, 0.0, 0.0])
280 line = mdFile.readline()
281 if '</StuntDoubles>' in line:
284 line = mdFile.readline()
289def writeFile(outputFileName):
290 outputFile = open(outputFileName, 'w')
292 outputFile.write("<OpenMD version=1>\n")
294# for metaline in metaData1:
295# outputFile.write(metaline)
296 outputFile.write(" <MetaData>\n")
297 outputFile.write("\n\n")
298 outputFile.write("component{\n")
299 outputFile.write(soluteTypeLine)
300 outputFile.write(soluteMolLine)
301 outputFile.write("}\n")
303 outputFile.write("component{\n")
304 outputFile.write(solventTypeLine)
305 outputFile.write("nMol = %d;\n" % (nSolvents))
306 outputFile.write("}\n")
307 outputFile.write("\n\n")
308 outputFile.write(" </MetaData>\n")
309 outputFile.write(" <Snapshot>\n")
311 for frameline in frameData1:
312 outputFile.write(frameline)
314 outputFile.write(" <StuntDoubles>\n")
318 for i in range(len(indices1)):
319 if (pvqj1[i] == 'pv'):
320 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]))
321 elif(pvqj1[i] == 'pvqj'):
322 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]))
324 newIndex = newIndex + 1
326 outputFile.write(" </StuntDoubles>\n")
327 outputFile.write(" </Snapshot>\n")
328 outputFile.write("</OpenMD>\n")
332 boxTolerance = 1.0e-3
336 diff = math.fabs( Hmat1[i][j] - Hmat2[i][j])
339 if (maxDiff > boxTolerance):
340 print("The solute and solvent boxes have different geometries:")
341 print(" Solute | Solvent")
342 print(" -------------------------------------|------------------------------------")
344 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])))
346 print(" -------------------------------------|------------------------------------")
352 return math.floor(x + 0.5)
354 return math.ceil(x - 0.5)
356def frange(start,stop,step=1.0):
362def wrapVector(myVect):
363 scaled = [0.0, 0.0, 0.0]
365 scaled[i] = myVect[i] * BoxInv1[i]
366 scaled[i] = scaled[i] - roundMe(scaled[i])
367 myVect[i] = scaled[i] * Hmat1[i][i]
372 for i in range(len(L1)):
373 myDot = myDot + L1[i]*L2[i]
378 myLength = math.sqrt(dot(L1, L1))
379 for i in range(len(L1)):
380 L2.append(L1[i] / myLength)
384 # don't call this with anything other than length 3 lists please
387 L3[0] = L1[1]*L2[2] - L1[2]*L2[1]
388 L3[1] = L1[2]*L2[0] - L1[0]*L2[2]
389 L3[2] = L1[0]*L2[1] - L1[1]*L2[0]
392def removeOverlaps(rcut, nSolventAtoms, nSoluteAtoms):
396 for i in range(0, len(indices2), nSolventAtoms):
398 for atom1 in range (i, (i+nSolventAtoms)):
400 iPos = positions2[atom1]
401 for j in range(0, len(indices1)):
402 for atom2 in range (j, (j+nSoluteAtoms), nSoluteAtoms):
403 jPos = positions1[atom2]
404 dpos = [jPos[0]-iPos[0], jPos[1]-iPos[1], jPos[2]-iPos[2]]
405 dpos = wrapVector(dpos)
406 dist2 = dot(dpos, dpos)
412 if (keepThisMolecule == 0):
415 keepers.append(keepThisMolecule)
419 myIndex = len(indices2) - 1
420 for i in range(0, len(keepers)):
422 if (keepers[i] == 1):
423 nSolvents = nSolvents + 1
424 atomStartIndex = i * nSolventAtoms
425 for j in range (atomStartIndex, (atomStartIndex+nSolventAtoms)):
426 indices1.append(myIndex)
427 pvqj1.append(pvqj2[j])
428 if (pvqj2[j] == 'pv'):
429 positions1.append(positions2[j])
430 velocities1.append(velocities2[j])
431 quaternions1.append([0.0, 0.0, 0.0, 0.0])
432 angVels1.append([0.0, 0.0, 0.0])
434 positions1.append(positions2[j])
435 velocities1.append(velocities2[j])
436 quaternions1.append(quaternions2[j])
437 angVels1.append(angVels2[j])
438 # indices1.append(indices2[j])
443 opts, args = getopt.getopt(argv, "hu:v:n:p:r:o:", ["help", "solute=", "solvent=", "nSoluteAtoms=", "nSolventAtoms=", "rcut=" "output-file="])
444 except getopt.GetoptError:
447 for opt, arg in opts:
448 if opt in ("-h", "--help"):
451 elif opt in ("-u", "--solute"):
453 global _haveMDFileName1
455 elif opt in ("-v", "--solvent"):
457 global _haveMDFileName2
459 elif opt in ("-n", "--nSoluteAtoms"):
460 nSoluteAtoms = int(arg)
461 global _haveNSoluteAtoms
462 _haveNSoluteAtoms = 1
463 elif opt in ("-p", "--nSolventAtoms"):
464 nSolventAtoms = int(arg)
465 global _haveNSolventAtoms
466 _haveNSolventAtoms = 1
467 elif opt in ("-r", "--rcut"):
471 elif opt in ("-o", "--output-file"):
473 global _haveOutputFileName
474 _haveOutputFileName = 1
476 if (_haveMDFileName1 != 1):
478 print("No OpenMD (omd) file was specified for the solute")
481 if (_haveMDFileName2 != 1):
483 print("No OpenMD (omd) file was specified for the solvent")
486 if (_haveOutputFileName != 1):
488 print("No output file was specified")
492 print("No cutoff radius was specified, using 4 angstroms")
495 if (_haveNSoluteAtoms != 1):
496 print("Number of solute atoms was not specified. Using 1 atom.")
499 if (_haveNSolventAtoms != 1):
500 print("Number of solute atoms was not specified. Using 1 atom.")
503 readFile1(mdFileName1)
504 readFile2(mdFileName2)
506 removeOverlaps(rcut, nSolventAtoms, nSoluteAtoms)
507 writeFile(outputFileName)
509if __name__ == "__main__":
510 if len(sys.argv) == 1: