diff --git a/docs/src/versions.md b/docs/src/versions.md index ebac1c485..d8f8d3a19 100644 --- a/docs/src/versions.md +++ b/docs/src/versions.md @@ -9,9 +9,8 @@ Major refactors and enhancements to intensity calculations. This new interface allows unification between LSWT and classical spin dynamics calculations. This interface allows: Custom observables as local quantum operators, better support for linebroadening, and automatic binning to facilitate comparison with -experimental data. See [`intensity_formula`](@ref) for documentation. - -Experimental neturon scattering data can now be loaded using [`load_nxs`](@ref). +experimental data. See [`intensity_formula`](@ref) for documentation. Use +[`load_nxs`](@ref) to load experimental neutron scattering data. **Breaking changes**. @@ -40,6 +39,10 @@ Rename `polarize_spin!` to [`set_dipole!`](@ref) for consistency with [`set_coherent!`](@ref). The behavior of the former function is unchanged: the spin at a given site will still be polarized along the provided direction. +Rename `reshape_geometry` to [`reshape_supercell`](@ref), which is the +fundamental reshaping function. Rename `resize_periodically` to +[`resize_supercell`](@ref). + The constructor [`SpinInfo`](@ref) now requires a ``g``-factor or tensor as a named argument. @@ -156,8 +159,8 @@ interface, see the [Structure Factor Calculations](@ref) page. * [`repeat_periodically`](@ref) replaces `extend_periodically`. -Additional related functions include [`resize_periodically`](@ref) and -[`reshape_geometry`](@ref), the latter being fundamental. +Additional related functions include `resize_periodically` and +`reshape_geometry`, the latter being fundamental. * [`print_symmetry_table`](@ref) replaces `print_bond_table()`. diff --git a/examples/fei2_tutorial.jl b/examples/fei2_tutorial.jl index d936b200b..89ca51e01 100644 --- a/examples/fei2_tutorial.jl +++ b/examples/fei2_tutorial.jl @@ -214,11 +214,11 @@ print_wrapped_intensities(sys) suggest_magnetic_supercell([[0, -1/4, 1/4]], sys.latsize) -# The function [`reshape_geometry`](@ref) allows an arbitrary reshaping of the +# The function [`reshape_supercell`](@ref) allows an arbitrary reshaping of the # system. After selecting the supercell geometry, it becomes much easier to find # the energy-minimizing spin configuration. -sys_supercell = reshape_geometry(sys, [1 0 0; 0 1 -2; 0 1 2]) +sys_supercell = reshape_supercell(sys, [1 0 0; 0 1 -2; 0 1 2]) langevin.kT = 0 for i in 1:10_000 diff --git a/src/Plotting.jl b/src/Plotting.jl index 062adf1b3..7b6a1b84a 100644 --- a/src/Plotting.jl +++ b/src/Plotting.jl @@ -259,7 +259,7 @@ function plot_spins(sys::System; linecolor=:grey, arrowcolor=:red, ) if !isnothing(sys.origin) - sys_origin = resize_periodically(sys,sys.origin.latsize) + sys_origin = resize_supercell(sys,sys.origin.latsize) # Translate to a correct lattice site in the middle of the bigger system center_origin = (sys_origin.crystal.latvecs * Vec3(sys_origin.latsize))/2 diff --git a/src/Reshaping.jl b/src/Reshaping.jl index 764f2c7af..8f56a2e89 100644 --- a/src/Reshaping.jl +++ b/src/Reshaping.jl @@ -1,6 +1,6 @@ """ - reshape_geometry(sys::System, A) + reshape_supercell(sys::System, A) Maps an existing [`System`](@ref) to a new one that has the shape and periodicity of a requested supercell. The columns of the ``3×3`` integer matrix @@ -14,13 +14,13 @@ operations will be unavailable for this system, e.g., setting interactions by symmetry propagation. In practice, one can set all interactions using the original system, and then reshape as a final step. """ -function reshape_geometry(sys::System{N}, A) where N +function reshape_supercell(sys::System{N}, A) where N # latsize for new system new_latsize = NTuple{3, Int}(gcd.(eachcol(A))) # Unit cell for new system, in units of original unit cell. Obtained by # dividing each column of A by corresponding new_latsize component. new_cell_size = Int.(A / diagm(collect(new_latsize))) - return reshape_geometry_aux(sys, new_latsize, new_cell_size) + return reshape_supercell_aux(sys, new_latsize, new_cell_size) end @@ -46,7 +46,7 @@ function set_interactions_from_origin!(sys::System{N}) where N end -function reshape_geometry_aux(sys::System{N}, new_latsize::NTuple{3, Int}, new_cell_size::Matrix{Int}) where N +function reshape_supercell_aux(sys::System{N}, new_latsize::NTuple{3, Int}, new_cell_size::Matrix{Int}) where N is_homogeneous(sys) || error("Cannot reshape system with inhomogeneous interactions.") # `origin` describes the unit cell of the original system. For sequential @@ -126,16 +126,16 @@ function cell_dimensions(sys) end """ - resize_periodically(sys::System{N}, latsize) where N + resize_supercell(sys::System{N}, latsize) where N Creates a [`System`](@ref) identical to `sys` but enlarged to a given number of unit cells in each lattice vector direction. An error will be thrown if `sys` is incommensurate with `latsize`. Use -[`reshape_geometry`](@ref) instead to reduce the volume, or to perform an +[`reshape_supercell`](@ref) instead to reduce the volume, or to perform an incommensurate reshaping. """ -function resize_periodically(sys::System{N}, latsize::NTuple{3,Int}) where N +function resize_supercell(sys::System{N}, latsize::NTuple{3,Int}) where N # Shape of the original system, in multiples of the original unit cell. sysdims = cell_dimensions(sys) * diagm(collect(sys.latsize)) # Proposed system shape, given in fractional coordinates of original system @@ -145,7 +145,7 @@ function resize_periodically(sys::System{N}, latsize::NTuple{3,Int}) where N if norm(A - round.(A)) > 1e-12 error("Incommensurate system size.") end - return reshape_geometry(sys, diagm(collect(latsize))) + return reshape_supercell(sys, diagm(collect(latsize))) end """ @@ -158,7 +158,7 @@ function repeat_periodically(sys::System{N}, counts::NTuple{3,Int}) where N counts = NTuple{3,Int}(counts) @assert all(>=(1), counts) # Scale each column by `counts` and reshape - return reshape_geometry_aux(sys, counts .* sys.latsize, Matrix(cell_dimensions(sys))) + return reshape_supercell_aux(sys, counts .* sys.latsize, Matrix(cell_dimensions(sys))) end diff --git a/src/SpinWaveTheory/SpinWaveTheory.jl b/src/SpinWaveTheory/SpinWaveTheory.jl index 35afb8fb0..a53ed77fd 100644 --- a/src/SpinWaveTheory/SpinWaveTheory.jl +++ b/src/SpinWaveTheory/SpinWaveTheory.jl @@ -142,7 +142,7 @@ end function SpinWaveTheory(sys::System{N}; energy_ϵ::Float64=1e-8, energy_tol::Float64=1e-6) where N # Reshape into single unit cell cellsize_mag = cell_dimensions(sys) * diagm(collect(sys.latsize)) - sys = reshape_geometry_aux(sys, (1,1,1), cellsize_mag) + sys = reshape_supercell_aux(sys, (1,1,1), cellsize_mag) # Computes the Stevens operator in the local reference frame and the SO(3) rotation matrix from global to local frame # (:dipole mode only) diff --git a/src/Sunny.jl b/src/Sunny.jl index ac8e1c531..a1fa67748 100644 --- a/src/Sunny.jl +++ b/src/Sunny.jl @@ -70,7 +70,7 @@ export SpinInfo, System, Site, all_sites, position_to_site, symmetry_equivalent_bonds, set_exchange_at!, remove_periodicity! include("Reshaping.jl") -export reshape_geometry, resize_periodically, repeat_periodically, +export reshape_supercell, resize_supercell, repeat_periodically, print_wrapped_intensities, suggest_magnetic_supercell include("Integrators.jl") diff --git a/src/System/System.jl b/src/System/System.jl index b9e1a48d9..ee817c61b 100644 --- a/src/System/System.jl +++ b/src/System/System.jl @@ -219,7 +219,7 @@ end Converts a position `r` to four indices of a [`Site`](@ref). The coordinates of `r` are given in units of the lattice vectors for the original crystal. This function can be useful for working with systems that have been reshaped using -[`reshape_geometry`](@ref). +[`reshape_supercell`](@ref). # Example diff --git a/test/test_lswt.jl b/test/test_lswt.jl index 3e69647f5..349eb6efc 100644 --- a/test/test_lswt.jl +++ b/test/test_lswt.jl @@ -37,7 +37,7 @@ end randomize_spins!(sys) A = [1 1 1; -1 1 0; 0 0 1] - sys_swt = reshape_geometry(sys, A) + sys_swt = reshape_supercell(sys, A) langevin.kT = 0 for i in 1:50_000 @@ -141,11 +141,11 @@ end set_exchange!(sys_SUN, JL, Bond(1, 1, [1, 0, 0]); biquad=JQ) set_exchange!(sys_dip, JL, Bond(1, 1, [1, 0, 0]); biquad=JQ) - sys_swt_SUN = reshape_geometry(sys_SUN, [1 1 1; -1 1 0; 0 0 1]) + sys_swt_SUN = reshape_supercell(sys_SUN, [1 1 1; -1 1 0; 0 0 1]) set_dipole!(sys_swt_SUN, ( 1, 0, 0), position_to_site(sys_swt_SUN, (0, 0, 0))) set_dipole!(sys_swt_SUN, (-1, 0, 0), position_to_site(sys_swt_SUN, (0, 1, 0))) - sys_swt_dip = reshape_geometry(sys_dip, [1 1 1; -1 1 0; 0 0 1]) + sys_swt_dip = reshape_supercell(sys_dip, [1 1 1; -1 1 0; 0 0 1]) set_dipole!(sys_swt_dip, ( 1, 0, 0), position_to_site(sys_swt_dip, (0, 0, 0))) set_dipole!(sys_swt_dip, (-1, 0, 0), position_to_site(sys_swt_dip, (0, 1, 0))) @@ -198,7 +198,7 @@ end set_onsite_coupling!(sys_dip, D*Sz^2, 1) set_external_field!(sys_dip, [0, 0, h]) - sys_swt_dip = reshape_geometry(sys_dip, [1 -1 0; 1 1 0; 0 0 1]) + sys_swt_dip = reshape_supercell(sys_dip, [1 -1 0; 1 1 0; 0 0 1]) c₂ = 1 - 1/(2S) θ = acos(h / (2S*(4J+D*c₂))) set_dipole!(sys_swt_dip, ( sin(θ), 0, cos(θ)), position_to_site(sys_swt_dip, (0,0,0))) diff --git a/test/test_resize.jl b/test/test_resize.jl index a893cf76c..bf61aa36a 100644 --- a/test/test_resize.jl +++ b/test/test_resize.jl @@ -37,16 +37,16 @@ A1 = [1 0 0; 0 2 0; 0 0 1] A2 = [1 0 0; 1 2 0; 0 0 1] - newsys1 = reshape_geometry(sys, A1) - newsys2 = reshape_geometry(sys, A2) + newsys1 = reshape_supercell(sys, A1) + newsys2 = reshape_supercell(sys, A2) @test energy(sys) / prod(sys.latsize) ≈ 2.55 - newsys = reshape_geometry(sys, A1) + newsys = reshape_supercell(sys, A1) @test energy(newsys) / prod(newsys.latsize) ≈ 2.55 - newsys = reshape_geometry(sys, A2) + newsys = reshape_supercell(sys, A2) @test energy(newsys) / prod(newsys.latsize) ≈ 2.55 - newsys = reshape_geometry(sys, A1) + newsys = reshape_supercell(sys, A1) @test energy(newsys) / prod(newsys.latsize) ≈ 2.55 end @@ -59,15 +59,15 @@ end randomize_spins!(sys) # Reshape to sheared volume - sys2 = reshape_geometry(sys, [3 0 0; 2 3 0; 0 0 3]) + sys2 = reshape_supercell(sys, [3 0 0; 2 3 0; 0 0 3]) # Reshape back to original volume - sys3 = reshape_geometry(sys2, diagm([3,3,3])) + sys3 = reshape_supercell(sys2, diagm([3,3,3])) @test sys2.dipoles != sys.dipoles @test sys3.dipoles == sys.dipoles # Two equivalent ways of sizing up sys sys2 = repeat_periodically(sys, (2, 2, 1)) - sys3 = resize_periodically(sys, (6, 6, 3)) + sys3 = resize_supercell(sys, (6, 6, 3)) @test sys2.dipoles == sys3.dipoles end @@ -80,7 +80,7 @@ end # Commensurate shear that is specially designed to preserve the periodicity of # the system volume - sys2 = reshape_geometry(sys, [3 3 0; 0 3 0; 0 0 3]) + sys2 = reshape_supercell(sys, [3 3 0; 0 3 0; 0 0 3]) # Users always specify a bond using atom indices of the original unit cell, # but `sys2.interactions_union` is internally reindexed. @@ -111,7 +111,7 @@ end 0 latsize[2] 0 0 0 latsize[3]] @test det(A) ≈ prod(latsize) - sys2 = reshape_geometry(sys, A) + sys2 = reshape_supercell(sys, A) @test Sunny.natoms(sys2.crystal) == 2 @test energy(sys2) ≈ E0 @@ -195,8 +195,8 @@ end sys.dipoles[:, j, k, 1] = circshift([s, s, -s, -s], mod(j+k, 4)) end - sys_supercell = reshape_geometry(sys, [2 0 1; -1 1 0; -1 -1 1]) - sys2 = resize_periodically(sys_supercell, (4,4,4)) + sys_supercell = reshape_supercell(sys, [2 0 1; -1 1 0; -1 -1 1]) + sys2 = resize_supercell(sys_supercell, (4,4,4)) E0 = energy(sys) / length(sys.dipoles) E1 = energy(sys_supercell) / length(sys_supercell.dipoles)