erlab.plotting.atoms¶
Plot atoms.
Classes and functions for plotting atoms and bonds in a crystal structure using matplotlib’s 3D plotting capabilities.
Some of the projection code was adapted from kwant.
Classes
|
Crystal positions and bond geometry for three-dimensional plotting. |
- class erlab.plotting.atoms.CrystalProperty(atom_pos, avec, offset=(0.0, 0.0, 0.0), radii=None, colors=None, repeat=(1, 1, 1), bounds=None, mask=None, r_factor=0.4)[source]¶
Bases:
objectCrystal positions and bond geometry for three-dimensional plotting.
Positions, lattice vectors, offsets, bounds, atomic radii, and bond lengths must use one consistent length unit. The class does not assign or convert physical units.
- classmethod from_fractional(frac_pos, avec, *args, **kwargs)[source]¶
Create plotting properties from fractional atomic coordinates.
- Parameters:
frac_pos (
dict[str,list[tuple[float,float,float]]]) – Mapping from each species name to its fractional coordinates(u, v, w).avec (
ndarray[tuple[Any,...],dtype[float64]]) – Direct-lattice vectors with shape(3, 3). Vectors are stored by row. Their unit becomes the unit of the Cartesian atom positions.*args – Additional arguments passed to the
CrystalPropertyconstructor.**kwargs – Additional arguments passed to the
CrystalPropertyconstructor.
- Returns:
CrystalProperty– New instance whose Cartesian positions areu * avec[0] + v * avec[1] + w * avec[2]. The input mapping is not modified.
- property bounds: list[tuple[float, float]]¶
Bounds for the x, y, and z coordinates, in that order.
An unspecified direction has bounds
(-inf, inf).
- property atom_pos: dict[str, ndarray[tuple[Any, ...], dtype[float64]]]¶
Repeated and filtered Cartesian positions for each species.
The calculation applies
repeat,offset,bounds, andmask, and removes duplicate positions after rounding to five decimal places. The result is cached after its first use.
- add_bonds(atom1, atom2, min_length=0.0, max_length=2.6, linewidth=0.25, color=None)[source]¶
Add bonds between two species.
- Parameters:
min_length (
float, default:0.0) – Inclusive center-to-center distance range. Values use the same unit as the atom positions.max_length (
float, default:2.6) – Inclusive center-to-center distance range. Values use the same unit as the atom positions.linewidth (
float, default:0.25) – Stored bond width. Withscale_bonds=Trueinplot(), this value is interpreted in position-coordinate units. Otherwise, Matplotlib interprets it as a line width in points.color (
str|tuple[float,...] |None, default:None) – Matplotlib color for the new bonds. If omitted, use"#b2b2b2".
Notes
This method appends to existing bonds. Each visible segment is shortened at both ends by the corresponding atomic radius multiplied by
r_factor.
- plot(ax=None, scale_bonds=True, scale_atoms=True, clean_axes=True, bond_kw=None, atom_kw=None)[source]¶
Plot the crystal structure.
- Parameters:
ax (
Axes3D|None, default:None) – A 3D axes object to plot the crystal on. If not provided, add_subplot will be called on the current figure.scale_bonds (
bool, default:True) – Whether to scale the bond linewidths based on the distance from the camera, by default Truescale_atoms (
bool, default:True) – Whether to scale the atom sizes based on the distance from the camera, by default Trueclean_axes (
bool, default:True) – Whether to clean the axes by removing the background and grid, setting pane color, and removing the margins, by default Truebond_kw (
dict|None, default:None) – Keyword arguments passed ontoBond3DCollectionatom_kw (
dict|None, default:None) – Keyword arguments passed ontompl_toolkits.mplot3d.Axes3D.scatterused to plot the atoms.