[lammps-users] pair_eam data access from external class

Hi,

I’m writing a new compute class that requires access to some pair_eam data (specifically frho,rhor,z2r). Assuming the PairEAM class has already been created by the input script prior to my compute function being called, how can I access the PairEAM object from my compute class?

Thanks.
-AdamC

Hi,
I'm writing a new compute class that requires access to some pair_eam data
(specifically frho,rhor,z2r). Assuming the PairEAM class has already been
created by the input script prior to my compute function being called, how
can I access the PairEAM object from my compute class?

adam,

not sure if this is a good idea. outside of the individual pair class instance,
you can only access them through the API defined in the baseline pair class
from which PairEAM is derived. while it would be technically possible, to bypass
all the protection layers that c++ offers, but that would also negate
the benefits
of it and would make for a very hackish implementation.

i would recommend instead that your compute just reads in the EAM parameter
file again. you can copy over the parsing code from PairEAM and have similarly
less programming effort and a much cleaner implementation.

cheers,
    axel.

Axel;

Thanks for your response. I completely agree with your sentiments, I just wanted to make sure I wasn’t missing a legitimate way of accessing this data. I looked in to copying over the code and it seems like there will be some problems doing this as well since I will need access to variables that PairEAM has access to only through inheritance (neighbor lists). Things do start to get ugly again since I can’t cleanly regenerate the neighbor lists from scratch. Any suggestions?

-AdamC

Axel;
Thanks for your response. I completely agree with your sentiments, I just
wanted to make sure I wasn't missing a legitimate way of accessing this
data. I looked in to copying over the code and it seems like there will be
some problems doing this as well since I will need access to variables that
PairEAM has access to only through inheritance (neighbor lists). Things do
start to get ugly again since I can't cleanly regenerate the neighbor lists
from scratch. Any suggestions?

it is impossible to give advice on something that specific without
knowing the details of what you want to do.

why do you need access to the neighbor lists?

in principle they should be accessible since both the Compute
and the Pair base class are derived from pointers. the tricky thing
would be to identify which neighbor list would "belong" to PairEAM.
if you really need access to the/a neighbor list, perhaps it would be
possible to add a request to build a suitable neighbor list from your
compute. i have not yet dug into the neighbor lists general code that
deep so far.

another option would be to create a modified version of the PairEAM
class that would generate and output the information that you want to
compute during the call to the PairEAM::compute() method.

which would be the best way to proceed depends a lot on what you
are planning to do...

cheers,
    axel.

I’m writing a tool for computing the elastic coefficients of a system using the 2nd differential of the pair potential. This only needs to be done once, at the beginning of the simulation and not after every time step. I’m starting by writing this for the EAM potential, but I plan on expanding it to work with all potentials eventually.

While I don’t think that I have any specific need for the neighbor list, PairEAM uses it when looping over each atom pair to sum up the electron density contributions and embedding energy.

Also I’m not exactly clear as to why the neighbor lists are used to access the atom positions instead of atom->x, although I’m guessing it has something to do with running the simulation in parallel and only accessing local atoms. If you have any insight on this I’d appreciate it.

-AdamC

Also I'm not exactly clear as to why the neighbor lists are used to access
the atom positions instead of atom->x, although I'm guessing it has
something to do with running the simulation in parallel and only accessing
local atoms. If you have any insight on this I'd appreciate it.

neighbor lists are used mainly for efficiency reasons. it changes the
scaling of the loop over all pairs of atoms within the cutoff from an
O(N**2) complexity to an O(N) complexity. while building the neighbor
lists costs extra time, it usually does not need to be done at every step
and when using a grid search for potential neighbors, it is an O(N)
process, too.
on top of that, lammps encodes exclusions for bonded interactions into the
neighborlists.

there is nothing stopping you from accessing the atom coordinates directly
within your compute. all you have to do is to then make sure that you compute
only the contributions of the corresponding local atoms. have a look at what
other computes are doing to access the coordinates.
cheers,
    axel.

Great, thats exactly what I was hoping to hear. Thanks for your help!

-AdamC

The force->pair_match() function will give you a pointer to the
pair EAM class, whether it is the only pair style or part of a hybrid
simulation. You can use that pointer to grab any quantity in
the class that is public. If you want a private datum then you
have 2 choices. Move it in the pair_eam.h file to the public section,
or make your new compute class a "friend" of the PairEAM class.

If you want neighbor list info, you don;t get it from a pair class.
Rather your compute should request a neighbor list, like several
of them do - see compute group/group for example.

Steve

I don’t know how I missed this… force->pair_match() is exactly what you need to obtain all the pair information. Axel, I suggest you might take a look at this, it sounds live you might have been in a similar situation as me.

Steve thanks for the help, you’ve returned my faith in LAMMPS code design. (:

-AdamC

Steve thanks for the help, you've returned my faith in LAMMPS code design. (:

Your faith is misplaced, but I'm glad you're happier.

Steve