/usr/share/pyshared/MMTK/Skeleton.py is in python-mmtk 2.7.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # This module handles the skeleton descriptions stored in trajectory files.
#
# Written by Konrad Hinsen
#
import MMTK
import MMTK.Environment
import MMTK.ForceFields
import copy, sys, types
#
# Atoms
#
class A:
def __init__(self, name, index, type = None):
self.name = name
self.index = index
self.type = type
def make(self, info, conf = None):
atom = MMTK.Atom(self.type, name = self.name)
self.assignIndex(atom, info, conf)
return atom
def assignIndex(self, atom, info, conf):
atom.setIndex(self.index)
info[self.index] = atom
if conf is not None and self.index is not None:
atom.setPosition(MMTK.Vector(conf[self.index]))
#
# Composite chemical objects
#
class Composite:
def __init__(self, name, list, type = None, **kwargs):
self.name = name
self.list = list
self.type = type
self.kwargs = kwargs
def make(self, info, conf = None):
object = self._class(self.type, name=self.name)
for sub in self.list:
sub.assignIndex(getattr(object, sub.name), info, conf)
if self.kwargs.has_key('dc'):
for a1, a2, d in self.kwargs['dc']:
object.addDistanceConstraint(info[a1], info[a2], d)
return object
def assignIndex(self, object, info, conf):
for sub in self.list:
sub.assignIndex(getattr(object, sub.name), info, conf)
class G(Composite):
pass
class M(Composite):
_class = MMTK.Molecule
class C(Composite):
_class = MMTK.Complex
class AC(Composite):
def make(self, info, conf = None):
atoms = map(lambda a, i=info, c=conf: a.make(i, c), self.list)
return MMTK.AtomCluster(atoms, name = self.name)
#class X(Composite):
# _class = MMTK.Crystal
class S(Composite):
def make(self, info, conf = None):
import MMTK.Proteins
n_residues = len(self.type)/3
residues = [self.type[3*i:3*i+3] for i in range(n_residues)]
self.kwargs['name'] = self.name
chain = apply(MMTK.Proteins.PeptideChain, (residues,), self.kwargs)
for i in range(len(self.list)):
self.list[i].assignIndex(chain[i], info, conf)
chain[i].name = self.list[i].name
return chain
class N(Composite):
def make(self, info, conf = None):
import MMTK.NucleicAcids
n_residues = len(self.type)/3
residues = [self.type[3*i:3*i+3].strip() for i in range(n_residues)]
self.kwargs['name'] = self.name
chain = apply(MMTK.NucleicAcids.NucleotideChain, (residues,),
self.kwargs)
for i in range(len(self.list)):
self.list[i].assignIndex(chain[i], info, conf)
return chain
#
# Collections and universes
#
class c:
def __init__(self, creation, objects):
self.creation = creation
self.objects = objects
def make(self, info, conf = None):
collection = _evalString(self.creation)
attr = None
for o in self.objects:
if isinstance(o, basestring):
attr = o
elif attr:
setattr(collection, attr, o.make(info, conf))
attr = None
else:
collection.addObject(o.make(info, conf))
return collection
#
# Objects constructed from a list of other objects (e.g. proteins)
#
class l:
def __init__(self, class_name, name, objects):
self.class_name = class_name
self.objects = objects
self.name = name
def make(self, info, conf = None):
import MMTK.Proteins
classes = {'Protein': MMTK.Proteins.Protein}
return classes[self.class_name] \
(map(lambda o, i=info, c=conf: o.make(i, c), self.objects),
name = self.name)
#
# Objects without subobjects
#
class o:
def __init__(self, creation):
self.creation = creation
def make(self, info, conf = None):
return _evalString(self.creation)
#
# Evaluate description string
# In case of a NameError, suppose the missing name is the name of a
# module, import that module, and try again. In case of an AttributeError,
# suppose that the missing attribute is a subpackage, import that subpackage,
# and try again.
#
def _evalString(description):
local = {}
namespace = copy.copy(vars(MMTK))
namespace['MMTK'] = MMTK
imported = ['MMTK', 'MMTK.ForceFields']
done = False
while not done:
try:
o = eval(description, namespace, local)
done = True
except NameError, exception:
name = str(exception).split("'")[1]
__import__(name)
namespace[name] = sys.modules[name]
imported.append(name)
except AttributeError, exception:
if str(exception).split("'")[1] == "module":
name = str(exception).split("'")[3]
for m in imported:
try:
module_name = "%s.%s" % (m, name)
__import__(module_name)
imported.append(module_name)
except ImportError:
pass
else:
raise
return o
|