本文整理匯總了Python中mdtraj.core.topology.Topology.from_openmm方法的典型用法代碼示例。如果您正苦於以下問題:Python Topology.from_openmm方法的具體用法?Python Topology.from_openmm怎麽用?Python Topology.from_openmm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mdtraj.core.topology.Topology
的用法示例。
在下文中一共展示了Topology.from_openmm方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _initialize
# 需要導入模塊: from mdtraj.core.topology import Topology [as 別名]
# 或者: from mdtraj.core.topology.Topology import from_openmm [as 別名]
def _initialize(self, simulation):
"""Deferred initialization of the reporter, which happens before
processing the first report.
At the time that the first report is processed, we now have access
to the simulation object, which we don't have at the point when the
reporter is instantiated
Parameters
----------
simulation : simtk.openmm.app.Simulation
The Simulation to generate a report for
"""
if self._atomSubset is not None:
if not min(self._atomSubset) >= 0:
raise ValueError('atomSubset must be zero indexed. '
'the smallest allowable value is zero')
if not max(self._atomSubset) < simulation.system.getNumParticles():
raise ValueError('atomSubset must be zero indexed. '
'the largest value must be less than the number '
'of particles in the system')
if not all(a==int(a) for a in self._atomSubset):
raise ValueError('all of the indices in atomSubset must be integers')
self._atomSlice = self._atomSubset
if hasattr(self._traj_file, 'topology'):
self._traj_file.topology = _topology_from_subset(
Topology.from_openmm(simulation.topology), self._atomSubset)
else:
self._atomSlice = slice(None)
if hasattr(self._traj_file, 'topology'):
self._traj_file.topology = Topology.from_openmm(simulation.topology)
system = simulation.system
if self._temperature:
# Compute the number of degrees of freedom.
dof = 0
for i in range(system.getNumParticles()):
if system.getParticleMass(i) > 0*units.dalton:
dof += 3
dof -= system.getNumConstraints()
if any(type(system.getForce(i)) == mm.CMMotionRemover for i in range(system.getNumForces())):
dof -= 3
self._dof = dof
if simulation.topology.getUnitCellDimensions() is None:
self._cell = False
示例2: topology
# 需要導入模塊: from mdtraj.core.topology import Topology [as 別名]
# 或者: from mdtraj.core.topology.Topology import from_openmm [as 別名]
def topology(self, topology_object):
"""Set the topology in the file
Parameters
----------
topology_object : mdtraj.Topology
A topology object
"""
# we want to be able to handle the simtk.openmm Topology object
# here too, so if it's not an mdtraj topology we'll just guess
# that it's probably an openmm topology and convert
if not isinstance(topology_object, Topology):
topology_object = Topology.from_openmm(topology_object)
try:
topology_dict = {"chains": [], "bonds": []}
for chain in topology_object.chains:
chain_dict = {"residues": [], "index": int(chain.index)}
for residue in chain.residues:
residue_dict = {
"index": int(residue.index),
"name": str(residue.name),
"atoms": [],
"resSeq": int(residue.resSeq),
}
for atom in residue.atoms:
try:
element_symbol_string = str(atom.element.symbol)
except AttributeError:
element_symbol_string = ""
residue_dict["atoms"].append(
{"index": int(atom.index), "name": str(atom.name), "element": element_symbol_string}
)
chain_dict["residues"].append(residue_dict)
topology_dict["chains"].append(chain_dict)
for atom1, atom2 in topology_object.bonds:
topology_dict["bonds"].append([int(atom1.index), int(atom2.index)])
except AttributeError as e:
raise AttributeError(
"topology_object fails to implement the"
"chains() -> residue() -> atoms() and bond() protocol. "
"Specifically, we encountered the following %s" % e
)
# actually set the tables
try:
self._remove_node(where="/", name="topology")
except self.tables.NoSuchNodeError:
pass
data = json.dumps(topology_dict)
if not isinstance(data, bytes):
data = data.encode("ascii")
if self.tables.__version__ >= "3.0.0":
self._handle.create_array(where="/", name="topology", obj=[data])
else:
self._handle.createArray(where="/", name="topology", object=[data])
示例3: topology
# 需要導入模塊: from mdtraj.core.topology import Topology [as 別名]
# 或者: from mdtraj.core.topology.Topology import from_openmm [as 別名]
def topology(self, topology_object):
"""Set the topology in the file
Parameters
----------
topology_object : mdtraj.Topology
A topology object
"""
_check_mode(self.mode, ('w', 'a'))
# we want to be able to handle the simtk.openmm Topology object
# here too, so if it's not an mdtraj topology we'll just guess
# that it's probably an openmm topology and convert
if not isinstance(topology_object, Topology):
topology_object = Topology.from_openmm(topology_object)
try:
topology_dict = {
'chains': [],
'bonds': []
}
for chain in topology_object.chains:
chain_dict = {
'residues': [],
'index': int(chain.index)
}
for residue in chain.residues:
residue_dict = {
'index': int(residue.index),
'name': str(residue.name),
'atoms': [],
"resSeq": int(residue.resSeq),
"segmentID": str(residue.segment_id)
}
for atom in residue.atoms:
try:
element_symbol_string = str(atom.element.symbol)
except AttributeError:
element_symbol_string = ""
residue_dict['atoms'].append({
'index': int(atom.index),
'name': str(atom.name),
'element': element_symbol_string
})
chain_dict['residues'].append(residue_dict)
topology_dict['chains'].append(chain_dict)
for atom1, atom2 in topology_object.bonds:
topology_dict['bonds'].append([
int(atom1.index),
int(atom2.index)
])
except AttributeError as e:
raise AttributeError('topology_object fails to implement the'
'chains() -> residue() -> atoms() and bond() protocol. '
'Specifically, we encountered the following %s' % e)
# actually set the tables
try:
self._remove_node(where='/', name='topology')
except self.tables.NoSuchNodeError:
pass
data = json.dumps(topology_dict)
if not isinstance(data, bytes):
data = data.encode('ascii')
if self.tables.__version__ >= '3.0.0':
self._handle.create_array(where='/', name='topology', obj=[data])
else:
self._handle.createArray(where='/', name='topology', object=[data])