Quickly Hide or Show Nodes in SAMSON Using NSL

Managing complex molecular scenes in SAMSON can be challenging, especially when dealing with large biomolecular assemblies or hierarchical structures. Often, molecular modelers want a quick way to hide some elements (e.g., water molecules, ligands, labels) or show only the parts of interest such as protein backbones or a specific binding site. You can do this efficiently using the Node Specification Language (NSL) with visibility-related node attributes.

This blog post introduces how to use NSL expressions to control the visibility of elements in SAMSON. We’ll explore the difference between node.visible and node.visibilityFlag, how they relate to the node hierarchy, and provide practical examples you can start using right away in your own molecular modeling projects.

Understanding Visibility in NSL

In SAMSON, each node can have a visibility flag that determines whether it is individually set to be visible or not. However, due to hierarchical structures (e.g., atoms inside residues, residues inside chains), a node might still be hidden if one of its ancestors is set to be invisible.

  • node.visibilityFlag (n.vf): Directly reflects the state of a node’s visibility flag.
  • node.visible (n.v): Indicates whether the node is actually visible in the scene, which means its visibility flag is true and all its ancestors are also visible.

This distinction helps you understand why some nodes may be technically ‘enabled’ (visibility flag is true) but are not shown in the view—you’ve probably toggled off their parent node without realizing it.

Common Use Cases

Let’s go through some helpful scenarios:

1. Select all visible nodes

This returns all nodes that are currently visible, taking into account both their own flags and those of their ancestors.

2. Select all nodes with visibility flags enabled (not necessarily visible)

This helps in identifying nodes that would be visible, if none of their ancestors were hidden.

3. Find hidden nodes

This is useful when you’re debugging why something isn’t appearing in the viewport.

4. Make sure all ligands are visible

This NSL query finds ligands that are currently hidden, allowing you to make them visible manually or through scripts.

Useful Tip: Toggling Visibility by Category

Let’s say you want to hide all water molecules:

You can use this to select all water nodes, and then manually toggle visibility for the selection.

Related Attributes

  • n.h (hidden): Indicates if a node is hidden either by its own flag or because one of its ancestors is hidden.
  • n.vf (visibility flag): The state of the node’s own flag, regardless of ancestors.

These allow you to precisely understand and control presentation elements in complex molecular systems. Understanding these small distinctions can make a big difference when preparing publication figures or sharing molecular scenes with collaborators.

To learn more about visibility and other node attributes, visit the official documentation page: https://documentation.samson-connect.net/users/latest/nsl/node/.

SAMSON and all SAMSON Extensions are free for non-commercial use. You can get SAMSON at https://www.samson-connect.net.

Comments are closed.