pymatgen.io.vasp.inputs module¶
Classes for reading/manipulating/writing VASP input files. All major VASP input files.
-
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.
-
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
-
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.
-
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.
-
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
-
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
[source]¶ Style for kpoint generation. One of Kpoints_supported_modes enum.
- Type
return
-
supported_modes
[source]¶ alias of
Kpoints_supported_modes
-
class
Kpoints_supported_modes
(value)[source]¶ Bases:
enum.Enum
Enum type of all supported modes for Kpoint generation.
-
static
from_string
(s: str) → pymatgen.io.vasp.inputs.Kpoints_supported_modes[source]¶ - Parameters
s – String
- Returns
Kpoints_supported_modes
-
static
-
class
Orbital
(n, l, j, E, occ)[source]¶ Bases:
tuple
Create new instance of Orbital(n, l, j, E, occ)
-
class
OrbitalDescription
(l, E, Type, Rcut, Type2, Rcut2)[source]¶ Bases:
tuple
Create new instance of OrbitalDescription(l, E, Type, Rcut, Type2, Rcut2)
-
class
Poscar
(structure: pymatgen.core.structure.Structure, comment: str = None, selective_dynamics=None, true_names: bool = True, velocities=None, predictor_corrector=None, predictor_corrector_preamble=None, sort_structure: bool = False)[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.
-
true_names
[source]¶ Boolean indication whether Poscar contains actual real names parsed from either a POTCAR or the POSCAR itself.
-
selective_dynamics
[source]¶ Selective dynamics attribute for each site if available. A Nx3 array of booleans.
-
velocities
[source]¶ Velocities for each site (typically read in from a CONTCAR). A Nx3 array of floats.
-
predictor_corrector
[source]¶ 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
[source]¶ Predictor corrector preamble contains the predictor-corrector key, POTIM, and thermostat parameters that precede the site-specic predictor corrector data in MD CONTCAR
-
temperature
[source]¶ Temperature of velocity Maxwell-Boltzmann initialization. Initialized to -1 (MB hasn”t been performed).
- Parameters
structure – Structure object.
comment – Optional comment line for POSCAR. Defaults to unit cell formula of structure. Defaults to None.
selective_dynamics – bool values for selective dynamics, where N is number of sites. Defaults to None.
true_names – Set to False if 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 – Velocities for the POSCAR. Typically parsed in MD runs or can be used to initialize velocities.
predictor_corrector – Predictor corrector for the POSCAR. Typically parsed in MD runs.
predictor_corrector_preamble – Preamble to the predictor corrector.
sort_structure – Whether to sort structure. Useful if species are not grouped properly together.
-
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
[source]¶ 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.
-
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.
-
-
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', 'Perdew-Zunger81'][source]¶
-
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.
-
class
PotcarSingle
(data, symbol=None)[source]¶ Bases:
object
Object for a single POTCAR. The builder assumes the POTCAR contains the complete untouched data in “data” as a string and a dict of keywords.
-
keywords
[source]¶ Keywords parsed from the POTCAR as a dict. All keywords are also accessible as attributes in themselves. E.g., potcar.enmax, potcar.encut, etc.
md5 hashes of the entire POTCAR file and the actual data are validated against a database of known good hashes. Appropriate warnings or errors are raised if a POTCAR hash fails validation.
- Parameters
data – Complete and single potcar file as a string.
symbol – POTCAR symbol corresponding to the filename suffix e.g. “Tm_3” for POTCAR.TM_3”. If not given, pymatgen will attempt to extract the symbol from the file itself. However, this is not always reliable!
-
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
-
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', 'Perdew-Zunger81': 'POT_LDA_PAW'}[source]¶
-
get_potcar_file_hash
()[source]¶ Computes a hash of the entire PotcarSingle.
This hash corresponds to the md5 hash of the POTCAR file itself.
- Returns
Hash value.
-
get_potcar_hash
()[source]¶ Computes a md5 hash of the data defining the PotcarSingle.
- Returns
Hash value.
-
identify_potcar
(mode: str = 'data')[source]¶ Identify the symbol and compatible functionals associated with this PotcarSingle.
This method checks the md5 hash of either the POTCAR data (PotcarSingle.hash) or the entire POTCAR file (PotcarSingle.file_hash) against a database of hashes for POTCARs distributed with VASP 5.4.4.
- Parameters
mode (str) – ‘data’ or ‘file’. ‘data’ mode checks the hash of the POTCAR data itself, while ‘file’ mode checks the hash of the entire POTCAR file, including metadata.
- Returns
List of symbols associated with the PotcarSingle potcar_functionals (List): List of potcar functionals associated with
the PotcarSingle
- Return type
symbol (List)
-
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>}[source]¶
-
-
exception
UnknownPotcarWarning
[source]¶ Bases:
UserWarning
Warning raised when POTCAR hashes do not pass validation
-
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.
-
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.