Stop selecting the wrong nodes: a practical NSL workflow for molecular models

Large molecular models make a simple task surprisingly fiddly: finding the atoms, residues, or structural groups you actually want. A broad search can return several kinds of nodes at once, while a query using not may include folders or other unrelated objects. SAMSON’s Node Specification Language (NSL) helps you make selections more precise—but the key is to define both what you want and what kind of node should be returned.

NSL expressions can be entered in Select > Find or in the filter box in the Document view. Find is useful for creating a selection from a query; the Document view is convenient when you want to filter the hierarchy and select matching nodes there.

Selecting nodes with the Find command
Enter an NSL expression in Find to select matching nodes in the active document.

Start by choosing the node type

A molecular document contains more than atoms. It can also contain residues, bonds, chains, structural groups, and other nodes. If a query should return atoms, make that scope explicit with node.type atom (short form: n.t a). For residues, use node.type residue (short form: n.t r).

This matters especially with exclusions. For example, not residue.type CYS does not mean “all residues except cysteine”: it can also match nodes that are not cysteine residues, including folders. To return non-cysteine residues, combine the desired type with the exclusion:

node.type residue and not residue.type CYS

The same principle applies whenever a query uses not: first define the universe of nodes you want, then exclude from it.

Build a selection in small steps

Think of an NSL expression as a short description of a selection. Start with the target type, add a property, and then refine with an operator. For example:

  • node.type residue finds residue nodes.
  • residue.id 20:40, 50:60 specifies two ranges of residue IDs.
  • node.type residue and not residue.type ALA specifies residues while excluding alanine.
  • Carbon in node.selected finds carbon atoms in the current selection.

NSL also accepts concise forms, such as n.t r for node.type residue and r.id for residue.id. The full names can be easier to read while learning; the short forms are handy once you recognize them.

Use names and distance carefully

Quoted names are useful when you know the name of a node. A quoted string without wildcards is an exact match, so "ALA 22" matches that full name. For a simple pattern, use glob wildcards: * matches zero or more characters and ? matches exactly one. For example, "*Backbone" matches names ending in “Backbone.” Pressing Tab in the Find search box can also suggest matching names as you type.

Distance queries are useful for exploring a local environment. For example, "CA" within 5A of S finds nodes named “CA” within five angstroms of sulfur atoms. But proximity can match a larger structural node if one of its atoms is close to the target. To ask specifically for atoms, scope the query: node.type atom within 5A of "GLN 2". This includes atoms belonging to GLN 2 itself. To exclude that group, add out of:

node.type atom within 5A of "GLN 2" out of "GLN 2"

Filtering and selecting nodes in the Document view
Use an NSL expression in the Document view to filter nodes, then press Enter to select them.

A quick troubleshooting checklist

  • Too many kinds of results? Add a node-type condition such as n.t a or n.t r.
  • Names contain spaces? Put the name in quotes.
  • Need a range? Use a colon, as in r.id 20:40.
  • Using not? Pair it with a positive type condition to keep the results focused.
  • Using distance? Specify the result node type, and decide whether to include or exclude the reference group.

These habits turn NSL from a collection of search tricks into a repeatable way to make selections that are easier to understand and verify. For the complete syntax and more examples, see the SAMSON Node Specification Language documentation.

Note: SAMSON and all SAMSON Extensions are free for non-commercial use. Get SAMSON.

Comments are closed.