Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track spacegroup setting #325

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/src/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
polynomial order according to an error tolerance.
* Rename mode `:dipole_large_S` to `:dipole_uncorrected` to emphasize that
corrections are missing.
* [`Crystal`](@ref) constructor suggests disambiguation via the possible HM
symbols.
* Rename `primitive_cell_shape` to [`primitive_cell`](@ref).

## v0.7.2
(Sep 11, 2024)
Expand Down
23 changes: 11 additions & 12 deletions examples/01_LSWT_CoRh2O4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ a = 8.5031 # (Å)
latvecs = lattice_vectors(a, a, a, 90, 90, 90)

# Construct the [`Crystal`](@ref) cell from the spacegroup number 227 and one
# representative atom of each occupied Wyckoff. In the standard setting of
# spacegroup 227, position `[0, 0, 0]` belongs to Wyckoff 8a, which is the
# diamond cubic crystal.
# representative atom of each occupied Wyckoff. Two choices of origin are
# possible. With choice 1, position `[0, 0, 0]` belongs to Wyckoff 8a, which is
# the diamond cubic lattice.

positions = [[0, 0, 0]]
cryst = Crystal(latvecs, positions, 227; types=["Co"], setting="1")
cryst = Crystal(latvecs, positions, 227; types=["Co"], choice=1)

# [`view_crystal`](@ref) launches an interface for interactive inspection and
# symmetry analysis.
Expand Down Expand Up @@ -104,16 +104,15 @@ plot_spins(sys; color=[S[3] for S in sys.dipoles])

# ### Reshaping the magnetic cell

# The most compact magnetic cell for this Néel order is a primitive unit cell.
# Reduce the magnetic cell size using [`reshape_supercell`](@ref), where columns
# of the `shape` matrix are primitive lattice vectors as multiples of the
# conventional cubic lattice vectors ``(𝐚_1, 𝐚_2, 𝐚_3)``. One could
# alternatively use `shape = cryst.latvecs \ cryst.prim_latvecs`. Verify that
# The most compact magnetic cell for this Néel order is the primitive unit cell.
# Columns of the [`primitive_cell`](@ref) matrix provide the primitive lattice
# vectors as multiples of the conventional cubic lattice vectors.

shape = primitive_cell(cryst)

# Reduce the magnetic cell size using [`reshape_supercell`](@ref). Verify that
# the energy per site is unchanged after the reshaping the supercell.

shape = [0 1 1;
1 0 1;
1 1 0] / 2
sys_prim = reshape_supercell(sys, shape)
@assert energy_per_site(sys_prim) ≈ -2J*(3/2)^2

Expand Down
2 changes: 1 addition & 1 deletion examples/02_LLD_CoRh2O4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using Sunny, GLMakie
units = Units(:meV, :angstrom)
a = 8.5031 # (Å)
latvecs = lattice_vectors(a, a, a, 90, 90, 90)
cryst = Crystal(latvecs, [[0,0,0]], 227, setting="1")
cryst = Crystal(latvecs, [[0, 0, 0]], 227; choice=1)

sys = System(cryst, [1 => Moment(s=3/2, g=2)], :dipole)
J = 0.63 # (meV)
Expand Down
9 changes: 4 additions & 5 deletions examples/07_Dipole_Dipole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@

using Sunny, GLMakie

# Create a pyrochlore crystal from spacegroup 227.
# Create a pyrochlore crystal from spacegroup 227, origin choice 2.

units = Units(:K, :angstrom)
latvecs = lattice_vectors(10.19, 10.19, 10.19, 90, 90, 90)
positions = [[1/8, 1/8, 1/8]]
cryst = Crystal(latvecs, positions, 227, setting="1")
positions = [[0, 0, 0]]
cryst = Crystal(latvecs, positions, 227; choice=2)
view_crystal(cryst)

# Create a system and reshape to the primitive cell, which contains four atoms.
# Add antiferromagnetic nearest neighbor exchange interactions.

primitive_cell = [1/2 1/2 0; 0 1/2 1/2; 1/2 0 1/2]
sys = System(cryst, [1 => Moment(s=7/2, g=2)], :dipole; seed=0)
sys = reshape_supercell(sys, primitive_cell)
sys = reshape_supercell(sys, primitive_cell(cryst))
J1 = 0.304 # (K)
set_exchange!(sys, J1, Bond(1, 2, [0,0,0]))

Expand Down
4 changes: 2 additions & 2 deletions examples/spinw_tutorials/SW13_LiNiPO4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Sunny, GLMakie

# Build an orthorhombic lattice and populate the Ni atoms according to
# spacegroup 62 (Pnma).
# spacegroup 62 (Pnma setting).

units = Units(:meV, :angstrom)
a = 10.02
Expand All @@ -18,7 +18,7 @@ c = 4.68
latvecs = lattice_vectors(a, b, c, 90, 90, 90)
positions = [[1/4, 1/4, 0]]
types = ["Ni"]
cryst = Crystal(latvecs, positions, 62, setting=""; types)
cryst = Crystal(latvecs, positions, "Pnma"; types)
view_crystal(cryst)

