Plugins: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Implementing features over VASP carries a somewhat significant overhead, both in term of code development and maintenance. An alternative approach is to use our Plugin infrastructure. Simply write [https://www.python.org/ Python] functions in a pre-defined format and VASP will recognize and execute your code while it is running. This page describes the steps that you will need to write your first Python script and link it with VASP. | Implementing features over VASP carries a somewhat significant overhead, both in term of code development and maintenance. | ||
An alternative approach is to use our Plugin infrastructure. Simply write [https://www.python.org/ Python] functions in a pre-defined format and VASP will recognize and execute your code while it is running. | |||
This page describes the steps that you will need to write your first Python script and link it with VASP. | |||
==Installation== | ==Installation== | ||
Line 18: | Line 20: | ||
==Run-time instructions== | ==Run-time instructions== | ||
When running VASP with the python interface you will need to add the <code>lib</code> directory of your python to <code>LD_LIBRARY_PATH</code>. You can do this somewhat easily with <code>conda</code> by running <code>python3-config --ldflags</code>, followed by | When running VASP with the python interface you will need to add the <code>lib</code> directory of your python to <code>LD_LIBRARY_PATH</code>. | ||
You can do this somewhat easily with <code>conda</code> by running <code>python3-config --ldflags</code>, followed by | |||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path-from-earlier-command> | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path-from-earlier-command> | ||
==Python Scripting== | |||
Start by creating a file called <code>vasp_plugin.py</code> in the folder in which you are running a VASP calculation. | |||
An alternative route through entry-points is also possible (see below for further instructions). | |||
The relevant lines of python code to access data from vasp through the any of the interfaces listed above are: | |||
def local_potential(constants, additions): | |||
"""Defines the PLUGINS/LOCAL_POTENTIAL interface""" | |||
def force_and_stress(constants, additions): | |||
"""Defines the PLUGINS/FORCE_AND_STRESS interface""" | |||
def structure(constants, additions): | |||
"""Defines the PLUGINS/STRUCTURE interface""" | |||
def occupancies(constants, additions): | |||
"""Defines the PLUGINS/OCCUPANCIES interface""" |
Revision as of 08:47, 11 June 2024
Implementing features over VASP carries a somewhat significant overhead, both in term of code development and maintenance. An alternative approach is to use our Plugin infrastructure. Simply write Python functions in a pre-defined format and VASP will recognize and execute your code while it is running. This page describes the steps that you will need to write your first Python script and link it with VASP.
Installation
Create a new conda environment.
conda create -n vasp_plugin python=3.10
Enter the create vasp_plugin
conda environment
conda activate vasp_plugin
Navigate to the plugins
directory within VASP source code,
cd </path/to/vasp/source/code>/src/plugins
Install the VASP Python package through pip
pip install .
Add the following lines to your makefile.include
CPP_OPTIONS+= -DPLUGINS LLIBS += $(shell python3-config --ldflags --embed) -lstdc++ CXX_FLAGS = -Wall -Wextra $(shell python3 -m pybind11 --includes) -std=c++11
Compile VASP using the guide to installing VASP.6.X.X
Mind: Make sure to be within the conda environment when you compile VASP. |
Run-time instructions
When running VASP with the python interface you will need to add the lib
directory of your python to LD_LIBRARY_PATH
.
You can do this somewhat easily with conda
by running python3-config --ldflags
, followed by
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path-from-earlier-command>
Python Scripting
Start by creating a file called vasp_plugin.py
in the folder in which you are running a VASP calculation.
An alternative route through entry-points is also possible (see below for further instructions).
The relevant lines of python code to access data from vasp through the any of the interfaces listed above are:
def local_potential(constants, additions): """Defines the PLUGINS/LOCAL_POTENTIAL interface"""
def force_and_stress(constants, additions): """Defines the PLUGINS/FORCE_AND_STRESS interface"""
def structure(constants, additions): """Defines the PLUGINS/STRUCTURE interface"""
def occupancies(constants, additions): """Defines the PLUGINS/OCCUPANCIES interface"""