pymatgen.io.vasp.inputs module

Classes for reading/manipulating/writing VASP input files. All major VASP input files.

exception BadIncarWarning[source]

Bases: UserWarning

Warning class for bad Incar parameters.

class Incar(params=None)[source]

Bases: dict, monty.json.MSONable

INCAR object for reading and writing INCAR files. Essentially consists of a dictionary with some helper functions

Creates an Incar object.

Parameters

params (dict) – A set of input parameters as a dictionary.

as_dict()[source]
Returns

MSONable dict.

check_params()[source]

Raises a warning for nonsensical or non-existant INCAR tags and parameters. If a keyword doesn’t exist (e.g. theres a typo in a keyword), your calculation will still run, however VASP will igore the parameter without letting you know, hence why we have this Incar method.

diff(other)[source]

Diff function for Incar. Compares two Incars and indicates which parameters are the same and which are not. Useful for checking whether two runs were done using the same parameters.

Parameters

other (Incar) – The other Incar object to compare to.

Returns

{“Same” : parameters_that_are_the_same, “Different”: parameters_that_are_different} Note that the parameters are return as full dictionaries of values. E.g. {“ISIF”:3}

Return type

Dict of the following format

classmethod from_dict(d)[source]
Parameters

d – Dict representation.

Returns

Incar

static from_file(filename)[source]

Reads an Incar object from a file.

Parameters

filename (str) – Filename for file

Returns

Incar object

static from_string(string)[source]

Reads an Incar object from a string.

Parameters

string (str) – Incar string

Returns

Incar object

get_string(sort_keys=False, pretty=False)[source]

Returns a string representation of the INCAR. The reason why this method is different from the __str__ method is to provide options for pretty printing.

Parameters
  • sort_keys (bool) – Set to True to sort the INCAR parameters alphabetically. Defaults to False.

  • pretty (bool) – Set to True for pretty aligned output. Defaults to False.

static proc_val(key, val)[source]

Static helper method to convert INCAR parameters to proper types, e.g., integers, floats, lists, etc.

Parameters
  • key – INCAR parameter key

  • val – Actual value of INCAR parameter.

write_file(filename)[source]

Write Incar to a file.

Parameters

filename (str) – filename to write to.

class Kpoints(comment='Default gamma', num_kpts=0, style=<Kpoints_supported_modes.Gamma: 1>, kpts=((1, 1, 1), ), kpts_shift=(0, 0, 0), kpts_weights=None, coord_type=None, labels=None, tet_number=0, tet_weight=0, tet_connections=None)[source]

Bases: monty.json.MSONable

KPOINT reader/writer.

Highly flexible constructor for Kpoints object. The flexibility comes at the cost of usability and in general, it is recommended that you use the default constructor only if you know exactly what you are doing and requires the flexibility. For most usage cases, the three automatic schemes can be constructed far more easily using the convenience static constructors (automatic, gamma_automatic, monkhorst_automatic) and it is recommended that you use those.

Parameters
  • comment (str) – String comment for Kpoints

  • num_kpts – Following VASP method of defining the KPOINTS file, this parameter is the number of kpoints specified. If set to 0 (or negative), VASP automatically generates the KPOINTS.

  • style – Style for generating KPOINTS. Use one of the Kpoints.supported_modes enum types.

  • kpts (2D array) – 2D array of kpoints. Even when only a single specification is required, e.g. in the automatic scheme, the kpts should still be specified as a 2D array. e.g., [[20]] or [[2,2,2]].

  • kpts_shift (3x1 array) – Shift for Kpoints.

  • kpts_weights – Optional weights for kpoints. Weights should be integers. For explicit kpoints.

  • coord_type – In line-mode, this variable specifies whether the Kpoints were given in Cartesian or Reciprocal coordinates.

  • labels – In line-mode, this should provide a list of labels for each kpt. It is optional in explicit kpoint mode as comments for k-points.

  • tet_number – For explicit kpoints, specifies the number of tetrahedrons for the tetrahedron method.

  • tet_weight – For explicit kpoints, specifies the weight for each tetrahedron for the tetrahedron method.

  • tet_connections – For explicit kpoints, specifies the connections of the tetrahedrons for the tetrahedron method. Format is a list of tuples, [ (sym_weight, [tet_vertices]), …]

The default behavior of the constructor is for a Gamma centered, 1x1x1 KPOINTS with no shift.

as_dict()[source]
Returns

MSONable dict.

static automatic(subdivisions)[source]

Convenient static constructor for a fully automatic Kpoint grid, with gamma centered Monkhorst-Pack grids and the number of subdivisions along each reciprocal lattice vector determined by the scheme in the VASP manual.

