git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8271 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2012-06-13 15:43:58 +00:00
parent 597dc8f9d8
commit ee74e0f713
4 changed files with 219 additions and 35 deletions

View File

@ -12,6 +12,7 @@
------------------------------------------------------------------------- */
#include "math.h"
#include "string.h"
#include "compute_gyration_molecule.h"
#include "atom.h"
#include "update.h"
@ -27,26 +28,47 @@ ComputeGyrationMolecule::ComputeGyrationMolecule(LAMMPS *lmp,
int narg, char **arg) :
Compute(lmp, narg, arg)
{
if (narg != 3) error->all(FLERR,"Illegal compute gyration/molecule command");
if (narg < 3) error->all(FLERR,"Illegal compute gyration/molecule command");
if (atom->molecular == 0)
error->all(FLERR,"Compute gyration/molecule requires molecular atom style");
vector_flag = 1;
extvector = 0;
tensor = 0;
int iarg = 3;
while (iarg < narg) {
if (strcmp(arg[iarg],"tensor") == 0) {
tensor = 1;
iarg++;
} else error->all(FLERR,"Illegal compute gyration/molecule command");
}
// setup molecule-based data
nmolecules = molecules_in_group(idlo,idhi);
size_vector = nmolecules;
memory->create(massproc,nmolecules,"gyration/molecule:massproc");
memory->create(masstotal,nmolecules,"gyration/molecule:masstotal");
memory->create(com,nmolecules,3,"gyration/molecule:com");
memory->create(comall,nmolecules,3,"gyration/molecule:comall");
memory->create(rg,nmolecules,"gyration/molecule:rg");
memory->create(rgall,nmolecules,"gyration/molecule:rgall");
vector = rgall;
rg = vector = NULL;
rgt = array = NULL;
if (tensor) {
memory->create(rgt,nmolecules,6,"gyration/molecule:rgt");
memory->create(array,nmolecules,6,"gyration/molecule:array");
array_flag = 1;
size_array_rows = nmolecules;
size_array_cols = 6;
extarray = 0;
} else {
memory->create(rg,nmolecules,"gyration/molecule:rg");
memory->create(vector,nmolecules,"gyration/molecule:vector");
vector_flag = 1;
size_vector = nmolecules;
extvector = 0;
}
// compute masstotal for each molecule
@ -84,7 +106,7 @@ ComputeGyrationMolecule::~ComputeGyrationMolecule()
memory->destroy(com);
memory->destroy(comall);
memory->destroy(rg);
memory->destroy(rgall);
memory->destroy(rgt);
}
/* ---------------------------------------------------------------------- */
@ -106,6 +128,114 @@ void ComputeGyrationMolecule::compute_vector()
invoked_array = update->ntimestep;
molcom();
for (i = 0; i < nmolecules; i++) rg[i] = 0.0;
double **x = atom->x;
int *mask = atom->mask;
int *molecule = atom->molecule;
int *type = atom->type;
int *image = atom->image;
double *mass = atom->mass;
double *rmass = atom->rmass;
int nlocal = atom->nlocal;
double xprd = domain->xprd;
double yprd = domain->yprd;
double zprd = domain->zprd;
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
xbox = (image[i] & 1023) - 512;
ybox = (image[i] >> 10 & 1023) - 512;
zbox = (image[i] >> 20) - 512;
imol = molecule[i];
if (molmap) imol = molmap[imol-idlo];
else imol--;
dx = (x[i][0] + xbox*xprd) - comall[imol][0];
dy = (x[i][1] + ybox*yprd) - comall[imol][1];
dz = (x[i][2] + zbox*zprd) - comall[imol][2];
if (rmass) massone = rmass[i];
else massone = mass[type[i]];
rg[imol] += (dx*dx + dy*dy + dz*dz) * massone;
}
MPI_Allreduce(rg,vector,nmolecules,MPI_DOUBLE,MPI_SUM,world);
for (i = 0; i < nmolecules; i++) vector[i] = sqrt(vector[i]/masstotal[i]);
}
/* ---------------------------------------------------------------------- */
void ComputeGyrationMolecule::compute_array()
{
int i,j,imol;
double xbox,ybox,zbox,dx,dy,dz;
double massone;
invoked_array = update->ntimestep;
molcom();
for (i = 0; i < nmolecules; i++)
for (j = 0; j < 6; j++)
rgt[i][j] = 0.0;
double **x = atom->x;
int *mask = atom->mask;
int *molecule = atom->molecule;
int *type = atom->type;
int *image = atom->image;
double *mass = atom->mass;
double *rmass = atom->rmass;
int nlocal = atom->nlocal;
double xprd = domain->xprd;
double yprd = domain->yprd;
double zprd = domain->zprd;
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
xbox = (image[i] & 1023) - 512;
ybox = (image[i] >> 10 & 1023) - 512;
zbox = (image[i] >> 20) - 512;
imol = molecule[i];
if (molmap) imol = molmap[imol-idlo];
else imol--;
dx = (x[i][0] + xbox*xprd) - comall[imol][0];
dy = (x[i][1] + ybox*yprd) - comall[imol][1];
dz = (x[i][2] + zbox*zprd) - comall[imol][2];
if (rmass) massone = rmass[i];
else massone = mass[type[i]];
rgt[imol][0] += dx*dx * massone;
rgt[imol][1] += dy*dy * massone;
rgt[imol][2] += dz*dz * massone;
rgt[imol][3] += dx*dy * massone;
rgt[imol][4] += dx*dz * massone;
rgt[imol][5] += dy*dz * massone;
}
if (nmolecules)
MPI_Allreduce(&rgt[0][0],&array[0][0],nmolecules*6,
MPI_DOUBLE,MPI_SUM,world);
for (i = 0; i < nmolecules; i++)
for (j = 0; j < 6; j++)
array[i][j] = sqrt(array[i][j]/masstotal[i]);
}
/* ----------------------------------------------------------------------
calculate per-molecule COM
------------------------------------------------------------------------- */
void ComputeGyrationMolecule::molcom()
{
int i,imol;
double xbox,ybox,zbox,dx,dy,dz;
double massone;
for (i = 0; i < nmolecules; i++)
com[i][0] = com[i][1] = com[i][2] = 0.0;
@ -122,7 +252,7 @@ void ComputeGyrationMolecule::compute_vector()
double yprd = domain->yprd;
double zprd = domain->zprd;
for (int i = 0; i < nlocal; i++)
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
xbox = (image[i] & 1023) - 512;
ybox = (image[i] >> 10 & 1023) - 512;
@ -144,28 +274,6 @@ void ComputeGyrationMolecule::compute_vector()
comall[i][1] /= masstotal[i];
comall[i][2] /= masstotal[i];
}
for (i = 0; i < nmolecules; i++) rg[i] = 0.0;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
xbox = (image[i] & 1023) - 512;
ybox = (image[i] >> 10 & 1023) - 512;
zbox = (image[i] >> 20) - 512;
imol = molecule[i];
if (molmap) imol = molmap[imol-idlo];
else imol--;
dx = (x[i][0] + xbox*xprd) - comall[imol][0];
dy = (x[i][1] + ybox*yprd) - comall[imol][1];
dz = (x[i][2] + zbox*zprd) - comall[imol][2];
if (rmass) massone = rmass[i];
else massone = mass[type[i]];
rg[imol] += (dx*dx + dy*dy + dz*dz) * massone;
}
MPI_Allreduce(rg,rgall,nmolecules,MPI_DOUBLE,MPI_SUM,world);
for (i = 0; i < nmolecules; i++) rgall[i] = sqrt(rgall[i]/masstotal[i]);
}
/* ----------------------------------------------------------------------
@ -174,8 +282,10 @@ void ComputeGyrationMolecule::compute_vector()
double ComputeGyrationMolecule::memory_usage()
{
double bytes = 4*nmolecules * sizeof(double);
double bytes = 2*nmolecules * sizeof(double);
if (molmap) bytes += (idhi-idlo+1) * sizeof(int);
bytes += 2*nmolecules*3 * sizeof(double);
if (tensor) bytes += 2*6*nmolecules * sizeof(double);
else bytes += 2*nmolecules * sizeof(double);
return bytes;
}