[lammps-users] Question about modifing Lammps

Hi,

I'm an MSci physics student at King's College London in the UK, and I'm using Lammps to run simulations for my project.

I wrote a routine to add forces on atoms from my own biasing potential. To implement this properly, my routine needs to access the atomic co-ordinates (arrays) from memory. I've looked through the source files but I'm unsure about how to do this. Could you give me a pointer on how to access the atomic positions, for use in my own routine?

Thanking you in advance,

Pepe Falahat

Hi,

hi pepe,

I'm an MSci physics student at King's College London in the UK, and I'm using Lammps to run simulations for my project.

I wrote a routine to add forces on atoms from my own biasing potential. To implement this properly, my routine needs to access the atomic co-ordinates (arrays) from memory. I've looked through the source files but I'm unsure about how to do this. Could you give me a pointer on how to access the atomic positions, for use in my own routine?

have a look at, e.g., the code for "fix spring" in fix_spring.h/.cpp
this applies in tether mode a force to group of atoms. that should
help to get you started. the most important thing to remember is
that you should design your code to be able to run in parallel with
domain decomposition, i.e. not all atom coordinates are available
on each processor.

cheers,
    axel.

Hi, Axel,
Actually I think I’m in a similar situation as Pepe, I would like to do some post-processing with coordinates for dynamics of the system I’m studying. Since the dynamics is quite fast, I’d like to do analysis of the coordinates for each or every 5-10 time steps. I think I could just dump the coordinates out first and analyze them, but that would require a huge diskspace for us and may waste some time on writing/reading to the disk. So I would rather do it on the fly, keeping everything in memory only.
In old lammps codes (very old version with fortran), we were able to do that by just sticking in a subroutine right before the ‘dump’ subroutine. but by reading your posts here, I’m worried that I’m not farmiliar with writing parallel codes and lost in the new structure of the c++ version of lammps, I couldnot find the right place to put in the subroutine any more. Would you please be kind enough to give me some suggestions for that?
Thanks in advance.
Jihang

Hi, Axel,

hi jihang,

[...]

In old lammps codes (very old version with fortran), we were able to
do that by just sticking in a subroutine right before the 'dump'

this sounds like an ugly hack.

subroutine. but by reading your posts here, I'm worried that I'm not
farmiliar with writing parallel codes and lost in the new structure of
the c++ version of lammps, I couldnot find the right place to put in
the subroutine any more. Would you please be kind enough to give me
some suggestions for that?

in general, i don't like the idea of just adding a call to
some unrelated functionality. this is bad program design and
what i personally like so much about LAMMPS is that its
structure is designed to add features in a very clean fashion.

so my first suggestion is to not just replicate your hack, but
rather spend some effort to understand the layout of LAMMPS.
the documentation is very helpful about it, and it is worth
reading (re-reading) it a couple of times and experimenting
for a while. while this may take a little bit longer right
now, it will be an infinite advantage for you as soon as you
have to do some other programming within LAMMPS.

i would then have a look at how other analysis features are
implemented in LAMMPS, for example the R_gyr calculation. where
you would assign a variable to a compute that calculates the
radius of gyration and then output it via "fix print".

cheers,
    axel.

Could you give me a pointer on how to access the atomic positions, for use in my own routine?

double **x = atom->x;
then x[i][0] is the x coord of atom i
these atoms are the ones owned by that proc

The atom class can be accessed in any code you add to LAMMPS.

Steve

Add a fix or a compute. See doc/Section_modify.html for details.

Steve