9 from sys
import version_info
10 if version_info >= (2,6,0):
11 def swig_import_helper():
12 from os.path
import dirname
16 fp, pathname, description = imp.find_module(
'_IMP_modeller', [dirname(__file__)])
22 _mod = imp.load_module(
'_IMP_modeller', fp, pathname, description)
26 _IMP_modeller = swig_import_helper()
27 del swig_import_helper
32 _swig_property = property
35 def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
36 if (name ==
"thisown"):
return self.this.own(value)
38 if type(value).__name__ ==
'SwigPyObject':
39 self.__dict__[name] = value
41 method = class_type.__swig_setmethods__.get(name,
None)
42 if method:
return method(self,value)
44 self.__dict__[name] = value
46 raise AttributeError(
"You cannot add attributes to %s" % self)
48 def _swig_setattr(self,class_type,name,value):
49 return _swig_setattr_nondynamic(self,class_type,name,value,0)
51 def _swig_getattr(self,class_type,name):
52 if (name ==
"thisown"):
return self.this.own()
53 method = class_type.__swig_getmethods__.get(name,
None)
54 if method:
return method(self)
55 raise AttributeError(name)
58 try: strthis =
"proxy of " + self.this.__repr__()
60 return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
65 except AttributeError:
72 weakref_proxy = weakref.proxy
74 weakref_proxy =
lambda x: x
77 class IMP_MODELLER_SwigPyIterator(_object):
78 """Proxy of C++ swig::IMP_MODELLER_SwigPyIterator class"""
79 __swig_setmethods__ = {}
80 __setattr__ =
lambda self, name, value: _swig_setattr(self, IMP_MODELLER_SwigPyIterator, name, value)
81 __swig_getmethods__ = {}
82 __getattr__ =
lambda self, name: _swig_getattr(self, IMP_MODELLER_SwigPyIterator, name)
83 def __init__(self, *args, **kwargs):
raise AttributeError(
"No constructor defined - class is abstract")
85 __swig_destroy__ = _IMP_modeller.delete_IMP_MODELLER_SwigPyIterator
86 __del__ =
lambda self :
None;
88 """value(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
89 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_value(self)
93 incr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
94 incr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
96 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_incr(self, n)
100 decr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
101 decr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
103 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_decr(self, n)
105 def distance(self, *args):
106 """distance(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t"""
107 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_distance(self, *args)
109 def equal(self, *args):
110 """equal(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
111 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_equal(self, *args)
114 """copy(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator"""
115 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_copy(self)
118 """next(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
119 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_next(self)
122 """__next__(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
123 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___next__(self)
126 """previous(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
127 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_previous(self)
129 def advance(self, *args):
130 """advance(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
131 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_advance(self, *args)
133 def __eq__(self, *args):
134 """__eq__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
135 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___eq__(self, *args)
137 def __ne__(self, *args):
138 """__ne__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
139 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___ne__(self, *args)
141 def __iadd__(self, *args):
142 """__iadd__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
143 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___iadd__(self, *args)
145 def __isub__(self, *args):
146 """__isub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
147 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___isub__(self, *args)
149 def __add__(self, *args):
150 """__add__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
151 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___add__(self, *args)
153 def __sub__(self, *args):
155 __sub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator
156 __sub__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t
158 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___sub__(self, *args)
160 def __iter__(self):
return self
161 IMP_MODELLER_SwigPyIterator_swigregister = _IMP_modeller.IMP_MODELLER_SwigPyIterator_swigregister
162 IMP_MODELLER_SwigPyIterator_swigregister(IMP_MODELLER_SwigPyIterator)
169 IMP_HAS_DEPRECATED = _IMP_modeller.IMP_HAS_DEPRECATED
170 IMP_DEBUG = _IMP_modeller.IMP_DEBUG
171 IMP_RELEASE = _IMP_modeller.IMP_RELEASE
172 IMP_SILENT = _IMP_modeller.IMP_SILENT
173 IMP_PROGRESS = _IMP_modeller.IMP_PROGRESS
174 IMP_TERSE = _IMP_modeller.IMP_TERSE
175 IMP_VERBOSE = _IMP_modeller.IMP_VERBOSE
176 IMP_NONE = _IMP_modeller.IMP_NONE
177 IMP_USAGE = _IMP_modeller.IMP_USAGE
178 IMP_INTERNAL = _IMP_modeller.IMP_INTERNAL
179 IMP_COMPILER_HAS_AUTO = _IMP_modeller.IMP_COMPILER_HAS_AUTO
180 IMP_COMPILER_HAS_DEBUG_VECTOR = _IMP_modeller.IMP_COMPILER_HAS_DEBUG_VECTOR
181 IMP_COMPILER_HAS_NULLPTR = _IMP_modeller.IMP_COMPILER_HAS_NULLPTR
182 IMP_BASE_HAS_BOOST_RANDOM = _IMP_modeller.IMP_BASE_HAS_BOOST_RANDOM
183 IMP_BASE_HAS_GPERFTOOLS = _IMP_modeller.IMP_BASE_HAS_GPERFTOOLS
184 IMP_BASE_HAS_LOG4CXX = _IMP_modeller.IMP_BASE_HAS_LOG4CXX
185 IMP_BASE_HAS_TCMALLOC_HEAPCHECKER = _IMP_modeller.IMP_BASE_HAS_TCMALLOC_HEAPCHECKER
186 IMP_BASE_HAS_TCMALLOC_HEAPPROFILER = _IMP_modeller.IMP_BASE_HAS_TCMALLOC_HEAPPROFILER
188 class _DirectorObjects(object):
189 """@internal Simple class to keep references to director objects
190 to prevent premature deletion."""
193 def register(self, obj):
194 """Take a reference to a director object; will only work for
195 refcounted C++ classes"""
196 if hasattr(obj,
'get_ref_count'):
197 self._objects.append(obj)
199 """Only drop our reference and allow cleanup by Python if no other
200 Python references exist (we hold 3 references: one in self._objects,
201 one in x, and one in the argument list for getrefcount) *and* no
202 other C++ references exist (the Python object always holds one)"""
203 objs = [x
for x
in self._objects
if sys.getrefcount(x) > 3 \
204 or x.get_ref_count() > 1]
208 def get_object_count(self):
209 """Get number of director objects (useful for testing only)"""
210 return len(self._objects)
211 _director_objects = _DirectorObjects()
213 DEFAULT_CHECK = _IMP_modeller.DEFAULT_CHECK
214 NONE = _IMP_modeller.NONE
215 USAGE = _IMP_modeller.USAGE
216 USAGE_AND_INTERNAL = _IMP_modeller.USAGE_AND_INTERNAL
219 """set_check_level(IMP::base::CheckLevel tf)"""
220 return _IMP_modeller.set_check_level(*args)
223 """get_check_level() -> IMP::base::CheckLevel"""
224 return _IMP_modeller.get_check_level()
225 class _ostream(_object):
226 """Proxy of C++ std::ostream class"""
227 __swig_setmethods__ = {}
228 __setattr__ =
lambda self, name, value: _swig_setattr(self, _ostream, name, value)
229 __swig_getmethods__ = {}
230 __getattr__ =
lambda self, name: _swig_getattr(self, _ostream, name)
231 def __init__(self, *args, **kwargs):
raise AttributeError(
"No constructor defined")
232 __repr__ = _swig_repr
233 def write(self, *args):
234 """write(_ostream self, char const * osa_buf)"""
235 return _IMP_modeller._ostream_write(self, *args)
237 _ostream_swigregister = _IMP_modeller._ostream_swigregister
238 _ostream_swigregister(_ostream)
240 IMP_COMPILER_HAS_OVERRIDE = _IMP_modeller.IMP_COMPILER_HAS_OVERRIDE
241 IMP_COMPILER_HAS_FINAL = _IMP_modeller.IMP_COMPILER_HAS_FINAL
243 IMP_CGAL_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_FILESYSTEM
244 IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS
245 IMP_CGAL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CGAL_HAS_BOOST_RANDOM
246 IMP_CGAL_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_SYSTEM
248 IMP_ALGEBRA_HAS_IMP_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_IMP_CGAL
249 IMP_ALGEBRA_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_FILESYSTEM
250 IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS
251 IMP_ALGEBRA_HAS_BOOST_RANDOM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_RANDOM
252 IMP_ALGEBRA_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_SYSTEM
253 IMP_ALGEBRA_HAS_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_CGAL
254 IMP_ALGEBRA_HAS_ANN = _IMP_modeller.IMP_ALGEBRA_HAS_ANN
256 IMP_KERNEL_HAS_IMP_CGAL = _IMP_modeller.IMP_KERNEL_HAS_IMP_CGAL
257 IMP_KERNEL_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_KERNEL_HAS_BOOST_PROGRAMOPTIONS
258 IMP_KERNEL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_KERNEL_HAS_BOOST_RANDOM
259 IMP_KERNEL_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_KERNEL_HAS_BOOST_SYSTEM
260 IMP_KERNEL_HAS_CGAL = _IMP_modeller.IMP_KERNEL_HAS_CGAL
262 IMP_DISPLAY_HAS_IMP_BASE = _IMP_modeller.IMP_DISPLAY_HAS_IMP_BASE
263 IMP_DISPLAY_HAS_IMP_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_IMP_CGAL
264 IMP_DISPLAY_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_FILESYSTEM
265 IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS
266 IMP_DISPLAY_HAS_BOOST_RANDOM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_RANDOM
267 IMP_DISPLAY_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_SYSTEM
268 IMP_DISPLAY_HAS_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_CGAL
270 IMP_SCORE_FUNCTOR_HAS_IMP_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_IMP_CGAL
271 IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM
272 IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS
273 IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM
274 IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM
275 IMP_SCORE_FUNCTOR_HAS_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_CGAL
277 IMP_CORE_HAS_IMP_BASE = _IMP_modeller.IMP_CORE_HAS_IMP_BASE
278 IMP_CORE_HAS_IMP_CGAL = _IMP_modeller.IMP_CORE_HAS_IMP_CGAL
279 IMP_CORE_HAS_IMP_KERNEL = _IMP_modeller.IMP_CORE_HAS_IMP_KERNEL
280 IMP_CORE_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_FILESYSTEM
281 IMP_CORE_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CORE_HAS_BOOST_PROGRAMOPTIONS
282 IMP_CORE_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CORE_HAS_BOOST_RANDOM
283 IMP_CORE_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_SYSTEM
284 IMP_CORE_HAS_CGAL = _IMP_modeller.IMP_CORE_HAS_CGAL
286 IMP_MODELLER_HAS_IMP_ALGEBRA = _IMP_modeller.IMP_MODELLER_HAS_IMP_ALGEBRA
287 IMP_MODELLER_HAS_IMP_BASE = _IMP_modeller.IMP_MODELLER_HAS_IMP_BASE
288 IMP_MODELLER_HAS_IMP_CGAL = _IMP_modeller.IMP_MODELLER_HAS_IMP_CGAL
289 IMP_MODELLER_HAS_IMP_DISPLAY = _IMP_modeller.IMP_MODELLER_HAS_IMP_DISPLAY
290 IMP_MODELLER_HAS_IMP_KERNEL = _IMP_modeller.IMP_MODELLER_HAS_IMP_KERNEL
291 IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR = _IMP_modeller.IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR
292 IMP_MODELLER_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_FILESYSTEM
293 IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS
294 IMP_MODELLER_HAS_BOOST_RANDOM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_RANDOM
295 IMP_MODELLER_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_SYSTEM
296 IMP_MODELLER_HAS_CGAL = _IMP_modeller.IMP_MODELLER_HAS_CGAL
297 BinormalTermList=list
298 _plural_types.append(
"BinormalTermList")
299 _value_types.append(
"BinormalTerm")
301 _object_types.append(
"MultipleBinormalRestraint")
304 def _object_cast_to_MultipleBinormalRestraint(*args):
305 """_object_cast_to_MultipleBinormalRestraint(Object o) -> MultipleBinormalRestraint"""
306 return _IMP_modeller._object_cast_to_MultipleBinormalRestraint(*args)
316 def _import_modeller_scripts_optimizers():
317 """Do the equivalent of "import modeller.scripts, modeller.optimizers".
318 (We can't do the regular import because Python tries a relative import
319 first, and that would load the modeller module in IMP.) This is an
320 absolute import. Once we can require that everybody uses Python 2.6,
321 this should no longer be required."""
322 modeller = _import_module(
"modeller",
"modeller",
None)
323 scripts = _import_module(
"scripts",
"modeller.scripts", modeller)
324 optimizers = _import_module(
"optimizers",
"modeller.optimizers", modeller)
325 modeller.scripts = scripts
326 modeller.optimizers = optimizers
329 def _import_module(partname, fqname, parent):
330 """Import a single Python module, possibly from a parent."""
331 fp, pathname, description = imp.find_module(partname,
332 parent
and parent.__path__)
334 m = imp.load_module(fqname, fp, pathname, description)
341 modeller = _import_modeller_scripts_optimizers()
344 class _TempDir(object):
345 """Make a temporary directory that is deleted when the object is."""
348 self.tmpdir = tempfile.mkdtemp()
351 shutil.rmtree(self.tmpdir, ignore_errors=
True)
355 """A Modeller restraint which evaluates all defined IMP restraints.
356 This can be used to incorporate IMP Restraints into an existing
357 comparative modeling pipeline, or to use Modeller optimizers or
359 @param particles A list of the IMP atoms (as Particle objects),
360 same order as the Modeller atoms.
361 @note since Modeller, unlike IMP, is sensitive to the ordering
362 of atoms, it usually makes sense to create the model in
363 Modeller and then use ModelLoader to load it into IMP,
364 since that will preserve the Modeller atom ordering in IMP.
367 _physical_type = modeller.physical.absposition
369 def __init__(self, particles):
370 modeller.terms.energy_term.__init__(self)
371 self._particles = particles
373 def eval(self, mdl, deriv, indats):
374 atoms = self.indices_to_atoms(mdl, indats)
375 _copy_modeller_coords_to_imp(atoms, self._particles)
376 if len(self._particles) == 0:
379 score = self._particles[0].get_model().evaluate(deriv)
381 dvx = [0.] * len(indats)
382 dvy = [0.] * len(indats)
383 dvz = [0.] * len(indats)
384 _get_imp_derivs(self._particles, dvx, dvy, dvz)
385 return (score, dvx, dvy, dvz)
391 """An IMP restraint using all defined Modeller restraints.
392 This is useful if you want to use Modeller restraints with an IMP
393 optimizer, or in combination with IMP restraints.
395 @param model The IMP Model object.
396 @param modeller_model The Modeller model object.
397 @param particles A list of the IMP atoms (as Particle objects),
398 in the same order as the Modeller atoms.
399 @note since Modeller, unlike IMP, is sensitive to the ordering
400 of atoms, it usually makes sense to create the model in
401 Modeller and then use ModelLoader to load it into IMP,
402 since that will preserve the Modeller atom ordering in IMP.
403 @note Currently only the coordinates of the atoms are translated
404 between Modeller and IMP; thus, a Modeller restraint which
405 uses any other attribute (e.g. charge) will not react if
406 this attribute is changed by IMP.
408 def __init__(self, model, modeller_model, particles):
409 IMP.Restraint.__init__(self, model)
410 self._modeller_model = modeller_model
411 self._particles = particles
413 def unprotected_evaluate(self, accum):
414 atoms = self._modeller_model.atoms
415 sel = modeller.selection(self._modeller_model)
416 _copy_imp_coords_to_modeller(self._particles, atoms)
417 energies = sel.energy()
419 _add_modeller_derivs_to_imp(atoms, self._particles, accum)
423 def get_version_info(self):
424 return IMP.VersionInfo(
"IMP developers",
"0.1")
425 def do_show(self, fh):
426 fh.write(
"ModellerRestraints")
428 return [x
for x
in self._particles]
433 def _copy_imp_coords_to_modeller(particles, atoms):
434 """Copy atom coordinates from IMP to Modeller"""
438 for (num, at)
in enumerate(atoms):
439 at.x = particles[num].get_value(xkey)
440 at.y = particles[num].get_value(ykey)
441 at.z = particles[num].get_value(zkey)
444 def _copy_modeller_coords_to_imp(atoms, particles):
445 """Copy atom coordinates from Modeller to IMP"""
449 for (num, at)
in enumerate(atoms):
450 particles[num].set_value(xkey, at.x)
451 particles[num].set_value(ykey, at.y)
452 particles[num].set_value(zkey, at.z)
455 def _add_modeller_derivs_to_imp(atoms, particles, accum):
456 """Add atom derivatives from Modeller to IMP"""
457 for (num, at)
in enumerate(atoms):
459 xyz.add_to_derivative(0, at.dvx, accum)
460 xyz.add_to_derivative(1, at.dvy, accum)
461 xyz.add_to_derivative(2, at.dvz, accum)
464 def _get_imp_derivs(particles, dvx, dvy, dvz):
465 """Move atom derivatives from IMP to Modeller"""
469 for idx
in range(0, len(dvx)):
470 dvx[idx] = particles[idx].get_derivative(xkey)
471 dvy[idx] = particles[idx].get_derivative(ykey)
472 dvz[idx] = particles[idx].get_derivative(zkey)
476 def _HarmonicLowerBoundGenerator(parameters, modalities):
477 (mean, stdev) = parameters
481 def _HarmonicUpperBoundGenerator(parameters, modalities):
482 (mean, stdev) = parameters
486 def _HarmonicGenerator(parameters, modalities):
487 (mean, stdev) = parameters
491 def _CosineGenerator(parameters, modalities):
492 (phase, force_constant) = parameters
493 (periodicity,) = modalities
496 def _LinearGenerator(parameters, modalities):
497 (scale,) = parameters
500 def _SplineGenerator(parameters, modalities):
501 (open, low, high, delta, lowderiv, highderiv) = parameters[:6]
503 for v
in parameters[6:]:
511 _unary_func_generators = {
512 1: _HarmonicLowerBoundGenerator,
513 2: _HarmonicUpperBoundGenerator,
514 3: _HarmonicGenerator,
517 10: _SplineGenerator,
521 def _DistanceRestraintGenerator(form, modalities, atoms, parameters):
522 unary_func_gen = _unary_func_generators[form]
526 def _AngleRestraintGenerator(form, modalities, atoms, parameters):
527 unary_func_gen = _unary_func_generators[form]
529 atoms[0], atoms[1], atoms[2])
531 def _MultiBinormalGenerator(form, modalities, atoms, parameters):
532 nterms = modalities[0]
533 if len(parameters) != nterms * 6:
534 raise ValueError(
"Incorrect number of parameters (%d) for multiple "
535 "binormal restraint - expecting %d (%d terms * 6)" \
536 % (len(parameters), nterms * 6, nterms))
539 for i
in range(nterms):
541 t.set_weight(parameters[i])
542 t.set_means((parameters[nterms + i * 2],
543 parameters[nterms + i * 2 + 1]))
544 t.set_standard_deviations((parameters[nterms * 3 + i * 2],
545 parameters[nterms * 3 + i * 2 + 1]))
546 t.set_correlation(parameters[nterms * 5 + i])
550 def _DihedralRestraintGenerator(form, modalities, atoms, parameters):
552 return _MultiBinormalGenerator(form, modalities, atoms, parameters)
553 unary_func_gen = _unary_func_generators[form]
555 atoms[0], atoms[1], atoms[2], atoms[3])
557 def _get_protein_atom_particles(protein):
558 """Given a protein particle, get the flattened list of all child atoms"""
561 for ichain
in range(protein.get_number_of_children()):
562 chain = protein.get_child(ichain)
563 for ires
in range(chain.get_number_of_children()):
564 residue = chain.get_child(ires)
565 for iatom
in range(residue.get_number_of_children()):
566 atom = residue.get_child(iatom)
567 atom_particles.append(atom.get_particle())
568 return atom_particles
570 def _load_restraints_line(line, atom_particles):
571 """Parse a single Modeller restraints file line and return the
572 corresponding IMP restraint."""
575 if typ ==
'MODELLER5':
578 raise NotImplementedError(
"Only 'R' lines currently read from " + \
579 "Modeller restraints files")
580 form = int(spl.pop(0))
581 modalities = [int(spl.pop(0))]
582 features = [int(spl.pop(0))]
585 natoms = [int(spl.pop(0))]
586 nparam = int(spl.pop(0))
587 nfeat = int(spl.pop(0))
588 for i
in range(nfeat - 1):
589 modalities.append(int(spl.pop(0)))
590 features.append(int(spl.pop(0)))
591 natoms.append(int(spl.pop(0)))
592 atoms = [int(spl.pop(0))
for x
in range(natoms[0])]
593 for i
in range(len(atoms)):
594 atoms[i] = atom_particles[atoms[i] - 1]
595 parameters = [float(spl.pop(0))
for x
in range(nparam)]
596 restraint_generators = {
597 1 : _DistanceRestraintGenerator,
598 2 : _AngleRestraintGenerator,
599 3 : _DihedralRestraintGenerator,
601 restraint_gen = restraint_generators[features[0]]
602 return restraint_gen(form, modalities, atoms, parameters)
605 def _load_entire_restraints_file(filename, protein):
606 """Yield a set of IMP restraints from a Modeller restraints file."""
607 atoms = _get_protein_atom_particles(protein)
608 fh = open(filename,
'r')
611 rsr = _load_restraints_line(line, atoms)
614 except Exception, err:
615 print "Cannot read restraints file line:\n" + line
620 """@deprecated Use ModelLoader instead.
622 Convert a Modeller restraints file into equivalent IMP::Restraints.
623 @param filename Name of the Modeller restraints file.
624 @param protein An IMP::atom::Hierarchy containing the protein atoms
625 (e.g. as returned by read_pdb). The Modeller restraints
626 file is assumed to act on the same PDB described by
628 @return A Python list of the newly-created IMP::Restraint objects.
630 return list(_load_entire_restraints_file(filename, protein))
633 def _copy_residue(r, model):
634 """Copy residue information from modeller to imp"""
639 p.set_name(str(
"residue "+r.num));
643 def _copy_atom(a, model):
644 """Copy atom information from modeller"""
651 ap.set_input_index(a.index)
654 def _copy_chain(c, model):
655 """Copy chain information from modeller"""
662 def _get_forcefield(submodel):
674 """Add radii to the hierarchy using the Modeller radius library, radii.lib.
675 Each radius is scaled by the given scale (Modeller usually scales radii
676 by a factor of 0.82). submodel specifies the topology submodel, which is
677 the column in radii.lib to use."""
681 for line
in open(filename):
682 if line.startswith(
'#'):
continue
685 radii[spl[0]] = float(spl[submodel])
695 """Read a Modeller model into IMP. After creating this object, the atoms
696 in the Modeller model can be loaded into IMP using the load_atoms()
697 method, then optionally any Modeller static restraints can be read in
698 with load_static_restraints() or load_static_restraints_file().
699 @param modeller_model The Modeller model object to read.
702 def __init__(self, modeller_model):
703 self._modeller_model = modeller_model
705 def load_atoms(self, model):
706 """Construct an IMP::atom::Hierarchy that contains the same atoms as
708 @param model The IMP::Model object in which the hierarchy will be
709 created. The highest level hierarchy node is a PROTEIN.
710 @return the newly-created root IMP::atom::Hierarchy.
715 for chain
in self._modeller_model.chains:
720 for residue
in chain.residues:
721 rp = _copy_residue(residue, model)
724 for atom
in residue.atoms:
725 ap = _copy_atom(atom, model)
728 self._atoms[atom.index] = ap
730 self._modeller_hierarchy = hpp
733 def _get_nonbonded_list(self, atoms, pair_filter, edat, distance):
738 if pair_filter
is None:
740 if edat.excl_local[0]:
741 pair_filter.set_bonds(list(self.load_bonds()))
742 if edat.excl_local[1]:
743 pair_filter.set_angles(list(self.load_angles()))
744 if edat.excl_local[2]:
745 pair_filter.set_dihedrals(list(self.load_dihedrals()))
746 nbl.add_pair_filter(pair_filter)
749 def load_bonds(self):
750 """Load the Modeller bond topology into the IMP model. Each bond is
751 represented in IMP as an IMP::atom::Bond, with no defined length
752 or stiffness. These bonds are primarily useful as input to
753 IMP::atom::StereochemistryPairFilter, to exclude bond interactions
754 from the nonbonded list. Typically the contribution to the scoring
755 function from the bonds is included in the Modeller static restraints
756 (use load_static_restraints() or load_static_restraints_file() to
757 load these). If you want to regenerate the stereochemistry in IMP,
758 do not use these functions (as then stereochemistry scoring terms
759 and exclusions would be double-counted) and instead use the
760 IMP::atom::CHARMMTopology class.
762 You must call load_atoms() prior to using this function.
763 @see load_angles(), load_dihedrals(), load_impropers()
764 @return A generator listing all of the bonds.
766 if not hasattr(self,
'_modeller_hierarchy'):
767 raise ValueError(
"Call load_atoms() first.")
768 for (maa, mab)
in self._modeller_model.bonds:
769 pa = self._atoms[maa.index]
770 pb = self._atoms[mab.index]
780 IMP.atom.Bond.SINGLE).get_particle()
782 def load_angles(self):
783 """Load the Modeller angle topology into the IMP model.
784 See load_bonds() for more details."""
785 return self._internal_load_angles(self._modeller_model.angles,
788 def load_dihedrals(self):
789 """Load the Modeller dihedral topology into the IMP model.
790 See load_bonds() for more details."""
791 return self._internal_load_angles(self._modeller_model.dihedrals,
794 def load_impropers(self):
795 """Load the Modeller improper topology into the IMP model.
796 See load_bonds() for more details."""
797 return self._internal_load_angles(self._modeller_model.impropers,
800 def _internal_load_angles(self, angles, angle_class):
801 if not hasattr(self,
'_modeller_hierarchy'):
802 raise ValueError(
"Call load_atoms() first.")
803 for modeller_atoms
in angles:
804 imp_particles = [self._atoms[x.index]
for x
in modeller_atoms]
806 a = angle_class.setup_particle(p,
808 yield a.get_particle()
810 def load_static_restraints_file(self, filename):
811 """Convert a Modeller static restraints file into equivalent
812 IMP::Restraints. load_atoms() must have been called first to read
813 in the atoms that the restraints will act upon.
814 @param filename Name of the Modeller restraints file. The restraints
815 in this file are assumed to act upon the model read in by
816 load_atoms(); no checking is done to enforce this.
817 @return A Python generator of the newly-created IMP::Restraint
820 if not hasattr(self,
'_modeller_hierarchy'):
821 raise ValueError(
"Call load_atoms() first.")
822 return _load_entire_restraints_file(filename, self._modeller_hierarchy)
825 def load_static_restraints(self):
826 """Convert the current set of Modeller static restraints into equivalent
827 IMP::Restraints. load_atoms() must have been called first to read
828 in the atoms that the restraints will act upon.
829 @return A Python generator of the newly-created IMP::Restraint
832 class _RestraintGenerator(object):
833 """Simple generator wrapper"""
834 def __init__(self, gen):
836 def __iter__(self, *args, **keys):
838 def close(self, *args, **keys):
839 return self._gen.close(*args, **keys)
840 def next(self, *args, **keys):
841 return self._gen.next(*args, **keys)
842 def send(self, *args, **keys):
843 return self._gen.send(*args, **keys)
844 def throw(self, *args, **keys):
845 return self._gen.throw(*args, **keys)
848 rsrfile = os.path.join(t.tmpdir,
'restraints.rsr')
849 self._modeller_model.restraints.write(file=rsrfile)
851 gen = self.load_static_restraints_file(rsrfile)
852 wrap = _RestraintGenerator(gen)
857 def load_dynamic_restraints(self, pair_filter=None):
858 """Convert the current set of Modeller dynamic restraints
859 (e.g. soft-sphere, electrostatics) into equivalent IMP::Restraints.
860 load_atoms() must have been called first to read
861 in the atoms that the restraints will act upon.
863 If pair_filter is given, it is an IMP::PairFilter object to exclude
864 pairs from the nonbonded lists used by the dynamic restraints.
865 Otherwise, an IMP::atom::StereochemistryPairFilter object is created
866 to exclude Modeller bonds, angles and dihedrals, as specified by
867 edat.excl_local. (Note that this calls load_bonds(), load_angles()
868 and load_dihedrals(), so will create duplicate lists of bonds if
869 those methods are called manually as well.)
871 @note Currently only soft-sphere, electrostatic and Lennard-Jones
872 restraints are loaded.
873 @return A Python generator of the newly-created IMP::Restraint
876 if not hasattr(self,
'_modeller_hierarchy'):
877 raise ValueError(
"Call load_atoms() first.")
878 edat = self._modeller_model.env.edat
879 libs = self._modeller_model.env.libs
883 if edat.dynamic_sphere:
886 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, 0.)
889 libs.topology.submodel, edat.radii_factor)
896 if edat.dynamic_lennard
or edat.dynamic_coulomb:
898 d = max(edat.contact_shell - 3.0, 0.0)
899 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, d)
900 ff = _get_forcefield(libs.topology.submodel)
901 ff.add_radii(self._modeller_hierarchy)
903 if edat.dynamic_lennard:
904 ff.add_well_depths(self._modeller_hierarchy)
906 edat.lennard_jones_switch[1])
910 if edat.dynamic_coulomb:
912 edat.coulomb_switch[1])
914 ps.set_relative_dielectric(edat.relative_dielectric)
918 def read_pdb(name, model, special_patches=None):
919 """@deprecated Use IMP::atom::read_pdb() instead to read a PDB file,
920 or ModelLoader to read a Modeller model.
922 Construct an IMP::atom::Hierarchy from a PDB file.
923 @param name The name of the PDB file to read.
924 @param model The IMP::Model object in which the hierarchy will be
925 created. The highest level hierarchy node is a PROTEIN.
926 @param special_patches If given, a function that applies patches
927 (e.g. nucleic acid termini) to the Modeller model.
928 @return the newly-created root IMP::atom::Hierarchy.
930 e = modeller.environ()
931 e.libs.topology.read(
'${LIB}/top_heav.lib')
932 e.libs.parameters.read(
'${LIB}/par.lib')
934 modeller_model = modeller.scripts.complete_pdb(e, name,
935 special_patches=special_patches)
937 hpp = loader.load_atoms(model)
938 hpp.get_particle().set_name(name)
943 """Proxy of C++ IMP::modeller::MultipleBinormalRestraint class"""
944 __swig_setmethods__ = {}
945 for _s
in [
IMP.kernel.Restraint]: __swig_setmethods__.update(getattr(_s,
'__swig_setmethods__',{}))
946 __setattr__ =
lambda self, name, value: _swig_setattr(self, MultipleBinormalRestraint, name, value)
947 __swig_getmethods__ = {}
948 for _s
in [
IMP.kernel.Restraint]: __swig_getmethods__.update(getattr(_s,
'__swig_getmethods__',{}))
949 __getattr__ =
lambda self, name: _swig_getattr(self, MultipleBinormalRestraint, name)
950 def __init__(self, *args):
951 """__init__(IMP::modeller::MultipleBinormalRestraint self, IMP::kernel::ParticleQuad const & q1, IMP::kernel::ParticleQuad const & q2) -> MultipleBinormalRestraint"""
952 this = _IMP_modeller.new_MultipleBinormalRestraint(*args)
953 try: self.this.append(this)
954 except: self.this = this
955 def add_term(self, *args):
956 """add_term(MultipleBinormalRestraint self, BinormalTerm term)"""
957 return _IMP_modeller.MultipleBinormalRestraint_add_term(self, *args)
960 """get_input_particles(MultipleBinormalRestraint self) -> IMP::kernel::ParticlesTemp"""
961 return _IMP_modeller.MultipleBinormalRestraint_get_input_particles(self)
964 """get_input_containers(MultipleBinormalRestraint self) -> IMP::kernel::ContainersTemp"""
965 return _IMP_modeller.MultipleBinormalRestraint_get_input_containers(self)
967 def do_get_inputs(self):
968 """do_get_inputs(MultipleBinormalRestraint self) -> IMP::kernel::ModelObjectsTemp"""
969 return _IMP_modeller.MultipleBinormalRestraint_do_get_inputs(self)
971 def get_version_info(self):
972 """get_version_info(MultipleBinormalRestraint self) -> VersionInfo"""
973 return _IMP_modeller.MultipleBinormalRestraint_get_version_info(self)
975 def do_show(self, *args):
976 """do_show(MultipleBinormalRestraint self, _ostream out)"""
977 return _IMP_modeller.MultipleBinormalRestraint_do_show(self, *args)
979 __swig_destroy__ = _IMP_modeller.delete_MultipleBinormalRestraint
980 __del__ =
lambda self :
None;
982 """__str__(MultipleBinormalRestraint self) -> std::string"""
983 return _IMP_modeller.MultipleBinormalRestraint___str__(self)
986 """__repr__(MultipleBinormalRestraint self) -> std::string"""
987 return _IMP_modeller.MultipleBinormalRestraint___repr__(self)
990 return _object_cast_to_MultipleBinormalRestraint(o)
991 get_from = staticmethod(get_from)
993 MultipleBinormalRestraint_swigregister = _IMP_modeller.MultipleBinormalRestraint_swigregister
994 MultipleBinormalRestraint_swigregister(MultipleBinormalRestraint)
997 """Proxy of C++ IMP::modeller::BinormalTerm class"""
998 __swig_setmethods__ = {}
999 __setattr__ =
lambda self, name, value: _swig_setattr(self, BinormalTerm, name, value)
1000 __swig_getmethods__ = {}
1001 __getattr__ =
lambda self, name: _swig_getattr(self, BinormalTerm, name)
1003 """__init__(IMP::modeller::BinormalTerm self) -> BinormalTerm"""
1004 this = _IMP_modeller.new_BinormalTerm()
1005 try: self.this.append(this)
1006 except: self.this = this
1007 def set_correlation(self, *args):
1008 """set_correlation(BinormalTerm self, double correlation)"""
1009 return _IMP_modeller.BinormalTerm_set_correlation(self, *args)
1011 def set_weight(self, *args):
1012 """set_weight(BinormalTerm self, double weight)"""
1013 return _IMP_modeller.BinormalTerm_set_weight(self, *args)
1015 def set_means(self, *args):
1016 """set_means(BinormalTerm self, IMP::FloatPair means)"""
1017 return _IMP_modeller.BinormalTerm_set_means(self, *args)
1019 def set_standard_deviations(self, *args):
1020 """set_standard_deviations(BinormalTerm self, IMP::FloatPair stdevs)"""
1021 return _IMP_modeller.BinormalTerm_set_standard_deviations(self, *args)
1023 def show(self, *args):
1025 show(BinormalTerm self, _ostream out=std::cout)
1026 show(BinormalTerm self)
1028 return _IMP_modeller.BinormalTerm_show(self, *args)
1031 """__str__(BinormalTerm self) -> std::string"""
1032 return _IMP_modeller.BinormalTerm___str__(self)
1035 """__repr__(BinormalTerm self) -> std::string"""
1036 return _IMP_modeller.BinormalTerm___repr__(self)
1038 __swig_destroy__ = _IMP_modeller.delete_BinormalTerm
1039 __del__ =
lambda self :
None;
1040 BinormalTerm_swigregister = _IMP_modeller.BinormalTerm_swigregister
1041 BinormalTerm_swigregister(BinormalTerm)
1044 def get_module_version():
1045 """get_module_version() -> std::string const"""
1046 return _IMP_modeller.get_module_version()
1049 """get_example_path(std::string fname) -> std::string"""
1050 return _IMP_modeller.get_example_path(*args)
1053 """get_data_path(std::string fname) -> std::string"""
1054 return _IMP_modeller.get_data_path(*args)
1055 import _version_check
1056 _version_check.check_version(get_module_version())