Commit e4ccca2e authored by Jason Swails's avatar Jason Swails
Browse files

Very simple change to get ~20% performance improvement in reading Amber prmtop

files.
parent 2762adf4
...@@ -122,6 +122,7 @@ class PrmtopLoader(object): ...@@ -122,6 +122,7 @@ class PrmtopLoader(object):
with open(inFilename, 'r') as fIn: with open(inFilename, 'r') as fIn:
for line in fIn: for line in fIn:
if line[0] == '%':
if line.startswith('%VERSION'): if line.startswith('%VERSION'):
tag, self._prmtopVersion = line.rstrip().split(None, 1) tag, self._prmtopVersion = line.rstrip().split(None, 1)
elif line.startswith('%FLAG'): elif line.startswith('%FLAG'):
...@@ -134,7 +135,7 @@ class PrmtopLoader(object): ...@@ -134,7 +135,7 @@ class PrmtopLoader(object):
index1=format.index(')') index1=format.index(')')
format = format[index0+1:index1] format = format[index0+1:index1]
m = FORMAT_RE_PATTERN.search(format) m = FORMAT_RE_PATTERN.search(format)
self._raw_format[self._flags[-1]] = (format, m.group(1), m.group(2), m.group(3), m.group(4)) self._raw_format[self._flags[-1]] = (format, m.group(1), m.group(2), int(m.group(3)), m.group(4))
elif line.startswith('%COMMENT'): elif line.startswith('%COMMENT'):
continue continue
elif self._flags \ elif self._flags \
...@@ -144,8 +145,7 @@ class PrmtopLoader(object): ...@@ -144,8 +145,7 @@ class PrmtopLoader(object):
else: else:
flag=self._flags[-1] flag=self._flags[-1]
(format, numItems, itemType, (format, numItems, itemType,
itemLength, itemPrecision) = self._getFormat(flag) iLength, itemPrecision) = self._getFormat(flag)
iLength=int(itemLength)
line = line.rstrip() line = line.rstrip()
for index in range(0, len(line), iLength): for index in range(0, len(line), iLength):
item = line[index:index+iLength] item = line[index:index+iLength]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment