vaspio Package

vaspio Package

This package implements modules for input and output to and from VASP. It imports the key classes form both vasp_input and vasp_output to allow most classes to be simply called as pymatgen.io.vaspio.Incar for example, to retain backwards compatibility.

vasp_input Module

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

class Incar(params=None)[source]

Bases: dict

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

Creates an Incar object.

Args:
params:
A set of input parameters as a dictionary.
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.

Args:
other:
The other Incar object to compare to.
Returns:
Dict of the following format: {“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}
classmethod from_dict(d)[source]
static from_file(filename)[source]

Reads an Incar object from a file.

Args:
filename - Filename for file
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.

Args:
sort_keys:
Set to True to sort the INCAR parameters alphabetically. Defaults to False.
pretty:
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.

Args:
key:
INCAR parameter key
val:
Actual value of INCAR parameter.
to_dict[source]
write_file(filename)[source]

Write Incar to a file.

Args:
filename:
filename to write to.
class Kpoints(comment='Default gamma', num_kpts=0, style='Gamma', 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: pymatgen.serializers.json_coders.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.

Args:
comment:
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 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:
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.

Args:
subdivisions:
Parameter determining number of subdivisions along each reciprocal lattice vector.
Returns:
Kpoints object
static automatic_density(structure, kppa)[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.
Args:
structure:
Input structure
kppa:
Grid density
classmethod from_dict(d)[source]
static from_file(filename)[source]

Reads a Kpoints object from a KPOINTS file.

Args:
filename:
filename to read from.
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.

Args:
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.

Args:
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
supported_modes = Enum(['Cartesian', 'Reciprocal', 'Line_mode', 'Monkhorst', 'Automatic', 'Gamma'])
to_dict[source]

json friendly dict representation of Kpoints

write_file(filename)[source]

Write Kpoints to a file.

Args:
filename:
filename to write to.
class Poscar(structure, comment=None, selective_dynamics=None, true_names=True, velocities=None, predictor_corrector=None)[source]

Bases: pymatgen.serializers.json_coders.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 for each site (typically read in from a MD CONTCAR).

temperature

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

Args:
structure:
Structure object. See pymatgen.core.structure.Structure.
comment:
Optional comment line for POSCAR. Defaults to unit cell formula of structure. Defaults to None.
selective_dynamics:
Nx3 2D array of boolean values for selective dynamics, where N is number of sites. Defaults to None.
true_names:
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:
Velocities for the POSCAR. Typically parsed in MD runs or can be used to initialize velocities.
predictor_corrector:
Velocities for the POSCAR. Typically parsed in MD runs or can be used to initialize velocities.
classmethod from_dict(d)[source]
static from_file(filename, check_for_POTCAR=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.

Args:
filename:
File name containing Poscar data.
check_for_POTCAR:
Whether to check if a POTCAR is present in the same directory as the POSCAR. Defaults to True.
Returns:
Poscar object.
static from_string(data, default_names=None)[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.

Args:
data:
string containing Poscar data.
default_names:
default symbols for the POSCAR file, usually coming from a POTCAR in the same directory.
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.

Args:
direct:
Whether coordinates are output in direct or cartesian. Defaults to True.
vasp4_compatible:
Set to True to omit site symbols on 6th line to maintain backward vasp 4.x compatibility. Defaults to False.
significant_figures:
Number 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[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.

Args:
temperature:
Temperature in Kelvin.
site_symbols[source]

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

to_dict[source]
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='PBE', sym_potcar_map=None)[source]

Bases: list

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

Args:
symbols:
Element symbols for POTCAR. This should correspond to the symbols used by VASP. E.g., “Mg”, “Fe_pv”, etc.
functional:
Functional used.
sym_potcar_map:
Allows a user to specify a specific element symbol to raw POTCAR mapping.
DEFAULT_FUNCTIONAL = 'PBE'
classmethod from_dict(d)[source]
static from_file(filename)[source]
set_symbols(symbols, functional='PBE', sym_potcar_map=None)[source]

Initialize the POTCAR from a set of symbols. Currently, the POTCARs can be fetched from a location specified in the environment variable VASP_PSP_DIR or in a pymatgen.cfg or specified explicitly in a map.

Args:
symbols:
A list of element symbols
functional:
(optional) the functional to use from the config file
sym_potcar_map:
(optional) 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.
symbols[source]

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

to_dict[source]
write_file(filename)[source]

Write Potcar to a file.

Args:
filename:
filename to write to.
class PotcarSingle(*args, **kwds)[source]

Bases: pymatgen.io.vaspio.vasp_input.PotcarSingle

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.

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

Bases: dict, pymatgen.serializers.json_coders.MSONable

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

Args:
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 to_dict and from_dict method.
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.

Args:
input_dir:
Directory to read VASP input from.
optional_files:
Optional files to read in as well as a dict of {filename: Object type}. Object type must have a static method from_file.
to_dict[source]
write_input(output_dir='.', make_dir_if_not_present=True)[source]

Write VASP input to a directory.

Args:
output_dir:
Directory to write to. Defaults to current directory (”.”).
make_dir_if_not_present:
Create the directory if not present. Defaults to True.
get_potcar_dir()[source]

vasp_output Module

Classes for reading/manipulating/writing VASP ouput files.

class Chgcar(poscar, data)[source]

Bases: pymatgen.io.vaspio.vasp_output.VolumetricData

Simple object for reading a CHGCAR file.

Args:
poscar:
Poscar object containing structure.
data:
Actual data.
static from_file(filename)[source]
class Locpot(poscar, data)[source]

Bases: pymatgen.io.vaspio.vasp_output.VolumetricData

Simple object for reading a LOCPOT file.

Args:
poscar:
Poscar object containing structure.
data:
Actual data.
static from_file(filename)[source]
class Oszicar(filename)[source]

Bases: object

A basic parser for an OSZICAR output from VASP. In general, while the OSZICAR is useful for a quick look at the output from a VASP run, we recommend that you use the Vasprun parser instead, which gives far richer information about a run.

electronic_steps

All electronic steps as a list of list of dict. e.g., [[{“rms”: 160.0, “E”: 4507.24605593, “dE”: 4507.2, “N”: 1, “deps”: -17777.0, “ncg”: 16576}, ...], [....] where electronic_steps[index] refers the list of electronic steps in one ionic_step, electronic_steps[index][subindex] refers to a particular electronic step at subindex in ionic step at index. The dict of properties depends on the type of VASP run, but in general, “E”, “dE” and “rms” should be present in almost all runs.

ionic_steps:

All ionic_steps as a list of dict, e.g., [{“dE”: -526.36, “E0”: -526.36024, “mag”: 0.0, “F”: -526.36024}, ...] This is the typical output from VASP at the end of each ionic step.

Args:
filename:
Filename of file to parse
all_energies[source]

Compilation of all energies from all electronic steps and ionic steps as a tuple of list of energies, e.g., ((4507.24605593, 143.824705755, -512.073149912, ...), ...)

final_energy[source]

Final energy from run.

to_dict[source]
class Outcar(filename)[source]

Bases: object

Parser for data in OUTCAR that is not available in Vasprun.xml

Note, this class works a bit differently than most of the other VaspObjects, since the OUTCAR can be very different depending on which “type of run” performed.

Creating the OUTCAR class with a filename reads “regular parameters” that are always present.

magnetization

Magnetization on each ion as a tuple of dict, e.g., ({“d”: 0.0, “p”: 0.003, “s”: 0.002, “tot”: 0.005}, ... ) Note that this data is not always present. LORBIT must be set to some other value than the default.

charge

Charge on each ion as a tuple of dict, e.g., ({“p”: 0.154, “s”: 0.078, “d”: 0.0, “tot”: 0.232}, ...) Note that this data is not always present. LORBIT must be set to some other value than the default.

is_stopped

True if OUTCAR is from a stopped run (using STOPCAR, see Vasp Manual).

run_stats

Various useful run stats as a dict including “System time (sec)”, “Total CPU time used (sec)”, “Elapsed time (sec)”, “Maximum memory used (kb)”, “Average memory used (kb)”, “User time (sec)”.

One can then call a specific reader depending on the type of run being performed. These are currently: read_igpar(), read_lepsilon() and read_lcalcpol().

See the documentation of those methods for more documentation.

Authors: Rickard Armiento, Shyue Ping Ong

read_igpar()[source]
Renders accessible:
er_ev = e<r>_ev (dictionary with Spin.up/Spin.down as keys) er_bp = e<r>_bp (dictionary with Spin.up/Spin.down as keys) er_ev_tot = spin up + spin down summed er_bp_tot = spin up + spin down summed p_elc = spin up + spin down summed p_ion = spin up + spin down summed

(See VASP section “LBERRY, IGPAR, NPPSTR, DIPOL tags” for info on what these are).

read_lcalcpol()[source]
read_lepsilon()[source]
to_dict[source]
class Procar(filename)[source]

Bases: object

Object for reading a PROCAR file.

data

A nested dict containing the PROCAR data of the form below. It should be noted that VASP uses 1-based indexing for atoms, but this is converted to zero-based indexing in this parser to be consistent with representation of structures in pymatgen:

{
    atom_index: {
        kpoint_index: {
            "bands": {
                band_index: {
                    "p": 0.002,
                    "s": 0.025,
                    "d": 0.0
                },
                ...
            },
            "weight": 0.03125
        },
        ...
}
Args:
filename:
Name of file containing PROCAR.
get_d_occupation(atom_index)[source]

Deprecated since version v2.6.4: Use get_occpuation instead.

Returns the d occupation of a particular atom.

Args:
atom_index:
Index of atom in PROCAR. It should be noted that VASP uses 1-based indexing for atoms, but this is converted to zero-based indexing in this parser to be consistent with representation of structures in pymatgen.
Returns:
d-occupation of atom at atom_index.
get_occupation(atom_index, orbital)[source]

Returns the occupation for a particular orbital of a particular atom.

Args:
atom_num:
Index of atom in the PROCAR. It should be noted that VASP uses 1-based indexing for atoms, but this is converted to zero-based indexing in this parser to be consistent with representation of structures in pymatgen.
orbital:
A string representing an orbital. If it is a single character, e.g., s, p, d or f, the sum of all s-type, p-type, d-type or f-type orbitals occupations are returned respectively. If it is a specific orbital, e.g., px, dxy, etc., only the occupation of that orbital is returned.
Returns:
Sum occupation of orbital of atom.
exception VaspParserError[source]

Bases: exceptions.Exception

Exception class for VASP parsing.

class Vasprun(filename, ionic_step_skip=None, parse_dos=True, parse_eigen=True, parse_projected_eigen=False)[source]

Bases: object

Vastly improved sax-based parser for vasprun.xml files. Speedup over Dom is at least 2x for smallish files (~1Mb) to orders of magnitude for larger files (~10Mb). All data is stored as attributes, which are delegated to the VasprunHandler object. Note that the results would differ depending on whether the read_electronic_structure option is set to True.

Vasp results

ionic_steps

All ionic steps in the run as a list of {“structure”: structure at end of run, “electronic_steps”: {All electronic step data in vasprun file}, “stresses”: stress matrix}

structures

List of Structure objects for the structure at each ionic step.

tdos

Total dos calculated at the end of run.

idos

Integrated dos calculated at the end of run.

pdos

List of list of PDos objects. Access as pdos[atomindex][orbitalindex]

efermi

Fermi energy

eigenvalues

Available only if parse_eigen=True. Final eigenvalues as a dict of {(spin, kpoint index):[[eigenvalue, occu]]}. This representation is based on actual ordering in VASP and is meant as an intermediate representation to be converted into proper objects. The kpoint index is 0-based (unlike the 1-based indexing in VASP).

projected_eigenvalues

Final projected eigenvalues as a dict of {(atom index, band index, kpoint index, Orbital, Spin):float} This representation is based on actual ordering in VASP and is meant as an intermediate representation to be converted into proper objects. The kpoint, band and atom indices are 0-based (unlike the 1-based indexing in VASP).

dielectric
The real and imaginary part of the dielectric constant (e.g., computed
by RPA) in function of the energy (frequency). Optical properties (e.g.
absorption coefficient) can be obtained through this.
The date is given as a tuple of 3 values containing each of them
the energy, the real part tensor, and the imaginary part tensor
([energies],[[real_partxx,real_partyy,real_partzz,real_partxy,
real_partyz,real_partxz]],[[imag_partxx,imag_partyy,imag_partzz,
imag_partxy, imag_partyz, imag_partxz]])

Vasp inputs

incar

Incar object for parameters specified in INCAR file.

parameters

Incar object with parameters that vasp actually used, including all defaults.

kpoints

Kpoints object for KPOINTS specified in run.

actual_kpoints

List of actual kpoints, e.g., [[0.25, 0.125, 0.08333333], [-0.25, 0.125, 0.08333333], [0.25, 0.375, 0.08333333], ....]

actual_kpoints_weights

List of kpoint weights, E.g., [0.04166667, 0.04166667, 0.04166667, 0.04166667, 0.04166667, ....]

atomic_symbols

List of atomic symbols, e.g., [“Li”, “Fe”, “Fe”, “P”, “P”, “P”]

potcar_symbols

List of POTCAR symbols. e.g., [“PAW_PBE Li 17Jan2003”, “PAW_PBE Fe 06Sep2000”, ..]

Author: Shyue Ping Ong

Args:
filename:
Filename to parse
ionic_step_skip:
If ionic_step_skip is a number > 1, only every ionic_step_skip ionic steps will be read for structure and energies. This is very useful if you are parsing very large vasprun.xml files and you are not interested in every single ionic step. Note that the initial and final structure of all runs will always be read, regardless of the ionic_step_skip.
parse_dos:
Whether to parse the dos. Defaults to True. Set to False to shave off significant time from the parsing if you are not interested in getting those data.
parse_eigen:
Whether to parse the eigenvalues. Defaults to True. Set to False to shave off significant time from the parsing if you are not interested in getting those data.
parse_projected_eigen:
Whether to parse the projected eigenvalues. Defaults to False. Set to True to obtain projected eigenvalues. Note that this can take an extreme amount of time and memory. So use this wisely.
complete_dos[source]

A complete dos object which incorporates the total dos and all projected dos.

converged[source]

True if a relaxation run is converged. Checking is performed on both the final electronic convergence as well as whether the number of ionic steps is equal to the NSW setting.

eigenvalue_band_properties[source]

Band properties from the eigenvalues as a tuple, (band gap, cbm, vbm, is_band_gap_direct).

final_energy[source]

Final energy from the vasp run.

final_structure[source]

Final structure from vasprun.

get_band_structure(kpoints_filename=None, efermi=None, line_mode=False)[source]

Returns the band structure as a BandStructure object

Args:
kpoints_filename:
Full path of the KPOINTS file from which the band structure is generated. If none is provided, the code will try to intelligently determine the appropriate KPOINTS file by substituting the filename of the vasprun.xml with KPOINTS. The latter is the default behavior.
efermi:
If you want to specify manually the fermi energy this is where you should do it. By default, the None value means the code will get it from the vasprun.
line_mode:
force the band structure to be considered as a run along symmetry lines
Returns:

a BandStructure object (or more specifically a BandStructureSymmLine object if the run is detected to be a run along symmetry lines)

Two types of runs along symmetry lines are accepted: non-sc with Line-Mode in the KPOINT file or hybrid, self-consistent with a uniform grid+a few kpoints along symmetry lines (explicit KPOINTS file) (it’s not possible to run a non-sc band structure with hybrid functionals). The explicit KPOINTS file needs to have data on the kpoint label as commentary.

TODO:
  • make a bit more general for non Symm Line band structures
  • make a decision on the convention with 2*pi or not.
hubbards[source]

Hubbard U values used if a vasprun is a GGA+U run. {} otherwise.

initial_structure[source]

Initial structure from vasprun.

is_hubbard[source]

True if run is a DFT+U run.

is_spin[source]

True if run is spin-polarized.

run_type[source]

Returns the run type. Currently supports only GGA and HF calcs.

TODO: Fix for other functional types like LDA, PW91, etc.

supported_properties = ['lattice_rec', 'vasp_version', 'incar', 'parameters', 'potcar_symbols', 'atomic_symbols', 'kpoints', 'actual_kpoints', 'structures', 'actual_kpoints_weights', 'dos_energies', 'eigenvalues', 'tdos', 'idos', 'pdos', 'efermi', 'ionic_steps', 'dos_has_errors', 'projected_eigenvalues', 'dielectric']
to_dict[source]

Json-serializable dict representation.

class VasprunHandler(filename, parse_dos=True, parse_eigen=True, parse_projected_eigen=False)[source]

Bases: xml.sax.handler.ContentHandler

Sax handler for vasprun.xml. Attributes are mirrored into Vasprun object. Generally should not be initiatized on its own.

characters(data)[source]
endElement(name)[source]
startElement(name, attributes)[source]
class VolumetricData(structure, data, distance_matrix=None)[source]

Bases: object

Simple volumetric object for reading LOCPOT and CHGCAR type files.

structure

Structure associated with the Volumetric Data object

..attribute:: is_spin_polarized

True if run is spin polarized

..attribute:: dim

Tuple of dimensions of volumetric grid in each direction (nx, ny, nz).

..attribute:: data

Actual data as a dict of {string: np.array}. The string are “total” and “diff”, in accordance to the output format of vasp LOCPOT and CHGCAR files where the total spin density is written first, followed by the difference spin density.
ngridpts

Total number of grid points in volumetric data.

Typically, this constructor is not used directly and the static from_file constructor is used. This constructor is designed to allow summation and other operations between VolumetricData objects.

Args:
structure:
Structure associated with the volumetric data
data:
Actual volumetric data.
distance_matrix:
A pre-computed distance matrix if available. Useful so pass distance_matrices between sums, shortcircuiting an otherwise expensive operation.
get_average_along_axis(ind)[source]

Get the averaged total of the volumetric data a certain axis direction. For example, useful for visualizing Hartree Potentials from a LOCPOT file.

Args:
ind : Index of axis.
Returns:
Average total along axis
get_axis_grid(ind)[source]

Returns the grid for a particular axis.

Args:
ind:
Axis index.
get_integrated_diff(ind, radius, nbins=1)[source]

Get integrated difference of atom index ind up to radius. This can be an extremely computationally intensive process, depending on how many grid points are in the VolumetricData.

Args:
ind:
Index of atom.
radius:
Radius of integration.
nbins:
Number of bins. Defaults to 1. This allows one to obtain the charge integration up to a list of the cumulative charge integration values for radii for [radius/nbins, 2 * radius/nbins, ....].
Returns:
Differential integrated charge as a np array of [[radius, value], ...]. Format is for ease of plotting. E.g., plt.plot(data[:,0], data[:,1])
linear_add(other, scale_factor=1.0)[source]

Method to do a linear sum of volumetric objects. Used by + and - operators as well. Returns a VolumetricData object containing the linear sum.

Args:
other:
Another VolumetricData object
scale_factor:
Factor to scale the other data by.
Returns:
VolumetricData corresponding to self + scale_factor * other.
static parse_file(filename)[source]

Convenience method to parse a generic volumetric data file in the vasp like format. Used by subclasses for parsing file.

Args:
filename:
Path of file to parse
Returns:
(poscar, data)
spin_data[source]

The data decomposed into actual spin data as {spin: data}. Essentially, this provides the actual Spin.up and Spin.down data instead of the total and diff. Note that by definition, a non-spin-polarized run would have Spin.up data == Spin.down data.

write_file(file_name, vasp4_compatible=False)[source]

Write the VolumetricData object to a vasp compatible file.

Args:
file_name:
the path to a file
vasp4_compatible:
True if the format is vasp4 compatible
get_adjusted_fermi_level(efermi, cbm, band_structure)[source]

When running a band structure computations the fermi level needs to be take from the static run that gave the charge density used for the non-self consistent band structure run. Sometimes this fermi level is however a little too low because of the mismatch between the uniform grid used in the static run and the band structure k-points (e.g., the VBM is on Gamma and the Gamma point is not in the uniform mesh). Here we use a procedure consisting in looking for energy levels higher than the static fermi level (but lower than the LUMO) if any of these levels make the band structure appears insulating and not metallic anymore, we keep this adjusted fermi level. This procedure has shown to detect correctly most insulators.

Args:
cbm:
the cbm of the static run
efermi:
the fermi energy of the static run
run_bandstructure:
a band_structure object
Returns:
a new adjusted fermi level
get_band_structure_from_vasp_multiple_branches(dir_name, efermi=None, projections=False)[source]

this method is used to get band structure info from a VASP directory. It takes into account that the run can be divided in several branches named “branch_x”. If the run has not been divided in branches the method will turn to parsing vasprun.xml directly.

The method returns None is there”s a parsing error

Args:
dir_name:
Directory containing all bandstructure runs.
efermi:
Efermi for bandstructure.
projections:
True if you want to get the data on site projections if any Note that this is sometimes very large
Returns:
A BandStructure Object
parse_from_incar(filename, key)[source]

Helper function to parse a parameter from the INCAR.

parse_parameters(val_type, val)[source]

Helper function to convert a Vasprun parameter into the proper type. Boolean, int and float types are converted.

Args:
val_type : Value type parsed from vasprun.xml. val : Actual string value parsed for vasprun.xml.
parse_v_parameters(val_type, val, filename, param_name)[source]

Helper function to convert a Vasprun array-type parameter into the proper type. Boolean, int and float types are converted.

Args:
val_type:
Value type parsed from vasprun.xml.
val:
Actual string value parsed for vasprun.xml.
filename:
Fullpath of vasprun.xml. Used for robust error handling. E.g., if vasprun.xml contains *** for some Incar parameters, the code will try to read from an INCAR file present in the same directory.
param_name:
Name of parameter.
Returns:
Parsed value.

Table Of Contents

This Page