IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/22
The Integrative Modeling Platform
display/show_particles_as_spheres.py

Write two colored sets of random IMP::core::XYZR particles to a Pymol input file.

1 ## \example display/show_particles_as_spheres.py
2 # Write two colored sets of random IMP::core::XYZR particles to a Pymol
3 # input file.
4 
5 import IMP
6 import IMP.algebra
7 import IMP.container
8 import IMP.core
9 import IMP.display
10 import sys
11 
13  sys.argv,
14  "Write two colored sets of random XYZR particles to a Pymol input file")
15 
16 # create two lists of random particles for display
17 m = IMP.Model()
18 n = 10
19 radius = 1.0
20 bounding_box_size = 10.0
21 xyzrs0 = IMP.core.create_xyzr_particles(m, 10, radius, bounding_box_size)
22 xyzrs1 = IMP.core.create_xyzr_particles(m, 10, radius, bounding_box_size)
23 xyzrs0_container = IMP.container.ListSingletonContainer(m, xyzrs0)
24 xyzrs1_container = IMP.container.ListSingletonContainer(m, xyzrs1)
25 
26 # create a writer that generates Pymol Python scripts for visualizing
27 # the particle lists
28 w = IMP.display.PymolWriter("out.pym")
29 # write first list of particles
30 g0 = IMP.core.XYZRsGeometry(xyzrs0_container)
31 g0.set_name("my particles")
32 g0.set_color(IMP.display.Color(1, 0, 0))
33 w.add_geometry(g0)
34 # write second list of particles
35 g1 = IMP.core.XYZRsGeometry(xyzrs1_container)
36 g1.set_name("my other particles")
37 g1.set_color(IMP.display.Color(0, 1, 0))
38 w.add_geometry(g1)
39 # make sure that the file is flushed
40 del w