Whether you’re preparing a simulation, cleaning up atomic structures, or designing nanoscale materials, selectively hiding, showing, or modifying atoms can be tedious if done manually. SAMSON, the integrative molecular design platform, comes with a powerful toolset that simplifies this process: the Simple Script and Atoms Selector Extensions.
In this post, we’ll explore how you can programmatically control which atoms are visible, selected, or modified using simple mathematical expressions. This saves researchers time and enhances precision, especially when working with large or complex molecular systems.
Why scripting selections matters
Imagine you’re analyzing a complex structure: a protein-ligand complex, a graphene sheet, or a quantum dot. You want to highlight atoms of interest—perhaps those inside a specific region of space, or atoms of a certain element or charge. Doing this manually might take hours. Using SAMSON’s scripting capabilities, it takes seconds.
Working with visibility and selection
The Simple Script Extension allows atomic-level scripting using a structured and readable syntax, very similar to C. You can assign values, use logical expressions, and even loop over atoms to apply transformations or filters.
Let’s say you want to show only atoms located within a sphere of radius 10 Å centered at (0, 0, 2):
|
1 2 3 4 |
if ((a.x^2 + a.y^2 + (a.z - 2)^2) < 100) a.visibilityFlag := 1; else a.visibilityFlag := 0; |
This simple conditional ensures that only atoms within the sphere remain visible.
Or suppose you want to only select atoms with both x and y coordinates greater than 0. You can write:
|
1 2 3 4 |
if (a.x > 0 and a.y > 0) n.selectionFlag := 1; else n.selectionFlag := 0; |
Using a ternary operator for a more compact version:
|
1 |
((a.x > 0) and (a.y > 0)) ? n.sf := 1 : n.sf := 0; |
A faster alternative: Atoms Selector
For even quicker selections, the Atoms Selector Extension lets you specify just a single expression without writing a full script. For example, to select all atoms within a 10 Å cylinder centered at (15, 15):
|
1 |
((a.x - 15)^2 + (a.y - 15)^2) < 100 |
This instantly isolates the desired region.

Use case: Custom visibility for zoomed-in analyses
Combining both extensions gives even more power. You might select atoms with one tool, then hide everything unselected using a script, for example:
|
1 2 3 4 |
if (n.sf == 1) a.vf := 1; else a.vf := 0; |
This is ideal when preparing images, presentations, or narrowing down the data inputs for simulations.
Conclusion
Direct scripting of selection and visibility criteria in SAMSON makes atomic manipulation efficient and reproducible. Whether you’re cleaning a structure, isolating features, or customizing visualizations, these scripting tools are a valuable addition to your molecular modeling workflow.
To learn more or discover more scripting capabilities, visit the official documentation page: Making Nano-batarangs (and more).
SAMSON and all SAMSON Extensions are free for non-commercial use. You can download SAMSON at www.samson-connect.net.
