本文整理汇总了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])