Node Specification Language#
SAMSON has a powerful Node Specification Language (NSL) that may be used to select data graph nodes based on their properties. For example, the Find command of the user interface of SAMSON lets users enter a NSL string to select nodes from the data graph.
Internally, SAMSON converts a NSL string into a node predicate (SBNodePredicate
) that may be passed to the getNodes function of SBDDataGraphNode
. Developers may choose to collect nodes from the data graph either from a NSL string or from a constructed node predicate (SBNodePredicate
).
NSL expressions may be used to find nodes in SAMSON (press Ctrl/Cmd + F) or in the SDK with the makeNodePredicate function.
See also
See User guide: Node Specification Language for more information.
For developers, the NSL relies on the SBCFunctor library, to manage functors and predicates. These may be used to e.g. search the data graph:
// find all atoms with temperature factor > 1.0
SBNodeIndexer nodeIndexer;
SAMSON::getActiveDocument()->getNodes(nodeIndexer,
SBNode::IsType(SBNode::Atom) && (SBAtom::GetTemperatureFactor() > 1.0));
You can also use an NSL string directly to retrieve nodes from the active document:
// Select all residue nodes from the active document
// that are within 4 angstrom of any sulfur atom.
// Note: the selection string may be abbreviated to "n.t r w 4A of S"
SBNodeIndexer nodeIndexer;
SAMSON::getNodes(nodeIndexer, "node.type residue within 4A of S");
Or you can create a node predicate from an NSL string. Note that in this case the ownership of the predicate is passed to the caller, who should delete the predicate when it's done using it.
// Make a predicate that is true if and only if
// the node is a hydrogen atom bonded to an oxygen atom.
// Note: the selection string may be abbreviated to "H l O"
SBNodePredicate* nodePredicate = SAMSON::makeNodePredicate("H linking O");
Please, refer to Getting nodes to learn more how to use the Node Specification Language to collect nodes.
See also