This is a read-only mirror of pymolwiki.org

Difference between revisions of "Dynamic mesh"

From PyMOL Wiki
Jump to navigation Jump to search
(Wizard > Density)
(Supported map_auto_expand_sym)
Line 6: Line 6:
 
== Usage ==
 
== Usage ==
  
  dynamic_mesh mapname [, level [, radius]]
+
  dynamic_mesh mapname [, level [, radius [, sym_source]]]
  
 
where
 
where
Line 13: Line 13:
 
  level = float: contour level of isomesh {default: 0.8}
 
  level = float: contour level of isomesh {default: 0.8}
 
  radius = float: radius of isomesh around the center of the view {default: 8}
 
  radius = float: radius of isomesh around the center of the view {default: 8}
 +
sym_source = string: name of object from which symmetry
 +
                  information is derived {default: None}
  
 
== Example ==
 
== Example ==
Line 20: Line 22:
 
fetch 1HWK, 1hwk_map, type=2fofc, async=1
 
fetch 1HWK, 1hwk_map, type=2fofc, async=1
 
run dynamic_mesh.py
 
run dynamic_mesh.py
dynamic_mesh 1hwk_map
+
dynamic_mesh 1hwk_map, sym_source=1hwk
 
show sticks, resn 117
 
show sticks, resn 117
 
show ribbon
 
show ribbon
Line 32: Line 34:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
# Dynamic Mesh by Takanori Nakane, License: BSD-2 Clause
 
# Dynamic Mesh by Takanori Nakane, License: BSD-2 Clause
# version 0.11: 20120823
+
# version 0.2: 20120825
 
+
 
'''
 
'''
 
This script was tested on PyMOL 1.2 and 1.5.
 
This script was tested on PyMOL 1.2 and 1.5.
 
+
 
Example:
 
Example:
 
+
 
fetch 1HWK, async=1
 
fetch 1HWK, async=1
 
fetch 1HWK, 1hwk_map, type=2fofc, async=1
 
fetch 1HWK, 1hwk_map, type=2fofc, async=1
 
run dynamic_mesh.py
 
run dynamic_mesh.py
dynamic_mesh 1hwk_map
+
dynamic_mesh 1hwk_map, sym_source=1hwk
 
show sticks, resn 117
 
show sticks, resn 117
 
show ribbon
 
show ribbon
 
zoom chain A and resn 117
 
zoom chain A and resn 117
 
+
 
Note: On PyMOL <= 1.4, you have to download the electron density
 
Note: On PyMOL <= 1.4, you have to download the electron density
 
map from the Uppsala Electron Density Server manually.
 
map from the Uppsala Electron Density Server manually.
 
'''
 
'''
 
+
 
from pymol.callback import Callback
 
from pymol.callback import Callback
 
from pymol import cmd
 
from pymol import cmd
 
   
 
   
 
class DynamicMesh(Callback):
 
class DynamicMesh(Callback):
     def __init__(self, meshname, level = 0.8, radius = 8):
+
     def __init__(self, meshname, level, radius, sym_source):
 
         self.center = cmd.get_position()
 
         self.center = cmd.get_position()
 
         self.level = level
 
         self.level = level
Line 62: Line 64:
 
         cmd.set("auto_zoom", 0)
 
         cmd.set("auto_zoom", 0)
 
         cmd.pseudoatom("__center__", pos = self.center, quiet = 1)
 
         cmd.pseudoatom("__center__", pos = self.center, quiet = 1)
 +
        if sym_source != None:
 +
            cmd.set("map_auto_expand_sym", 1)
 +
            cmd.set_symmetry("__center__", *cmd.get_symmetry(sym_source))
 
         cmd.hide("everything", "__center__")
 
         cmd.hide("everything", "__center__")
 
         cmd.set_key("pgup", self.contour_plus)
 
         cmd.set_key("pgup", self.contour_plus)
Line 67: Line 72:
 
         # TODO: Where should I unregister them?
 
         # TODO: Where should I unregister them?
 
         self.update()
 
         self.update()
 
+
 
     def contour_plus(self):
 
     def contour_plus(self):
 
         self.level += 0.1
 
         self.level += 0.1
 
         print "Map level: " + str(self.level)
 
         print "Map level: " + str(self.level)
 
         self.update()
 
         self.update()
 
+
 
     def contour_minus(self):
 
     def contour_minus(self):
 
         if (self.level < 0.15):
 
         if (self.level < 0.15):
Line 79: Line 84:
 
         print "Map level: " + str(self.level)
 
         print "Map level: " + str(self.level)
 
         self.update()
 
         self.update()
 
