Difference between revisions of "Selection Macros"

From PyMOLWiki
Jump to navigation Jump to search
(syntax, screenshot)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Selection Macros==
+
[[Image:right-click-macro.png|right|frame|The atom-right-click context menu title shows a selection macro]]
===General===
+
 
Macros make it possible to represent a long atom selection phrase such as
+
[[Selection Macros]] allow to represent a long [[Selection Algebra|atom selection]] phrase such as
 
    
 
    
<pre>PyMOL> select pept and segi lig and chain b and resi 142 and name ca</pre>
+
PyMOL> select pept and segi lig and chain B and resi 142 and name CA
  
 
in a more compact form:
 
in a more compact form:
  
<pre>PyMOL> select /pept/lig/b/142/ca</pre>
+
PyMOL> select /pept/lig/B/142/CA
 +
 
 +
== Syntax and Semantics ==
  
 
An atom selection macro uses slashes to define fields corresponding to identifiers. The macro is used to select atoms using the boolean "and," that is, the selected atoms must have all the matching identifiers:
 
An atom selection macro uses slashes to define fields corresponding to identifiers. The macro is used to select atoms using the boolean "and," that is, the selected atoms must have all the matching identifiers:
 
    
 
    
<pre>   /object-name/segi-identifier/chain-identifier/resi-identifier/name-identifier</pre>
+
<source lang="python">
 +
/object-name/segi-identifier/chain-identifier/resi-identifier/name-identifier
 +
</source>
 +
 
 +
* must contain '''at least one slash'''
 +
* no spaces allowed
 +
* '''empty''' fields are interpreted as '''wildcards'''
 +
* starting with a slash:
 +
** '''yes''': fields from the '''right''' can be omitted
 +
** '''no''': fields from the '''left''' can be omitted
  
These identifiers form a hierarchy from the object-name at the top, down to the name-identifier at the bottom. PyMOL has to be able to recognize the macro as one word, so no spaces are allowed within it.
+
== Details ==
  
 
Macros come in two flavors: those that begin with a slash and those that don't. The presence or absence of a slash at the beginning of the macro determines how it is interpreted. If the macro begins with a slash, PyMOL expects to find the fields starting from the top of the hierarchy: the first field to the right of the slash is interpreted as an object-name; the second field as an identifier to segi; the third as an identifier to chain, and so on. It may take any of the following forms:
 
Macros come in two flavors: those that begin with a slash and those that don't. The presence or absence of a slash at the beginning of the macro determines how it is interpreted. If the macro begins with a slash, PyMOL expects to find the fields starting from the top of the hierarchy: the first field to the right of the slash is interpreted as an object-name; the second field as an identifier to segi; the third as an identifier to chain, and so on. It may take any of the following forms:
Line 29: Line 40:
 
   PyMOL> zoom /pept
 
   PyMOL> zoom /pept
 
   PyMOL> show spheres, /pept/lig/
 
   PyMOL> show spheres, /pept/lig/
   PyMOL> show cartoon, /pept/lig/a
+
   PyMOL> show cartoon, /pept/lig/A
   PyMOL> color pink, /pept/lig/a/10
+
   PyMOL> color pink, /pept/lig/A/10
   PyMOL> color yellow, /pept/lig/a/10/ca   
+
   PyMOL> color yellow, /pept/lig/A/10/CA
 
</pre>
 
</pre>
  
Line 44: Line 55:
  
 
EXAMPLES
 
EXAMPLES
   PyMOL> zoom 10/cb
+
   PyMOL> zoom 10/CB
   PyMOL> show spheres, a/10-12/ca
+
   PyMOL> show spheres, A/10-12/CB
   PyMOL> show cartoon, lig/b/6+8/c+o
+
   PyMOL> show cartoon, lig/B/6+8/C+O
   PyMOL> color pink, pept/enz/c/3/n
+
   PyMOL> color pink, pept/enz/C/3/N
 
</pre>
 
</pre>
 
  
 
===Omitting Fields in a Macro===
 
===Omitting Fields in a Macro===
Line 64: Line 74:
 
   PyMOL> zoom 142/                  # Residue 142 fills the viewer.  
 
   PyMOL> zoom 142/                  # Residue 142 fills the viewer.  
 
    
 
    
   PyMOL> show spheres, 156/ca       # The alpha carbon of residue 156
