force

py4vasp.calculation.force

(*args, **kwargs)

The forces determine the path of the atoms in a trajectory.

You can use this class to analyze the forces acting on the atoms. The forces are the first derivative of the DFT total energy. The forces being small is an important criterion for the convergence of a relaxation calculation. The size of the forces is also related to the maximal time step in MD simulations. When you choose a too large time step, the forces become large and the atoms may move too much in a single step leading to an unstable trajectory. You can use this class to visualize the forces in a trajectory or read the values to analyze them numerically.

Examples

Let us create some example data so that we can illustrate how to use this class. Of course you can also use your own VASP calculation data if you have it available.

>>> from py4vasp import demo
>>> calculation = demo.calculation(path)

If you access the forces, 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.

>>> calculation.force.number_steps()
1

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

>>> calculation.force[:].number_steps()
4

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

>>> calculation.force[3].number_steps()
1
>>> calculation.force[1:4].number_steps()
3

force_rescale

= 1.5
Scaling constant to convert forces to Å.

number_steps

()
Return the number of forces in the trajectory.

path

Returns the path from which the output is obtained.

plot

(*args, **kwargs) → View

Wrapper around to_view() method.

This method will visualize the quantity in the structure. Please refer to the to_view() method for a documentation of the allowed arguments.

Returns

View
A visualization of the quantity within the crystal structure.

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

() → dict

Returns possible alternatives for this particular quantity VASP can produce.

The returned dictionary contains a single item with the name of the quantity mapping to all possible selections. Each of these selection may be passed to other functions of this quantity to select which output of VASP is used. Some quantities provide additional elements which can be passed as selection for other routines.

Returns

dict
The key indicates this quantity and the values possible choices for arguments to other functions of this quantity.

to_dict

() → dict

Read the forces into a dictionary.

Forces and associated structural information for one or more selected steps of the trajectory are returned in a dictionary. This includes the lattice vectors, atomic positions, and atomic species in addition to the forces acting on each atom. The forces are in Cartesian coordinates and in units of eV/Å.

Returns

dict
Contains the forces for all selected steps and the structural information to know on which atoms the forces act.

Examples

First, we create some example data so that we can illustrate how to use this method. You can also use your own VASP calculation data if you have it available.

>>> from py4vasp import demo
>>> calculation = demo.calculation(path)

If you use the to_dict method, 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. The structure is included to provide the necessary context for the forces.

>>> calculation.force.to_dict()
{'structure': {...}, 'forces': array([[...]])}

To select the results for all steps, you don’t specify the array boundaries. Notice that in this case the forces contain an additional dimension for the different steps.

>>> calculation.force[:].to_dict()
{'structure': {...}, 'forces': array([[[...]]])}

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

>>> calculation.force[1].to_dict()
{'structure': {...}, 'forces': array([[...]])}
>>> calculation.force[0:2].to_dict()
{'structure': {...}, 'forces': array([[[...]]])}

to_ngl

(*args, **kwargs) → NGLWidget

Convert the view to an NGL widget.

This method wraps the to_view() method and converts the resulting View to an NGL widget. The to_view() method documents all the possible arguments of this function.

Returns

NGLWidget
A widget to display the structure and other quantities in the unit cell.

to_vasp_viewer

(*args, **kwargs) → VASPViewerWidget

Convert the view to a VASP Viewer widget.

This method wraps the to_view() method and converts the resulting View to a VASP Viewer widget. The to_view() method documents all the possible arguments of this function.

Returns

VASPViewerWidget
A widget to display the structure and other quantities in the unit cell.

to_view

(supercell: int | np.ndarray = None) → View

Visualize the forces showing arrows at the atoms.

This method adds arrows to the atoms in the structure sized according to the strength of the force. The length of the arrows is scaled by a constant force_rescale to convert from eV/Å to a length in Å.

Parameters

supercell: int | np.ndarray = None
If present the structure is replicated the specified number of times along each direction.

Returns

View
Shows the structure with cell and all atoms adding arrows to the atoms sized according to the strength of the force.

Examples

First, we create some example data so that we can illustrate how to use this method. You can also use your own VASP calculation data if you have it available.

>>> from py4vasp import demo
>>> calculation = demo.calculation(path)

If you use the to_view method, 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.

>>> calculation.force.to_view()
View(..., ion_arrows=[IonArrow(quantity=array([[...]]), label='forces', ...)], ...)

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

>>> calculation.force[:].to_view()
View(..., ion_arrows=[IonArrow(quantity=array([[[...]]]), label='forces', ...)], ...)

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

>>> calculation.force[1].to_view()
View(..., ion_arrows=[IonArrow(quantity=array([[...]]), label='forces', ...)], ...)
>>> calculation.force[0:2].to_view()
View(..., ion_arrows=[IonArrow(quantity=array([[[...], [...]]]), label='forces', ...)], ...)

You may also replicate the structure by specifying a supercell.

>>> calculation.force.to_view(supercell=2)
View(..., supercell=array([2, 2, 2]), ...)

The supercell size can also be different for the different directions.

>>> calculation.force.to_view(supercell=[2,3,1])
View(..., supercell=array([2, 3, 1]), ...)