home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.6.1
The Integrative Modeling Platform
IMP Manual
Reference Guide
Modules
Classes
Examples
version 2.6.1
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
import
sys
7
8
IMP.setup_from_argv
(sys.argv,
"symmetry example"
)
9
10
m =
IMP.Model
()
11
m.set_log_level(IMP.SILENT)
12
ps = []
13
# create 4 xyz particles
14
for
i
in
range(0, 4):
15
p =
IMP.Particle
(m)
16
ps.append(p)
17
d =
IMP.core.XYZ.setup_particle
(p,
IMP.algebra.Vector3D
(.5, 0, 0))
18
IMP.core.XYZR.setup_particle
(p, 1)
19
20
# set the 0 particle as the reference particle for the others as
21
# they will get their positions from it
22
for
i, p
in
enumerate(ps[1:]):
23
# the other 3 particles are all symmetric copies of the first
24
IMP.core.Reference.setup_particle
(p, ps[0])
25
# the symmetry operation is rotation around the z axis
26
tr =
IMP.algebra.Transformation3D
(
27
IMP.algebra.get_rotation_about_axis
(IMP.algebra.get_basis_vector_3d(2),
28
3.14 / 2.0 * (
29
i + 1)),
30
IMP.algebra.Vector3D
(0, 0, 0))
31
sm =
IMP.core.TransformationSymmetry
(tr)
32
# set up a constraint for the one particle, if you have more than one with the same symmetry
33
# transform, you should use an IMP.container.SingletonsConstraint.
34
c =
IMP.core.SingletonConstraint
(sm,
None
, m, p)
35
m.add_score_state(c)
36
lsc =
IMP.container.ListSingletonContainer
(m, ps)
37
r =
IMP.core.ExcludedVolumeRestraint
(lsc, 1)
38
sf =
IMP.core.RestraintsScoringFunction
([r])
39
40
d0 =
IMP.core.XYZ
(ps[0])
41
# print only optimize the main particle
42
d0.set_coordinates_are_optimized(
True
)
43
44
opt =
IMP.core.ConjugateGradients
(m)
45
opt.set_scoring_function(sf)
46
opt.optimize(10)
47
print(
"score is "
, sf.evaluate(
False
))
48
for
p
in
ps:
49
print(p.get_name(),
IMP.core.XYZ
(p).get_coordinates())