energy

py4vasp.calculation.energy
class py4vasp.calculation._energy.Energy(*args, **kwargs)

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. The total energy of the system is one of the most important results to analyze materials. Total energy differences of different atom arrangements reveal which structure is more stable. Even when the number of atoms are different between two systems, you may be able to compare the total energies by adding a corresponding amount of single atom energies. In this case, you need to double check the convergence because some error cancellation does not happen if the number of atoms is changes. Finally, monitoring the total energy can reveal insights about the stability of the thermostat.

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()
plot(*args, **kwargs)

Wrapper around the to_graph() function.

This will merge multiple graphs if you specify different sources with the selection arguments. All arguments are passed to the wrapped function.

print()

Print a string representation of this instance.

read(*args, **kwargs)

Convenient wrapper around to_dict. Check that function for examples and optional arguments.

selections()

Returns all possible selections you can use for the other routines.

Returns:

Each element of the tuple is one possible selection for an energy or temperature. Note that some elements correspond to the same underlying data. If they are, they will be next to each other in the returned tuple.

Return type:

tuple

to_csv(*args, filename=None, **kwargs)

Converts data to a csv file.

Writes out a csv file for data stored in a dataframe generated with the to_frame() method. Useful for creating external plots for further analysis.

If no filename is provided a default filename is deduced from the name of the class.

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 to_graph() function. Please check the documentation of that function to learn which arguments are allowed.

Parameters:

filename (str | Path) – Name of the csv file which the data is exported to.

to_dict(selection=None)

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. If no energy is selected this will default to selecting all energies. Separate distinct labels by commas or whitespace. You can add or subtract different contributions e.g. TOTEN + EKIN. For a complete list of all possible selections, please use >>> calc.energy.selections()

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.to_dict()

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

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

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

>>> calc.energy[5].to_dict()
>>> calc.energy[1:6].to_dict()
to_frame(*args, **kwargs)

Wrapper around the to_frame() function.

Generates dataframes from the graph object. For information about parameters that can be passed to this method, look at to_graph().

Returns:

Pandas dataframe corresponding to data in the graph

Return type:

Dataframe

to_graph(selection='TOTEN')

Read the energy data and generate a figure of the selected components.

Parameters:

selection (str or None) – String specifying the labels of the energy to be read. If no energy is selected this will default to selecting the total energy. Separate distinct labels by commas or whitespace. You can add or subtract different contributions e.g. TOTEN + EKIN. For a complete list of all possible selections, please use >>> calc.energy.selections()

Returns:

figure containing the selected energies for every selected ionic step.

Return type:

Graph

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_graph()

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

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

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

>>> calc.energy[5].to_graph()
>>> calc.energy[1:6].to_graph()
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 to_graph() 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. If no energy is selected this will default to selecting the total energy. Separate distinct labels by commas or whitespace. You can add or subtract different contributions e.g. TOTEN + EKIN. For a complete list of all possible selections, please use >>> calc.energy.selections()

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(*args, **kwargs)

Convert the graph of this quantity to a plotly figure.

The arguments to this function are automatically passed on to the to_graph() function. Please check the documentation of that function to learn which arguments are allowed.