本文整理匯總了Python中MMTK.Utility.isSequenceObject方法的典型用法代碼示例。如果您正苦於以下問題:Python Utility.isSequenceObject方法的具體用法?Python Utility.isSequenceObject怎麽用?Python Utility.isSequenceObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MMTK.Utility
的用法示例。
在下文中一共展示了Utility.isSequenceObject方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: removeObject
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import isSequenceObject [as 別名]
def removeObject(self, object):
"""
Remove an object or a list or collection of objects from the
collection. The object(s) to be removed must be elements of the
collection.
:param object: the object to be removed, or a list or collection
of objects whose elements are to be removed
:raises ValueError: if the object is not an element of the collection
"""
from MMTK.ChemicalObjects import isChemicalObject
if isChemicalObject(object):
self.removeChemicalObject(object)
elif isCollection(object) or Utility.isSequenceObject(object):
for o in object:
self.removeObject(o)
else:
raise ValueError('Object not in this collection')
示例2: addObject
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import isSequenceObject [as 別名]
def addObject(self, object):
"""
Add objects to the collection.
:param object: the object(s) to be added. If it is another collection
or a list, all of its elements are added
"""
from MMTK.ChemicalObjects import isChemicalObject
if isChemicalObject(object):
self.addChemicalObject(object)
elif isCollection(object):
self.addChemicalObjectList(object.objectList())
elif Utility.isSequenceObject(object):
if object and isChemicalObject(object[0]):
self.addChemicalObjectList(list(object))
else:
for o in object:
self.addObject(o)
else:
raise TypeError('Wrong object type in collection')
示例3: __init__
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import isSequenceObject [as 別名]
def __init__(self, universe, objects):
"""
:param universe: the universe for which the subspace is created
:type universe: :class:`~MMTK.Universe.Universe`
:param objects: a sequence of objects whose rigid-body motion is
included in the subspace
"""
if not Utility.isSequenceObject(objects):
objects = [objects]
else:
objects = copy.copy(objects)
# Identify connected sets of linked rigid bodies and remove
# them from the plain rigid body list.
atom_map = {}
for o in objects:
for a in o.atomIterator():
am = atom_map.get(a, [])
am.append(o)
atom_map[a] = am
rb_map = {}
for rbs in atom_map.values():
if len(rbs) > 1:
for rb in rbs:
rb_map[rb] = rb_map.get(rb, frozenset()) \
.union(frozenset(rbs))
for rb in rb_map.keys():
objects.remove(rb)
while True:
changed = False
for rbs in rb_map.values():
for rb in rbs:
s = rb_map[rb]
rb_map[rb] = s.union(rbs)
if s != rb_map[rb]:
changed = True
if not changed:
break
lrbs = frozenset(rb_map.values())
# Generate the subspace vectors for the isolated rigid bodies.
ex_ey_ez = [Vector(1.,0.,0.), Vector(0.,1.,0.), Vector(0.,0.,1.)]
vectors = []
for o in objects:
rb_atoms = o.atomList()
for d in ex_ey_ez:
v = ParticleProperties.ParticleVector(universe)
for a in rb_atoms:
v[a] = d
vectors.append(v/N.sqrt(len(rb_atoms)))
if len(rb_atoms) > 1:
center = o.centerOfMass()
iv = len(vectors)-3
for d in ex_ey_ez:
v = ParticleProperties.ParticleVector(universe)
for a in rb_atoms:
v[a] = d.cross(a.position()-center)
for vt in vectors[iv:]:
v -= v.dotProduct(vt)*vt
norm_sq = N.sqrt(v.dotProduct(v))
if norm_sq > 0.:
vectors.append(v/norm_sq)
# Generate the subspace vectors for the linked rigid bodies.
for lrb in lrbs:
lrb_ss = LinkedRigidBodyMotionSubspace(universe, lrb)
for v in lrb_ss.getBasis():
vectors.append(v)
Subspace.__init__(self, universe, vectors)
# The vector set is already orthonormal by construction,
# so we can skip the lengthy SVD procedure.
self._basis = ParticleVectorSet(universe, len(vectors))
for i in range(len(vectors)):
self._basis.array[i] = vectors[i].array