aiida_pythonjob_ins.conversions¶
Mappings between Euphonic objects and AiiDA’s native materials-science types.
AiiDA ships domain data types for reciprocal-space data (https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/data_types.html#materials-science-data-types):
KpointsData– k-/q-point positions (+ optional labels + cell). We use it as the q-point specification for Fourier interpolation, and as the natural representation of a phonon band path.BandsData(aKpointsDatasubclass) – band energies on those points. A EuphonicQpointPhononModesis essentiallyBandsData(frequencies) plus eigenvectors, so we build aBandsDataby composition and keep the eigenvectors in our ownQpointPhononModesData.
Using BandsData also unlocks existing AiiDA plotting, e.g.
bands.show_mpl() pops up a matplotlib band-structure plot without any
AiiDALab dependency.
These are plain converter functions, deliberately NOT calcfunctions. They
are the reusable “verbs” that produce an object (an AiiDA node or a euphonic
object), called from contexts that each preclude the decorator: inside the
workflow’s calcfunctions (generate_band_path, assemble_bands) and inside
Data-class methods (to_structure/to_kpoints/to_bands), which must work
without any engine. Several also take/return non-node objects (euphonic
Crystal, ndarray), which a calcfunction could not accept. Provenance is
recorded one level up, by the @calcfunction/PythonJob wrappers in
aiida_pythonjob_ins.workflows that call these helpers.
(The reverse direction – node -> plain Python for aiida-pythonjob inputs – is
a deserialization concern and lives in aiida_pythonjob_ins.serialization.)
Functions¶
|
Convert a Euphonic |
|
Convert a native AiiDA |
|
Convert a |
|
Build a |
|
Convert a Euphonic |
|
Derive a concise, human-readable legend label for each line of a collection. |
|
Convert a Euphonic |
Convert a native |
|
|
Compose a |
Module Contents¶
- aiida_pythonjob_ins.conversions.crystal_to_structure(crystal: euphonic.Crystal) aiida.orm.StructureData[source]¶
Convert a Euphonic
Crystalto a native AiiDAStructureData.Single source of truth for the Crystal -> StructureData direction (used by
EuphonicCrystalDataand byCrystalStructureMixin.to_structure). Uses AiiDA’s native API only – no ASE. Euphonic stores fractional positions;StructureDatawants Cartesian. Masses are carried over for fidelity.
- aiida_pythonjob_ins.conversions.structure_to_crystal(structure: aiida.orm.StructureData) euphonic.Crystal[source]¶
Convert a native AiiDA
StructureDatato a EuphonicCrystal.The reverse of
crystal_to_structure().Crystalrequires atom masses, whichStructureDatacarries on its kinds.
- aiida_pythonjob_ins.conversions.structure_to_spglib_cell(structure: aiida.orm.StructureData) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]¶
Convert a
StructureDatato a spglib/seekpath cell tuple.Returns
(lattice, positions, numbers)by reusing Euphonic’sCrystal.to_spglib_cell(rather than re-deriving the species numbering by hand).
- aiida_pythonjob_ins.conversions.qpoints_to_kpoints_data(qpoints: numpy.ndarray, cell: numpy.ndarray, labels: list[tuple[int, str]] | None = None) aiida.orm.KpointsData[source]¶
Build a
KpointsDatafrom fractional q-points, a cell and labels.
- aiida_pythonjob_ins.conversions.spectrum1d_to_xydata(spectrum: Any) aiida.orm.XyData[source]¶
Convert a Euphonic
Spectrum1D(e.g. a DOS) to a nativeXyData.Uses
get_bin_centres()so the x and y arrays have matching lengths (Spectrum1Dstores bin edges inx_datawhen it is histogram-like). Unit labels are recorded on theXyDataarrays.
- aiida_pythonjob_ins.conversions.spectrum_collection_labels(collection: euphonic.Spectrum1DCollection) list[str][source]¶
Derive a concise, human-readable legend label for each line of a collection.
Only the
line_datametadata keys that actually differ between lines are used, so a collection already grouped down to one line – where every key is common rather than varying – is labelled"Total"instead of repeating metadata that no longer distinguishes anything.atom_symbol, if it varies, is rendered bare ("C"); other varying keys are appended in parentheses ("C (order 2)") in the fixed order atom_symbol/quantum_order/detector_angle, with any other, unrecognised keys appended afterwards in sorted order for determinism. This is deliberately a plotting convenience, not a lossless encoding – the full metadata travels separately (seespectrum_collection_to_xydata()).
- aiida_pythonjob_ins.conversions.spectrum_collection_to_xydata(collection: euphonic.Spectrum1DCollection) aiida.orm.XyData[source]¶
Convert a Euphonic
Spectrum1DCollectionto a nativeXyData.Like
spectrum1d_to_xydata(), one x array of bin centres is shared by every line; unlike it, there are several y arrays (one per line), and the collection’s metadata – which is what actually distinguishes the lines – would otherwise be lost. It is preserved on the node as two attributes:spectrum_metadata– the metadata common to the whole collection;spectrum_line_data– the list of per-line metadata dicts.
Both are ordinary AiiDA node attributes: JSON-serialisable Python values attached before the node is stored, becoming immutable once it is (matching the provenance guarantee AiiDA gives every stored node). They sit alongside
XyData’s own attributes without collision (its arrays are namespaced under anarray|prefix). Seexydata_to_spectrum_collection()for the reverse direction, which is what makes this round trip reversible.Each y array is additionally named with a concise label from
spectrum_collection_labels(), sofor name, y, unit in xy.get_y()is directly plottable without parsing the attached metadata.
- aiida_pythonjob_ins.conversions.xydata_to_spectrum_collection(xy: aiida.orm.XyData) euphonic.Spectrum1DCollection[source]¶
Convert a native
XyDataback to a EuphonicSpectrum1DCollection.The reverse of
spectrum_collection_to_xydata(): rebuilds the collection’s metadata from thespectrum_metadata/spectrum_line_datanode attributes, so the recovered collection can be grouped, selected and summed by that metadata exactly as the original could – which is what lets the grouping step inaiida_pythonjob_ins.workflows.toscaoperate on data read back from the graph rather than needing the original Python object.Bin centres are recovered, not edges (see the module-level note on
spectrum1d_to_xydata()): the resulting collection is a point spectrum, which is sufficient for grouping, summing and broadening but not for exact rebinning.
- aiida_pythonjob_ins.conversions.modes_to_bands_data(modes: Any, kpoints: aiida.orm.KpointsData | None = None) aiida.orm.BandsData[source]¶
Compose a
BandsDatafrom EuphonicQpointPhononModes.BandsDatais a join: q-points + cell + high-symmetry labels (from the path) plus frequencies (frommodes); neither Euphonic class holds all of it (QpointPhononModeshas no labels;Spectrum1DCollectionhas no 3-D q-points/eigenvectors).Parameters¶
- modes
A Euphonic
QpointPhononModesobject (supplies q-points + frequencies).- kpoints
Optional
KpointsDataproviding the exact q-point positions and high-symmetry labels (e.g. the path used to computemodes). If given, its q-points and cell are validated againstmodes(a mismatch means path and modes are inconsistent). If omitted, positions come frommodesand labels fall back to Euphonic’s automatic tick labels (QpointPhononModes.get_dispersion().x_tick_labels).