4Splits OpenMD dump file frames into seperate omd files
9 -h, --help show this help
10 -m, --meta-data=... use specified OpenMD (.omd) file
11 -s, --split-frame=... split every n frames
19__author__ = "Charles Vardeman (cvardema@nd.edu)"
20__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
37def splitFile(mdFileName, skipFrameNumber):
38 mdFile = open(mdFileName, 'r')
40 (filepath, filename) = os.path.split(mdFileName)
42 (outfilePrefix, ext) = os.path.splitext(filename)
49# Find OpenMD version info first
50 line = mdFile.readline()
52 if '<OOPSE version=' in line or '<OpenMD version=' in line:
55 line = mdFile.readline()
57# Rewind file and find start of MetaData block
61 line = mdFile.readline()
64 if '<MetaData>' in line:
66 metaDataFrame.append(line)
67 line = mdFile.readline()
68 if '</MetaData>' in line:
69 metaDataFrame.append(line)
74 line = mdFile.readline()
80 line = mdFile.readline()
82 if '<Snapshot>' in line:
84 division, remainder=divmod(foundFrames, int(skipFrameNumber))
86 outfilename = outfilePrefix + "_" + "%04d" % foundFrames + ext
87 outFile = open(outfilename, 'w')
88 outFile.write(OpenMDversion)
89 for metaline in metaDataFrame:
90 outFile.write(metaline)
91 while not '</Snapshot>' in line:
93 line = mdFile.readline()
95 outFile.write("</OpenMD>")
97 line = mdFile.readline()
105 opts, args = getopt.getopt(argv, "hm:s:", ["help", "meta-data=", "split-frame", ""])
106 except getopt.GetoptError:
109 for opt, arg in opts:
110 if opt in ("-h", "--help"):
113 elif opt in ("-m", "--meta-data"):
115 global _haveMDFileName
117 elif opt in ("-s", "--split-frame"):
118 skipFrameNumber = arg
119 global _haveSplitFrame
121 if (_haveMDFileName != 1):
123 print("No OpenMD file was specified")
125 if (_haveSplitFrame != 1):
127 print("Frames to split was not specified")
129 splitFile(mdFileName, skipFrameNumber);
131if __name__ == "__main__":
132 if len(sys.argv) == 1: