One Filter to Rule Them All: How to Use the Selection Flag in SAMSON

When building complex molecular models, it’s easy to get lost in the sea of atoms, molecules, surfaces, and properties. You may wonder: How do I quickly filter what I’ve selected? Or reliably identify selection states within my model? This is where the selectionFlag attribute in SAMSON’s Node Specification Language (NSL) becomes an incredibly useful tool.

Whether you’re scripting workflows, developing extensions, or simply trying to navigate large models more easily, understanding how selectionFlag works can make your life a lot easier. Let’s dive into what this flag does, how it differs from related concepts like selected, and how to use it effectively.

What is the selectionFlag?

The selectionFlag attribute, exposed under the short name sf in the propertyModel namespace, indicates whether a given property model node has been selected using the graphical interface—or programmatically—but the key point is that it checks the node’s internal flag, independent of whether the node currently appears selected in the UI.

In practical terms, this means pm.sf is useful for querying selection states in the dataset itself, especially during scripting or when building workflows driven by selection criteria.

The Difference Between selected and selectionFlag

At first glance, pm.selected and pm.sf might seem redundant. But here’s the difference:

  • pm.selected checks if the node is currently selected, as seen in the UI.
  • pm.sf queries the internal selection state flag. This doesn’t always align with what’s visually selected—especially after scripting operations.

Imagine this scenario: you’ve just run a script that selects a subset of atoms, but then change the visual selection for something else. selected wouldn’t match anymore, but sf would still reflect the earlier selection state. That’s why selectionFlag is much more dependable in workflows where consistency of selection logic matters.

Using selectionFlag in Practice

Here’s how you can query or exclude nodes based on selection flag:

  • pm.sf — finds all nodes whose selection flag is true.
  • pm.sf false — finds all nodes whose selection flag is false.

This can be particularly useful in cases like:

  • Applying a material only to the selected part of a model: pm.sf true and pm.hm false — select property model nodes that were flagged by a previous selection but don’t yet have a material.
  • Cleaning up temporary selections: not pm.sf — get all nodes that weren’t part of the working selection.

Why It Matters

In large molecular systems or when working with simulation data, precision and automation are critical. You may need to script actions like hiding specific regions, highlighting selected channels, or tagging a filtered subset. Using selectionFlag ensures you’re targeting the correct nodes without having to second-guess the UI. This is especially useful when working with views, selections, or macros that outlive a single visual session.

Conclusion

If you’re new to NSL or want to go beyond point-and-click, selectionFlag is a small but powerful attribute that gives you programmatic confidence in your selections. It’s a valuable part of your toolbox when working in SAMSON, especially for workflows that involve scripting and repeatability.

To learn more about the available attributes for property model nodes in NSL, including examples and additional use cases, explore the full documentation page here.

SAMSON and all SAMSON Extensions are free for non-commercial use. You can get SAMSON here.

Comments are closed.