[lammps-users] Calling lammps library from a external C program: how to collect energy?

Hi all,

I would like to collect the potential energy of my system from a
external program written in C using lammps as a library.

I have succeed in invoking the lammps routine following the
documentation and examples in examples/couple/c_drivers.c.
I have succeed in adding some routines to the library.cpp so that I can
get the force acting on each atom.

I would like at this point to define a routine lammps_get_energy that
allow me to collect the potential energy of the system. And that point,
I encounter different difficulties.

I have try to implement something analoguous to what is written in
compute_pe.cpp but I failed for I think two reasons:
- I am not used to C++ (I am used to C)
- I do not know enough the structure of lammps to be able to have an
overview of the different module dependence in lammps.

Does any one could help me?

Thank in advances,


If you invoke the compute_scalar() method of the
PE compute from your library interface
routine, then the total PE of the system will be stored
in the "scalar" variable of the compute.
I.e. if computePE is a ptr to the compute:

double PE = computePE->scalar;


Thanks a lot Steve, it works perfectly.

Actually, I am currenlty trying to write a program using lammps as a
library to implement the CI - NEB (CLimbing Image Nudged Elastic Band)
If such a code interests other people, and if I suceed, I will give the
source to the community.

So basically, I just want to use lammps library to calculate forces and
And so, a part from the energy, I need also the forces acting on each
I now how to get the forces acting on each atom using the pointer on
atom->f. But I wonder how to update it and if I need to update it , I
guess yes.
For instance, imagine I use the lammps_put_coords routine of library.cpp
to modify a configuration, I guess forces are not immediately updated..
so which routine shall I call before looking in atom->f?

Thank in advance.


You'll have to look at how something like Verlet::run() calls
the force routines.

We are working on a version of NEB that will be inside
LAMMPS, similar to temper and prd. Will probably
have an initial version out by the end of the year.