Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Jan 1, 2025
1 parent a01338f commit 13f95e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ produces output as well.
struct GeoOptDefaultCallback
verbosity::Int
always_show_header::Bool
show_virial::Bool
prev_time::Ref{UInt64}
end
function GeoOptDefaultCallback(verbosity=1; always_show_header=verbosity > 1)
GeoOptDefaultCallback(verbosity, always_show_header, Ref{UInt64}(0))
function GeoOptDefaultCallback(verbosity=1;
show_virial=true, always_show_header=verbosity > 1)
GeoOptDefaultCallback(verbosity, always_show_header, show_virial, Ref{UInt64}(0))
end

format_log8(value) = (value < 0 ? " " : "+") * (@sprintf "%8.2f" log10(abs(value)))
Expand All @@ -40,11 +42,18 @@ function (cb::GeoOptDefaultCallback)(optim_state, geoopt_state)
("log10(ΔE)", 9, logΔE),
("max(Force)", 10, fstr),
# TODO Maximal atomic displacement
# TODO Current virial, trace of lattice deformation matrix
("Δtime", 6, tstr),
# TODO Would be nice to have some simple way to add in
# a few calculator-specific things (e.g. total number of SCF iterations)
]
if cb.show_virial
maxvirial = austrip(maximum(abs, geoopt_state.virial))
pressure = -austrip(tr(geoopt_state.virial)) / 3
vstr = iszero(maxvirial) ? "" : round(maxvirial, sigdigits=8)
pstr = iszero(pressure) ? "" : round(pressure, sigdigits=2)
push!(fields, ("max(Virial)", 11, vstr))
push!(fields, ("Pressure", 8, pstr))
end
push!(fields, ("Δtime", 6, tstr))
# TODO Would be nice to have some simple way to add in
# a few calculator-specific things (e.g. total number of SCF iterations)

if cb.always_show_header
hlines = :all
Expand Down
3 changes: 2 additions & 1 deletion src/optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ function _minimize_energy!(system, calculator, solver;
tol_virial=1e-6u"eV", # TODO How reasonable ?
maxstep=0.8u"bohr",
verbosity::Integer=0,
callback=GeoOptDefaultCallback(verbosity),
callback=GeoOptDefaultCallback(verbosity;
show_virial=variablecell),
kwargs...)
solver = setup_solver(system, calculator, solver; maxstep)
system = convert_to_updatable(system)
Expand Down

0 comments on commit 13f95e0

Please sign in to comment.