pymatgen.io.vasp.inputs module

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]
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]
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]

json friendly dict representation of Kpoints

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 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]
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

style
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

An enumeration.

Automatic = 0
Cartesian = 4
Gamma = 1
Line_mode = 3
Monkhorst = 2
Reciprocal = 5
static from_string(s)[source]
class Orbital(n, l, j, E, occ)

Bases: tuple

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

E

Alias for field number 3

j

Alias for field number 2

l

Alias for field number 1

n

Alias for field number 0

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)

E

Alias for field number 1

Rcut

Alias for field number 3

Rcut2

Alias for field number 5

Type

Alias for field number 2

Type2

Alias for field number 4

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.

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.
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).

as_dict()[source]
classmethod from_dict(d)[source]
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.

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.

predictor_corrector
selective_dynamics
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.
site_symbols

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

velocities
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]
classmethod from_dict(d)[source]
static from_file(filename)[source]
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.
spec

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

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.

Parameters:data – Complete and single potcar file as a string.
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.

atomic_no

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

electron_configuration
element

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

static from_file(filename)[source]
static from_symbol_and_functional(symbol, functional=None)[source]
functional
functional_class
functional_dir = {'PBE': 'POT_GGA_PAW_PBE', 'PBE_52': 'POT_GGA_PAW_PBE_52', 'PBE_54': 'POT_GGA_PAW_PBE_54', 'LDA': 'POT_LDA_PAW', 'LDA_52': 'POT_LDA_PAW_52', 'LDA_54': 'POT_LDA_PAW_54', 'PW91': 'POT_GGA_PAW_PW91', 'LDA_US': 'POT_LDA_US', 'PW91_US': 'POT_GGA_US_PW91'}
functional_tags = {'pe': {'name': 'PBE', 'class': 'GGA'}, '91': {'name': 'PW91', 'class': 'GGA'}, 'rp': {'name': 'revPBE', 'class': 'GGA'}, 'am': {'name': 'AM05', 'class': 'GGA'}, 'ps': {'name': 'PBEsol', 'class': 'GGA'}, 'pw': {'name': 'PW86', 'class': 'GGA'}, 'lm': {'name': 'Langreth-Mehl-Hu', 'class': 'GGA'}, 'pb': {'name': 'Perdew-Becke', 'class': 'GGA'}, 'ca': {'name': 'Perdew-Zunger81', 'class': 'LDA'}, 'hl': {'name': 'Hedin-Lundquist', 'class': 'LDA'}, 'wi': {'name': 'Wigner Interpoloation', 'class': 'LDA'}}
get_potcar_hash()[source]
nelectrons
parse_functions = {'LULTRA': <function parse_bool>, 'LUNSCR': <function parse_bool>, 'LCOR': <function parse_bool>, 'LPAW': <function parse_bool>, 'EATOM': <function parse_float>, 'RPACOR': <function parse_float>, 'POMASS': <function parse_float>, 'ZVAL': <function parse_float>, 'RCORE': <function parse_float>, 'RWIGS': <function parse_float>, 'ENMAX': <function parse_float>, 'ENMIN': <function parse_float>, 'EMMIN': <function parse_float>, 'EAUG': <function parse_float>, 'DEXC': <function parse_float>, 'RMAX': <function parse_float>, 'RAUG': <function parse_float>, 'RDEP': <function parse_float>, 'RDEPT': <function parse_float>, 'QCUT': <function parse_float>, 'QGAM': <function parse_float>, 'RCLOC': <function parse_float>, 'IUNSCR': <function parse_int>, 'ICORE': <function parse_int>, 'NDATA': <function parse_int>, 'VRHFIN': <function parse_string>, 'LEXCH': <function parse_string>, 'TITEL': <function parse_string>, 'STEP': <function parse_list>, 'RRKJ': <function parse_list>, 'GGA': <function parse_list>}
potential_type
symbol

Symbol of POTCAR, e.g., Fe_pv

write_file(filename)[source]
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]
classmethod from_dict(d)[source]
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.
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.
parse_bool(s)[source]
parse_float(s)[source]
parse_int(s)[source]
parse_list(s)[source]
parse_string(s)[source]