Utility Modules Reference
aiida_muon.utils.sites_supercells
Functions for generating the initial grid of candidate muon sites and building supercells.
niche_add_impurities
Generates a grid of candidate muon (impurity) positions using the NICHE algorithm. Returns a list of fractional coordinate vectors, each offset by +0.001 to break symmetry-exact positions.
Parameters
| Name | Type | Description |
|---|---|---|
structure |
pymatgen.core.Structure |
Host crystal structure (no muon) |
niche_atom |
str |
Chemical symbol used as muon placeholder (typically 'H') |
niche_spacing |
float |
Minimum spacing (Å) between two grid points |
niche_distance |
float |
Minimum distance from host atoms (Å); hardcoded to 1 in the workflow |
Returns list[np.ndarray] — fractional positions of candidate sites.
gensup
Creates one supercell per candidate site by making a copy of the unit cell,
expanding it by sc_mat, and appending the muon.
Returns list[pymatgen.core.Structure] — supercells with embedded muon.
compute_suggest_supercell_size
Heuristic that estimates a suitable supercell size from the unit-cell lattice parameters (targets a minimum cell dimension of roughly 9 Å).
aiida_muon.utils.clustering
Symmetry-aware clustering of relaxed muon positions.
analyze_structures
Groups the relaxed muon positions by spatial proximity (within d_tol Å) and,
if magmom is given, by magnetic symmetry. Returns a dict with:
unique_pos— list of unique fractional positionsmapping— integer array mapping each site to its cluster labelmag_inequivalent— list of supercells for magnetically inequivalent sites that require an additional DFT calculation
prune_too_close_pos
Returns an index array marking positions that are within min_distance Å of a
lower-index position (and, optionally, within e_tol eV of its energy).
Marked positions should be discarded as duplicates.
aiida_muon.utils.magnetism
Utilities for handling collinear magnetism and computing local magnetic fields.
get_collinear_mag_kindname
Assigns spin-up/spin-down kind names to a pymatgen Structure based on the
supplied magnetic moment list. The kind names are used by aiida-quantumespresso
to set the starting magnetisation for pw.x.
make_collinear_getmag_kind
Convenience wrapper that calls get_collinear_mag_kindname and converts the
result to AiiDA StructureData format with the appropriate starting_magnetization
QE parameters.
compute_dipolar_field
Computes the classical dipolar field at each unique muon site using
muesr / muLFC. Called internally by FindMuonWorkChain.get_dipolar_field.
aiida_muon.utils.hubbard
check_get_hubbard_u_parms
Looks up Hubbard U values for the species present in structure. Uses a
built-in element heuristic unless u_dict is provided. Returns an empty dict
if the structure has fewer than two distinct species (the muon placeholder is
excluded from the count).
create_hubbard_structure
Maps Hubbard parameters from reference (either a HubbardStructureData or a
{species: U} dict) onto supercell_structure and returns a
HubbardStructureData.
aiida_muon.utils.export_findmuon
Post-processing helpers for use after a workflow finishes.
get_clustering_after_run
Returns a pandas.DataFrame summarising all relaxed sites: fractional position,
energy relative to the minimum, cluster label, and multiplicity.
get_distortions
get_distortions(unrelaxed_supercell, relaxed_supercell,
muon_atomic_number=1, only_final_muon_position=True, verbose=False)
Computes atomic displacements (distortions) induced by the muon relaxation. Useful for visualising the local lattice distortion around each candidate site.
Returns dict with:
distortion_norm— norm of displacement vector for each atom (Å)delta_distance— change in distance from the muon to each atom (Å)
aiida_muon.utils.score
Experimental
This module is part of the experimental machine-learning features.
ScoreCalculator
Computes per-frame disagreement scores between a DFT trajectory and an MLIP calculator. The composite score for frame i is:
Key methods
| Method | Description |
|---|---|
add_dft_trajectory(traj, shift=None) |
Load a DFT trajectory (ASE-readable) |
evaluate_on_dft_trajectory() |
Run the MLIP on all frames |
compute_scores() |
Compute composite scores |
find_frames(num_frames, similarity_thr) |
Select the most informative frames |
model_reliability() |
Return a reliability summary dict |
aiida_muon.utils.trajectory
atoms_list_to_trajectory_data
Converts a list of ASE Atoms objects to an AiiDA TrajectoryData node.
aiida_muon.utils.niche
Niche
Core NICHE class. Places an impurity atom on a grid over the unit cell,
filtering positions that are too close to existing atoms. Called internally by
niche_add_impurities.