Skip to main content

Atoms_plotter

Package for plotting ASE atoms-objects using matplotlib. Can be used to create vector graphics, or used interactively in a jupyter-notebook.

Installation

clone repository into Atoms_plotter install with

cd Atoms_plotter
python3 -m pip install -e . 

Ideally with a development install (-e) so changes are easily updated.

Usage

  • use installed entry point plot_atoms. See plot_atoms --help for options

In a python script

Initialize the class; set options either when initialising or modify class attributes.

from AtomsPlotter import atoms_plotter
from ase.io import read
from sys import argv
atoms=read(argv[1])
ap=atoms_plotter(atoms,show=True)
ap.plot()

In a jupyter-notebook

import ase
import ase.io
import matplotlib.pyplot
atoms=ase.io.read('CONTCAR')
%matplotlib widget #for interactive use
from AtomsPlotter import atoms_plotter

plotter=atoms_plotter(atoms=atoms, constraints=True)
plotter.dimension='3D'
plotter.plot()

some options

plotter.atom_scale=0.5            # atoms drawn at this fraction of their covalent radius
plotter.inches_per_angstrom=0.4   # figure size per Angstrom of cell/structure
plotter.bondlinewidth=1           # multiplier of the default stick width
#plotter.scale=70                 # legacy: fixed marker size (points^2 per Angstrom radius)
plotter.colorbonds=True
plotter.constraints=False #draw constraints as x
plotter.draw_outline=True
plotter.repeat=[2,2] #repeat the unit cell in x,y (periodic structures)
plotter.use_bondorders=True #double/triple bonds
plotter.dimension='2D' #2D projection
plotter.plot()

#plot lewis-like structures. bonds as simple black lines, no atoms.

plotter.dimension='2D'
plotter.lewis=True
plotter.atoms.rotate(90, 'z',rotate_cell=True)
plotter.view=2
plotter.plot()

Sizing

Figure size and atom/bond sizes are derived from the structure itself: the figure is inches_per_angstrom inches per Angstrom of cell (or molecule) extent, clamped so the longer edge stays between min_figsize and max_figsize inches, and atoms are drawn with atom_scale times their covalent radius in real-space units. The same settings therefore give a uniform look across structures of any size. Setting scale to a number restores the legacy behaviour where marker sizes are a fixed number of points^2 per Angstrom of covalent radius.

Molecules

Structures without periodic boundary conditions are framed by the bounding box of their atoms (plus their drawn radii), so a molecule is always centered in the figure no matter where it sits in space. By default molecules are also rotated onto their principal axes (largest extent on x, smallest on z) so e.g. planar molecules are shown face-on and linear molecules lengthwise; disable with auto_orient=False.

Examples

examples/ contains a few periodic POSCAR structures and, under examples/molecules/, molecules from ASE's database, e.g.

plot_atoms examples/THF@Si.poscar
plot_atoms examples/molecules/C2H2.xyz
plot_atoms examples/molecules/C60.xyz -D 3D --elev 10 --azim 30

Rendered output for every example is in examples/renders/: plain 2D (default settings, plot_atoms <file>) and a tilted 3D view (plot_atoms <file> -D 3D --elev 10 --azim 30, saved as *_3d.svg).

THF@Si C60 C2H2
THF@Si C60 C2H2
THF@Si 3D C60 3D C2H2 3D

Changelog

1.0.0

  • Uniform sizing: figure size now scales with the cell/structure (inches_per_angstrom, clamped by min_figsize/max_figsize), and atom/bond sizes are computed in real-space units (atom_scale, bondlinewidth as stick-width multiplier). scale now defaults to None; pass a number for the legacy fixed point-based sizes.
  • Molecules get a sensible default view: radius-aware bounding-box framing (centered wherever the molecule sits in space) and principal-axis auto-orientation (auto_orient).
  • Frame computation fixed for non-orthogonal cells (previously only the diagonal of the cell was considered, cropping e.g. hexagonal cells); atoms sticking out of the cell are no longer cut off.
  • repeat attribute of atoms_plotter is now actually used (previously documented but ignored); CLI -r/--repeat fixed (a precedence bug made it a no-op).
  • CLI --double_bonds, --triple_bonds, --double_bond_offset, --triple_bond_offset are passed through correctly (previously set nonexistent attributes); removed broken empirical scaling of scale/bondlinewidth by the cell size and a stray debug print.
  • outline_width constructor argument is honored (was hardcoded).
  • Bond-order detection uses the correct periodic-image distance.
  • 3D z-order is computed along the actual viewing direction (elev/azim), so occlusion is correct for any camera angle, not just the top-down view; 3D axes margins trimmed.
  • Bond outlines are no longer drawn when draw_outline=False.
  • plot() no longer mutates the supplied atoms object (cell of non-periodic structures used to be overwritten).
  • CLI handles filenames containing @ (e.g. THF@Si.poscar).
  • New CLI options: --atom_scale, --inches_per_angstrom, --auto_orient, -f/--format; -B/--bonds is wired up.
  • from AtomsPlotter import atoms_plotter works (package __init__).
  • Added example molecules from ASE's database under examples/molecules/ and a real test suite.

0.3.3

  • Fix plot_atoms_2D / plot_atoms_3D colour assignment: elements missing from color_dict (e.g. Au, Pt) used to inherit the last-iterated atom's jmol colour because self.COLORS was rebuilt inside the per-atom loop with the outer-loop atomic number as the fallback. Now built once with a per-atom jmol fallback.
  • Add Au (gold) to the default color_dict.
  • Promote plot_atom_colorscaling to a real constructor keyword (plot_atom_colorscaling=False by default). Previously it was referenced from both render paths but the __init__ assignment was commented out, so any code that hit the color_dict=None branch raised AttributeError.
  • Guard the z-fraction colour scaling against z_norm == 0 so flat (2-D) structures no longer divide by zero.
  • Tidy four ruff E702 (semicolon-chained statements) in check_pbc.

(0.3.2 was prepared but never published — its scope is included in 0.3.3 above.)

Metadata

Release files for AtomsPlotter 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AtomsPlotter 1.0.1
File Size Uploaded Provenance Actions
atomsplotter-1.0.1.tar.gz 29.1 kB Without provenance Details for atomsplotter-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for AtomsPlotter 1.0.1
File Interpreter ABI Platform Actions
atomsplotter-1.0.1-py3-none-any.whl Python 3 none any Details for atomsplotter-1.0.1-py3-none-any.whl

Total release size: 55.2 kB

Release files / atomsplotter-1.0.1.tar.gz

Download URL atomsplotter-1.0.1.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b3adf2b491499956c22d680c4a1ed616aa6870f94d826a1d8854b75b24f86ddf
BLAKE2b-256 checksum
How to use checksums
4d6139fcf9323ea5978d64a511ab059669ef20266855748cfda05099f96ac2e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / atomsplotter-1.0.1-py3-none-any.whl

Download URL atomsplotter-1.0.1-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96fb0681d6ae2154b8d87aada386dc07e6b512a818641cba911cab2593cc5046
BLAKE2b-256 checksum
How to use checksums
d1d9491e79f82d5aaf681c7041b75825dda7d3af7804ee6ed4cbbeb0c440fbc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for AtomsPlotter 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page