IMP logo
IMP Reference Guide  develop.879b8d2544,2020/09/29
The Integrative Modeling Platform
core/simple.py

Illustration of simple usage of the IMP library from Python.

1 ## \example core/simple.py
2 # Illustration of simple usage of the IMP library from Python.
3 #
4 
5 import IMP
6 import IMP.algebra
7 import IMP.core
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "simple example")
11 
12 m = IMP.Model()
13 
14 # Create two "untyped" particles
15 p1 = m.add_particle('p1')
16 p2 = 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)
23 d1.set_coordinates(IMP.algebra.Vector3D(10.0, 10.0, 10.0))
24 d2.set_coordinates(IMP.algebra.Vector3D(-10.0, -10.0, -10.0))
25 print(d1, d2)
26 
27 # Harmonically restrain p1 to be zero distance from the origin
28 f = IMP.core.Harmonic(0.0, 1.0)
30 r1 = IMP.core.SingletonRestraint(m, s, p1)
31 
32 # Harmonically restrain p1 and p2 to be distance 5.0 apart
33 f = IMP.core.Harmonic(5.0, 1.0)
35 r2 = IMP.core.PairRestraint(m, s, (p1, p2))
36 
37 # Optimize the x,y,z coordinates of both particles with conjugate gradients
38 sf = IMP.core.RestraintsScoringFunction([r1, r2], "scoring function")
39 d1.set_coordinates_are_optimized(True)
40 d2.set_coordinates_are_optimized(True)
42 o.set_scoring_function(sf)
43 o.optimize(50)
44 print(d1, d2)