Skip to content

Instantly share code, notes, and snippets.

@cortner
Last active December 4, 2017 13:30
Show Gist options
  • Save cortner/03e0a670b257685e1a4b8774b0f0efda to your computer and use it in GitHub Desktop.
Save cortner/03e0a670b257685e1a4b8774b0f0efda to your computer and use it in GitHub Desktop.
Reproduces the memory overwrite bug in neighbour list
using JuLIP, JuLIP.ASE, JuLIP.Potentials
using ProgressMeter
# set up a heptamer
r0 = 1.0
N = 6
phi = linspace(0., (N-1)* 2*pi/N, N)|>collect
x0 = 2.5 # position of center
y0 = 2.5
x = x0 + [0; r0 * cos.(phi)]
y = y0 + [0; r0 * sin.(phi)]
X = [x';y'; zeros(N+1)']|> vecs
at = Atoms("H$(length(X))", X)
set_cell!(at, diagm([5, 5, 1.0]))
set_pbc!(at, (true, true, true))
set_constraint!(at, FixedCell2D(at))
lj =LennardJones(1., 1.) * SplineCutoff(1.7, 2.5)
set_calculator!(at, lj);
minimise!(at, precond=:id)
q = position_dofs(at)
kBT = 0.1
nsteps = 10^5
dt = 1.e-4
E0 = energy(at, q)
println("Initial Energy = $(E0)")
Evals = [0.]
srand(100)
# use progress meter to see that something is happening
p = Progress(nsteps,10)
#integrate and compute energies
for j=1:nsteps
q += -gradient(at, q) *dt+ sqrt(2. * kBT *dt) * randn(14)
push!(Evals, energy(at, q)-E0)
ProgressMeter.next!(p; showvalues = [("Energy",Evals[end])])
end
Ebar = mean(Evals)
println("Mean Eneergy After Shift = $(Ebar) ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment