Unverified Commit 8ce5a685 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2269 from tristanic/master

Avoid repeated matching of duplicate impropers
parents dd4eed16 913410fc
......@@ -1968,12 +1968,15 @@ class PeriodicTorsionGenerator(object):
else:
force = existing[0]
wildcard = self.ff._atomClasses['']
proper_cache = {}
for torsion in data.propers:
type1 = data.atomType[data.atoms[torsion[0]]]
type2 = data.atomType[data.atoms[torsion[1]]]
type3 = data.atomType[data.atoms[torsion[2]]]
type4 = data.atomType[data.atoms[torsion[3]]]
match = None
type1, type2, type3, type4 = [data.atomType[data.atoms[torsion[i]]] for i in range(4)]
sig = (type1, type2, type3, type4)
sig = frozenset((sig, sig[::-1]))
match = proper_cache.get(sig, None)
if match == -1:
continue
if match is None:
for index in self.propersForAtomType[type2]:
tordef = self.proper[index]
types1 = tordef.types1
......@@ -1986,18 +1989,39 @@ class PeriodicTorsionGenerator(object):
match = tordef
if not hasWildcard:
break
if match is None:
proper_cache[sig] = -1
else:
proper_cache[sig] = match
if match is not None:
for i in range(len(match.phase)):
if match.k[i] != 0:
force.addTorsion(torsion[0], torsion[1], torsion[2], torsion[3], match.periodicity[i], match.phase[i], match.k[i])
impr_cache = {}
for torsion in data.impropers:
t1, t2, t3, t4 = tatoms = [data.atomType[data.atoms[torsion[i]]] for i in range(4)]
sig = (t1, t2, t3, t4)
match = impr_cache.get(sig, None)
if match == -1:
# Previously checked, and doesn't appear in the database
continue
elif match:
i1, i2, i3, i4, tordef = match
a1, a2, a3, a4 = (torsion[i] for i in (i1, i2, i3, i4))
match = (a1, a2, a3, a4, tordef)
if match is None:
match = _matchImproper(data, torsion, self)
if match is not None:
order = match[:4]
i1, i2, i3, i4 = tuple(torsion.index(a) for a in order)
impr_cache[sig] = (i1, i2, i3, i4, match[-1])
else:
impr_cache[sig] = -1
if match is not None:
(a1, a2, a3, a4, tordef) = match
for i in range(len(tordef.phase)):
if tordef.k[i] != 0:
force.addTorsion(a1, a2, a3, a4, tordef.periodicity[i], tordef.phase[i], tordef.k[i])
parsers["PeriodicTorsionForce"] = PeriodicTorsionGenerator.parseElement
......
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