10 from __future__
import print_function, division, absolute_import
15 from sys
import version_info
as _swig_python_version_info
16 if _swig_python_version_info >= (2, 7, 0):
17 def swig_import_helper():
19 pkg = __name__.rpartition(
'.')[0]
20 mname =
'.'.join((pkg,
'_IMP_modeller')).lstrip(
'.')
22 return importlib.import_module(mname)
24 return importlib.import_module(
'_IMP_modeller')
25 _IMP_modeller = swig_import_helper()
26 del swig_import_helper
27 elif _swig_python_version_info >= (2, 6, 0):
28 def swig_import_helper():
29 from os.path
import dirname
33 fp, pathname, description = imp.find_module(
'_IMP_modeller', [dirname(__file__)])
39 _mod = imp.load_module(
'_IMP_modeller', fp, pathname, description)
43 _IMP_modeller = swig_import_helper()
44 del swig_import_helper
47 del _swig_python_version_info
49 _swig_property = property
54 import builtins
as __builtin__
58 def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
59 if (name ==
"thisown"):
60 return self.this.own(value)
62 if type(value).__name__ ==
'SwigPyObject':
63 self.__dict__[name] = value
65 method = class_type.__swig_setmethods__.get(name,
None)
67 return method(self, value)
69 object.__setattr__(self, name, value)
71 raise AttributeError(
"You cannot add attributes to %s" % self)
74 def _swig_setattr(self, class_type, name, value):
75 return _swig_setattr_nondynamic(self, class_type, name, value, 0)
78 def _swig_getattr(self, class_type, name):
79 if (name ==
"thisown"):
80 return self.this.own()
81 method = class_type.__swig_getmethods__.get(name,
None)
84 raise AttributeError(
"'%s' object has no attribute '%s'" % (class_type.__name__, name))
89 strthis =
"proxy of " + self.this.__repr__()
90 except __builtin__.Exception:
92 return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
95 def _swig_setattr_nondynamic_method(set):
96 def set_attr(self, name, value):
97 if (name ==
"thisown"):
98 return self.this.own(value)
99 if hasattr(self, name)
or (name ==
"this"):
100 set(self, name, value)
102 raise AttributeError(
"You cannot add attributes to %s" % self)
108 weakref_proxy = weakref.proxy
109 except __builtin__.Exception:
110 weakref_proxy =
lambda x: x
113 class IMP_MODELLER_SwigPyIterator(object):
114 """Proxy of C++ swig::IMP_MODELLER_SwigPyIterator class."""
116 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
118 def __init__(self, *args, **kwargs):
119 raise AttributeError(
"No constructor defined - class is abstract")
120 __repr__ = _swig_repr
121 __swig_destroy__ = _IMP_modeller.delete_IMP_MODELLER_SwigPyIterator
122 __del__ =
lambda self:
None
125 """value(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
126 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_value(self)
131 incr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
132 incr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
134 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_incr(self, n)
139 decr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
140 decr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
142 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_decr(self, n)
145 def distance(self, x):
146 """distance(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t"""
147 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_distance(self, x)
151 """equal(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
152 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_equal(self, x)
156 """copy(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator"""
157 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_copy(self)
161 """next(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
162 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_next(self)
166 """__next__(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
167 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___next__(self)
171 """previous(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
172 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_previous(self)
175 def advance(self, n):
176 """advance(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
177 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_advance(self, n)
181 """__eq__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
182 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___eq__(self, x)
186 """__ne__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
187 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___ne__(self, x)
190 def __iadd__(self, n):
191 """__iadd__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
192 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___iadd__(self, n)
195 def __isub__(self, n):
196 """__isub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
197 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___isub__(self, n)
200 def __add__(self, n):
201 """__add__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
202 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___add__(self, n)
205 def __sub__(self, *args):
207 __sub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator
208 __sub__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t
210 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___sub__(self, *args)
214 IMP_MODELLER_SwigPyIterator_swigregister = _IMP_modeller.IMP_MODELLER_SwigPyIterator_swigregister
215 IMP_MODELLER_SwigPyIterator_swigregister(IMP_MODELLER_SwigPyIterator)
223 IMP_DEBUG = _IMP_modeller.IMP_DEBUG
224 IMP_RELEASE = _IMP_modeller.IMP_RELEASE
225 IMP_SILENT = _IMP_modeller.IMP_SILENT
226 IMP_PROGRESS = _IMP_modeller.IMP_PROGRESS
227 IMP_TERSE = _IMP_modeller.IMP_TERSE
228 IMP_VERBOSE = _IMP_modeller.IMP_VERBOSE
229 IMP_MEMORY = _IMP_modeller.IMP_MEMORY
230 IMP_NONE = _IMP_modeller.IMP_NONE
231 IMP_USAGE = _IMP_modeller.IMP_USAGE
232 IMP_INTERNAL = _IMP_modeller.IMP_INTERNAL
233 IMP_KERNEL_HAS_LOG4CXX = _IMP_modeller.IMP_KERNEL_HAS_LOG4CXX
234 IMP_COMPILER_HAS_AUTO = _IMP_modeller.IMP_COMPILER_HAS_AUTO
235 IMP_COMPILER_HAS_DEBUG_VECTOR = _IMP_modeller.IMP_COMPILER_HAS_DEBUG_VECTOR
236 IMP_COMPILER_HAS_UNIQUE_PTR = _IMP_modeller.IMP_COMPILER_HAS_UNIQUE_PTR
237 IMP_KERNEL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_KERNEL_HAS_BOOST_RANDOM
238 IMP_KERNEL_HAS_NUMPY = _IMP_modeller.IMP_KERNEL_HAS_NUMPY
239 IMP_KERNEL_HAS_GPERFTOOLS = _IMP_modeller.IMP_KERNEL_HAS_GPERFTOOLS
240 IMP_KERNEL_HAS_TCMALLOC_HEAPCHECKER = _IMP_modeller.IMP_KERNEL_HAS_TCMALLOC_HEAPCHECKER
241 IMP_KERNEL_HAS_TCMALLOC_HEAPPROFILER = _IMP_modeller.IMP_KERNEL_HAS_TCMALLOC_HEAPPROFILER
242 IMPKERNEL_SHOW_WARNINGS = _IMP_modeller.IMPKERNEL_SHOW_WARNINGS
245 class _DirectorObjects(object):
246 """@internal Simple class to keep references to director objects
247 to prevent premature deletion."""
250 def register(self, obj):
251 """Take a reference to a director object; will only work for
252 refcounted C++ classes"""
253 if hasattr(obj,
'get_ref_count'):
254 self._objects.append(obj)
256 """Only drop our reference and allow cleanup by Python if no other
257 Python references exist (we hold 3 references: one in self._objects,
258 one in x, and one in the argument list for getrefcount) *and* no
259 other C++ references exist (the Python object always holds one)"""
260 objs = [x
for x
in self._objects
if sys.getrefcount(x) > 3 \
261 or x.get_ref_count() > 1]
265 def get_object_count(self):
266 """Get number of director objects (useful for testing only)"""
267 return len(self._objects)
268 _director_objects = _DirectorObjects()
270 class _ostream(object):
271 """Proxy of C++ std::ostream class."""
273 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
275 def __init__(self, *args, **kwargs):
276 raise AttributeError(
"No constructor defined")
277 __repr__ = _swig_repr
279 def write(self, osa_buf):
280 """write(_ostream self, char const * osa_buf)"""
281 return _IMP_modeller._ostream_write(self, osa_buf)
283 _ostream_swigregister = _IMP_modeller._ostream_swigregister
284 _ostream_swigregister(_ostream)
286 IMP_COMPILER_HAS_OVERRIDE = _IMP_modeller.IMP_COMPILER_HAS_OVERRIDE
287 IMP_COMPILER_HAS_FINAL = _IMP_modeller.IMP_COMPILER_HAS_FINAL
288 IMP_HAS_NOEXCEPT = _IMP_modeller.IMP_HAS_NOEXCEPT
289 IMP_C_OPEN_BINARY = _IMP_modeller.IMP_C_OPEN_BINARY
291 IMP_CGAL_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_FILESYSTEM
292 IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS
293 IMP_CGAL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CGAL_HAS_BOOST_RANDOM
294 IMP_CGAL_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_SYSTEM
295 IMP_CGAL_HAS_NUMPY = _IMP_modeller.IMP_CGAL_HAS_NUMPY
296 IMPCGAL_SHOW_WARNINGS = _IMP_modeller.IMPCGAL_SHOW_WARNINGS
298 IMP_ALGEBRA_HAS_IMP_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_IMP_CGAL
299 IMP_ALGEBRA_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_FILESYSTEM
300 IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS
301 IMP_ALGEBRA_HAS_BOOST_RANDOM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_RANDOM
302 IMP_ALGEBRA_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_SYSTEM
303 IMP_ALGEBRA_HAS_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_CGAL
304 IMP_ALGEBRA_HAS_NUMPY = _IMP_modeller.IMP_ALGEBRA_HAS_NUMPY
305 IMP_ALGEBRA_HAS_ANN = _IMP_modeller.IMP_ALGEBRA_HAS_ANN
306 IMPALGEBRA_SHOW_WARNINGS = _IMP_modeller.IMPALGEBRA_SHOW_WARNINGS
308 IMP_DISPLAY_HAS_IMP_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_IMP_CGAL
309 IMP_DISPLAY_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_FILESYSTEM
310 IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS
311 IMP_DISPLAY_HAS_BOOST_RANDOM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_RANDOM
312 IMP_DISPLAY_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_SYSTEM
313 IMP_DISPLAY_HAS_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_CGAL
314 IMP_DISPLAY_HAS_NUMPY = _IMP_modeller.IMP_DISPLAY_HAS_NUMPY
315 IMPDISPLAY_SHOW_WARNINGS = _IMP_modeller.IMPDISPLAY_SHOW_WARNINGS
317 IMP_SCORE_FUNCTOR_HAS_IMP_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_IMP_CGAL
318 IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM
319 IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS
320 IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM
321 IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM
322 IMP_SCORE_FUNCTOR_HAS_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_CGAL
323 IMP_SCORE_FUNCTOR_HAS_HDF5 = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_HDF5
324 IMP_SCORE_FUNCTOR_HAS_NUMPY = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_NUMPY
325 IMPSCOREFUNCTOR_SHOW_WARNINGS = _IMP_modeller.IMPSCOREFUNCTOR_SHOW_WARNINGS
327 IMP_CORE_HAS_IMP_CGAL = _IMP_modeller.IMP_CORE_HAS_IMP_CGAL
328 IMP_CORE_HAS_IMP_KERNEL = _IMP_modeller.IMP_CORE_HAS_IMP_KERNEL
329 IMP_CORE_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_FILESYSTEM
330 IMP_CORE_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CORE_HAS_BOOST_PROGRAMOPTIONS
331 IMP_CORE_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CORE_HAS_BOOST_RANDOM
332 IMP_CORE_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_SYSTEM
333 IMP_CORE_HAS_CGAL = _IMP_modeller.IMP_CORE_HAS_CGAL
334 IMP_CORE_HAS_HDF5 = _IMP_modeller.IMP_CORE_HAS_HDF5
335 IMP_CORE_HAS_NUMPY = _IMP_modeller.IMP_CORE_HAS_NUMPY
336 IMPCORE_SHOW_WARNINGS = _IMP_modeller.IMPCORE_SHOW_WARNINGS
338 IMP_MODELLER_HAS_IMP_ALGEBRA = _IMP_modeller.IMP_MODELLER_HAS_IMP_ALGEBRA
339 IMP_MODELLER_HAS_IMP_CGAL = _IMP_modeller.IMP_MODELLER_HAS_IMP_CGAL
340 IMP_MODELLER_HAS_IMP_DISPLAY = _IMP_modeller.IMP_MODELLER_HAS_IMP_DISPLAY
341 IMP_MODELLER_HAS_IMP_KERNEL = _IMP_modeller.IMP_MODELLER_HAS_IMP_KERNEL
342 IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR = _IMP_modeller.IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR
343 IMP_MODELLER_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_FILESYSTEM
344 IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS
345 IMP_MODELLER_HAS_BOOST_RANDOM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_RANDOM
346 IMP_MODELLER_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_SYSTEM
347 IMP_MODELLER_HAS_CGAL = _IMP_modeller.IMP_MODELLER_HAS_CGAL
348 IMP_MODELLER_HAS_HDF5 = _IMP_modeller.IMP_MODELLER_HAS_HDF5
349 IMP_MODELLER_HAS_NUMPY = _IMP_modeller.IMP_MODELLER_HAS_NUMPY
350 IMP_MODELLER_HAS_PYTHON_IHM = _IMP_modeller.IMP_MODELLER_HAS_PYTHON_IHM
351 IMPMODELLER_SHOW_WARNINGS = _IMP_modeller.IMPMODELLER_SHOW_WARNINGS
362 import modeller.scripts
363 import modeller.optimizers
365 class _TempDir(object):
366 """Make a temporary directory that is deleted when the object is."""
369 self.tmpdir = tempfile.mkdtemp()
372 shutil.rmtree(self.tmpdir, ignore_errors=
True)
376 """A Modeller restraint which evaluates an IMP scoring function.
377 This can be used to incorporate IMP Restraints into an existing
378 comparative modeling pipeline, or to use Modeller optimizers or
382 _physical_type = modeller.physical.absposition
384 def __init__(self, particles, scoring_function=None):
386 @param particles A list of the IMP atoms (as Particle objects),
387 same order as the Modeller atoms.
388 @param scoring_function An IMP::ScoringFunction object that will
389 be incorporated into the Modeller score (molpdf).
390 @note since Modeller, unlike IMP, is sensitive to the ordering
391 of atoms, it usually makes sense to create the model in
392 Modeller and then use ModelLoader to load it into IMP,
393 since that will preserve the Modeller atom ordering in IMP.
395 modeller.terms.energy_term.__init__(self)
396 self._particles = particles
398 self._sf = scoring_function
400 self._sf = particles[0].get_model()
402 def eval(self, mdl, deriv, indats):
403 atoms = self.indices_to_atoms(mdl, indats)
404 _copy_modeller_coords_to_imp(atoms, self._particles)
405 if len(self._particles) == 0:
408 score = self._sf.evaluate(deriv)
410 dvx = [0.] * len(indats)
411 dvy = [0.] * len(indats)
412 dvz = [0.] * len(indats)
413 _get_imp_derivs(self._particles, dvx, dvy, dvz)
414 return (score, dvx, dvy, dvz)
420 """An IMP restraint using all defined Modeller restraints.
421 This is useful if you want to use Modeller restraints with an IMP
422 optimizer, or in combination with IMP restraints.
424 @note Currently only the coordinates of the atoms are translated
425 between Modeller and IMP; thus, a Modeller restraint which
426 uses any other attribute (e.g. charge) will not react if
427 this attribute is changed by IMP.
430 def __init__(self, model, modeller_model, particles):
432 @param model The IMP Model object.
433 @param modeller_model The Modeller model object.
434 @param particles A list of the IMP atoms (as Particle objects),
435 in the same order as the Modeller atoms.
436 @note since Modeller, unlike IMP, is sensitive to the ordering
437 of atoms, it usually makes sense to create the model in
438 Modeller and then use ModelLoader to load it into IMP,
439 since that will preserve the Modeller atom ordering in IMP.
442 if hasattr(x,
'get_particle'):
443 return x.get_particle()
446 IMP.Restraint.__init__(self, model,
"ModellerRestraints %1%")
447 self._modeller_model = modeller_model
448 self._particles = [get_particle(x)
for x
in particles]
450 def unprotected_evaluate(self, accum):
451 atoms = self._modeller_model.atoms
452 sel = modeller.selection(self._modeller_model)
453 _copy_imp_coords_to_modeller(self._particles, atoms)
454 energies = sel.energy()
456 _add_modeller_derivs_to_imp(atoms, self._particles, accum)
462 def do_show(self, fh):
463 fh.write(
"ModellerRestraints")
465 return self._particles
468 def _copy_imp_coords_to_modeller(particles, atoms):
469 """Copy atom coordinates from IMP to Modeller"""
473 for (num, at)
in enumerate(atoms):
474 at.x = particles[num].get_value(xkey)
475 at.y = particles[num].get_value(ykey)
476 at.z = particles[num].get_value(zkey)
479 def _copy_modeller_coords_to_imp(atoms, particles):
480 """Copy atom coordinates from Modeller to IMP"""
484 for (num, at)
in enumerate(atoms):
485 particles[num].set_value(xkey, at.x)
486 particles[num].set_value(ykey, at.y)
487 particles[num].set_value(zkey, at.z)
490 def _add_modeller_derivs_to_imp(atoms, particles, accum):
491 """Add atom derivatives from Modeller to IMP"""
492 for (num, at)
in enumerate(atoms):
494 xyz.add_to_derivative(0, at.dvx, accum)
495 xyz.add_to_derivative(1, at.dvy, accum)
496 xyz.add_to_derivative(2, at.dvz, accum)
499 def _get_imp_derivs(particles, dvx, dvy, dvz):
500 """Move atom derivatives from IMP to Modeller"""
504 for idx
in range(0, len(dvx)):
505 dvx[idx] = particles[idx].get_derivative(xkey)
506 dvy[idx] = particles[idx].get_derivative(ykey)
507 dvz[idx] = particles[idx].get_derivative(zkey)
511 def _HarmonicLowerBoundGenerator(parameters, modalities):
512 (mean, stdev) = parameters
516 def _HarmonicUpperBoundGenerator(parameters, modalities):
517 (mean, stdev) = parameters
521 def _HarmonicGenerator(parameters, modalities):
522 (mean, stdev) = parameters
526 def _CosineGenerator(parameters, modalities):
527 (phase, force_constant) = parameters
528 (periodicity,) = modalities
531 def _LinearGenerator(parameters, modalities):
532 (scale,) = parameters
535 def _SplineGenerator(parameters, modalities):
536 (open, low, high, delta, lowderiv, highderiv) = parameters[:6]
538 for v
in parameters[6:]:
546 _unary_func_generators = {
547 1: _HarmonicLowerBoundGenerator,
548 2: _HarmonicUpperBoundGenerator,
549 3: _HarmonicGenerator,
552 10: _SplineGenerator,
556 def _DistanceRestraintGenerator(form, modalities, atoms, parameters):
557 unary_func_gen = _unary_func_generators[form]
559 unary_func_gen(parameters, modalities),
562 def _AngleRestraintGenerator(form, modalities, atoms, parameters):
563 unary_func_gen = _unary_func_generators[form]
565 unary_func_gen(parameters, modalities),
566 atoms[0], atoms[1], atoms[2])
568 def _MultiBinormalGenerator(form, modalities, atoms, parameters):
569 nterms = modalities[0]
570 if len(parameters) != nterms * 6:
571 raise ValueError(
"Incorrect number of parameters (%d) for multiple "
572 "binormal restraint - expecting %d (%d terms * 6)" \
573 % (len(parameters), nterms * 6, nterms))
575 atoms[:4], atoms[4:8])
576 for i
in range(nterms):
578 t.set_weight(parameters[i])
579 t.set_means((parameters[nterms + i * 2],
580 parameters[nterms + i * 2 + 1]))
581 t.set_standard_deviations((parameters[nterms * 3 + i * 2],
582 parameters[nterms * 3 + i * 2 + 1]))
583 t.set_correlation(parameters[nterms * 5 + i])
587 def _DihedralRestraintGenerator(form, modalities, atoms, parameters):
589 return _MultiBinormalGenerator(form, modalities, atoms, parameters)
590 unary_func_gen = _unary_func_generators[form]
592 unary_func_gen(parameters, modalities),
593 atoms[0], atoms[1], atoms[2], atoms[3])
595 def _get_protein_atom_particles(protein):
596 """Given a protein particle, get the flattened list of all child atoms"""
598 for ichain
in range(protein.get_number_of_children()):
599 chain = protein.get_child(ichain)
600 for ires
in range(chain.get_number_of_children()):
601 residue = chain.get_child(ires)
602 for iatom
in range(residue.get_number_of_children()):
603 atom = residue.get_child(iatom)
604 atom_particles.append(atom.get_particle())
605 return atom_particles
607 def _load_restraints_line(line, atom_particles):
608 """Parse a single Modeller restraints file line and return the
609 corresponding IMP restraint."""
612 if typ ==
'MODELLER5':
615 raise NotImplementedError(
"Only 'R' lines currently read from " + \
616 "Modeller restraints files")
617 form = int(spl.pop(0))
618 modalities = [int(spl.pop(0))]
619 features = [int(spl.pop(0))]
622 natoms = [int(spl.pop(0))]
623 nparam = int(spl.pop(0))
624 nfeat = int(spl.pop(0))
625 for i
in range(nfeat - 1):
626 modalities.append(int(spl.pop(0)))
627 features.append(int(spl.pop(0)))
628 natoms.append(int(spl.pop(0)))
629 atoms = [int(spl.pop(0))
for x
in range(natoms[0])]
630 for i
in range(len(atoms)):
631 atoms[i] = atom_particles[atoms[i] - 1]
632 parameters = [float(spl.pop(0))
for x
in range(nparam)]
633 restraint_generators = {
634 1 : _DistanceRestraintGenerator,
635 2 : _AngleRestraintGenerator,
636 3 : _DihedralRestraintGenerator,
638 restraint_gen = restraint_generators[features[0]]
639 return restraint_gen(form, modalities, atoms, parameters)
642 def _load_entire_restraints_file(filename, protein):
643 """Yield a set of IMP restraints from a Modeller restraints file."""
644 atoms = _get_protein_atom_particles(protein)
645 fh = open(filename,
'r')
648 rsr = _load_restraints_line(line, atoms)
651 except Exception
as err:
652 print(
"Cannot read restraints file line:\n" + line)
656 def _copy_residue(r, model):
657 """Copy residue information from modeller to imp"""
662 p.set_name(str(
"residue "+r.num));
666 def _copy_atom(a, model):
667 """Copy atom information from modeller"""
673 if hasattr(a,
'charge'):
675 if hasattr(a,
'type'):
677 ap.set_input_index(a.index)
680 def _copy_chain(c, model):
681 """Copy chain information from modeller"""
688 def _get_forcefield(submodel):
700 """Add radii to the hierarchy using the Modeller radius library, radii.lib.
701 Each radius is scaled by the given scale (Modeller usually scales radii
702 by a factor of 0.82). submodel specifies the topology submodel, which is
703 the column in radii.lib to use."""
707 for line
in open(filename):
708 if line.startswith(
'#'):
continue
711 radii[spl[0]] = float(spl[submodel])
712 atoms = IMP.atom.get_by_type(hierarchy, IMP.atom.ATOM_TYPE)
721 """Read a Modeller model into IMP. After creating this object, the atoms
722 in the Modeller model can be loaded into IMP using the load_atoms()
723 method, then optionally any Modeller static restraints can be read in
724 with load_static_restraints() or load_static_restraints_file().
726 This class can also be used to read Modeller alignment structures;
727 however, only load_atoms() will be useful in such a case (since
728 alignment structures don't have restraints or other information).
734 @param modeller_model The Modeller model or alignment structure
737 self._modeller_model = modeller_model
740 """Construct an IMP::atom::Hierarchy that contains the same atoms as
741 the Modeller model or alignment structure.
743 IMP atoms created from a Modeller model will be given charges and
744 CHARMM types, extracted from the model. Alignment structures don't
745 contain this information, so the IMP atoms won't either.
747 @param model The IMP::Model object in which the hierarchy will be
748 created. The highest level hierarchy node is a PROTEIN.
749 @return the newly-created root IMP::atom::Hierarchy.
754 for chain
in self._modeller_model.chains:
759 for residue
in chain.residues:
760 rp = _copy_residue(residue, model)
763 for atom
in residue.atoms:
764 ap = _copy_atom(atom, model)
767 self._atoms[atom.index] = ap
769 self._modeller_hierarchy = hpp
772 def _get_nonbonded_list(self, atoms, pair_filter, edat, distance):
777 if pair_filter
is None:
779 if edat.excl_local[0]:
780 pair_filter.set_bonds(list(self.
load_bonds()))
781 if edat.excl_local[1]:
783 if edat.excl_local[2]:
785 nbl.add_pair_filter(pair_filter)
789 """Load the Modeller bond topology into the IMP model. Each bond is
790 represented in IMP as an IMP::atom::Bond, with no defined length
791 or stiffness. These bonds are primarily useful as input to
792 IMP::atom::StereochemistryPairFilter, to exclude bond interactions
793 from the nonbonded list. Typically the contribution to the scoring
794 function from the bonds is included in the Modeller static restraints
795 (use load_static_restraints() or load_static_restraints_file() to
796 load these). If you want to regenerate the stereochemistry in IMP,
797 do not use these functions (as then stereochemistry scoring terms
798 and exclusions would be double-counted) and instead use the
799 IMP::atom::CHARMMTopology class.
801 You must call load_atoms() prior to using this function.
802 @see load_angles(), load_dihedrals(), load_impropers()
803 @return A generator listing all of the bonds.
805 if not hasattr(self,
'_modeller_hierarchy'):
806 raise ValueError(
"Call load_atoms() first.")
807 for (maa, mab)
in self._modeller_model.bonds:
808 pa = self._atoms[maa.index]
809 pb = self._atoms[mab.index]
819 IMP.atom.Bond.SINGLE).get_particle()
822 """Load the Modeller angle topology into the IMP model.
823 See load_bonds() for more details."""
824 return self._internal_load_angles(self._modeller_model.angles,
828 """Load the Modeller dihedral topology into the IMP model.
829 See load_bonds() for more details."""
830 return self._internal_load_angles(self._modeller_model.dihedrals,
834 """Load the Modeller improper topology into the IMP model.
835 See load_bonds() for more details."""
836 return self._internal_load_angles(self._modeller_model.impropers,
839 def _internal_load_angles(self, angles, angle_class):
840 if not hasattr(self,
'_modeller_hierarchy'):
841 raise ValueError(
"Call load_atoms() first.")
842 for modeller_atoms
in angles:
843 imp_particles = [self._atoms[x.index]
for x
in modeller_atoms]
845 a = angle_class.setup_particle(p,
847 yield a.get_particle()
850 """Convert a Modeller static restraints file into equivalent
851 IMP::Restraints. load_atoms() must have been called first to read
852 in the atoms that the restraints will act upon.
853 @param filename Name of the Modeller restraints file. The restraints
854 in this file are assumed to act upon the model read in by
855 load_atoms(); no checking is done to enforce this.
856 @return A Python generator of the newly-created IMP::Restraint
859 if not hasattr(self,
'_modeller_hierarchy'):
860 raise ValueError(
"Call load_atoms() first.")
861 return _load_entire_restraints_file(filename, self._modeller_hierarchy)
865 """Convert the current set of Modeller static restraints into equivalent
866 IMP::Restraints. load_atoms() must have been called first to read
867 in the atoms that the restraints will act upon.
868 @return A Python generator of the newly-created IMP::Restraint
871 class _RestraintGenerator(object):
872 """Simple generator wrapper"""
875 def __iter__(self, *args, **keys):
877 def close(self, *args, **keys):
878 return self._gen.close(*args, **keys)
880 return next(self._gen)
882 def send(self, *args, **keys):
883 return self._gen.send(*args, **keys)
884 def throw(self, *args, **keys):
885 return self._gen.throw(*args, **keys)
888 rsrfile = os.path.join(t.tmpdir,
'restraints.rsr')
889 self._modeller_model.restraints.write(file=rsrfile)
892 wrap = _RestraintGenerator(gen)
898 """Convert Modeller dynamic restraints into IMP::Restraint objects.
900 For each currently active Modeller dynamic restraint
901 (e.g. soft-sphere, electrostatics) an equivalent IMP::Restraint
903 load_atoms() must have been called first to read
904 in the atoms that the restraints will act upon.
906 If pair_filter is given, it is an IMP::PairFilter object to exclude
907 pairs from the nonbonded lists used by the dynamic restraints.
908 Otherwise, an IMP::atom::StereochemistryPairFilter object is created
909 to exclude Modeller bonds, angles and dihedrals, as specified by
910 edat.excl_local. (Note that this calls load_bonds(), load_angles()
911 and load_dihedrals(), so will create duplicate lists of bonds if
912 those methods are called manually as well.)
914 @note Currently only soft-sphere, electrostatic and Lennard-Jones
915 restraints are loaded.
916 @return A Python generator of the newly-created IMP::Restraint
919 if not hasattr(self,
'_modeller_hierarchy'):
920 raise ValueError(
"Call load_atoms() first.")
921 edat = self._modeller_model.env.edat
922 libs = self._modeller_model.env.libs
924 m = atoms[0].get_model()
927 if edat.dynamic_sphere:
930 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, 0.)
933 libs.topology.submodel, edat.radii_factor)
940 if edat.dynamic_lennard
or edat.dynamic_coulomb:
942 d = max(edat.contact_shell - 3.0, 0.0)
943 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, d)
944 ff = _get_forcefield(libs.topology.submodel)
945 ff.add_radii(self._modeller_hierarchy)
947 if edat.dynamic_lennard:
948 ff.add_well_depths(self._modeller_hierarchy)
950 edat.lennard_jones_switch[1])
954 if edat.dynamic_coulomb:
956 edat.coulomb_switch[1])
958 ps.set_relative_dielectric(edat.relative_dielectric)
964 """get_module_version() -> std::string const"""
965 return _IMP_modeller.get_module_version()
968 """get_example_path(std::string fname) -> std::string"""
969 return _IMP_modeller.get_example_path(fname)
972 """get_data_path(std::string fname) -> std::string"""
973 return _IMP_modeller.get_data_path(fname)
975 from .
import _version_check
static CHARMMAtom setup_particle(Model *m, ParticleIndex pi, String charmm_type)
static Charged setup_particle(Model *m, ParticleIndex pi, Float charge)
Lower bound harmonic function (non-zero when feature < mean)
def load_static_restraints
Convert the current set of Modeller static restraints into equivalent IMP::Restraints.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
def load_bonds
Load the Modeller bond topology into the IMP model.
A Modeller restraint which evaluates an IMP scoring function.
Coulomb (electrostatic) score between a pair of particles.
static Atom setup_particle(Model *m, ParticleIndex pi, Atom other)
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
static XYZR setup_particle(Model *m, ParticleIndex pi)
A decorator for a particle which has bonds.
def load_impropers
Load the Modeller improper topology into the IMP model.
Make CGAL functionality available to IMP.
std::string get_module_version()
Return the version of this module, as a string.
std::string get_data_path(std::string file_name)
Return the full path to one of this module's data files.
Dihedral restraint between four particles.
def load_static_restraints_file
Convert a Modeller static restraints file into equivalent IMP::Restraints.
A score on the distance between the surfaces of two spheres.
Return all close unordered pairs of particles taken from the SingletonContainer.
static Residue setup_particle(Model *m, ParticleIndex pi, ResidueType t, int index, int insertion_code)
A single binormal term in a MultipleBinormalRestraint.
def load_dynamic_restraints
Convert Modeller dynamic restraints into IMP::Restraint objects.
Distance restraint between two particles.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Composable functors to implement scores via compile-time composition.
An IMP restraint using all defined Modeller restraints.
CHARMM force field parameters.
Bond create_bond(Bonded a, Bonded b, Bond o)
Connect the two wrapped particles by a custom bond.
def load_dihedrals
Load the Modeller dihedral topology into the IMP model.
static Float get_k_from_standard_deviation(Float sd, Float t=297.15)
Return the k to use for a given Gaussian standard deviation.
Angle restraint between three particles.
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Lennard-Jones score between a pair of particles.
A particle that describes an angle between three particles.
The standard decorator for manipulating molecular structures.
Store a list of ParticleIndexes.
static Bonded setup_particle(Model *m, ParticleIndex pi)
def load_atoms
Construct an IMP::atom::Hierarchy that contains the same atoms as the Modeller model or alignment str...
Version and module information for Objects.
A decorator for a particle with x,y,z coordinates.
Modeller-style multiple binormal (phi/psi) restraint.
def add_soft_sphere_radii
Add radii to the hierarchy using the Modeller radius library, radii.lib.
A particle that describes a dihedral angle between four particles.
def load_angles
Load the Modeller angle topology into the IMP model.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
static bool get_is_setup(const IMP::ParticleAdaptor &p)
virtual VersionInfo get_version_info() const
Get information about the module and version of the object.
A filter that excludes bonds, angles and dihedrals.
Read a Modeller model into IMP.
Class to handle individual particles of a Model object.
std::string get_data_path(std::string file_name)
Return the full path to one of this module's data files.
Smooth interaction scores by switching the derivatives (force switch).
Output IMP model data in various file formats.
Functionality for loading, creating, manipulating and scoring atomic structures.
static Chain setup_particle(Model *m, ParticleIndex pi, std::string id)
Hierarchies get_leaves(const Selection &h)
Applies a PairScore to each Pair in a list.
virtual ModelObjectsTemp do_get_inputs() const =0
Closed cubic spline function.
A decorator for an atom that has a defined CHARMM type.
A restraint is a term in an IMP ScoringFunction.
Harmonic function (symmetric about the mean)