+
   PyMOL> show spheres, 156/CA       # The alpha carbon of residue 156
 
                                     # is shown as a sphere     
 
                                     # is shown as a sphere     
 
                                      
 
                                      
   PyMOL> show cartoon, a//          # Chain "A" is shown as a cartoon.   
+
   PyMOL> show cartoon, A//          # Chain "A" is shown as a cartoon.   
 
    
 
    
   PyMOL> color pink, pept//b        # Chain "B" in object "pept"
+
   PyMOL> color pink, /pept//B      # Chain "B" in object "pept"
 
                                     # is colored pink.
 
                                     # is colored pink.
 
</pre>
 
</pre>
  
 +
== See Also ==
  
 
+
* [[Selection Algebra]]
Selection macros must contain at least one forward slash in order to distinguish them from other words in the selection language. Being words, they must not contain any spaces. When using macros, it is also important to understand that they are converted into long form before being submitted to the selection engine. This can help in the interpretation of error messages.
 
 
 
  
 
[[Category:Selector Quick Reference]]
 
[[Category:Selector Quick Reference]]
 
[[Category:Selecting|Selection Macros]]
 
[[Category:Selecting|Selection Macros]]
 +
[[Category:Coloring]]

Latest revision as of 06:19, 29 November 2017

The atom-right-click context menu title shows a selection macro

Selection Macros allow to represent a long atom selection phrase such as

PyMOL> select pept and segi lig and chain B and resi 142 and name CA

in a more compact form:

PyMOL> select /pept/lig/B/142/CA

Syntax and Semantics

An atom selection macro uses slashes to define fields corresponding to identifiers. The macro is used to select atoms using the boolean "and," that is, the selected atoms must have all the matching identifiers:

/object-name/segi-identifier/chain-identifier/resi-identifier/name-identifier
  • must contain at least one slash
  • no spaces allowed
  • empty fields are interpreted as wildcards
  • starting with a slash:
    • yes: fields from the right can be omitted
    • no: fields from the left can be omitted

Details

Macros come in two flavors: those that begin with a slash and those that don't. The presence or absence of a slash at the beginning of the macro determines how it is interpreted. If the macro begins with a slash, PyMOL expects to find the fields starting from the top of the hierarchy: the first field to the right of the slash is interpreted as an object-name; the second field as an identifier to segi; the third as an identifier to chain, and so on. It may take any of the following forms:

Macros Beginning With a Slash

  
   /object-name/segi-identifier/chain-identifier/resi-identifier/name-identifier
   /object-name/segi-identifier/chain-identifier/resi-identifier
   /object-name/segi-identifier/chain-identifier
   /object-name/segi-identifier
   /object-name


EXAMPLES
   PyMOL> zoom /pept
   PyMOL> show spheres, /pept/lig/
   PyMOL> show cartoon, /pept/lig/A
   PyMOL> color pink, /pept/lig/A/10
   PyMOL> color yellow, /pept/lig/A/10/CA

Macros Not Beginning With a Slash

If the macro does not begin with a slash, it is interpreted differently. In this case, PyMOL expects to find the fields ending with the bottom of the hierarchy. Macros that don't start with a slash may take the following forms:

                                             resi-identifier/name-identifier
                            chain-identifier/resi-identifier/name-identifier
            segi-identifier/chain-identifier/resi-identifier/name-identifier
object-name/segi-identifier/chain-identifier/resi-identifier/name-identifier


EXAMPLES
   PyMOL> zoom 10/CB
   PyMOL> show spheres, A/10-12/CB
   PyMOL> show cartoon, lig/B/6+8/C+O
   PyMOL> color pink, pept/enz/C/3/N

Omitting Fields in a Macro

You can also omit fields between slashes. Omitted fields will be interpreted as wildcards, as in the following forms:

   
   resi-identifier/
   resi-identifier/name-identifier
   chain-identifier//
   object-name//chain-identifier                

   
EXAMPLES
   PyMOL> zoom 142/                  # Residue 142 fills the viewer. 
   
   PyMOL> show spheres, 156/CA       # The alpha carbon of residue 156
                                     # is shown as a sphere     
                                     
   PyMOL> show cartoon, A//          # Chain "A" is shown as a cartoon.  
   
   PyMOL> color pink, /pept//B       # Chain "B" in object "pept"
                                     # is colored pink.

See Also