A very Simple Sample of DMC solving H atoms

using Random
using LinearAlgebra
using Distributions

Random.seed!(1)

"""
    H atom
"""
energy(r) =  -1.0 / (norm(r))

function DMC_core!(box, walkers, Δt, E_o)
    for i in eachindex(walkers)
        dr = randn(3).* sqrt(Δt/3)
        walkers[i] += dr
        E_new = energy(walkers[i])
        p_accept = exp(-Δt * (E_new - E_o))
        if rand() < p_accept
            push!(box,walkers[i])
        else
            walkers[i] = sample(box)
    end end
end

function DMC_Integer(walkers,Step,E_guess,Δt)
    box = []
    for i in 1:Step
        DMC_core!(box, walkers, Δt, E_guess)
    end
    return box
end

N_walkers = 5000
steps = 2000
Δt = 0.01

box = DMC_Integer([rand(3).-0.5 for i in 1:1000],steps,-1,Δt)
histogram([norm(i) for i in box])

OUTPUT:

CC BY-SA 4.0 Cat GD. Last modified: October 26, 2024. Website built with Franklin.jl and the Julia programming language.