Energy

class py4vasp.data.Energy(raw_data)

Bases: py4vasp.data._trajectory.DataTrajectory, py4vasp.data._export.Image

The energy data for one or several steps of a relaxation or MD simulation.

You can use this class to inspect how the ionic relaxation converges or during an MD simulation whether the total energy is conserved.

Parameters

raw_energy (RawEnergy) – Dataclass containing the raw energy values for the ionic run and labels specifying which energies are stored.

Examples

If you access a method of this class, the result will depend on the steps that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.read()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].read()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].read()
>>> calc.energy[1:6].read()

Methods Summary

from_dict(dict_)

Initialize refinement class from data dictionary

from_file([file])

Read the data dictionary from the given file.

labels([selection])

Return the labels corresponding to a particular selection defaulting to all labels.

plot([selection])

Read the energy data and generate a plotly figure.

print()

Print a string representation of this class to standard output.

read([selection])

Read the energy data and store it in a dictionary.

to_dict([selection])

Read the energy data and store it in a dictionary.

to_image(*args[, filename])

Read the data and generate an image writing to the given filename.

to_numpy([selection])

Read the energy of the selected steps.

to_plotly([selection])

Read the energy data and generate a plotly figure.

Methods Documentation

classmethod from_dict(dict_)

Initialize refinement class from data dictionary

Parameters

data_dict (dict) – Data dictionary that contains one or more different raw data sources.

classmethod from_file(file=None)

Read the data dictionary from the given file.

You want to use this method if you want to avoid using the Calculation wrapper, for example because you renamed the output of the VASP calculation.

Parameters

file (str or Path or raw.File) – Filename from which the data is extracted. If not present the default filename is used. Alternatively, you can open the file yourself and pass the File object. In that case, you need to take care the file is properly closed again and be aware the generated instance of this class becomes unusable after the file is closed.

Returns

The returned instance handles opening and closing the file for every function called on it, unless a File object in which case this is left to the user.

Return type

DataBase

labels(selection='__all__')

Return the labels corresponding to a particular selection defaulting to all labels.

plot(selection='TOTEN')

Read the energy data and generate a plotly figure.

Parameters

selection (str or None) – String specifying the labels of the energy to be read. A substring of the label is sufficient. If no energy is select this will default to selecting the total energy. Separate distinct labels by commas. For a complete list of all possible selections, please use >>> calc.energy.labels()

Returns

plotly figure containing the selected energies for every selected ionic step.

Return type

plotly.graph_objects.Figure

Examples

If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.plot()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].plot()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].plot()
>>> calc.energy[1:6].plot()
print()

Print a string representation of this class to standard output.

read(selection='__all__')

Read the energy data and store it in a dictionary.

Parameters

selection (str or None) – String specifying the labels of the energy to be read. A substring of the label is sufficient. If no energy is select this will default to selecting all energies. Separate distinct labels by commas. For a complete list of all possible selections, please use >>> calc.energy.labels()

Returns

Contains the exact labels corresponding to the selection and the associated energies for every selected ionic step.

Return type

dict

Examples

If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.read()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].read()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].read()
>>> calc.energy[1:6].read()
to_dict(selection='__all__')

Read the energy data and store it in a dictionary.

Parameters

selection (str or None) – String specifying the labels of the energy to be read. A substring of the label is sufficient. If no energy is select this will default to selecting all energies. Separate distinct labels by commas. For a complete list of all possible selections, please use >>> calc.energy.labels()

Returns

Contains the exact labels corresponding to the selection and the associated energies for every selected ionic step.

Return type

dict

Examples

If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.read()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].read()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].read()
>>> calc.energy[1:6].read()
to_image(*args, filename=None, **kwargs)

Read the data and generate an image writing to the given filename.

The filetype is automatically deduced from the filename; possible are common raster (png, jpg) and vector (svg, pdf) formats. If no filename is provided a default filename is deduced from the name of the class and the picture has png format.

Note that the filename must be a keyword argument, i.e., you explicitly need to write filename=”name_of_file” because the arguments are passed on to the plot() function. Please check the documentation of that function to learn which arguments are allowed.

to_numpy(selection='TOTEN')

Read the energy of the selected steps.

Parameters

selection (str or None) – String specifying the labels of the energy to be read. A substring of the label is sufficient. If no energy is select this will default to selecting the total energy. Separate distinct labels by commas. For a complete list of all possible selections, please use >>> calc.energy.labels()

Returns

Contains energies associated with the selection for the selected ionic step(s). When only a single step is inquired, result is a float otherwise an array. If you select multiple quantities a tuple of them is returned.

Return type

float or np.ndarray or tuple

Examples

If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.to_numpy()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].to_numpy()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].to_numpy()
>>> calc.energy[1:6].to_numpy()
to_plotly(selection='TOTEN')

Read the energy data and generate a plotly figure.

Parameters

selection (str or None) – String specifying the labels of the energy to be read. A substring of the label is sufficient. If no energy is select this will default to selecting the total energy. Separate distinct labels by commas. For a complete list of all possible selections, please use >>> calc.energy.labels()

Returns

plotly figure containing the selected energies for every selected ionic step.

Return type

plotly.graph_objects.Figure

Examples

If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.

>>> calc.energy.plot()

To select the results for all steps, you don’t specify the array boundaries.

>>> calc.energy[:].plot()

You can also select specific steps or a subset of steps as follows

>>> calc.energy[5].plot()
>>> calc.energy[1:6].plot()