Parameters

subdivisions – Parameter determining number of subdivisions along each reciprocal lattice vector.

Returns

Kpoints object

static automatic_density(structure, kppa, force_gamma=False)[source]

Returns an automatic Kpoint object based on a structure and a kpoint density. Uses Gamma centered meshes for hexagonal cells and Monkhorst-Pack grids otherwise.

Algorithm:

Uses a simple approach scaling the number of divisions along each reciprocal lattice vector proportional to its length.

Parameters
  • structure (Structure) – Input structure

  • kppa (int) – Grid density

  • force_gamma (bool) – Force a gamma centered mesh (default is to use gamma only for hexagonal cells or odd meshes)

Returns

Kpoints

static automatic_density_by_vol(structure, kppvol, force_gamma=False)[source]

Returns an automatic Kpoint object based on a structure and a kpoint density per inverse Angstrom^3 of reciprocal cell.

Algorithm:

Same as automatic_density()

Parameters
  • structure (Structure) – Input structure

  • kppvol (int) – Grid density per Angstrom^(-3) of reciprocal cell

  • force_gamma (bool) – Force a gamma centered mesh

Returns

Kpoints

static automatic_gamma_density(structure, kppa)[source]

Returns an automatic Kpoint object based on a structure and a kpoint density. Uses Gamma centered meshes always. For GW.

Algorithm:

Uses a simple approach scaling the number of divisions along each reciprocal lattice vector proportional to its length.

Parameters
  • structure – Input structure

  • kppa – Grid density

static automatic_linemode(divisions, ibz)[source]

Convenient static constructor for a KPOINTS in mode line_mode. gamma centered Monkhorst-Pack grids and the number of subdivisions along each reciprocal lattice vector determined by the scheme in the VASP manual.

Parameters
  • divisions – Parameter determining the number of k-points along each hight symetry lines.

  • ibz – HighSymmKpath object (pymatgen.symmetry.bandstructure)

Returns

Kpoints object

classmethod from_dict(d)[source]
Parameters

d – Dict representation.

Returns

Kpoints

static from_file(filename)[source]

Reads a Kpoints object from a KPOINTS file.

Parameters

filename (str) – filename to read from.

Returns

Kpoints object

static from_string(string)[source]

Reads a Kpoints object from a KPOINTS string.

Parameters

string (str) – KPOINTS string.

Returns

Kpoints object

static gamma_automatic(kpts=(1, 1, 1), shift=(0, 0, 0))[source]

Convenient static constructor for an automatic Gamma centered Kpoint grid.

Parameters
  • kpts – Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors. Defaults to (1,1,1)

  • shift – Shift to be applied to the kpoints. Defaults to (0,0,0).

Returns

Kpoints object

static monkhorst_automatic(kpts=(2, 2, 2), shift=(0, 0, 0))[source]

Convenient static constructor for an automatic Monkhorst pack Kpoint grid.

Parameters
  • kpts – Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors. Defaults to (2,2,2)

  • shift – Shift to be applied to the kpoints. Defaults to (0,0,0).

Returns

Kpoints object

property style

Style for kpoint generation. One of Kpoints_supported_modes enum.

Type

return

supported_modes

alias of Kpoints_supported_modes

write_file(filename)[source]

Write Kpoints to a file.

Parameters

filename (str) – Filename to write to.

class Kpoints_supported_modes[source]

Bases: enum.Enum

Enum type of all supported modes for Kpoint generation.

Automatic = 0
Cartesian = 4
Gamma = 1
Line_mode = 3
Monkhorst = 2
Reciprocal = 5
from_string = <function Kpoints_supported_modes.from_string>[source]
class Orbital(n, l, j, E, occ)

Bases: tuple

Create new instance of Orbital(n, l, j, E, occ)

property E

Alias for field number 3

property j

Alias for field number 2

property l

Alias for field number 1

property n

Alias for field number 0

property occ

Alias for field number 4

class OrbitalDescription(l, E, Type, Rcut, Type2, Rcut2)

Bases: tuple

Create new instance of OrbitalDescription(l, E, Type, Rcut, Type2, Rcut2)

property E

Alias for field number 1

property Rcut

Alias for field number 3

property Rcut2

Alias for field number 5

property Type

Alias for field number 2

property Type2

Alias for field number 4

property l

Alias for field number 0

class Poscar(structure, comment=None, selective_dynamics=None, true_names=True, velocities=None, predictor_corrector=None, predictor_corrector_preamble=None)[source]

Bases: monty.json.MSONable

Object for representing the data in a POSCAR or CONTCAR file. Please note that this current implementation. Most attributes can be set directly.

