[lammps-users] Accessing astore through an input script

My group has written code in the past for calculating coupling constant based on two initial structures. We begin by finding our atomic structures in a different script and then saving the atom positions inside the Fix-> astore variable, using this method to set up the astore variable
char *newarg = new char[6];
newarg[0] = (char *) “TLS1”;
newarg[1] = (char *) “all”;
newarg[2] = (char *) “STORE”;
newarg[3] = (char *) “peratom”;
newarg[4] = (char *) “0”;
newarg[5] = (char *) “3”;

//Adds the Fix, and stores the pos1 array in the astore variable of the StoreFix command.
int iTLS1 = modify->find_fix((char *) “TLS1”);
FixStore *TLS1 = (FixStore *) modify->fix[iTLS1];
lAtoms = TLS1->astore;

And then we copy values from atom->x into TLS1->astore.

When we want to calculate our coupling constant, we copy the atom positions back from TLS1->astore into atom->x. We do the same thing with our second structure as well.

I was wondering if it is possible to input values into astore through an input file, like in my attempt below

read_dump TLS.pos 0 x y z
fix TLS1 all all STORE peratom 0 3
run 0
fix TLSLat1 all STORELAT
read_dump TLS.pos 1 x y z
fix TLS2 all STORE peratom 0 3
fix TLSlat2 all STORELAT
run 0
couple_elastic 0.005 linear relax

This method does only seems initialize TLS1-> astore and TLS2-> astore, but not load any data into TLS1->astore and TLS2->astore. This makes sense to me given that it was written in a different forum post, https://lammps.sandia.gov/threads/msg83755.html, that it us up to the user to fill in astore. So, must I write a new script to do this, or is there is a method where I can use an input file?
Thank you


You cannot expect an “internal” command to work from the LAMMPS command line and have its data accessible.
You can use fix store/state instead. https://docs.lammps.org/fix_store_state.html


I tried the fix store/state command, but it does not update the astore and I get a segmentation error.

what do you mean by that? remember that I cannot see from here what you have been doing. most likely it was not correct.

let me be a bit more specific (i expected that you would infer this from checking out the source code of fix store/state).

a) you define the store/state fix after reading the coordinates (and possible a run 0) and it should have the updated coordinates. you should be able to verify it with a write_dump command where you write out the current coordinates and what fix store/state has stored.
b) you have to access the contents of the fix store/state using the “normal” means to retrieve a per-atom property from a fix defined in an input.

  • pass the fix id as argument to the command/code trying to read it.
  • then look up the index of the fix instance in the array of fixes in Modify with modify->find_fix(ID)
  • get the pointer to the fix from the modify->fix array
  • check that this is the correct fix style and the data is present and has the desired dimensions
  • then you should be able to access the stored data from fix->array_atom

unlike the internal STORE fix, the fix store state data can be accessed from any LAMMPS command that allows access to per-atom data from fixes through f_ID references.


I tried the fix store/state command, but it does not update the astore and I get a segmentation error.

Okay, in that case our method of getting our structural data for calculating the coupling constant is not ideal?
I.E. we are copying atom positions over into fix->astore as opposed to using a premade fix?

it all depends on what you want to achieve. fix store/state has an interface to and can be controlled by LAMMPS scripting, fix STORE not.

there is no way to have script command access to internal data from C++ classes unless there is an interface. so the STORE fix data can only be accessed from C++ code.


Thank you very much for the help