httk.analyse.matsci¶
Materials-science analysis built on generic numerical primitives.
Submodules¶
Classes¶
A normalized float convex-hull phase diagram. |
|
Mutable, not-thread-safe accumulator for incrementally building a phase diagram. |
Package Contents¶
- class httk.analyse.matsci.PhaseDiagram(elements, ids, compositions, energies_per_atom, tolerance, unknown_ids, unknown_compositions)¶
A normalized float convex-hull phase diagram.
Construct with
from_compositions()orfrom_structures(). Energies supplied to either factory are total formula-unit or unit-cell energies and are divided by the corresponding atom count. An energy ofNonemarks an unknown-energy phase, which is retained in the separateunknown_ids/unknown_compositionschannel and contributes elements toelements, potentially widening the composition space, but takes no part in hull construction or the indexed hull API. At least one supplied phase must have a known energy; an input whose energies are allNoneis rejected. All exposed compositions and energies are plain floats.Hull membership is delegated to
LowerConvexHull. At duplicated compositions only the lower-energy polymorph is stable, except that every polymorph tied within the requested energytoleranceis stable.Nonedecompositions identify stable phases, including uncontested phases outside the convex hull of every other input.- Parameters:
elements (tuple[str, Ellipsis]) – Element-coordinate labels in sorted order.
ids (tuple[str, Ellipsis]) – Identifiers for energy-known phases in input order.
compositions (tuple[tuple[float, Ellipsis], Ellipsis]) – Normalized composition rows for energy-known phases.
energies_per_atom (tuple[float, Ellipsis]) – Per-atom energies for energy-known phases.
tolerance (float) – Maximum energy excess treated as stable.
unknown_ids (tuple[str, Ellipsis]) – Identifiers for phases without known energy.
unknown_compositions (tuple[tuple[float, Ellipsis], Ellipsis]) – Normalized composition rows for phases without known energy.
- classmethod from_compositions(compositions, energies, ids=None, *, tolerance=1e-08)¶
Build a diagram from formula-unit compositions and total energies.
Each composition maps an element label to its count in the formula unit to which the matching total energy refers. An energy of
Noneretains the phase in the unknown-energy channel without including it in the hull or indexed hull API. Counts must be finite and non-negative, with a strictly positive total atom count. Elements are sorted independently of mapping insertion order before rows are normalized to atomic fractions. At least one energy must be known; inputs whose energies are allNoneare rejected.idsentries may individually beNoneto derive the default formula label for that phase.- Parameters:
compositions (collections.abc.Sequence[collections.abc.Mapping[str, int | float | fractions.Fraction]]) – Formula-unit element counts for each phase.
energies (collections.abc.Sequence[float | None]) – Total formula-unit energies corresponding to
compositions.ids (collections.abc.Sequence[str | None] | None) – Optional phase identifiers, with
Noneentries using formula labels.tolerance (float) – Maximum energy excess treated as stable.
- Returns:
The normalized phase diagram.
- Raises:
ValueError – If the phase data, energies, identifiers, or tolerance are invalid.
- Return type:
Self
- classmethod from_structures(structures, energies, ids=None, *, tolerance=1e-08)¶
Build a diagram from structures and their total unit-cell energies.
Each site contributes its named species’
chemical_symbolsweighted byconcentration."vacancy"contributes no atoms;"X"is rejected because an unknown element cannot define a composition coordinate. An energy ofNoneretains the phase in the unknown-energy channel without including it in the hull or indexed hull API. Default identifiers are deterministic alphabetically sorted labels using the (possibly fractional) unit-cell counts without reducing them, andidsentries may individually beNoneto derive that default label. At least one energy must be known; inputs whose energies are allNoneare rejected.- Parameters:
structures (collections.abc.Sequence[httk.atomistic.StructureLike]) – Structures supplying the phase compositions.
energies (collections.abc.Sequence[float | None]) – Total unit-cell energies corresponding to
structures.ids (collections.abc.Sequence[str | None] | None) – Optional phase identifiers, with
Noneentries using formula labels.tolerance (float) – Maximum energy excess treated as stable.
- Returns:
The normalized phase diagram.
- Raises:
ValueError – If the structures, energies, identifiers, or tolerance are invalid.
- Return type:
Self
- property elements: tuple[str, Ellipsis]¶
Return the element-coordinate order used by
compositions.
- property unknown_ids: tuple[str, Ellipsis]¶
Return identifiers for phases without known energy in input order.
- property compositions: tuple[tuple[float, Ellipsis], Ellipsis]¶
Return composition-fraction rows for energy-known phases in
elementsorder.
- property unknown_compositions: tuple[tuple[float, Ellipsis], Ellipsis]¶
Return composition-fraction rows for phases without known energy in
elementsorder.
- property energies_per_atom: tuple[float, Ellipsis]¶
Return energies per atom for energy-known phases in input order.
- property energy_above_hull: tuple[float, Ellipsis]¶
Return non-negative energy distances from the lower hull in per-atom units.
- property phase_lines: tuple[tuple[int, int], Ellipsis]¶
Return sorted midpoint-supported stable tie-lines as
(smaller, larger)indices.
- decomposition(index)¶
Return optimal stable-phase
(index, weight)pairs, orNonewhen stable.
- is_stable(index)¶
Return whether the phase at
indexis stable within the energy tolerance.
- plot(*, ax=None, show_unstable=True, label_stable=True, show_unknown=True)¶
Plot the phase diagram and return its matplotlib Axes.
Binary diagrams use the fraction of the second element on the x axis. The y axis is formation energy relative to the lowest stable pure-element endpoints when both are present, and raw energy per atom otherwise. One-element diagrams use raw energy at a single composition point. Unknown-energy phases are shown as open gray squares at
y=0.0in binary diagrams (including raw-energy mode) whenshow_unknownis true; they do not affect the energy reference or hull geometry.Diagrams with three or more elements use a regular composition polygon whose corner
kis at angle2*pi*k/N. Phase lines are drawn individually in black; stable phases are filled, unstable phases are open, and unknown-energy phases are open gray squares. Matplotlib is imported only here and this method never callsshowor writes a file.- Parameters:
- Returns:
The
matplotlib.axes.Axescontaining the diagram.- Raises:
ImportError – If Matplotlib is unavailable.
- Return type:
Any
- class httk.analyse.matsci.PhaseDiagramBuilder(*, tolerance=1e-08)¶
Mutable, not-thread-safe accumulator for incrementally building a phase diagram.
- Parameters:
tolerance (float) – Maximum energy excess treated as stable when building the diagram.
- add_phase(composition, energy, id=None)¶
Add a formula-unit composition and return this builder for chaining.
- Parameters:
composition (collections.abc.Mapping[str, int | float | fractions.Fraction]) – Formula-unit element counts for the phase.
energy (float | None) – Total formula-unit energy, or
Nonewhen unknown.id (str | None) – Optional phase identifier.
- Returns:
This builder.
- Raises:
TypeError – If
compositionis not a mapping.- Return type:
Self
- add_structure(structure, energy, id=None)¶
Convert and add a structure, returning this builder for chaining.
- Parameters:
structure (httk.atomistic.StructureLike) – Structure supplying the phase composition.
energy (float | None) – Total unit-cell energy, or
Nonewhen unknown.id (str | None) – Optional phase identifier.
- Returns:
This builder.
- Return type:
Self
- build()¶
Build an independent snapshot, requiring at least one known phase energy.
The builder may contain unknown-energy phases, but an all-
Noneenergy collection is rejected by the factory validation used to create the snapshot.- Returns:
An independent phase-diagram snapshot.
- Raises:
ValueError – If no phase has a known energy or the phase data is invalid.
- Return type: