Created
March 2, 2026 19:55
-
-
Save mducle/d5eb536bc7f1b2128abacdd1e18cc17a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing.spawn import freeze_support | |
| from pyspinw.anisotropy import AxisMagnitudeAnisotropy | |
| from pyspinw.coupling import HeisenbergCoupling | |
| from pyspinw.hamiltonian import Hamiltonian | |
| #from pyspinw.interface import couplings, axis_anisotropies, filter | |
| from pyspinw.interface import * | |
| from pyspinw.legacy.genmagstr import genmagstr | |
| from pyspinw.path import Path, Path1D | |
| from pyspinw.sample import Powder | |
| from pyspinw.site import LatticeSite | |
| from pyspinw.symmetry.supercell import TrivialSupercell, SummationSupercell, CommensuratePropagationVector | |
| from pyspinw.symmetry.unitcell import UnitCell | |
| from pyspinw.structures import Structure | |
| import sys | |
| from pyspinw.debug_plot import debug_plot | |
| if __name__ == "__main__": | |
| """Reproduces Tutorial 2: https://spinw.org/tutorials/02tutorial""" | |
| freeze_support() | |
| use_rust = "py" not in sys.argv[1] if len(sys.argv) > 1 else True | |
| # AFM chain | |
| unit_cell = UnitCell(3, 8, 8) | |
| s = generate_helical_structure(unit_cell, positions=[[0,0,0]], moments=[[0,1,0]], | |
| perpendicular=[0,0,1], propagation_vector=[0.5, 0, 0], names=["MCu1"]) | |
| exchanges = couplings(sites=s, | |
| max_distance=3.1, | |
| coupling_type=HeisenbergCoupling, | |
| j=1) | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| hamiltonian.print_summary() | |
| path = Path([[0,0,0], [1,0,0]]) | |
| fig = hamiltonian.spaghetti_plot(path, scale='log', use_rust=use_rust, show=False) | |
| fig.axes[0].set_ylim(bottom=0) | |
| #fig.savefig('py01.pdf') | |
| # Antiferromagnetic chain example with applied magnetic field | |
| unit_cell = UnitCell(4,6,6) | |
| s = generate_structure(unit_cell, positions=[[0,0,0], [0.5,0,0]], moments=[[0,0,1], [0,0,-1]], names=['X', 'Y']) | |
| exchanges = couplings(sites=s, | |
| bond=1, | |
| coupling_type=HeisenbergCoupling, | |
| j=1) | |
| anisotropies = axis_anisotropies(s.sites, -0.1) | |
| hamiltonian = Hamiltonian(s, exchanges, anisotropies) | |
| hamiltonian.print_summary() | |
| path = Path([[0,0,0], [2,0,0]]) | |
| fig = hamiltonian.spaghetti_plot(path, field=[0,0,7], use_rust=use_rust, show=False) | |
| fig.axes[0].set_ylim(bottom=0) | |
| #fig.savefig('py02.pdf') | |
| # Ferromagnetic chain example | |
| unit_cell = UnitCell(1,1,1) | |
| only_site = LatticeSite(0, 0, 0, 0,0,1, name="X") | |
| s = Structure([only_site], unit_cell=unit_cell) | |
| exchanges = couplings(sites=[only_site], | |
| unit_cell=unit_cell, | |
| max_distance=1.1, | |
| coupling_type=HeisenbergCoupling, | |
| j=-1, | |
| direction_filter=filter([1,0,0], symmetric=True)) | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| path = Path([[0,0,0], [1,0,0]]) | |
| fig = hamiltonian.spaghetti_plot(path, use_rust=use_rust, show=False) | |
| fig.axes[0].set_ylim(bottom=0) | |
| #fig.savefig('py03.pdf') | |
| # Kagome Antiferromagnet example | |
| unit_cell = UnitCell(6, 6, 10, gamma=120) | |
| s = generate_structure(unit_cell, positions=[[0.5,0,0], [0,0.5,0], [0.5,0.5,0]], moments=[[1,2,0], [-2,-1,0], [1,-1,0]], | |
| names=['X','Y','Z'], magnitudes=[1,1,1], moments_unit='lu') | |
| j1 = couplings(sites=s, bond=1, coupling_type=HeisenbergCoupling, j=1) | |
| j2 = couplings(sites=s, bond=2, coupling_type=HeisenbergCoupling, j=0.11) | |
| exchanges = j1 + j2 | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| hamiltonian.print_summary() | |
| path = Path([[-0.5,0,0], [0,0,0], [0.5,0.5,0]]) | |
| fig = hamiltonian.spaghetti_plot(path, use_rust=use_rust, show=False) | |
| fig.axes[0].set_ylim(bottom=0) | |
| #fig.savefig('py04.pdf') | |
| # Kagome Ferromagnet example | |
| unit_cell = UnitCell(6,6,5, gamma=120) | |
| x = LatticeSite(0.5, 0, 0, 0, 1, 0, name="X") | |
| y = LatticeSite(0, 0.5, 0, 0, 1, 0, name="Y") | |
| z = LatticeSite(0.5, 0.5, 0, 0, 1, 0, name="Z") | |
| sites = [x, y, z] | |
| s = Structure(sites, unit_cell=unit_cell, supercell=TrivialSupercell(scaling=(1,1,1))) | |
| exchanges = couplings(sites=[x, y, z], | |
| unit_cell=unit_cell, | |
| bond=1, | |
| coupling_type=HeisenbergCoupling, | |
| j=-1) | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| hamiltonian.print_summary() | |
| path = Path([[-0.5,0,0], [0,0,0], [0.5,0.5,0]]) | |
| fig = hamiltonian.spaghetti_plot(path, show=False, use_rust=use_rust) | |
| fig.axes[0].set_ylim(bottom=0) | |
| #fig.savefig('py05.pdf') | |
| # Kagome 3x3 Antiferromagnet example | |
| unit_cell = UnitCell(6, 6, 40, gamma=120) | |
| s = generate_helical_structure(unit_cell, positions=[[0.5,0,0], [0,0.5,0], [0.5,0.5,0]], | |
| moments=[[0,1,0], [0,1,0], [-1,-1,0]], magnitudes=[1,1,1], names=['X', 'Y', 'Z'], | |
| moments_unit='lu', perpendicular=[0,0,1], propagation_vector=[-1./3., -1./3., 0]) | |
| exchanges = couplings(sites=s, | |
| bond=1, | |
| coupling_type=HeisenbergCoupling, | |
| j=1) | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| hamiltonian.print_summary() | |
| path = Path([[-0.5,0,0], [0,0,0], [0.5,0.5,0]]) | |
| import matplotlib.pyplot as plt | |
| fig = hamiltonian.spaghetti_plot(path, show=False, use_rust=use_rust) | |
| fig.axes[0].set_ylim(bottom=0) | |
| fig.axes[1].set_ylim(0, 1) | |
| #fig.savefig('py06.pdf') | |
| # Triangular Antiferromagnet example | |
| unit_cell = UnitCell(3, 3, 4, gamma=120) | |
| s = generate_helical_structure(unit_cell, positions=[[0,0,0]], moments=[[0,1,0]], magnitudes=[3./2], names=['X'], | |
| perpendicular=[0,0,1], propagation_vector=[1./3., 1./3., 0]) | |
| exchanges = couplings(sites=s, | |
| bond=1, | |
| coupling_type=HeisenbergCoupling, | |
| j=1) | |
| anisotropies = axis_anisotropies(s.sites, 0.2) | |
| hamiltonian = Hamiltonian(s, exchanges, anisotropies) | |
| hamiltonian.print_summary() | |
| path = Path([[0,0,0], [1,1,0]], n_points_per_segment=401) | |
| import matplotlib.pyplot as plt | |
| fig = hamiltonian.spaghetti_plot(path, show=False, use_rust=use_rust) | |
| fig.axes[0].set_ylim(bottom=0) | |
| fig.axes[1].set_ylim(0, 5) | |
| #fig.savefig('py07.pdf') | |
| # Square Antiferromagnet example | |
| unit_cell = UnitCell(3, 3, 9) | |
| sites = [LatticeSite(0, 0, 0, 1, 0, 0, name="X")] | |
| k = CommensuratePropagationVector(0.5, 0.5, 0) | |
| s = Structure(sites, unit_cell, supercell=SummationSupercell(propagation_vectors=[k])) | |
| j1 = couplings(sites, unit_cell, min_distance=0, max_distance=3.1, coupling_type=HeisenbergCoupling, j=59.65) | |
| j2 = couplings(sites, unit_cell, min_distance=4, max_distance=4.3, coupling_type=HeisenbergCoupling, j=-3.75) | |
| j3 = couplings(sites, unit_cell, min_distance=5, max_distance=6.1, coupling_type=HeisenbergCoupling, j=1) | |
| exchanges = j1 + j2 + j3 | |
| hamiltonian = Hamiltonian(s, exchanges) | |
| hamiltonian.print_summary() | |
| path = Path([[3/4, 1/4, 0], [1/2, 1/2, 0], [1/2, 0, 0], [3/4, 1/4, 0], [1, 0, 0], [1/2, 0, 0]], n_points_per_segment=51) | |
| import matplotlib.pyplot as plt | |
| fig = hamiltonian.spaghetti_plot(path, show=False, use_rust=use_rust) | |
| fig.axes[0].set_ylim(0, 600) | |
| fig.axes[1].set_ylim(0, 20) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment