Selection Algebra: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
(byring)
(examples: ignore_case=0 compatible)
Line 177: Line 177:
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">
<source lang="python">
# selects 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.
select chain a and (not resi 125)
select chain A and (not resi 125)


# The following two selections are equivalent,  
# The following two selections are equivalent,  
select (name cb or name cg1 or name cg2) and chain A
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  
# select c-beta's, c-gamma-1's and c-gamma-2's  
# that are in chain A.
# that are in chain A.
select name cb+cg1+cg2 and chain A
select name CB+CG1+CG2 and chain A


# select all residues within 5 Ang. or any organic small molecules
# select all residues within 5 Ang. or any organic small molecules
Line 191: Line 191:


# select helices
# select helices
select ss 'h'
select ss 'H'


# select anything shown as a line
# select anything shown as a line
Line 203: Line 203:


# select the 1st arginine
# select the 1st arginine
select first resn arg
select first resn ARG


# select 1foo's segment G's chain X's residue 444's alpha carbon
# select 1foo's segment G's chain X's residue 444's alpha carbon
Line 219: Line 219:
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:


<source lang="python">byres ((chain a or (chain b and (not resi 125))) around 5)</source>
<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.

Revision as of 08:21, 20 April 2016


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."

Operator Short Form Effect
not s1 !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 s2 Selects atoms included in either s1 or s2.
PyMOL> select all_prot, bb | sidechain
s1 in s2 s1 in s2 Selects 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. s2 Selects atoms in s1 whose identifiers name and resi match atoms in s2.
PyMOL> select similar_atms, pept like prot
s1 gap X Selects 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. X Selects atoms with centers within X Angstroms of the center of any atom ins1.
PyMOL> select near_ten, resi 10 around 5
s1 expand X s1 x. X Expands s1 by all atoms within X Angstroms of the center of any atom in s1.
PyMOL> select near_ten_x, near_ten expand 3
s1 within X of s2 s1 w. X of s2 Selects atoms in s1 that are within X Angstroms of any atom in s2.
PyMOL> select bbnearten, bb w. 4 of resi 10
s1 near_to X of s2 s1 nto. X of s2 Same as within, but excludes s2 from the selection (and thus is identical to s1 and s2 around X).
s1 beyond X of s2 s1 be. X of s2 Selects atoms in s1 that are at least X Anstroms away from s2.
byres s1 br. s1 Expands selection to complete residues.
PyMOL> select complete_res, br. bbnear10
bymolecule s1 bm. s1 Expands selection to complete molecules.
PyMOL> select complete_mol, bm. bbnear10
byfragment s1 bf. s1 Expands selection to complete fragments.
PyMOL> select complete_frag, bf. bbnear10
bysegment s1 bs. s1 Expands selection to complete segments.
PyMOL> select complete_seg, bs. bbnear10
byobject s1 bo. s1 Expands selection to complete objects.
PyMOL> select near_obj, bo. near_res
bycell s1 Expands selection to unit cell.
PyMOL> select complete_cell, bycell orig_res
byring s1 New in 1.8.2: All rings of size ≤ 7 which have at least one atom in s1
PyMOL> select rings, byring (all)
neighbor s1 nbr. s1 Selects atoms directly bonded to s1, excludes s1.
PyMOL> select vicinos, neighbor resi 10
bound_to s1 bto. s1 Selects atoms directly bonded to s1, may include s1.
s1 extend X s1 xt. X Extends s1 by X bonds connected to atoms in s1.
PyMOL> select connect_x, near10 extend 3
pepseq SEQ ps. SEQ Selects peptide sequence matching upper-case one-letter sequence SEQ (see also FindSeq).
PyMOL> select 1tvn and ps. FATEW
rep rep Selects atoms which show representation rep.
PyMOL> select sele, rep spheres

Comparison of distance operators

There are serveral very similar operators that select by pairwise atom distances. The following table lists the details how they differ.

Syntax 1: s1 operator X of s2
Syntax 2: s1 and (s2 operator X)

operator distance is ... measured from includes s2 syntax notes
near_to ≤ X center never 1 equivalent to "around"
within ≤ X center if matches s1 1
beyond > X center never 1
gap > X center+vdw never 2
around ≤ X center never 2 equivalent to "near_to"
expand ≤ X center always 2

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.
select chain A and (not resi 125)

# The following two selections are equivalent, 
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.
select name CB+CG1+CG2 and chain A

# select all residues within 5 Ang. or any organic small molecules
select br. all within 5 of organic

# select helices
select ss 'H'

# select anything shown as a line
select rep lines

# select all residues with a b-factor less than 20, within 3 angstroms of any water
select br. b<20 & (all within 3 of resn HOH)

# select anything colored blue
select color blue

# select the 1st arginine
select first resn ARG

# select 1foo's segment G's chain X's residue 444's alpha carbon
select 1foo/G/X/444/CA
# same thing
select 1foo and segi G and c. X and i. 444 and n. CA

# select the entire object that residue 23's beta caron is in:
select bo. i. 23 and n. CA

# select the molecule that chain C is in
select bm. c. C

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.

See Also

Single-word Selectors, Selection Macros, Property_Selectors, Identify