When working with a large molecular or crystal structure, selecting atoms one at a time is rarely practical. Yet many useful modeling tasks start with a geometric question: which atoms lie inside a sphere, form a patterned sheet, or belong to a custom outline? In SAMSON, coordinate-based expressions let you describe that region and apply it to atoms in the active document.
The key idea is to turn a shape into a mathematical condition. For every atom, the expression checks its coordinates; the result determines whether that atom is selected. This is useful for isolating part of a structure, preparing a region for further work, or creating a distinctive nanoscale shape from a larger sheet.
Start with a simple geometric cut
For example, this Atoms Selector expression selects atoms inside a circular region of radius 10, centered at (15, 15) in the x-y plane:
|
1 |
((a.x - 15)^2 + (a.y - 15)^2) < 100 |
The expression comes from the equation for a circle: the squared distance from the center is less than the squared radius. Because the condition does not mention a.z, atoms at any z-coordinate can match. In other words, this defines a cylinder through the structure along the z direction, not a sphere. That distinction matters when you are cutting a region from a crystal or another three-dimensional model.
To make a spherical region, include the z-distance too. For a sphere centered at (0, 0, 2) with radius 10, the corresponding condition is:
|
1 |
a.x^2 + a.y^2 + (a.z - 2)^2 < 100 |
Before applying any expression, check the coordinate values and the units used by your structure. A radius that is sensible in one length unit may be far too large or small in another.
Selection and editing are different jobs
The Atoms Selector Extension is a focused option when your goal is simply to select atoms matching a mathematical expression. It uses the same atom variables and mathematical expressions described for Simple Script, and it also accepts the keyword all to select every atom in the active document.
When you need the expression to do more than select—for instance, change atom positions, visibility, or element type—use the Simple Script Extension. It can set atom properties such as a.x, a.y, a.z, and a.visibilityFlag, as well as the selection flag. A useful habit is to decide first whether you want to identify atoms, hide atoms outside a region, or modify their properties. These are related tasks, but they are not interchangeable.
Build a custom outline from a sheet
The same coordinate-based approach can describe more intricate silhouettes. The SAMSON tutorial demonstrates selecting atoms from a graphene sheet to create nano-tiles and a Batman-inspired batarang. The shape is defined through conditions on x and y, including regions for the wings, head, and ears. A Boolean variable tracks whether each atom falls inside the outline; matching atoms are selected and made visible, while non-matching atoms are deselected and hidden.
In that example, the script first uses x := a.x / 2 and y := a.y / 2 to scale the coordinates used in the shape equations. The tutorial notes that the graphene sheet should lie in the z-plane and its positions should be at least in nanometers for those particular dimensions. The practical lesson is to keep the geometry and coordinate scale consistent: if the outline appears empty or unexpectedly large, verify the sheet orientation, coordinate range, and scaling before changing the shape equations.
Here is the resulting kind of pattern:

And the batarang example shows how several simple geometric tests can combine into one recognizable outline:

A reliable way to experiment
-
Begin with a simple region, such as a circle or sphere, and confirm that it selects the expected atoms.
-
Check the structure’s coordinate range and orientation. Expressions operate on atom coordinates as they are represented in the active document.
-
Add complexity gradually: combine conditions with
andoror, then divide the outline into understandable regions. -
If you use Simple Script to hide atoms outside a shape, remember that visibility is a change to the displayed structure. Keep a copy or otherwise preserve the original state if you may need to restore it.
This approach is not limited to novelty shapes. The same reasoning helps with practical selection tasks: define a spatial region, test which atoms satisfy it, then choose whether to select, hide, or edit those atoms. For the complete syntax, examples, and both batarang scripts, see the original SAMSON tutorial.
Note: SAMSON and all SAMSON Extensions are free for non-commercial use. Get SAMSON.
