httk.workflow.vasp¶
Small, dependency-free VASP runner helpers for native v2 workflows.
This is an independent, data-oriented interface rather than a port of the
historic VASP_* Python or shell APIs. Historical authorship is documented
in v1_runtime/NOTICE.
The implementation is split across cohesive sibling modules — inputs,
diagnostics, remedies, and reports — and this package is a thin
public facade that re-exports their surface unchanged. Importing the package
also registers the packaged VASP workflows with the generic scaffold (see the
workflows module), which is how httk workflow job new --workflow
vasp-relax resolves a runner the scaffold never names.
Attributes¶
Classes¶
The VASP-5 header information needed by execution helpers. |
|
One assembled POTCAR and the provenance of every piece in it. |
|
Which pseudopotential of a library one species was given. |
|
Options for dependency-free VASP input preparation. |
|
One named, ordered ladder of bounded remedies. |
|
One explicit bounded remedy proposal. |
|
Classified result of one supervised VASP execution. |
Functions¶
|
Remove the largest reproducible k-point detail blocks from OUTCAR. |
|
Remove standard rerun outputs while preserving declared names. |
|
Diagnose completion and final convergence from VASP output files. |
|
Return the final |
|
Return the final volume reported by |
|
Return OUTCAR's maximum plane-wave count. |
|
Return the last optimizer step size from OUTCAR. |
|
Validate VASP's conservative absolute-path length constraint. |
|
Assemble POTCAR from explicit species and a configurable suffix policy. |
|
Calculate a reciprocal-length automatic grid. |
|
Calculate a conservative VASP band count from input metadata. |
|
Replace CONTCAR's comment with the reference POSCAR comment. |
|
Derive one reproducible 63-bit seed from a caller-supplied string. |
|
Make a left-handed POSCAR lattice right-handed without moving sites. |
|
Write a non-potential metadata summary suitable for logs. |
|
Prepare POSCAR, POTCAR, KPOINTS, and INCAR with recorded choices. |
|
Apply a deterministic bounded perturbation to POSCAR site coordinates. |
|
Read the last value of each simple INCAR assignment. |
|
Read a VASP-5 POSCAR header without interpreting site coordinates. |
|
Multiply POSCAR's universal linear scale by a positive factor. |
|
Return the explicit comment override or a five-per-atom default. |
|
Atomically replace selected INCAR tags while preserving other lines. |
|
Write a standard automatic KPOINTS file. |
|
Explicitly apply a proposed remedy through a replayable workdir batch. |
|
Return the job-scoped remedy history file of one job payload. |
|
Return, but do not apply, the next remedy of policy. |
|
Register one named remedy policy and return the normalized result. |
|
Return one registered remedy policy, naming the alternatives if absent. |
Return the names of every registered remedy policy, in registration order. |
|
|
Run VASP with live VASP-5/6 diagnostics and a structured report. |
Package Contents¶
- httk.workflow.vasp.VASP_RESTART_ARTIFACTS: tuple[str, Ellipsis] = ('CONTCAR', 'vasp-run-report.json')¶
- httk.workflow.vasp.clean_outcar(path='OUTCAR', output='OUTCAR.cleaned')[source]¶
Remove the largest reproducible k-point detail blocks from OUTCAR.
- Parameters:
path (str | os.PathLike[str]) – Read the OUTCAR file at this path.
output (str | os.PathLike[str]) – Write the cleaned OUTCAR to this path.
- Returns:
The cleaned output path.
- Return type:
- httk.workflow.vasp.clean_vasp_outputs(directory='.', *, keep=(), also_remove=())[source]¶
Remove standard rerun outputs while preserving declared names.
The files in
VASP_RESTART_ARTIFACTS—CONTCARandvasp-run-report.json— are kept even without keep, because they are what the remedy machinery and restart promotion read: a pre-run cleanup that deletes them destroys the evidence of the run it is cleaning up after. Name them in also_remove to delete them anyway.- Parameters:
directory (str | os.PathLike[str]) – Remove outputs from this directory.
keep (collections.abc.Iterable[str]) – Preserve these output names.
also_remove (collections.abc.Iterable[str]) – Allow restart artifacts to be removed by naming them here.
- Returns:
The paths removed from the directory.
- Raises:
ValueError – If an output to remove is not a regular file.
- Return type:
tuple[pathlib.Path, Ellipsis]
- httk.workflow.vasp.diagnose_vasp_files(directory='.')[source]¶
Diagnose completion and final convergence from VASP output files.
- Parameters:
directory (str | os.PathLike[str]) – Read VASP output files from this directory.
- Returns:
Diagnostics inferred from the available output files.
- Return type:
tuple[httk.workflow.supervision.Diagnostic, Ellipsis]
- httk.workflow.vasp.last_oszicar_energy(path='OSZICAR')[source]¶
Return the final
E0value, orNonewhen it is absent.- Parameters:
path (str | os.PathLike[str]) – Read the OSZICAR file at this path.
- Returns:
The final parsed
E0value, orNonewhen no value is found.- Return type:
float | None
- httk.workflow.vasp.last_vasprun_volume(path='vasprun.xml')[source]¶
Return the final volume reported by
vasprun.xml.- Parameters:
path (str | os.PathLike[str]) – Read the vasprun XML file at this path.
- Returns:
The final parsed volume, or
Nonewhen no volume is found.- Return type:
float | None
- httk.workflow.vasp.outcar_plane_wave_count(path='OUTCAR')[source]¶
Return OUTCAR’s maximum plane-wave count.
- Parameters:
path (str | os.PathLike[str]) – Read the OUTCAR file at this path.
- Returns:
The parsed maximum plane-wave count, or
Nonewhen absent.- Return type:
int | None
- httk.workflow.vasp.outcar_potim(path='OUTCAR')[source]¶
Return the last optimizer step size from OUTCAR.
- Parameters:
path (str | os.PathLike[str]) – Read the OUTCAR file at this path.
- Returns:
The last parsed optimizer step size, or
Nonewhen absent.- Return type:
float | None
- httk.workflow.vasp.validate_vasp_workdir(path='.', *, maximum_length=240)[source]¶
Validate VASP’s conservative absolute-path length constraint.
- Parameters:
path (str | os.PathLike[str]) – Resolve and validate this workdir path.
maximum_length (int) – Reject resolved paths longer than this byte length.
- Returns:
The resolved workdir path.
- Raises:
ValueError – If the limit is invalid or the resolved path is too long.
- Return type:
- httk.workflow.vasp.DEFAULT_KPOINT_CENTERING = 'Monkhorst-Pack'¶
- httk.workflow.vasp.KPOINT_CENTERINGS = ('Gamma', 'Monkhorst-Pack')¶
- class httk.workflow.vasp.PoscarHeader[source]¶
The VASP-5 header information needed by execution helpers.
- Parameters:
comment – Preserve the POSCAR comment line.
scale – Preserve the universal POSCAR scale.
lattice – Preserve the three lattice vectors.
species – Preserve the VASP-5 species names.
counts – Preserve the atom count for each species.
- class httk.workflow.vasp.PotcarAssembly[source]¶
One assembled POTCAR and the provenance of every piece in it.
- Parameters:
path – Record the assembled POTCAR path.
library – Record the pseudopotential library root.
choices – Record the selected potential for each species.
provenance – Record the provenance output path.
- path: pathlib.Path¶
- library: pathlib.Path¶
- choices: tuple[PotcarChoice, Ellipsis]¶
- provenance: pathlib.Path¶
- class httk.workflow.vasp.PotcarChoice[source]¶
Which pseudopotential of a library one species was given.
The suffix policy of
assemble_potcar()silently prefers one PAW variant over another, and the choice changes the numbers a calculation produces, so every choice is recorded: the variant directory, the suffix that selected it, the full source path, its digest, and theTITELthe potential names itself with.- Parameters:
species – Record the POSCAR species name.
variant – Record the selected pseudopotential directory name.
suffix – Record the suffix selected for the species.
source – Record the source potential path.
sha256 – Record the source file digest.
titel – Record the potential’s
TITELvalue, when present.
- source: pathlib.Path¶
- class httk.workflow.vasp.VaspPreparationOptions[source]¶
Options for dependency-free VASP input preparation.
accuracy_per_atomis the target total-energy accuracy in eV per atom:EDIFFGis set to that budget for the whole cell andEDIFFto the same budget divided byediff_margin, so the electronic loop converges roughly one and a half orders of magnitude tighter than the ionic loop it feeds. The margin of33is a heuristic, empirical default carried over from httk v1, not a derived quantity.- Parameters:
kpoint_density – Set the reciprocal-length k-point density.
centering – Select the automatic k-point centering.
accuracy_per_atom – Set the target total-energy accuracy, or disable derived accuracy tags when unset.
ediff_margin – Divide the cell accuracy by this margin for
EDIFF.pseudopotential_library – Assemble POTCAR from this library when set.
parallel_tag – Set the selected parallel INCAR tag when set.
parallel_value – Set the value for the selected parallel tag.
normalize_handedness – Normalize a left-handed POSCAR before preparation.
incar_tags – Apply these explicit INCAR tags before derived defaults.
- pseudopotential_library: str | os.PathLike[str] | None = None¶
- incar_tags: collections.abc.Mapping[str, object]¶
- httk.workflow.vasp.assemble_potcar(library, *, poscar='POSCAR', output='POTCAR', suffix_preference=('_3', '_2', '_d', '_sv', '_pv', '', '_h', '_s'), provenance=None)[source]¶
Assemble POTCAR from explicit species and a configurable suffix policy.
The suffix policy decides which PAW variant each species gets, so the result describes what it chose: the returned
PotcarAssemblynames every potential, and the same record is written next to the POTCAR as<POTCAR>.provenance.jsonunless provenance names another file.- Parameters:
library (str | os.PathLike[str]) – Search this pseudopotential library root.
poscar (str | os.PathLike[str]) – Read species names from this POSCAR.
output (str | os.PathLike[str]) – Write the assembled POTCAR to this path.
suffix_preference (collections.abc.Iterable[str]) – Try these species suffixes in order.
provenance (str | os.PathLike[str] | None) – Write provenance to this path, or beside the POTCAR when unset.
- Returns:
The assembled POTCAR and its provenance.
- Raises:
FileNotFoundError – If a species has no matching potential.
- Return type:
- httk.workflow.vasp.automatic_kpoint_grid(density, *, poscar='POSCAR', minimum=3, equal=False, bump=0)[source]¶
Calculate a reciprocal-length automatic grid.
- Parameters:
density (float) – Scale reciprocal lengths by this positive density.
poscar (str | os.PathLike[str]) – Read lattice vectors from this POSCAR.
minimum (int) – Enforce this minimum value in each grid direction.
equal (bool) – Use the largest direction value for all directions.
bump (int) – Add this nonnegative amount to each calculated direction.
- Returns:
The three automatic grid dimensions.
- Raises:
ValueError – If an argument is invalid or the lattice is singular.
- Return type:
- httk.workflow.vasp.calculate_nbands(*, poscar='POSCAR', potcar='POTCAR', incar='INCAR', divisor=None)[source]¶
Calculate a conservative VASP band count from input metadata.
The count is a heuristic, deliberately generous margin over VASP’s own default of roughly half the valence electrons plus half the atom count: too few bands is a run that stops with
TOO FEW BANDSor converges to the wrong state, while a handful of extra empty bands costs only time. The spin-polarized branch adds0.6 * electronsplus a magnetization- or atom-count-derived margin, and the maximum of the candidate formulas wins; the numbers themselves are empirical defaults carried over from httk v1. The result is rounded up to an even number, and to a multiple of divisor when a parallel band divisor (NPAR) is in play, because VASP would otherwise round NBANDS up itself and report a changed value.- Parameters:
poscar (str | os.PathLike[str]) – Read species and atom counts from this POSCAR.
potcar (str | os.PathLike[str]) – Read valence counts from this POTCAR.
incar (str | os.PathLike[str]) – Read spin and magnetization tags from this INCAR.
divisor (int | None) – Round the result up to a multiple of this positive divisor.
- Returns:
The conservative even band count.
- Raises:
ValueError – If the divisor or required input metadata is invalid.
- Return type:
- httk.workflow.vasp.contcar_to_poscar(contcar='CONTCAR', *, reference='POSCAR', output='POSCAR')[source]¶
Replace CONTCAR’s comment with the reference POSCAR comment.
- Parameters:
contcar (str | os.PathLike[str]) – Read the relaxed structure from this CONTCAR path.
reference (str | os.PathLike[str]) – Read the replacement comment from this POSCAR path.
output (str | os.PathLike[str]) – Write the resulting POSCAR to this path.
- Returns:
The written POSCAR path.
- Raises:
ValueError – If either input file is empty.
- Return type:
- httk.workflow.vasp.derive_seed(entropy)[source]¶
Derive one reproducible 63-bit seed from a caller-supplied string.
The string is the caller’s own identity of the perturbation — an attempt ordinal, a job key, a remedy step — so the same attempt always derives the same seed and two different attempts derive different ones, without anything reading a clock or a global random state.
- Parameters:
entropy (str) – Identify the perturbation with this nonempty string.
- Returns:
The reproducible seed.
- Raises:
ValueError – If entropy is not a nonempty string.
- Return type:
- httk.workflow.vasp.normalize_poscar_handedness(path='POSCAR')[source]¶
Make a left-handed POSCAR lattice right-handed without moving sites.
- Parameters:
path (str | os.PathLike[str]) – Normalize the POSCAR file at this path.
- Returns:
The normalized POSCAR path.
- Return type:
- httk.workflow.vasp.potcar_summary(path='POTCAR', output='POTCAR.summary')[source]¶
Write a non-potential metadata summary suitable for logs.
- Parameters:
path (str | os.PathLike[str]) – Read POTCAR metadata from this path.
output (str | os.PathLike[str]) – Write the summary to this path.
- Returns:
The written summary path.
- Return type:
- httk.workflow.vasp.prepare_vasp_inputs(options=None, *, directory='.')[source]¶
Prepare POSCAR, POTCAR, KPOINTS, and INCAR with recorded choices.
incar_tagsis applied to the INCAR first and wins over everything derived afterwards: the derived values are defaults for what the caller did not say, so an explicitEDIFF,MAGMOM, orNBANDSsurvives preparation, and an explicitISPINis what the band-count heuristic reads.- Parameters:
options (VaspPreparationOptions | None) – Use these preparation options, or their defaults when unset.
directory (str | os.PathLike[str]) – Prepare the VASP inputs in this directory.
- Returns:
A record of prepared files and selected input choices.
- Raises:
ValueError – If the workdir, options, or input metadata is invalid.
- Return type:
- httk.workflow.vasp.rattle_poscar(path='POSCAR', *, amplitude=0.01, seed=None, entropy=None)[source]¶
Apply a deterministic bounded perturbation to POSCAR site coordinates.
A perturbation has to be reproducible and different between two attempts of the same calculation, so this function never invents entropy of its own: either seed names the stream explicitly, or entropy is a string
derive_seed()turns into one — typically something attempt-derived, such asf"{job_key}:{attempt_ordinal}". Giving neither is refused rather than silently repeated, because two retries that rattle identically are two identical calculations.- Parameters:
- Returns:
The updated POSCAR path.
- Raises:
ValueError – If the perturbation settings or coordinate rows are invalid.
- Return type:
- httk.workflow.vasp.read_incar(path='INCAR')[source]¶
Read the last value of each simple INCAR assignment.
- httk.workflow.vasp.read_poscar_header(path='POSCAR')[source]¶
Read a VASP-5 POSCAR header without interpreting site coordinates.
- Parameters:
path (str | os.PathLike[str]) – Read the POSCAR file at this path.
- Returns:
The parsed POSCAR header.
- Raises:
ValueError – If the header is too short or malformed.
- Return type:
- httk.workflow.vasp.scale_poscar_lattice(factor, path='POSCAR')[source]¶
Multiply POSCAR’s universal linear scale by a positive factor.
- Parameters:
factor (float) – Multiply the current scale by this positive finite value.
path (str | os.PathLike[str]) – Update the POSCAR file at this path.
- Returns:
The updated POSCAR path.
- Raises:
ValueError – If the factor or POSCAR scale line is invalid.
- Return type:
- httk.workflow.vasp.suggested_magnetic_moments(path='POSCAR')[source]¶
Return the explicit comment override or a five-per-atom default.
The five Bohr magnetons per atom are a heuristic starting guess, not a physical prediction: a deliberately high initial moment lets a spin-polarized relaxation fall into a low-spin solution, whereas starting too low tends to keep it there, so overestimating is the safer direction. The value of five is the empirical default carried over from httk v1. Encode a per-structure choice in the POSCAR comment as
[MAGMOM=...].- Parameters:
path (str | os.PathLike[str]) – Read the POSCAR comment and species counts from this path.
- Returns:
The explicit or generated MAGMOM value.
- Return type:
- httk.workflow.vasp.update_incar(values, path='INCAR')[source]¶
Atomically replace selected INCAR tags while preserving other lines.
VASP allows several
;-separated assignments per line, andread_incar()reads them all, so an update has to rewrite the individual statements of a line rather than drop or keep the whole line: updatingISYMinISPIN = 2 ; ISYM = 2leavesISPIN = 2and appends the newISYM, instead of leaving a line that still assigns the old value.- Parameters:
values (collections.abc.Mapping[str, object]) – Replace these INCAR tag assignments.
path (str | os.PathLike[str]) – Update the INCAR file at this path.
- Returns:
The updated INCAR path.
- Raises:
ValueError – If a tag name is empty or invalid.
- Return type:
- httk.workflow.vasp.write_automatic_kpoints(grid, path='KPOINTS', *, centering=DEFAULT_KPOINT_CENTERING)[source]¶
Write a standard automatic KPOINTS file.
The centering defaults to
DEFAULT_KPOINT_CENTERINGhere, inVaspPreparationOptions, and in the Bash bridge, so a workflow that hits a k-point failure class still has theGammaremedy available.- Parameters:
grid (collections.abc.Sequence[int]) – Write these three positive grid dimensions.
path (str | os.PathLike[str]) – Write the KPOINTS file to this path.
centering (str) – Use this supported k-point centering.
- Returns:
The written KPOINTS path.
- Raises:
ValueError – If the grid or centering is unsupported.
- Return type:
- httk.workflow.vasp.DEFAULT_REMEDY_HISTORY = '.httk-vasp/remedies.json'¶
- httk.workflow.vasp.REMEDY_OPERATIONS = ('bump_bands', 'bump_kpoints', 'centering', 'contcar_to_poscar', 'equal_kpoints', 'scale_ediff',...¶
- class httk.workflow.vasp.RemedyPolicy[source]¶
One named, ordered ladder of bounded remedies.
A policy is data, not code: sequences maps a diagnosed problem to the escalating steps tried for it, precedence orders the problems so one diagnosis is remedied at a time, and refusals names the problems this policy deliberately has no input remedy for. A group with its own reviewed practice registers its own policy with
register_remedy_policy()instead of editing this module.- Parameters:
name – Identify the registered policy.
sequences – Map diagnostic codes to ordered remedy changes.
precedence – Order diagnostic codes for remedy selection.
refusals – Explain diagnostic codes this policy will not remedy.
- sequences: collections.abc.Mapping[str, RemedySequence]¶
- refusals: collections.abc.Mapping[str, str]¶
- class httk.workflow.vasp.VaspRemedyDecision[source]¶
One explicit bounded remedy proposal.
- Parameters:
policy – Identify the policy that produced the decision.
problem – Identify the selected diagnostic problem.
step – Record the ladder step considered.
changes – Record the input changes to apply.
give_up – Mark that no remedy should be applied.
reason – Explain the decision.
- httk.workflow.vasp.apply_vasp_remedy(decision, *, directory='.', history_path=DEFAULT_REMEDY_HISTORY, durable=False)[source]¶
Explicitly apply a proposed remedy through a replayable workdir batch.
The history is recorded before the inputs change, so an application interrupted halfway advances the ladder rather than repeating one remedy for ever. A history file inside the VASP directory is written by the same replayable batch as the inputs; a job-scoped one, which the batch cannot reach, is written atomically just before the batch commits.
durable synchronizes the batch and the job-scoped history on a durable workspace, so a power cut cannot lose a remedy the ladder has already recorded. It defaults to
Falsefor a caller applying a remedy outside an attempt; the Bash bridge sources it from the workspace durability contract.- Parameters:
decision (VaspRemedyDecision) – Apply this previously planned remedy.
directory (str | os.PathLike[str]) – Apply changes in this VASP directory.
history_path (str | os.PathLike[str]) – Read and update the remedy history at this path.
durable (bool) – Synchronize the published batch when true.
- Returns:
The committed remedy batch path.
- Raises:
ValueError – If the decision gives up or its changes are not applicable.
- Return type:
- httk.workflow.vasp.job_remedy_history_path(payload)[source]¶
Return the job-scoped remedy history file of one job payload.
The escalation ladder is a property of the job, not of the directory one attempt happened to run in, so it lives beside the job state in
<payload>/.httk-job/rather than in the workdir. A job with an isolated workdir therefore keeps escalating instead of silently starting the ladder from the beginning on every attempt.- Parameters:
payload (str | os.PathLike[str]) – Locate the job payload.
- Returns:
The job-scoped remedy history path.
- Return type:
- httk.workflow.vasp.plan_vasp_remedy(diagnostics, *, directory='.', history_path=DEFAULT_REMEDY_HISTORY, policy='reviewed-v1')[source]¶
Return, but do not apply, the next remedy of policy.
The decision is validated against the real contents of directory: a ladder step whose changes cannot be executed there is skipped, and the first executable step wins. When nothing is left the decision gives up, so a runner only ever hands
apply_vasp_remedy()a remedy it can perform.- Parameters:
diagnostics (collections.abc.Sequence[httk.workflow.supervision.Diagnostic]) – Supply diagnostics from the VASP run.
directory (str | os.PathLike[str]) – Inspect and plan changes in this VASP directory.
history_path (str | os.PathLike[str]) – Read the remedy history from this path.
policy (str) – Select this registered remedy policy.
- Returns:
The next applicable remedy decision.
- Raises:
ValueError – If the remedy history or policy is invalid.
- Return type:
- httk.workflow.vasp.register_remedy_policy(name, sequences, precedence, *, refusals=None, replace=False)[source]¶
Register one named remedy policy and return the normalized result.
Every problem named in sequences must also appear in precedence, which is what decides which of several simultaneous diagnostics is acted on, and every change must spell one supported remedy operation, so a policy that cannot be executed is refused when it is registered rather than when a run needs it.
- Parameters:
name (str) – Register the policy under this nonempty name.
sequences (collections.abc.Mapping[str, collections.abc.Sequence[collections.abc.Sequence[tuple[str, object]]]]) – Define ordered changes for each diagnostic code.
precedence (collections.abc.Sequence[str]) – Order diagnostic codes for selection.
refusals (collections.abc.Mapping[str, str] | None) – Explain diagnostic codes deliberately left without a remedy.
replace (bool) – Replace an existing policy with this definition.
- Returns:
The normalized registered policy.
- Raises:
ValueError – If the policy is duplicate, incomplete, or unsupported.
- Return type:
- httk.workflow.vasp.remedy_policy(name)[source]¶
Return one registered remedy policy, naming the alternatives if absent.
- Parameters:
name (str) – Select this registered policy.
- Returns:
The selected remedy policy.
- Raises:
ValueError – If no policy has this name.
- Return type:
- httk.workflow.vasp.remedy_policy_names()[source]¶
Return the names of every registered remedy policy, in registration order.
- class httk.workflow.vasp.VaspRunReport[source]¶
Classified result of one supervised VASP execution.
- Parameters:
process – Preserve the supervised process result.
classification – Record the final VASP run classification.
diagnostics – Preserve live and file-level diagnostics.
- diagnostics: tuple[httk.workflow.supervision.Diagnostic, Ellipsis]¶
- write(path)[source]¶
Write the report as JSON.
- Parameters:
path (str | os.PathLike[str]) – Write the report to this path.
- Returns:
The report path.
- Return type:
- httk.workflow.vasp.run_vasp(argv, *, directory='.', timeout=None, termination_grace=10.0, report_path='vasp-run-report.json')[source]¶
Run VASP with live VASP-5/6 diagnostics and a structured report.
- Parameters:
argv (collections.abc.Sequence[str]) – Execute this VASP command argument vector.
directory (str | os.PathLike[str]) – Run VASP in this directory.
timeout (float | None) – Stop the process after this duration when set.
termination_grace (float) – Allow this duration for graceful termination.
report_path (str | os.PathLike[str]) – Write the structured report at this workdir-relative path.
- Returns:
The classified VASP run report.
- Return type: