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)[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[source]¶
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)[source]¶
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.
- 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()[source]¶
Stream complete ionic frames without retaining the sequence.
- Returns:
An iterator yielding one
OutcarFrameat a time.- Return type:
- frame(index)[source]¶
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.
- 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[source]¶
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.
- httk.atomistic.integrations.vasp.io.read_outcar(source)[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)[source]¶
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.
- property poscar: dict[str, Any] | None¶
Return the lazily loaded POSCAR payload, or
Nonewhen absent.
- property contcar: dict[str, Any] | None¶
Return the lazily loaded CONTCAR payload, or
Nonewhen absent.
- 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)[source]¶
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: the cell vectors are still to be multiplied by the scaling factor, and the coordinates may be Cartesian or fractional depending oncartesian. Doing that conversion needs the assembled cell, so it belongs to whoever builds the structure —httk.core.load()— not to the reader.- Parameters:
source (Any) – POSCAR/CONTCAR filename, text stream, or iterable of source lines.
- Returns:
The neutral mapping, including the original text in
rawwhen available.- Raises:
ValueError – If the input is malformed.
- Return type:
- httk.atomistic.integrations.vasp.io.read_potcar_summary(source)[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)[source]¶
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.
- property symbols: tuple[str, Ellipsis] | None¶
Return initial species symbols, or
Nonefor the older header form.
- httk.atomistic.integrations.vasp.io.read_xdatcar(source)[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)[source]¶
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)[source]¶
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)[source]¶
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.