structure

Associated Structure.

comment

Optional comment string.

true_names

Boolean indication whether Poscar contains actual real names parsed from either a POTCAR or the POSCAR itself.

selective_dynamics

Selective dynamics attribute for each site if available. A Nx3 array of booleans.

velocities

Velocities for each site (typically read in from a CONTCAR). A Nx3 array of floats.

predictor_corrector

Predictor corrector coordinates and derivatives for each site; i.e. a list of three 1x3 arrays for each site (typically read in from a MD CONTCAR).

predictor_corrector_preamble

Predictor corrector preamble contains the predictor-corrector key, POTIM, and thermostat parameters that precede the site-specic predictor corrector data in MD CONTCAR

temperature

Temperature of velocity Maxwell-Boltzmann initialization. Initialized to -1 (MB hasn”t been performed).

Parameters
  • structure (Structure) – Structure object.

  • comment (str) – Optional comment line for POSCAR. Defaults to unit cell formula of structure. Defaults to None.

  • selective_dynamics (Nx3 array) – bool values for selective dynamics, where N is number of sites. Defaults to None.

  • true_names (bool) – Set to False is the names in the POSCAR are not well-defined and ambiguous. This situation arises commonly in vasp < 5 where the POSCAR sometimes does not contain element symbols. Defaults to True.

  • velocities (Nx3 array) – Velocities for the POSCAR. Typically parsed in MD runs or can be used to initialize velocities.

  • predictor_corrector (Nx3 array) – Predictor corrector for the POSCAR. Typically parsed in MD runs.

as_dict()[source]
Returns

MSONable dict.

classmethod from_dict(d)[source]
Parameters

d – Dict representation.

Returns

Poscar

static from_file(filename, check_for_POTCAR=True, read_velocities=True)[source]

Reads a Poscar from a file.

The code will try its best to determine the elements in the POSCAR in the following order:

1. If check_for_POTCAR is True, the code will try to check if a POTCAR is in the same directory as the POSCAR and use elements from that by default. (This is the VASP default sequence of priority). 2. If the input file is Vasp5-like and contains element symbols in the 6th line, the code will use that if check_for_POTCAR is False or there is no POTCAR found. 3. Failing (2), the code will check if a symbol is provided at the end of each coordinate.

If all else fails, the code will just assign the first n elements in increasing atomic number, where n is the number of species, to the Poscar. For example, H, He, Li, …. This will ensure at least a unique element is assigned to each site and any analysis that does not require specific elemental properties should work fine.

Parameters
  • filename (str) – File name containing Poscar data.

  • check_for_POTCAR (bool) – Whether to check if a POTCAR is present in the same directory as the POSCAR. Defaults to True.

  • read_velocities (bool) – Whether to read or not velocities if they are present in the POSCAR. Default is True.

Returns

Poscar object.

static from_string(data, default_names=None, read_velocities=True)[source]

Reads a Poscar from a string.

The code will try its best to determine the elements in the POSCAR in the following order:

1. If default_names are supplied and valid, it will use those. Usually, default names comes from an external source, such as a POTCAR in the same directory.

2. If there are no valid default names but the input file is Vasp5-like and contains element symbols in the 6th line, the code will use that.

3. Failing (2), the code will check if a symbol is provided at the end of each coordinate.

If all else fails, the code will just assign the first n elements in increasing atomic number, where n is the number of species, to the Poscar. For example, H, He, Li, …. This will ensure at least a unique element is assigned to each site and any analysis that does not require specific elemental properties should work fine.

Parameters
  • data (str) – String containing Poscar data.

  • default_names ([str]) – Default symbols for the POSCAR file, usually coming from a POTCAR in the same directory.

  • read_velocities (bool) – Whether to read or not velocities if they are present in the POSCAR. Default is True.

Returns

Poscar object.

get_string(direct=True, vasp4_compatible=False, significant_figures=6)[source]

Returns a string to be written as a POSCAR file. By default, site symbols are written, which means compatibility is for vasp >= 5.

Parameters
  • direct (bool) – Whether coordinates are output in direct or cartesian. Defaults to True.

  • vasp4_compatible (bool) – Set to True to omit site symbols on 6th line to maintain backward vasp 4.x compatibility. Defaults to False.

  • significant_figures (int) – No. of significant figures to output all quantities. Defaults to 6. Note that positions are output in fixed point, while velocities are output in scientific format.

Returns

String representation of POSCAR.

property natoms

Sequence of number of sites of each type associated with the Poscar. Similar to 7th line in vasp 5+ POSCAR or the 6th line in vasp 4 POSCAR.

property predictor_corrector

Predictor corrector in Poscar

