4Skips every n frames of an OpenMD dump file and loads it into new dump file
9 -h, --help show this help
10 -m, --meta-data=... use specified OpenMD (.dump) file
11 -o, --output-file=... use specified output file
12 -s, --split-frame=... split every n frames
16 omdShrink -s 10 -m long.dump -o short.dump
20__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
35def shrinkFile(mdFileName, outputFileName, skipFrameNumber):
36 mdFile = open(mdFileName, 'r')
37 outFile = open(outputFileName, 'w')
42 # Find OpenMD version info first
43 line = mdFile.readline()
45 if '<OOPSE version=' in line or '<OpenMD version=' in line:
48 line = mdFile.readline()
50 # Rewind file and find start of MetaData block
54 line = mdFile.readline()
57 if '<MetaData>' in line:
59 metaDataFrame.append(line)
60 line = mdFile.readline()
61 if '</MetaData>' in line:
62 metaDataFrame.append(line)
67 line = mdFile.readline()
69 outFile.write(OpenMDversion)
70 for metaline in metaDataFrame:
71 if 'sampleTime' in metaline:
72 metasplit = metaline.split()
73 sampleTime = float(metasplit[2].strip(';'))
74 newSampleTime = sampleTime * int(skipFrameNumber)
75 outFile.write('sampleTime = %10d;\n' % (newSampleTime))
77 outFile.write(metaline)
82 line = mdFile.readline()
84 if '<Snapshot>' in line:
85 division, remainder=divmod(foundFrames, int(skipFrameNumber))
88 while not '</Snapshot>' in line:
90 line = mdFile.readline()
92 line = mdFile.readline()
95 outFile.write("</OpenMD>")
102 opts, args = getopt.getopt(argv, "hm:o:s:", ["help", "meta-data=", "output-file=", "split-frame", ""])
103 except getopt.GetoptError:
106 for opt, arg in opts:
107 if opt in ("-h", "--help"):
110 elif opt in ("-m", "--meta-data"):
112 global _haveMDFileName
114 elif opt in ("-o", "--output-file"):
116 global _haveOutFileName
118 elif opt in ("-s", "--split-frame"):
119 skipFrameNumber = arg
120 global _haveSplitFrame
122 if (_haveMDFileName != 1):
124 print("No OpenMD input file was specified")
126 if (_haveOutFileName != 1):
128 print("No output file was specified")
130 if (_haveSplitFrame != 1):
132 print("Frames to split was not specified")
134 shrinkFile(mdFileName, outputFileName, skipFrameNumber);
136if __name__ == "__main__":
137 if len(sys.argv) == 1: