本文整理匯總了Python中MMTK.Utility.uniqueAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Python Utility.uniqueAttribute方法的具體用法?Python Utility.uniqueAttribute怎麽用?Python Utility.uniqueAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MMTK.Utility
的用法示例。
在下文中一共展示了Utility.uniqueAttribute方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import uniqueAttribute [as 別名]
def write(self, object, configuration = None, tag = None):
"""
Write an object to the file
:param object: the object to be written
:type object: :class:`~MMTK.Collections.GroupOfAtoms`
:param configuration: the configuration from which the coordinates
are taken (default: current configuration)
:type configuration: :class:`~MMTK.ParticleProperties.Configuration`
"""
if not ChemicalObjects.isChemicalObject(object):
for o in object:
self.write(o, configuration)
else:
toplevel = tag is None
if toplevel:
tag = Utility.uniqueAttribute()
if hasattr(object, 'pdbmap'):
for residue in object.pdbmap:
self.file.nextResidue(residue[0], )
sorted_atoms = residue[1].items()
sorted_atoms.sort(lambda x, y:
cmp(x[1].number, y[1].number))
for atom_name, atom in sorted_atoms:
atom = object.getAtom(atom)
p = atom.position(configuration)
if Utility.isDefinedPosition(p):
try: occ = atom.occupancy
except AttributeError: occ = 0.
try: temp = atom.temperature_factor
except AttributeError: temp = 0.
self.file.writeAtom(atom_name, p/Units.Ang,
occ, temp, atom.type.symbol)
self.atom_sequence.append(atom)
else:
self.warning = True
setattr(atom, tag, None)
else:
if hasattr(object, 'is_protein'):
for chain in object:
self.write(chain, configuration, tag)
elif hasattr(object, 'is_chain'):
self.file.nextChain(None, object.name)
for residue in object:
self.write(residue, configuration, tag)
self.file.terminateChain()
elif hasattr(object, 'molecules'):
for m in object.molecules:
self.write(m, configuration, tag)
elif hasattr(object, 'groups'):
for g in object.groups:
self.write(g, configuration, tag)
if toplevel:
for a in object.atomList():
if not hasattr(a, tag):
self.write(a, configuration, tag)
delattr(a, tag)
示例2: evaluatorTerms
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import uniqueAttribute [as 別名]
def evaluatorTerms(self, universe, subset1, subset2, global_data):
data = ForceFieldData()
if subset1 is not None:
label1 = Utility.uniqueAttribute()
label2 = Utility.uniqueAttribute()
for atom in subset1.atomList():
setattr(atom, label1, None)
for atom in subset2.atomList():
setattr(atom, label2, None)
for o in universe:
for bu in o.bondedUnits():
if not hasattr(bu, 'bonds'): continue
options = {'bonds': 1, 'bond_angles': 1,
'dihedrals': 1, 'impropers': 1}
self.getOptions(bu, options)
if options['bonds']:
if subset1 is None:
for bond in bu.bonds:
self.addBondTerm(data, bond, bu, global_data)
else:
for bond in bu.bonds:
atoms = [bond.a1, bond.a2]
if _checkSubset(atoms, label1, label2):
self.addBondTerm(data, bond, bu, global_data)
if options['bond_angles']:
if subset1 is None:
for angle in bu.bonds.bondAngles():
self.addBondAngleTerm(data, angle, bu, global_data)
else:
for angle in bu.bonds.bondAngles():
atoms = [angle.a1, angle.a2, angle.ca]
if _checkSubset(atoms, label1, label2):
self.addBondAngleTerm(data, angle, bu,
global_data)
d = options['dihedrals']
i = options['impropers']
if d or i:
if subset1 is None:
for angle in bu.bonds.dihedralAngles():
if angle.improper and i:
self.addImproperTerm(data, angle, bu,
global_data)
elif not angle.improper and d:
self.addDihedralTerm(data, angle, bu,
global_data)
else:
for angle in bu.bonds.dihedralAngles():
atoms = [angle.a1, angle.a2, angle.a3, angle.a4]
if _checkSubset(atoms, label1, label2):
if angle.improper and i:
self.addImproperTerm(data, angle, bu,
global_data)
elif not angle.improper and d:
self.addDihedralTerm(data, angle, bu,
global_data)
if subset1 is not None:
for atom in subset1.atomList():
delattr(atom, label1)
for atom in subset2.atomList():
delattr(atom, label2)
global_data.add('initialized', 'bonded')
from MMTK_forcefield import HarmonicDistanceTerm, HarmonicAngleTerm, \
CosineDihedralTerm
eval_list = []
bonds = data.get('bonds')
if bonds:
import sys
main = sys.modules['__main__']
indices = Numeric.array(map(lambda b: b[:2], bonds))
parameters = Numeric.array(map(lambda b: b[2:], bonds))
## setattr(main, 'indices', indices)
## setattr(main, 'parameters', parameters)
## print parameters
eval_list.append(HarmonicDistanceTerm(universe._spec,
indices, parameters))
angles = data.get('angles')
if angles:
indices = Numeric.array(map(lambda a: a[:3], angles))
parameters = Numeric.array(map(lambda a: a[3:], angles))
eval_list.append(HarmonicAngleTerm(universe._spec,
indices, parameters))
dihedrals = data.get('dihedrals')
if dihedrals:
def _dihedral_parameters(p):
return [p[4], Numeric.cos(p[5]), Numeric.sin(p[5]), p[6]]
indices = Numeric.array(map(lambda d: d[:4], dihedrals))
parameters = Numeric.array(map(_dihedral_parameters, dihedrals))
eval_list.append(CosineDihedralTerm(universe._spec,
indices, parameters))
return eval_list
示例3: description
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import uniqueAttribute [as 別名]
def description(self, index_map = None):
tag = Utility.uniqueAttribute()
s = self._description(tag, index_map, 1)
for a in self.atomList():
delattr(a, tag)
return s
示例4: evaluatorParameters
# 需要導入模塊: from MMTK import Utility [as 別名]
# 或者: from MMTK.Utility import uniqueAttribute [as 別名]
def evaluatorParameters(self, universe, subset1, subset2, global_data):
data = ForceFieldData()
data.set('universe', universe)
if subset1 is not None:
label1 = Utility.uniqueAttribute()
label2 = Utility.uniqueAttribute()
for atom in subset1.atomList():
setattr(atom, label1, None)
for atom in subset2.atomList():
setattr(atom, label2, None)
for o in universe:
for bu in o.bondedUnits():
if not hasattr(bu, 'bonds'): continue
options = {'bonds': 1, 'bond_angles': 1,
'dihedrals': 1, 'impropers': 1}
self.getOptions(bu, options)
if options['bonds']:
if subset1 is None:
for bond in bu.bonds:
self.addBondTerm(data, bond, bu, global_data)
else:
for bond in bu.bonds:
atoms = [bond.a1, bond.a2]
if _checkSubset(atoms, label1, label2):
self.addBondTerm(data, bond, bu, global_data)
if options['bond_angles']:
if subset1 is None:
for angle in bu.bonds.bondAngles():
self.addBondAngleTerm(data, angle, bu, global_data)
else:
for angle in bu.bonds.bondAngles():
atoms = [angle.a1, angle.a2, angle.ca]
if _checkSubset(atoms, label1, label2):
self.addBondAngleTerm(data, angle, bu,
global_data)
d = options['dihedrals']
i = options['impropers']
if d or i:
if subset1 is None:
for angle in bu.bonds.dihedralAngles():
if angle.improper and i:
self.addImproperTerm(data, angle, bu,
global_data)
elif not angle.improper and d:
self.addDihedralTerm(data, angle, bu,
global_data)
else:
for angle in bu.bonds.dihedralAngles():
atoms = [angle.a1, angle.a2, angle.a3, angle.a4]
if _checkSubset(atoms, label1, label2):
if angle.improper and i:
self.addImproperTerm(data, angle, bu,
global_data)
elif not angle.improper and d:
self.addDihedralTerm(data, angle, bu,
global_data)
if subset1 is not None:
for atom in subset1.atomList():
delattr(atom, label1)
for atom in subset2.atomList():
delattr(atom, label2)
global_data.add('initialized', 'bonded')
return {'harmonic_distance_term': data.get('bonds'),
'harmonic_angle_term': data.get('angles'),
'cosine_dihedral_term': data.get('dihedrals')}