11 from sys
import version_info
12 if version_info >= (2,6,0):
13 def swig_import_helper():
14 from os.path
import dirname
18 fp, pathname, description = imp.find_module(
'_IMP_modeller', [dirname(__file__)])
24 _mod = imp.load_module(
'_IMP_modeller', fp, pathname, description)
28 _IMP_modeller = swig_import_helper()
29 del swig_import_helper
34 _swig_property = property
37 def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
38 if (name ==
"thisown"):
return self.this.own(value)
40 if type(value).__name__ ==
'SwigPyObject':
41 self.__dict__[name] = value
43 method = class_type.__swig_setmethods__.get(name,
None)
44 if method:
return method(self,value)
46 self.__dict__[name] = value
48 raise AttributeError(
"You cannot add attributes to %s" % self)
50 def _swig_setattr(self,class_type,name,value):
51 return _swig_setattr_nondynamic(self,class_type,name,value,0)
53 def _swig_getattr(self,class_type,name):
54 if (name ==
"thisown"):
return self.this.own()
55 method = class_type.__swig_getmethods__.get(name,
None)
56 if method:
return method(self)
57 raise AttributeError(name)
60 try: strthis =
"proxy of " + self.this.__repr__()
62 return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
67 except AttributeError:
72 def _swig_setattr_nondynamic_method(set):
73 def set_attr(self,name,value):
74 if (name ==
"thisown"):
return self.this.own(value)
75 if hasattr(self,name)
or (name ==
"this"):
78 raise AttributeError(
"You cannot add attributes to %s" % self)
84 weakref_proxy = weakref.proxy
86 weakref_proxy =
lambda x: x
89 class IMP_MODELLER_SwigPyIterator(object):
90 """Proxy of C++ swig::IMP_MODELLER_SwigPyIterator class"""
91 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
92 def __init__(self, *args, **kwargs):
raise AttributeError(
"No constructor defined - class is abstract")
94 __swig_destroy__ = _IMP_modeller.delete_IMP_MODELLER_SwigPyIterator
95 __del__ =
lambda self :
None;
97 """value(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
98 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_value(self)
102 incr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
103 incr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
105 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_incr(self, n)
109 decr(IMP_MODELLER_SwigPyIterator self, size_t n=1) -> IMP_MODELLER_SwigPyIterator
110 decr(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator
112 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_decr(self, n)
114 def distance(self, *args):
115 """distance(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t"""
116 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_distance(self, *args)
118 def equal(self, *args):
119 """equal(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
120 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_equal(self, *args)
123 """copy(IMP_MODELLER_SwigPyIterator self) -> IMP_MODELLER_SwigPyIterator"""
124 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_copy(self)
127 """next(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
128 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_next(self)
131 """__next__(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
132 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___next__(self)
135 """previous(IMP_MODELLER_SwigPyIterator self) -> PyObject *"""
136 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_previous(self)
138 def advance(self, *args):
139 """advance(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
140 return _IMP_modeller.IMP_MODELLER_SwigPyIterator_advance(self, *args)
142 def __eq__(self, *args):
143 """__eq__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
144 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___eq__(self, *args)
146 def __ne__(self, *args):
147 """__ne__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> bool"""
148 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___ne__(self, *args)
150 def __iadd__(self, *args):
151 """__iadd__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
152 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___iadd__(self, *args)
154 def __isub__(self, *args):
155 """__isub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
156 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___isub__(self, *args)
158 def __add__(self, *args):
159 """__add__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator"""
160 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___add__(self, *args)
162 def __sub__(self, *args):
164 __sub__(IMP_MODELLER_SwigPyIterator self, ptrdiff_t n) -> IMP_MODELLER_SwigPyIterator
165 __sub__(IMP_MODELLER_SwigPyIterator self, IMP_MODELLER_SwigPyIterator x) -> ptrdiff_t
167 return _IMP_modeller.IMP_MODELLER_SwigPyIterator___sub__(self, *args)
169 def __iter__(self):
return self
170 IMP_MODELLER_SwigPyIterator_swigregister = _IMP_modeller.IMP_MODELLER_SwigPyIterator_swigregister
171 IMP_MODELLER_SwigPyIterator_swigregister(IMP_MODELLER_SwigPyIterator)
178 IMP_DEBUG = _IMP_modeller.IMP_DEBUG
179 IMP_RELEASE = _IMP_modeller.IMP_RELEASE
180 IMP_SILENT = _IMP_modeller.IMP_SILENT
181 IMP_PROGRESS = _IMP_modeller.IMP_PROGRESS
182 IMP_TERSE = _IMP_modeller.IMP_TERSE
183 IMP_VERBOSE = _IMP_modeller.IMP_VERBOSE
184 IMP_MEMORY = _IMP_modeller.IMP_MEMORY
185 IMP_NONE = _IMP_modeller.IMP_NONE
186 IMP_USAGE = _IMP_modeller.IMP_USAGE
187 IMP_INTERNAL = _IMP_modeller.IMP_INTERNAL
188 IMP_BASE_HAS_LOG4CXX = _IMP_modeller.IMP_BASE_HAS_LOG4CXX
189 IMP_COMPILER_HAS_AUTO = _IMP_modeller.IMP_COMPILER_HAS_AUTO
190 IMP_COMPILER_HAS_DEBUG_VECTOR = _IMP_modeller.IMP_COMPILER_HAS_DEBUG_VECTOR
191 IMP_BASE_HAS_BOOST_RANDOM = _IMP_modeller.IMP_BASE_HAS_BOOST_RANDOM
192 IMP_BASE_HAS_GPERFTOOLS = _IMP_modeller.IMP_BASE_HAS_GPERFTOOLS
193 IMP_BASE_HAS_TCMALLOC_HEAPCHECKER = _IMP_modeller.IMP_BASE_HAS_TCMALLOC_HEAPCHECKER
194 IMP_BASE_HAS_TCMALLOC_HEAPPROFILER = _IMP_modeller.IMP_BASE_HAS_TCMALLOC_HEAPPROFILER
195 IMPBASE_SHOW_WARNINGS = _IMP_modeller.IMPBASE_SHOW_WARNINGS
197 class _DirectorObjects(object):
198 """@internal Simple class to keep references to director objects
199 to prevent premature deletion."""
202 def register(self, obj):
203 """Take a reference to a director object; will only work for
204 refcounted C++ classes"""
205 if hasattr(obj,
'get_ref_count'):
206 self._objects.append(obj)
208 """Only drop our reference and allow cleanup by Python if no other
209 Python references exist (we hold 3 references: one in self._objects,
210 one in x, and one in the argument list for getrefcount) *and* no
211 other C++ references exist (the Python object always holds one)"""
212 objs = [x
for x
in self._objects
if sys.getrefcount(x) > 3 \
213 or x.get_ref_count() > 1]
217 def get_object_count(self):
218 """Get number of director objects (useful for testing only)"""
219 return len(self._objects)
220 _director_objects = _DirectorObjects()
222 class _ostream(object):
223 """Proxy of C++ std::ostream class"""
224 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
225 def __init__(self, *args, **kwargs):
raise AttributeError(
"No constructor defined")
226 __repr__ = _swig_repr
227 def write(self, *args):
228 """write(_ostream self, char const * osa_buf)"""
229 return _IMP_modeller._ostream_write(self, *args)
231 _ostream_swigregister = _IMP_modeller._ostream_swigregister
232 _ostream_swigregister(_ostream)
234 IMP_COMPILER_HAS_OVERRIDE = _IMP_modeller.IMP_COMPILER_HAS_OVERRIDE
235 IMP_COMPILER_HAS_FINAL = _IMP_modeller.IMP_COMPILER_HAS_FINAL
236 IMP_HAS_NOEXCEPT = _IMP_modeller.IMP_HAS_NOEXCEPT
238 IMP_CGAL_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_FILESYSTEM
239 IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CGAL_HAS_BOOST_PROGRAMOPTIONS
240 IMP_CGAL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CGAL_HAS_BOOST_RANDOM
241 IMP_CGAL_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CGAL_HAS_BOOST_SYSTEM
242 IMPCGAL_SHOW_WARNINGS = _IMP_modeller.IMPCGAL_SHOW_WARNINGS
244 IMP_ALGEBRA_HAS_IMP_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_IMP_CGAL
245 IMP_ALGEBRA_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_FILESYSTEM
246 IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_PROGRAMOPTIONS
247 IMP_ALGEBRA_HAS_BOOST_RANDOM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_RANDOM
248 IMP_ALGEBRA_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_ALGEBRA_HAS_BOOST_SYSTEM
249 IMP_ALGEBRA_HAS_CGAL = _IMP_modeller.IMP_ALGEBRA_HAS_CGAL
250 IMP_ALGEBRA_HAS_ANN = _IMP_modeller.IMP_ALGEBRA_HAS_ANN
251 IMPALGEBRA_SHOW_WARNINGS = _IMP_modeller.IMPALGEBRA_SHOW_WARNINGS
253 IMP_KERNEL_HAS_IMP_CGAL = _IMP_modeller.IMP_KERNEL_HAS_IMP_CGAL
254 IMP_KERNEL_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_KERNEL_HAS_BOOST_PROGRAMOPTIONS
255 IMP_KERNEL_HAS_BOOST_RANDOM = _IMP_modeller.IMP_KERNEL_HAS_BOOST_RANDOM
256 IMP_KERNEL_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_KERNEL_HAS_BOOST_SYSTEM
257 IMP_KERNEL_HAS_CGAL = _IMP_modeller.IMP_KERNEL_HAS_CGAL
258 IMPKERNEL_SHOW_WARNINGS = _IMP_modeller.IMPKERNEL_SHOW_WARNINGS
260 IMP_DISPLAY_HAS_IMP_BASE = _IMP_modeller.IMP_DISPLAY_HAS_IMP_BASE
261 IMP_DISPLAY_HAS_IMP_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_IMP_CGAL
262 IMP_DISPLAY_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_FILESYSTEM
263 IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_PROGRAMOPTIONS
264 IMP_DISPLAY_HAS_BOOST_RANDOM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_RANDOM
265 IMP_DISPLAY_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_DISPLAY_HAS_BOOST_SYSTEM
266 IMP_DISPLAY_HAS_CGAL = _IMP_modeller.IMP_DISPLAY_HAS_CGAL
267 IMPDISPLAY_SHOW_WARNINGS = _IMP_modeller.IMPDISPLAY_SHOW_WARNINGS
269 IMP_SCORE_FUNCTOR_HAS_IMP_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_IMP_CGAL
270 IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_FILESYSTEM
271 IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_PROGRAMOPTIONS
272 IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_RANDOM
273 IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_BOOST_SYSTEM
274 IMP_SCORE_FUNCTOR_HAS_CGAL = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_CGAL
275 IMP_SCORE_FUNCTOR_HAS_HDF5 = _IMP_modeller.IMP_SCORE_FUNCTOR_HAS_HDF5
276 IMPSCOREFUNCTOR_SHOW_WARNINGS = _IMP_modeller.IMPSCOREFUNCTOR_SHOW_WARNINGS
278 IMP_CORE_HAS_IMP_BASE = _IMP_modeller.IMP_CORE_HAS_IMP_BASE
279 IMP_CORE_HAS_IMP_CGAL = _IMP_modeller.IMP_CORE_HAS_IMP_CGAL
280 IMP_CORE_HAS_IMP_KERNEL = _IMP_modeller.IMP_CORE_HAS_IMP_KERNEL
281 IMP_CORE_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_FILESYSTEM
282 IMP_CORE_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_CORE_HAS_BOOST_PROGRAMOPTIONS
283 IMP_CORE_HAS_BOOST_RANDOM = _IMP_modeller.IMP_CORE_HAS_BOOST_RANDOM
284 IMP_CORE_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_CORE_HAS_BOOST_SYSTEM
285 IMP_CORE_HAS_CGAL = _IMP_modeller.IMP_CORE_HAS_CGAL
286 IMP_CORE_HAS_HDF5 = _IMP_modeller.IMP_CORE_HAS_HDF5
287 IMPCORE_SHOW_WARNINGS = _IMP_modeller.IMPCORE_SHOW_WARNINGS
289 IMP_MODELLER_HAS_IMP_ALGEBRA = _IMP_modeller.IMP_MODELLER_HAS_IMP_ALGEBRA
290 IMP_MODELLER_HAS_IMP_BASE = _IMP_modeller.IMP_MODELLER_HAS_IMP_BASE
291 IMP_MODELLER_HAS_IMP_CGAL = _IMP_modeller.IMP_MODELLER_HAS_IMP_CGAL
292 IMP_MODELLER_HAS_IMP_DISPLAY = _IMP_modeller.IMP_MODELLER_HAS_IMP_DISPLAY
293 IMP_MODELLER_HAS_IMP_KERNEL = _IMP_modeller.IMP_MODELLER_HAS_IMP_KERNEL
294 IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR = _IMP_modeller.IMP_MODELLER_HAS_IMP_SCORE_FUNCTOR
295 IMP_MODELLER_HAS_BOOST_FILESYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_FILESYSTEM
296 IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS = _IMP_modeller.IMP_MODELLER_HAS_BOOST_PROGRAMOPTIONS
297 IMP_MODELLER_HAS_BOOST_RANDOM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_RANDOM
298 IMP_MODELLER_HAS_BOOST_SYSTEM = _IMP_modeller.IMP_MODELLER_HAS_BOOST_SYSTEM
299 IMP_MODELLER_HAS_CGAL = _IMP_modeller.IMP_MODELLER_HAS_CGAL
300 IMP_MODELLER_HAS_HDF5 = _IMP_modeller.IMP_MODELLER_HAS_HDF5
301 IMPMODELLER_SHOW_WARNINGS = _IMP_modeller.IMPMODELLER_SHOW_WARNINGS
302 BinormalTermList=list
303 _plural_types.append(
"BinormalTermList")
304 _value_types.append(
"BinormalTerm")
306 _object_types.append(
"MultipleBinormalRestraint")
309 def _object_cast_to_MultipleBinormalRestraint(*args):
310 """_object_cast_to_MultipleBinormalRestraint(Object o) -> MultipleBinormalRestraint"""
311 return _IMP_modeller._object_cast_to_MultipleBinormalRestraint(*args)
321 def _import_modeller_scripts_optimizers():
322 """Do the equivalent of "import modeller.scripts, modeller.optimizers".
323 (We can't do the regular import because Python tries a relative import
324 first, and that would load the modeller module in IMP.) This is an
325 absolute import. Once we can require that everybody uses Python 2.6,
326 this should no longer be required."""
327 modeller = _import_module(
"modeller",
"modeller",
None)
328 scripts = _import_module(
"scripts",
"modeller.scripts", modeller)
329 optimizers = _import_module(
"optimizers",
"modeller.optimizers", modeller)
330 modeller.scripts = scripts
331 modeller.optimizers = optimizers
334 def _import_module(partname, fqname, parent):
335 """Import a single Python module, possibly from a parent."""
336 fp, pathname, description = imp.find_module(partname,
337 parent
and parent.__path__)
339 m = imp.load_module(fqname, fp, pathname, description)
346 modeller = _import_modeller_scripts_optimizers()
349 class _TempDir(object):
350 """Make a temporary directory that is deleted when the object is."""
353 self.tmpdir = tempfile.mkdtemp()
356 shutil.rmtree(self.tmpdir, ignore_errors=
True)
360 """A Modeller restraint which evaluates all defined IMP restraints.
361 This can be used to incorporate IMP Restraints into an existing
362 comparative modeling pipeline, or to use Modeller optimizers or
366 _physical_type = modeller.physical.absposition
370 @param particles A list of the IMP atoms (as Particle objects),
371 same order as the Modeller atoms.
372 @note since Modeller, unlike IMP, is sensitive to the ordering
373 of atoms, it usually makes sense to create the model in
374 Modeller and then use ModelLoader to load it into IMP,
375 since that will preserve the Modeller atom ordering in IMP.
377 modeller.terms.energy_term.__init__(self)
378 self._particles = particles
380 def eval(self, mdl, deriv, indats):
381 atoms = self.indices_to_atoms(mdl, indats)
382 _copy_modeller_coords_to_imp(atoms, self._particles)
383 if len(self._particles) == 0:
386 score = self._particles[0].get_model().evaluate(deriv)
388 dvx = [0.] * len(indats)
389 dvy = [0.] * len(indats)
390 dvz = [0.] * len(indats)
391 _get_imp_derivs(self._particles, dvx, dvy, dvz)
392 return (score, dvx, dvy, dvz)
398 """An IMP restraint using all defined Modeller restraints.
399 This is useful if you want to use Modeller restraints with an IMP
400 optimizer, or in combination with IMP restraints.
402 @note Currently only the coordinates of the atoms are translated
403 between Modeller and IMP; thus, a Modeller restraint which
404 uses any other attribute (e.g. charge) will not react if
405 this attribute is changed by IMP.
408 def __init__(self, model, modeller_model, particles):
410 @param model The IMP Model object.
411 @param modeller_model The Modeller model object.
412 @param particles A list of the IMP atoms (as Particle objects),
413 in the same order as the Modeller atoms.
414 @note since Modeller, unlike IMP, is sensitive to the ordering
415 of atoms, it usually makes sense to create the model in
416 Modeller and then use ModelLoader to load it into IMP,
417 since that will preserve the Modeller atom ordering in IMP.
420 if hasattr(x,
'get_particle'):
421 return x.get_particle()
424 IMP.Restraint.__init__(self, model,
"ModellerRestraints %1%")
425 self._modeller_model = modeller_model
426 self._particles = [get_particle(x)
for x
in particles]
428 def unprotected_evaluate(self, accum):
429 atoms = self._modeller_model.atoms
430 sel = modeller.selection(self._modeller_model)
431 _copy_imp_coords_to_modeller(self._particles, atoms)
432 energies = sel.energy()
434 _add_modeller_derivs_to_imp(atoms, self._particles, accum)
439 return IMP.VersionInfo(
"IMP developers",
"0.1")
440 def do_show(self, fh):
441 fh.write(
"ModellerRestraints")
443 return self._particles
446 def _copy_imp_coords_to_modeller(particles, atoms):
447 """Copy atom coordinates from IMP to Modeller"""
451 for (num, at)
in enumerate(atoms):
452 at.x = particles[num].get_value(xkey)
453 at.y = particles[num].get_value(ykey)
454 at.z = particles[num].get_value(zkey)
457 def _copy_modeller_coords_to_imp(atoms, particles):
458 """Copy atom coordinates from Modeller to IMP"""
462 for (num, at)
in enumerate(atoms):
463 particles[num].set_value(xkey, at.x)
464 particles[num].set_value(ykey, at.y)
465 particles[num].set_value(zkey, at.z)
468 def _add_modeller_derivs_to_imp(atoms, particles, accum):
469 """Add atom derivatives from Modeller to IMP"""
470 for (num, at)
in enumerate(atoms):
472 xyz.add_to_derivative(0, at.dvx, accum)
473 xyz.add_to_derivative(1, at.dvy, accum)
474 xyz.add_to_derivative(2, at.dvz, accum)
477 def _get_imp_derivs(particles, dvx, dvy, dvz):
478 """Move atom derivatives from IMP to Modeller"""
482 for idx
in range(0, len(dvx)):
483 dvx[idx] = particles[idx].get_derivative(xkey)
484 dvy[idx] = particles[idx].get_derivative(ykey)
485 dvz[idx] = particles[idx].get_derivative(zkey)
489 def _HarmonicLowerBoundGenerator(parameters, modalities):
490 (mean, stdev) = parameters
494 def _HarmonicUpperBoundGenerator(parameters, modalities):
495 (mean, stdev) = parameters
499 def _HarmonicGenerator(parameters, modalities):
500 (mean, stdev) = parameters
504 def _CosineGenerator(parameters, modalities):
505 (phase, force_constant) = parameters
506 (periodicity,) = modalities
509 def _LinearGenerator(parameters, modalities):
510 (scale,) = parameters
513 def _SplineGenerator(parameters, modalities):
514 (open, low, high, delta, lowderiv, highderiv) = parameters[:6]
516 for v
in parameters[6:]:
524 _unary_func_generators = {
525 1: _HarmonicLowerBoundGenerator,
526 2: _HarmonicUpperBoundGenerator,
527 3: _HarmonicGenerator,
530 10: _SplineGenerator,
534 def _DistanceRestraintGenerator(form, modalities, atoms, parameters):
535 unary_func_gen = _unary_func_generators[form]
539 def _AngleRestraintGenerator(form, modalities, atoms, parameters):
540 unary_func_gen = _unary_func_generators[form]
542 atoms[0], atoms[1], atoms[2])
544 def _MultiBinormalGenerator(form, modalities, atoms, parameters):
545 nterms = modalities[0]
546 if len(parameters) != nterms * 6:
547 raise ValueError(
"Incorrect number of parameters (%d) for multiple "
548 "binormal restraint - expecting %d (%d terms * 6)" \
549 % (len(parameters), nterms * 6, nterms))
552 for i
in range(nterms):
554 t.set_weight(parameters[i])
555 t.set_means((parameters[nterms + i * 2],
556 parameters[nterms + i * 2 + 1]))
557 t.set_standard_deviations((parameters[nterms * 3 + i * 2],
558 parameters[nterms * 3 + i * 2 + 1]))
559 t.set_correlation(parameters[nterms * 5 + i])
563 def _DihedralRestraintGenerator(form, modalities, atoms, parameters):
565 return _MultiBinormalGenerator(form, modalities, atoms, parameters)
566 unary_func_gen = _unary_func_generators[form]
568 atoms[0], atoms[1], atoms[2], atoms[3])
570 def _get_protein_atom_particles(protein):
571 """Given a protein particle, get the flattened list of all child atoms"""
574 for ichain
in range(protein.get_number_of_children()):
575 chain = protein.get_child(ichain)
576 for ires
in range(chain.get_number_of_children()):
577 residue = chain.get_child(ires)
578 for iatom
in range(residue.get_number_of_children()):
579 atom = residue.get_child(iatom)
580 atom_particles.append(atom.get_particle())
581 return atom_particles
583 def _load_restraints_line(line, atom_particles):
584 """Parse a single Modeller restraints file line and return the
585 corresponding IMP restraint."""
588 if typ ==
'MODELLER5':
591 raise NotImplementedError(
"Only 'R' lines currently read from " + \
592 "Modeller restraints files")
593 form = int(spl.pop(0))
594 modalities = [int(spl.pop(0))]
595 features = [int(spl.pop(0))]
598 natoms = [int(spl.pop(0))]
599 nparam = int(spl.pop(0))
600 nfeat = int(spl.pop(0))
601 for i
in range(nfeat - 1):
602 modalities.append(int(spl.pop(0)))
603 features.append(int(spl.pop(0)))
604 natoms.append(int(spl.pop(0)))
605 atoms = [int(spl.pop(0))
for x
in range(natoms[0])]
606 for i
in range(len(atoms)):
607 atoms[i] = atom_particles[atoms[i] - 1]
608 parameters = [float(spl.pop(0))
for x
in range(nparam)]
609 restraint_generators = {
610 1 : _DistanceRestraintGenerator,
611 2 : _AngleRestraintGenerator,
612 3 : _DihedralRestraintGenerator,
614 restraint_gen = restraint_generators[features[0]]
615 return restraint_gen(form, modalities, atoms, parameters)
618 def _load_entire_restraints_file(filename, protein):
619 """Yield a set of IMP restraints from a Modeller restraints file."""
620 atoms = _get_protein_atom_particles(protein)
621 fh = open(filename,
'r')
624 rsr = _load_restraints_line(line, atoms)
627 except Exception
as err:
628 print(
"Cannot read restraints file line:\n" + line)
633 """Convert a Modeller restraints file into IMP::Restraint objects.
635 @deprecated Use ModelLoader instead.
637 @param filename Name of the Modeller restraints file.
638 @param protein An IMP::atom::Hierarchy containing the protein atoms
639 (e.g. as returned by read_pdb). The Modeller restraints
640 file is assumed to act on the same PDB described by
642 @return A Python list of the newly-created IMP::Restraint objects.
644 return list(_load_entire_restraints_file(filename, protein))
647 def _copy_residue(r, model):
648 """Copy residue information from modeller to imp"""
653 p.set_name(str(
"residue "+r.num));
657 def _copy_atom(a, model):
658 """Copy atom information from modeller"""
664 if hasattr(a,
'charge'):
666 if hasattr(a,
'type'):
668 ap.set_input_index(a.index)
671 def _copy_chain(c, model):
672 """Copy chain information from modeller"""
679 def _get_forcefield(submodel):
691 """Add radii to the hierarchy using the Modeller radius library, radii.lib.
692 Each radius is scaled by the given scale (Modeller usually scales radii
693 by a factor of 0.82). submodel specifies the topology submodel, which is
694 the column in radii.lib to use."""
698 for line
in open(filename):
699 if line.startswith(
'#'):
continue
702 radii[spl[0]] = float(spl[submodel])
712 """Read a Modeller model into IMP. After creating this object, the atoms
713 in the Modeller model can be loaded into IMP using the load_atoms()
714 method, then optionally any Modeller static restraints can be read in
715 with load_static_restraints() or load_static_restraints_file().
717 This class can also be used to read Modeller alignment structures;
718 however, only load_atoms() will be useful in such a case (since
719 alignment structures don't have restraints or other information).
725 @param modeller_model The Modeller model or alignment structure
728 self._modeller_model = modeller_model
731 """Construct an IMP::atom::Hierarchy that contains the same atoms as
732 the Modeller model or alignment structure.
734 IMP atoms created from a Modeller model will be given charges and
735 CHARMM types, extracted from the model. Alignment structures don't
736 contain this information, so the IMP atoms won't either.
738 @param model The IMP::Model object in which the hierarchy will be
739 created. The highest level hierarchy node is a PROTEIN.
740 @return the newly-created root IMP::atom::Hierarchy.
745 for chain
in self._modeller_model.chains:
750 for residue
in chain.residues:
751 rp = _copy_residue(residue, model)
752 hrp = IMP.atom.Hierarchy.decorate_particle(rp)
754 for atom
in residue.atoms:
755 ap = _copy_atom(atom, model)
756 hap = IMP.atom.Hierarchy.decorate_particle(ap)
758 self._atoms[atom.index] = ap
760 self._modeller_hierarchy = hpp
763 def _get_nonbonded_list(self, atoms, pair_filter, edat, distance):
768 if pair_filter
is None:
770 if edat.excl_local[0]:
771 pair_filter.set_bonds(list(self.
load_bonds()))
772 if edat.excl_local[1]:
774 if edat.excl_local[2]:
776 nbl.add_pair_filter(pair_filter)
780 """Load the Modeller bond topology into the IMP model. Each bond is
781 represented in IMP as an IMP::atom::Bond, with no defined length
782 or stiffness. These bonds are primarily useful as input to
783 IMP::atom::StereochemistryPairFilter, to exclude bond interactions
784 from the nonbonded list. Typically the contribution to the scoring
785 function from the bonds is included in the Modeller static restraints
786 (use load_static_restraints() or load_static_restraints_file() to
787 load these). If you want to regenerate the stereochemistry in IMP,
788 do not use these functions (as then stereochemistry scoring terms
789 and exclusions would be double-counted) and instead use the
790 IMP::atom::CHARMMTopology class.
792 You must call load_atoms() prior to using this function.
793 @see load_angles(), load_dihedrals(), load_impropers()
794 @return A generator listing all of the bonds.
796 if not hasattr(self,
'_modeller_hierarchy'):
797 raise ValueError(
"Call load_atoms() first.")
798 for (maa, mab)
in self._modeller_model.bonds:
799 pa = self._atoms[maa.index]
800 pb = self._atoms[mab.index]
810 IMP.atom.Bond.SINGLE).get_particle()
813 """Load the Modeller angle topology into the IMP model.
814 See load_bonds() for more details."""
815 return self._internal_load_angles(self._modeller_model.angles,
819 """Load the Modeller dihedral topology into the IMP model.
820 See load_bonds() for more details."""
821 return self._internal_load_angles(self._modeller_model.dihedrals,
825 """Load the Modeller improper topology into the IMP model.
826 See load_bonds() for more details."""
827 return self._internal_load_angles(self._modeller_model.impropers,
830 def _internal_load_angles(self, angles, angle_class):
831 if not hasattr(self,
'_modeller_hierarchy'):
832 raise ValueError(
"Call load_atoms() first.")
833 for modeller_atoms
in angles:
834 imp_particles = [self._atoms[x.index]
for x
in modeller_atoms]
836 a = angle_class.setup_particle(p,
838 yield a.get_particle()
841 """Convert a Modeller static restraints file into equivalent
842 IMP::Restraints. load_atoms() must have been called first to read
843 in the atoms that the restraints will act upon.
844 @param filename Name of the Modeller restraints file. The restraints
845 in this file are assumed to act upon the model read in by
846 load_atoms(); no checking is done to enforce this.
847 @return A Python generator of the newly-created IMP::Restraint
850 if not hasattr(self,
'_modeller_hierarchy'):
851 raise ValueError(
"Call load_atoms() first.")
852 return _load_entire_restraints_file(filename, self._modeller_hierarchy)
856 """Convert the current set of Modeller static restraints into equivalent
857 IMP::Restraints. load_atoms() must have been called first to read
858 in the atoms that the restraints will act upon.
859 @return A Python generator of the newly-created IMP::Restraint
862 class _RestraintGenerator(object):
863 """Simple generator wrapper"""
866 def __iter__(self, *args, **keys):
868 def close(self, *args, **keys):
869 return self._gen.close(*args, **keys)
871 return next(self._gen)
873 def send(self, *args, **keys):
874 return self._gen.send(*args, **keys)
875 def throw(self, *args, **keys):
876 return self._gen.throw(*args, **keys)
879 rsrfile = os.path.join(t.tmpdir,
'restraints.rsr')
880 self._modeller_model.restraints.write(file=rsrfile)
883 wrap = _RestraintGenerator(gen)
889 """Convert Modeller dynamic restraints into IMP::Restraint objects.
891 For each currently active Modeller dynamic restraint
892 (e.g. soft-sphere, electrostatics) an equivalent IMP::Restraint
894 load_atoms() must have been called first to read
895 in the atoms that the restraints will act upon.
897 If pair_filter is given, it is an IMP::PairFilter object to exclude
898 pairs from the nonbonded lists used by the dynamic restraints.
899 Otherwise, an IMP::atom::StereochemistryPairFilter object is created
900 to exclude Modeller bonds, angles and dihedrals, as specified by
901 edat.excl_local. (Note that this calls load_bonds(), load_angles()
902 and load_dihedrals(), so will create duplicate lists of bonds if
903 those methods are called manually as well.)
905 @note Currently only soft-sphere, electrostatic and Lennard-Jones
906 restraints are loaded.
907 @return A Python generator of the newly-created IMP::Restraint
910 if not hasattr(self,
'_modeller_hierarchy'):
911 raise ValueError(
"Call load_atoms() first.")
912 edat = self._modeller_model.env.edat
913 libs = self._modeller_model.env.libs
917 if edat.dynamic_sphere:
920 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, 0.)
923 libs.topology.submodel, edat.radii_factor)
930 if edat.dynamic_lennard
or edat.dynamic_coulomb:
932 d = max(edat.contact_shell - 3.0, 0.0)
933 nbl = self._get_nonbonded_list(atoms, pair_filter, edat, d)
934 ff = _get_forcefield(libs.topology.submodel)
935 ff.add_radii(self._modeller_hierarchy)
937 if edat.dynamic_lennard:
938 ff.add_well_depths(self._modeller_hierarchy)
940 edat.lennard_jones_switch[1])
944 if edat.dynamic_coulomb:
946 edat.coulomb_switch[1])
948 ps.set_relative_dielectric(edat.relative_dielectric)
953 """Construct an IMP::atom::Hierarchy from a PDB file.
955 @deprecated Use IMP::atom::read_pdb() instead to read a PDB file,
956 or ModelLoader to read a Modeller model.
958 @param name The name of the PDB file to read.
959 @param model The IMP::Model object in which the hierarchy will be
960 created. The highest level hierarchy node is a PROTEIN.
961 @param special_patches If given, a function that applies patches
962 (e.g. nucleic acid termini) to the Modeller model.
963 @return the newly-created root IMP::atom::Hierarchy.
965 e = modeller.environ()
966 e.libs.topology.read(
'${LIB}/top_heav.lib')
967 e.libs.parameters.read(
'${LIB}/par.lib')
969 modeller_model = modeller.scripts.complete_pdb(e, name,
970 special_patches=special_patches)
972 hpp = loader.load_atoms(model)
973 hpp.get_particle().set_name(name)
978 """Proxy of C++ IMP::modeller::MultipleBinormalRestraint class"""
979 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
980 def __init__(self, *args):
981 """__init__(IMP::modeller::MultipleBinormalRestraint self, IMP::kernel::ParticleQuad const & q1, IMP::kernel::ParticleQuad const & q2) -> MultipleBinormalRestraint"""
982 this = _IMP_modeller.new_MultipleBinormalRestraint(*args)
983 try: self.this.append(this)
984 except: self.this = this
985 def add_term(self, *args):
986 """add_term(MultipleBinormalRestraint self, BinormalTerm term)"""
987 return _IMP_modeller.MultipleBinormalRestraint_add_term(self, *args)
989 def do_get_inputs(self):
990 """do_get_inputs(MultipleBinormalRestraint self) -> IMP::kernel::ModelObjectsTemp"""
991 return _IMP_modeller.MultipleBinormalRestraint_do_get_inputs(self)
993 def get_version_info(self):
994 """get_version_info(MultipleBinormalRestraint self) -> VersionInfo"""
995 return _IMP_modeller.MultipleBinormalRestraint_get_version_info(self)
998 """__str__(MultipleBinormalRestraint self) -> std::string"""
999 return _IMP_modeller.MultipleBinormalRestraint___str__(self)
1002 """__repr__(MultipleBinormalRestraint self) -> std::string"""
1003 return _IMP_modeller.MultipleBinormalRestraint___repr__(self)
1006 return _object_cast_to_MultipleBinormalRestraint(o)
1007 get_from = staticmethod(get_from)
1009 MultipleBinormalRestraint_swigregister = _IMP_modeller.MultipleBinormalRestraint_swigregister
1010 MultipleBinormalRestraint_swigregister(MultipleBinormalRestraint)
1013 """Proxy of C++ IMP::modeller::BinormalTerm class"""
1014 thisown = _swig_property(
lambda x: x.this.own(),
lambda x, v: x.this.own(v), doc=
'The membership flag')
1016 """__init__(IMP::modeller::BinormalTerm self) -> BinormalTerm"""
1017 this = _IMP_modeller.new_BinormalTerm()
1018 try: self.this.append(this)
1019 except: self.this = this
1020 def set_correlation(self, *args):
1021 """set_correlation(BinormalTerm self, double correlation)"""
1022 return _IMP_modeller.BinormalTerm_set_correlation(self, *args)
1024 def set_weight(self, *args):
1025 """set_weight(BinormalTerm self, double weight)"""
1026 return _IMP_modeller.BinormalTerm_set_weight(self, *args)
1028 def set_means(self, *args):
1029 """set_means(BinormalTerm self, IMP::FloatPair means)"""
1030 return _IMP_modeller.BinormalTerm_set_means(self, *args)
1032 def set_standard_deviations(self, *args):
1033 """set_standard_deviations(BinormalTerm self, IMP::FloatPair stdevs)"""
1034 return _IMP_modeller.BinormalTerm_set_standard_deviations(self, *args)
1036 def show(self, *args):
1038 show(BinormalTerm self, _ostream out=std::cout)
1039 show(BinormalTerm self)
1041 return _IMP_modeller.BinormalTerm_show(self, *args)
1044 """__str__(BinormalTerm self) -> std::string"""
1045 return _IMP_modeller.BinormalTerm___str__(self)
1048 """__repr__(BinormalTerm self) -> std::string"""
1049 return _IMP_modeller.BinormalTerm___repr__(self)
1051 __swig_destroy__ = _IMP_modeller.delete_BinormalTerm
1052 __del__ =
lambda self :
None;
1053 BinormalTerm_swigregister = _IMP_modeller.BinormalTerm_swigregister
1054 BinormalTerm_swigregister(BinormalTerm)
1057 def get_module_version():
1058 """get_module_version() -> std::string const"""
1059 return _IMP_modeller.get_module_version()
1062 """get_example_path(std::string fname) -> std::string"""
1063 return _IMP_modeller.get_example_path(*args)
1066 """get_data_path(std::string fname) -> std::string"""
1067 return _IMP_modeller.get_data_path(*args)
1068 from .
import _version_check
1069 _version_check.check_version(get_module_version())
static Residue setup_particle(kernel::Model *m, ParticleIndex pi, ResidueType t, int index, int insertion_code)
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.
static Charged setup_particle(kernel::Model *m, ParticleIndex pi, Float charge)
def read_pdb
Construct an IMP::atom::Hierarchy from a PDB file.
std::string get_example_path(std::string file_name)
Return the path to installed example data for this module.
def load_bonds
Load the Modeller bond topology into the IMP model.
A Modeller restraint which evaluates all defined IMP restraints.
Coulomb (electrostatic) score between a pair of particles.
static CHARMMAtom setup_particle(kernel::Model *m, ParticleIndex pi, String charmm_type)
static Atom setup_particle(kernel::Model *m, ParticleIndex pi, Atom other)
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
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.
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
std::string get_data_path(std::string file_name)
Return the full path to installed data.
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
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.
def load_dynamic_restraints
Convert Modeller dynamic restraints into IMP::Restraint objects.
Distance restraint between two particles.
Composable functors to implement scores via compile-time composition.
An IMP restraint using all defined Modeller restraints.
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
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.
virtual VersionInfo get_version_info() const
Get information about the module and version of the object.
A single binormal term in a MultipleBinormalRestraint.
Angle restraint between three particles.
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
static Bonded setup_particle(kernel::Model *m, ParticleIndex pi)
Lennard-Jones score between a pair of particles.
A particle that describes an angle between three particles.
static Hierarchy setup_particle(kernel::Model *m, kernel::ParticleIndex pi, kernel::ParticleIndexesAdaptor children=kernel::ParticleIndexesAdaptor())
Store a kernel::ParticleIndexes.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Base functionality and abstract base classes for representation, scoring and sampling.
def load_atoms
Construct an IMP::atom::Hierarchy that contains the same atoms as the Modeller model or alignment str...
A restraint is a term in an IMP ScoringFunction.
A decorator for a particle with x,y,z coordinates.
static Chain setup_particle(kernel::Model *m, ParticleIndex pi, std::string id)
def load_restraints_file
Convert a Modeller restraints file into IMP::Restraint objects.
Class to handle individual model particles.
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.
Modeller-style multiple binormal (phi/psi) restraint.
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...
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
virtual ModelObjectsTemp do_get_inputs() const =0
A filter that excludes bonds, angles and dihedrals.
Read a Modeller model into IMP.
std::string get_data_path(std::string file_name)
Return the full path to installed data.
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.
Hierarchies get_leaves(const Selection &h)
Applies a PairScore to each Pair in a list.
Closed cubic spline function.
A decorator for an atom that has a defined CHARMM type.
Harmonic function (symmetric about the mean)