Dear Axel,
thanks, this sounds good.
What I'm not understanding so far is,
that I thought by using something like
double *coords = (double*)lammps_extract_variable(lmp,"MYCOORDS","MYGRP");
I would get only the coordinates for the atoms in MYGRP
and thus would not have to use gmask as selector?
no. atom style variables are always returned as an array of the size of
the number of local atoms.
A last question (hopefully) concerning this:
If I run that code now with MPI (more than one proc),
I get some garbage output, like:
x[1005]=7199496020021154586587594...
Is this to be expected without using the selector?
no. this is because the demo code i wrote only works for 1 processor. for
1 processor nlocal == natoms.
atom style variables are stored distributed across the domains, so the
length of the array is nlocal and not natoms for more than one MPI rank.
sorry about that. so the more correct library interface test code looks
like this:
#include <mpi.h>
#include <stdio.h>
#include <inttypes.h>
#include "library.h"
int main (int argc, char **argv)
{
void *lmp;
int i,gatoms;
int nlocal;
MPI_Init(&argc,&argv);
lammps_open(0,NULL,MPI_COMM_WORLD,&lmp);
lammps_file(lmp,"in.protein");
lammps_command(lmp,"group MYGRP type 2");
lammps_command(lmp,"variable MYCOORDS atom x");
lammps_command(lmp,"variable MYIDS atom id");
lammps_command(lmp,"variable MYCOUNT equal count(MYGRP)");
nlocal = *(int *)lammps_extract_global(lmp,"nlocal");
gatoms = (int) *(double *)lammps_extract_variable(lmp,"MYCOUNT",NULL);
printf("local atoms = %d atoms in group = %d\n",nlocal,gatoms);
double *coords = (double
*)lammps_extract_variable(lmp,"MYCOORDS","MYGRP");
double *ids = (double *)lammps_extract_variable(lmp,"MYIDS","MYGRP");
for (i=0; i < nlocal; ++i) {
if (ids[i] != 0.0)
printf("x[%03d]=%10.4f\n",(int)ids[i],coords[i]);
}
lammps_free((void *)coords);
lammps_close(lmp);
MPI_Finalize();
return 0;
}
axel.