-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMin_Energy.jl
61 lines (44 loc) · 1.33 KB
/
Min_Energy.jl
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
60
61
module Minimise_Energy
using JuLIP
using JuLIP.Potentials
using MultiHZ
using Pressure
import JuLIP: energy, forces, hessian_pos
export min_Energy
function min_Energy(at::AbstractAtoms)
max_iter_num = 1000
α = get_data(at, "Alpha")
α = [α α; α α]
k = 1.0
k = [k k; k k]
r = at.M
r1 = minimum(r)
r2 = maximum(r)
r0 = [2*r1 r1+r2; r1+r2 2*r2]
z = [1, 2]
V = MultiHZ.Multi_HZ(z, k, α, r0)
set_calculator!(at, V)
myresult = minimise!(at, precond = :id, method = :lbfgs, gtol=1e-14, verbose=2)
is_converged = myresult.f_converged || myresult.g_converged || myresult.x_converged
optmsg = myresult
iter_num = myresult.iterations
f_calls = myresult.f_calls
g_calls = myresult.g_calls
while (myresult.iterations == max_iter_num) & !(is_converged)
myresult = minimise!(at, precond = :id, method = :lbfgs, gtol=1e-14, verbose=2)
iter_num += myresult.iterations
f_calls += myresult.f_calls
g_calls += myresult.g_calls
end
optmsg = myresult
optmsg.iterations = iter_num
optmsg.f_calls = f_calls
optmsg.g_calls = g_calls
set_data!(at, "Optmsg", optmsg)
Energy = energy(V,at)
set_data!(at, "Energy", Energy)
p = Pressure.cal_Pressure(at)
set_data!(at, "Pressure", p)
return at
end
end