This is a read-only mirror of pymolwiki.org

Difference between revisions of "Selection Algebra"

From PyMOL Wiki
Jump to navigation Jump to search
 
(→‎Selection Operator/Modifier Table: Added "bycell" selection syntax)
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
Selections can be made more precise or inclusive by combining them with logical operators, including the boolean '''and''', '''or''', and '''not'''. The boolean '''and''' selects only those items that have both (or all) of the named properties, and the boolean '''or''' selects items that have either (or any) of them. Venn diagrams show that '''and ''' selects the areas of overlap, while '''or''' selects both areas.  
 
Selections can be made more precise or inclusive by combining them with logical operators, including the boolean '''and''', '''or''', and '''not'''. The boolean '''and''' selects only those items that have both (or all) of the named properties, and the boolean '''or''' selects items that have either (or any) of them. Venn diagrams show that '''and ''' selects the areas of overlap, while '''or''' selects both areas.  
  
http://pymol.sourceforge.net/newman/user/S0220venn.jpg
+
See [http://pymol.sourceforge.net/newman/user/S0220venn.jpg simple logic Venn diagram].
 
 
  
 
===Selection Operator/Modifier Table===
 
===Selection Operator/Modifier Table===
Line 55: Line 54:
 
<TD ALIGN="CENTER">br.<I> s</I>1</TD><TD>Expands selection to complete residues
 
<TD ALIGN="CENTER">br.<I> s</I>1</TD><TD>Expands selection to complete residues
 
<pre>PyMOL> select complete_res, br. bbnear10</pre>
 
<pre>PyMOL> select complete_res, br. bbnear10</pre>
 +
</TD></TR>
 +
<TR><TD ALIGN="CENTER">bymolecule<I> s</I>1</TD>
 +
<TD ALIGN="CENTER">bm.<I> s</I>1</TD><TD>Expands selection to complete molecules
 +
<pre>PyMOL> select complete_res, bm. bbnear10</pre>
 +
</TD></TR>
 +
<TR><TD ALIGN="CENTER">byfragment<I> s</I>1</TD>
 +
<TD ALIGN="CENTER">bf.<I> s</I>1</TD><TD>Expands selection to complete fragments
 +
<pre>PyMOL> select complete_res, bf. bbnear10</pre>
 +
</TD></TR>
 +
<TR><TD ALIGN="CENTER">bysegment<I> s</I>1</TD>
 +
<TD ALIGN="CENTER">bs.<I> s</I>1</TD><TD>Expands selection to complete segments
 +
<pre>PyMOL> select complete_res, bs. bbnear10</pre>
 
</TD></TR>
 
</TD></TR>
 
<TR><TD ALIGN="CENTER">byobject<I> s</I>1</TD>
 
<TR><TD ALIGN="CENTER">byobject<I> s</I>1</TD>
 
<TD ALIGN="CENTER">bo.<I> s</I>1</TD><TD>Expands selection to complete objects>
 
<TD ALIGN="CENTER">bo.<I> s</I>1</TD><TD>Expands selection to complete objects>
 
<pre>PyMOL> select near_obj, bo. near_res</pre>
 
<pre>PyMOL> select near_obj, bo. near_res</pre>
 +
</TD></TR>
 +
<TR><TD ALIGN="CENTER">bycell<I> s</I>1</TD>
 +
<TD ALIGN="CENTER">???<I> s</I>1</TD><TD>Expands selection to unit cell>
 +
<pre>PyMOL> select complete_cell, bycell orig_res</pre>
 
</TD></TR>
 
</TD></TR>
 
<TR><TD ALIGN="CENTER">neighbor<I> s</I>1</TD>
 
<TR><TD ALIGN="CENTER">neighbor<I> s</I>1</TD>
Line 72: Line 87:
 
===Examples===
 
===Examples===
 
Logical selections can be combined. For example, you might select atoms that are part of chain a, but not residue number 125:
 
Logical selections can be combined. For example, you might select atoms that are part of chain a, but not residue number 125:
     
+
<source lang="python">
<pre>
+
# selects atoms that are part of chain a, but not residue number 125.
  PyMOL> select chain a and (not resi 125)      # selects atoms that are part of
+
PyMOL> select chain a and (not resi 125)
                                                # chain a, but not  
 
                                                # residue number 125.
 
  
  PyMOL> select (name cb or name cg1 or name cg2) and chain A   # These two
+
# The following two selections are equivalent,
                                                                  # selections are
+
PyMOL> select (name cb or name cg1 or name cg2) and chain A
  PyMOL> select name cb+cg1+cg2 and chain A                      # equivalent.
+
 
                                                                  # select c-beta's,
+
# select c-beta's, c-gamma-1's and c-gamma-2's  
                                                                  # c-gamma-1's and  
+
# that are in chain A.
                                                                  # c-gamma-2's  
+
PyMOL> select name cb+cg1+cg2 and chain A                     
                                                                  # that are  
+
</source>
                                                                  # in chain A.
 
</pre>
 
  
 
Like the results of groups of arithmetic operations, the results of groups of logical operations depend on which operation is performed first. They have an order of precedence. To ensure that the operations are performed in the order you have in mind, use parentheses:
 
Like the results of groups of arithmetic operations, the results of groups of logical operations depend on which operation is performed first. They have an order of precedence. To ensure that the operations are performed in the order you have in mind, use parentheses:
  
<pre>   byres ((chain a or (chain b and (not resi 125))) around 5) </pre>
+
<source lang="python">byres ((chain a or (chain b and (not resi 125))) around 5)</source>
  
 
PyMOL will expand its logical selection out from the innermost parentheses.
 
PyMOL will expand its logical selection out from the innermost parentheses.
Line 96: Line 107:
  
 
[[Category:Selector Quick Reference]]
 
[[Category:Selector Quick Reference]]
 
 
[[Category:Selecting|Selection Algebra]]
 
[[Category:Selecting|Selection Algebra]]

Revision as of 21:36, 30 June 2009

Selection Algebra

Intro

Selections can be made more precise or inclusive by combining them with logical operators, including the boolean and, or, and not. The boolean and selects only those items that have both (or all) of the named properties, and the boolean or selects items that have either (or any) of them. Venn diagrams show that and selects the areas of overlap, while or selects both areas.

See simple logic Venn diagram.

Selection Operator/Modifier Table

Selection operators and modifiers are listed below. The dummy variables s1 and s2 stand for selection-expressions such as "chain a" or "hydro."

OperatorShort form Effect
nots1 !s1 Selects atoms that are not included in s1
PyMOL> select sidechains, ! bb
s1 and s2 s1 & s2 Selects atoms included in both s1 and s2
PyMOL> select far_bb, bb &farfrm_ten
s1 or s2 s1 | s2Selects atoms included in either s1 or s2
PyMOL> select all_prot, bb | sidechain
s1 in s2 s1 in s2Selects atoms in s1 whose
identifiers name, resi, resn, chain and segi all match atoms in s2
PyMOL> select same_atms, pept in prot
s1 like s2 s1 l. s2Selects atoms in s1 whose identifiers name and resi match atoms in s2
PyMOL> select similar_atms, pept like prot
s1 gap X s1 gap XSelects all atoms whose van der Waals radii are separated from the van der Waals radii of s1 by a minimum of X Angstroms.
PyMOL> select farfrm_ten, resi 10 gap 5
s1 around X s1 a. XSelects atoms with centers within X Angstroms of the center of any atom in s1
PyMOL> select near_ten, resi 10 around 5
s1 expand X s1 e. XExpands s1 by all atoms within X Angstroms of the center of any atom in s1
PyMOL> select near_ten_x, near10 expand 3
  s1 within X of s s1 w. X of sSelects atoms in s1 that are within X Angstroms of the s2
PyMOL> select bbnearten, bb w. 4 of resi 10
byres s1 br. s1Expands selection to complete residues
PyMOL> select complete_res, br. bbnear10
bymolecule s1 bm. s1Expands selection to complete molecules
PyMOL> select complete_res, bm. bbnear10
byfragment s1 bf. s1Expands selection to complete fragments
PyMOL> select complete_res, bf. bbnear10
bysegment s1 bs. s1Expands selection to complete segments
PyMOL> select complete_res, bs. bbnear10
byobject s1 bo. s1Expands selection to complete objects>
PyMOL> select near_obj, bo. near_res
bycell s1 ??? s1Expands selection to unit cell>
PyMOL> select complete_cell, bycell orig_res
neighbor s1 nbr. s1Selects atoms directly bonded to s1
PyMOL> select vicinos, neighbor resi 10
s1 extend X s1 ? XExtends s1 by X bonds connected to atom in s1
PyMOL> select connect_x, near10 extend 3

Examples

Logical selections can be combined. For example, you might select atoms that are part of chain a, but not residue number 125:

# selects atoms that are part of chain a, but not residue number 125.
PyMOL> select chain a and (not resi 125)

# The following two selections are equivalent, 
PyMOL> select (name cb or name cg1 or name cg2) and chain A

# select c-beta's, c-gamma-1's and c-gamma-2's 
# that are in chain A.
PyMOL> select name cb+cg1+cg2 and chain A

Like the results of groups of arithmetic operations, the results of groups of logical operations depend on which operation is performed first. They have an order of precedence. To ensure that the operations are performed in the order you have in mind, use parentheses:

byres ((chain a or (chain b and (not resi 125))) around 5)

PyMOL will expand its logical selection out from the innermost parentheses.