vasptools module

The main part of the vasptools module is the class VaspRun which provides methods in order to deal with VASP calculations outputs. vasptools contains the following submodules :

All above submodules are loaded whith vasptools. The VaspRun class is loaded in the vasptools namespace.

In the following, run will refer to a VaspRun object instanced as :

>>> import vasptools
>>> run = vasptools.VaspRun("vasprun.xml")

vasptools.vasprun : the core part

class VaspRun

class vasptools.vasprun.VaspRun(xmlFile = "vasprun.xml", verbose = True)[source]

VASP calculation class

Parameters:
  • xmlFile (string) – name or path to vasprun.xml output file of VASP (default is ‘vasprun.xml’).
  • verbose (bool) – verbosity of methods (default is ‘True’)

Examples :

>>> import vasptools
>>> run = vasptools.vasprun.VaspRun()
>>> run = vasptools.VaspRun()
>>> run = vasptools.VaspRun("dos.xml")

General attributes

VaspRun.eFermi
Variables:eFermi (float) – Energy of the Fermi level in eV.
VaspRun.allMotsClefs
Variables:allMotsClefs (dict) – dictionary of all parameters of the calculation.

Example :

>>> run.allMotsClefs["ENCUT"]
500.0
VaspRun.INCAR
Variables:INCAR (dict) – dictionary of all parameters of the INCAR file.

Methods in order to print general information

VaspRun.valeurMotClef(flag)
Return type:string
Returns:Return the value of the parameter ‘flag’.
Parameters:flag (string) – name of the parameter.

See listerMotsClefs() which return the list of parameters name.

>>> run.valeurMotClef("ENCUT")
ENCUT = 500.0
500.0
>>> encut = run.valeurMotClef("ENCUT")
ENCUT = 500.0
>>> encut
500.0

Parameters value can also be obtained from allMotsClefs class atribute, see allMotsClefs.

>>> run.allMotsClefs("ENCUT")
500.0
VaspRun.listerMotsClefs()

Print all parameters of the calculation.

See also valeurMotClef().

VaspRun.printINCAR()

Print parameters present in the INCAR file

>>> run.printINCAR()
# fichier INCAR du calcul
NELMIN = 6              ENCUT = 500.0         ISTART = 0
SYSTEM = "Cu2O           PREC = medium          ISIF = 3
IBRION = 2             EDIFFG = -0.01          EDIFF = 1e-06
VaspRun.printAtomsData()

Print atomic data

>>> run.printAtomsData()
# system :
        * atom number : 6
        * type number : 2
        * atom list   :  Cu,  Cu,  Cu,  Cu,   O,   O
# Atom types :
Atom Cu :
        weight            : 63.546
        Valence electrons : 11
        type              : 1
        Pseudopotential   :  PAW_PBE Cu 05Jan2001
Atom O :
        weight            : 16.0
        Valence electrons : 6
        type              : 2
        Pseudopotential   :  PAW_PBE O 08Apr2002

Density of state

VaspRun.lectureDOS()

Read total DOS and projected DOS into vasprun.xml.

Return type:[bool, bool]
Returns:The first element is True if total DOS was read and the second element is True if projected DOS were read.

The following attribute are available after using this method :

  • total DOS is stored in a list object called : dosTotale
  • projected DOS are stored in a list object called : dosPartielles
  • abscissa of the DOS are stored in a list object called : energiesDOS
  • Fermi level energy is stored in : eFermi

Example :

>>> run.lectureDOS()
# Lecture de la densité d'états
    * ISPIN = 1
    * densité d'états totale
    * densités d'états partielles
[True, True]
VaspRun.energiesDOS
Variables:energieDOS (list) – Abscissa of the density of states.
>>> run.energiesDOS
[-19.7886, -19.6826, -19.5765, ..., 11.8109, 11.917, 12.023]
VaspRun.dosTotale
Variables:dosTotale[spin][energy][i] (list) – total DOS.

Index of dosTotale are :

  1. spin index (0 is spin up, 1 is spin down)
  2. energy index (0 to len(run.energiesDOS))
  3. i index (0 the DOS, 1 is the integrated DOS)

The following loop gives the dos of spin up:

>>> [dos[0] for dos in run.dosTotale[0]]

The following loop gives the integrated dos of spin down :

>>> [dos[1] for dos in run.dosTotale[1]]
VaspRun.dosPartielles
Variables:dosPartielles[iat][spin][energy][i] (list) – Projected DOS

Index of dosTotale are:

  1. atom index (0 to Natoms)
  2. spin index (0 is spin up, 1 is spin down)
  3. energy index (0 to len(run.energiesDOS))
  4. i index

i index take values :

  • 0 to 2 if DOS is l-projected (s, p, d)
  • 0 to 8 if DOS is lm-projected (s, py, pz, px, dxy, dyz, dz2, dxz, dx2-y2)
VaspRun.DOSTotaleLue
Variables:DOSTotaleLue (bool) – True if total DOS has been already read
VaspRun.DOSPartiellesLues
Variables:DOSPartiellesLues (bool) – True if projected DOS have been already read

Energy bands

VaspRun.lectureBandes()

Read energy bands into vasprun.xml.

Return type:bool
Returns:Return True if energy bands are read.

Energy bands are stored into bands attribute.

VaspRun.bands
Variables:bands[spin][k][bands][i] (list) – Energy bands

Index of bands are :

  1. spin index (0 is spin up, 1 is spin down)
  2. k points index (0 to number of k points)
  3. bands index (0 to NBANS - 1)
  4. i index : 0 energy, 1 ocupency

The number of k points along a line of the reciprocal space is Ndivision. k-points are listed for each line of the reciprocal space successively and store in listePoinstK.

The number of bands, NBANS, can be obtain with valeurMotClef() or directly with allMotsClefs.

K-points

VaspRun.lecturePointsK()

Read k-points used for the calculation.

Return type:bool
Returns:True if k points are read.
VaspRun.pointsKLues
Variables:pointsKLues (bool) – True if k points have been already read.
VaspRun.listePointsK
Variables:listePointsK[k][i] (list) – List of all k-points.

Index of listePointsK :

  1. index of the k-point.
  2. coordinate of the k-point in the reciprocal space (i = 0 to 2).
VaspRun.typePointsK
Variables:typePointsK (string) – Name of the method used to generate the kpoints grid (gamma, listgenerated ...)

The following attributes are relevant only in the case of k-points generated along line of the reciprocal space, that is typePointsK equal listgenerated.

VaspRun.directionsPointsK
Variables:directionsPointsK[l][i] (list) – Coordinates of the first and the last k-points on each line of the reciprocal space along which energy bands are computed.

Index of directionPointsK

  1. l is the line of the reciprocal space index
  2. i is the index upon k-points coordinates : 0 to 2 for the first k-points of the line and 3 to 5 for the last k-points of the line.

Example, if you compute energy bands from (1/2, 1/2, 1/2) to Gamma and from Gamma to (0,1/2,0) :

>>> run.directionPointsK
[[0.5, 0.5, 0.5, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.5, 0.0],
VaspRun.Ndivision
Variables:Ndivision (int) – Number of k-points along a line of the reciprocal space.

Structure

VaspRun.getInitialStructure(verbose = True)

Read initial structure of the calculation.

Parameters:verbose (bool) – verbosity of the method.
Return type:crystal, see crystal.
Returns:A crystal object

The initial structure is initialStructure.

VaspRun.getFinalStructure(verbose = True)

Read final structure of the calculation.

Parameters:verbose (bool) – verbosity of the method.
Return type:crystal, see crystal.
Returns:A crystal object

The final structure is finalStructure.

VaspRun.initialStructure
VaspRun.finalStructure
Variables:
  • initialStructure (crystal) – Initial structure of the calculation as a crystal object.
  • finalStructure (crystal) – Final structure of the calculation as a crystal object.

vasptools.dos : denisty of states

This module contains functions in order to print projected DOS into files or in order to print or plot total DOS.

All functions take only one arguments : a VaspRun object.

vasptools.dos.showTotalDOS(run)[source]

Plot total DOS using matplotlib.pyplot.

Parameters:run (VaspRun) – A VaspRun object corresponding to a DOS calculation.
vasptools.dos.printTotalDOStoFile(run)[source]

Print the total DOS into a file.

Parameters:run (VaspRun) – A VaspRun object corresponding to a DOS calculation.
Return type:list
Returns:list of created files

Output file name for the total DOS is totalDOS.dat for non spin polarized calculations and totalDOS_up.dat or totalDOS_down.dat for spin polarized calculations.

vasptools.dos.printProjectedDOStoFile(run)[source]

Print projected DOS to files with one file per atom.

Parameters:run (VaspRun) – A VaspRun object corresponding to a DOS calculation.
Return type:list
Returns:list of created files

Output file names are projectedDOS_X_N.dat for non spin polarized calculations where X is the atom name and N is the atom number in the structure. For spin polarized calculations, output file names are projectedDOS_up_X_N.dat or projectedDOS_down_X_N.dat.

vasptools.bands : energy bands

This module contains functions in order to plot energy bands or to print them into files.

All functions take only one arguments which is a VaspRun object.

vasptools.bands.showBands(run)

Plot total DOS using matplotlib.pyplot.

Parameters:run (VaspRun) – A VaspRun object corresponding to a bands calculation
vasptools.bands.bandesToFiles(run, parDirection = False)

Print energy bands into file.

Parameters:
  • run (VaspRun) – A VaspRun object corresponding to a bands calculation
  • parDirection (bool) – If True one file is created for each line of the reciprocal space along which energy bands were computed.
Return type:

list

Returns:

list of created files

If parDirection is False (default), output file names are bands.dat or bands_up.dat and bands_down.dat for spin polarized calculations. If parDirection is True, one file is created for each line of the reciprocal space along which energy bands were computed. If X is the index of the lines of the reciprocal space, the output file names are bands_dirX.dat or bands_dirX_up.dat and bands_dirX_down.dat for spin polarized calculations.

vasptools.utils

This module contains functions in order to do simple operations (split, arithmetic) on charge density.

vasptools.utils.readCHGCAR(chgcarName, full = False, verbose = True)[source]

Read up + down and up - down densities in a CHGCAR file.

Parameters:
  • chgcarName (string) – Name of the CHGCAR file
  • full (bool) – If False (default) only up + down density is read. If True, up - down density is also read.
  • verbose (bool) – control verbosity of the function.
Return type:

list

Returns:

The up + down and the up - down densities

vasptools.utils.sumDensities(chgcar1, chgcar2, fact1, fact2, verbose = True)[source]

Read CHGCAR1 and CHGCAR2 files and do the following linear operation

CHGCAR_sum = fact1 * CHGCAR1 + fact2 * CHGCAR2
Parameters:
  • chgcar1 (string) – Name of the first CHGCAR file
  • chgcar2 (string) – Name of the second CHGCAR file
  • fact1 (float) – Name of the scaling factor of the density read on CHGCAR1
  • fact2 (float) – Name of the scaling factor of the density read on CHGCAR2
  • verbose (bool) – control verbosity of the function.
Return type:

list

Returns:

The result of the linear operation.

Operation is done on the first density of the CHGCAR file, namely the up + down density.

vasptools.atom : Atom class

class vasptools.atom.Atom(name = "H", atomType = -1, Ne = 1, w = 1., pseudo = "")[source]

Atom class is used in order to manage atomic data. Default is an hydrogen atom.

Parameters:
  • name (string) – Atom name
  • atomType (int) – Atom type
  • Ne (int) – Number of valence electrons
  • w (float) – Atomic weight
  • pseudo (string) – Pseudopotential used for core electrons.
Atom.name
Variables:name (string) – Atom name
Atom.atomType
Variables:atomType (int) – Atom type
Atom.Ne
Variables:Ne (int) – Number of valence electrons
Atom.w
Variables:w (float) – Atomic weight
Atom.pseudo
Variables:pseudo (string) – Pseudopotential used for core electrons.