When working with molecular systems at scale, manually selecting elements within a complex model is not only time-consuming—it can sometimes be nearly impossible. Whether you’re preparing a system for simulation, applying materials, or isolating specific elements programmatically, accessing selections via scripting gives you speed and precision.
In the SAMSON molecular design platform, the selectionFlag attribute of property model nodes provides an efficient solution to this challenge.
What is a selection flag?
The selectionFlag attribute—abbreviated as sf when used in the propertyModel (pm) attribute space—tells you whether or not a specific node is flagged as selected. This can be particularly useful in batch operations or when writing selectors in the Node Specification Language (NSL).
Why not just use selected?
The selected attribute also exists, and it looks quite similar. However, understanding the distinction between selected and selectionFlag can save you from confusion:
selectedis a final condition—it tells you whether the node is selected after all selection flags and logic have been computed.selectionFlag(pm.sf) reflects whether a node is candidate for selection—before the actual selection state is finalized.
In other words, pm.sf gives you more granular control in scripts where complex selection logic is being applied. It’s like toggling a checkbox in your code without necessarily applying it immediately.
Practical use cases
If you’re scripting a workflow and want to exclude certain property model nodes from a bulk operation based on visibility or naming patterns, selectionFlag becomes essential. Here’s an example:
|
1 2 |
// Select all visible property models starting with 'L' that are not flagged for selection yet: pm.vf true and pm.n "L*" and not pm.sf |
This expression combines three attributes:
pm.vf trueensures the visibility flag is onpm.n "L*"selects nodes with IDs starting with “L”not pm.sffilters out already-flagged nodes
Using this kind of logic, you could dynamically pre-select or exclude nodes prior to executing transformations or simulations.
Setting the flag in code
In custom Python scripts or C++ extensions, you can modify the selection flag directly to automate user interactions, which becomes very helpful in large molecular environments.
For example, in Python bindings (via SAMSON’s scripting interface), you might use something like:
|
1 |
node.setSelectionFlag(True) |
Visual confirmation
Keep in mind that setting the selectionFlag does not always provide immediate visual feedback if the final selected attribute hasn’t been updated. But it does mark the node for selection in operations downstream—similar to queueing in a staging area.
Conclusion
Whether you’re scripting cleaner selection conditions or controlling how parts of your molecular system interact, using pm.sf gives you lower-level control. It’s especially handy when applied in combination with filters based on node names and visibility.
To learn more about the selectionFlag attribute and the broader property model attribute space, refer to the official documentation here: https://documentation.samson-connect.net/users/latest/nsl/propertyModel/
SAMSON and all SAMSON Extensions are free for non-commercial use. Get SAMSON here.
