"...ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "f7f701363753918f51443d42150ea92f9d602923"
Unverified Commit 32a5f304 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed issues in applying patches (#4279)

parent 10c909dd
...@@ -481,6 +481,7 @@ class ForceField(object): ...@@ -481,6 +481,7 @@ class ForceField(object):
def registerPatch(self, patch): def registerPatch(self, patch):
"""Register a new patch that can be applied to templates.""" """Register a new patch that can be applied to templates."""
patch.index = len(self._patches)
self._patches[patch.name] = patch self._patches[patch.name] = patch
def registerTemplatePatch(self, residue, patch, patchResidueIndex): def registerTemplatePatch(self, residue, patch, patchResidueIndex):
...@@ -792,6 +793,17 @@ class ForceField(object): ...@@ -792,6 +793,17 @@ class ForceField(object):
else: else:
self.excludeWith = self.atoms[0] self.excludeWith = self.atoms[0]
def __eq__(self, other):
if not isinstance(other, ForceField._VirtualSiteData):
return False
if self.type != other.type or self.index != other.index or self.atoms != other.atoms or self.excludeWith != other.excludeWith:
return False
if self.type in ('average2', 'average3', 'outOfPlane'):
return self.weights == other.weights
elif self.type == 'localCoords':
return self.originWeights == other.originWeights and self.xWeights == other.xWeights and self.yWeights == other.yWeights and self.localPos == other.localPos
return False
class _PatchData(object): class _PatchData(object):
"""Inner class used to encapsulate data about a patch definition.""" """Inner class used to encapsulate data about a patch definition."""
def __init__(self, name, numResidues): def __init__(self, name, numResidues):
...@@ -807,6 +819,10 @@ class ForceField(object): ...@@ -807,6 +819,10 @@ class ForceField(object):
self.allAtomNames = set() self.allAtomNames = set()
self.virtualSites = [[] for i in range(numResidues)] self.virtualSites = [[] for i in range(numResidues)]
self.attributes = {} self.attributes = {}
self.index = None
def __lt__(self, other):
return self.index < other.index
def createPatchedTemplates(self, templates): def createPatchedTemplates(self, templates):
"""Apply this patch to a set of templates, creating new modified ones.""" """Apply this patch to a set of templates, creating new modified ones."""
...@@ -1582,7 +1598,7 @@ def _applyPatchesToMatchResidues(forcefield, data, residues, templateForResidue, ...@@ -1582,7 +1598,7 @@ def _applyPatchesToMatchResidues(forcefield, data, residues, templateForResidue,
patchedTemplates = {} patchedTemplates = {}
for name, template in forcefield._templates.items(): for name, template in forcefield._templates.items():
if name in forcefield._templatePatches: if name in forcefield._templatePatches:
patches = [forcefield._patches[patchName] for patchName, patchResidueIndex in forcefield._templatePatches[name] if forcefield._patches[patchName].numResidues == 1] patches = sorted([forcefield._patches[patchName] for patchName, patchResidueIndex in forcefield._templatePatches[name] if forcefield._patches[patchName].numResidues == 1])
if len(patches) > 0: if len(patches) > 0:
newTemplates = [] newTemplates = []
patchedTemplates[name] = newTemplates patchedTemplates[name] = newTemplates
......
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