Refine exchange plot labels and induced terminology
Browse filesFiles changed (12)
- app.py+6-6
- docs/IMX-09_UPPASD_CONVENTION_CLOSEOUT.md+2-2
- docs/PHYSICS_LIMITS.md+1-1
- docs/THEORY.md+2-2
- src/induced_exchange/__init__.py+2
- src/induced_exchange/downfolding.py+1-1
- src/induced_exchange/induced.py+11-7
- src/induced_exchange/magnons.py+5-5
- src/induced_exchange/space.py+20-7
- tests/test_induced.py+3-3
- tests/test_magnons.py+1-1
- tests/test_space.py+13
137 unmodified lines1381391401411411421431441451461471471481491501501511521531541551551561571585 unmodified lines16416516616716716816917027 unmodified lines198199200201201202203204137 unmodified lines load_status = gr.Markdown() parsed_summary = gr.Markdown() classification = gr.Dataframe(headers=["site", "atom_type", "moment (mu_B)", "role"], datatype=["number", "str", "number", "str"], type="array", row_count=1, label="Role preview (default: m < 0.5 μB is induced)", interactive=False) induced_site_toggle = gr.CheckboxGroup(choices=[], value=[], label="Induced/slave sites (toggle)", info="Select induced sites explicitly. By default, sites with reference moment m < 0.5 μB are selected; all other sites are robust.") induced_site_toggle = gr.CheckboxGroup(choices=[], value=[], label="Induced sites (toggle)", info="Select induced sites explicitly. By default, sites with reference moment m < 0.5 μB are selected; all other sites are robust.") with gr.Row(): mesh_size = gr.Slider(4, 16, value=8, step=1, label="Seekpath points per segment", info="The exchange, response, dressed-exchange, and magnon plots use this high-symmetry path. The same value controls the auxiliary 3-D mesh used only for J_eff(r).") analyze_button = gr.Button("Run analysis", variant="primary")
with gr.Tab("2 · Raw exchange"): gr.Markdown("### Raw rigid-site exchange\nAll supplied sites and literal UppASD jfile Jij rows are retained. The ordering diagnostic is the largest eigenvalue of J(q) under the UppASD ordered-pair convention `H = −Σᵢ≠ⱼ Jij eᵢ·eⱼ`. The scan is restricted to the seekpath high-symmetry path (or the explicitly labelled fallback path if seekpath cannot classify the structure); it is not a global 3-D ordering search.") gr.Markdown("### Raw rigid-site exchange\nAll supplied sites and literal UppASD jfile Jij rows are retained. The ordering diagnostic is the largest eigenvalue of J(q) under the UppASD ordered-pair convention `H = −Σᵢ≠ⱼ Jij eᵢ·eⱼ`. The scan is restricted to the seekpath high-symmetry path (or the explicitly labelled fallback path if seekpath cannot classify the structure); it is not a global 3-D ordering search. The distance plot separates `J_MM` (robust–robust, circles), `J_Mm` (robust–induced, squares), and `J_mm` (induced–induced, triangles).") raw_ordering = gr.Markdown("Load an input set and run analysis.") with gr.Row(): distance_plot = gr.Plot(label="Jij versus distance") distance_plot = gr.Plot(label="Raw Jij by subspace · distance") raw_plot = gr.Plot(label="J(q) eigenvalue scan · high-symmetry path") shell_table = gr.Dataframe(headers=["shell", "radius", "count", "mean Jij", "min Jij", "max Jij"], row_count=1, label="Radial exchange shells", interactive=False)
with gr.Tab("3 · Induced response"): gr.Markdown("### Induced/slave response\nClassify sites explicitly in the Input tab. The induced response is algebraic and instantaneous; induced sites are not independent LLG/LSWT degrees of freedom. The response panel uses a coherent unit-amplitude robust spin spiral along the same seekpath high-symmetry path.") gr.Markdown("### Induced response\nClassify sites explicitly in the Input tab. The induced response is algebraic and instantaneous; induced sites are not independent LLG/LSWT degrees of freedom. The response panel uses a coherent unit-amplitude robust spin spiral along the same seekpath high-symmetry path.") with gr.Row(): response_mode = gr.Radio([("J-weighted approximation", "j_weighted"), ("Historical unweighted", "historical")], value="j_weighted", label="Response model") x_override = gr.Textbox(label="X override", placeholder="blank = infer · e.g. 0.12 or 2:0.12, 3:0.08", info="J-weighted mode: X has inverse-energy units and p_ind = X K e, where p_ind = m_ind/|m_ind⁰|.")5 unmodified lines inference_table = gr.Dataframe(headers=["site", "m_ref (mu_B)", "source field (energy)", "X (1/energy)", "warnings"], row_count=1, label="X inference and source-field normalization", interactive=False)
with gr.Tab("4 · Dressed exchange"): gr.Markdown("### Robust-space exchange after induced-moment elimination\nThe induced contribution is a model-dependent correction using the selected response approximation. `J_eff(q)` is the Fourier-space matrix in the robust basis; the q-plot shows its leading eigenvalue. For one robust site (such as Fe with Pt treated as induced), this matrix is a scalar. The first real-space plot uses shell means to compare the direct `J_RR(r)`, cross-block `K_RI(r)`, Mryasov/downfolded `J_Mryasov(r)`, and Polesya/slave `J_Polesya(r)` channels. With the same static response model, the last two are numerically equivalent and are shown with separate labels. The induced correction `ΔJ_induced(r)` and its relative value `ΔJ_induced(r) / J_RR(r)` are plotted separately below. Real-space x-axes use the implicit UppASD lattice parameter convention (`alat = 1`), while all curves are reconstructed from a separate complete q mesh; moment normalization remains separate in the magnon calculation. The exported `dressed_jfile` is directly compatible with UppASD's ordered-pair convention.") gr.Markdown("### Robust-space exchange after induced-moment elimination\nThe induced contribution is a model-dependent correction using the selected response approximation. `J_eff(q)` is the Fourier-space matrix in the robust basis; the q-plot shows its leading eigenvalue. For one robust site (such as Fe with Pt treated as induced), this matrix is a scalar. The first real-space plot uses shell means to compare the direct `J_RR(r)`, cross-block `K_RI(r)`, Mryasov/downfolded `J_Mryasov(r)`, and Polesya-like induced `J_Polesya(r)` channels. With the same static response model, the last two are numerically equivalent and are shown with separate labels. The induced correction `ΔJ_induced(r)` and its relative value `ΔJ_induced(r) / J_RR(r)` are plotted separately below. Real-space x-axes use the implicit UppASD lattice parameter convention (`alat = 1`), while all curves are reconstructed from a separate complete q mesh; moment normalization remains separate in the magnon calculation. The exported `dressed_jfile` is directly compatible with UppASD's ordered-pair convention.") dressed_info = gr.Markdown() with gr.Row(): dressed_plot = gr.Plot(label="Robust-space J_eff(q) · high-symmetry path")27 unmodified lines
**Raw rigid-site model.** Every supplied magnetic site is treated as an ordinary rigid moment. This is diagnostic when some sites are physically induced.
**Polesya-like slave moments.** Induced moments are eliminated as algebraic variables. The historical mode uses an unweighted local neighbour sum; the selected J-weighted mode evaluates the labelled **J-weighted induced-response approximation**. **Polesya-like induced moments.** Induced moments are eliminated as algebraic variables. The historical mode uses an unweighted local neighbour sum; the selected J-weighted mode evaluates the labelled **J-weighted induced-response approximation**.
**Mryasov-like downfolding.** The induced subspace is eliminated variationally from one quadratic energy functional, yielding a robust-space `J_eff(q)`. No induced magnon branches are added.
216 unmodified lines217218219220220221222223224225225226227228216 unmodified lines
## 9. Polesya/Mryasov equivalence
The Polesya/slave response and Mryasov/downfolded result use the same `Xi` andThe Polesya-like induced response and Mryasov/downfolded result use the same `Xi` andthe same stationary `p*`. Induced sites are not added as independent LLG orLSWT degrees of freedom. Consequently the robust stationary energy and theadiabatic physical magnon spectrum are identical. The application retains thetwo labels to distinguish the representations, not to introduce separateslave branches.induced branches.
## 10. Export and provenance
3 unmodified lines4567789103 unmodified lines
The program can exactly manipulate the supplied effective spin model: it canFourier transform the supplied Cartesian `Jij`, solve the selected linearslave-response model, and perform the corresponding Schur-complementinduced-response model, and perform the corresponding Schur-complementdownfolding. It cannot determine the true electronic susceptibility from`Jij` alone.
60 unmodified lines616263646465666787 unmodified lines15515615715815815916016160 unmodified lines
## Induced moments
Sites are explicitly classified as **robust** or **induced/slave**. The UISites are explicitly classified as **robust** or **induced**. The UIinitially selects moments below 0.5 `mu_B` as induced, but this is only aneditable convenience; the chosen classification, not the threshold, definesthe calculation.87 unmodified linesrows therefore has `4*g*J/m [1-cos(qa)]`.Raw calculations retain all sites; robust-only calculations drop induced sites;dressed calculations first eliminate them. Induced sites never appear as extraindependent magnon branches in a slave-moment calculation.independent magnon branches in an induced-moment calculation.
Goldstone behaviour at Gamma, negative modes, and a non-Gamma orderingtendency are reported. A non-FM-compatible result is not presented as a41 unmodified lines42434445464748113 unmodified lines16216316416516616716841 unmodified lines SublatticeClassification, XInference, XInferenceResult, instantaneous_induced_moments, instantaneous_slave_moments,)from .downfolding import (113 unmodified lines "SublatticeClassification", "XInference", "XInferenceResult", "instantaneous_induced_moments", "instantaneous_slave_moments", "DressedExchangeRealSpace", "DownfoldingResult",287 unmodified lines288289290291291292293294287 unmodified lines The constructor accepts an :class:`InducedMomentResponse`, or a model plus explicit ``robust_sites`` and ``induced_sites``. In either form the same classification, kernel, X values, and approximation label are used by the explicit slave response and by the downfolded energy. explicit induced response and by the downfolded energy. """
def __init__(11234307 unmodified lines31231331431531531631731869 unmodified lines388389390391391392393394316 unmodified lines71171271371471471571671731 unmodified lines7497507517527527537547559 unmodified lines7657667677687687697707715 unmodified lines77777877978078078178278311 unmodified lines7957967977987998008018028033 unmodified lines807808809810811812"""Explicit Polesya-like induced/slave moment response models."""Explicit Polesya-like induced-moment response models.
This module implements the response layer only. It does not downfold theenergy or create dynamical degrees of freedom for induced sites. The307 unmodified lines
class InducedMomentResponse: """Evaluate historical or J-weighted instantaneous slave moments. """Evaluate historical or J-weighted instantaneous induced moments.
Parameters ----------69 unmodified lines
@property def response_label(self) -> str: return "J-weighted induced-response approximation" if self.mode == "j_weighted" else "historical local/unweighted slave response" return "J-weighted induced-response approximation" if self.mode == "j_weighted" else "historical local/unweighted induced response"
@property def local_neighbour_matrix(self) -> np.ndarray:316 unmodified lines *, coordinates: str = "fractional", ) -> InducedResponseResult: """Evaluate the instantaneous slave response for supplied q-space e(q). """Evaluate the instantaneous induced response for supplied q-space e(q).
``robust_configuration`` contains dimensionless robust orientation amplitudes and has shape ``(nq, nrobust)`` for scalar amplitudes, or31 unmodified lines return InducedResponseResult(response, fields, condition, singular, self.induced_sites, self.mode, tuple(warnings), q_fractional, q_cartesian, hermiticity, self._reference_induced_moments())
def response_real_space(self, robust_configuration: Mapping[int, Any] | Sequence[Any] | np.ndarray) -> InducedResponseResult: """Evaluate normalized slave polarization for a robust configuration. """Evaluate normalized induced polarization for a robust configuration.
The input is a dimensionless robust orientation configuration. This computes an algebraic response at one instant. It does not propagate9 unmodified lines return InducedResponseResult(result, source, condition, singular, self.induced_sites, self.mode, tuple(warnings), reference_induced_moments=self._reference_induced_moments())
def instantaneous_slave_moments(def instantaneous_induced_moments( model: MagneticCrystal, robust_configuration: Mapping[int, Any] | Sequence[Any] | np.ndarray, robust_sites: Sequence[int] | Mapping[Hashable, Sequence[int]],5 unmodified lines neighbourhood: str | Sequence[int] | Mapping[int, Sequence[int]] = "first_shell", cutoff: float | None = None,) -> np.ndarray: """Return only the instantaneous dimensionless slave polarization ``p``.""" """Return only the instantaneous dimensionless induced polarization ``p``."""
response = InducedMomentResponse( model,11 unmodified lines# A concise spelling is useful in notebooks and retains the physical name.InducedResponse = InducedMomentResponse
# Backward-compatible alias for callers of the original API spelling.instantaneous_slave_moments = instantaneous_induced_moments
__all__ = [ "InducedMomentResponse",3 unmodified lines "SublatticeClassification", "XInference", "XInferenceResult", "instantaneous_induced_moments", "instantaneous_slave_moments",]27 unmodified lines282930313132333422 unmodified lines57585960616061626364489 unmodified lines554555556557557558559560125 unmodified lines68668768868968969069169227 unmodified linesexpressed in mu_B. The eigenvalues of ``D`` are hbar*omega in theexchange-energy unit.
Induced sites never enter this dynamical basis. A Polesya/slave calculationInduced sites never enter this dynamical basis. A Polesya-like induced-variable calculationuses the dressed robust matrix after analytical elimination, so its physicallow-energy spectrum is directly comparable to the Mryasov/downfolded one."""22 unmodified lines "robust_raw": "robust-only raw", "mryasov": "Mryasov-like downfolded robust", "downfolded": "Mryasov-like downfolded robust", "polesya": "Polesya-like slave, induced variables eliminated", "slave": "Polesya-like slave, induced variables eliminated", "polesya": "Polesya-like induced variables eliminated", "slave": "Polesya-like induced variables eliminated",}
489 unmodified lines ``model='robust_only'`` retains only explicitly supplied robust sites. ``model='mryasov'`` and ``model='polesya'`` both use the robust dressed interaction after induced variables have been eliminated; the latter name records the slave-response representation, not extra slave branches. records the induced-response representation, not extra induced branches. """
selected_model = _normalise_model_name(model)125 unmodified lines
def polesya_fm_magnon_spectrum(source: InducedExchangeDownfolding | InducedMomentResponse | DownfoldingResult, q_points: Sequence[Sequence[float]] | np.ndarray | None = None, **kwargs: Any) -> FMSpinWaveResult: """Convenience wrapper for the physical Polesya-like slave spectrum.""" """Convenience wrapper for the physical Polesya-like induced spectrum."""
return fm_magnon_spectrum(source, q_points, model="polesya", **kwargs)
758 unmodified lines75976076176276376476276376476576676776876977077177277377477577677776777877978078178278378476 unmodified lines861862863851864865866867158 unmodified lines1026102710281016102910301031103247 unmodified lines10801081108210701083108410851086758 unmodified lines model = session.loaded.model distances = model.bond_distances values = np.asarray([bond.jij for bond in model.exchange_bonds], dtype=float) if len(distances): ax.scatter(distances, values, s=22, color="#18a999", alpha=0.78) else: robust = set(session.robust_sites) induced = set(session.induced_sites) categories = ( (r"$J_{MM}$", lambda bond: bond.i in robust and bond.j in robust, "o", "#18a999"), (r"$J_{Mm}$", lambda bond: (bond.i in robust and bond.j in induced) or (bond.i in induced and bond.j in robust), "s", "#183b56"), (r"$J_{mm}$", lambda bond: bond.i in induced and bond.j in induced, "^", "#e07a5f"), ) plotted = False for label, selector, marker, color in categories: selected = np.asarray([selector(bond) for bond in model.exchange_bonds], dtype=bool) if np.any(selected): ax.scatter(distances[selected], values[selected], s=34, color=color, marker=marker, alpha=0.8, label=label) plotted = True if not plotted: ax.text(0.5, 0.5, "No exchange rows", ha="center", va="center") ax.axhline(0.0, color="#8b98a6", linewidth=0.8, label="_nolegend_") ax.set(xlabel="authoritative bond distance", ylabel=f"Jij ({model.units.energy})", title="Raw exchange versus distance") ax.set(xlabel="authoritative bond distance", ylabel=f"Jij ({model.units.energy})", title="Raw exchange by subspace versus distance") ax.grid(alpha=0.18) if plotted: ax.legend(frameon=False) fig.tight_layout() plt.close(fig) return fig76 unmodified lines if cross is not None and cross.ndim == 3 and cross.shape[1:] == (1, 1): _plot_shell_series(ax, distances, selections, cross[:, 0, 0], "J_Mm(r) = K_Mm(r)", "#183b56") _plot_shell_series(ax, distances, selections, dressed[:, 0, 0], "J_Mryasov(r)", "#e07a5f") # The Polesya/slave and Mryasov/downfolded curves use the same static # The Polesya-like induced and Mryasov/downfolded curves use the same static # response operator in this package, so retain both labels while # making their numerical equivalence explicit. _plot_shell_series(ax, distances, selections, dressed[:, 0, 0], "J_Polesya(r) = J_Mryasov(r)", "#e07a5f", linestyle=":", marker=None)158 unmodified lines
fig, ax = plt.subplots(figsize=(8.4, 4.1)) colors = {"raw": "#183b56", "robust-only": "#18a999", "dressed": "#e07a5f", "polesya": "#8c5e8a"} labels = {"raw": "Raw all-rigid", "robust-only": "Robust-only raw", "dressed": "Mryasov-like downfolded", "polesya": "Polesya-like slave"} labels = {"raw": "Raw all-rigid", "robust-only": "Robust-only raw", "dressed": "Mryasov-like downfolded", "polesya": "Polesya-like induced variables eliminated"} x, tick_positions, tick_labels, source = _path_axis(session, len(next(iter(session.magnons.values())).energies) if session.magnons else 0) linestyles = {"raw": "-", "robust-only": "--", "dressed": "-", "polesya": ":"} for name, spectrum in session.magnons.items():47 unmodified lines return "No FM spectrum could be constructed for the current input." path_source = "unknown" if session.path is None else session.path.path.source lines = [f"The spectrum is evaluated only along the high-symmetry q path (`{path_source}`); the horizontal axis is Cartesian reciprocal-space path distance."] labels = {"raw": "Raw all-rigid", "robust-only": "Robust-only raw", "dressed": "Mryasov-like downfolded", "polesya": "Polesya-like slave"} labels = {"raw": "Raw all-rigid", "robust-only": "Robust-only raw", "dressed": "Mryasov-like downfolded", "polesya": "Polesya-like induced variables eliminated"} for name, spectrum in session.magnons.items(): status = "stable/FM-compatible" if spectrum.stable and spectrum.fm_compatible else "UNSTABLE — signed harmonic data only" lines.append(f"**{labels.get(name, name)}:** `{status}` · branches = `{spectrum.energies.shape[1]}` · negative modes = `{len(spectrum.unstable_indices)}`")7 unmodified lines891011111213148 unmodified lines2324252626272829122 unmodified lines1521531541551551561571587 unmodified lines MagneticCrystal, MagneticSite, SublatticeClassification, instantaneous_slave_moments, instantaneous_induced_moments, reciprocal_lattice,)from induced_exchange.downfolding import InducedExchangeDownfolding, inverse_fourier_dressed_jij8 unmodified lines return MagneticCrystal(np.eye(3), list(sites), list(bonds))
def test_one_robust_one_induced_infers_x_and_evaluates_slave_moment():def test_one_robust_one_induced_infers_x_and_evaluates_induced_moment(): model = crystal([site(1, 3.0), site(2, 1.5)], [ExchangeBond(2, 1, (0, 0, 0), 2.0)]) response = InducedMomentResponse(model, [1], [2], mode="j_weighted")
122 unmodified lines
def test_convenience_wrapper_is_algebraic_and_does_not_propagate(): model = crystal([site(1, 1.0), site(2, 2.0)], [ExchangeBond(2, 1, (0, 0, 0), 3.0)]) values = instantaneous_slave_moments(model, [2.0], [1], [2], x={2: 0.5}) values = instantaneous_induced_moments(model, [2.0], [1], [2], x={2: 0.5}) assert np.allclose(values, [3.0])
144 unmodified lines145146147148148149150151144 unmodified lines assert stiffness.q_max == 0.25
def test_polesya_and_mryasov_physical_spectra_are_identical_without_slave_branches():def test_polesya_and_mryasov_physical_spectra_are_identical_without_induced_branches(): model = crystal( [site(1, 1.0), site(2, 1.0)], [137 unmodified lines138139140141142143144145146147148149150151152153154155156137 unmodified lines assert "coherent unit-amplitude" in response_markdown(session)
def test_raw_exchange_plot_separates_robust_cross_and_induced_markers(): pytest.importorskip("matplotlib.pyplot") loaded = load_uppasd("examples/induced_toy/inpsd.dat", energy_unit="meV") session = analyse_model(loaded, SublatticeClassification.from_inputs([1], [2]), mesh_size=2, x=0.5)
figure = _figure_realspace(session) labels = {r"$J_{MM}$", r"$J_{Mm}$", r"$J_{mm}$"} labelled = [collection for collection in figure.axes[0].collections if collection.get_label() in labels] assert {collection.get_label() for collection in labelled} == labels marker_shapes = {tuple(np.round(collection.get_paths()[0].vertices.ravel(), 8)) for collection in labelled} assert len(marker_shapes) == 3
def test_dressed_realspace_plots_separate_induced_correction_and_label_channels(): pytest.importorskip("matplotlib.pyplot") loaded = load_uppasd("examples/induced_toy/inpsd.dat", energy_unit="meV")app.py+6-6
docs/IMX-09_UPPASD_CONVENTION_CLOSEOUT.md+2-2
docs/PHYSICS_LIMITS.md+1-1
docs/THEORY.md+2-2
src/induced_exchange/__init__.py+2
src/induced_exchange/downfolding.py+1-1
src/induced_exchange/induced.py+11-7
src/induced_exchange/magnons.py+5-5
src/induced_exchange/space.py+20-7
tests/test_induced.py+3-3
tests/test_magnons.py+1-1
tests/test_space.py+13