Skip to content

Commit

Permalink
Simplify spherical_shell, update versions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Aug 5, 2023
1 parent 6db0c47 commit 8ee53b2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions docs/src/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Remove `intensities` function. Instead, use one of
[`intensities_interpolated`](@ref) or [`intensities_binned`](@ref). These will
require an [`intensity_formula`](@ref), which defines a calculator (e.g., LSWT).

Sunny now expects all wavevectors in units of inverse Angstrom (1/Å). This
facilitates orientational averaging. Replace `connected_path` with
[`connected_path_from_rlu`](@ref), which returns wavevectors in 1/Å. Now
[`spherical_shell`](@ref) needs one fewer argument, and returns wavevectors in
1/Å.

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.
Expand Down
2 changes: 1 addition & 1 deletion examples/longer_examples/CoRh2O4-tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function powder_average(sc, rs, density; η=0.1, mode=:perp, kwargs...)
prog = Progress(length(rs); dt=10., desc="Powder Averaging: ", color=:blue);
output = zeros(Float64, length(rs), length(ωs(sc)))
for (i, r) in enumerate(rs)
qs = spherical_shell(sc, r, density)
qs = spherical_shell(r, density)
if length(qs) == 0
qs = [[0., 0., 0.]] ## If radius is too small, just look at 0 vector
end
Expand Down
7 changes: 3 additions & 4 deletions examples/powder_averaging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@ add_sample!(sc, sys)
# lorentzian(ω-ω₀, 0.1)`.

qpoints = [[0.0, 0.0, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.0], [0.0, 0.0, 0.0]]
qs, markers = connected_path_from_rlu(crystal, qpoints, 50)
qs, xticks = connected_path_from_rlu(crystal, qpoints, 50)

is = intensities_interpolated(sc, qs; interpolation=:round, formula = intensity_formula(sc,:trace))
is_broad = broaden_energy(sc, is, (ω, ω₀) -> lorentzian-ω₀, 0.1))

## Plot results
fig = Figure(; resolution=(1000,400))
xticklabels = [string(tuple(qs[i]...)) for i in markers]
plotparams = (;
aspect=1.4,
ylabel = "ω (meV)",
xlabel = "𝐪 (RLU)",
xticks=(markers, xticklabels),
xticks,
xticklabelrotation=π/10,
xticklabelsize=14,
)
Expand All @@ -86,7 +85,7 @@ function powder_average(sc, rs, density; η=0.1, kwargs...)
output = zeros(Float64, length(rs), nω)

for (i, r) in enumerate(rs)
qs = spherical_shell(sc, r, density) # Get points on a sphere of radius r
qs = spherical_shell(r, density) # Get points on a sphere of radius r
if length(qs) == 0
qs = [[0., 0., 0.]] # If no points (r is too small), just look at 0 vector
end
Expand Down
17 changes: 7 additions & 10 deletions src/Intensities/PowderAveraging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ function spherical_points_fibonacci(N)
end

"""
spherical_shell(sc::SampledCorrelations, radius, density)
spherical_shell(radius, density)
Returns a set of wave vectors lying on a sphere of specified radius, where
`radius` is given in ``Å^{-1}``. `density` controls how many points to select
per ``Å^{-2}``.
Sample points on a sphere of given `radius`, with given sample `density`.
The points are generated by mapping a Fibonacci lattice onto a sphere.
"""
function spherical_shell(sc::SampledCorrelations, radius, density)
function spherical_shell(radius, density)
numpoints = round(Int, 4π*radius^2 * density)
crystal = orig_crystal(sc)
C = inv(2π*inv(crystal.latvecs)') # Transformation for inverse angstroms to RLU
return if numpoints == 0
[Vec3(0,0,0)] # If radius too small, just return the 0 vector
if numpoints == 0
return [Vec3(0,0,0)] # If radius too small, just return the 0 vector
else
map(v->C*v, radius * spherical_points_fibonacci(numpoints))
return radius * spherical_points_fibonacci(numpoints)
end
end

function powder_average_interpolated(sc::SampledCorrelations, q_ias, density; kwargs...)
# FIXME
A = inv(inv(sc.crystal.latvecs)') # Transformation to convert from inverse angstroms to RLUs
= length(ωs(sc))
output = zeros(Float64, length(q_ias), nω) # generalize this so matches contract
Expand Down

0 comments on commit 8ee53b2

Please sign in to comment.