trj-render is a lightweight C++17 tool that reads LAMMPS trajectory files (.lammpstrj) and renders each frame as a 2D PNG image. It projects 3D atomic coordinates onto a customizable viewing plane, allowing rotation, scaling, and selective frame rendering.
- Parse and visualize
.lammpstrjtrajectory files frame by frame - Adjustable rotation angles around X, Y, and Z axes
- Configurable scaling factor (or automatic adjustment)
- Selective rendering of a specific frame
- Renders both simulation box edges and atoms with per-type colors and radii
- Output image format: PNG (via lodepng)
All dependencies are header-only libraries included via external/:
| Library | Purpose | License |
|---|---|---|
| lammpstrj-parser | LAMMPS trajectory reader | MIT |
| lodepng | PNG encoding | Zlib |
| cxxopts | Command-line parser | MIT |
- Requirements
- C++17-compatible compiler (tested with GCC ≥ 8.5.0)
- GNU Make
git clone --recursive https://github.com/kaityo256/trj-render.git
cd trj-renderIf you have already cloned it without --recursive, initialize submodules manually:
git submodule update --init --recursivemakeThis will compile the program and produce the executable trj2png in the project directory.
./trj2png [options] filename | Option | Description |
|---|---|
-x, --rx <deg> |
Rotation around X-axis (degrees) |
-y, --ry <deg> |
Rotation around Y-axis (degrees) |
-z, --rz <deg> |
Rotation around Z-axis (degrees) |
-s, --scale <num> |
Scale factor for the simulation box → pixels (if negative, the scale is automatically adjusted so that the larger side of the image becomes 800 px) |
-f, --frame <idx> |
Render only the specified frame (0-based). If omitted, all frames are rendered. |
--radiusN <num> |
Radius of atom type N (0–15). Only applied if specified. |
--visibleN=<bool> |
Visibility of atom type N (true to display, false to hide). The = sign is required for boolean options (e.g. --visible1=false). |
--xmin <value> |
Minimum x-coordinate to display |
--xmax <value> |
Maximum x-coordinate to display |
--ymin <value> |
Minimum y-coordinate to display |
--ymax <value> |
Maximum y-coordinate to display |
--zmin <value> |
Minimum z-coordinate to display |
--zmax <value> |
Maximum z-coordinate to display |
-h, --help |
Show help message |
- Render all frames, rotating by 30° around Y and −15° around Z, scaling by 200:
./trj2png -y 30 -z -15 -s 200 sample.lammpstrj
- Render only frame 3, rotating by 45° around X, with automatic scaling:
./trj2png --rx 45 --scale -1 -f 3 sample.lammpstrj
- Render frame 20, rotating by 30° around X, 3° around Y, and 3° around Z, and set the radius of atom type 2 to 10:
./trj2png -x 30 -y 3 -z 3 --radius2=10 -f 20 sample.lammpstrj
- Render frame 99, rotating by 10° around X, 3° around Y, and 3° around Z, displaying only atoms with x-coordinates between 50 and 60, setting the radius of atom type 2 to 10, and hiding atom type 2:
./trj2png -x 10 -y 3 -z 3 --xmin 50 --xmax 60 --radius2=10 --visible2=false -f 99 sample.lammpstrj
- Each frame is saved as a PNG file named:
frame.0000.png frame.0001.png ... - Atom color, border, and radius are automatically assigned based on atom type.
MIT License © 2025 Hiroshi Watanabe
See individual library directories for their respective licenses.