[lammps-users] how to get pe when using lammps as a library

Hi LAMMPS users,

I would like to use lammps as a library and hybridize it with my MC code, so I need to update potential energy after MC steps. How can I get the trial potential energy without running MD step? I have tried to add the following function to library.cpp

double lammps_get_pe(void *ptr)
LAMMPS *lammps = (LAMMPS *) ptr;
double pe;

return pe;

However, the pe won’t update after changing coordinates (in example c_driver.c) as:

double pe_new= lammps_get_pe(ptr);
printf(“pe = %f\n”, pe_new/natoms);

Could someone can tell me how lammps invokes to calculate the potential energy after the change of coordinates? Thank you in advance.



You can't get the PE without evaluating forces, energies, etc. Which
would be done by a "run 0", at a minimum. See the temper.cpp command
for how it extracts PE. If you then change coords (in your caller program),
you would have to do this again. LAMMPS has no way of knowing
what you incrementally changed.