You are reading the documentation for version 1.6 of OpenStructure. You may also want to read the documentation for: 1.1 1.2 1.3 1.4 1.5 devel
For the course of this tutorial, we assume that you have DNG up and running.
As already mentioned in the Introduction to the mol Module, the basic representation of molecular structures, sequences, images are completely independent from the graphical rendering. Thus, to display it on the screen, we first have to create a graphical representation of the object. This is illustrated for the entity below, but follows a similar scheme for density maps, surfaces and other types of data.
pdb = io.LoadPDB('/path/to/molecule.pdb') go = gfx.Entity('PROTEIN', pdb) scene.Add(go) scene.CenterOn(go)
The last command is not mandatory, but very convenient to center the camera on the object.
The scene is the central registry for graphical objects and manages rendering
parameters. Among other parameters, it is used to setup the lighting, fog,
background color and the camera. The scene is a singleton, meaning that there is
only one scene available. The instance can be accessed via
Now, the color of the screen has changed to white. To set it back to black, simply assign
Objects are added to the scene by calling
# retrieving the previously added protein obj = scene['PROTEIN'] # set color of the protein to red obj.SetColor(gfx.RED)
The last command assigns a uniform red color to all atoms.
The Graphical Entity¶
Molecules are rendered in different representations. Some representations show the structure at atomic detail (connectivity level display styles), while others simplify the structure significantly (trace-based display styles).
To change the display mode of an entity programmatically, use the
# render the molecule with an interpolated line trace obj.SetRenderMode(gfx.SLINE) # switch back to simple line rendering obj.SetRenderMode(gfx.SIMPLE) # switch to helix-strand-coil cartoon obj.SetRenderMode(gfx.HSC)
It is also possible to change the render mode of only a part of the structure. To display the ligand with balls and sticks and everything else in cartoon mode, we make use of the query language to select everything that is not part of the protein. Remember from above, that we stored our molecule in the pdb variable.
not_protein = pdb.Select('peptide=false') obj.SetRenderMode(gfx.HSC) obj.SetRenderMode(gfx.CUSTOM, not_protein)
The Basics of Coloring¶
The color of each atom can be set individually. The simplest coloring scheme is to set all atoms to the same color:
Assigning colors based on selections is also possible. To reproduce the well-known CPK coloring, 4 consecutive coloring operations are sufficient:
obj.SetColor(gfx.WHITE, 'ele=C') obj.SetColor(gfx.BLUE, 'ele=N') obj.SetColor(gfx.RED, 'ele=O') obj.SetColor(gfx.YELLOW, 'ele=S')
But because this is such a common task, the entity provides a built-in method to color the atoms by element:
As already seen above, the coloring operations can be chained to achieve the desired effect. For example, sometimes one wants to apply conventional CPK coloring to the protein and then change the color of C-alpha atoms to pink:
obj.ColorByElement() obj.SetColor(gfx.Color(1, 0, 1), 'aname=CA and ele=C')
Internally, the chain of calls to the coloring methods is stored as a list of coloring operations that is reapplied sequentially. This makes sure that the coloring remains when changing render modes or updating the geometry of the molecule. This storage scheme has one drawback. Consider the following code:
for i in range(100): obj.SetColor(gfx.RED)
While the code obviously achieves the desired effect, it is far from optimal
because all of the 100 color operations are applied every time the graphical
entity needs an update. When you see a slow down in rendering after playing
around with the coloring operations, consider calling
Coloring the Entity By Property¶
The most complex but also most powerful coloring method is
# will color the atoms by the atomic b-factor, setting atoms with # a temperature factor of 0 to blue and atoms with a temperature factor of # 100 and higher to red. Values in between are linearly interpolated. obj.ColorBy('abfac', gfx.BLUE, gfx.RED, 0, 100)
Fine-tuning the Coloring¶
Enter search terms or a module, class or function name.
You are here