"plugins/amoeba/vscode:/vscode.git/clone" did not exist on "b4543a46335e7dff5d1c2555d1ec98389e2f4dfb"
Commit 2c80cda8 authored by peastman's avatar peastman
Browse files

Merge pull request #1210 from jchodera/top

Added getNumAtoms, getNumResidues, getNumChains to simtk.openmm.app.Topology
parents 2049b1fe d74e4789
...@@ -62,12 +62,30 @@ class Topology(object): ...@@ -62,12 +62,30 @@ class Topology(object):
def __repr__(self): def __repr__(self):
nchains = len(self._chains) nchains = len(self._chains)
nres = sum(1 for r in self.residues()) nres = self._numResidues
natom = sum(1 for a in self.atoms()) natom = self._numAtoms
nbond = len(self._bonds) nbond = len(self._bonds)
return '<%s; %d chains, %d residues, %d atoms, %d bonds>' % ( return '<%s; %d chains, %d residues, %d atoms, %d bonds>' % (
type(self).__name__, nchains, nres, natom, nbond) type(self).__name__, nchains, nres, natom, nbond)
def getNumAtoms(self):
"""Return the number of atoms in the Topology.
"""
natom = self._numAtoms
return natom
def getNumResidues(self):
"""Return the number of residues in the Topology.
"""
nres = self._numResidues
return nres
def getNumChains(self):
"""Return the number of chains in the Topology.
"""
nchain = len(self._chains)
return nchain
def addChain(self, id=None): def addChain(self, id=None):
"""Create a new Chain and add it to the Topology. """Create a new Chain and add it to the Topology.
......
import sys
import unittest
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
import simtk.openmm.app.element as elem
if sys.version_info >= (3, 0):
from io import StringIO
else:
from cStringIO import StringIO
class TestTopology(unittest.TestCase):
"""Test the Topology object"""
def check_pdbfile(self, pdbfilename, natoms, nres, nchains):
"""Check that a PDB file has the specified number of atoms, residues, and chains."""
pdb = PDBFile(pdbfilename)
top = pdb.topology
self.assertEqual(pdb.topology.getNumAtoms(), natoms)
self.assertEqual(pdb.topology.getNumResidues(), nres)
self.assertEqual(pdb.topology.getNumChains(), nchains)
def test_getters(self):
"""Test getters for number of atoms, residues, chains."""
self.check_pdbfile('systems/1T2Y.pdb', 271, 25, 1)
if __name__ == '__main__':
unittest.main()
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