This is the core function of a module to compute solvent accessible surface areas of molecules.
It works fine, but it would benefit of being faster. Without a full reworking of the data structures, etc, performance boils down to how fast this low-level function can run.
Rules: do not multi-thread. This already happens at a higher level.
Note that exposed_i
is a BitArray
, which has to be updated.
using BenchmarkTools
using StaticArrays
#
# Input data
#
function data()
x = rand(SVector{3,Float32})
y = rand(SVector{3,Float32})
dot_cache_i = [rand(SVector{3,Float32}) for _ in 1:200]
exposed_i=trues(200)
rj_sq=0.1
return x, y, dot_cache_i, exposed_i, rj_sq
end
#
# function to accelerate
#
function update_dot_exposure!(x, y, dot_cache_i, exposed_i, rj_sq)
for idot in eachindex(exposed_i)
if exposed_i[idot]
dot_on_surface = x + dot_cache_i[idot]
# Position the dot on the atom's surface in the molecule's coordinate system
# Check if the dot is inside the neighboring atom j
if sum(abs2, dot_on_surface - y) < rj_sq
exposed_i[idot] = false
end
end
end
return nothing
end
I get:
julia> @benchmark update_dot_exposure!($(data())...)
BenchmarkTools.Trial: 10000 samples with 737 evaluations per sample.
Range (min β¦ max): 171.301 ns β¦ 206.906 ns β GC (min β¦ max): 0.00% β¦ 0.00%
Time (median): 177.859 ns β GC (median): 0.00%
Time (mean Β± Ο): 177.764 ns Β± 1.354 ns β GC (mean Β± Ο): 0.00% Β± 0.00%
β βββββββββββββ β
β βββββ β
β
βββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββ
β
β
ββ
ββ
β
β
β
171 ns Histogram: log(frequency) by time 184 ns <
Memory estimate: 0 bytes, allocs estimate: 0.