dynamics Package

hist Module

History file with structural relaxation results.

class abipy.dynamics.hist.HistFile(filepath)[source]

Bases: abipy.core.mixins.AbinitNcFile, abipy.core.mixins.NotebookWriter

File with the history of a structural relaxation or molecular dynamics calculation.

Usage example:

with HistFile("foo_HIST") as hist:
    hist.plot()

Inheritance Diagram

Inheritance diagram of HistFile
classmethod from_file(filepath)[source]

Initialize the object from a netcdf file

close()[source]

Close the file.

params[source]

OrderedDict with parameters that might be subject to convergence studies.

final_energy[source]

Total energy in eV of the last iteration.

final_pressure[source]

Final pressure in Gpa.

get_fstats_dict(step)[source]

Return monty.collections.AttrDict with stats on the forces at the given step.

to_string(verbose=0, title=None)[source]

String representation.

property num_steps

Number of iterations performed.

steps[source]

Step indices.

property initial_structure

The initial abipy.core.structure.Structure.

property final_structure

The abipy.core.structure.Structure of the last iteration.

structures[source]

List of abipy.core.structure.Structure objects at the different steps.

etotals[source]

numpy.ndarray with total energies in eV at the different steps.

get_relaxation_analyzer()[source]

Return a pymatgen RelaxationAnalyzer object to analyze the relaxation in a calculation.

to_xdatcar(filepath=None, groupby_type=True, to_unit_cell=False, **kwargs)[source]

Return Xdatcar pymatgen object. See write_xdatcar for the meaning of arguments.

Parameters
  • to_unit_cell (bool) – Whether to translate sites into the unit cell.

  • kwargs – keywords arguments passed to Xdatcar constructor.

write_xdatcar(filepath='XDATCAR', groupby_type=True, overwrite=False, to_unit_cell=False)[source]

Write Xdatcar file with unit cell and atomic positions to file filepath.

Parameters
  • filepath – Xdatcar filename. If None, a temporary file is created.

  • groupby_type – If True, atoms are grouped by type. Note that this option may change the order of the atoms. This option is needed because there are post-processing tools (e.g. ovito) that do not work as expected if the atoms in the structure are not grouped by type.

  • overwrite – raise RuntimeError, if False and filepath exists.

  • to_unit_cell (bool) – Whether to translate sites into the unit cell.

Returns

path to Xdatcar file.

visualize(appname='ovito', to_unit_cell=False)[source]

Visualize the crystalline structure with visualizer. See Visualizer for the list of applications and formats supported.

Parameters

to_unit_cell (bool) – Whether to translate sites into the unit cell.

plot_ax(ax, what, fontsize=8, **kwargs)[source]

Helper function to plot quantity what on axis ax.

Parameters
  • fontsize – fontsize for legend.

  • are passed to matplotlib plot method. (kwargs) –

plot(what_list=None, ax_list=None, fontsize=8, **kwargs)[source]

Plot the evolution of structural parameters (lattice lengths, angles and volume) as well as pressure, info on forces and total energy.

Parameters
  • what_list

  • ax_list – List of matplotlib.axes.Axes. If None, a new figure is created.

  • fontsize – fontsize for legend

Returns: matplotlib.figure.Figure

Keyword arguments controlling the display of the figure:

kwargs

Meaning

title

Title of the plot (Default: None).

show

True to show the figure (default: True).

savefig

“abc.png” or “abc.eps” to save the figure to a file.

size_kwargs

Dictionary with options passed to fig.set_size_inches e.g. size_kwargs=dict(w=3, h=4)

tight_layout

True to call fig.tight_layout (default: False)

ax_grid

True (False) to add (remove) grid from all axes in fig. Default: None i.e. fig is left unchanged.

ax_annotate

Add labels to subplots e.g. (a), (b). Default: False

fig_close

Close figure. Default: False.

plot_energies(ax=None, fontsize=8, **kwargs)[source]

Plot the total energies as function of the iteration step.

Parameters
  • axmatplotlib.axes.Axes or None if a new figure should be created.

  • fontsize – Legend and title fontsize.

Returns: matplotlib.figure.Figure

Keyword arguments controlling the display of the figure:

kwargs

Meaning

title

Title of the plot (Default: None).

show

True to show the figure (default: True).

savefig

“abc.png” or “abc.eps” to save the figure to a file.

size_kwargs

Dictionary with options passed to fig.set_size_inches e.g. size_kwargs=dict(w=3, h=4)

tight_layout

True to call fig.tight_layout (default: False)

ax_grid

True (False) to add (remove) grid from all axes in fig. Default: None i.e. fig is left unchanged.

ax_annotate

Add labels to subplots e.g. (a), (b). Default: False

fig_close

Close figure. Default: False.

yield_figs(**kwargs)[source]

This function generates a predefined list of matplotlib figures with minimal input from the user.

mvplot_trajectories(colormap='hot', sampling=1, figure=None, show=True, with_forces=True, **kwargs)[source]

