defectpl.vasp¶
Eigenvalue parsing¶
read_eigenval_file
¶
Parse a VASP EIGENVAL file and return spin-resolved eigenvalues at one k-point.
The EIGENVAL file must come from a spin-polarised (ISPIN = 2) calculation;
a ValueError is raised otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the VASP EIGENVAL file. |
required |
k_idx
|
int
|
Zero-based k-point index to extract. Default 0 (the Γ point for single-k calculations). |
0
|
Returns:
| Type | Description |
|---|---|
dict
|
Keys and types:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in defectpl\vasp.py
get_spin_multiplicity
¶
Calculate the spin multiplicity of the electronic configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
homo_up_idx
|
int
|
The HOMO level position index extracted for the spin-up channel. |
required |
homo_down_idx
|
int
|
The HOMO level position index extracted for the spin-down channel. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The calculated spin multiplicity (\(2S + 1\)). |
Source code in defectpl\vasp.py
OUTCAR parsing¶
OutcarParser
¶
Lightweight parser for VASP OUTCAR files.
Provides structure, force, and convergence queries without any
pymatgen dependency at import time (pymatgen is loaded lazily inside
:meth:get_structures_and_forces when needed).
This class is a thin wrapper around the module-level functions
:func:get_nions, :func:get_structures_and_forces, and
:func:check_outcar_convergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the VASP OUTCAR file. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
filename_path |
Path
|
Resolved absolute path to the OUTCAR. |
natoms |
int
|
Number of ions in the supercell, read from OUTCAR on construction. |
Examples:
>>> parser = OutcarParser("OUTCAR")
>>> conv = parser.check_convergence()
>>> print(conv["structural_converged"], conv["electronic_converged"])
>>> final_struct, final_forces = parser.get_final_structure_and_forces()
Source code in defectpl\vasp.py
get_natoms
¶
Extracts the total atom count from the underlying file.
Returns:
| Type | Description |
|---|---|
int
|
The quantity of ions configured within the VASP simulation. |
Source code in defectpl\vasp.py
get_structures_and_forces
¶
Wrapper method pulling all configurations and corresponding forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poscar_path
|
str or Path
|
Path to a POSCAR/CONTCAR to override elements, by default None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
structures |
list of pymatgen.core.Structure
|
A list of structures parsed sequentially from the run history. |
forces |
list of numpy.ndarray
|
Forces lists matching corresponding structural arrays. |
Source code in defectpl\vasp.py
get_final_structure_and_forces
¶
Extracts only the final structural step and force values from the OUTCAR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poscar_path
|
str or Path
|
Path to a POSCAR/CONTCAR to override elements, by default None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
structure |
Structure
|
The last recorded dynamic chemical cell state. |
forces |
ndarray
|
The last recorded absolute atomic forces array. |
Source code in defectpl\vasp.py
check_convergence
¶
Executes standard convergence and processing sanity runs on the active file.
Returns:
| Type | Description |
|---|---|
dict
|
Status reporting flag values tracking internal convergence goals. |
Source code in defectpl\vasp.py
get_structures_and_forces
¶
Extracts all structures and forces from the OUTCAR file as a standalone function.
Lattice matrices are dynamically updated per ionic configuration using the 'VOLUME and BASIS-vectors are now :' blocks parsed strictly from the OUTCAR itself. Species tracking elements are parsed natively from the OUTCAR's POTCAR mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
poscar_path
|
str or Path
|
Path to a POSCAR/CONTCAR to override chemical species symbols, by default None. If not provided, species mapping relies completely on the internal OUTCAR logic. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
structures |
list of pymatgen.core.Structure
|
A list of Structure objects representing each ionic step with correct dynamic lattices. |
forces |
list of numpy.ndarray
|
A list of 2D NumPy arrays of shape (NIONS, 3) representing the total forces (eV/Å) at each corresponding ionic step. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If either the outcar_path or poscar_path do not exist. |
ValueError
|
If position indices are requested prior to matrix processing, or if the data stream terminates prematurely. |
Source code in defectpl\vasp.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
get_final_structure_and_forces_from_outcar
¶
A standalone function to extract only the final structure and forces from the OUTCAR file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
poscar_path
|
str or Path
|
Path to a POSCAR/CONTCAR to override elements, by default None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
structure |
Structure
|
The last recorded dynamic chemical cell state. |
forces |
ndarray
|
The last recorded absolute atomic forces array. |
Source code in defectpl\vasp.py
get_first_structure_and_forces_from_outcar
¶
A standalone function to extract only the first structure and forces from the OUTCAR file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
poscar_path
|
str or Path
|
Path to a POSCAR/CONTCAR to override elements, by default None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
structure |
Structure
|
The first recorded dynamic chemical cell state. |
forces |
ndarray
|
The first recorded absolute atomic forces array. |
Source code in defectpl\vasp.py
check_outcar_convergence
¶
Checks whether a VASP calculation converged electronically and structurally.
Scans the OUTCAR file to find structural convergence tokens and looks at the final electronic step count to ensure it didn't stop because it hit NELM (maximum electronic steps limit).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the convergence status results:
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified OUTCAR file does not exist. |
Source code in defectpl\vasp.py
get_nions
¶
Extracts the number of ions (NIONS) from a VASP OUTCAR file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The total number of ions inside the VASP run. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified OUTCAR file does not exist. |
ValueError
|
If the 'NIONS =' string token cannot be found in the file structure. |
Source code in defectpl\vasp.py
get_species_and_index_map
¶
Extracts the atomic species list from an OUTCAR file to build an atom index map.
Handles multi-occurrence or interleaved POTCAR definitions (e.g., N, C, N, C) by aligning the element type sequence exactly with the length of the 'ions per type' array printed by VASP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcar_path
|
str or Path
|
The path to the VASP OUTCAR file. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
A flat list of element symbols corresponding to each index in the simulation. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified OUTCAR file does not exist. |
ValueError
|
If species definitions or ion counts cannot be successfully determined from the file stream. |