IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
simple.py
1## \example core/simple.py
2# Illustration of simple usage of the IMP library from Python.
3#
4
5import IMP
6import IMP.algebra
7import IMP.core
8import sys
9
10IMP.setup_from_argv(sys.argv, "simple example")
11
12m = IMP.Model()
13
14# Create two "untyped" particles
15p1 = m.add_particle('p1')
16p2 = m.add_particle('p2')
17
18# "Decorate" the particles with x,y,z attributes (point-like particles)
21
22# Use some XYZ-specific functionality (set coordinates)
23d1.set_coordinates(IMP.algebra.Vector3D(10.0, 10.0, 10.0))
24d2.set_coordinates(IMP.algebra.Vector3D(-10.0, -10.0, -10.0))
25print(d1, d2)
26
27# Harmonically restrain p1 to be zero distance from the origin
28f = IMP.core.Harmonic(0.0, 1.0)
30r1 = IMP.core.SingletonRestraint(m, s, p1)
31
32# Harmonically restrain p1 and p2 to be distance 5.0 apart
33f = IMP.core.Harmonic(5.0, 1.0)
35r2 = IMP.core.PairRestraint(m, s, (p1, p2))
36
37# Optimize the x,y,z coordinates of both particles with conjugate gradients
38sf = IMP.core.RestraintsScoringFunction([r1, r2], "scoring function")
39d1.set_coordinates_are_optimized(True)
40d2.set_coordinates_are_optimized(True)
42o.set_scoring_function(sf)
43o.optimize(50)
44print(d1, d2)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Simple conjugate gradients optimizer.
Score a pair of particles based on the distance between their centers.
Harmonic function (symmetric about the mean)
Applies a PairScore to a Pair.
Create a scoring function on a list of restraints.
Applies a SingletonScore to a Singleton.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
Basic functionality that is expected to be used by a wide variety of IMP users.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.