property selective_dynamics

Selective dynamics in Poscar

set_temperature(temperature)[source]

Initializes the velocities based on Maxwell-Boltzmann distribution. Removes linear, but not angular drift (same as VASP)

Scales the energies to the exact temperature (microcanonical ensemble) Velocities are given in A/fs. This is the vasp default when direct/cartesian is not specified (even when positions are given in direct coordinates)

Overwrites imported velocities, if any.

Parameters

temperature (float) – Temperature in Kelvin.

property site_symbols

Sequence of symbols associated with the Poscar. Similar to 6th line in vasp 5+ POSCAR.

property velocities

Velocities in Poscar

write_file(filename, **kwargs)[source]

Writes POSCAR to a file. The supported kwargs are the same as those for the Poscar.get_string method and are passed through directly.

class Potcar(symbols=None, functional=None, sym_potcar_map=None)[source]

Bases: list, monty.json.MSONable

Object for reading and writing POTCAR files for calculations. Consists of a list of PotcarSingle.

Parameters
  • symbols ([str]) – Element symbols for POTCAR. This should correspond to the symbols used by VASP. E.g., “Mg”, “Fe_pv”, etc.

  • functional (str) – Functional used. To know what functional options there are, use Potcar.FUNCTIONAL_CHOICES. Note that VASP has different versions of the same functional. By default, the old PBE functional is used. If you want the newer ones, use PBE_52 or PBE_54. Note that if you intend to compare your results with the Materials Project, you should use the default setting. You can also override the default by setting PMG_DEFAULT_FUNCTIONAL in your .pmgrc.yaml.

  • sym_potcar_map (dict) – Allows a user to specify a specific element symbol to raw POTCAR mapping.

FUNCTIONAL_CHOICES = ['PBE', 'PBE_52', 'PBE_54', 'LDA', 'LDA_52', 'LDA_54', 'PW91', 'LDA_US', 'PW91_US']
as_dict()[source]
Returns

MSONable dict representation

classmethod from_dict(d)[source]
Parameters

d – Dict representation

Returns

Potcar

static from_file(filename: str)[source]

Reads Potcar from file.

Parameters

filename – Filename

Returns

Potcar

set_symbols(symbols, functional=None, sym_potcar_map=None)[source]

Initialize the POTCAR from a set of symbols. Currently, the POTCARs can be fetched from a location specified in .pmgrc.yaml. Use pmg config to add this setting.

Parameters
  • symbols ([str]) – A list of element symbols

  • functional (str) – The functional to use. If None, the setting PMG_DEFAULT_FUNCTIONAL in .pmgrc.yaml is used, or if this is not set, it will default to PBE.

  • sym_potcar_map (dict) – A map of symbol:raw POTCAR string. If sym_potcar_map is specified, POTCARs will be generated from the given map data rather than the config file location.

property spec

Get the atomic symbols and hash of all the atoms in the POTCAR file.

property symbols

Get the atomic symbols of all the atoms in the POTCAR file.

write_file(filename)[source]

Write Potcar to a file.

Parameters

filename (str) – filename to write to.

class PotcarSingle(data)[source]

Bases: object

Object for a single POTCAR. The builder assumes the complete string is the POTCAR contains the complete untouched data in “data” as a string and a dict of keywords.

data

POTCAR data as a string.

keywords

Keywords parsed from the POTCAR as a dict. All keywords are also accessible as attributes in themselves. E.g., potcar.enmax, potcar.encut, etc.

Parameters

data – Complete and single potcar file as a string.

property atomic_no

Attempt to return the atomic number based on the VRHFIN keyword.

property electron_configuration

Electronic configuration of the PotcarSingle.

Type

return

property element

Attempt to return the atomic symbol based on the VRHFIN keyword.

static from_file(filename: str) → pymatgen.io.vasp.inputs.PotcarSingle[source]

Reads PotcarSingle from file.

Parameters

filename – Filename.

Returns

PotcarSingle.

static from_symbol_and_functional(symbol: str, functional: str = None)[source]

Makes a PotcarSingle from a symbol and functional.

Parameters
  • symbol – Symbol, e.g., Li_sv

  • functional – E.g., PBE

Returns

PotcarSingle

property functional

Functional associated with PotcarSingle.

Type

return

property functional_class

Functional class associated with PotcarSingle.

Type

return

