Skip to content

Commit

Permalink
Allow set_onsite_coupling! with zero
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Jul 30, 2023
1 parent 1888468 commit bd8ae6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/System/OnsiteCoupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ See also [`spin_operators`](@ref).
"""
function set_onsite_coupling!(sys::System{N}, op::Matrix{ComplexF64}, i::Int) where N
is_homogeneous(sys) || error("Use `set_onsite_coupling_at!` for an inhomogeneous system.")
ints = interactions_homog(sys)

# If `sys` has been reshaped, then operate first on `sys.origin`, which
# contains full symmetry information.
Expand All @@ -139,18 +140,14 @@ function set_onsite_coupling!(sys::System{N}, op::Matrix{ComplexF64}, i::Int) wh
return
end

ints = interactions_homog(sys)

iszero(op) && return
(1 <= i <= natoms(sys.crystal)) || error("Atom index $i is out of range.")

if !is_anisotropy_valid(sys.crystal, i, op)
@error """Symmetry-violating anisotropy: $op.
Use `print_site(crystal, $i)` for more information."""
error("Invalid anisotropy.")
end

(1 <= i <= natoms(sys.crystal)) || error("Atom index $i is out of range.")

if !iszero(ints[i].onsite)
warn_coupling_override("Overriding anisotropy for atom $i.")
end
Expand Down
15 changes: 11 additions & 4 deletions src/System/PairExchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ end

# Internal function only
function push_coupling!(couplings, bond, bilin, biquad)
isculled = bond_parity(bond)
# Remove previous coupling on this bond
filter!(c -> c.bond != bond, couplings)

# If the new coupling is exactly zero, return early
iszero(bilin) && iszero(biquad) && return

# Otherwise, add the new coupling to the list
isculled = bond_parity(bond)
push!(couplings, PairCoupling(isculled, bond, bilin, biquad))
sort!(couplings, by=c->c.isculled)

return
end

Expand Down Expand Up @@ -75,6 +82,9 @@ set_exchange!(sys, J2, bond)
```
"""
function set_exchange!(sys::System{N}, J, bond::Bond; biquad=0.) where N
is_homogeneous(sys) || error("Use `set_exchange_at!` for an inhomogeneous system.")
ints = interactions_homog(sys)

# If `sys` has been reshaped, then operate first on `sys.origin`, which
# contains full symmetry information.
if !isnothing(sys.origin)
Expand All @@ -85,9 +95,6 @@ function set_exchange!(sys::System{N}, J, bond::Bond; biquad=0.) where N

validate_bond(sys.crystal, bond)

is_homogeneous(sys) || error("Use `set_exchange_at!` for an inhomogeneous system.")
ints = interactions_homog(sys)

J = to_float_or_mat3(J)

# Verify that exchange is symmetry-consistent
Expand Down

0 comments on commit bd8ae6e

Please sign in to comment.