From 13f95e0dd45ae469d87696dccf9f6a248ba787b4 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Wed, 1 Jan 2025 21:03:10 +0100 Subject: [PATCH] up --- src/callbacks.jl | 21 +++++++++++++++------ src/optimization.jl | 3 ++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/callbacks.jl b/src/callbacks.jl index fa385ce..39f07d8 100644 --- a/src/callbacks.jl +++ b/src/callbacks.jl @@ -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))) @@ -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 diff --git a/src/optimization.jl b/src/optimization.jl index cfae951..9fa5e69 100644 --- a/src/optimization.jl +++ b/src/optimization.jl @@ -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)