Call mayavi to plot atomic trajectories and the variation of the unit cell.

mvanimate(delay=500)[source]
get_panel()[source]

Build panel with widgets to interact with the abipy.dynamics.hist.HistFile either in a notebook or in panel app.

write_notebook(nbpath=None)[source]

Write a jupyter notebook to nbpath. If nbpath is None, a temporay file in the current working directory is created. Return path to the notebook.

class abipy.dynamics.hist.HistRobot(*args)[source]

Bases: abipy.abio.robots.Robot

This robot analyzes the results contained in multiple HIST.nc files.

Inheritance Diagram

Inheritance diagram of HistRobot
EXT = 'HIST'
to_string(verbose=0)[source]

String representation with verbosity level verbose.

get_dataframe(with_geo=True, index=None, abspath=False, with_spglib=True, funcs=None, **kwargs)[source]

Return a pandas.DataFrame with the most important final results and the filenames as index.

Parameters
  • with_geo – True if structure info should be added to the dataframe

  • abspath – True if paths in index should be absolute. Default: Relative to getcwd().

  • index – Index of the dataframe, if None, robot labels are used

  • with_spglib – If True, spglib is invoked to get the space group symbol and number

kwargs:
attrs:

List of additional attributes of the abipy.electrons.gsr.GsrFile to add to the pandas.DataFrame.

funcs: Function or list of functions to execute to add more data to the DataFrame.

Each function receives a abipy.electrons.gsr.GsrFile object and returns a tuple (key, value) where key is a string with the name of column and value is the value to be inserted.

property what_list

List with all quantities that can be plotted (what_list).

gridplot(what_list=None, sharex='row', sharey='row', fontsize=8, **kwargs)[source]

Plot the what value extracted from multiple HIST.nc files on a grid.

Parameters
  • what_list – List of quantities to plot. Must be in [“energy”, “abc”, “angles”, “volume”, “pressure”, “forces”]

  • sharex – True if xaxis should be shared.

  • sharey – True if yaxis should be shared.

  • fontsize – fontsize for legend.

Returns: matplotlib.figure.Figure

Keyword arguments controlling the display of the figure:

kwargs

Meaning

title

Title of the plot (Default: None).

show

True to show the figure (default: True).

savefig

“abc.png” or “abc.eps” to save the figure to a file.

size_kwargs

Dictionary with options passed to fig.set_size_inches e.g. size_kwargs=dict(w=3, h=4)

tight_layout

True to call fig.tight_layout (default: False)

ax_grid

True (False) to add (remove) grid from all axes in fig. Default: None i.e. fig is left unchanged.

ax_annotate

Add labels to subplots e.g. (a), (b). Default: False

fig_close

Close figure. Default: False.

combiplot(what_list=None, colormap='jet', fontsize=6, **kwargs)[source]

Plot multiple HIST.nc files on a grid. One plot for each what value.

Parameters
  • what_list – List of strings with the quantities to plot. If None, all quanties are plotted.

  • colormap – matplotlib color map.

  • fontsize – fontisize for legend.

Returns: matplotlib.figure.Figure.

Keyword arguments controlling the display of the figure:

kwargs

Meaning

title

Title of the plot (Default: None).

show

True to show the figure (default: True).

savefig

“abc.png” or “abc.eps” to save the figure to a file.

size_kwargs

Dictionary with options passed to fig.set_size_inches e.g. size_kwargs=dict(w=3, h=4)

tight_layout

True to call fig.tight_layout (default: False)

ax_grid

True (False) to add (remove) grid from all axes in fig. Default: None i.e. fig is left unchanged.

ax_annotate

Add labels to subplots e.g. (a), (b). Default: False

fig_close

Close figure. Default: False.

yield_figs(**kwargs)[source]

This function generates a predefined list of matplotlib figures with minimal input from the user.

write_notebook(nbpath=None)[source]

Write a jupyter notebook to nbpath. If nbpath is None, a temporay file in the current working directory is created. Return path to the notebook.

class abipy.dynamics.hist.HistReader(path)[source]

Bases: abipy.iotools.ETSF_Reader

This object reads data from the HIST file.

Inheritance Diagram

Inheritance diagram of HistReader
num_steps[source]

Number of iterations present in the HIST.nc file.

natom[source]

Number of atoms un the unit cell.

read_all_structures()[source]

Return the list of structures at the different iteration steps.

read_eterms(unit='eV')[source]

monty.collections.AttrDict with the decomposition of the total energy in units unit

read_cart_forces(unit='eV ang^-1')[source]

Read and return a numpy.ndarray with the cartesian forces in unit unit. Shape (num_steps, natom, 3)

read_reduced_forces()[source]

Read and return a numpy.ndarray with the forces in reduced coordinates Shape (num_steps, natom, 3)

read_cart_stress_tensors()[source]

Return the stress tensors (nstep x 3 x 3) in cartesian coordinates (GPa) and the list of pressures in GPa unit.