IMP
2.0.1
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
core/symmetry.py
Show how to use the code in core to enforce symmetry.
1
## \example core/symmetry.py
2
## Show how to use the code in core to enforce symmetry.
3
4
import
IMP.core
5
import
IMP.container
6
7
m=
IMP.Model
()
8
m.set_log_level(IMP.base.SILENT)
9
ps =[]
10
# create 4 xyz particles
11
for
i
in
range(0,4):
12
p =
IMP.Particle
(m)
13
ps.append(p)
14
d=
IMP.core.XYZ.setup_particle
(p,
IMP.algebra.Vector3D
(.5,0,0))
15
IMP.core.XYZR.setup_particle
(p, 1)
16
17
# set the 0 particle as the reference particle for the others as
18
# they will get their positions from it
19
for
i,p
in
enumerate(ps[1:]):
20
# the other 3 particles are all symmetric copies of the first
21
IMP.core.Reference.setup_particle
(p, ps[0])
22
# the symmetry operation is rotation around the z axis
23
tr=
IMP.algebra.Transformation3D
(
IMP.algebra.get_rotation_about_axis
(IMP.algebra.get_basis_vector_3d(2),
24
3.14/2.0*(i+1)),
25
IMP.algebra.Vector3D
(0,0,0))
26
sm=
IMP.core.TransformationSymmetry
(tr)
27
# set up a constraint for the one particle, if you have more than one with the same symmetry
28
# transform, you should use an IMP.container.SingletonsConstraint.
29
c=
IMP.core.SingletonConstraint
(sm,
None
, p)
30
m.add_score_state(c)
31
r=
IMP.core.ExcludedVolumeRestraint
(
IMP.container.ListSingletonContainer
(ps),
32
1)
33
m.add_restraint(r)
34
35
d0=
IMP.core.XYZ
(ps[0])
36
# print only optimize the main particle
37
d0.set_coordinates_are_optimized(
True
)
38
39
opt=
IMP.core.ConjugateGradients
(m)
40
opt.optimize(10)
41
print
"score is "
, m.evaluate(
False
)
42
for
p
in
ps:
43
print
p.get_name(),
IMP.core.XYZ
(p).get_coordinates()