Basic Usage

In this section we cover the basics of setting up a VASP calculation using the plugin. The procedure can be logically split into two steps. The first step is to set up VASP input using the VASP interface provided by the pymatgen package. In the second step these objects, together with a set of user specified output parser instructions, are passed as an input to the AiiDA calculation.

Note

The pymatgen syntax will not be covered here in great detail! - just a short use-case example will be provided. For more details on pymatgen we refer you to pymatgen documentation.

Preparing Pymatgen Input

A short example of setting up pymatgen VASP input is given below. The goal is to create: POSCAR, INPUTCAR, KPOINTS, and POTCAR files, which represent a minimal input for any VASP calculation.

An excerpt from the full code is shown below to illustrate the input setup procedure:

import numpy as np
#
# Pymatgen imports
import pymatgen as mg
from pymatgen.io import vasp as vaspio
#
# POSCAR
lattice_constant = 5.97
lattice = lattice_constant * np.array([
    [0.0, 0.5, 0.5],
    [0.5, 0.0, 0.5],
    [0.5, 0.5, 0.0]
])
lattice = mg.Lattice(lattice)

struct = mg.Structure(
    lattice,
    [Mn, Mn, Ga],
    # site coords
    [[0.00, 0.00, 0.00], [0.25, 0.25, 0.25], [0.50, 0.50, 0.50]]
)
poscar = vaspio.Poscar(struct, comment='cubic Mn2Ga')

# KPOINTS
kpoints = vaspio.Kpoints.monkhorst_automatic(
    kpts=(10, 10, 10), shift=(0.0, 0.0, 0.0)
)

Therefore, for each VASP input file we have a pymatgen object representing it, e.g. KPOINTS is represented by the pymatgen.io.vasp.Kpoints object. Our task here is just to provide basic information needed to construct the VASP input files.

Full code used for this example can be found here .

Preparing AiiDA calculation

The aim of this section is to set up a working AiiDA calculation. We will assume that all pymatgen objects representing the VASP input have already been created. Our task then is to create a VASP calculation object and pass it the content of the pymatgen input files.

Before we pass the input files to the AiiDA calculation we need to split the POSCAR file, since it may contain both dictionary and array data. This is achieved by the disassemble_poscar function which returns a dictonary of POSCAR parts. It its important to note that each of these parts is already an instance of AiiDA’s Data class and can be directly stored in the AiiDA database. The split is done like this:

# AiiDA imports
from aiida.orm import Code, DataFactory
from aiida.orm.calculation.job.vasp import vasp as vplugin
from aiida import load_dbenv
load_dbenv()

# split the poscar for AiiDA serialization
poscar_parts = vplugin.disassemble_poscar(poscar)

Note

This intermediate step represents only a transitional solution which will be improved in future versions!

The next step is to create an instance of the AiiDA VASP calculation and pass it the input files. The code to do this is shown below:

# split the poscar for AiiDA serialization
poscar_parts = vplugin.disassemble_poscar(poscar)

# === Prepare Calculation
ParameterData = DataFactory('parameter')
StructureData = DataFactory('structure')

codename = 'Vasp'  # this may be differ from user-to-user
code = Code.get(codename)  # executable to call, module imports etc

calc = code.new_calc()
calc.label = "VASP plugin development"
calc.description = "Test input plugin"
calc.set_max_wallclock_seconds(5*60)  # 5 min
calc.set_resources({
    "num_machines": 1,
    "num_mpiprocs_per_machine": 1,
    'num_cores_per_machine': 24  # this will differ from machine-to-machine
})
calc.set_withmpi(True)

calc.use_poscar(poscar_parts['poscar'])
calc.use_structure(poscar_parts['structure'])
calc.use_incar(
    ParameterData(dict=incar.as_dict())
)
calc.use_kpoints(
    ParameterData(dict=kpoints.as_dict())
)
calc.use_potcar(
    ParameterData(dict=potcar.as_dict())
)

# settings
settings = {'PARSER_INSTRUCTIONS': []}
pinstr = settings['PARSER_INSTRUCTIONS']
pinstr.append({
    'instr': 'dummy_data',
    'type': 'data',
    'params': {}
})

# additional files to return
settings.setdefault(
    'ADDITIONAL_RETRIEVE_LIST', [
        'OSZICAR',
        'CONTCAR',
        'OUTCAR',
        'vasprun.xml'
        ]
)
calc.use_settings(ParameterData(dict=settings))

The calculation can now be submitted.

What is important to notice are the calc.use_method‘s which are specific to the VASP plugin. These can be logically divided into four groups:

  • use_incar, use_potcar, use_kpoints - passed as a ParameterData object, which store the dict representation of the pymatgen object
  • use_poscar, use_structure, use_structure_extras - passed as correspondingly named objects in the poscar_parts dict, which was obtained by splitting up the POTCAR object. Note: the structure_extras in the example is not shown because this data is optional, i.e. it may contain array data that can be found in the CONTCAR file, e.g. the final velicities of ions, etc.
  • use_settings - pased as ParameterData. Used to specify additional files to retreive and output parser instructions.
  • use_chgcar, use_wavecar - passed as a SinglefileData object. See the next section for more details on using these inputs.

Full code used for this example can be found here .

CHGCAR and WAVECAR Files

The CHGCAR and WAVECAR files are usually used for continuation runs. The plugin treats them as an optional input. The SinglefileData object can be created like this:

from aiida.orm.data.singlefile import SinglefileData

input_file = SinglefileData()
input_file.set_file('path/to/the/file/CHGCAR')

The input_file now points to the actual file on the disc and will be copied to the AiiDA database when the calculation’s store_all method is called. It is important to note here that we must have an input CHACAR/WAVECAR file written at some location on the disc before we can create a SinglefileData object.

Once we have created a SinglefileData representation of the CHACAR/WAVECAR file we can pass it to AiiDA as an input like this:

chgcar = SinglefileData()
chgcar.set_file('path/to/the/file/CHGCAR')
...
calc.use_chgcar(chgcar)

and similarly for the WAVECAR file.