From coordinates to custom shapes: a practical way to select atoms

Large molecular structures are difficult to edit atom by atom. If you need a region with a particular shape—a sphere, cylinder, tile, or even a graphene silhouette—manual clicking can be slow and imprecise. A more repeatable approach is to describe the region mathematically and let SAMSON evaluate the condition for each atom.

The key idea is simple: use each atom’s coordinates, a.x, a.y, and a.z, in an expression that is true for atoms inside the shape you want. This turns a geometric boundary into a selection rule you can reuse or adjust.

Start with a familiar shape

For a sphere of radius 10 centered at (0, 0, 2), the squared distance from an atom to the center is a.x^2 + a.y^2 + (a.z - 2)^2. Comparing that distance with the squared radius, 100, gives the condition for being inside the sphere:

This expression is useful because it makes the geometry explicit: change the center coordinates to move the sphere, or change 100 to adjust its radius squared. The Simple Script example applies the same test by setting an atom’s visibility flag to 1 inside the sphere and 0 outside. That hides atoms outside the region; it does not itself delete them.

Use a selector when selection is all you need

If your goal is only to select atoms according to a mathematical condition, the Atoms Selector Extension accepts an expression directly. For example, to select atoms inside a cylinder of radius 10 centered at (15, 15) in the x-y plane:

There is no z-coordinate in this test, so the condition describes a cylinder extending along the z direction, rather than a sphere. This distinction is easy to miss when adapting a formula: include every coordinate that should limit the shape, and leave out coordinates along which it should extend.

Selecting a cylindrical region from a quartz crystal

Make the coordinate system work for you

Before running a coordinate-based rule, check where the structure sits and which length units are active. The same radius value will select a different physical region if the model’s coordinates use different units. The batarang example in the tutorial scales x and y by dividing them by 2, and notes that the positions should be at least in nanometers. That scaling makes its shape inequalities easier to express, but it also means the coordinates in the script are not being used directly.

A useful habit is to test a simple condition first—for example, select atoms with positive x and y coordinates—and inspect the result. Then add the shape boundary or adjust its center and size. This helps catch an incorrect origin, unit assumption, or inequality before applying a more involved rule.

From selection rule to designed outline

Complex silhouettes can be built from simpler regions and conditions. In the graphene batarang example, the script uses symmetry through abs(x), divides the outline into regions, and applies different inequalities for the wings, head, and ears. A Boolean variable tracks whether an atom lies inside the intended outline; the script then sets both its selection and visibility flags accordingly.

A graphene sheet shaped into a nano-batarang using Simple Script

You do not need to begin with a complex design. First identify the coordinate plane containing the sheet, then write down the boundary conditions for each part of the outline. Keep the first version simple, check which atoms are selected, and refine the conditions as needed. The same approach can help define custom tiles or other coordinate-based regions without manually selecting every atom.

Simple Script can also modify atom positions and visibility, while Atoms Selector is designed for selecting atoms from an expression. Choose the tool that matches the task: use a selector for a condition-based selection, and use a script when you also need to change supported atom properties.

For more examples and the complete batarang scripts, see the original SAMSON tutorial.

Note: SAMSON and all SAMSON Extensions are free for non-commercial use. Get SAMSON.

Comments are closed.