Visualization¶
Pictures¶
render ¶
render(system, path=None, *, atoms=None, color=None, colormap='viridis', value_range=None, representation='spheres', radius=None, bonds=None, bond_radius=None, box=True, box_radius=None, box_color='black', polyhedra=None, polyhedra_alpha=0.6, polyhedra_color='atom', polyhedra_edges=None, mesh=None, mesh_color='#8fb0d8', mesh_alpha=1.0, dislocations=None, dislocation_radius=0.5, burgers_vectors=False, burgers_scale=3.0, burgers_radius=0.3, burgers_color=(0.7, 0.7, 0.7), vectors=None, vector_scale=1.0, vector_radius=0.5, vector_color=(1.0, 1.0, 0.0), vector_alignment='base', lines=None, line_radius=0.1, line_color=(0.6, 0.6, 0.6), wrap_lines=False, legend=False, **options)
A picture of a system: its atoms, optionally bonds, the box, Voronoi cells and a surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
path
|
str or path - like
|
A PNG file to write the picture to. |
None
|
atoms
|
array_like
|
A boolean mask or indices of the atoms shown. Default all. |
None
|
color
|
optional
|
The colors of the atoms, see |
None
|
colormap
|
str
|
The colormap of values. Default viridis. |
'viridis'
|
value_range
|
sequence of float64
|
The values at the two ends of the colormap. |
None
|
representation
|
str
|
How atoms and bonds are drawn, one of |
'spheres'
|
radius
|
(float32, array_like or str)
|
Radius of the atoms in Å, one or (N,) each, or the radii of the
elements: "display", "covalent" or "vdw". Default the |
None
|
bonds
|
(float64, NeighborList, covalent or topology)
|
Bonds between the atoms closer than this cutoff in Å, the pairs of a
neighbor list, covalent bonds (see |
None
|
bond_radius
|
float32
|
Radius of the bonds in Å. Default that of the representation. |
None
|
box
|
bool
|
Draw the edges of the box. Default True. |
True
|
box_radius
|
float32
|
Radius of the edges in Å. Default a tenth of the median atom radius. |
None
|
box_color
|
color
|
Color of the edges. Default black. |
'black'
|
polyhedra
|
VoronoiPolyhedra
|
Voronoi cells to draw for the atoms shown. |
None
|
polyhedra_alpha
|
float32
|
Opacity of the cells. Default 0.6. |
0.6
|
polyhedra_color
|
(atom, edges)
|
Color the faces as their atoms, or by their number of edges. Default atom. |
"atom"
|
polyhedra_edges
|
float32
|
Radius in Å of the edges of the cells; 0 draws none. Default a twentieth of the median atom radius. |
None
|
mesh
|
TriangleMesh
|
A surface to draw, such as that of
|
None
|
mesh_color
|
optional
|
One color for the surface, or (F, 3) colors of its triangles. Default light blue. |
'#8fb0d8'
|
mesh_alpha
|
float32
|
Opacity of the surface. Default 1. |
1.0
|
dislocations
|
DislocationResult
|
Dislocation lines to draw, such as those of
|
None
|
dislocation_radius
|
float32
|
Radius of the tubes in Å. Default 0.5. |
0.5
|
burgers_vectors
|
bool
|
Also draw the Burgers vector of each line: an arrow from the middle of the line along the vector in space. Default False. |
False
|
burgers_scale
|
float32
|
Length of the arrows in units of the Burgers vectors. Default 3. |
3.0
|
burgers_radius
|
float32
|
Radius of the shafts of the arrows in Å. Default 0.3. |
0.3
|
burgers_color
|
optional
|
One color for the arrows, or "family" for the color of each line. Default light gray. |
(0.7, 0.7, 0.7)
|
vectors
|
str or array_like
|
A column of three components, such as displacement, velocities or forces, or (N, 3) vectors: an arrow for each atom shown. |
None
|
vector_scale
|
float32
|
Length of the arrows in units of the vectors; negative reverses them. Default 1. |
1.0
|
vector_radius
|
float32
|
Radius of the shafts of the arrows in Å. Default 0.5. |
0.5
|
vector_color
|
optional
|
One color for the arrows, or "atom" for the color of each atom. Default yellow. |
(1.0, 1.0, 0.0)
|
vector_alignment
|
(base, center, head)
|
The point of the arrow at its atom: its tail, its middle or its tip. Default base. |
"base"
|
lines
|
array_like or sequence of array_like
|
Polylines to draw, such as the paths of
|
None
|
line_radius
|
float32
|
Radius of the lines in Å. Default 0.1. |
0.1
|
line_color
|
optional
|
One color for the lines. Default gray. |
(0.6, 0.6, 0.6)
|
wrap_lines
|
bool
|
Cut the lines at the periodic faces of the box and move the parts outside in through the opposite faces (True), or draw them as they are (False, default). |
False
|
legend
|
(bool, str or mapping)
|
A legend at the top left, which needs matplotlib. True gives the names of the structures or elements of the atoms shown with their colors, or a bar with the values and the colormap of a column or of (N,) values. A string does the same with this title, as for values that have no name. A mapping gives its own names and colors. Default none. |
False
|
**options
|
Any
|
The options of |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(height, width, 4) uint8 RGBA picture. |
show_image ¶
Shows a picture in a notebook, such as Jupyter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
(ndarray, str or path - like)
|
A picture as |
required |
width
|
int32
|
Its width on the page in pixels. Default the width of the picture. |
None
|
Scene ¶
Spheres, cylinders and polygons to render.
Colors are sRGB from 0 to 1, lengths in Å.
add_spheres ¶
Adds spheres, such as atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centers
|
array_like
|
(N, 3) float32 centers. |
required |
radii
|
float32 or array_like
|
Radius of every sphere, or (N,) each. |
required |
colors
|
array_like
|
One color, as three numbers from 0 to 1 or a name such as "#rrggbb", or (N, 3) each. |
required |
ids
|
array_like
|
(N,) int64 non-negative ids; outlines separate different ids. Default new ids, one per sphere. |
None
|
add_cylinders ¶
Adds cylinders without caps, such as bonds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
starts
|
array_like
|
(M, 3) float32, the two ends of each cylinder. |
required |
ends
|
array_like
|
(M, 3) float32, the two ends of each cylinder. |
required |
radii
|
float32 or array_like
|
Radius of every cylinder, or (M,) each. |
required |
colors
|
array_like
|
One color, or (M, 3) each. |
required |
ids
|
array_like
|
(M,) int64 non-negative ids. Default new ids. |
None
|
add_triangles ¶
Adds triangles, seen from both sides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array_like
|
(T, 3, 3) float32, the corners of each triangle. |
required |
colors
|
array_like
|
One color, or (T, 3) each. |
required |
alpha
|
float32 or array_like
|
Opacity from 0 to 1 of every triangle, or (T,) each. Default 1. |
1.0
|
ids
|
array_like
|
(T,) int64 non-negative ids. Default new ids. |
None
|
add_polygons ¶
Adds convex polygons, such as the faces of Voronoi cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array_like
|
(V, 3) float32 points. |
required |
corner_offsets
|
array_like
|
(F + 1,) int64, the corners of polygon f are
|
required |
corners
|
array_like
|
(C,) int64, the vertex of each corner, in order around its polygon. |
required |
colors
|
array_like
|
One color, or (F, 3) each. |
required |
alpha
|
float32 or array_like
|
Opacity of every polygon, or (F,) each. Default 1. |
1.0
|
ids
|
array_like
|
(F,) int64 ids, the same for the triangles of a polygon. Default new ids. |
None
|
add_box ¶
Adds the twelve edges of a box, with a sphere on each corner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box
|
Box
|
The box. |
required |
radius
|
float32
|
Radius of the edges in Å. Default 0.15. |
0.15
|
color
|
color
|
Default black. |
(0.0, 0.0, 0.0)
|
render ¶
render(path=None, *, width=1200, height=900, view='iso', up=None, perspective=False, fov=30.0, zoom=1.0, focus=None, span=None, aperture=0.0, focal_distance=None, style='matte', background='white', device='cpu', progress=None, cancel=None, **options)
Renders the scene, framed to fill the picture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
A PNG file to write the picture to. |
None
|
width
|
int32
|
Size of the picture in pixels. Default 1200 by 900. |
1200
|
height
|
int32
|
Size of the picture in pixels. Default 1200 by 900. |
1200
|
view
|
str or array_like
|
One of top, bottom, front, back, left, right and iso, or the (3,) direction of view. Default iso. |
'iso'
|
up
|
array_like
|
(3,) float32, the direction up in the picture. Default that of the view, or z. |
None
|
perspective
|
bool
|
A perspective camera, or orthographic. Default False. |
False
|
fov
|
float32
|
Vertical angle of view of a perspective camera in degrees. Default 30. |
30.0
|
zoom
|
float32
|
Magnification of the framed scene. Default 1. |
1.0
|
focus
|
array_like
|
(3,) float32, the point in Å at the middle of the picture. Default the middle of the scene. |
None
|
span
|
float32
|
The length in Å the picture shows from its bottom to its top at the focus, in place of the framing and zoom. Default the scene framed. |
None
|
aperture
|
float32
|
Radius in Å of the lens of a perspective camera: 0 for a picture sharp everywhere, more for depth of field. Default 0. |
0.0
|
focal_distance
|
float32
|
Distance in Å from the camera along the view to the plane that stays sharp. Default that of the focus. |
None
|
style
|
str
|
One of |
'matte'
|
background
|
color or None
|
The background, or None for transparent. Default white. |
'white'
|
device
|
(cpu, gpu, auto)
|
Trace the rays on the processor, on the GPU (see
|
"cpu"
|
progress
|
optional
|
Progress reports and cancellation. |
None
|
cancel
|
optional
|
Progress reports and cancellation. |
None
|
**options
|
Any
|
Settings of the style to change: ambient, diffuse, specular, shininess, metalness, key, highlight, fill, fill_intensity, base_light, srgb, ao_samples, ao_distance, ao_strength, shadows, shadow_strength, flat, toon_levels, outline_width, outline_depth, outline_color, fog, supersample, samples, bounces, light_size. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(height, width, 4) uint8 RGBA picture, rows from the top. |
write_png ¶
Writes an RGBA image to a PNG file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
The file. |
required |
image
|
ndarray
|
(H, W, 4) uint8 image, rows from the top. |
required |
gpu_available ¶
Whether pictures can be traced on a GPU: with Metal on macOS, with Vulkan on Linux, with Direct3D 12 on Windows.
Returns:
| Type | Description |
|---|---|
bool
|
True when a GPU is found and its shader compiles. |
Colors, radii and bonds¶
atom_names ¶
The names the colors and radii of the atoms go by.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) str, their elements; atoms of a type without an element, or of the
element X, named after their type: |
atom_colors ¶
(N, 3) sRGB colors of the atoms of a system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
color
|
optional
|
None for the |
None
|
colormap_name
|
str
|
The colormap of values. Default viridis. |
'viridis'
|
value_range
|
sequence of float64
|
The values at the two ends of the colormap. |
None
|
elements
|
mapping
|
Colors of elements, such as |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(N, 3) float64 colors from 0 to 1. |
atom_radii ¶
(N,) radii of the atoms of a system in Å.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
radius
|
str
|
The radii of the elements: "display", "covalent" or "vdw". Default display. |
'display'
|
elements
|
mapping
|
Radii of elements in Å, such as |
None
|
scale
|
float64
|
A factor of every radius. Default 1. |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) float64, the |
color_coding ¶
The atoms colored by the values of a column through a colormap, as OVITO's color coding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
column
|
str
|
A column of numbers, a component such as |
required |
colormap
|
str
|
One of |
'rainbow'
|
value_range
|
sequence of float64
|
(low, high) values of the two ends; by default the smallest and the largest finite value of the atoms colored. |
None
|
atoms
|
array_like
|
A boolean mask or indices of the atoms to color; the others keep their colors. All by default. |
None
|
Returns:
| Type | Description |
|---|---|
System
|
The system with the colors in its |
color_by_type ¶
The atoms colored by the value of a column, as OVITO's color by type:
one of LABEL_COLORS for each value, in increasing order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
column
|
str
|
A column of values of one component, such as |
required |
atoms
|
array_like
|
A boolean mask or indices of the atoms to color; the others keep their colors. All by default. |
None
|
Returns:
| Type | Description |
|---|---|
System
|
The system with the colors in its |
assign_color ¶
The atoms in one color, as OVITO's assign color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
color
|
str or sequence of float64
|
A color: three numbers from 0 to 1, a code |
required |
atoms
|
array_like
|
A boolean mask or indices of the atoms to color; the others keep their colors. All by default. |
None
|
Returns:
| Type | Description |
|---|---|
System
|
The system with the colors in its |
colormap ¶
Colors of values through a colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array_like
|
(N,) float32, the values. |
required |
name
|
str
|
One of |
'viridis'
|
value_range
|
sequence of float64
|
(low, high) values of the two ends; by default the smallest and the largest finite value. Values beyond take the color of their end, NaN that of the low end. Not for labels. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(N, 3) float64 sRGB colors from 0 to 1. |
element_colors ¶
(N, 3) default sRGB colors of elements, or of atom types named
Type k, from 0 to 1.
element_radii ¶
(N,) radii of elements in Å.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
sequence of str
|
Chemical symbols. |
required |
kind
|
(display, covalent, vdw)
|
The radii pictures show, the covalent radii or the van der Waals radii. Default display. |
"display"
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) float64 radii; elements without a value take 1.5 Å as covalent radius and 2 Å as van der Waals radius. |
covalent_bonds ¶
The covalent bonds of a system: the pairs of atoms closer than the sum of their covalent radii and 0.45 Å.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms, with an element column. |
required |
Returns:
| Type | Description |
|---|---|
NeighborList
|
The bonds, each pair both ways. |
voxel_faces ¶
The faces of the box cut into the cells of a grid over it, each with the value of the cell inside it, to show the grid as colors on the box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array_like
|
(na, nb, nc) float64, the values of the cells of a grid that divides the box into na, nb and nc cells along its vectors a, b and c, such as the values of a SpatialBinning along all three. |
required |
box
|
Box
|
The box the grid divides. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mesh |
TriangleMesh
|
Two triangles for each cell at each of the six faces of the box, their normals pointing out of a right-handed box. |
face_values |
ndarray
|
(F,) float64, the value of the cell of each triangle, for colors such as
those of |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
For values that are not a three-dimensional grid of finite numbers. |
style_settings ¶
Every setting of a style: the options of Scene.render it
changes, and the defaults of the others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str
|
One of |
'matte'
|
Returns:
| Type | Description |
|---|---|
dict
|
Each setting by name; |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
For an unknown style. |
Movies¶
write_movie ¶
Writes pictures as a movie with FFmpeg, which must be on the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
The file; its suffix, such as |
required |
pictures
|
iterable of numpy.ndarray
|
(H, W, 3) or (H, W, 4) uint8 images of one size, rows from the top. They are taken one at a time, so a generator of pictures writes a long movie without holding them in memory. |
required |
fps
|
float64
|
Pictures per second. Default 30. |
30
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If FFmpeg is not on the PATH. |
InvalidParameter
|
If |
CalculationFailed
|
If FFmpeg fails, with what it says. |
Plots¶
plot ¶
Plot templates for figures of journals, and plots of the results of mdapy. Needs matplotlib.
figure ¶
A figure of the width of a column of a journal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
(single, double)
|
One column (88 mm), two (180 mm), or a width in mm. Default single. |
"single"
|
height
|
float64
|
Height in mm. Default 3/4 of the width of one panel times the rows. |
None
|
nrows
|
int32
|
Rows and columns of panels. Default 1. |
1
|
ncols
|
int32
|
Rows and columns of panels. Default 1. |
1
|
**options
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
The figure and its axes, as |
panel_label ¶
A bold lower-case label of a panel, at the top left of its axes.
save ¶
Saves a figure in several formats: vector PDF and SVG with text kept as text, and PNG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The figure. |
required |
path
|
str or path - like
|
The file, its suffix replaced by each format. |
required |
formats
|
sequence of str
|
Default PDF, SVG and PNG. |
('pdf', 'svg', 'png')
|
Returns:
| Type | Description |
|---|---|
list of pathlib.Path
|
The files written. |
parity ¶
A parity plot of predicted against reference values, with the root mean square error in the legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
array_like of float64
|
The values, of the same size. |
required |
predicted
|
array_like of float64
|
The values, of the same size. |
required |
ax
|
Axes
|
The axes; by default a new figure. |
None
|
label
|
str
|
Name of the set in the legend. |
''
|
unit
|
str
|
Unit of the error in the legend. |
''
|
scale
|
float64
|
Factor of the error in the legend, such as 1000 for meV from eV. |
1.0
|
density
|
bool
|
A hexagonal density map instead of points, for many values. |
False
|
color
|
str
|
Color of the points. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
scatter ¶
Two columns of the atoms against each other, a point for each atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms. |
required |
x
|
str
|
A column of numbers, a component such as |
required |
y
|
str
|
A column of numbers, a component such as |
required |
ax
|
Axes
|
The axes; by default a new figure. |
None
|
atoms
|
array_like
|
A boolean mask or indices of the atoms drawn. Default all of them. |
None
|
max_points
|
int32
|
At most this many atoms drawn, picked at random with a fixed seed from those with finite values. Default 20000. |
20000
|
color
|
str
|
Color of the points. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
rdf ¶
The radial distribution function, and optionally its partial
functions, of a mdapy.analysis.RadialDistributionResult.
structure_factor ¶
The structure factor of a mdapy.analysis.StructureFactorResult.
bond_angles ¶
The bond angle distribution of a
mdapy.analysis.BondAngleResult.
msd ¶
The mean squared displacement of a
mdapy.analysis.DisplacementResult against time, with a fit of
the diffusion coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DisplacementResult
|
The mean squared displacement. |
required |
timestep
|
float64
|
Time between frames in ps. Default 1. |
1.0
|
ax
|
Axes
|
The axes. |
None
|
fit
|
tuple of int32
|
(first, last) lags of a straight line fitted to the MSD, whose slope over 6 is the diffusion coefficient, shown in the legend. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
stacking_fault ¶
The generalized stacking fault energy of a
mdapy.simulation.StackingFaultResult, in mJ/m²: a point for each
slip computed, joined by a line. options go to ax.plot, such as
label.
band_structure ¶
The phonon frequencies of a
mdapy.lattice_dynamics.BandStructure along its path, with the
special points marked and labeled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
BandStructure
|
The band structure; with |
required |
ax
|
Axes
|
The axes. |
None
|
color
|
str
|
One color for every branch; by default each branch its own. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
phonon_dos ¶
The phonon density of states of a
mdapy.lattice_dynamics.PhononDOS, frequencies upward, to put
beside a band structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PhononDOS
|
The density of states. |
required |
ax
|
Axes
|
The axes. |
None
|
projected
|
bool
|
Also the density of each atom of the cell, when computed. |
False
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
structure_counts ¶
The number of atoms of each type of a structure identification, in the colors of the types.
phase_diagram ¶
The boundaries of the phases of a
mdapy.simulation.BinaryPhaseDiagram: where each tie line ends, against
the temperature, with the name of each phase in the middle of where it is the
only one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
BinaryPhaseDiagram
|
The phase diagram. |
required |
ax
|
Axes
|
The axes. |
None
|
labels
|
bool
|
Write the names of the phases. Default True. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |
pressure_temperature ¶
The boundaries of the phases of a
mdapy.simulation.PressureTemperatureDiagram: the temperature of each
against the pressure, with the name of each phase in the middle of where it
is stable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PressureTemperatureDiagram
|
The phase diagram. |
required |
ax
|
Axes
|
The axes. |
None
|
labels
|
bool
|
Write the names of the phases. Default True. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes. |