imp — Access the import internals

imp — Access the import internals

The core of IMP is the Python library, which provides all of the necessary components, as a set of classes and modules, to allow methods developers to build an integrative modeling protocol from scratch. Most users of IMP will use one of the higher-level interfaces described in later sections of this tutorial; however, we will briefly demonstrate this library here to illustrate the core IMP concepts that these interfaces rely on.
IMP is primarily implemented in C++ for speed; however, each of the classes is wrapped so that it can also be used from Python. A protocol can thus be developed from scratch by simply writing a Python script. As an example, we will first look at the script

import IMP
import IMP.algebra
import IMP.core

m = IMP.Model()

# Create two "untyped" Particles
p1 = IMP.Particle(m)
p2 = IMP.Particle(m)

# "Decorate" the Particles with x,y,z attributes (point-like particles)
d1 = IMP.core.XYZ.setup_particle(p1)
d2 = IMP.core.XYZ.setup_particle(p2)

# Use some XYZ-specific functionality (set coordinates)
d1.set_coordinates(IMP.algebra.Vector3D(10.0, 10.0, 10.0))
d2.set_coordinates(IMP.algebra.Vector3D(-10.0, -10.0, -10.0))
print d1, d2

# Harmonically restrain p1 to be zero distance from the origin
f = IMP.core.Harmonic(0.0, 1.0)
s = IMP.core.DistanceToSingletonScore(f, IMP.algebra.Vector3D(0., 0., 0.))
r1 = IMP.core.SingletonRestraint(s, p1)

# Harmonically restrain p1 and p2 to be distance 5.0 apart
f = IMP.core.Harmonic(5.0, 1.0)
s = IMP.core.DistancePairScore(f)
r2 = IMP.core.PairRestraint(s, (p1, p2))

# Optimize the x,y,z coordinates of both particles with conjugate gradients
o = IMP.core.ConjugateGradients(m)
print (d1, d2)

Return the magic string value used to recognize byte-compiled code files (.pyc file). (This value may be different for each Python version.)


  • rohit
    17-Jun-2022 12:39:01 AM
    Very much helpful.

  • Utkarsh
    16-Jun-2022 11:10:00 PM
    Nice one!
  • Umesh
    16-Jun-2022 10:38:23 PM
    Very informative