Commit 13a801ab by peastman

Fixed error when a file contains only one residue

parent 733dc3ae
...@@ -928,25 +928,26 @@ class PDBFixer(object): ...@@ -928,25 +928,26 @@ class PDBFixer(object):
context.setPositions(newPositions) context.setPositions(newPositions)
mm.LocalEnergyMinimizer.minimize(context) mm.LocalEnergyMinimizer.minimize(context)
state = context.getState(getPositions=True) state = context.getState(getPositions=True)
nearest = self._findNearestDistance(context, newTopology, newAtoms) if newTopology.getNumResidues() > 1:
if nearest < 0.13: nearest = self._findNearestDistance(context, newTopology, newAtoms)
if nearest < 0.13:
# Some atoms are very close together. Run some dynamics while slowly increasing the strength of the
# repulsive interaction to try to improve the result. # Some atoms are very close together. Run some dynamics while slowly increasing the strength of the
# repulsive interaction to try to improve the result.
for i in range(10):
context.setParameter('C', 0.15*(i+1)) for i in range(10):
integrator.step(200) context.setParameter('C', 0.15*(i+1))
d = self._findNearestDistance(context, newTopology, newAtoms) integrator.step(200)
if d > nearest: d = self._findNearestDistance(context, newTopology, newAtoms)
nearest = d if d > nearest:
state = context.getState(getPositions=True) nearest = d
if nearest >= 0.13: state = context.getState(getPositions=True)
break if nearest >= 0.13:
context.setState(state) break
context.setParameter('C', 1.0) context.setState(state)
mm.LocalEnergyMinimizer.minimize(context) context.setParameter('C', 1.0)
state = context.getState(getPositions=True) mm.LocalEnergyMinimizer.minimize(context)
state = context.getState(getPositions=True)
# Now create a new Topology, including all atoms from the original one and adding the missing atoms. # Now create a new Topology, including all atoms from the original one and adding the missing atoms.
......
...@@ -10,9 +10,10 @@ def test_mutate_1(): ...@@ -10,9 +10,10 @@ def test_mutate_1():
fixer.findMissingAtoms() fixer.findMissingAtoms()
fixer.addMissingAtoms() fixer.addMissingAtoms()
fixer.addMissingHydrogens(7.0) fixer.addMissingHydrogens(7.0)
temp_pdb = tempfile.NamedTemporaryFile(mode='w+') with tempfile.NamedTemporaryFile(mode='w+') as temp_pdb:
app.PDBFile.writeFile(fixer.topology, fixer.positions, temp_pdb) app.PDBFile.writeFile(fixer.topology, fixer.positions, temp_pdb)
pdb = app.PDBFile(temp_pdb.name) temp_pdb.flush()
pdb = app.PDBFile(temp_pdb.name)
new_residue57 = list(fixer.topology.residues())[16] new_residue57 = list(fixer.topology.residues())[16]
assert new_residue57.name == "GLY", "Name of mutated residue did not change correctly!" assert new_residue57.name == "GLY", "Name of mutated residue did not change correctly!"
......
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