Skip to content

Commit

Permalink
Added exclamation mark to minimize_energy.
Browse files Browse the repository at this point in the history
  • Loading branch information
CedricTravelletti committed Jan 10, 2024
1 parent 6b82707 commit 392342d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/Al_supercell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ println("Initial regret $(energy_pert - energy_true).")

optim_options = (f_tol=1e-6, iterations=6, show_trace=true)

results = minimize_energy(al_supercell, calculator; optim_options...)
results = minimize_energy!(al_supercell, calculator; optim_options...)
println(results)
2 changes: 1 addition & 1 deletion examples/H2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ calculator = DFTKCalculator(system; model_kwargs, basis_kwargs, scf_kwargs)
solver = OptimizationOptimJL.LBFGS()
optim_options = (f_tol=1e-32, iterations=20, show_trace=true)

results = minimize_energy(system, calculator; solver=solver, optim_options...)
results = minimize_energy!(system, calculator; solver=solver, optim_options...)
println(results)
@printf "Bond length: %3f bohrs.\n" norm(results.minimizer[1:end])
2 changes: 1 addition & 1 deletion examples/H2_LJ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ lj = LennardJones(-1.17u"hartree", 0.743u"angstrom", 1, 1, 0.6u"nm")
solver = OptimizationOptimJL.LBFGS()
optim_options = (f_tol=1e-6, iterations=100, show_trace=false)

results = minimize_energy(system, lj; solver=solver, optim_options...)
results = minimize_energy!(system, lj; solver=solver, optim_options...)
println("Bond length: $(norm(results.minimizer[1:3] - results.minimizer[4:end])).")
2 changes: 1 addition & 1 deletion examples/TiAl_EmpiricalPotentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ system = AbstractSystem(data; particles)
solver = OptimizationOptimJL.LBFGS()
optim_options = (f_tol=1e-8, g_tol=1e-8, iterations=10, show_trace=true)

results = minimize_energy(system, lj; solver=solver, optim_options...)
results = minimize_energy!(system, lj; solver=solver, optim_options...)
println(results)
4 changes: 2 additions & 2 deletions src/optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# IMPORTANT: Note that we always work in cartesian coordinates.
=#

export minimize_energy
export minimize_energy!


"""
Expand Down Expand Up @@ -35,7 +35,7 @@ function Optimization.OptimizationFunction(system, calculator; kwargs...)
OptimizationFunction(f; grad=g!)
end

function minimize_energy(system, calculator; solver=Optim.LBFGS(), kwargs...)
function minimize_energy!(system, calculator; solver=Optim.LBFGS(), kwargs...)
# Use current system parameters as starting positions.
x0 = austrip.(not_clamped_positions(system)) # Optim modifies x0 in-place, so need a mutable type.
f_opt = OptimizationFunction(system, calculator)
Expand Down
2 changes: 1 addition & 1 deletion test/geometry_optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
solver = OptimizationOptimJL.LBFGS()
optim_options = (f_tol=1e-6, iterations=4, show_trace=false)

results = minimize_energy(system, calculator; solver=solver, optim_options...)
results = minimize_energy!(system, calculator; solver=solver, optim_options...)
@test isapprox(results.u[1], 0; atol=1e-5)
end

0 comments on commit 392342d

Please # to comment.