Changing the state of the thermostat/barostat

Hi,

I am writing a TPS code in C++ that invokes LAMMPS as a library to perform the underlying dynamics. Currently, I am able to obtain the state of the thermostat/barostat at each frame of a trajectory by using a custom thermo_style and then something along the lines of (simplified):

double eta1;
lmp->output->thermo->evaluate_keyword(“f_p1[1]”,&eta1);

However, is there a way to modify the state of the thermostat/barostat e.g. if I wanted to perturb the value of eta1 and put this back into the first element of the global vector computed by fix npt?

I have had a look in library.cpp: there is void *lammps_extract_fix(…) which might provide another way to obtain this information, but I cannot see away to alter the values. I also tried something like:

lmp->modify->fix->eta[0] = &eta1

but this doesn’t work as double *eta is a protected variable in fix_nh.h (and possibly/probably for other reasons too…).

Any help appreciated!

Cheers,
Steve

PS I am happy to have a go at implementing a new library.cpp function similar to lammps_scatter_atoms() if necessary, but I will need pointing in the right direction.

Hi,

I am writing a TPS code in C++ that invokes LAMMPS as a library to perform
the underlying dynamics. Currently, I am able to obtain the state of the
thermostat/barostat at each frame of a trajectory by using a custom
thermo_style and then something along the lines of (simplified):

double eta1;
lmp->output->thermo->evaluate_keyword("f_p1[1]",&eta1);

However, is there a way to modify the state of the thermostat/barostat e.g.
if I wanted to perturb the value of eta1 and put this back into the first
element of the global vector computed by fix npt?

I have had a look in library.cpp: there is void *lammps_extract_fix(...)
which might provide another way to obtain this information, but I cannot see

this won't work, since this only accesses properties that are in any
of the Fix::compute*() methods.

away to alter the values. I also tried something like:

lmp->modify->fix->eta[0] = &eta1

this cannot work, since eta is not a member of Fix but of FixNH.

but this doesn't work as double *eta is a protected variable in fix_nh.h
(and possibly/probably for other reasons too...).

Any help appreciated!

the way to gain access internal data structure in LAMMPS is done
through an "extract" API in classes which will return a pointer to the
data entity. to get access to eta (and mtchain) in FixNH, you would
first need to modify fix_nh.cpp like this:

diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp
index 139b9ae..a2cff5c 100644
--- a/src/fix_nh.cpp
+++ b/src/fix_nh.cpp
@@ -1645,6 +1645,12 @@ void *FixNH::extract(const char *str, int &dim)
   dim=0;
   if (strcmp(str,"t_target") == 0) {
     return &t_target;
+ } else if (strcmp(str,"mtchain") == 0) {
+ return &mtchain;
+ }
+ dim=1;
+ if (strcmp(str,"eta") == 0) {
+ return η
   }
   return NULL;
}

and then expose this function to the library interface. the latter
would require a little bit of work and some thinking, since it cannot
easily by fitted into lammps_extract_fix().

axel.