openmm / pdbfixer

PDBFixer fixes problems in PDB files
Other
461 stars 115 forks source link

ValueError in _findNearestDistance when protein has only one residue #167

Closed nitroamos closed 6 years ago

nitroamos commented 6 years ago

I'm setting up a bunch of test cases and I ran into an exception. In this pdb, I've removed all but one residue, and then I tell PDBFixer not to add any residues. It still has to add the OXT. Based on this, I hit this exception:

Traceback (most recent call last):
  File "../pdbCompiler.py", line 152, in <module>
    fixer.addMissingAtoms()
  File "/home/andera52/workspace/PDBCompiler/pdbCompilerAnacondaEnv/lib/python3.6/site-packages/pdbfixer/pdbfixer.py", line 931, in addMissingAtoms
    nearest = self._findNearestDistance(context, newTopology, newAtoms)
  File "/home/andera52/workspace/PDBCompiler/pdbCompilerAnacondaEnv/lib/python3.6/site-packages/pdbfixer/pdbfixer.py", line 1180, in _findNearestDistance
    dist = math.sqrt(min(np.dot(p[i], p[i]) for i in range(len(atomResidue)) if atomResidue[i] != atom.residue))
ValueError: min() arg is an empty sequence

It looks like the problem is because there's only one residue in the protein, but _findNearestDistance is looking for a different residue than the one the atom is in. Maybe this could easily be fixed by _findNearestDistance returning sys.float_info.max in this case.

My guess is this kind of edge case likely only comes up in testing so probably you don't care, but I thought I'd report it anyway. :-)

test1.pdb.gz