In molecular modeling, selecting the right things – atoms, groups, visual representations – is part of almost every workflow. But when working in complex models in SAMSON, especially with presentation nodes, it’s easy to think you’ve selected something when you haven’t – or worse, modify things unintentionally.
That’s where the selectionFlag attribute of presentation nodes becomes important. This blog post explains what it is, why it can help you manage selections better, and how to use it efficiently in your NSL (Node Specification Language) queries.
Understanding the problem 🔍
Let’s say you’ve selected a few visual styles in your molecular model – maybe cartoons for proteins or ball-and-stick for ligands. But when you try to run a script or perform an operation, it doesn’t behave as expected. You may be selecting actual molecules and their atoms, but not their presentations (the visual nodes that define how they look) – or vice versa.
This often happens because presentation nodes and their selection states are managed separately from the molecular data nodes.
Enter selectionFlag
In SAMSON, presentation nodes have an attribute called selectionFlag, accessible in NSL by pr.sf. This allows you to query and filter based on whether a visual representation is flagged as selected – even if the node isn’t strictly selected in the usual sense.
Here’s what you need to know:
pr.sf truematches presentation nodes with the selection flag set.pr.sf falsematches those without it.
Practical example
For example, if you only want to adjust the visibility of selected visual nodes (e.g. hide all selected cartoons):
pr.sf true and pr.vf true
This targets visual nodes that are highlighted (have the selection flag) and are currently visible.
If you want to deselect all visual presentation nodes that are selected by mistake, this command could be used in a script that resets their selection flags.
Why not just use selected?
The selected keyword (e.g., pr.selected) tests whether the node is selected in the workspace. But selectionFlag is more flexible: it lets you flag (and unflag) nodes efficiently without altering the actual selection state visible to users. This is useful in automation and scripting workflows when batch-processing visual nodes or syncing them with molecular selections.
A tip for large models
In complex scenes with hundreds of visual styles, using pr.sf in your filters helps avoid graphical clutter and potential mistakes. For example:
pr.sf true and not pr.vf
The above query lets you identify selection-flagged visual nodes that are currently invisible, which can help debug rendering issues.
Related attributes
Pair selectionFlag with other useful presentation attributes like:
pr.vorpr.vf: to manage visibility.pr.h: to test if the presentation node is hidden.
These can be combined to write precise NSL expressions that reduce mistakes when toggling, hiding, replacing or exporting parts of your model.
Summary
For anyone using SAMSON regularly, adding selectionFlag to your toolbox gives clearer control over how visual representations respond to selection-based workflows. It’s a subtle distinction, but in practice, essential to avoid applying actions to the wrong things – or wondering why nothing is happening at all. 🧬
To learn more about presentation node attributes and how to use them in NSL, check the official documentation page.
SAMSON and all SAMSON Extensions are free for non-commercial use. You can get SAMSON at https://www.samson-connect.net.
