httk.atomistic.integrations.vasp.io¶
VASP file-format readers for httk-atomistic.
Submodules¶
- httk.atomistic.integrations.vasp.io.oszicar
- httk.atomistic.integrations.vasp.io.outcar
- httk.atomistic.integrations.vasp.io.outputs
- httk.atomistic.integrations.vasp.io.poscar_reader
- httk.atomistic.integrations.vasp.io.poscar_writer
- httk.atomistic.integrations.vasp.io.potcar
- httk.atomistic.integrations.vasp.io.volumetric
- httk.atomistic.integrations.vasp.io.wavecar
- httk.atomistic.integrations.vasp.io.xdatcar
Classes¶
Store one six-by-six elastic-moduli table. |
|
Lazy OUTCAR metadata reader whose scans reopen the source each time. |
|
Store one complete ionic-step snapshot with VASP numeric lexemes unchanged. |
|
Lazily resolve standard VASP files in a calculation directory. |
|
Re-openable, forward-streaming XDATCAR source. |
Functions¶
|
Read OSZICAR text without converting numeric lexemes. |
|
Return a lazy OUTCAR payload; only filesystem filenames are accepted. |
|
Parse a VASP POSCAR/CONTCAR into a neutral, string-preserving mapping. |
|
Extract one metadata mapping per |
|
Read an XDATCAR path into a lazy neutral |
|
Read a VASP WAVECAR path into a neutral payload. |
|
Write a neutral WAVECAR payload to a binary path. |
|
Write POSCAR content followed by a VASP/VESTA volumetric grid. |
Package Contents¶
- httk.atomistic.integrations.vasp.io.read_oszicar(source)¶
Read OSZICAR text without converting numeric lexemes.
Electronic iterations are attached to the following ionic summary. A trailing electronic block is retained as an incomplete final entry when no summary follows it.
- class httk.atomistic.integrations.vasp.io.ElasticModuliBlock¶
Store one six-by-six elastic-moduli table.
- Parameters:
heading – Heading identifying the table in the source.
rows – Table rows with their source numeric lexemes.
- class httk.atomistic.integrations.vasp.io.OutcarFile(filename)¶
Lazy OUTCAR metadata reader whose scans reopen the source each time.
OUTCAR paths, including compressed paths, are accepted by deliberate forward-streaming divergence from
WavecarFile; random frame access re-streams the file. Construction validates only that the path exists. Prologue and full scans are lazy: the first prologue access scans to the ionic marker and can traverse the whole file when no marker exists. The full pass streams the source once and caches summary fields, all stress rows, and all elastic-moduli blocks. No source handle is retained, soclose()only marks this lazy object closed. The publicpathproperty returns the source filename.- Parameters:
filename (str | os.PathLike[str]) – Filesystem path to an OUTCAR, optionally compressed.
- close()¶
Mark this lazy object closed; it owns no persistent stream.
- property version_numbers: tuple[int, Ellipsis]¶
Return the numeric components of the VASP version string.
- property parameters: collections.abc.Mapping[str, str]¶
Return the first recognized VASP parameter lexeme for each parameter.
- property ions_per_type: tuple[int, Ellipsis] | None¶
Return the number of ions for each potential type, when reported.
- frames()¶
Stream complete ionic frames without retaining the sequence.
- Returns:
An iterator yielding one
OutcarFrameat a time.- Return type:
- frame(index)¶
Return one frame by rescanning from the start of the file.
- Parameters:
index (int) – Zero-based frame index.
- Returns:
The requested frame, or
Nonewhen it is beyond the file.- Raises:
ValueError – If
indexis negative or not an integer.- Return type:
OutcarFrame | None
- property final_energies: FinalEnergies¶
Return energies from the last complete or partial energy block.
- property last_frame: OutcarFrame | None¶
Return the last complete ionic frame, when one exists.
- stresses()¶
Return all six-token
in kBrows in file order.
- property elastic_moduli: tuple[ElasticModuliBlock, Ellipsis]¶
Return parsed elastic-moduli tables in source order.
- property magnetization: tuple[float, Ellipsis] | None¶
Return per-ion total magnetic moments from the final
magnetization (x)block.The values are the last (
tot) column of each ion row in the lastmagnetization (x)block in the file, in Bohr magnetons. The per-orbital columns and themagnetization (y)/(z)blocks themselves are out of scope, so for a noncollinear run these values are only the x projection of each moment. A caller treating them as a collinear axis projection must checknoncollinear_magnetizationfirst. A malformed or truncated final block never raises: it yieldsNoneand records an entry inissues, so an OUTCAR from a killed job is ordinary input.
- property noncollinear_magnetization: bool¶
Whether a
magnetization (y)or(z)block follows the final(x)block.When
Truethemagnetizationvalues are only the x projection of a noncollinear moment and must not be treated as a collinear axis magnitude.- Returns:
Truefor a noncollinear final block,Falseotherwise, including when the file has no magnetization block.- Return type:
- class httk.atomistic.integrations.vasp.io.OutcarFrame¶
Store one complete ionic-step snapshot with VASP numeric lexemes unchanged.
- Parameters:
index – Zero-based ionic-step index.
cell – Lattice-vector lexemes, when the step contains a cell.
positions – Position lexemes, when the step contains positions.
forces – Force lexemes, when the step contains forces.
stress_kbar – Six stress lexemes in VASP order, when present.
free_energy – Free-energy lexeme, when present.
energy_without_entropy – Energy-without-entropy lexeme, when present.
energy_sigma0 – Sigma-zero energy lexeme, when present.
temperature – Temperature lexeme, when present.
- cell_floats()¶
Convert the cell lexemes to floating-point values when present.
- positions_floats()¶
Convert the position lexemes to floating-point values when present.
- forces_floats()¶
Convert the force lexemes to floating-point values when present.
- stress_gpa_voigt()¶
Convert stress to tensile-positive GPa Voigt order
xx, yy, zz, yz, xz, xy.The conversion multiplies kbar by
0.1, reverses VASP’s compressive-positive sign, and reorders the shear components.
- httk.atomistic.integrations.vasp.io.read_outcar(source)¶
Return a lazy OUTCAR payload; only filesystem filenames are accepted.
- Parameters:
source (Any) – Filesystem path to an OUTCAR, optionally compressed.
- Returns:
A neutral payload containing the lazy OUTCAR reader.
- Raises:
TypeError – If
sourceis not a filesystem path.FileNotFoundError – If the path does not exist.
- Return type:
- class httk.atomistic.integrations.vasp.io.VASPOutputs(directory, *, precision=None)¶
Lazily resolve standard VASP files in a calculation directory.
File lookup probes each registered compression suffix after the plain filename. Payload readers are created only when their properties are first accessed. The lazy OUTCAR and XDATCAR children are owned here and closed by
close(); payload mappings do not retain open handles.- Parameters:
directory (str | os.PathLike[str]) – Filesystem directory containing VASP output files.
precision (float | None) – Cartesian coordinate precision in Å propagated to the POSCAR/CONTCAR reads (see
read_poscar()).None(the default) keeps the digit-derived precision and, on firstposcar/contcaraccess, emits the same recommendation warningread_poscardoes — relaxed CONTCAR coordinates are written to full double precision, so without a value the symmetry tolerance comes out unrealistically tight. Validated lazily by the reader.
- close()¶
Close owned lazy file objects; repeated calls are harmless.
- property poscar: dict[str, Any] | None¶
Return the lazily loaded POSCAR payload, or
Nonewhen absent.The read uses this object’s
precision(warning when it was not supplied).
- property contcar: dict[str, Any] | None¶
Return the lazily loaded CONTCAR payload, or
Nonewhen absent.The read uses this object’s
precision(warning when it was not supplied).
- property outcar: httk.atomistic.integrations.vasp.io.outcar.OutcarFile | None¶
Return the owned lazy OUTCAR reader, or
Nonewhen absent.
- property xdatcar: httk.atomistic.integrations.vasp.io.xdatcar.XdatcarFile | None¶
Return the owned lazy XDATCAR reader, or
Nonewhen absent.
- httk.atomistic.integrations.vasp.io.read_poscar(source, *, precision=None)¶
Parse a VASP POSCAR/CONTCAR into a neutral, string-preserving mapping.
sourcemay be a filename, opened throughhttk.core.TextstreamFileViewso compressed files such asCONTCAR.bz2are decompressed transparently, or an already-open text stream / iterable of lines.The returned mapping has the keys
format(always"vasp-poscar"),comment,scaleandvolume(both keys are always present; exactly one is non-None),cell,symbols(which may beNonefor VASP-4; any species token shaped[A-Z][a-z]?followed by_,/or.is truncated to that leading symbol, soLi_sv,O_handLu/read asLi,OandLu; every other token, includingvacancy, is left untouched),counts,cartesian,coords, andselective_dynamics(which may beNonewhen selective dynamics is not declared), andraw(the original decompressed text, orNonewhen unavailable). For filenames and binary sources,rawpreserves CRLF and provides the writer’s byte-exact round-trip channel. For an open text stream, it reflects the stream’s already translated text and is not byte-exact. Malformed input raises a clearValueErrornaming the offending line.Three further keys report how precisely the file wrote its numbers, each the coarsest claim among the tokens it covers, or
Nonewhen none of them claim anything:cell_precision,scale_precision, andcoordinate_precision. They are the precisions of the tokens as written, deliberately not converted. In Direct mode, conventional special fractions written exactly as0.0,0.5, or1.0make no precision claim; signed forms follow the same rule. The cell vectors are still to be multiplied by the scaling factor, and Cartesian coordinates are still to be transformed into the fractional frame. Doing those conversions needs the assembled cell, so it belongs to whoever builds the structure —httk.core.load()— not to the reader.A further key,
precision_override, carries the caller’sprecisionvalue (orNone). When given, it is the Cartesian coordinate precision as a length in Å — the same units ascartesian_precision()and thesymprecused by symmetry recognition — and whoever builds the structure uses it in place of the digit-derived precision. Relaxed VASP CONTCAR coordinates are written to full double precision, so the digit-derived precision is unrealistically tight (~machine epsilon) and yields a symmetry tolerance that makes spglib reject nearly every candidate; pass a realistic value (e.g.5e-4) for such files. WhenprecisionisNonea recommendation warning is emitted.- Parameters:
source (Any) – POSCAR/CONTCAR filename, text stream, or iterable of source lines.
precision (float | None) – Cartesian coordinate precision as a length in Å, or
Noneto keep the digit-derived behavior (and emit a recommendation warning). Must be a finite number greater than zero when given.
- Returns:
The neutral mapping, including the original text in
rawwhen available, andprecision_override(the passed value orNone).- Raises:
ValueError – If the input is malformed, or
precisionis not a finite number greater than zero.- Return type:
- httk.atomistic.integrations.vasp.io.read_potcar_summary(source)¶
Extract one metadata mapping per
TITELheader without retaining POTCAR text.Only header metadata is returned; the potential body is never retained or exposed because it can contain licensed data. Concatenated
POTCAR.summaryheaders are accepted.
- class httk.atomistic.integrations.vasp.io.XdatcarFile(filename)¶
Re-openable, forward-streaming XDATCAR source.
Construction checks only that
filenameexists. Compressed paths are accepted by deliberate forward-streaming divergence fromWavecarFile; repeated scans re-stream the file. Header properties scan the header;framesopens a fresh stream and never caches frames. Variable-cell files are identified by a repeated POSCAR-like header and expose that header’s cell on the following frame. An incomplete final coordinate block is dropped and reported inissuesduring the full pass. The publicpathproperty returns the source filename.- Parameters:
filename (str | os.PathLike[str]) – Filesystem path to an XDATCAR, optionally compressed.
- close()¶
Close the object; scans use short-lived streams and own no handle.
- property symbols: tuple[str, Ellipsis] | None¶
Return initial species symbols, or
Nonefor the older header form.
- frames()¶
Yield complete frames in file order without retaining them.
- Yield:
One complete frame mapping at a time.
- httk.atomistic.integrations.vasp.io.read_xdatcar(source)¶
Read an XDATCAR path into a lazy neutral
vasp-xdatcarpayload.- Parameters:
source (str | os.PathLike[str]) – Filesystem path to an XDATCAR, optionally compressed.
- Returns:
A neutral payload containing the lazy XDATCAR reader.
- Raises:
TypeError – If
sourceis not a filesystem path.FileNotFoundError – If the path does not exist.
- Return type:
- httk.atomistic.integrations.vasp.io.read_wavecar(source, *, double_precision=None, gamma_half=None)¶
Read a VASP WAVECAR path into a neutral payload.
- Parameters:
source (str | os.PathLike[str]) – Filesystem path to an uncompressed WAVECAR.
double_precision (bool | None) – Override the coefficient precision declared by the file.
gamma_half (str | None) – Consumer hint for the gamma-half orientation, or
Nonewhen unspecified.
- Returns:
A payload containing the lazy WAVECAR source and the gamma-half hint.
- Raises:
ValueError – If an option is invalid or the file is malformed.
- Return type:
- httk.atomistic.integrations.vasp.io.write_wavecar(destination, payload)¶
Write a neutral WAVECAR payload to a binary path.
- Parameters:
destination (str | os.PathLike[str]) – Filesystem path for the uncompressed binary output.
payload (collections.abc.Mapping[str, Any]) – Neutral payload containing a WAVECAR source.
- Raises:
ValueError – If the destination or payload cannot represent a WAVECAR.
TypeError – If the payload is not a mapping.
KeyError – If the payload mapping does not contain
"wavecar".
- httk.atomistic.integrations.vasp.io.write_vasp_volumetric(destination, poscar_payload, grid, *, cols=10)¶
Write POSCAR content followed by a VASP/VESTA volumetric grid.
- Parameters:
destination (str | os.PathLike[str] | io.TextIOBase) – Filesystem path or open text stream for the output.
poscar_payload (collections.abc.Mapping[str, Any]) – Neutral POSCAR payload supplying the structure header.
grid (Any) – Three-dimensional real-valued grid in the order written by the format.
cols (int) – Maximum number of values written on each grid line.
- Raises:
ValueError – If the grid or column count is not writable as volumetric data.