[lammps-users] Lammps library

Hi everyone,

I am trying to use Lammps as a library inside a C wrapper and I would need to extract the potential energy of a solid metallic system. In the input file for Lammps I have added the line:

compute pot all pe

and then in the wrapper I call:
lammps_command(ptr,"minimize 1e-5 1e-7 50 500");
potential_energy = *(double *)lammps_extract(ptr,3,"pot","pe");

The minimization command works fine but the lammps_extract keeps giving me a segmentation fault I can't get rid of. Is there any way of extracting the potential energy of an atomic configuration if this one does not work???

I have tried adding the command
run 0

and adding a fix
fix nve all nve

None of these worked out.

Thanks a lot,
Enrique

That's the basic idea, but the lammps_extract function returns NULL
if the low-level object doesn't provide a hook for it to call. That's what
is happening in this case, b/c no one has added the hook to the compute pe
class. So you should always check the return on this call for a possible
NULL, else you will crash.

Now that I look at the library interface, lammps_extract() isn't that
useful for fixes and computes in their current form. So I will update
it today and post a patch. You won't need to add anything to compute pe.
Stay tuned.

Steve

Hi there,

I am having troubles as well when I try to get the coordinates with:
lammps_get_coords(ptr,x)
When the sample is created by Lammps everything seems to work fine but when in the input file for Lammps I tell him to read a file and then try to get the coordinates I am getting a mpi error (Allreduce function according to Totalview), which is a bit astonishing because I am running in one single processor.
The minimize command runs ok and I can extract the box dimension.
Maybe I have to add something to the input I do not know.
By the way, the lammps_extract(ptr, 3,"pot","pe") does not return NULL, just gives a segmentation fault.

Any idea....
Thanks a lot,
Enrique

See the example/couple programs. They use lammps_get_coord and
seem to work fine. I just posted a patch that updated the README
in that dir to make the build instructions current with the newest
LAMMPS lib interface, so grab that first.

Re: lammps_extract, the patch from a couple days ago changed
that interface. There is no longer a lammps_extract() but some
variants. Try those and see if your problems go away.

Steve

Thanks Steve,

That's what I do not really understand. I tried lammps_get_coords(ptr,x)
in the wrapper you have in example/couple and it works fine. In my code,
Lammps is reading a sample, and it can extract the box dimensions, runs
minimize and gives me the right energy, but when I try to get the
coordinates, it gives me a segmentation fault in what it looks like a mpi
function. In Totalview it seems like the coordinates are changed correctly
but it gets stacked in that Allreduce function. Same thing for
lammps_put_coords.

With the new patch, lammps_extract_compute, is working perfectly.

Below is the input to lammps, just in case I am doing something wrong.

# 3d FeCr CDEAM

units metal
atom_style atomic
atom_modify map array

boundary p p p

read_data ini_lammps.dat

pair_style eam/cd
pair_coeff * * potentials/fecrhe-CD-EAM-Lammps-v2.fcn Fe Cr He

compute pot all pe

Thanks a lot,
Enrique

See the example/couple programs. They use lammps_get_coord and
seem to work fine. I just posted a patch that updated the README in

that dir to make the build instructions current with the newest LAMMPS
lib interface, so grab that first.

Re: lammps_extract, the patch from a couple days ago changed
that interface. There is no longer a lammps_extract() but some
variants. Try those and see if your problems go away.

Steve

Hi there,
I am having troubles as well when I try to get the coordinates with:

lammps_get_coords(ptr,x)

When the sample is created by Lammps everything seems to work fine but

when in the input file for Lammps I tell him to read a file and then
try

to get the coordinates I am getting a mpi error (Allreduce function

according to Totalview), which is a bit astonishing because I am
running

in one single processor.
The minimize command runs ok and I can extract the box dimension. Maybe

I have to add something to the input I do not know.

By the way, the lammps_extract(ptr, 3,"pot","pe") does not return NULL,

just gives a segmentation fault.

Any idea....
Thanks a lot,
Enrique

That's the basic idea, but the lammps_extract function returns NULL if

the low-level object doesn't provide a hook for it to call. That's
what

is happening in this case, b/c no one has added the hook to the

compute

pe
class. So you should always check the return on this call for a possible
NULL, else you will crash.
Now that I look at the library interface, lammps_extract() isn't that

useful for fixes and computes in their current form. So I will update
it today and post a patch. You won't need to add anything to compute
pe.

Stay tuned.
Steve

Hi everyone,
I am trying to use Lammps as a library inside a C wrapper and I would

need to extract the potential energy of a solid metallic system. In
the input file for Lammps I have added the line:

compute pot all pe
and then in the wrapper I call:
lammps_command(ptr,"minimize 1e-5 1e-7 50 500");
potential_energy = *(double *)lammps_extract(ptr,3,"pot","pe"); The

minimization command works fine but the lammps_extract keeps giving
me a segmentation fault I can't get rid of. Is there any way
of

extracting the potential energy of an atomic configuration if this

one

does not work???
I have tried adding the command
run 0
and adding a fix
fix nve all nve
None of these worked out.
Thanks a lot,
Enrique
----------------------------------------
Enrique Martinez Saez
MST-8, EFRC
Los Alamos National Laboratory
Los Alamos, NM, 87544
Ph: 505 606 2149
Fax: 505 667 8021
[email protected]
------------------------------------------------------------------------------

This SF.net email is sponsored by

I don't know. I would put print statements in the lammps_get_coords() function
and verify that everything is setup correctly before the Allreduce. I don't see
how the Allreduce can fail if natoms is the same on every proc.

Steve