AtomSelectionSpec
Extends: AtomSpec
Source: specs.ts
Atom selection object. Used to specify what atoms should be selected. Can include
any field from AtomSpec in which case atoms must equal the specified value.
All fields must match for the selection to hold. Ordinary string, number, and
boolean atom fields also accept lists; only one value of each list must match.
Selection controls such as invert and byres keep their individual types.
An empty object matches all atoms. Missing atom fields do not match. Distances
are in angstroms, and spatial selections are evaluated separately within each
model. After matching fields, selection expansion is applied in the order
expand, within, then byres.
Example
$3Dmol.download("pdb:2EJ0",viewer,{},function(){
viewer.setStyle({chain:'B'},{cartoon:{color:'spectrum'}});
viewer.setStyle({chain:'B',invert:true},{cartoon:{}});
viewer.setStyle({bonds: 0},{sphere:{radius:0.5}}); //water molecules
viewer.setStyle({resn:'PMP',byres:true,expand:5},{stick:{colorscheme:"greenCarbon"}});
viewer.setStyle({resi:["91-95","42-50"]},{cartoon:{color:"green",thickness:1.0}});
viewer.render();
});Combine boolean clauses while distinguishing atom indices from residue numbers.
var model = viewer.addModel();
model.addAtoms([
{elem: "C", x: -3, y: 0, z: 0, resi: 10},
{elem: "N", x: -1, y: 0, z: 0, resi: 10},
{elem: "O", x: 1, y: 0, z: 0, resi: 20},
{elem: "S", x: 3, y: 0, z: 0, resi: 30}
]);
viewer.setStyle({}, {sphere: {radius: 0.5, color: "lightgray"}});
viewer.setStyle({model: model.getID(), and: [
{or: [{elem: "N"}, {elem: "O"}]},
{not: {resi: 20}}
]}, {sphere: {radius: 0.8, color: "orange"}});
// Only nitrogen matches: index 1, residue 10, in this model.
viewer.addLabel("Selected: index 1 / resi 10", {
useScreen: true, position: {x: 12, y: 20, z: 0},
fontSize: 14, fontColor: "black", showBackground: false
});
viewer.zoomTo();
viewer.render();Spatial selections stay within each model, even when models overlap.
var first = viewer.addModel();
first.addAtoms([
{elem: "C", x: -2, y: 0, z: 0},
{elem: "O", x: -0.4, y: 0, z: 0},
{elem: "N", x: 2, y: 0, z: 0}
]);
var second = viewer.addModel();
second.addAtoms([{elem: "N", x: -2, y: 1.5, z: 0}]);
viewer.setStyle({}, {sphere: {radius: 0.4, color: "lightgray"}});
viewer.setStyle({model: second}, {sphere: {radius: 0.4, color: "green"}});
viewer.setStyle({elem: "C"}, {sphere: {radius: 0.5, color: "black"}});
// Oxygen is near carbon in the first model; the green atom belongs to another model.
viewer.setStyle({within: {distance: 2, sel: {elem: "C"}}},
{sphere: {radius: 0.65, color: "orange"}});
// expand includes the carbon seed as well as the nearby oxygen, but not the green atom.
viewer.addStyle({elem: "C", expand: 2}, {cross: {radius: 0.9, color: "royalblue"}});
viewer.addLabel("within: orange; expand: blue crosses", {
useScreen: true, position: {x: 12, y: 20, z: 0},
fontSize: 12, fontColor: "black", showBackground: false
});
viewer.zoomTo();
viewer.render();Instance Fields
and: Array | object
take the intersection of the provided lists of AtomSelectionSpecs
Properties
___cached_results(any, optional)
atom: string
Inherited from AtomSpec#atom
Atom name; may be more specific than 'elem' (e.g 'CA' for alpha carbon)
b: number
Inherited from AtomSpec#b
Atom b factor data
bondOrder: Array
Inherited from AtomSpec#bondOrder
Array of this atom's bond orders, corresponding to the atom indices in 'bonds'
bondStyles: Array
Inherited from AtomSpec#bondStyles
custom bond styling by position in bonds
bonds: number
Overrides: AtomSpec#bonds
overloaded to select number of bonds, e.g. {bonds: 0} will select all nonbonded atoms
byres: boolean
If present, expand through bonds to atoms with the same chain and residue number as selected atoms. Omit this field to disable residue expansion.
callback: function
Inherited from AtomSpec#callback
Click handler receiving the atom, viewer, mouse or touch event, viewer container, and intersections sorted nearest first.
chain: string
Inherited from AtomSpec#chain
Chain this atom belongs to, if specified in input file (e.g 'A' for chain A)
clickable: boolean
Inherited from AtomSpec#clickable
Set this flag to true to enable click selection handling for this atom
color: ColorSpec
Inherited from AtomSpec#color
Atom's color, as hex code or built-in color string
elem: string
Inherited from AtomSpec#elem
Element abbreviation (e.g. 'H', 'Ca', etc)
expand: number | string
Expand the selection by a distance in angstroms within the same model.
frame: number
For setStyle, select a loaded frame to style; otherwise styles apply to all loaded frames. Does not change the frame queried by selectedAtoms; use setFrame for that.
hetflag: boolean
Inherited from AtomSpec#hetflag
Set to true if atom is a heteroatom
hover_callback: function
Inherited from AtomSpec#hover_callback
Hover handler receiving the atom, viewer, mouse or touch event, viewer container, and intersections sorted nearest first.
hoverable: boolean
Inherited from AtomSpec#hoverable
Set this flag to true to enable hover selection handling for this atom
index: number | Array
Overrides: AtomSpec#index
index of the atom or atoms to select
invert: boolean
Overrides: AtomSpec#invert
if set, inverts the meaning of the selection
lchain: string
Inherited from AtomSpec#lchain
Label chain (not author)
lresi: number
Inherited from AtomSpec#lresi
Label residues number (not author)
lresn: string
Inherited from AtomSpec#lresn
Residue label name
model: GLModel | number | Array | Array
A model object or model ID, or an array of either. IDs are returned by GLModel.getID(). A single negative number counts back from the next model ID (-1 is the most recently assigned ID); removed models leave gaps.
not: AtomSelectionSpec
take the inverse of the provided AtomSelectionSpec
or: Array | object
take the union of the provided lists of AtomSelectionSpecs
Properties
___cached_results(any, optional)
pdbline: string
Inherited from AtomSpec#pdbline
If applicable, this atom's record entry from the input PDB file (used to output new PDB from models)
predicate: function
user supplied function that gets passed an AtomSpec and should return true if the atom should be selected
properties: Record.<string, any>
Inherited from AtomSpec#properties
Additional data such as charge or custom numeric properties. Property coloring checks this mapping before top-level atom fields.
resi: number | SelectionRange | Array
Overrides: AtomSpec#resi
overloaded to allow ranges and lists of residues, e.g. {resi: "5-10"} or {resi: [5,10,32]}
resn: string
Inherited from AtomSpec#resn
Parent residue name
serial: number
Inherited from AtomSpec#serial
Atom's serial id number
singleBonds: boolean
Inherited from AtomSpec#singleBonds
true if this atom forms only single bonds or no bonds at all
ss: string
Inherited from AtomSpec#ss
Secondary structure identifier (for cartoon render; e.g. 'h' for helix)
style: AtomStyleSpec
Inherited from AtomSpec#style
style of atom
surfaceColor: ColorSpec
Inherited from AtomSpec#surfaceColor
Hex code for color to be used for surface patch over this atom
unhover_callback: function
Inherited from AtomSpec#unhover_callback
Unhover handler with the same arguments as the hover handler.
The event and intersections can be undefined when hover is cleared.
within: WithinSelectionSpec
intersects the selection with the set of atoms within a given distance from another selection
x: number
Inherited from AtomSpec#x
Atom's x coordinate
y: number
Inherited from AtomSpec#y
Atom's y coordinate
z: number
Inherited from AtomSpec#z
Atom's z coordinate