Skip to content

Commit 8191003

Browse files
committed
Fix bug in parsing group adjacency list multiplicities.
Also added comments for the somewhat complicated reg-ex. Thanks for finding the bug, Nick.
1 parent 636b68a commit 8191003

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rmgpy/molecule/adjlist.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ def fromAdjacencyList(adjlist, group=False, saturateH=False):
353353
if lines[0].split()[0] == 'multiplicity':
354354
line = lines.pop(0)
355355
if group:
356-
match = re.match('\s*multiplicity\s+\[\d(?:,\s*\d)*\]\s*$', line)
356+
match = re.match('\s*multiplicity\s+\[\s*(\d(?:,\s*\d)*)\s*\]\s*$', line)
357+
# should match "multiplicity [1]" or " multiplicity [ 1, 2, 3 ]" or " multiplicity [1,2,3]"
358+
# and whatever's inside the [] (excluding leading and trailing spaces) should be captured as group 1.
359+
# Multiplicities must be only one digit (i.e. less than 10)
360+
# The (?:,\s*\d)* matches patters like ", 2" 0 or more times, but doesn't capture them (because of the leading ?:)
357361
assert match, "Invalid multiplicity line '{0}'. Should be a list like 'multiplicity [1,2,3]'".format(line)
358362
multiplicities = match.group(1).split(',')
359363
multiplicity = [int(i) for i in multiplicities]

0 commit comments

Comments
 (0)