# Create a system with exchange parameters taken from [T. Jensen, et al., PRB
Expand Down
4 changes: 2 additions & 2 deletions examples/spinw_tutorials/SW18_Distorted_kagome.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

using Sunny, GLMakie

# Build the distorted kagome crystal, with spacegroup 12.
# Build the distorted kagome crystal, with spacegroup 12 ("C 1 2/m 1" setting).

units = Units(:meV, :angstrom)
latvecs = lattice_vectors(10.2, 5.94, 7.81, 90, 117.7, 90)
positions = [[0, 0, 0], [1/4, 1/4, 0]]
types = ["Cu1", "Cu2"]
cryst = Crystal(latvecs, positions, 12; types, setting="b1")
cryst = Crystal(latvecs, positions, "C 1 2/m 1"; types)
view_crystal(cryst)

# Define the interactions.
Expand Down
2 changes: 1 addition & 1 deletion ext/PlottingExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function reference_bonds_upto(cryst, nbonds, ndims)
end

function propagate_reference_bond_for_cell(cryst, b_ref)
symops = Sunny.canonical_group_order(cryst.symops)
symops = Sunny.canonical_group_order(cryst.sg.symops)

found = map(_ -> Bond[], cryst.positions)
for s in symops
Expand Down
6 changes: 4 additions & 2 deletions src/MCIF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ function set_dipoles_from_mcif!(sys::System, filename::AbstractString)
tol = 0.1 * sys.crystal.symprec # Tolerance might need tuning
orig_cryst = orig_crystal(sys)

primvecs = @something orig_cryst.prim_latvecs orig_cryst.latvecs
primcell = @something primitive_cell(orig_cryst) Mat3(I)
primvecs = orig_cryst.latvecs * primcell

suggestion = if all(isinteger.(rationalize.(primvecs \ supervecs2; tol)))
suggested_shape = rationalize.(orig_cryst.latvecs \ supervecs2; tol)
suggestion = if isdiag(suggested_shape)
sz = fractional_vec3_to_string(diag(suggested_shape))
diag_strs = number_to_math_string.(diag(suggested_shape))
sz = "("*join(diag_strs, ", ")*")"
error("Use `resize_supercell(sys, $sz)` to get compatible system")
else
shp = fractional_mat3_to_string(suggested_shape)
Expand Down
11 changes: 5 additions & 6 deletions src/Reshaping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ function reshape_supercell(sys::System, shape)

orig = orig_crystal(sys)
check_shape_commensurate(orig, shape)

primvecs = @something orig.prim_latvecs orig.latvecs
prim_shape = primvecs \ orig.latvecs * shape
prim_shape′ = round.(Int, prim_shape)
@assert prim_shape′ ≈ prim_shape
prim_cell = @something primitive_cell(orig) Mat3(I)
shape_in_prim = prim_cell \ shape
@assert all_integer(shape_in_prim; orig.symprec)
shape_in_prim = round.(Int, shape_in_prim)

# Unit cell for new system, in units of original unit cell.
new_dims = NTuple{3, Int}(gcd.(eachcol(prim_shape′)))
new_dims = NTuple{3, Int}(gcd.(eachcol(shape_in_prim)))
new_shape = Mat3(shape * diagm(collect(inv.(new_dims))))
new_cryst = reshape_crystal(orig_crystal(sys), new_shape)

Expand Down
6 changes: 4 additions & 2 deletions src/Sunny.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ export spin_matrices, stevens_matrices, to_product_space, rotate_operator, print
include("Symmetry/LatticeUtils.jl")
include("Symmetry/SymOp.jl")
include("Symmetry/MSymOp.jl")
include("Symmetry/SpacegroupData.jl")
include("Symmetry/WyckoffData.jl")
include("Symmetry/Crystal.jl")
include("Symmetry/Bond.jl")
include("Symmetry/SymmetryAnalysis.jl")
include("Symmetry/AllowedCouplings.jl")
include("Symmetry/AllowedAnisotropy.jl")
include("Symmetry/Parsing.jl")
include("Symmetry/Printing.jl")
export Crystal, subcrystal, standardize, lattice_vectors, lattice_params, primitive_cell_shape, Bond,
export Crystal, subcrystal, standardize, lattice_vectors, lattice_params, primitive_cell, Bond,
reference_bonds, print_site, print_bond, print_symmetry_table, print_suggested_frame

include("Units.jl")
Expand Down Expand Up @@ -174,7 +176,7 @@ PT.@setup_workload begin
PT.@compile_workload begin
# Crystal loading
latvecs = lattice_vectors(1, 1, 1, 90, 90, 90)
cryst = Crystal(latvecs, [[0,0,0]], 227, setting="1")
cryst = Crystal(latvecs, [[0,0,0]], 227; choice=1)
repr("text/plain", cryst)
print_symmetry_table(cryst, 0.8; io=devnull)
end
Expand Down
Loading
Loading