Examples#
This gallery collects practical SAMSON Python API recipes. Use it to find a script close to the task you want to automate, then open the recipe page for the complete code and notes.
Building systems#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want to create atoms and bonds programmatically. |
An active document. |
A structural model with a decane-like chain. |
Beginner |
|
|
You want to generate a simple geometric atom distribution. |
An active document. |
A structural model populated with carbon atoms on a sphere. |
Beginner |
|
|
You want a larger procedural construction workflow. |
A nanotube model or nanotube creator workflow. |
A woven carbon nanotube fabric. |
Advanced |
|
Colorization and visualization#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want a spatial color gradient. |
Atoms in the active document. |
Atom colors based on X coordinates. |
Beginner |
|
|
You want to visualize motion along a path. |
A trajectory path and atoms. |
Atom colors based on velocity norm. |
Intermediate |
|
|
You want to colorize coarse-grained nodes by names or types. |
Coarse-grained nodes in the active document. |
Group or atom colors that reveal coarse-grained structure. |
Intermediate |
|
|
You want color to encode connected-component mass. |
Molecules or connected components. |
Component colors based on molecular weight. |
Intermediate |
|
Processing and analysis#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want to compare two superimposed molecules. |
Two molecule nodes with comparable atoms. |
RMSD values printed in angstroms. |
Intermediate |
|
|
You want bond-length statistics over trajectory frames. |
A path and bonds in the active document. |
Min, mean, and max bond lengths plotted over frames. |
Intermediate |
|
|
You want minimum atom distances over trajectory frames. |
A path and atoms in the active document. |
Minimum interatomic distances plotted over frames. |
Advanced |
|
Selections#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want to select nodes from geometric criteria. |
Atoms and bonds in the active document. |
Selected atoms and bonds between two X positions. |
Beginner |
|
|
You want reusable selection logic for connected components. |
Molecules or connected components. |
Selected components that match the mass criteria. |
Intermediate |
|
Note
Select connected components by molecular weight and Dialog: select connected components by molecular weight intentionally use the same sample script. The first entry is listed with selection recipes; the dialog entry is listed with GUI recipes because it focuses on presenting the workflow through a dialog.
Animations and export#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want to animate a path inside a presentation. |
A path in the active document. |
A presentation that plays the path. |
Intermediate |
|
|
You want to record path or camera animations from Python. |
A path or camera-ready document. |
Image sequence or movie output. |
Intermediate |
|
|
You want files for each frame of a trajectory. |
A path and structural models. |
PDB or XYZ files for trajectory frames. |
Intermediate |
|
Simulation and external packages#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want to combine SAMSON structures with ASE workflows. |
ASE installed in SAMSON’s Python environment. |
Optimized structures or simulation results. |
Advanced |
|
Apps and GUIs#
Recipe |
Use when |
Input |
Output |
Difficulty |
APIs used |
|---|---|---|---|---|---|
You want a small embedded PySide6 interface in SAMSON. |
SAMSON’s embedded Python environment with PySide6. |
A GUI with buttons that run SAMSON commands. |
Intermediate |
|
|
You want user-adjustable inputs before selecting components. |
Molecules or connected components. |
A dialog-driven selection workflow. |
Intermediate |
|
Contributing examples#
When adding a new example, prefer a small reusable recipe with:
a clear title and
.. meta::description;a short purpose statement and prerequisites;
the script or a
.. literalinclude::of a sample file;the expected result after running it;
a short note on how to adapt the script;
the main SAMSON Python APIs used.
Keep scripts deterministic when possible. If an example requires a document, selection, path, plugin, external package, or local file, state that before the code block.