+
 
     def update(self):
 
     def update(self):
 
         self.center = cmd.get_position()
 
         self.center = cmd.get_position()
 
         cmd.alter_state(0, "__center__", "(x, y, z) = p", space={'p': self.center})
 
         cmd.alter_state(0, "__center__", "(x, y, z) = p", space={'p': self.center})
 
         cmd.isomesh("dynamic_mesh", self.mesh, self.level, "__center__", carve = self.radius)
 
         cmd.isomesh("dynamic_mesh", self.mesh, self.level, "__center__", carve = self.radius)
 
+
 
     def __call__(self):
 
     def __call__(self):
 
         tmp = cmd.get_position()
 
         tmp = cmd.get_position()
Line 92: Line 97:
 
         if (r > 0.3): # increase this number if it is too slow
 
         if (r > 0.3): # increase this number if it is too slow
 
             self.update()
 
             self.update()
       
+
 
     def get_extent(self):
 
     def get_extent(self):
 
         tmp = cmd.get_position()
 
         tmp = cmd.get_position()
 
         return [[tmp[0] - self.radius, tmp[1] - self.radius, tmp[2] - self.radius], \
 
         return [[tmp[0] - self.radius, tmp[1] - self.radius, tmp[2] - self.radius], \
 
                 [tmp[0] + self.radius, tmp[1] + self.radius, tmp[2] + self.radius]]
 
                 [tmp[0] + self.radius, tmp[1] + self.radius, tmp[2] + self.radius]]
 
+
def dynamic_mesh(meshname, level = 0.8, radius = 8):
+
def dynamic_mesh(meshname, level = 0.8, radius = 8, sym_source = None):
 
     '''
 
     '''
 
DESCRIPTION
 
DESCRIPTION
Line 105: Line 110:
 
     The mesh will dynamically follow the center of the view.
 
     The mesh will dynamically follow the center of the view.
 
     Contour leveo of isomesh can be changed by PageDown and PageUp keys.
 
     Contour leveo of isomesh can be changed by PageDown and PageUp keys.
 
+
     NOTE: Crystallographic operations will not be applied to the map.
+
     NOTE: Crystallographic operations can be applied to the map.
    Only pre-calculated volume can be displayed.
 
 
   
 
   
 
USAGE
 
USAGE
 
   
 
   
     dynamic_mesh mapname [, level [, radius]]
+
     dynamic_mesh mapname [, level [, radius [, sym_source]]]
 
   
 
   
 
ARGUMENTS
 
ARGUMENTS
Line 120: Line 124:
 
   
 
   
 
     radius = float: radius of isomesh around the center of the view {default: 8}
 
     radius = float: radius of isomesh around the center of the view {default: 8}
 
+
 +
    sym_source = string: name of object from which symmetry
 +
                        information is derived {default: None}
 +
 
 
SEE ALSO
 
SEE ALSO
 
   
 
   
 
     isomesh
 
     isomesh
 
     '''
 
     '''
       
+
 
     cmd.delete("dynamic_mesh") # TODO: support multiple meshs
 
     cmd.delete("dynamic_mesh") # TODO: support multiple meshs
 
     cmd.delete("dymesh_callback")
 
     cmd.delete("dymesh_callback")
     cmd.load_callback(DynamicMesh(meshname, float(level), float(radius)),'dymesh_callback')
+
     cmd.load_callback(DynamicMesh(meshname, float(level), float(radius), sym_source), 'dymesh_callback')
 
+
 
cmd.extend('dynamic_mesh', dynamic_mesh)
 
cmd.extend('dynamic_mesh', dynamic_mesh)
 
cmd.auto_arg[0]['dynamic_mesh'] = [ cmd.map_sc, 'map object', ', ']
 
cmd.auto_arg[0]['dynamic_mesh'] = [ cmd.map_sc, 'map object', ', ']
 +
cmd.auto_arg[3]['dynamic_mesh'] = [ cmd.object_sc, 'object', ', ']
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 139: Line 147:
 
* [[get_position]]
 
* [[get_position]]
 
* [[Density Wizard]]
 
* [[Density Wizard]]
 +
* [[map_auto_expand_sym]]
 
* Coot http://lmb.bioch.ox.ac.uk/coot/
 
* Coot http://lmb.bioch.ox.ac.uk/coot/
  
 
[[Category:Script_Library]]
 
[[Category:Script_Library]]
 
[[Category:UI_Scripts]]
 
[[Category:UI_Scripts]]

Revision as of 11:59, 25 August 2012

dynamic_mesh displays isomesh around the center of the view. When the view is moved, the isomesh will be updated automatically. You can also change contour level by PageDown/PageUp keys. This script is intended to implement interface similar to Coot for examing electron density maps.

Note: PyMOL's Density Wizard (Menu > Wizard > Density) provides similar functionality. It is implemented using wizard framework, while this uses CallBack object.