functional_dir = {'LDA': 'POT_LDA_PAW', 'LDA_52': 'POT_LDA_PAW_52', 'LDA_54': 'POT_LDA_PAW_54', 'LDA_US': 'POT_LDA_US', 'PBE': 'POT_GGA_PAW_PBE', 'PBE_52': 'POT_GGA_PAW_PBE_52', 'PBE_54': 'POT_GGA_PAW_PBE_54', 'PW91': 'POT_GGA_PAW_PW91', 'PW91_US': 'POT_GGA_US_PW91'}
functional_tags = {'91': {'class': 'GGA', 'name': 'PW91'}, 'am': {'class': 'GGA', 'name': 'AM05'}, 'ca': {'class': 'LDA', 'name': 'Perdew-Zunger81'}, 'hl': {'class': 'LDA', 'name': 'Hedin-Lundquist'}, 'lm': {'class': 'GGA', 'name': 'Langreth-Mehl-Hu'}, 'pb': {'class': 'GGA', 'name': 'Perdew-Becke'}, 'pe': {'class': 'GGA', 'name': 'PBE'}, 'ps': {'class': 'GGA', 'name': 'PBEsol'}, 'pw': {'class': 'GGA', 'name': 'PW86'}, 'rp': {'class': 'GGA', 'name': 'revPBE'}, 'wi': {'class': 'LDA', 'name': 'Wigner Interpoloation'}}
get_potcar_hash()[source]

Computes a hash for the PotcarSingle.

Returns

Hash value.

property nelectrons

Number of electrons

Type

return

parse_functions = {'DEXC': <function _parse_float>, 'EATOM': <function _parse_float>, 'EAUG': <function _parse_float>, 'EMMIN': <function _parse_float>, 'ENMAX': <function _parse_float>, 'ENMIN': <function _parse_float>, 'GGA': <function _parse_list>, 'ICORE': <function _parse_int>, 'IUNSCR': <function _parse_int>, 'LCOR': <function _parse_bool>, 'LEXCH': <function _parse_string>, 'LPAW': <function _parse_bool>, 'LULTRA': <function _parse_bool>, 'LUNSCR': <function _parse_bool>, 'NDATA': <function _parse_int>, 'POMASS': <function _parse_float>, 'QCUT': <function _parse_float>, 'QGAM': <function _parse_float>, 'RAUG': <function _parse_float>, 'RCLOC': <function _parse_float>, 'RCORE': <function _parse_float>, 'RDEP': <function _parse_float>, 'RDEPT': <function _parse_float>, 'RMAX': <function _parse_float>, 'RPACOR': <function _parse_float>, 'RRKJ': <function _parse_list>, 'RWIGS': <function _parse_float>, 'STEP': <function _parse_list>, 'TITEL': <function _parse_string>, 'VRHFIN': <function _parse_string>, 'ZVAL': <function _parse_float>}
property potential_type

Type of PSP. E.g., US, PAW, etc.

Type

return

property symbol

Symbol of POTCAR, e.g., Fe_pv

write_file(filename: str) → None[source]

Writes PotcarSingle to a file. :param filename: Filename

class VaspInput(incar, kpoints, poscar, potcar, optional_files=None, **kwargs)[source]

Bases: dict, monty.json.MSONable

Class to contain a set of vasp input objects corresponding to a run.

Parameters
  • incar – Incar object.

  • kpoints – Kpoints object.

  • poscar – Poscar object.

  • potcar – Potcar object.

  • optional_files – Other input files supplied as a dict of { filename: object}. The object should follow standard pymatgen conventions in implementing a as_dict() and from_dict method.

as_dict()[source]
Returns

MSONable dict.

classmethod from_dict(d)[source]
Parameters

d – Dict representation.

Returns

VaspInput

static from_directory(input_dir, optional_files=None)[source]

Read in a set of VASP input from a directory. Note that only the standard INCAR, POSCAR, POTCAR and KPOINTS files are read unless optional_filenames is specified.

Parameters
  • input_dir (str) – Directory to read VASP input from.

  • optional_files (dict) – Optional files to read in as well as a dict of {filename: Object type}. Object type must have a static method from_file.

run_vasp(run_dir: Union[str, pathlib.Path] = '.', vasp_cmd: list = None, output_file: Union[str, pathlib.Path] = 'vasp.out', err_file: Union[str, pathlib.Path] = 'vasp.err')[source]

Write input files and run VASP.

Parameters
  • run_dir – Where to write input files and do the run.

  • vasp_cmd – Args to be supplied to run VASP. Otherwise, the PMG_VASP_EXE in .pmgrc.yaml is used.

  • output_file – File to write output.

  • err_file – File to write err.

write_input(output_dir='.', make_dir_if_not_present=True)[source]

Write VASP input to a directory.

Parameters
  • output_dir (str) – Directory to write to. Defaults to current directory (“.”).

  • make_dir_if_not_present (bool) – Create the directory if not present. Defaults to True.