forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8271 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
597dc8f9d8
commit
ee74e0f713
|
@ -11,9 +11,12 @@
|
|||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "math.h"
|
||||
#include "compute_gyration.h"
|
||||
#include "update.h"
|
||||
#include "atom.h"
|
||||
#include "group.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
@ -25,8 +28,19 @@ ComputeGyration::ComputeGyration(LAMMPS *lmp, int narg, char **arg) :
|
|||
{
|
||||
if (narg != 3) error->all(FLERR,"Illegal compute gyration command");
|
||||
|
||||
scalar_flag = 1;
|
||||
scalar_flag = vector_flag = 1;
|
||||
size_vector = 6;
|
||||
extscalar = 0;
|
||||
extvector = 0;
|
||||
|
||||
vector = new double[6];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeGyration::~ComputeGyration()
|
||||
{
|
||||
delete [] vector;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -47,3 +61,57 @@ double ComputeGyration::compute_scalar()
|
|||
scalar = group->gyration(igroup,masstotal,xcm);
|
||||
return scalar;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
compute the radius-of-gyration tensor of group of atoms
|
||||
around center-of-mass cm
|
||||
must unwrap atoms to compute Rg tensor correctly
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeGyration::compute_vector()
|
||||
{
|
||||
invoked_vector = update->ntimestep;
|
||||
|
||||
double masstotal;
|
||||
double xcm[3];
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
int *image = atom->image;
|
||||
double *mass = atom->mass;
|
||||
double *rmass = atom->rmass;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
int xbox,ybox,zbox;
|
||||
double dx,dy,dz,massone;
|
||||
double xprd = domain->xprd;
|
||||
double yprd = domain->yprd;
|
||||
double zprd = domain->zprd;
|
||||
|
||||
double rg[6];
|
||||
rg[0] = rg[1] = rg[2] = rg[3] = rg[4] = rg[5] = 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;
|
||||
dx = (x[i][0] + xbox*xprd) - xcm[0];
|
||||
dy = (x[i][1] + ybox*yprd) - xcm[1];
|
||||
dz = (x[i][2] + zbox*zprd) - xcm[2];
|
||||
if (rmass) massone = rmass[i];
|
||||
else massone = mass[type[i]];
|
||||
rg[0] += dx*dx * massone;
|
||||
rg[1] += dy*dy * massone;
|
||||
rg[2] += dz*dz * massone;
|
||||
rg[3] += dx*dy * massone;
|
||||
rg[4] += dx*dz * massone;
|
||||
rg[5] += dy*dz * massone;
|
||||
}
|
||||
MPI_Allreduce(rg,vector,6,MPI_DOUBLE,MPI_SUM,world);
|
||||
|
||||
if (masstotal == 0.0) return;
|
||||
for (int i = 0; i < 6; i++) vector[i] = sqrt(vector[i]/masstotal);
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@ namespace LAMMPS_NS {
|
|||
class ComputeGyration : public Compute {
|
||||
public:
|
||||
ComputeGyration(class LAMMPS *, int, char **);
|
||||
~ComputeGyration() {}
|
||||
~ComputeGyration();
|
||||
void init();
|
||||
double compute_scalar();
|
||||
void compute_vector();
|
||||
|
||||
private:
|
||||
double masstotal;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -30,15 +30,20 @@ class ComputeGyrationMolecule : public Compute {
|
|||
~ComputeGyrationMolecule();
|
||||
void init();
|
||||
void compute_vector();
|
||||
void compute_array();
|
||||
double memory_usage();
|
||||
|
||||
private:
|
||||
int tensor;
|
||||
int nmolecules;
|
||||
int idlo,idhi;
|
||||
|
||||
double *massproc,*masstotal;
|
||||
double **com,**comall;
|
||||
double *rg,*rgall;
|
||||
double *rg;
|
||||
double **rgt;
|
||||
|
||||
void molcom();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue