PLUGINS/LOCAL POTENTIAL: Difference between revisions

From VASP Wiki
No edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TAGDEF|PLUGINS/LOCAL_POTENTIAL| .TRUE. {{!}} .FALSE.}}
{{DISPLAYTITLE:PLUGINS/LOCAL_POTENTIAL}}
{{TAGDEF|PLUGINS/LOCAL_POTENTIAL| .True. {{!}} .False.|.False.}}


Description: {{TAG|PLUGINS/LOCAL_POTENTIAL}} calls the Python plugin for the local potential interface for each SCF step
Description: {{TAG|PLUGINS/LOCAL_POTENTIAL}} calls the Python plugin for the local potential interface for each SCF step
----
----


When {{TAG|PLUGINS/LOCAL_POTENTIAL}}=.TRUE., VASP calls the <code>local_potential</code> Python function.  
When {{TAG|PLUGINS/LOCAL_POTENTIAL}}=.TRUE., VASP calls the <code>local_potential</code> Python function at the end of each SCF step.  
See here for details on how to setup your Python script such that VASP can recognize it.
 
The primary use-case of this tag is to add a quantity on the real space grid to the local potential and a scalar quantity to the total energy of a VASP calculation through a Python plugin.
The primary use-case of this tag is to add a quantity on the real space grid to the local potential and a scalar quantity to the total energy of a VASP calculation through a Python plugin.


==Expected Inputs==
==Expected inputs==


The <code>local_potential</code> Python function expects the following inputs,
The <code>local_potential</code> Python function expects the following inputs,
    def local_potential(constants, additions):
<syntaxhighlight lang="python" line>
def local_potential(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]
<syntaxhighlight lang="python" line>
@dataclass(frozen=True)
class ConstantsLocalPotential:
     ENCUT: float
     ENCUT: float
     NELECT: float
     NELECT: float
     shape_grid: NDArray[np.int32]
     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
     ZVAL: NDArray[np.float64]
     ZVAL: DoubleArray
     charge_density: NDArray[np.float64]
     charge_density: Optional[DoubleArray] = None
     hartree_potential: NDArray[np.float64]
     hartree_potential: Optional[DoubleArray] = None
     ion_potential: NDArray[np.float64]
     ion_potential: Optional[DoubleArray] = None
     dipole_moment: NDArray[np.float64]
     dipole_moment: Optional[DoubleArray] = None
</syntaxhighlight>
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>number_ions</code> is the total number of ions listed in the {{FILE|POSCAR}} file,
<code>number_ion_types</code> is the number of ion corresponding to each ion type in the convention of the {{FILE|POSCAR}} file,
<code>ion_types</code> stores the total number of ion types,
<code>atomic_numbers</code> contains the atomic number for each atom type,
<code>lattice_vectors</code> and <code>positions</code> contain the lattice vectors and positions of the current SCF step
<code>charge_density</code>,<code>hartree_potential</code>,<code>ion_potential</code> contains the charge density, the hartree potential and the ion potential respectively on the real space grid.
<code>dipole_moment</code> stores an array with three elements consisting of the dipole moment along x, y and z cartesian directions.
{{NB| mind | The dipole moment is provided only if {{TAG|LDIPOL}}{{=}}.TRUE.}}
{{NB| mind | The dipole moment is provided only if {{TAG|LDIPOL}}{{=}}.TRUE.}}
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 AdditionsLocalPotential:
     total_energy: float
     total_energy: float
     total_potential: NDArray[np.float64]
     total_potential: 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 every real space local potential grid point,
<syntaxhighlight lang="python" line>
import numpy as np
def local_potential(constants, additions)
    additions.total_potential += np.ones(constants.shape_grid)
</syntaxhighlight>
{{WARN_PLUGINS_CONSTANTS}}


== Related tags and articles ==
[[Plugins]],
{{TAG|PLUGINS/FORCE_AND_STRESS}},
{{TAG|PLUGINS/OCCUPANCIES}},
{{TAG|PLUGINS/STRUCTURE}}


{{sc|PLUGINS/LOCAL_POTENTIAL|Examples|Examples that use this tag}}


----
[[Category:INCAR tag]]
<!--[[The_VASP_Manual|Contents]]-->
 
<!-- Link to categories like this: [[Category:INCAR]][[Category:Electronic Minimization]]
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:20, 19 December 2024

PLUGINS/LOCAL_POTENTIAL = .True. | .False.
Default: PLUGINS/LOCAL_POTENTIAL = .False. 

Description: PLUGINS/LOCAL_POTENTIAL calls the Python plugin for the local potential interface for each SCF step


When PLUGINS/LOCAL_POTENTIAL=.TRUE., VASP calls the local_potential Python function at the end of each SCF step. The primary use-case of this tag is to add a quantity on the real space grid to the local potential and a scalar quantity to the total energy of a VASP calculation through a Python plugin.

Expected inputs

The local_potential Python function expects the following inputs,

def local_potential(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 ConstantsLocalPotential:
    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
    charge_density: Optional[DoubleArray] = None
    hartree_potential: Optional[DoubleArray] = None
    ion_potential: Optional[DoubleArray] = None
    dipole_moment: 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 charge_density,hartree_potential,ion_potential contains the charge density, the hartree potential and the ion potential respectively on the real space grid. dipole_moment stores an array with three elements consisting of the dipole moment along x, y and z cartesian directions.

Mind: The dipole moment is provided only if LDIPOL=.TRUE.

The additions dataclass consists of the following modifiable outputs

@dataclass
class AdditionsLocalPotential:
    total_energy: float
    total_potential: DoubleArray

Modifying quantities

Modify the quantities listed in additions by adding to them. For example, if you wanted to add one to every real space local potential grid point,

import numpy as np
def local_potential(constants, additions)
    additions.total_potential += np.ones(constants.shape_grid)
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/FORCE_AND_STRESS, PLUGINS/OCCUPANCIES, PLUGINS/STRUCTURE

Examples that use this tag