-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.jl
More file actions
59 lines (46 loc) · 1.69 KB
/
utils.jl
File metadata and controls
59 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using ConcreteStructs, Distributions, Statistics, StaticArrays
function Arianna.unnormalised_log_target_density(e, system::Particles)
return - e / system.temperature
end
function Arianna.delta_log_target_density(e1, e2, system::Particles)
return -(e2 - e1) ./ system.temperature
end
fold_back(x, box) = x .- fld.(x, box) .* box
function vector_1D(c1, c2, side_length)
dx = c1 - c2
return dx - round(dx / side_length) * side_length
end
@inline function vector(c1::SVector{N,T}, c2::SVector{N,T}, box::SVector{N,T}) where {N, T<:AbstractFloat}
@inbounds return SVector{N,T}(ntuple(i -> vector_1D(c1[i], c2[i], box[i]), Val(N)))
end
@inline function nearest_image_distance_squared(xi::SVector{N,T}, xj::SVector{N,T},
box::SVector{N,T}) where {N, T<:AbstractFloat}
@inbounds dx = vector(xi, xj, box)
return sum(abs2, dx)
end
struct SpeciesList
sp_ids::Vector{Vector{Int}}
sp_heads::Vector{Int}
end
function SpeciesList(species)
available_species = sort(unique(species))
ids = Vector{Vector{Int}}(undef, length(available_species))
heads = zeros(Int, length(species))
for k in eachindex(available_species)
ids[k] = findall(isequal(available_species[k]), species)
for i in eachindex(species)
if species[i] == available_species[k]
heads[i] = findfirst(isequal(i), ids[k])
end
end
end
return SpeciesList(ids, heads)
end
Arianna.@callback function energy(system::Particles)
return system.energy[1] / length(system)
end
function volume_sphere(r, d::Int)
d == 0 && return 1
d == 1 && return 2r
return 2π * r^2 * volume_sphere(r, d - 2) / d
end