function call to LAMMPS from fortran code

Dear lammps users,

Can anybody tell me how to call LAMMPS as a function from a fortran code?
I have simulated monolayer graphene using AIREBO and generated
configurations. I am post-processing the data and I need to calculate the
excess pressure on some clusters of selected particles. To calculate the
pressure I have to use LAMMPS.
In the LAMMPS documentation it is said that from a fortran code it is
possible to make a function call to LAMMPS. There are two examples in
src/couple/simple direstory in C and C++ which I don't understand much.
So, if anybody can share a simple example in fortran where LAMMPS has been
called, then it will be very helpfull.
Any comment, suggestion in this regard is highly appreciated.
Thank you very much
Chandana

Dear lammps users,

Can anybody tell me how to call LAMMPS as a function from a fortran code?
I have simulated monolayer graphene using AIREBO and generated
configurations. I am post-processing the data and I need to calculate the
excess pressure on some clusters of selected particles. To calculate the
pressure I have to use LAMMPS.

really? how should that be done?

i don't think so. all you need would be to make sure that the data
you need as input to your post processing is properly computed
and contained in your dump file. what data do your need or
how would you otherwise do the calculation?

In the LAMMPS documentation it is said that from a fortran code it is
possible to make a function call to LAMMPS. There are two examples in
src/couple/simple direstory in C and C++ which I don't understand much.
So, if anybody can share a simple example in fortran where LAMMPS has been
called, then it will be very helpfull.

in order to use the library interface from fortran, you will
first have to write a wrapper that interfaces your fortran
code with the C interface in the library and have a decent
understanding of the data layout of the data structures
in LAMMPS. if you don't understand the existing code
in the couple/simple directory, a fortran wrapper won't
help you much.

cheers,
    axel.

in order to use the library interface from fortran, you will
first have to write a wrapper that interfaces your fortran
code with the C interface in the library and have a decent
understanding of the data layout of the data structures
in LAMMPS. if you don't understand the existing code
in the couple/simple directory, a fortran wrapper won't
help you much.

due to the significant amount of hack value
and to demonstrate my point, i just sat down
and programmed a fortran version of the simple.c
and simple.cpp code coupling examples and
the corresponding wrappers for the library code.

libfwrapper.c needs to be compiled with mpicc
simple.f90 correspondingly with mpif77 or mpif90

to link it all together, follow the instructions for
the other "simple" examples, but use mpif77
(or mpif90) and add -lstdc++ to the linker command.

enjoy (if you can),
   axel.

libfwrapper.c.gz (1.07 KB)

simple.f90.gz (1.54 KB)

Awesome. Axel does Fortran too. I'll
add this to the distro.

Axel, could you also do a LISP or APL
binding to the LAMMPS lib?

Steve

Awesome. Axel does Fortran too. I'll

sure thing. you gotta know thy enemy.

add this to the distro.

please note, that the fortran interface is not
complete and not all wrapped features work
in full. it only provides the functionality
required by simple.f90
some of the missing stuff could be easily added.
the rest may need a closer look and
a *lot* of motivation.

an alternative approach would be to write
an interface class in fortran 2003/2008
using ISO_C_BINDING. but i leave that
to real fortran enthusiasts.

Axel, could you also do a LISP or APL
binding to the LAMMPS lib?

hmm... APL

if somebody sends me an IBM model M type
keyboard with APL symbols (does this exist?),
i might think about it. always wanted to be
able to write self-encrypting software, and
my perl code is still far too readable. :wink:

but i have this crazy keyboard fetish and
cannot code well with one than isn't at
least 15 years old and "clicky".
(the one i currently type on was manufactured
on october 23rd 1991 and is mine since 1999).

axel.