Commit a700032d authored by Peter Eastman's avatar Peter Eastman
Browse files

Added Topology.loadBondDefinitions()

parent cd68d924
...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of ...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org. Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2012 Stanford University and the Authors. Portions copyright (c) 2012-2013 Stanford University and the Authors.
Authors: Peter Eastman Authors: Peter Eastman
Contributors: Contributors:
...@@ -47,6 +47,7 @@ class Topology(object): ...@@ -47,6 +47,7 @@ class Topology(object):
""" """
_standardBonds = {} _standardBonds = {}
_hasLoadedStandardBonds = False
def __init__(self): def __init__(self):
"""Create a new Topology object""" """Create a new Topology object"""
...@@ -133,17 +134,32 @@ class Topology(object): ...@@ -133,17 +134,32 @@ class Topology(object):
"""Set the dimensions of the crystallographic unit cell.""" """Set the dimensions of the crystallographic unit cell."""
self._unitCellDimensions = dimensions self._unitCellDimensions = dimensions
@staticmethod
def loadBondDefinitions(file):
"""Load an XML file containing definitions of bonds that should be used by createStandardBonds().
The built in residues.xml file containing definitions for standard amino acids and nucleotides is loaded automatically.
This method can be used to load additional definitions for other residue types. They will then be used in subsequent
calls to createStandardBonds().
"""
tree = etree.parse(file)
for residue in tree.getroot().findall('Residue'):
bonds = []
Topology._standardBonds[residue.attrib['name']] = bonds
for bond in residue.findall('Bond'):
bonds.append((bond.attrib['from'], bond.attrib['to']))
def createStandardBonds(self): def createStandardBonds(self):
"""Create bonds based on the atom and residue names for all standard residue types.""" """Create bonds based on the atom and residue names for all standard residue types.
if len(Topology._standardBonds) == 0:
# Load the standard bond defitions. Definitions for standard amino acids and nucleotides are built in. You can call loadBondDefinitions() to load
additional definitions for other residue types.
"""
if not Topology._hasLoadedStandardBonds:
# Load the standard bond definitions.
tree = etree.parse(os.path.join(os.path.dirname(__file__), 'data', 'residues.xml')) Topology.loadBondDefinitions(os.path.join(os.path.dirname(__file__), 'data', 'residues.xml'))
for residue in tree.getroot().findall('Residue'): Topology._hasLoadedStandardBonds = True
bonds = []
Topology._standardBonds[residue.attrib['name']] = bonds
for bond in residue.findall('Bond'):
bonds.append((bond.attrib['from'], bond.attrib['to']))
for chain in self._chains: for chain in self._chains:
# First build a map of atom names to atoms. # First build a map of atom names to atoms.
......
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