[lammps-users] Appropriate Way to Get Energy and Force

Is this an appropriate way to Get energy and force

double Dimer::GetForceAndEnergy()
{
update->minimize->init();
update->minimize->setup();
double tempEnergy = update->minimize->einitial;
update->minimize->cleanup();
return tempEnergy;
}

I wanted to use the energy_force() but it is in accessible.

Thank you,
Alec

Is this an appropriate way to Get energy and force

it is impossible to give an authoritative answer without knowing the context.

Force and (potential) energy are usually tallied into their respective accumulators/arrays during force computation as part of either minimization or time integration.
How and if energy is tallied depends on the “eflag” setting. It usually has to be “requested” by a “consumer” (see “Modify::addstep_compute()”).
Since force and energy are contributed by multiple classes, the process works by first clearing the accumulators and then adding to them (either directly or with the *tally() functions).

double Dimer::GetForceAndEnergy()
{
update->minimize->init();
update->minimize->setup();
double tempEnergy = update->minimize->einitial;
update->minimize->cleanup();
return tempEnergy;
}

I wanted to use the energy_force() but it is in accessible.

this seems to hint that you are writing a minimizer style. Such a class should be derived from the “Min” class and if done correctly, it should be accessible.

axel.

Please see: https://docs.lammps.org/Modify.html and https://docs.lammps.org/Modify_min.html

Thank you,
I was basing this on the NEB code since I need to keep track of three different structures simultaneously using replicas. Is there any minimization codes that work using replicas?
Thanks again,

Alec

Okay, I will try that.
Thank you,
Alec

the code construct used for NEB can work in principle with any type of minimizer. The specifics of NEB require a dynamics based minimizer, though.
it looks like you need two custom classes/styles. the replica class that does the minimization and a custom (dummy) “minimizer” that will just do a single step of energy/force computation.

Okay, I’ll give that a shot
Thanks for the advice

Let me elaborate a bit more on the flow of control during a NEB run.

  • You have different conformations that are applied to the different replica.
  • Each replica is running a minimization to completion (that is why the damped dynamics minimizer is required since they have a fixed set of steps and no “sub-step” iterations", there for all replicas run in step)
  • you also then have fix neb, that handles the communication between the replica and defines the NEB specific forces that are applied on top of the computed forces from the system (hence the designation to run in the “Fix::post_force()” step.

You obviously need to come up with a different flow of control and can thus probably forgo the post_force post-processing of forces and instead do the inter-replica communication directly from inside your custom command.

axel.