Skip to content

Commit

Permalink
Address concerns from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshanuikabundi committed Aug 8, 2024
1 parent 137d890 commit 2f46987
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
16 changes: 3 additions & 13 deletions pdbfixer/pdbfixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class CCDResidueDefinition:
Description of a residue from the Chemical Component Dictionary (CCD).
"""
residueName: str
smiles: Optional[str]
atoms: list[CCDAtomDefinition]
bonds: list[CCDBondDefinition]

Expand All @@ -155,12 +154,6 @@ def fromReader(cls, reader: PdbxReader) -> 'CCDResidueDefinition':

descriptorsData = block.getObj("pdbx_chem_comp_descriptor")
typeCol = descriptorsData.getAttributeIndex("type")
smilesCol = descriptorsData.getAttributeIndex("descriptor")
smiles = None
for row in descriptorsData.getRowList():
if row[typeCol] in ["SMILES", "SMILES_CANONICAL"]:
smiles = row[smilesCol]
break

atomData = block.getObj('chem_comp_atom')
atomNameCol = atomData.getAttributeIndex('atom_id')
Expand Down Expand Up @@ -200,7 +193,7 @@ def fromReader(cls, reader: PdbxReader) -> 'CCDResidueDefinition':
else:
bonds = []

return cls(residueName=residueName, smiles=smiles, atoms=atoms, bonds=bonds)
return cls(residueName=residueName, atoms=atoms, bonds=bonds)

def _guessFileFormat(file, filename):
"""Guess whether a file is PDB or PDBx/mmCIF based on its filename and contents."""
Expand Down Expand Up @@ -452,7 +445,7 @@ def _initializeFromPDBx(self, file):
self.modifiedResidues.append(ModifiedResidue(row[asymIdCol], int(row[resNumCol]), row[resNameCol], row[standardResCol]))


def _downloadCCDDefinition(self, residueName: str, checkCache: bool = True) -> Optional[CCDResidueDefinition]:
def _downloadCCDDefinition(self, residueName: str) -> Optional[CCDResidueDefinition]:
"""
Download a residue definition from the Chemical Component Dictionary.
Expand All @@ -463,9 +456,6 @@ def _downloadCCDDefinition(self, residueName: str, checkCache: bool = True) -> O
residueName : str
The name of the residue, as specified in the PDB Chemical Component
Dictionary.
checkCache : bool
If ``False``, attempt to re-download the CCD entry regardless of
what is in the cache. Defaults to ``True``.
Returns
-------
Expand Down Expand Up @@ -1572,7 +1562,7 @@ def _createForceField(self, newTopology, water):
forcefield._templates[resName] = template
indexInResidue = {}
# If we can't find formal charges in the CCD, make everything uncharged
formalCharges = defaultdict(lambda: 0)
formalCharges = defaultdict(int)
# See if we can get formal charges from the CCD
if water:
# The formal charges in the CCD can only be relied on if the
Expand Down
16 changes: 6 additions & 10 deletions pdbfixer/tests/test_charge_and_solvate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ def test_charge_and_solvate(pdbCode, soluteCharge):
fixer = PDBFixer(pdbid=pdbCode)
fixer.findMissingResidues()

chains_to_cap = {chain for chain, resi in fixer.missingResidues}
for chainidx in chains_to_cap:
chain = [*fixer.topology.chains()][chainidx]
last_resi = len([*chain.residues()])
# Capping with GLY because ACE/NME currently breaks addMissingHydrogens
# Adding a cap keeps the protein compact and the addSolvent call quick
fixer.missingResidues[chainidx, 0] = ["GLY"]
fixer.missingResidues[chainidx, last_resi] = ["GLY"]
# fixer.missingResidues[chainidx, 0] = ['ACE']
# fixer.missingResidues[chainidx, last_resi] = ['NME']
chainLengths = [len([*chain.residues()]) for chain in fixer.topology.chains()]
for chainidx, residx in list(fixer.missingResidues):
if residx == 0:
fixer.missingResidues[chainidx, residx] = ["ACE"]
elif residx == chainLengths[chainidx]:
fixer.missingResidues[chainidx, residx] = ["NME"]

fixer.findNonstandardResidues()
fixer.replaceNonstandardResidues()
Expand Down

0 comments on commit 2f46987

Please sign in to comment.