Skip to content

Commit

Permalink
Replace spin_irrep_label -> spin_label
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Oct 21, 2023
1 parent 25076f1 commit d7a43f7
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/src/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Deprecate `spin_operators`, `stevens_operators`, `large_S_spin_operators` and
`large_S_stevens_operators`. Use instead [`spin_matrices`](@ref) and
[`stevens_matrices`](@ref), which require a specific spin-``S`` label. To
infer this, one can use [`spin_irrep_label`](@ref).
infer this, one can use [`spin_label`](@ref).
* To perform a calculation with dipoles in the large-$S$ limit, use the new mode
`:dipole_large_S` when constructing a [`System`](@ref).

Expand Down
2 changes: 1 addition & 1 deletion ext/PlottingExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ function plot_coherents(sys::System{N};scale = 1., quantization_axis = nothing,
else
quantization_axis
end
S = spin_matrices(spin_irrep_label(sys,site[4]))
S = spin_matrices(spin_label(sys,site[4]))
spin_operator = S[1] .* v[1] .+ S[2] .* v[2] .+ S[3] .* v[3]
basis_rotation = eigvecs(spin_operator;sortby = λ -> -real(λ))
dir[i] = Makie.Point3f(v...)
Expand Down
2 changes: 1 addition & 1 deletion src/Sunny.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ include("System/OnsiteCoupling.jl")
include("System/Ewald.jl")
include("System/Interactions.jl")
export SpinInfo, System, Site, eachsite, position_to_site, global_position, magnetic_moment,
set_coherent!, set_dipole!, polarize_spins!, randomize_spins!, energy, energy_per_site, spin_irrep_label,
set_coherent!, set_dipole!, polarize_spins!, randomize_spins!, energy, energy_per_site, spin_label,
set_onsite_coupling!, set_pair_coupling!, set_exchange!, dmvec, enable_dipole_dipole!, set_external_field!,
to_inhomogeneous, set_external_field_at!, set_vacancy_at!, set_onsite_coupling_at!, set_exchange_at!,
set_pair_coupling_at!, symmetry_equivalent_bonds, remove_periodicity!
Expand Down
8 changes: 4 additions & 4 deletions src/System/OnsiteCoupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function onsite_coupling(sys, site, matrep::AbstractMatrix)
if sys.mode == :SUN
return Hermitian(matrep)
elseif sys.mode == :dipole
S = spin_irrep_label(sys, to_atom(site))
S = spin_label(sys, to_atom(site))
λ = anisotropy_renormalization(S)
c = matrix_to_stevens_coefficients(hermitianpart(matrep))
return StevensExpansion.* c)
Expand Down Expand Up @@ -107,7 +107,7 @@ set_onsite_coupling!(sys, S -> -D*S[3]^3, i)
set_onsite_coupling!(sys, S -> 20*(S[1]^4 + S[2]^4 + S[3]^4), i)
# An equivalent expression of this quartic anisotropy, up to a constant shift
O = stevens_matrices(spin_irrep_label(sys, i))
O = stevens_matrices(spin_label(sys, i))
set_onsite_coupling!(sys, O[4,0] + 5*O[4,4], i)
```
"""
Expand Down Expand Up @@ -157,7 +157,7 @@ function set_onsite_coupling!(sys::System, op, i::Int)
end

function set_onsite_coupling!(sys::System, fn::Function, i::Int)
S = spin_matrices(spin_irrep_label(sys, i))
S = spin_matrices(spin_label(sys, i))
set_onsite_coupling!(sys, fn(S), i)
end

Expand All @@ -179,7 +179,7 @@ function set_onsite_coupling_at!(sys::System, op, site::Site)
end

function set_onsite_coupling_at!(sys::System, fn::Function, site::Site)
S = spin_matrices(spin_irrep_label(sys, to_atom(site)))
S = spin_matrices(spin_label(sys, to_atom(site)))
set_onsite_coupling_at!(sys, fn(S), site)
end

Expand Down
24 changes: 12 additions & 12 deletions src/System/PairExchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ function set_pair_coupling_aux!(sys::System, scalar::Float64, bilin::Union{Float

# Renormalize biquadratic interactions
if sys.mode == :dipole
S1 = spin_irrep_label(sys, bond.i)
S2 = spin_irrep_label(sys, bond.j)
S1 = spin_label(sys, bond.i)
S2 = spin_label(sys, bond.j)
biquad *= (1 - 1/2S1) * (1 - 1/2S2)
end

Expand Down Expand Up @@ -236,8 +236,8 @@ function set_pair_coupling!(sys::System{N}, op::AbstractMatrix, bond; extract_pa
error("Symbolic operators required for mode `:dipole_large_S`.")
end

N1 = Int(2spin_irrep_label(sys, bond.i)+1)
N2 = Int(2spin_irrep_label(sys, bond.j)+1)
N1 = Int(2spin_label(sys, bond.i)+1)
N2 = Int(2spin_label(sys, bond.j)+1)
scalar, bilin, biquad, tensordec = decompose_general_coupling(op, N1, N2; extract_parts)

set_pair_coupling_aux!(sys, scalar, bilin, biquad, tensordec, bond)
Expand All @@ -249,8 +249,8 @@ function set_pair_coupling!(sys::System{N}, fn::Function, bond; extract_parts=tr
error("General couplings not yet supported for mode `:dipole_large_S`.")
end

S1 = spin_irrep_label(sys, bond.i)
S2 = spin_irrep_label(sys, bond.j)
S1 = spin_label(sys, bond.i)
S2 = spin_label(sys, bond.j)
Si, Sj = to_product_space(spin_matrices.([S1, S2])...)
set_pair_coupling!(sys, fn(Si, Sj), bond; extract_parts)
return
Expand Down Expand Up @@ -358,8 +358,8 @@ function set_pair_coupling_at_aux!(sys::System, scalar::Float64, bilin::Union{Fl

# Renormalize biquadratic interactions
if sys.mode == :dipole
S1 = spin_irrep_label(sys, to_atom(site1))
S2 = spin_irrep_label(sys, to_atom(site2))
S1 = spin_label(sys, to_atom(site1))
S2 = spin_label(sys, to_atom(site2))
biquad *= (1 - 1/2S1) * (1 - 1/2S2)
end

Expand Down Expand Up @@ -422,8 +422,8 @@ function set_pair_coupling_at!(sys::System{N}, op::AbstractMatrix, site1::Site,
error("Symbolic operators required for mode `:dipole_large_S`.")
end

N1 = Int(2spin_irrep_label(sys, to_atom(site1))+1)
N2 = Int(2spin_irrep_label(sys, to_atom(site2))+1)
N1 = Int(2spin_label(sys, to_atom(site1))+1)
N2 = Int(2spin_label(sys, to_atom(site2))+1)
scalar, bilin, biquad, tensordec = decompose_general_coupling(op, N1, N2; extract_parts=true)

set_pair_coupling_at_aux!(sys, scalar, bilin, biquad, tensordec, site1, site2, offset)
Expand All @@ -435,8 +435,8 @@ function set_pair_coupling_at!(sys::System{N}, fn::Function, site1::Site, site2:
error("General couplings not yet supported for mode `:dipole_large_S`.")
end

S1 = spin_irrep_label(sys, to_atom(site1))
S2 = spin_irrep_label(sys, to_atom(site2))
S1 = spin_label(sys, to_atom(site1))
S2 = spin_label(sys, to_atom(site2))
Si, Sj = to_product_space(spin_matrices.([S1, S2])...)
set_pair_coupling_at!(sys, fn(Si, Sj), site1, site2; offset)
return
Expand Down
8 changes: 4 additions & 4 deletions src/System/System.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ const Site = Union{NTuple{4, Int}, CartesianIndex{4}}
@inline eachcell(sys::System) = CartesianIndices(sys.latsize)

"""
spin_irrep_label(sys::System, i::Int)
spin_label(sys::System, i::Int)
If atom `i` or site `site` carries a single spin-``S`` moment, then returns
``S``. Otherwise, throws an error.
If atom `i` carries a single spin-``S`` moment, then returns the half-integer
label ``S``. Otherwise, throws an error.
"""
function spin_irrep_label(sys::System, i::Int)
function spin_label(sys::System, i::Int)
if sys.mode == :dipole_large_S
return Inf
else
Expand Down
8 changes: 4 additions & 4 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Base.@deprecate_binding large_S_spin_operators spin_matrices(Inf)
Base.@deprecate_binding large_S_stevens_operators stevens_matrices(Inf)

Base.@deprecate spin_operators(sys::System, i::Int) let
@warn "`spin_operators` will soon be removed! Use `spin_matrices(spin)` instead where `spin = spin_irrep_label(sys, i)`."
spin_matrices(spin_irrep_label(sys, i))
@warn "`spin_operators` will soon be removed! Use `spin_matrices(spin)` instead where `spin = spin_label(sys, i)`."
spin_matrices(spin_label(sys, i))
end
Base.@deprecate stevens_operators(sys::System, i::Int) let
@warn "`stevens_operators` will soon be removed! Use `stevens_matrices(spin)` instead where `spin = spin_irrep_label(sys, i)`."
stevens_matrices(spin_irrep_label(sys, i))
@warn "`stevens_operators` will soon be removed! Use `stevens_matrices(spin)` instead where `spin = spin_label(sys, i)`."
stevens_matrices(spin_label(sys, i))
end

Base.@deprecate suggest_magnetic_supercell(qs, latsize) suggest_magnetic_supercell(qs)
Expand Down
6 changes: 3 additions & 3 deletions test/shared.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function add_quadratic_interactions!(sys, mode)

#=
# This is a bit slower, but must also work
S = spin_irrep_label(sys, 1)
S = spin_label(sys, 1)
O = stevens_matrices(S)
Q = [O[2,q] for q in 2:-1:-2]
Qi, Qj = to_product_space(Q, Q)
Expand All @@ -54,11 +54,11 @@ function add_quartic_interactions!(sys, mode)
if mode in (:dipole, :dipole_large_S)
# Stevens operators O[4,q] are quartic in dipoles
i = 3
O = stevens_matrices(spin_irrep_label(sys, i))
O = stevens_matrices(spin_label(sys, i))
set_onsite_coupling!(sys, 0.2*((1/20)O[4,0] + (1/4)O[4,4]), i)

# Bilinear interactions in quadrupoles also have quartic scaling.
O = stevens_matrices(spin_irrep_label(sys, 1))
O = stevens_matrices(spin_label(sys, 1))
Q = [O[2,q] for q in 2:-1:-2]
Qi, Qj = to_product_space(Q, Q)
biquad = [1.2 0 0 0 0
Expand Down
2 changes: 1 addition & 1 deletion test/test_lswt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
A,B,C,D = 2.6, -1.3, 0.2, -5.7
set_exchange!(sys, [A D D; D B C; D C B], Bond(4, 4, [1, 1, 0]))#; biquad = 0.3)

O = stevens_matrices(spin_irrep_label(sys, 3))
O = stevens_matrices(spin_label(sys, 3))
c1, c2, c3 = 2.6, -1.3, 0.2, -5.7
Λ = c1 * (O[2,-2] - 2O[2,-1] - 2O[2,1]) +
c2 * (-7O[4,-3] + 2O[4,-2] + O[4,-1] + O[4,1] + 7O[4,3]) +
Expand Down
2 changes: 1 addition & 1 deletion test/test_rescaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
c = randn(2k+1)
E1, E2 = map([:dipole, :dipole_large_S]) do mode
sys = System(cryst, (1,1,1), [SpinInfo(1; S, g=2)], mode)
O = stevens_matrices(spin_irrep_label(sys, 1))
O = stevens_matrices(spin_label(sys, 1))
set_onsite_coupling!(sys, sum(c[k-q+1]*O[k, q] for q in -k:k), 1)
return energy(sys)
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
sys = System(cryst, (L,1,1), [SpinInfo(1, S=2, g=2)], :SUN; seed)
randomize_spins!(sys)

S = spin_matrices(spin_irrep_label(sys, 1))
S = spin_matrices(spin_label(sys, 1))
R = Sunny.random_orthogonal(sys.rng, 3; special=true)
Λ = Sunny.rotate_operator(D*(S[3]^2-(1/5)*S[3]^4), R)
set_onsite_coupling!(sys, Λ, 1)
Expand Down
4 changes: 2 additions & 2 deletions test/test_symmetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ end

# Most general allowed anisotropy for this crystal
c = randn(9)
O = stevens_matrices(spin_irrep_label(sys, 1))
O = stevens_matrices(spin_label(sys, 1))
Λ = sum(c .* [O[2,0], O[2,2], O[4,0], O[4,2], O[4,4], O[6,0], O[6,2], O[6,4], O[6,6]])
set_onsite_coupling!(sys, Λ, 1)

Expand Down Expand Up @@ -329,7 +329,7 @@ end
randomize_spins!(sys0)

i = 1
O = stevens_matrices(spin_irrep_label(sys0, i))
O = stevens_matrices(spin_label(sys0, i))
Λ = randn()*(O[2,0]+3O[2,2]) +
randn()*(O[4,0]-5O[4,2]) + randn()*(O[4,0]+5O[4,4]) +
randn()*(O[6,0]-21O[6,4]) + randn()*(O[6,0]+(105/16)O[6,2]+(231/16)O[6,6])
Expand Down

0 comments on commit d7a43f7

Please sign in to comment.