PLUGINS/FORCE AND STRESS: Difference between revisions

From VASP Wiki
(Created page with "{{TAGDEF|PLUGINS/FORCE_AND_STRESS| .TRUE. {{!}} .FALSE.}} Description: {{TAG|PLUGINS/FORCE_AND_STRESS}} calls the Python plugin for the force and stress interface for each ionic relaxation step ---- When {{TAG|PLUGINS/FORCE_AND_STRESS}}=.TRUE., VASP calls the <code>force_and_stress</code> Python function at the end of each ionic relaxation step. The primary use-case of this tag is to modify forces and the stress tensor to be consistent with modifications to the potent...")
 
No edit summary
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TAGDEF|PLUGINS/FORCE_AND_STRESS| .TRUE. {{!}} .FALSE.}}
{{TAGDEF|PLUGINS/FORCE_AND_STRESS| .True. {{!}} .False.|.False.}}


Description: {{TAG|PLUGINS/FORCE_AND_STRESS}} calls the Python plugin for the force and stress interface for each ionic relaxation step
Description: {{TAG|PLUGINS/FORCE_AND_STRESS}} calls the Python plugin for the force and stress interface for each ionic relaxation step
Line 5: Line 5:


When {{TAG|PLUGINS/FORCE_AND_STRESS}}=.TRUE., VASP calls the <code>force_and_stress</code> Python function at the end of each ionic relaxation step.  
When {{TAG|PLUGINS/FORCE_AND_STRESS}}=.TRUE., VASP calls the <code>force_and_stress</code> Python function at the end of each ionic relaxation step.  
The primary use-case of this tag is to modify forces and the stress tensor to be consistent with modifications to the potential performed with {{TAG|PLUGINS/LOCAL_POTENTIAL}}
You can use this tag to modify forces and the stress tensor to be consistent with modifications to the potential performed with {{TAG|PLUGINS/LOCAL_POTENTIAL}}.
Furthermore, you could implement new force corrections like van-der-Waals functionals.


==Expected inputs==
==Expected inputs==


The <code>force_and_stress</code> Python function expects the following inputs,
The <code>force_and_stress</code> Python function expects the following inputs,
    def force_and_stress(constants, additions):
<syntaxhighlight lang="python" line>
def force_and_stress(constants, additions):
</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].
The <code>constants</code> dataclass consists of the following inputs, listed here with their associated [https://numpy.org/doc/stable/user/basics.types.html datatypes]
The <code>constants</code> dataclass consists of the following inputs, listed here with their associated [https://numpy.org/doc/stable/user/basics.types.html datatypes]
     {{TAGBL|ENCUT}}: float
<syntaxhighlight lang="python" line>
     {{TAGBL|NELECT}}: float
@dataclass(frozen=True)
     shape_grid: NDArray[np.int32]
class ConstantsForceAndStress:
     ENCUT: float
     NELECT: float
     shape_grid: IntArray
     number_ions: int
     number_ions: int
     number_ion_types: int
     number_ion_types: int
     ion_types: NDArray[np.int32]
     ion_types: IndexArray
     atomic_numbers: NDArray[np.int32]
     atomic_numbers: IntArray
     lattice_vectors: NDArray[np.float64]
     lattice_vectors: DoubleArray
     positions: NDArray[np.float64]
     positions: DoubleArray
     {{TAGBL|ZVAL}}: NDArray[np.float64]
     ZVAL: DoubleArray
     {{TAGBL|POMASS}}: NDArray[np.float64]
     POMASS: DoubleArray
     forces: NDArray[np.float64]
     forces: DoubleArray
     stress: NDArray[np.float64]
     stress: DoubleArray
     charge_density: NDArray[np.float64]
     charge_density: Optional[DoubleArray] = None
</syntaxhighlight>
Note that the {{FILE|INCAR}} tags are capitalized.
Note that the {{FILE|INCAR}} tags are capitalized.
<code>shape_grid</code> is a three dimensional integer array which stores the shape of the real space grid, {{TAG|NGXF}}, {{TAG|NGYF}} and {{TAG|NGZF}},
<code>shape_grid</code> is a three dimensional integer array which stores the shape of the real space grid, {{TAG|NGXF}}, {{TAG|NGYF}} and {{TAG|NGZF}},
Line 35: Line 42:
<code>lattice_vectors</code> and <code>positions</code> contain the lattice vectors and positions of the current SCF step
<code>lattice_vectors</code> and <code>positions</code> contain the lattice vectors and positions of the current SCF step
<code>forces</code> and <code>stress</code> are the computed forces and stress tensor and <code>charge_density</code> contains the charge density on the real space grid.
<code>forces</code> and <code>stress</code> are the computed forces and stress tensor and <code>charge_density</code> contains the charge density on the real space grid.
The <code>additions</code> dataclass consists of the following modifiable outputs
The <code>additions</code> dataclass consists of the following modifiable outputs
<syntaxhighlight lang="python" line>
@dataclass
class AdditionsForceAndStress:
     total_energy: float
     total_energy: float
     forces: NDArray[np.float64]
     forces: DoubleArray
     stress: NDArray[np.float64]
     stress: DoubleArray
</syntaxhighlight>


==Modifying quantities==
==Modifying quantities==
Modify the quantities listed in additions by adding to them. For example, if you wanted to add one to the forces
Modify the quantities listed in additions by adding to them. For example, if you wanted to add one to the forces
    def force_and_stress(constants, additions)
<syntaxhighlight lang="python" line>
        additions.forces += np.ones((constants.number_ions,3))
import numpy as np
{{NB| mind | You may not make modifications to quantities in <code>constants</code>}}
def force_and_stress(constants, additions)
    additions.forces += np.ones((constants.number_ions,3))
</syntaxhighlight>
{{WARN_PLUGINS_CONSTANTS}}


----
== Related tags and articles ==
<!--[[The_VASP_Manual|Contents]]-->
[[Plugins]],
{{TAG|PLUGINS/LOCAL_POTENTIAL}},
{{TAG|PLUGINS/MACHINE_LEARNING}},
{{TAG|PLUGINS/OCCUPANCIES}},
{{TAG|PLUGINS/STRUCTURE}}
 
{{sc|PLUGINS/FORCE_AND_STRESS|Examples|Examples that use this tag}}


<!-- Link to categories like this: [[Category:INCAR]][[Category:Electronic Minimization]]
[[Category:INCAR tag]]
only comment it out when you want the page to show up on the category page, i.e., not when it is in the Construction namespace.-->

Latest revision as of 08:19, 19 December 2024

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.

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

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.

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.

Related tags and articles

Plugins, PLUGINS/LOCAL_POTENTIAL, PLUGINS/MACHINE_LEARNING, PLUGINS/OCCUPANCIES, PLUGINS/STRUCTURE

Examples that use this tag