Usage

dynamic_mesh mapname [, level [, radius [, sym_source]]]

where

map_name = string: name of volumetric object(map) to display 
level = float: contour level of isomesh {default: 0.8}
radius = float: radius of isomesh around the center of the view {default: 8}
sym_source = string: name of object from which symmetry
                 information is derived {default: None}

Example

fetch 1HWK, async=1
fetch 1HWK, 1hwk_map, type=2fofc, async=1
run dynamic_mesh.py
dynamic_mesh 1hwk_map, sym_source=1hwk
show sticks, resn 117
show ribbon
zoom chain A and resn 117

Note: On PyMOL <= 1.4, you have to download the electron density map from the Uppsala Electron Density Server manually.

Script

# Dynamic Mesh by Takanori Nakane, License: BSD-2 Clause
# version 0.2:  20120825
 
'''
This script was tested on PyMOL 1.2 and 1.5.
 
Example:
 
fetch 1HWK, async=1
fetch 1HWK, 1hwk_map, type=2fofc, async=1
run dynamic_mesh.py
dynamic_mesh 1hwk_map, sym_source=1hwk
show sticks, resn 117
show ribbon
zoom chain A and resn 117
 
Note: On PyMOL <= 1.4, you have to download the electron density
map from the Uppsala Electron Density Server manually.
'''
 
from pymol.callback import Callback
from pymol import cmd
 
class DynamicMesh(Callback):
    def __init__(self, meshname, level, radius, sym_source):
        self.center = cmd.get_position()
        self.level = level
        self.radius = radius
        self.mesh = meshname
        cmd.set("auto_zoom", 0)
        cmd.pseudoatom("__center__", pos = self.center, quiet = 1)
        if sym_source != None:
            cmd.set("map_auto_expand_sym", 1)
            cmd.set_symmetry("__center__", *cmd.get_symmetry(sym_source))
        cmd.hide("everything", "__center__")
        cmd.set_key("pgup", self.contour_plus)
        cmd.set_key("pgdn", self.contour_minus)
        # TODO: Where should I unregister them?
        self.update()
 
    def contour_plus(self):
        self.level += 0.1
        print "Map level: " + str(self.level)
        self.update()
 
    def contour_minus(self):
        if (self.level < 0.15):
            return
        self.level -= 0.1
        print "Map level: " + str(self.level)
        self.update()
 
    def update(self):
        self.center = cmd.get_position()
        cmd.alter_state(0, "__center__", "(x, y, z) = p", space={'p': self.center})
        cmd.isomesh("dynamic_mesh", self.mesh, self.level, "__center__", carve = self.radius)
 
    def __call__(self):
        tmp = cmd.get_position()
        r = (self.center[0] - tmp[0]) * (self.center[0] - tmp[0]) + \
            (self.center[1] - tmp[1]) * (self.center[1] - tmp[1]) + \
            (self.center[2] - tmp[2]) * (self.center[2] - tmp[2])
        if (r > 0.3): # increase this number if it is too slow
            self.update()
 
    def get_extent(self):
        tmp = cmd.get_position()
        return [[tmp[0] - self.radius, tmp[1] - self.radius, tmp[2] - self.radius], \
                [tmp[0] + self.radius, tmp[1] + self.radius, tmp[2] + self.radius]]
 
def dynamic_mesh(meshname, level = 0.8, radius = 8, sym_source = None):
    '''
DESCRIPTION
 
    Make 'dynamic' mesh from volumetric data such as electron density map.
    The mesh will dynamically follow the center of the view.
    Contour leveo of isomesh can be changed by PageDown and PageUp keys.
 
    NOTE: Crystallographic operations can be applied to the map.
 
USAGE
 
    dynamic_mesh mapname [, level [, radius [, sym_source]]]
 
ARGUMENTS
 
    map_name = string: name of volumetric object(map) to display
 
    level = float: contour level of isomesh {default: 0.8}
 
    radius = float: radius of isomesh around the center of the view {default: 8}
 
    sym_source = string: name of object from which symmetry
                         information is derived {default: None}

SEE ALSO
 
    isomesh
    '''
 
    cmd.delete("dynamic_mesh") # TODO: support multiple meshs
    cmd.delete("dymesh_callback")
    cmd.load_callback(DynamicMesh(meshname, float(level), float(radius), sym_source), 'dymesh_callback')
 
cmd.extend('dynamic_mesh', dynamic_mesh)
cmd.auto_arg[0]['dynamic_mesh'] = [ cmd.map_sc, 'map object', ', ']
cmd.auto_arg[3]['dynamic_mesh'] = [ cmd.object_sc, 'object', ', ']

See Also