ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/utilities/md2md
(Generate patch)

Comparing trunk/src/applications/utilities/md2md (file contents):
Revision 1293 by chuckv, Sun Sep 14 01:32:26 2008 UTC vs.
Revision 2041 by gezelter, Fri Nov 14 14:31:47 2014 UTC

# Line 1 | Line 1
1 < #!/usr/bin/env python
1 > #!@PYTHON_EXECUTABLE@
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
17 <  -d, --depthFirst        write out the replicated system depth-first
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  
19
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.3 $"
28 < __date__ = "$Date: 2008-09-14 01:32:23 $"
29 < __copyright__ = "Copyright (c) 2008 by the University of Notre Dame"
30 < __license__ = "OOPSE"
27 > __version__ = "$Revision$"
28 > __date__ = "$Date$"
29 > __copyright__ = "Copyright (c) 2009 by the University of Notre Dame"
30 > __license__ = "OpenMD"
31  
32   import sys
33   import getopt
# Line 35 | Line 36 | from sets import *
36   import random
37   from sets import *
38  
38 _haveMDFileName = 0
39 _haveOutputFileName = 0
40
41 repeatX = 1
42 repeatY = 1
43 repeatZ = 1
44
39   metaData = []
40   frameData = []
41   indices = []
# Line 58 | Line 52 | def readFile(mdFileName):
52  
53   def readFile(mdFileName):
54      mdFile = open(mdFileName, 'r')        
55 <    # Find OOPSE version info first
55 >    # Find OpenMD version info first
56      line = mdFile.readline()
57      while 1:
58 <        if '<OOPSE version=' in line:
59 <            OOPSEversion = line
58 >        if '<OOPSE version=' in line or '<OpenMD version=' in line:
59 >            OpenMDversion = line
60              break
61          line = mdFile.readline()
62          
# Line 125 | Line 119 | def readFile(mdFileName):
119                          myIndex = int(L[0])
120                          indices.append(myIndex)
121                          pvqj.append(L[1])
122 <                        x = float(L[2])
123 <                        y = float(L[3])
124 <                        z = float(L[4])
125 <                        p.append([x, y, z])
126 <                        vx = float(L[5])
127 <                        vy = float(L[6])
128 <                        vz = float(L[7])
129 <                        v.append([vx, vy, vz])
130 <                        if 'pvqj' in L[1]:
122 >                        if 'p' in L[1]:                              
123 >                            x = float(L[2])
124 >                            y = float(L[3])
125 >                            z = float(L[4])                            
126 >                            p.append([x, y, z])
127 >                        else:
128 >                            p.append([0.0, 0.0, 0.0])
129 >                        if 'v' in L[1]:                              
130 >                            vx = float(L[5])                                
131 >                            vy = float(L[6])
132 >                            vz = float(L[7])
133 >                            v.append([vx, vy, vz])
134 >                        else:
135 >                            v.append([0.0, 0.0, 0.0])
136 >                        if 'q' in L[1]:
137                              qw = float(L[8])
138                              qx = float(L[9])
139                              qy = float(L[10])
140                              qz = float(L[11])
141                              q.append([qw, qx, qy, qz])
142 +                        else:
143 +                            q.append([0.0, 0.0, 0.0, 0.0])
144 +                        if 'j' in L[1]:
145                              jx = float(L[12])
146                              jy = float(L[13])
147                              jz = float(L[14])
148                              j.append([jx, jy, jz])
149                          else:
147                            q.append([0.0, 0.0, 0.0, 0.0])
150                              j.append([0.0, 0.0, 0.0])
151                                                
152                          line = mdFile.readline()
# Line 156 | Line 158 | def readFile(mdFileName):
158      
159      mdFile.close()
160  
161 < def writeFile(outputFileName,depthFirst):
161 > def writeFile(outputFileName,repeatX,repeatY,repeatZ):
162      outputFile = open(outputFileName, 'w')
163  
164 <    outputFile.write("<OOPSE version=4>\n");
164 >    outputFile.write("<OpenMD version=1>\n");
165  
166      print "writing MetaData"
167      for metaline in metaData:
# Line 187 | Line 189 | def writeFile(outputFileName,depthFirst):
189  
190      print "writing StuntDoubles"
191      outputFile.write("    <StuntDoubles>\n")
190    whichSD = 0
192  
193      print repeatX, repeatY, repeatZ
194  
195 +    deco = [ (index, i) for i, index in enumerate(indices) ]
196 +    deco.sort()
197 +    whichSD = 0
198 +    for ii in range(repeatX):
199 +        for jj in range(repeatY):
200 +            for kk in range(repeatZ):
201 +                for index in range(len(deco)):
202 +                    (index,i) = deco[index]
203 +                    print i
204 +                    myP = []
205 +                    myP.append(p[i][0] + ii*Hmat[0][0] + jj*Hmat[1][0] + kk*Hmat[2][0])
206 +                    myP.append(p[i][1] + ii*Hmat[0][1] + jj*Hmat[1][1] + kk*Hmat[2][1])
207 +                    myP.append(p[i][2] + ii*Hmat[0][2] + jj*Hmat[1][2] + kk*Hmat[2][2])
208 +    
209 +                    if (pvqj[i] == 'p'):
210 +                        outputFile.write("%10d %7s %18.10g %18.10g %18.10g\n" % (whichSD, pvqj[i], myP[0], myP[1], myP[2]))
211  
212 <    if (depthFirst) :
213 <        whichSD = 0
214 <        for i in range(len(indices)):
215 <            for ii in range(repeatX):
216 <                for jj in range(repeatY):
217 <                    for kk in range(repeatZ):
218 <                        
202 <                        myP = []
203 <                        myP.append(p[i][0] + ii*Hmat[0][0] + jj*Hmat[1][0] + kk*Hmat[2][0])
204 <                        myP.append(p[i][1] + ii*Hmat[0][1] + jj*Hmat[1][1] + kk*Hmat[2][1])
205 <                        myP.append(p[i][2] + ii*Hmat[0][2] + jj*Hmat[1][2] + kk*Hmat[2][2])
206 <                        
207 <                        if (pvqj[i] == 'pv'):
208 <                            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]))
209 <                        elif (pvqj[i] == 'pvqj'):
210 <                            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]))
211 <                        
212 <                        whichSD = whichSD + 1
212 >                    elif (pvqj[i] == 'pv'):
213 >                        outputFile.write("%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e\n" % (whichSD, pvqj[i], myP[0], myP[1], myP[2], v[i][0], v[i][1], v[i][2]))
214 >                    elif (pvqj[i] == 'pq'):
215 >                        outputFile.write("%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e %13e\n" % (whichSD, pvqj[i], myP[0], myP[1], myP[2], q[i][0], q[i][1], q[i][2], q[i][3]))
216 >                    elif (pvqj[i] == 'pvqj'):
217 >                        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]))
218 >                    whichSD = whichSD + 1
219  
214    else:
215        whichSD = 0
216        for ii in range(repeatX):
217            for jj in range(repeatY):
218                for kk in range(repeatZ):
219                    for i in range(len(indices)):
220                        
221                        myP = []
222                        myP.append(p[i][0] + ii*Hmat[0][0] + jj*Hmat[1][0] + kk*Hmat[2][0])
223                        myP.append(p[i][1] + ii*Hmat[0][1] + jj*Hmat[1][1] + kk*Hmat[2][1])
224                        myP.append(p[i][2] + ii*Hmat[0][2] + jj*Hmat[1][2] + kk*Hmat[2][2])
225                        
226                        if (pvqj[i] == 'pv'):
227                            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]))
228                        elif (pvqj[i] == 'pvqj'):
229                            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]))
230                        
231                        whichSD = whichSD + 1
232
233
220      outputFile.write("    </StuntDoubles>\n")
221      outputFile.write("  </Snapshot>\n")
222 <    outputFile.write("</OOPSE>\n")
222 >    outputFile.write("</OpenMD>\n")
223      outputFile.close()
224  
225   def roundMe(x):
# Line 272 | Line 258 | def cross(L1, L2):
258      L3[2] = L1[0]*L2[1] - L1[1]*L2[0]
259      return L3
260  
261 < def mapToBox():
261 > def mapToBox(translateX, translateY, translateZ):
262 >    print "translating by %f\t%f\t%f" % (translateX, translateY, translateZ)
263      for i in range(len(indices)):
264 <        dpos = p[i]
264 >        dpos = []
265 >        dpos.append(p[i][0] + translateX)
266 >        dpos.append(p[i][1] + translateY)
267 >        dpos.append(p[i][2] + translateZ)
268          p[i] = wrapVector(dpos)
269  
280
270   def main(argv):
271 <    depthFirst = 0
271 >    repeatX = 1
272 >    repeatY = 1
273 >    repeatZ = 1
274 >    translateX = 0.0
275 >    translateY = 0.0
276 >    translateZ = 0.0
277 >    _haveMDFileName = 0
278 >    _haveOutputFileName = 0
279      try:                                
280 <        opts, args = getopt.getopt(argv, "hm:o:x:y:z:d", ["help", "meta-data=", "output-file=", "repeatX=", "repeatY=", "repeatZ=","depthFirst"])
280 >        opts, args = getopt.getopt(argv, "hm:o:x:y:z:t:u:v:", ["help", "meta-data=", "output-file=", "repeatX=", "repeatY=", "repeatZ=","translateX=","translateY=","translateZ="])
281      except getopt.GetoptError:          
282          usage()                          
283          sys.exit(2)                    
# Line 291 | Line 287 | def main(argv):
287              sys.exit()                  
288          elif opt in ("-m", "--meta-data"):
289              mdFileName = arg
294            global _haveMDFileName
290              _haveMDFileName = 1
291          elif opt in ("-o", "--output-file"):
292              outputFileName = arg
298            global _haveOutputFileName
293              _haveOutputFileName = 1
294          elif opt in ("-x", "--repeatX"):
301            global repeatX
295              repeatX = int(arg)
296          elif opt in ("-y", "--repeatY"):
304            global repeatY
297              repeatY = int(arg)
298          elif opt in ("-z", "--repeatZ"):
307            global repeatZ
299              repeatZ = int(arg)
300 <        elif opt in ("-d", "--depthFirst"):
301 <            depthFirst = 1
300 >        elif opt in ("-t", "--translateX"):
301 >            translateX = float(arg)
302 >        elif opt in ("-u", "--translateY"):
303 >            translateY = float(arg)
304 >        elif opt in ("-v", "--translateZ"):
305 >            translateZ = float(arg)
306      if (_haveMDFileName != 1):
307          usage()
308          print "No meta-data file was specified"
# Line 318 | Line 313 | def main(argv):
313          sys.exit()
314  
315      readFile(mdFileName)
316 <    mapToBox()    
317 <    writeFile(outputFileName, depthFirst)
316 >    mapToBox(translateX, translateY, translateZ)    
317 >    writeFile(outputFileName, repeatX, repeatY, repeatZ)
318  
319   if __name__ == "__main__":
320      if len(sys.argv) == 1:

Comparing trunk/src/applications/utilities/md2md (property svn:keywords):
Revision 1293 by chuckv, Sun Sep 14 01:32:26 2008 UTC vs.
Revision 2041 by gezelter, Fri Nov 14 14:31:47 2014 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines