PLUGINS/FORCE AND STRESS: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 14: | Line 14: | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
def force_and_stress(constants, additions): | def force_and_stress(constants, additions): | ||
... | |||
</syntaxhighlight> | </syntaxhighlight> | ||
where <code>constants</code> and <code>additions</code> and [https://docs.python.org/3/library/dataclasses.html Python dataclasses]. | where <code>constants</code> and <code>additions</code> and [https://docs.python.org/3/library/dataclasses.html Python dataclasses]. | ||
| Line 63: | Line 64: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{WARN_PLUGINS_CONSTANTS}} | {{WARN_PLUGINS_CONSTANTS}} | ||
We provide a special helper class if you want to interface ASE calculators with VASP. | |||
This class makes these use cases almost trivial | |||
<syntaxhighlight lang="python" line> | |||
from vasp.force_field import AseForceField | |||
def force_and_stress(constants, additions): | |||
calculator = ... # setup your ASE calculator | |||
force_field = AseForceField(calculator) | |||
force_field.force_and_stress(constants, additions) | |||
</syntaxhighlight> | |||
== Related tags and articles == | == Related tags and articles == | ||
| Line 68: | Line 81: | ||
{{TAG|PLUGINS/LOCAL_POTENTIAL}}, | {{TAG|PLUGINS/LOCAL_POTENTIAL}}, | ||
{{TAG|PLUGINS/OCCUPANCIES}}, | {{TAG|PLUGINS/OCCUPANCIES}}, | ||
{{TAG|PLUGINS/ML_MODE}}, | |||
{{TAG|PLUGINS/NEIGHBOR_CUTOFF}}, | |||
{{TAG|PLUGINS/STRUCTURE}} | {{TAG|PLUGINS/STRUCTURE}} | ||
Latest revision as of 10:06, 16 March 2026
PLUGINS/FORCE_AND_STRESS = .True. | .False.
Default: PLUGINS/FORCE_AND_STRESS = .False.
Description: PLUGINS/FORCE_AND_STRESS calls the Python plugin for the force and stress interface for each ionic relaxation step
When PLUGINS/FORCE_AND_STRESS=.TRUE., VASP calls the force_and_stress Python function at the end of each ionic relaxation step.
You can use this tag to modify forces and the stress tensor to be consistent with modifications to the potential performed with PLUGINS/LOCAL_POTENTIAL.
Furthermore, you could implement new force corrections like van-der-Waals functionals or use it to run a machine-learned interatomic potential as the force engine in VASP.
Usually the forces and stress are added to ones obtained by VASP, but you can set PLUGINS/ML_MODE to overwrite them instead.
Expected inputs
The force_and_stress Python function expects the following inputs,
def force_and_stress(constants, additions):
...
where constants and additions and Python dataclasses.
The constants dataclass consists of the following inputs, listed here with their associated datatypes
@dataclass(frozen=True)
class ConstantsForceAndStress:
ENCUT: float
NELECT: float
shape_grid: IntArray
number_ions: int
number_ion_types: int
ion_types: IndexArray
atomic_numbers: IntArray
lattice_vectors: DoubleArray
positions: DoubleArray
ZVAL: DoubleArray
POMASS: DoubleArray
forces: DoubleArray
stress: DoubleArray
charge_density: Optional[DoubleArray] = None
neighbor_list: List[Neighbors] = field(default_factory=list)
Note that the INCAR tags are capitalized.
shape_grid is a three dimensional integer array which stores the shape of the real space grid, NGXF, NGYF and NGZF,
number_ions is the total number of ions listed in the POSCAR file,
number_ion_types is the number of ion corresponding to each ion type in the convention of the POSCAR file,
ion_types stores the total number of ion types,
atomic_numbers contains the atomic number for each atom type,
lattice_vectors and positions contain the lattice vectors and positions of the current SCF step
forces and stress are the computed forces and stress tensor and charge_density contains the charge density on the real space grid.
neighbor_list contains a list of all neighbors near an atom up to a cutoff PLUGINS/NEIGHBOR_CUTOFF.
The additions dataclass consists of the following modifiable outputs
@dataclass
class AdditionsForceAndStress:
total_energy: float
forces: DoubleArray
stress: DoubleArray
Modifying quantities
Modify the quantities listed in additions by adding to them. For example, if you wanted to add one to the forces
import numpy as np
def force_and_stress(constants, additions)
additions.forces += np.ones((constants.number_ions,3))
Warning: You should not make modifications to quantities in constants. We implemented some safeguards to prevent accidental modifications. Intentional changes will lead to erratic behavior because we may change the VASP code assuming these quantities are constant.
|
We provide a special helper class if you want to interface ASE calculators with VASP. This class makes these use cases almost trivial
from vasp.force_field import AseForceField
def force_and_stress(constants, additions):
calculator = ... # setup your ASE calculator
force_field = AseForceField(calculator)
force_field.force_and_stress(constants, additions)
Related tags and articles
Plugins, PLUGINS/LOCAL_POTENTIAL, PLUGINS/OCCUPANCIES, PLUGINS/ML_MODE, PLUGINS/NEIGHBOR_CUTOFF, PLUGINS/STRUCTURE