Skip to content

Commit

Permalink
Only apply formal charges when all and only atom names match between …
Browse files Browse the repository at this point in the history
…the CCD and PDB
  • Loading branch information
Yoshanuikabundi committed Jul 30, 2024
1 parent b637451 commit 0b8cbf3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pdbfixer/pdbfixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ def _downloadFormalCharges(self, resName: str):
return {}

# Record the formal charges.
return {atom.atomName: atom.charge for atom in ccdDefinition.atoms}
return {atom.atomName: atom.charge for atom in ccdDefinition.atoms if not atom.leaving}

def _createForceField(self, newTopology, water):
"""Create a force field to use for optimizing the positions of newly added atoms."""
Expand Down Expand Up @@ -1567,10 +1567,14 @@ def _createForceField(self, newTopology, water):
template = app.ForceField._TemplateData(resName)
forcefield._templates[resName] = template
indexInResidue = {}
# If we can't find formal charges in the CCD, make everything uncharged
formalCharges = defaultdict(lambda: 0)
# See if we can get formal charges from the CCD
if water:
formalCharges = self._downloadFormalCharges(residue.name)
else:
formalCharges = defaultdict(lambda: 0)
downloadedFormalCharges = self._downloadFormalCharges(residue.name)
if set(downloadedFormalCharges) == {atom.name for atom in residue.atoms()}:
# We got formal charges and the atom names match, so we can use them
formalCharges = downloadedFormalCharges
for atom in residue.atoms():
element = atom.element
formalCharge = formalCharges.get(atom.name, 0)
Expand Down

0 comments on commit 0b8cbf3

Please sign in to comment.