Filtering Node Groups by Selection State in SAMSON

If you’ve worked with complex molecular systems in SAMSON, you’ve likely faced the challenge of isolating particular groups of atoms or molecular components. This becomes especially relevant when dealing with large biomolecular assemblies or simulations with numerous nodes. One of the simplest but most effective ways to approach this is through filtering by selection state using NSL, the Node Specification Language in SAMSON.

In this post, we’ll look at how you can use the ng.selected attribute to focus on only the node groups you’ve actively selected in the SAMSON interface. This is a small but incredibly useful piece of the NSL, and a great way to simplify your selections when scripting or building workflows.

When Filtering Saves You Time

Sometimes you don’t want to loop over every component in your molecular document. You may just want to apply an action (like highlighting, transforming, or exporting) to nodes you’ve already selected. That’s where ng.selected comes in: it filters node groups based on their selection status.

How It Works

The selected attribute in the node group (ng) attribute space is inherited from the basic node.selected attribute, but note: unlike other node attributes, it does not have a short name. This makes it explicit and less error-prone in usage.

Here’s how you use it:

  • ng.selected — Matches all selected node groups
  • not ng.selected — Matches all unselected node groups

This is especially valuable in scripts or NSL-enabled features where you want to act conditionally based on whether a group was selected manually by the user.

Practical Example

Let’s say you’re assembling a visualization or exporting data for analysis. You might use:

This filters actions to only selected node groups — ideal when working interactively.

Or imagine doing cleanup:

This would apply your operation (e.g., hiding or deleting) to all node groups that were not manually chosen.

More than Just Visual Aid

Selection is often seen as a visual operation — clicking to highlight elements — but in NSL, it’s also a programmable filter. Using ng.selected effectively saves time, avoids mistakes, and keeps your workflows efficient. Whether you’re scripting tools or simply specifying subsets for analysis, this tiny attribute can make a surprising difference.

You can learn more about ng.selected (as well as other node group attributes like name and selectionFlag) from the documentation page: Node Group Attributes Documentation.

SAMSON and all SAMSON Extensions are free for non-commercial use. You can download SAMSON from www.samson-connect.net.

Comments are closed.