diff --git a/src/DIPOLE/atom_vec_dipole.cpp b/src/DIPOLE/atom_vec_dipole.cpp
index 2b94516b7..25377ae82 100644
--- a/src/DIPOLE/atom_vec_dipole.cpp
+++ b/src/DIPOLE/atom_vec_dipole.cpp
@@ -1,833 +1,833 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "atom_vec_dipole.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecDipole::AtomVecDipole(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 0;
   mass_type = 1;
 
   comm_x_only = 0;
   comm_f_only = 1;
   size_forward = 6;
   size_reverse = 3;
   size_border = 11;
   size_velocity = 3;
   size_data_atom = 9;
   size_data_vel = 7;
   xcol_data = 4;
 
   atom->q_flag = atom->mu_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecDipole::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   q = memory->grow(atom->q,nmax,"atom:q");
   mu = memory->grow(atom->mu,nmax,4,"atom:mu");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecDipole::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   q = atom->q; mu = atom->mu;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecDipole::copy(int i, int j, int delflag)
 {
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   q[j] = q[i];
   mu[j][0] = mu[i][0];
   mu[j][1] = mu[i][1];
   mu[j][2] = mu[i][2];
   mu[j][3] = mu[i][3];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_comm(int n, int *list, double *buf,
                              int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_comm_vel(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = mu[j][0];
         buf[m++] = mu[j][1];
         buf[m++] = mu[j][2];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = mu[j][0];
         buf[m++] = mu[j][1];
         buf[m++] = mu[j][2];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_comm_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = mu[j][0];
     buf[m++] = mu[j][1];
     buf[m++] = mu[j][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecDipole::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecDipole::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::unpack_comm_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecDipole::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_border(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
       buf[m++] = mu[j][3];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
       buf[m++] = mu[j][3];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_border_vel(int n, int *list, double *buf,
                                    int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = mu[j][0];
       buf[m++] = mu[j][1];
       buf[m++] = mu[j][2];
       buf[m++] = mu[j][3];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = mu[j][0];
         buf[m++] = mu[j][1];
         buf[m++] = mu[j][2];
         buf[m++] = mu[j][3];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = mu[j][0];
         buf[m++] = mu[j][1];
         buf[m++] = mu[j][2];
         buf[m++] = mu[j][3];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = q[j];
     buf[m++] = mu[j][0];
     buf[m++] = mu[j][1];
     buf[m++] = mu[j][2];
     buf[m++] = mu[j][3];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecDipole::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
     mu[i][3] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecDipole::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
     mu[i][3] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     q[i] = buf[m++];
     mu[i][0] = buf[m++];
     mu[i][1] = buf[m++];
     mu[i][2] = buf[m++];
     mu[i][3] = buf[m++];
   }
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack all atom quantities for shipping to another proc
    xyz must be 1st 3 values, so that comm::exchange can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_exchange(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = q[i];
   buf[m++] = mu[i][0];
   buf[m++] = mu[i][1];
   buf[m++] = mu[i][2];
   buf[m++] = mu[i][3];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecDipole::unpack_exchange(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   q[nlocal] = buf[m++];
   mu[nlocal][0] = buf[m++];
   mu[nlocal][1] = buf[m++];
   mu[nlocal][2] = buf[m++];
   mu[nlocal][3] = buf[m++];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecDipole::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 16 * nlocal;
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecDipole::pack_restart(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = q[i];
   buf[m++] = mu[i][0];
   buf[m++] = mu[i][1];
   buf[m++] = mu[i][2];
   buf[m++] = mu[i][3];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecDipole::unpack_restart(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   q[nlocal] = buf[m++];
   mu[nlocal][0] = buf[m++];
   mu[nlocal][1] = buf[m++];
   mu[nlocal][2] = buf[m++];
   mu[nlocal][3] = buf[m++];
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecDipole::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   q[nlocal] = 0.0;
   mu[nlocal][0] = 0.0;
   mu[nlocal][1] = 0.0;
   mu[nlocal][2] = 0.0;
   mu[nlocal][3] = 0.0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecDipole::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   type[nlocal] = atoi(values[1]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   q[nlocal] = atof(values[2]);
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   mu[nlocal][0] = atof(values[6]);
   mu[nlocal][1] = atof(values[7]);
   mu[nlocal][2] = atof(values[8]);
   mu[nlocal][3] = sqrt(mu[nlocal][0]*mu[nlocal][0] +
                        mu[nlocal][1]*mu[nlocal][1] +
                        mu[nlocal][2]*mu[nlocal][2]);
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecDipole::data_atom_hybrid(int nlocal, char **values)
 {
   q[nlocal] = atof(values[0]);
   mu[nlocal][0] = atof(values[1]);
   mu[nlocal][1] = atof(values[2]);
   mu[nlocal][2] = atof(values[3]);
   mu[nlocal][3] = sqrt(mu[nlocal][0]*mu[nlocal][0] +
                        mu[nlocal][1]*mu[nlocal][1] +
                        mu[nlocal][2]*mu[nlocal][2]);
   return 4;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecDipole::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("q")) bytes += memory->usage(q,nmax);
   if (atom->memcheck("mu")) bytes += memory->usage(mu,nmax,4);
 
   return bytes;
 }
diff --git a/src/GPU/pair_eam_gpu.cpp b/src/GPU/pair_eam_gpu.cpp
index 113a9df05..25e6ba814 100644
--- a/src/GPU/pair_eam_gpu.cpp
+++ b/src/GPU/pair_eam_gpu.cpp
@@ -1,284 +1,284 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: Trung Dac Nguyen (ORNL), W. Michael Brown (ORNL)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "string.h"
 #include "pair_eam_gpu.h"
 #include "atom.h"
 #include "force.h"
 #include "comm.h"
 #include "domain.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "memory.h"
 #include "error.h"
 #include "neigh_request.h"
 #include "gpu_extra.h"
 
 using namespace LAMMPS_NS;
 
 #define MAXLINE 1024
 
 // External functions from cuda library for atom decomposition
 
 int eam_gpu_init(const int ntypes, double host_cutforcesq,
-		 int **host_type2rhor, int **host_type2z2r,
+                 int **host_type2rhor, int **host_type2z2r,
                  int *host_type2frho, double ***host_rhor_spline,
-		 double ***host_z2r_spline, double ***host_frho_spline,
+                 double ***host_z2r_spline, double ***host_frho_spline,
                  double rdr, double rdrho, int nrhor, int nrho, int nz2r,
-		 int nfrho, int nr, const int nlocal, const int nall,
-		 const int max_nbors, const int maxspecial, 
-		 const double cell_size, int &gpu_mode, FILE *screen, 
-		 int &fp_size);
+                 int nfrho, int nr, const int nlocal, const int nall,
+                 const int max_nbors, const int maxspecial,
+                 const double cell_size, int &gpu_mode, FILE *screen,
+                 int &fp_size);
 void eam_gpu_clear();
 int** eam_gpu_compute_n(const int ago, const int inum_full, const int nall,
-			double **host_x, int *host_type, double *sublo,
-			double *subhi, int *tag, int **nspecial, int **special,
-			const bool eflag, const bool vflag, const bool eatom,
-			const bool vatom, int &host_start, int **ilist,
-			int **jnum,  const double cpu_time, bool &success,
-			int &inum, void **fp_ptr);
-void eam_gpu_compute(const int ago, const int inum_full, const int nlocal, 
-		     const int nall,double **host_x, int *host_type, 
-		     int *ilist, int *numj, int **firstneigh, 
-		     const bool eflag, const bool vflag,
-		     const bool eatom, const bool vatom, int &host_start,
-		     const double cpu_time, bool &success, void **fp_ptr);
+                        double **host_x, int *host_type, double *sublo,
+                        double *subhi, int *tag, int **nspecial, int **special,
+                        const bool eflag, const bool vflag, const bool eatom,
+                        const bool vatom, int &host_start, int **ilist,
+                        int **jnum,  const double cpu_time, bool &success,
+                        int &inum, void **fp_ptr);
+void eam_gpu_compute(const int ago, const int inum_full, const int nlocal,
+                     const int nall,double **host_x, int *host_type,
+                     int *ilist, int *numj, int **firstneigh,
+                     const bool eflag, const bool vflag,
+                     const bool eatom, const bool vatom, int &host_start,
+                     const double cpu_time, bool &success, void **fp_ptr);
 void eam_gpu_compute_force(int *ilist, const bool eflag, const bool vflag,
-			   const bool eatom, const bool vatom);
+                           const bool eatom, const bool vatom);
 double eam_gpu_bytes();
 
 /* ---------------------------------------------------------------------- */
 
 PairEAMGPU::PairEAMGPU(LAMMPS *lmp) : PairEAM(lmp), gpu_mode(GPU_FORCE)
 {
   respa_enable = 0;
   cpu_time = 0.0;
-  GPU_EXTRA::gpu_ready(lmp->modify, lmp->error); 
+  GPU_EXTRA::gpu_ready(lmp->modify, lmp->error);
 }
 
 /* ----------------------------------------------------------------------
    check if allocated, since class can be destructed when incomplete
 ------------------------------------------------------------------------- */
 
 PairEAMGPU::~PairEAMGPU()
 {
   eam_gpu_clear();
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairEAMGPU::memory_usage()
 {
   double bytes = Pair::memory_usage();
   return bytes + eam_gpu_bytes();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairEAMGPU::compute(int eflag, int vflag)
 {
   int i,j,ii,jj,m,jnum,itype,jtype;
   double evdwl,*coeff;
 
   evdwl = 0.0;
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = eflag_global = eflag_atom = 0;
- 
+
   int nlocal = atom->nlocal;
   int newton_pair = force->newton_pair;
 
   // compute density on each atom on GPU
 
-  int nall = atom->nlocal + atom->nghost;  
+  int nall = atom->nlocal + atom->nghost;
   int inum, host_start, inum_dev;
-  
+
   bool success = true;
-  int *ilist, *numneigh, **firstneigh; 
-  if (gpu_mode != GPU_FORCE) { 
+  int *ilist, *numneigh, **firstneigh;
+  if (gpu_mode != GPU_FORCE) {
     inum = atom->nlocal;
     firstneigh = eam_gpu_compute_n(neighbor->ago, inum, nall, atom->x,
-				   atom->type, domain->sublo, domain->subhi,
-				   atom->tag, atom->nspecial, atom->special,
-				   eflag, vflag, eflag_atom, vflag_atom,
-				   host_start, &ilist, &numneigh, cpu_time,
-				   success, inum_dev, &fp_pinned);
+                                   atom->type, domain->sublo, domain->subhi,
+                                   atom->tag, atom->nspecial, atom->special,
+                                   eflag, vflag, eflag_atom, vflag_atom,
+                                   host_start, &ilist, &numneigh, cpu_time,
+                                   success, inum_dev, &fp_pinned);
   } else { // gpu_mode == GPU_FORCE
     inum = list->inum;
     ilist = list->ilist;
     numneigh = list->numneigh;
     firstneigh = list->firstneigh;
     eam_gpu_compute(neighbor->ago, inum, nlocal, nall, atom->x, atom->type,
-		    ilist, numneigh, firstneigh, eflag, vflag, eflag_atom,
-		    vflag_atom, host_start, cpu_time, success, &fp_pinned);
+                    ilist, numneigh, firstneigh, eflag, vflag, eflag_atom,
+                    vflag_atom, host_start, cpu_time, success, &fp_pinned);
   }
-    
+
   if (!success)
     error->one(FLERR,"Insufficient memory on accelerator");
 
   // communicate derivative of embedding function
 
   comm->forward_comm_pair(this);
-    
+
   // compute forces on each atom on GPU
-  if (gpu_mode != GPU_FORCE) 
+  if (gpu_mode != GPU_FORCE)
     eam_gpu_compute_force(NULL, eflag, vflag, eflag_atom, vflag_atom);
   else
     eam_gpu_compute_force(ilist, eflag, vflag, eflag_atom, vflag_atom);
 }
 
 /* ----------------------------------------------------------------------
    init specific to this pair style
 ------------------------------------------------------------------------- */
 
 void PairEAMGPU::init_style()
 {
-  if (force->newton_pair) 
+  if (force->newton_pair)
     error->all(FLERR,"Cannot use newton pair with eam/gpu pair style");
-  
+
   // convert read-in file(s) to arrays and spline them
 
   file2array();
   array2spline();
-  
+
   // Repeat cutsq calculation because done after call to init_style
   double maxcut = -1.0;
   double cut;
   for (int i = 1; i <= atom->ntypes; i++) {
     for (int j = i; j <= atom->ntypes; j++) {
       if (setflag[i][j] != 0 || (setflag[i][i] != 0 && setflag[j][j] != 0)) {
         cut = init_one(i,j);
         cut *= cut;
         if (cut > maxcut)
           maxcut = cut;
         cutsq[i][j] = cutsq[j][i] = cut;
       } else
         cutsq[i][j] = cutsq[j][i] = 0.0;
     }
   }
   double cell_size = sqrt(maxcut) + neighbor->skin;
-  
+
   int maxspecial=0;
   if (atom->molecular)
     maxspecial=atom->maxspecial;
   int fp_size;
   int success = eam_gpu_init(atom->ntypes+1, cutforcesq, type2rhor, type2z2r,
-			     type2frho, rhor_spline, z2r_spline, frho_spline,
-			     rdr, rdrho, nrhor, nrho, nz2r, nfrho, nr,
-			     atom->nlocal, atom->nlocal+atom->nghost, 300,
-			     maxspecial, cell_size, gpu_mode, screen, fp_size);
+                             type2frho, rhor_spline, z2r_spline, frho_spline,
+                             rdr, rdrho, nrhor, nrho, nz2r, nfrho, nr,
+                             atom->nlocal, atom->nlocal+atom->nghost, 300,
+                             maxspecial, cell_size, gpu_mode, screen, fp_size);
   GPU_EXTRA::check_flag(success,error,world);
-  
+
   if (gpu_mode == GPU_FORCE) {
     int irequest = neighbor->request(this);
     neighbor->requests[irequest]->half = 0;
     neighbor->requests[irequest]->full = 1;
   }
 
   if (fp_size == sizeof(double))
     fp_single = false;
   else
     fp_single = true;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairEAMGPU::single(int i, int j, int itype, int jtype,
-		       double rsq, double factor_coul, double factor_lj,
-		       double &fforce)
+                       double rsq, double factor_coul, double factor_lj,
+                       double &fforce)
 {
   int m;
   double r,p,rhoip,rhojp,z2,z2p,recip,phi,phip,psip;
   double *coeff;
 
   r = sqrt(rsq);
   p = r*rdr + 1.0;
   m = static_cast<int> (p);
   m = MIN(m,nr-1);
   p -= m;
   p = MIN(p,1.0);
-  
+
   coeff = rhor_spline[type2rhor[itype][jtype]][m];
   rhoip = (coeff[0]*p + coeff[1])*p + coeff[2];
   coeff = rhor_spline[type2rhor[jtype][itype]][m];
   rhojp = (coeff[0]*p + coeff[1])*p + coeff[2];
   coeff = z2r_spline[type2z2r[itype][jtype]][m];
   z2p = (coeff[0]*p + coeff[1])*p + coeff[2];
   z2 = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
-  
+
   double fp_i,fp_j;
   if (fp_single == false) {
     fp_i = ((double*)fp_pinned)[i];
     fp_j = ((double*)fp_pinned)[j];
   } else {
     fp_i = ((float*)fp_pinned)[i];
     fp_j = ((float*)fp_pinned)[j];
   }
-     
+
   recip = 1.0/r;
   phi = z2*recip;
   phip = z2p*recip - phi*recip;
   psip = fp_i*rhojp + fp_j*rhoip + phip;
   fforce = -psip*recip;
-  
+
   return phi;
 }
 
 /* ---------------------------------------------------------------------- */
 
-int PairEAMGPU::pack_comm(int n, int *list, double *buf, int pbc_flag, 
-			  int *pbc)
+int PairEAMGPU::pack_comm(int n, int *list, double *buf, int pbc_flag,
+                          int *pbc)
 {
   int i,j,m;
 
   m = 0;
 
   if (fp_single) {
     float *fp_ptr = (float *)fp_pinned;
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = static_cast<double>(fp_ptr[j]);
     }
   } else {
     double *fp_ptr = (double *)fp_pinned;
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = fp_ptr[j];
     }
   }
 
   return 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairEAMGPU::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   if (fp_single) {
     float *fp_ptr = (float *)fp_pinned;
     for (i = first; i < last; i++) fp_ptr[i] = buf[m++];
   } else {
     double *fp_ptr = (double *)fp_pinned;
     for (i = first; i < last; i++) fp_ptr[i] = buf[m++];
   }
 }
diff --git a/src/GPU/pair_eam_gpu.h b/src/GPU/pair_eam_gpu.h
index 3b48c6b37..8766e5a5b 100644
--- a/src/GPU/pair_eam_gpu.h
+++ b/src/GPU/pair_eam_gpu.h
@@ -1,67 +1,67 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #ifdef PAIR_CLASS
 
 PairStyle(eam/gpu,PairEAMGPU)
 
 #else
 
 #ifndef LMP_PAIR_EAM_GPU_H
 #define LMP_PAIR_EAM_GPU_H
 
 #include "stdio.h"
 #include "pair_eam.h"
 
 namespace LAMMPS_NS {
 
 class PairEAMGPU : public PairEAM {
  public:
 
   PairEAMGPU(class LAMMPS *);
   virtual ~PairEAMGPU();
   void compute(int, int);
   void init_style();
   double single(int, int, int, int, double, double, double, double &);
   double memory_usage();
 
   int pack_comm(int, int *, double *, int, int *);
   void unpack_comm(int, int, double *);
 
  enum { GPU_FORCE, GPU_NEIGH, GPU_HYB_NEIGH };
 
  protected:
   int gpu_mode;
   double cpu_time;
   int *gpulist;
   void *fp_pinned;
-  bool fp_single;  
+  bool fp_single;
 };
 
 }
 
 #endif
 #endif
 
 /* ERROR/WARNING messages:
 
 E: Insufficient memory on accelerator
 
 There is insufficient memory on one of the devices specified for the gpu
 package
 
 E: Cannot use newton pair with eam/gpu pair style
 
 Self-explanatory.
 
 */
diff --git a/src/GRANULAR/pair_gran_hertz_history.cpp b/src/GRANULAR/pair_gran_hertz_history.cpp
index 9b8cca362..9960df2c8 100644
--- a/src/GRANULAR/pair_gran_hertz_history.cpp
+++ b/src/GRANULAR/pair_gran_hertz_history.cpp
@@ -1,456 +1,456 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: Leo Silbert (SNL), Gary Grest (SNL)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "stdio.h"
 #include "string.h"
 #include "pair_gran_hertz_history.h"
 #include "atom.h"
 #include "update.h"
 #include "force.h"
 #include "fix_rigid.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "comm.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 PairGranHertzHistory::PairGranHertzHistory(LAMMPS *lmp) :
   PairGranHookeHistory(lmp) {}
 
 /* ---------------------------------------------------------------------- */
 
 void PairGranHertzHistory::compute(int eflag, int vflag)
 {
   int i,j,ii,jj,inum,jnum,itype,jtype;
   double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz;
   double radi,radj,radsum,rsq,r,rinv,rsqinv;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3;
   double wr1,wr2,wr3;
   double vtr1,vtr2,vtr3,vrel;
   double mi,mj,meff,damp,ccel,tor1,tor2,tor3;
   double fn,fs,fs1,fs2,fs3;
   double shrmag,rsht,polyhertz;
   int *ilist,*jlist,*numneigh,**firstneigh;
   int *touch,**firsttouch;
   double *shear,*allshear,**firstshear;
 
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = 0;
 
   computeflag = 1;
   int shearupdate = 1;
   if (update->setupflag) shearupdate = 0;
 
   // update body ptr and values for ghost atoms if using FixRigid masses
 
   if (fix_rigid && neighbor->ago == 0) {
     body = fix_rigid->body;
     comm->forward_comm_pair(this);
   }
 
   double **x = atom->x;
   double **v = atom->v;
   double **f = atom->f;
   double **omega = atom->omega;
   double **torque = atom->torque;
   double *radius = atom->radius;
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
   int nlocal = atom->nlocal;
 
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
   firsttouch = list->listgranhistory->firstneigh;
   firstshear = list->listgranhistory->firstdouble;
 
   // loop over neighbors of my atoms
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
     radi = radius[i];
     touch = firsttouch[i];
     allshear = firstshear[i];
     jlist = firstneigh[i];
     jnum = numneigh[i];
 
     for (jj = 0; jj < jnum; jj++) {
       j = jlist[jj];
       j &= NEIGHMASK;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
       radj = radius[j];
       radsum = radi + radj;
 
       if (rsq >= radsum*radsum) {
 
         // unset non-touching neighbors
 
         touch[jj] = 0;
         shear = &allshear[3*jj];
         shear[0] = 0.0;
         shear[1] = 0.0;
         shear[2] = 0.0;
 
       } else {
         r = sqrt(rsq);
         rinv = 1.0/r;
         rsqinv = 1.0/rsq;
 
         // relative translational velocity
 
         vr1 = v[i][0] - v[j][0];
         vr2 = v[i][1] - v[j][1];
         vr3 = v[i][2] - v[j][2];
 
         // normal component
 
         vnnr = vr1*delx + vr2*dely + vr3*delz;
         vn1 = delx*vnnr * rsqinv;
         vn2 = dely*vnnr * rsqinv;
         vn3 = delz*vnnr * rsqinv;
 
         // tangential component
 
         vt1 = vr1 - vn1;
         vt2 = vr2 - vn2;
         vt3 = vr3 - vn3;
 
         // relative rotational velocity
 
         wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
         wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
         wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
         // meff = effective mass of pair of particles
         // if I or J part of rigid body, use body mass
         // if I or J is frozen, meff is other particle
 
         if (rmass) {
           mi = rmass[i];
           mj = rmass[j];
         } else {
           mi = mass[type[i]];
           mj = mass[type[j]];
         }
         if (fix_rigid) {
           if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
           if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
         }
 
         meff = mi*mj / (mi+mj);
         if (mask[i] & freeze_group_bit) meff = mj;
         if (mask[j] & freeze_group_bit) meff = mi;
 
         // normal force = Hertzian contact + normal velocity damping
 
         damp = meff*gamman*vnnr*rsqinv;
         ccel = kn*(radsum-r)*rinv - damp;
         polyhertz = sqrt((radsum-r)*radi*radj / radsum);
         ccel *= polyhertz;
 
         // relative velocities
 
         vtr1 = vt1 - (delz*wr2-dely*wr3);
         vtr2 = vt2 - (delx*wr3-delz*wr1);
         vtr3 = vt3 - (dely*wr1-delx*wr2);
         vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
         vrel = sqrt(vrel);
 
         // shear history effects
 
         touch[jj] = 1;
         shear = &allshear[3*jj];
         if (shearupdate) {
           shear[0] += vtr1*dt;
           shear[1] += vtr2*dt;
           shear[2] += vtr3*dt;
         }
         shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] +
                       shear[2]*shear[2]);
 
         // rotate shear displacements
 
         rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz;
         rsht *= rsqinv;
         if (shearupdate) {
           shear[0] -= rsht*delx;
           shear[1] -= rsht*dely;
           shear[2] -= rsht*delz;
         }
 
         // tangential forces = shear + tangential velocity damping
 
         fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1);
         fs2 = -polyhertz * (kt*shear[1] + meff*gammat*vtr2);
         fs3 = -polyhertz * (kt*shear[2] + meff*gammat*vtr3);
 
         // rescale frictional displacements and forces if needed
 
         fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3);
         fn = xmu * fabs(ccel*r);
 
         if (fs > fn) {
           if (shrmag != 0.0) {
             shear[0] = (fn/fs) * (shear[0] + meff*gammat*vtr1/kt) -
               meff*gammat*vtr1/kt;
             shear[1] = (fn/fs) * (shear[1] + meff*gammat*vtr2/kt) -
               meff*gammat*vtr2/kt;
             shear[2] = (fn/fs) * (shear[2] + meff*gammat*vtr3/kt) -
               meff*gammat*vtr3/kt;
             fs1 *= fn/fs;
             fs2 *= fn/fs;
             fs3 *= fn/fs;
           } else fs1 = fs2 = fs3 = 0.0;
         }
 
         // forces & torques
 
         fx = delx*ccel + fs1;
         fy = dely*ccel + fs2;
         fz = delz*ccel + fs3;
         f[i][0] += fx;
         f[i][1] += fy;
         f[i][2] += fz;
 
         tor1 = rinv * (dely*fs3 - delz*fs2);
         tor2 = rinv * (delz*fs1 - delx*fs3);
         tor3 = rinv * (delx*fs2 - dely*fs1);
         torque[i][0] -= radi*tor1;
         torque[i][1] -= radi*tor2;
         torque[i][2] -= radi*tor3;
 
         if (j < nlocal) {
           f[j][0] -= fx;
           f[j][1] -= fy;
           f[j][2] -= fz;
           torque[j][0] -= radj*tor1;
           torque[j][1] -= radj*tor2;
           torque[j][2] -= radj*tor3;
         }
 
         if (evflag) ev_tally_xyz(i,j,nlocal,0,
                                  0.0,0.0,fx,fy,fz,delx,dely,delz);
       }
     }
   }
 }
 
 /* ----------------------------------------------------------------------
    global settings
 ------------------------------------------------------------------------- */
 
 void PairGranHertzHistory::settings(int narg, char **arg)
 {
   if (narg != 6) error->all(FLERR,"Illegal pair_style command");
 
   kn = force->numeric(arg[0]);
   if (strcmp(arg[1],"NULL") == 0) kt = kn * 2.0/7.0;
   else kt = force->numeric(arg[1]);
 
   gamman = force->numeric(arg[2]);
   if (strcmp(arg[3],"NULL") == 0) gammat = 0.5 * gamman;
   else gammat = force->numeric(arg[3]);
 
   xmu = force->numeric(arg[4]);
   dampflag = force->inumeric(arg[5]);
   if (dampflag == 0) gammat = 0.0;
 
   if (kn < 0.0 || kt < 0.0 || gamman < 0.0 || gammat < 0.0 ||
       xmu < 0.0 || xmu > 1.0 || dampflag < 0 || dampflag > 1)
     error->all(FLERR,"Illegal pair_style command");
 
   // convert Kn and Kt from pressure units to force/distance^2
 
   kn /= force->nktv2p;
   kt /= force->nktv2p;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairGranHertzHistory::single(int i, int j, int itype, int jtype,
                                     double rsq,
                                     double factor_coul, double factor_lj,
                                     double &fforce)
 {
   double radi,radj,radsum;
   double r,rinv,rsqinv,delx,dely,delz;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3;
   double mi,mj,meff,damp,ccel,polyhertz;
   double vtr1,vtr2,vtr3,vrel,shrmag,rsht;
   double fs1,fs2,fs3,fs,fn;
 
   double *radius = atom->radius;
   radi = radius[i];
   radj = radius[j];
   radsum = radi + radj;
 
   if (rsq >= radsum*radsum) {
     fforce = 0.0;
     svector[0] = svector[1] = svector[2] = svector[3] = 0.0;
     return 0.0;
   }
 
   r = sqrt(rsq);
   rinv = 1.0/r;
   rsqinv = 1.0/rsq;
 
   // relative translational velocity
 
   double **v = atom->v;
   vr1 = v[i][0] - v[j][0];
   vr2 = v[i][1] - v[j][1];
   vr3 = v[i][2] - v[j][2];
 
   // normal component
 
   double **x = atom->x;
   delx = x[i][0] - x[j][0];
   dely = x[i][1] - x[j][1];
   delz = x[i][2] - x[j][2];
 
   vnnr = vr1*delx + vr2*dely + vr3*delz;
   vn1 = delx*vnnr * rsqinv;
   vn2 = dely*vnnr * rsqinv;
   vn3 = delz*vnnr * rsqinv;
 
   // tangential component
 
   vt1 = vr1 - vn1;
   vt2 = vr2 - vn2;
   vt3 = vr3 - vn3;
 
   // relative rotational velocity
 
   double **omega = atom->omega;
   wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
   wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
   wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
   // meff = effective mass of pair of particles
   // if I or J part of rigid body, use body mass
   // if I or J is frozen, meff is other particle
 
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
 
   if (rmass) {
     mi = rmass[i];
     mj = rmass[j];
   } else {
     mi = mass[type[i]];
     mj = mass[type[j]];
   }
   if (fix_rigid) {
     // NOTE: need to make sure ghost atoms have updated body?
     // depends on where single() is called from
     body = fix_rigid->body;
     if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
     if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
   }
-  
+
   meff = mi*mj / (mi+mj);
   if (mask[i] & freeze_group_bit) meff = mj;
   if (mask[j] & freeze_group_bit) meff = mi;
 
 
   // normal force = Hertzian contact + normal velocity damping
 
   damp = meff*gamman*vnnr*rsqinv;
   ccel = kn*(radsum-r)*rinv - damp;
   polyhertz = sqrt((radsum-r)*radi*radj / radsum);
   ccel *= polyhertz;
 
   // relative velocities
 
   vtr1 = vt1 - (delz*wr2-dely*wr3);
   vtr2 = vt2 - (delx*wr3-delz*wr1);
   vtr3 = vt3 - (dely*wr1-delx*wr2);
   vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
   vrel = sqrt(vrel);
 
   // shear history effects
   // neighprev = index of found neigh on previous call
   // search entire jnum list of neighbors of I for neighbor J
   // start from neighprev, since will typically be next neighbor
   // reset neighprev to 0 as necessary
 
   int *jlist = list->firstneigh[i];
   int jnum = list->numneigh[i];
   int *touch = list->listgranhistory->firstneigh[i];
   double *allshear = list->listgranhistory->firstdouble[i];
 
   for (int jj = 0; jj < jnum; jj++) {
     neighprev++;
     if (neighprev >= jnum) neighprev = 0;
     if (touch[neighprev] == j) break;
   }
 
   double *shear = &allshear[3*neighprev];
   shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] +
                 shear[2]*shear[2]);
 
   // rotate shear displacements
 
   rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz;
   rsht *= rsqinv;
 
   // tangential forces = shear + tangential velocity damping
 
   fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1);
   fs2 = -polyhertz * (kt*shear[1] + meff*gammat*vtr2);
   fs3 = -polyhertz * (kt*shear[2] + meff*gammat*vtr3);
 
   // rescale frictional displacements and forces if needed
 
   fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3);
   fn = xmu * fabs(ccel*r);
 
   if (fs > fn) {
     if (shrmag != 0.0) {
       fs1 *= fn/fs;
       fs2 *= fn/fs;
       fs3 *= fn/fs;
       fs *= fn/fs;
     } else fs1 = fs2 = fs3 = fs = 0.0;
   }
 
   // set all forces and return no energy
 
   fforce = ccel;
   svector[0] = fs1;
   svector[1] = fs2;
   svector[2] = fs3;
   svector[3] = fs;
   return 0.0;
 }
diff --git a/src/GRANULAR/pair_gran_hooke.cpp b/src/GRANULAR/pair_gran_hooke.cpp
index 6e3fddbe1..88075420b 100644
--- a/src/GRANULAR/pair_gran_hooke.cpp
+++ b/src/GRANULAR/pair_gran_hooke.cpp
@@ -1,333 +1,333 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: Leo Silbert (SNL), Gary Grest (SNL)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "string.h"
 #include "pair_gran_hooke.h"
 #include "atom.h"
 #include "force.h"
 #include "fix_rigid.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "comm.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 PairGranHooke::PairGranHooke(LAMMPS *lmp) : PairGranHookeHistory(lmp)
 {
   no_virial_fdotr_compute = 0;
   history = 0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairGranHooke::compute(int eflag, int vflag)
 {
   int i,j,ii,jj,inum,jnum,itype,jtype;
   double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz;
   double radi,radj,radsum,rsq,r,rinv,rsqinv;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3;
   double wr1,wr2,wr3;
   double vtr1,vtr2,vtr3,vrel;
   double mi,mj,meff,damp,ccel,tor1,tor2,tor3;
   double fn,fs,ft,fs1,fs2,fs3;
   int *ilist,*jlist,*numneigh,**firstneigh;
 
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = 0;
 
   // update body ptr and values for ghost atoms if using FixRigid masses
 
   if (fix_rigid && neighbor->ago == 0) {
     body = fix_rigid->body;
     comm->forward_comm_pair(this);
   }
 
   double **x = atom->x;
   double **v = atom->v;
   double **f = atom->f;
   double **omega = atom->omega;
   double **torque = atom->torque;
   double *radius = atom->radius;
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
   int nlocal = atom->nlocal;
   int newton_pair = force->newton_pair;
 
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   // loop over neighbors of my atoms
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
     radi = radius[i];
     jlist = firstneigh[i];
     jnum = numneigh[i];
 
     for (jj = 0; jj < jnum; jj++) {
       j = jlist[jj];
       j &= NEIGHMASK;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
       radj = radius[j];
       radsum = radi + radj;
 
       if (rsq < radsum*radsum) {
         r = sqrt(rsq);
         rinv = 1.0/r;
         rsqinv = 1.0/rsq;
 
         // relative translational velocity
 
         vr1 = v[i][0] - v[j][0];
         vr2 = v[i][1] - v[j][1];
         vr3 = v[i][2] - v[j][2];
 
         // normal component
 
         vnnr = vr1*delx + vr2*dely + vr3*delz;
         vn1 = delx*vnnr * rsqinv;
         vn2 = dely*vnnr * rsqinv;
         vn3 = delz*vnnr * rsqinv;
 
         // tangential component
 
         vt1 = vr1 - vn1;
         vt2 = vr2 - vn2;
         vt3 = vr3 - vn3;
 
         // relative rotational velocity
 
         wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
         wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
         wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
         // meff = effective mass of pair of particles
         // if I or J part of rigid body, use body mass
         // if I or J is frozen, meff is other particle
 
         if (rmass) {
           mi = rmass[i];
           mj = rmass[j];
         } else {
           mi = mass[type[i]];
           mj = mass[type[j]];
         }
         if (fix_rigid) {
           if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
           if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
         }
 
         meff = mi*mj / (mi+mj);
         if (mask[i] & freeze_group_bit) meff = mj;
         if (mask[j] & freeze_group_bit) meff = mi;
 
         // normal forces = Hookian contact + normal velocity damping
 
         damp = meff*gamman*vnnr*rsqinv;
         ccel = kn*(radsum-r)*rinv - damp;
 
         // relative velocities
 
         vtr1 = vt1 - (delz*wr2-dely*wr3);
         vtr2 = vt2 - (delx*wr3-delz*wr1);
         vtr3 = vt3 - (dely*wr1-delx*wr2);
         vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
         vrel = sqrt(vrel);
 
         // force normalization
 
         fn = xmu * fabs(ccel*r);
         fs = meff*gammat*vrel;
         if (vrel != 0.0) ft = MIN(fn,fs) / vrel;
         else ft = 0.0;
 
         // tangential force due to tangential velocity damping
 
         fs1 = -ft*vtr1;
         fs2 = -ft*vtr2;
         fs3 = -ft*vtr3;
 
         // forces & torques
 
         fx = delx*ccel + fs1;
         fy = dely*ccel + fs2;
         fz = delz*ccel + fs3;
         f[i][0] += fx;
         f[i][1] += fy;
         f[i][2] += fz;
 
         tor1 = rinv * (dely*fs3 - delz*fs2);
         tor2 = rinv * (delz*fs1 - delx*fs3);
         tor3 = rinv * (delx*fs2 - dely*fs1);
         torque[i][0] -= radi*tor1;
         torque[i][1] -= radi*tor2;
         torque[i][2] -= radi*tor3;
 
         if (newton_pair || j < nlocal) {
           f[j][0] -= fx;
           f[j][1] -= fy;
           f[j][2] -= fz;
           torque[j][0] -= radj*tor1;
           torque[j][1] -= radj*tor2;
           torque[j][2] -= radj*tor3;
         }
 
         if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,
                                  0.0,0.0,fx,fy,fz,delx,dely,delz);
       }
     }
   }
 
   if (vflag_fdotr) virial_fdotr_compute();
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairGranHooke::single(int i, int j, int itype, int jtype, double rsq,
                              double factor_coul, double factor_lj,
                              double &fforce)
 {
   double radi,radj,radsum,r,rinv,rsqinv;
   double delx,dely,delz;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3;
   double vtr1,vtr2,vtr3,vrel;
   double mi,mj,meff,damp,ccel;
   double fn,fs,ft,fs1,fs2,fs3;
 
   double *radius = atom->radius;
   radi = radius[i];
   radj = radius[j];
   radsum = radi + radj;
 
   // zero out forces if caller requests non-touching pair outside cutoff
 
   if (rsq >= radsum*radsum) {
     fforce = 0.0;
     svector[0] = svector[1] = svector[2] = svector[3] = 0.0;
     return 0.0;
   }
 
   r = sqrt(rsq);
   rinv = 1.0/r;
   rsqinv = 1.0/rsq;
 
   // relative translational velocity
 
   double **v = atom->v;
   vr1 = v[i][0] - v[j][0];
   vr2 = v[i][1] - v[j][1];
   vr3 = v[i][2] - v[j][2];
 
   // normal component
 
   double **x = atom->x;
   delx = x[i][0] - x[j][0];
   dely = x[i][1] - x[j][1];
   delz = x[i][2] - x[j][2];
 
   vnnr = vr1*delx + vr2*dely + vr3*delz;
   vn1 = delx*vnnr * rsqinv;
   vn2 = dely*vnnr * rsqinv;
   vn3 = delz*vnnr * rsqinv;
 
   // tangential component
 
   vt1 = vr1 - vn1;
   vt2 = vr2 - vn2;
   vt3 = vr3 - vn3;
 
   // relative rotational velocity
 
   double **omega = atom->omega;
   wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
   wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
   wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
   // meff = effective mass of pair of particles
   // if I or J part of rigid body, use body mass
   // if I or J is frozen, meff is other particle
 
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
 
   if (rmass) {
     mi = rmass[i];
     mj = rmass[j];
   } else {
     mi = mass[type[i]];
     mj = mass[type[j]];
   }
   if (fix_rigid) {
     // NOTE: need to make sure ghost atoms have updated body?
     // depends on where single() is called from
     body = fix_rigid->body;
     if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
     if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
   }
-  
+
   meff = mi*mj / (mi+mj);
   if (mask[i] & freeze_group_bit) meff = mj;
   if (mask[j] & freeze_group_bit) meff = mi;
 
   // normal forces = Hookian contact + normal velocity damping
 
   damp = meff*gamman*vnnr*rsqinv;
   ccel = kn*(radsum-r)*rinv - damp;
 
   // relative velocities
 
   vtr1 = vt1 - (delz*wr2-dely*wr3);
   vtr2 = vt2 - (delx*wr3-delz*wr1);
   vtr3 = vt3 - (dely*wr1-delx*wr2);
   vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
   vrel = sqrt(vrel);
 
   // force normalization
 
   fn = xmu * fabs(ccel*r);
   fs = meff*gammat*vrel;
   if (vrel != 0.0) ft = MIN(fn,fs) / vrel;
   else ft = 0.0;
 
   // set all forces and return no energy
 
   fforce = ccel;
   svector[0] = -ft*vtr1;
   svector[1] = -ft*vtr2;
   svector[2] = -ft*vtr3;
   svector[3] = sqrt(svector[0]*svector[0] +
                     svector[1]*svector[1] +
                     svector[2]*svector[2]);
   return 0.0;
 }
diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp
index c7cd3ad3f..1ac57ee2e 100644
--- a/src/GRANULAR/pair_gran_hooke_history.cpp
+++ b/src/GRANULAR/pair_gran_hooke_history.cpp
@@ -1,769 +1,769 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: Leo Silbert (SNL), Gary Grest (SNL)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "string.h"
 #include "pair_gran_hooke_history.h"
 #include "atom.h"
 #include "atom_vec.h"
 #include "domain.h"
 #include "force.h"
 #include "update.h"
 #include "modify.h"
 #include "fix.h"
 #include "fix_pour.h"
 #include "fix_shear_history.h"
 #include "fix_rigid.h"
 #include "comm.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp)
 {
   single_enable = 1;
   no_virial_fdotr_compute = 1;
   history = 1;
   fix_history = NULL;
   suffix = NULL;
 
   single_extra = 4;
   svector = new double[4];
 
   computeflag = 0;
   neighprev = 0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 PairGranHookeHistory::~PairGranHookeHistory()
 {
   delete [] svector;
   if (fix_history) modify->delete_fix("SHEAR_HISTORY");
   if (suffix) delete[] suffix;
 
   if (allocated) {
     memory->destroy(setflag);
     memory->destroy(cutsq);
 
     delete [] onerad_dynamic;
     delete [] onerad_frozen;
     delete [] maxrad_dynamic;
     delete [] maxrad_frozen;
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairGranHookeHistory::compute(int eflag, int vflag)
 {
   int i,j,ii,jj,inum,jnum,itype,jtype;
   double xtmp,ytmp,ztmp,delx,dely,delz,fx,fy,fz;
   double radi,radj,radsum,rsq,r,rinv,rsqinv;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3;
   double wr1,wr2,wr3;
   double vtr1,vtr2,vtr3,vrel;
   double mi,mj,meff,damp,ccel,tor1,tor2,tor3;
   double fn,fs,fs1,fs2,fs3;
   double shrmag,rsht;
   int *ilist,*jlist,*numneigh,**firstneigh;
   int *touch,**firsttouch;
   double *shear,*allshear,**firstshear;
 
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = 0;
 
   computeflag = 1;
   int shearupdate = 1;
   if (update->setupflag) shearupdate = 0;
 
   // update body ptr and values for ghost atoms if using FixRigid masses
 
   if (fix_rigid && neighbor->ago == 0) {
     body = fix_rigid->body;
     comm->forward_comm_pair(this);
   }
 
   double **x = atom->x;
   double **v = atom->v;
   double **f = atom->f;
   double **omega = atom->omega;
   double **torque = atom->torque;
   double *radius = atom->radius;
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
   int nlocal = atom->nlocal;
 
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
   firsttouch = listgranhistory->firstneigh;
   firstshear = listgranhistory->firstdouble;
 
   // loop over neighbors of my atoms
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
     radi = radius[i];
     touch = firsttouch[i];
     allshear = firstshear[i];
     jlist = firstneigh[i];
     jnum = numneigh[i];
 
     for (jj = 0; jj < jnum; jj++) {
       j = jlist[jj];
       j &= NEIGHMASK;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
       radj = radius[j];
       radsum = radi + radj;
 
       if (rsq >= radsum*radsum) {
 
         // unset non-touching neighbors
 
         touch[jj] = 0;
         shear = &allshear[3*jj];
         shear[0] = 0.0;
         shear[1] = 0.0;
         shear[2] = 0.0;
 
       } else {
         r = sqrt(rsq);
         rinv = 1.0/r;
         rsqinv = 1.0/rsq;
 
         // relative translational velocity
 
         vr1 = v[i][0] - v[j][0];
         vr2 = v[i][1] - v[j][1];
         vr3 = v[i][2] - v[j][2];
 
         // normal component
 
         vnnr = vr1*delx + vr2*dely + vr3*delz;
         vn1 = delx*vnnr * rsqinv;
         vn2 = dely*vnnr * rsqinv;
         vn3 = delz*vnnr * rsqinv;
 
         // tangential component
 
         vt1 = vr1 - vn1;
         vt2 = vr2 - vn2;
         vt3 = vr3 - vn3;
 
         // relative rotational velocity
 
         wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
         wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
         wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
         // meff = effective mass of pair of particles
         // if I or J part of rigid body, use body mass
         // if I or J is frozen, meff is other particle
 
         if (rmass) {
           mi = rmass[i];
           mj = rmass[j];
         } else {
           mi = mass[type[i]];
           mj = mass[type[j]];
         }
         if (fix_rigid) {
           if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
           if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
         }
 
         meff = mi*mj / (mi+mj);
         if (mask[i] & freeze_group_bit) meff = mj;
         if (mask[j] & freeze_group_bit) meff = mi;
 
         // normal forces = Hookian contact + normal velocity damping
 
         damp = meff*gamman*vnnr*rsqinv;
         ccel = kn*(radsum-r)*rinv - damp;
 
         // relative velocities
 
         vtr1 = vt1 - (delz*wr2-dely*wr3);
         vtr2 = vt2 - (delx*wr3-delz*wr1);
         vtr3 = vt3 - (dely*wr1-delx*wr2);
         vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
         vrel = sqrt(vrel);
 
         // shear history effects
 
         touch[jj] = 1;
         shear = &allshear[3*jj];
 
         if (shearupdate) {
           shear[0] += vtr1*dt;
           shear[1] += vtr2*dt;
           shear[2] += vtr3*dt;
         }
         shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] +
                       shear[2]*shear[2]);
 
         // rotate shear displacements
 
         rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz;
         rsht *= rsqinv;
         if (shearupdate) {
           shear[0] -= rsht*delx;
           shear[1] -= rsht*dely;
           shear[2] -= rsht*delz;
         }
 
         // tangential forces = shear + tangential velocity damping
 
         fs1 = - (kt*shear[0] + meff*gammat*vtr1);
         fs2 = - (kt*shear[1] + meff*gammat*vtr2);
         fs3 = - (kt*shear[2] + meff*gammat*vtr3);
 
         // rescale frictional displacements and forces if needed
 
         fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3);
         fn = xmu * fabs(ccel*r);
 
         if (fs > fn) {
           if (shrmag != 0.0) {
             shear[0] = (fn/fs) * (shear[0] + meff*gammat*vtr1/kt) -
               meff*gammat*vtr1/kt;
             shear[1] = (fn/fs) * (shear[1] + meff*gammat*vtr2/kt) -
               meff*gammat*vtr2/kt;
             shear[2] = (fn/fs) * (shear[2] + meff*gammat*vtr3/kt) -
               meff*gammat*vtr3/kt;
             fs1 *= fn/fs;
             fs2 *= fn/fs;
             fs3 *= fn/fs;
           } else fs1 = fs2 = fs3 = 0.0;
         }
 
         // forces & torques
 
         fx = delx*ccel + fs1;
         fy = dely*ccel + fs2;
         fz = delz*ccel + fs3;
         f[i][0] += fx;
         f[i][1] += fy;
         f[i][2] += fz;
 
         tor1 = rinv * (dely*fs3 - delz*fs2);
         tor2 = rinv * (delz*fs1 - delx*fs3);
         tor3 = rinv * (delx*fs2 - dely*fs1);
         torque[i][0] -= radi*tor1;
         torque[i][1] -= radi*tor2;
         torque[i][2] -= radi*tor3;
 
         if (j < nlocal) {
           f[j][0] -= fx;
           f[j][1] -= fy;
           f[j][2] -= fz;
           torque[j][0] -= radj*tor1;
           torque[j][1] -= radj*tor2;
           torque[j][2] -= radj*tor3;
         }
 
         if (evflag) ev_tally_xyz(i,j,nlocal,0,
                                  0.0,0.0,fx,fy,fz,delx,dely,delz);
       }
     }
   }
 }
 
 /* ----------------------------------------------------------------------
    allocate all arrays
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::allocate()
 {
   allocated = 1;
   int n = atom->ntypes;
 
   memory->create(setflag,n+1,n+1,"pair:setflag");
   for (int i = 1; i <= n; i++)
     for (int j = i; j <= n; j++)
       setflag[i][j] = 0;
 
   memory->create(cutsq,n+1,n+1,"pair:cutsq");
 
   onerad_dynamic = new double[n+1];
   onerad_frozen = new double[n+1];
   maxrad_dynamic = new double[n+1];
   maxrad_frozen = new double[n+1];
 }
 
 /* ----------------------------------------------------------------------
    global settings
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::settings(int narg, char **arg)
 {
   if (narg != 6) error->all(FLERR,"Illegal pair_style command");
 
   kn = force->numeric(arg[0]);
   if (strcmp(arg[1],"NULL") == 0) kt = kn * 2.0/7.0;
   else kt = force->numeric(arg[1]);
 
   gamman = force->numeric(arg[2]);
   if (strcmp(arg[3],"NULL") == 0) gammat = 0.5 * gamman;
   else gammat = force->numeric(arg[3]);
 
   xmu = force->numeric(arg[4]);
   dampflag = force->inumeric(arg[5]);
   if (dampflag == 0) gammat = 0.0;
 
   if (kn < 0.0 || kt < 0.0 || gamman < 0.0 || gammat < 0.0 ||
       xmu < 0.0 || xmu > 1.0 || dampflag < 0 || dampflag > 1)
     error->all(FLERR,"Illegal pair_style command");
 }
 
 /* ----------------------------------------------------------------------
    set coeffs for one or more type pairs
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::coeff(int narg, char **arg)
 {
   if (narg > 2) error->all(FLERR,"Incorrect args for pair coefficients");
   if (!allocated) allocate();
 
   int ilo,ihi,jlo,jhi;
   force->bounds(arg[0],atom->ntypes,ilo,ihi);
   force->bounds(arg[1],atom->ntypes,jlo,jhi);
 
   int count = 0;
   for (int i = ilo; i <= ihi; i++) {
     for (int j = MAX(jlo,i); j <= jhi; j++) {
       setflag[i][j] = 1;
       count++;
     }
   }
 
   if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
 }
 
 /* ----------------------------------------------------------------------
    init specific to this pair style
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::init_style()
 {
   int i;
 
   // error and warning checks
 
   if (!atom->sphere_flag)
     error->all(FLERR,"Pair granular requires atom style sphere");
   if (comm->ghost_velocity == 0)
     error->all(FLERR,"Pair granular requires ghost atoms store velocity");
 
   // need a half neigh list and optionally a granular history neigh list
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->half = 0;
   neighbor->requests[irequest]->gran = 1;
   if (history) {
     irequest = neighbor->request(this);
     neighbor->requests[irequest]->id = 1;
     neighbor->requests[irequest]->half = 0;
     neighbor->requests[irequest]->granhistory = 1;
     neighbor->requests[irequest]->dnum = 3;
   }
 
   dt = update->dt;
 
   // if shear history is stored:
   // check if newton flag is valid
   // if first init, create Fix needed for storing shear history
 
   if (history && force->newton_pair == 1)
     error->all(FLERR,
                "Pair granular with shear history requires newton pair off");
 
   if (history && fix_history == NULL) {
     char **fixarg = new char*[3];
     fixarg[0] = (char *) "SHEAR_HISTORY";
     fixarg[1] = (char *) "all";
     fixarg[2] = (char *) "SHEAR_HISTORY";
     modify->add_fix(3,fixarg,suffix);
     delete [] fixarg;
     fix_history = (FixShearHistory *) modify->fix[modify->nfix-1];
     fix_history->pair = this;
   }
 
   // check for FixFreeze and set freeze_group_bit
 
   for (i = 0; i < modify->nfix; i++)
     if (strcmp(modify->fix[i]->style,"freeze") == 0) break;
   if (i < modify->nfix) freeze_group_bit = modify->fix[i]->groupbit;
   else freeze_group_bit = 0;
 
   // check for FixPour and set pour_type and pour_maxdiam
 
   int pour_type = 0;
   double pour_maxrad = 0.0;
   for (i = 0; i < modify->nfix; i++)
     if (strcmp(modify->fix[i]->style,"pour") == 0) break;
   if (i < modify->nfix) {
     pour_type = ((FixPour *) modify->fix[i])->ntype;
     pour_maxrad = ((FixPour *) modify->fix[i])->radius_hi;
   }
 
   // check for FixRigid
 
   fix_rigid = NULL;
   for (i = 0; i < modify->nfix; i++)
     if (strstr(modify->fix[i]->style,"rigid")) break;
   if (i < modify->nfix) fix_rigid = (FixRigid *) modify->fix[i];
 
   // set maxrad_dynamic and maxrad_frozen for each type
   // include future Fix pour particles as dynamic
 
   for (i = 1; i <= atom->ntypes; i++)
     onerad_dynamic[i] = onerad_frozen[i] = 0.0;
   if (pour_type) onerad_dynamic[pour_type] = pour_maxrad;
 
   double *radius = atom->radius;
   int *mask = atom->mask;
   int *type = atom->type;
   int nlocal = atom->nlocal;
 
   for (i = 0; i < nlocal; i++)
     if (mask[i] & freeze_group_bit)
       onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]],radius[i]);
     else
       onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]],radius[i]);
 
   MPI_Allreduce(&onerad_dynamic[1],&maxrad_dynamic[1],atom->ntypes,
                 MPI_DOUBLE,MPI_MAX,world);
   MPI_Allreduce(&onerad_frozen[1],&maxrad_frozen[1],atom->ntypes,
                 MPI_DOUBLE,MPI_MAX,world);
 }
 
 /* ----------------------------------------------------------------------
    neighbor callback to inform pair style of neighbor list to use
    optional granular history list
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::init_list(int id, NeighList *ptr)
 {
   if (id == 0) list = ptr;
   else if (id == 1) listgranhistory = ptr;
 }
 
 /* ----------------------------------------------------------------------
    init for one type pair i,j and corresponding j,i
 ------------------------------------------------------------------------- */
 
 double PairGranHookeHistory::init_one(int i, int j)
 {
   if (!allocated) allocate();
 
   // cutoff = sum of max I,J radii for
   // dynamic/dynamic & dynamic/frozen interactions, but not frozen/frozen
 
   double cutoff = maxrad_dynamic[i]+maxrad_dynamic[j];
   cutoff = MAX(cutoff,maxrad_frozen[i]+maxrad_dynamic[j]);
   cutoff = MAX(cutoff,maxrad_dynamic[i]+maxrad_frozen[j]);
   return cutoff;
 }
 
 /* ----------------------------------------------------------------------
   proc 0 writes to restart file
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::write_restart(FILE *fp)
 {
   write_restart_settings(fp);
 
   int i,j;
   for (i = 1; i <= atom->ntypes; i++)
     for (j = i; j <= atom->ntypes; j++)
       fwrite(&setflag[i][j],sizeof(int),1,fp);
 }
 
 /* ----------------------------------------------------------------------
   proc 0 reads from restart file, bcasts
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::read_restart(FILE *fp)
 {
   read_restart_settings(fp);
   allocate();
 
   int i,j;
   int me = comm->me;
   for (i = 1; i <= atom->ntypes; i++)
     for (j = i; j <= atom->ntypes; j++) {
       if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
       MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
     }
 }
 
 /* ----------------------------------------------------------------------
   proc 0 writes to restart file
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::write_restart_settings(FILE *fp)
 {
   fwrite(&kn,sizeof(double),1,fp);
   fwrite(&kt,sizeof(double),1,fp);
   fwrite(&gamman,sizeof(double),1,fp);
   fwrite(&gammat,sizeof(double),1,fp);
   fwrite(&xmu,sizeof(double),1,fp);
   fwrite(&dampflag,sizeof(int),1,fp);
 }
 
 /* ----------------------------------------------------------------------
   proc 0 reads from restart file, bcasts
 ------------------------------------------------------------------------- */
 
 void PairGranHookeHistory::read_restart_settings(FILE *fp)
 {
   if (comm->me == 0) {
     fread(&kn,sizeof(double),1,fp);
     fread(&kt,sizeof(double),1,fp);
     fread(&gamman,sizeof(double),1,fp);
     fread(&gammat,sizeof(double),1,fp);
     fread(&xmu,sizeof(double),1,fp);
     fread(&dampflag,sizeof(int),1,fp);
   }
   MPI_Bcast(&kn,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&kt,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&gamman,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&gammat,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&xmu,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&dampflag,1,MPI_INT,0,world);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairGranHookeHistory::reset_dt()
 {
   dt = update->dt;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairGranHookeHistory::single(int i, int j, int itype, int jtype,
                                     double rsq,
                                     double factor_coul, double factor_lj,
                                     double &fforce)
 {
   double radi,radj,radsum;
   double r,rinv,rsqinv,delx,dely,delz;
   double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3;
   double mi,mj,meff,damp,ccel,polyhertz;
   double vtr1,vtr2,vtr3,vrel,shrmag,rsht;
   double fs1,fs2,fs3,fs,fn;
-  
+
   double *radius = atom->radius;
   radi = radius[i];
   radj = radius[j];
   radsum = radi + radj;
 
   if (rsq >= radsum*radsum) {
     fforce = 0.0;
     svector[0] = svector[1] = svector[2] = svector[3] = 0.0;
     return 0.0;
   }
 
   r = sqrt(rsq);
   rinv = 1.0/r;
   rsqinv = 1.0/rsq;
 
   // relative translational velocity
 
   double **v = atom->v;
   vr1 = v[i][0] - v[j][0];
   vr2 = v[i][1] - v[j][1];
   vr3 = v[i][2] - v[j][2];
 
   // normal component
 
   double **x = atom->x;
   delx = x[i][0] - x[j][0];
   dely = x[i][1] - x[j][1];
   delz = x[i][2] - x[j][2];
 
   vnnr = vr1*delx + vr2*dely + vr3*delz;
   vn1 = delx*vnnr * rsqinv;
   vn2 = dely*vnnr * rsqinv;
   vn3 = delz*vnnr * rsqinv;
 
   // tangential component
 
   vt1 = vr1 - vn1;
   vt2 = vr2 - vn2;
   vt3 = vr3 - vn3;
 
   // relative rotational velocity
 
   double **omega = atom->omega;
   wr1 = (radi*omega[i][0] + radj*omega[j][0]) * rinv;
   wr2 = (radi*omega[i][1] + radj*omega[j][1]) * rinv;
   wr3 = (radi*omega[i][2] + radj*omega[j][2]) * rinv;
 
   // meff = effective mass of pair of particles
   // if I or J part of rigid body, use body mass
   // if I or J is frozen, meff is other particle
 
   double *rmass = atom->rmass;
   double *mass = atom->mass;
   int *type = atom->type;
   int *mask = atom->mask;
 
   if (rmass) {
     mi = rmass[i];
     mj = rmass[j];
   } else {
     mi = mass[type[i]];
     mj = mass[type[j]];
   }
   if (fix_rigid) {
     // NOTE: need to make sure ghost atoms have updated body?
     // depends on where single() is called from
     body = fix_rigid->body;
     if (body[i] >= 0) mi = fix_rigid->masstotal[body[i]];
     if (body[j] >= 0) mj = fix_rigid->masstotal[body[j]];
   }
-  
+
   meff = mi*mj / (mi+mj);
   if (mask[i] & freeze_group_bit) meff = mj;
   if (mask[j] & freeze_group_bit) meff = mi;
 
   // normal forces = Hookian contact + normal velocity damping
 
   damp = meff*gamman*vnnr*rsqinv;
   ccel = kn*(radsum-r)*rinv - damp;
 
   // relative velocities
 
   vtr1 = vt1 - (delz*wr2-dely*wr3);
   vtr2 = vt2 - (delx*wr3-delz*wr1);
   vtr3 = vt3 - (dely*wr1-delx*wr2);
   vrel = vtr1*vtr1 + vtr2*vtr2 + vtr3*vtr3;
   vrel = sqrt(vrel);
 
   // shear history effects
   // neighprev = index of found neigh on previous call
   // search entire jnum list of neighbors of I for neighbor J
   // start from neighprev, since will typically be next neighbor
   // reset neighprev to 0 as necessary
 
   int *jlist = list->firstneigh[i];
   int jnum = list->numneigh[i];
   int *touch = list->listgranhistory->firstneigh[i];
   double *allshear = list->listgranhistory->firstdouble[i];
 
   for (int jj = 0; jj < jnum; jj++) {
     neighprev++;
     if (neighprev >= jnum) neighprev = 0;
     if (touch[neighprev] == j) break;
   }
 
   double *shear = &allshear[3*neighprev];
   shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] +
                 shear[2]*shear[2]);
 
   // rotate shear displacements
 
   rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz;
   rsht *= rsqinv;
 
   // tangential forces = shear + tangential velocity damping
 
   fs1 = - (kt*shear[0] + meff*gammat*vtr1);
   fs2 = - (kt*shear[1] + meff*gammat*vtr2);
   fs3 = - (kt*shear[2] + meff*gammat*vtr3);
 
   // rescale frictional displacements and forces if needed
 
   fs = sqrt(fs1*fs1 + fs2*fs2 + fs3*fs3);
   fn = xmu * fabs(ccel*r);
 
   if (fs > fn) {
     if (shrmag != 0.0) {
       fs1 *= fn/fs;
       fs2 *= fn/fs;
       fs3 *= fn/fs;
       fs *= fn/fs;
     } else fs1 = fs2 = fs3 = fs = 0.0;
   }
 
   // set all forces and return no energy
 
   fforce = ccel;
   svector[0] = fs1;
   svector[1] = fs2;
   svector[2] = fs3;
   svector[3] = fs;
   return 0.0;
 }
 
 /* ---------------------------------------------------------------------- */
 
-int PairGranHookeHistory::pack_comm(int n, int *list, 
+int PairGranHookeHistory::pack_comm(int n, int *list,
                                     double *buf, int pbc_flag, int *pbc)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = body[j];
   }
   return 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairGranHookeHistory::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     body[i] = static_cast<int> (buf[m++]);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void *PairGranHookeHistory::extract(const char *str, int &dim)
 {
   dim = 0;
   if (strcmp(str,"computeflag") == 0) return (void *) &computeflag;
   return NULL;
 }
diff --git a/src/KSPACE/pair_lj_cut_coul_long.cpp b/src/KSPACE/pair_lj_cut_coul_long.cpp
index c5cfe503a..e83e50e23 100644
--- a/src/KSPACE/pair_lj_cut_coul_long.cpp
+++ b/src/KSPACE/pair_lj_cut_coul_long.cpp
@@ -1,1137 +1,1137 @@
-/* ----------------------------------------------------------------------
-   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
-   http://lammps.sandia.gov, Sandia National Laboratories
-   Steve Plimpton, sjplimp@sandia.gov
-
-   Copyright (2003) Sandia Corporation.  Under the terms of Contract
-   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under
-   the GNU General Public License.
-
-   See the README file in the top-level LAMMPS directory.
-------------------------------------------------------------------------- */
-
-/* ----------------------------------------------------------------------
-   Contributing author: Paul Crozier (SNL)
-------------------------------------------------------------------------- */
-
-#include "math.h"
-#include "stdio.h"
-#include "stdlib.h"
-#include "string.h"
-#include "pair_lj_cut_coul_long.h"
-#include "atom.h"
-#include "comm.h"
-#include "force.h"
-#include "kspace.h"
-#include "update.h"
-#include "integrate.h"
-#include "respa.h"
-#include "neighbor.h"
-#include "neigh_list.h"
-#include "neigh_request.h"
-#include "math_const.h"
-#include "memory.h"
-#include "error.h"
-
-using namespace LAMMPS_NS;
-using namespace MathConst;
-
-#define EWALD_F   1.12837917
-#define EWALD_P   0.3275911
-#define A1        0.254829592
-#define A2       -0.284496736
-#define A3        1.421413741
-#define A4       -1.453152027
-#define A5        1.061405429
-
-/* ---------------------------------------------------------------------- */
-
-PairLJCutCoulLong::PairLJCutCoulLong(LAMMPS *lmp) : Pair(lmp)
-{
-  respa_enable = 1;
-  ftable = NULL;
-  qdist = 0.0;
-}
-
-/* ---------------------------------------------------------------------- */
-
-PairLJCutCoulLong::~PairLJCutCoulLong()
-{
-  if (allocated) {
-    memory->destroy(setflag);
-    memory->destroy(cutsq);
-
-    memory->destroy(cut_lj);
-    memory->destroy(cut_ljsq);
-    memory->destroy(epsilon);
-    memory->destroy(sigma);
-    memory->destroy(lj1);
-    memory->destroy(lj2);
-    memory->destroy(lj3);
-    memory->destroy(lj4);
-    memory->destroy(offset);
-  }
-  if (ftable) free_tables();
-}
-
-/* ---------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::compute(int eflag, int vflag)
-{
-  int i,ii,j,jj,inum,jnum,itype,jtype,itable;
-  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair;
-  double fraction,table;
-  double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
-  double grij,expm2,prefactor,t,erfc;
-  int *ilist,*jlist,*numneigh,**firstneigh;
-  double rsq;
-
-  evdwl = ecoul = 0.0;
-  if (eflag || vflag) ev_setup(eflag,vflag);
-  else evflag = vflag_fdotr = 0;
-
-  double **x = atom->x;
-  double **f = atom->f;
-  double *q = atom->q;
-  int *type = atom->type;
-  int nlocal = atom->nlocal;
-  double *special_coul = force->special_coul;
-  double *special_lj = force->special_lj;
-  int newton_pair = force->newton_pair;
-  double qqrd2e = force->qqrd2e;
-
-  inum = list->inum;
-  ilist = list->ilist;
-  numneigh = list->numneigh;
-  firstneigh = list->firstneigh;
-
-  // loop over neighbors of my atoms
-
-  for (ii = 0; ii < inum; ii++) {
-    i = ilist[ii];
-    qtmp = q[i];
-    xtmp = x[i][0];
-    ytmp = x[i][1];
-    ztmp = x[i][2];
-    itype = type[i];
-    jlist = firstneigh[i];
-    jnum = numneigh[i];
-
-    for (jj = 0; jj < jnum; jj++) {
-      j = jlist[jj];
-      factor_lj = special_lj[sbmask(j)];
-      factor_coul = special_coul[sbmask(j)];
-      j &= NEIGHMASK;
-
-      delx = xtmp - x[j][0];
-      dely = ytmp - x[j][1];
-      delz = ztmp - x[j][2];
-      rsq = delx*delx + dely*dely + delz*delz;
-      jtype = type[j];
-
-      if (rsq < cutsq[itype][jtype]) {
-        r2inv = 1.0/rsq;
-
-        if (rsq < cut_coulsq) {
-          if (!ncoultablebits || rsq <= tabinnersq) {
-            r = sqrt(rsq);
-            grij = g_ewald * r;
-            expm2 = exp(-grij*grij);
-            t = 1.0 / (1.0 + EWALD_P*grij);
-            erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
-            prefactor = qqrd2e * qtmp*q[j]/r;
-            forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
-            if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
-          } else {
-            union_int_float_t rsq_lookup;
-            rsq_lookup.f = rsq;
-            itable = rsq_lookup.i & ncoulmask;
-            itable >>= ncoulshiftbits;
-            fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable];
-            table = ftable[itable] + fraction*dftable[itable];
-            forcecoul = qtmp*q[j] * table;
-            if (factor_coul < 1.0) {
-              table = ctable[itable] + fraction*dctable[itable];
-              prefactor = qtmp*q[j] * table;
-              forcecoul -= (1.0-factor_coul)*prefactor;
-            }
-          }
-        } else forcecoul = 0.0;
-
-        if (rsq < cut_ljsq[itype][jtype]) {
-          r6inv = r2inv*r2inv*r2inv;
-          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-        } else forcelj = 0.0;
-
-        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
-
-        f[i][0] += delx*fpair;
-        f[i][1] += dely*fpair;
-        f[i][2] += delz*fpair;
-        if (newton_pair || j < nlocal) {
-          f[j][0] -= delx*fpair;
-          f[j][1] -= dely*fpair;
-          f[j][2] -= delz*fpair;
-        }
-
-        if (eflag) {
-          if (rsq < cut_coulsq) {
-            if (!ncoultablebits || rsq <= tabinnersq)
-              ecoul = prefactor*erfc;
-            else {
-              table = etable[itable] + fraction*detable[itable];
-              ecoul = qtmp*q[j] * table;
-            }
-            if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
-          } else ecoul = 0.0;
-
-          if (rsq < cut_ljsq[itype][jtype]) {
-            evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
-              offset[itype][jtype];
-            evdwl *= factor_lj;
-          } else evdwl = 0.0;
-        }
-
-        if (evflag) ev_tally(i,j,nlocal,newton_pair,
-                             evdwl,ecoul,fpair,delx,dely,delz);
-      }
-    }
-  }
-
-  if (vflag_fdotr) virial_fdotr_compute();
-}
-
-/* ---------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::compute_inner()
-{
-  int i,j,ii,jj,inum,jnum,itype,jtype;
-  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair;
-  double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
-  double rsw;
-  int *ilist,*jlist,*numneigh,**firstneigh;
-
-  double **x = atom->x;
-  double **f = atom->f;
-  double *q = atom->q;
-  int *type = atom->type;
-  int nlocal = atom->nlocal;
-  double *special_coul = force->special_coul;
-  double *special_lj = force->special_lj;
-  int newton_pair = force->newton_pair;
-  double qqrd2e = force->qqrd2e;
-
-  inum = listinner->inum;
-  ilist = listinner->ilist;
-  numneigh = listinner->numneigh;
-  firstneigh = listinner->firstneigh;
-
-  double cut_out_on = cut_respa[0];
-  double cut_out_off = cut_respa[1];
-
-  double cut_out_diff = cut_out_off - cut_out_on;
-  double cut_out_on_sq = cut_out_on*cut_out_on;
-  double cut_out_off_sq = cut_out_off*cut_out_off;
-
-  // loop over neighbors of my atoms
-
-  for (ii = 0; ii < inum; ii++) {
-    i = ilist[ii];
-    qtmp = q[i];
-    xtmp = x[i][0];
-    ytmp = x[i][1];
-    ztmp = x[i][2];
-    itype = type[i];
-    jlist = firstneigh[i];
-    jnum = numneigh[i];
-
-    for (jj = 0; jj < jnum; jj++) {
-      j = jlist[jj];
-      factor_lj = special_lj[sbmask(j)];
-      factor_coul = special_coul[sbmask(j)];
-      j &= NEIGHMASK;
-
-      delx = xtmp - x[j][0];
-      dely = ytmp - x[j][1];
-      delz = ztmp - x[j][2];
-      rsq = delx*delx + dely*dely + delz*delz;
-
-      if (rsq < cut_out_off_sq) {
-        r2inv = 1.0/rsq;
-        forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv);
-        if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul;
-
-        jtype = type[j];
-        if (rsq < cut_ljsq[itype][jtype]) {
-          r6inv = r2inv*r2inv*r2inv;
-          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-        } else forcelj = 0.0;
-
-        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
-        if (rsq > cut_out_on_sq) {
-          rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff;
-          fpair  *= 1.0 + rsw*rsw*(2.0*rsw-3.0);
-        }
-
-        f[i][0] += delx*fpair;
-        f[i][1] += dely*fpair;
-        f[i][2] += delz*fpair;
-        if (newton_pair || j < nlocal) {
-          f[j][0] -= delx*fpair;
-          f[j][1] -= dely*fpair;
-          f[j][2] -= delz*fpair;
-        }
-      }
-    }
-  }
-}
-
-/* ---------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::compute_middle()
-{
-  int i,j,ii,jj,inum,jnum,itype,jtype;
-  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair;
-  double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
-  double rsw;
-  int *ilist,*jlist,*numneigh,**firstneigh;
-
-  double **x = atom->x;
-  double **f = atom->f;
-  double *q = atom->q;
-  int *type = atom->type;
-  int nlocal = atom->nlocal;
-  double *special_coul = force->special_coul;
-  double *special_lj = force->special_lj;
-  int newton_pair = force->newton_pair;
-  double qqrd2e = force->qqrd2e;
-
-  inum = listmiddle->inum;
-  ilist = listmiddle->ilist;
-  numneigh = listmiddle->numneigh;
-  firstneigh = listmiddle->firstneigh;
-
-  double cut_in_off = cut_respa[0];
-  double cut_in_on = cut_respa[1];
-  double cut_out_on = cut_respa[2];
-  double cut_out_off = cut_respa[3];
-
-  double cut_in_diff = cut_in_on - cut_in_off;
-  double cut_out_diff = cut_out_off - cut_out_on;
-  double cut_in_off_sq = cut_in_off*cut_in_off;
-  double cut_in_on_sq = cut_in_on*cut_in_on;
-  double cut_out_on_sq = cut_out_on*cut_out_on;
-  double cut_out_off_sq = cut_out_off*cut_out_off;
-
-  // loop over neighbors of my atoms
-
-  for (ii = 0; ii < inum; ii++) {
-    i = ilist[ii];
-    qtmp = q[i];
-    xtmp = x[i][0];
-    ytmp = x[i][1];
-    ztmp = x[i][2];
-    itype = type[i];
-    jlist = firstneigh[i];
-    jnum = numneigh[i];
-
-    for (jj = 0; jj < jnum; jj++) {
-      j = jlist[jj];
-      factor_lj = special_lj[sbmask(j)];
-      factor_coul = special_coul[sbmask(j)];
-      j &= NEIGHMASK;
-
-      delx = xtmp - x[j][0];
-      dely = ytmp - x[j][1];
-      delz = ztmp - x[j][2];
-      rsq = delx*delx + dely*dely + delz*delz;
-
-      if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) {
-        r2inv = 1.0/rsq;
-        forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv);
-        if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul;
-
-        jtype = type[j];
-        if (rsq < cut_ljsq[itype][jtype]) {
-          r6inv = r2inv*r2inv*r2inv;
-          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-        } else forcelj = 0.0;
-
-        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
-        if (rsq < cut_in_on_sq) {
-          rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff;
-          fpair *= rsw*rsw*(3.0 - 2.0*rsw);
-        }
-        if (rsq > cut_out_on_sq) {
-          rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff;
-          fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0);
-        }
-
-        f[i][0] += delx*fpair;
-        f[i][1] += dely*fpair;
-        f[i][2] += delz*fpair;
-        if (newton_pair || j < nlocal) {
-          f[j][0] -= delx*fpair;
-          f[j][1] -= dely*fpair;
-          f[j][2] -= delz*fpair;
-        }
-      }
-    }
-  }
-}
-
-/* ---------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::compute_outer(int eflag, int vflag)
-{
-  int i,j,ii,jj,inum,jnum,itype,jtype,itable;
-  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair;
-  double fraction,table;
-  double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
-  double grij,expm2,prefactor,t,erfc;
-  double rsw;
-  int *ilist,*jlist,*numneigh,**firstneigh;
-  double rsq;
-
-  evdwl = ecoul = 0.0;
-  if (eflag || vflag) ev_setup(eflag,vflag);
-  else evflag = 0;
-
-  double **x = atom->x;
-  double **f = atom->f;
-  double *q = atom->q;
-  int *type = atom->type;
-  int nlocal = atom->nlocal;
-  double *special_coul = force->special_coul;
-  double *special_lj = force->special_lj;
-  int newton_pair = force->newton_pair;
-  double qqrd2e = force->qqrd2e;
-
-  inum = listouter->inum;
-  ilist = listouter->ilist;
-  numneigh = listouter->numneigh;
-  firstneigh = listouter->firstneigh;
-
-  double cut_in_off = cut_respa[2];
-  double cut_in_on = cut_respa[3];
-
-  double cut_in_diff = cut_in_on - cut_in_off;
-  double cut_in_off_sq = cut_in_off*cut_in_off;
-  double cut_in_on_sq = cut_in_on*cut_in_on;
-
-  // loop over neighbors of my atoms
-
-  for (ii = 0; ii < inum; ii++) {
-    i = ilist[ii];
-    qtmp = q[i];
-    xtmp = x[i][0];
-    ytmp = x[i][1];
-    ztmp = x[i][2];
-    itype = type[i];
-    jlist = firstneigh[i];
-    jnum = numneigh[i];
-
-    for (jj = 0; jj < jnum; jj++) {
-      j = jlist[jj];
-      factor_lj = special_lj[sbmask(j)];
-      factor_coul = special_coul[sbmask(j)];
-      j &= NEIGHMASK;
-
-      delx = xtmp - x[j][0];
-      dely = ytmp - x[j][1];
-      delz = ztmp - x[j][2];
-      rsq = delx*delx + dely*dely + delz*delz;
-      jtype = type[j];
-
-      if (rsq < cutsq[itype][jtype]) {
-        r2inv = 1.0/rsq;
-
-        if (rsq < cut_coulsq) {
-          if (!ncoultablebits || rsq <= tabinnersq) {
-            r = sqrt(rsq);
-            grij = g_ewald * r;
-            expm2 = exp(-grij*grij);
-            t = 1.0 / (1.0 + EWALD_P*grij);
-            erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
-            prefactor = qqrd2e * qtmp*q[j]/r;
-            forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0);
-            if (rsq > cut_in_off_sq) {
-              if (rsq < cut_in_on_sq) {
-                rsw = (r - cut_in_off)/cut_in_diff;
-                forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw);
-                if (factor_coul < 1.0)
-                  forcecoul -=
-                    (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw);
-              } else {
-                forcecoul += prefactor;
-                if (factor_coul < 1.0)
-                  forcecoul -= (1.0-factor_coul)*prefactor;
-              }
-            }
-          } else {
-            union_int_float_t rsq_lookup;
-            rsq_lookup.f = rsq;
-            itable = rsq_lookup.i & ncoulmask;
-            itable >>= ncoulshiftbits;
-            fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable];
-            table = ftable[itable] + fraction*dftable[itable];
-            forcecoul = qtmp*q[j] * table;
-            if (factor_coul < 1.0) {
-              table = ctable[itable] + fraction*dctable[itable];
-              prefactor = qtmp*q[j] * table;
-              forcecoul -= (1.0-factor_coul)*prefactor;
-            }
-          }
-        } else forcecoul = 0.0;
-
-        if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) {
-          r6inv = r2inv*r2inv*r2inv;
-          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-          if (rsq < cut_in_on_sq) {
-            rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff;
-            forcelj *= rsw*rsw*(3.0 - 2.0*rsw);
-          }
-        } else forcelj = 0.0;
-
-        fpair = (forcecoul + forcelj) * r2inv;
-
-        f[i][0] += delx*fpair;
-        f[i][1] += dely*fpair;
-        f[i][2] += delz*fpair;
-        if (newton_pair || j < nlocal) {
-          f[j][0] -= delx*fpair;
-          f[j][1] -= dely*fpair;
-          f[j][2] -= delz*fpair;
-        }
-
-        if (eflag) {
-          if (rsq < cut_coulsq) {
-            if (!ncoultablebits || rsq <= tabinnersq) {
-              ecoul = prefactor*erfc;
-              if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
-            } else {
-              table = etable[itable] + fraction*detable[itable];
-              ecoul = qtmp*q[j] * table;
-              if (factor_coul < 1.0) {
-                table = ptable[itable] + fraction*dptable[itable];
-                prefactor = qtmp*q[j] * table;
-                ecoul -= (1.0-factor_coul)*prefactor;
-              }
-            }
-          } else ecoul = 0.0;
-
-          if (rsq < cut_ljsq[itype][jtype]) {
-            r6inv = r2inv*r2inv*r2inv;
-            evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
-              offset[itype][jtype];
-            evdwl *= factor_lj;
-          } else evdwl = 0.0;
-        }
-
-        if (vflag) {
-          if (rsq < cut_coulsq) {
-            if (!ncoultablebits || rsq <= tabinnersq) {
-              forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
-              if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
-            } else {
-              table = vtable[itable] + fraction*dvtable[itable];
-              forcecoul = qtmp*q[j] * table;
-              if (factor_coul < 1.0) {
-                table = ptable[itable] + fraction*dptable[itable];
-                prefactor = qtmp*q[j] * table;
-                forcecoul -= (1.0-factor_coul)*prefactor;
-              }
-            }
-          } else forcecoul = 0.0;
-
-          if (rsq <= cut_in_off_sq) {
-            r6inv = r2inv*r2inv*r2inv;
-            forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-          } else if (rsq <= cut_in_on_sq)
-            forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-
-          fpair = (forcecoul + factor_lj*forcelj) * r2inv;
-        }
-
-        if (evflag) ev_tally(i,j,nlocal,newton_pair,
-                             evdwl,ecoul,fpair,delx,dely,delz);
-      }
-    }
-  }
-}
-
-/* ----------------------------------------------------------------------
-   allocate all arrays
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::allocate()
-{
-  allocated = 1;
-  int n = atom->ntypes;
-
-  memory->create(setflag,n+1,n+1,"pair:setflag");
-  for (int i = 1; i <= n; i++)
-    for (int j = i; j <= n; j++)
-      setflag[i][j] = 0;
-
-  memory->create(cutsq,n+1,n+1,"pair:cutsq");
-
-  memory->create(cut_lj,n+1,n+1,"pair:cut_lj");
-  memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq");
-  memory->create(epsilon,n+1,n+1,"pair:epsilon");
-  memory->create(sigma,n+1,n+1,"pair:sigma");
-  memory->create(lj1,n+1,n+1,"pair:lj1");
-  memory->create(lj2,n+1,n+1,"pair:lj2");
-  memory->create(lj3,n+1,n+1,"pair:lj3");
-  memory->create(lj4,n+1,n+1,"pair:lj4");
-  memory->create(offset,n+1,n+1,"pair:offset");
-}
-
-/* ----------------------------------------------------------------------
-   global settings
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::settings(int narg, char **arg)
-{
- if (narg < 1 || narg > 2) error->all(FLERR,"Illegal pair_style command");
-
-  cut_lj_global = force->numeric(arg[0]);
-  if (narg == 1) cut_coul = cut_lj_global;
-  else cut_coul = force->numeric(arg[1]);
-
-  // reset cutoffs that have been explicitly set
-
-  if (allocated) {
-    int i,j;
-    for (i = 1; i <= atom->ntypes; i++)
-      for (j = i+1; j <= atom->ntypes; j++)
-        if (setflag[i][j]) cut_lj[i][j] = cut_lj_global;
-  }
-}
-
-/* ----------------------------------------------------------------------
-   set coeffs for one or more type pairs
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::coeff(int narg, char **arg)
-{
-  if (narg < 4 || narg > 5)
-    error->all(FLERR,"Incorrect args for pair coefficients");
-  if (!allocated) allocate();
-
-  int ilo,ihi,jlo,jhi;
-  force->bounds(arg[0],atom->ntypes,ilo,ihi);
-  force->bounds(arg[1],atom->ntypes,jlo,jhi);
-
-  double epsilon_one = force->numeric(arg[2]);
-  double sigma_one = force->numeric(arg[3]);
-
-  double cut_lj_one = cut_lj_global;
-  if (narg == 5) cut_lj_one = force->numeric(arg[4]);
-
-  int count = 0;
-  for (int i = ilo; i <= ihi; i++) {
-    for (int j = MAX(jlo,i); j <= jhi; j++) {
-      epsilon[i][j] = epsilon_one;
-      sigma[i][j] = sigma_one;
-      cut_lj[i][j] = cut_lj_one;
-      setflag[i][j] = 1;
-      count++;
-    }
-  }
-
-  if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
-}
-
-/* ----------------------------------------------------------------------
-   init specific to this pair style
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::init_style()
-{
-  if (!atom->q_flag)
-    error->all(FLERR,"Pair style lj/cut/coul/long requires atom attribute q");
-
-  // request regular or rRESPA neighbor lists
-
-  int irequest;
-
-  if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) {
-    int respa = 0;
-    if (((Respa *) update->integrate)->level_inner >= 0) respa = 1;
-    if (((Respa *) update->integrate)->level_middle >= 0) respa = 2;
-
-    if (respa == 0) irequest = neighbor->request(this);
-    else if (respa == 1) {
-      irequest = neighbor->request(this);
-      neighbor->requests[irequest]->id = 1;
-      neighbor->requests[irequest]->half = 0;
-      neighbor->requests[irequest]->respainner = 1;
-      irequest = neighbor->request(this);
-      neighbor->requests[irequest]->id = 3;
-      neighbor->requests[irequest]->half = 0;
-      neighbor->requests[irequest]->respaouter = 1;
-    } else {
-      irequest = neighbor->request(this);
-      neighbor->requests[irequest]->id = 1;
-      neighbor->requests[irequest]->half = 0;
-      neighbor->requests[irequest]->respainner = 1;
-      irequest = neighbor->request(this);
-      neighbor->requests[irequest]->id = 2;
-      neighbor->requests[irequest]->half = 0;
-      neighbor->requests[irequest]->respamiddle = 1;
-      irequest = neighbor->request(this);
-      neighbor->requests[irequest]->id = 3;
-      neighbor->requests[irequest]->half = 0;
-      neighbor->requests[irequest]->respaouter = 1;
-    }
-
-  } else irequest = neighbor->request(this);
-
-  cut_coulsq = cut_coul * cut_coul;
-
-  // set rRESPA cutoffs
-
-  if (strstr(update->integrate_style,"respa") &&
-      ((Respa *) update->integrate)->level_inner >= 0)
-    cut_respa = ((Respa *) update->integrate)->cutoff;
-  else cut_respa = NULL;
-
-  // insure use of KSpace long-range solver, set g_ewald
-
-  if (force->kspace == NULL)
-    error->all(FLERR,"Pair style is incompatible with KSpace style");
-  g_ewald = force->kspace->g_ewald;
-
-  // setup force tables
-
-  if (ncoultablebits) init_tables();
-}
-
-/* ----------------------------------------------------------------------
-   neighbor callback to inform pair style of neighbor list to use
-   regular or rRESPA
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::init_list(int id, NeighList *ptr)
-{
-  if (id == 0) list = ptr;
-  else if (id == 1) listinner = ptr;
-  else if (id == 2) listmiddle = ptr;
-  else if (id == 3) listouter = ptr;
-}
-
-/* ----------------------------------------------------------------------
-   init for one type pair i,j and corresponding j,i
-------------------------------------------------------------------------- */
-
-double PairLJCutCoulLong::init_one(int i, int j)
-{
-  if (setflag[i][j] == 0) {
-    epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j],
-                               sigma[i][i],sigma[j][j]);
-    sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]);
-    cut_lj[i][j] = mix_distance(cut_lj[i][i],cut_lj[j][j]);
-  }
-
-  // include TIP4P qdist in full cutoff, qdist = 0.0 if not TIP4P
-
-  double cut = MAX(cut_lj[i][j],cut_coul+2.0*qdist);
-  cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j];
-
-  lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0);
-  lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0);
-  lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0);
-  lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0);
-
-  if (offset_flag) {
-    double ratio = sigma[i][j] / cut_lj[i][j];
-    offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0));
-  } else offset[i][j] = 0.0;
-
-  cut_ljsq[j][i] = cut_ljsq[i][j];
-  lj1[j][i] = lj1[i][j];
-  lj2[j][i] = lj2[i][j];
-  lj3[j][i] = lj3[i][j];
-  lj4[j][i] = lj4[i][j];
-  offset[j][i] = offset[i][j];
-
-  // check interior rRESPA cutoff
-
-  if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3])
-    error->all(FLERR,"Pair cutoff < Respa interior cutoff");
-
-  // compute I,J contribution to long-range tail correction
-  // count total # of atoms of type I and J via Allreduce
-
-  if (tail_flag) {
-    int *type = atom->type;
-    int nlocal = atom->nlocal;
-
-    double count[2],all[2];
-    count[0] = count[1] = 0.0;
-    for (int k = 0; k < nlocal; k++) {
-      if (type[k] == i) count[0] += 1.0;
-      if (type[k] == j) count[1] += 1.0;
-    }
-    MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world);
-
-    double sig2 = sigma[i][j]*sigma[i][j];
-    double sig6 = sig2*sig2*sig2;
-    double rc3 = cut_lj[i][j]*cut_lj[i][j]*cut_lj[i][j];
-    double rc6 = rc3*rc3;
-    double rc9 = rc3*rc6;
-    etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] *
-      sig6 * (sig6 - 3.0*rc6) / (9.0*rc9);
-    ptail_ij = 16.0*MY_PI*all[0]*all[1]*epsilon[i][j] *
-      sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9);
-  }
-
-  return cut;
-}
-
-/* ----------------------------------------------------------------------
-   setup force tables used in compute routines
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::init_tables()
-{
-  int masklo,maskhi;
-  double r,grij,expm2,derfc,rsw;
-  double qqrd2e = force->qqrd2e;
-
-  tabinnersq = tabinner*tabinner;
-  init_bitmap(tabinner,cut_coul,ncoultablebits,
-              masklo,maskhi,ncoulmask,ncoulshiftbits);
-
-  int ntable = 1;
-  for (int i = 0; i < ncoultablebits; i++) ntable *= 2;
-
-  // linear lookup tables of length N = 2^ncoultablebits
-  // stored value = value at lower edge of bin
-  // d values = delta from lower edge to upper edge of bin
-
-  if (ftable) free_tables();
-
-  memory->create(rtable,ntable,"pair:rtable");
-  memory->create(ftable,ntable,"pair:ftable");
-  memory->create(ctable,ntable,"pair:ctable");
-  memory->create(etable,ntable,"pair:etable");
-  memory->create(drtable,ntable,"pair:drtable");
-  memory->create(dftable,ntable,"pair:dftable");
-  memory->create(dctable,ntable,"pair:dctable");
-  memory->create(detable,ntable,"pair:detable");
-
-  if (cut_respa == NULL) {
-    vtable = ptable = dvtable = dptable = NULL;
-  } else {
-    memory->create(vtable,ntable*sizeof(double),"pair:vtable");
-    memory->create(ptable,ntable*sizeof(double),"pair:ptable");
-    memory->create(dvtable,ntable*sizeof(double),"pair:dvtable");
-    memory->create(dptable,ntable*sizeof(double),"pair:dptable");
-  }
-
-  union_int_float_t rsq_lookup;
-  union_int_float_t minrsq_lookup;
-  int itablemin;
-  minrsq_lookup.i = 0 << ncoulshiftbits;
-  minrsq_lookup.i |= maskhi;
-
-  for (int i = 0; i < ntable; i++) {
-    rsq_lookup.i = i << ncoulshiftbits;
-    rsq_lookup.i |= masklo;
-    if (rsq_lookup.f < tabinnersq) {
-      rsq_lookup.i = i << ncoulshiftbits;
-      rsq_lookup.i |= maskhi;
-    }
-    r = sqrtf(rsq_lookup.f);
-    grij = g_ewald * r;
-    expm2 = exp(-grij*grij);
-    derfc = erfc(grij);
-    if (cut_respa == NULL) {
-      rtable[i] = rsq_lookup.f;
-      ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-      ctable[i] = qqrd2e/r;
-      etable[i] = qqrd2e/r * derfc;
-    } else {
-      rtable[i] = rsq_lookup.f;
-      ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2 - 1.0);
-      ctable[i] = 0.0;
-      etable[i] = qqrd2e/r * derfc;
-      ptable[i] = qqrd2e/r;
-      vtable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-      if (rsq_lookup.f > cut_respa[2]*cut_respa[2]) {
-        if (rsq_lookup.f < cut_respa[3]*cut_respa[3]) {
-          rsw = (r - cut_respa[2])/(cut_respa[3] - cut_respa[2]);
-          ftable[i] += qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
-          ctable[i] = qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
-        } else {
-          ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-          ctable[i] = qqrd2e/r;
-        }
-      }
-    }
-    minrsq_lookup.f = MIN(minrsq_lookup.f,rsq_lookup.f);
-  }
-
-  tabinnersq = minrsq_lookup.f;
-
-  int ntablem1 = ntable - 1;
-
-  for (int i = 0; i < ntablem1; i++) {
-    drtable[i] = 1.0/(rtable[i+1] - rtable[i]);
-    dftable[i] = ftable[i+1] - ftable[i];
-    dctable[i] = ctable[i+1] - ctable[i];
-    detable[i] = etable[i+1] - etable[i];
-  }
-
-  if (cut_respa) {
-    for (int i = 0; i < ntablem1; i++) {
-      dvtable[i] = vtable[i+1] - vtable[i];
-      dptable[i] = ptable[i+1] - ptable[i];
-    }
-  }
-
-  // get the delta values for the last table entries
-  // tables are connected periodically between 0 and ntablem1
-
-  drtable[ntablem1] = 1.0/(rtable[0] - rtable[ntablem1]);
-  dftable[ntablem1] = ftable[0] - ftable[ntablem1];
-  dctable[ntablem1] = ctable[0] - ctable[ntablem1];
-  detable[ntablem1] = etable[0] - etable[ntablem1];
-  if (cut_respa) {
-    dvtable[ntablem1] = vtable[0] - vtable[ntablem1];
-    dptable[ntablem1] = ptable[0] - ptable[ntablem1];
-  }
-
-  // get the correct delta values at itablemax
-  // smallest r is in bin itablemin
-  // largest r is in bin itablemax, which is itablemin-1,
-  //   or ntablem1 if itablemin=0
-  // deltas at itablemax only needed if corresponding rsq < cut*cut
-  // if so, compute deltas between rsq and cut*cut
-
-  double f_tmp,c_tmp,e_tmp,p_tmp,v_tmp;
-  itablemin = minrsq_lookup.i & ncoulmask;
-  itablemin >>= ncoulshiftbits;
-  int itablemax = itablemin - 1;
-  if (itablemin == 0) itablemax = ntablem1;
-  rsq_lookup.i = itablemax << ncoulshiftbits;
-  rsq_lookup.i |= maskhi;
-
-  if (rsq_lookup.f < cut_coulsq) {
-    rsq_lookup.f = cut_coulsq;
-    r = sqrtf(rsq_lookup.f);
-    grij = g_ewald * r;
-    expm2 = exp(-grij*grij);
-    derfc = erfc(grij);
-
-    if (cut_respa == NULL) {
-      f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-      c_tmp = qqrd2e/r;
-      e_tmp = qqrd2e/r * derfc;
-    } else {
-      f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2 - 1.0);
-      c_tmp = 0.0;
-      e_tmp = qqrd2e/r * derfc;
-      p_tmp = qqrd2e/r;
-      v_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-      if (rsq_lookup.f > cut_respa[2]*cut_respa[2]) {
-        if (rsq_lookup.f < cut_respa[3]*cut_respa[3]) {
-          rsw = (r - cut_respa[2])/(cut_respa[3] - cut_respa[2]);
-          f_tmp += qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
-          c_tmp = qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
-        } else {
-          f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
-          c_tmp = qqrd2e/r;
-        }
-      }
-    }
-
-    drtable[itablemax] = 1.0/(rsq_lookup.f - rtable[itablemax]);
-    dftable[itablemax] = f_tmp - ftable[itablemax];
-    dctable[itablemax] = c_tmp - ctable[itablemax];
-    detable[itablemax] = e_tmp - etable[itablemax];
-    if (cut_respa) {
-      dvtable[itablemax] = v_tmp - vtable[itablemax];
-      dptable[itablemax] = p_tmp - ptable[itablemax];
-    }
-  }
-}
-
-/* ----------------------------------------------------------------------
-  proc 0 writes to restart file
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::write_restart(FILE *fp)
-{
-  write_restart_settings(fp);
-
-  int i,j;
-  for (i = 1; i <= atom->ntypes; i++)
-    for (j = i; j <= atom->ntypes; j++) {
-      fwrite(&setflag[i][j],sizeof(int),1,fp);
-      if (setflag[i][j]) {
-        fwrite(&epsilon[i][j],sizeof(double),1,fp);
-        fwrite(&sigma[i][j],sizeof(double),1,fp);
-        fwrite(&cut_lj[i][j],sizeof(double),1,fp);
-      }
-    }
-}
-
-/* ----------------------------------------------------------------------
-  proc 0 reads from restart file, bcasts
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::read_restart(FILE *fp)
-{
-  read_restart_settings(fp);
-
-  allocate();
-
-  int i,j;
-  int me = comm->me;
-  for (i = 1; i <= atom->ntypes; i++)
-    for (j = i; j <= atom->ntypes; j++) {
-      if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
-      MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
-      if (setflag[i][j]) {
-        if (me == 0) {
-          fread(&epsilon[i][j],sizeof(double),1,fp);
-          fread(&sigma[i][j],sizeof(double),1,fp);
-          fread(&cut_lj[i][j],sizeof(double),1,fp);
-        }
-        MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world);
-        MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world);
-        MPI_Bcast(&cut_lj[i][j],1,MPI_DOUBLE,0,world);
-      }
-    }
-}
-
-/* ----------------------------------------------------------------------
-  proc 0 writes to restart file
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::write_restart_settings(FILE *fp)
-{
-  fwrite(&cut_lj_global,sizeof(double),1,fp);
-  fwrite(&cut_coul,sizeof(double),1,fp);
-  fwrite(&offset_flag,sizeof(int),1,fp);
-  fwrite(&mix_flag,sizeof(int),1,fp);
-}
-
-/* ----------------------------------------------------------------------
-  proc 0 reads from restart file, bcasts
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::read_restart_settings(FILE *fp)
-{
-  if (comm->me == 0) {
-    fread(&cut_lj_global,sizeof(double),1,fp);
-    fread(&cut_coul,sizeof(double),1,fp);
-    fread(&offset_flag,sizeof(int),1,fp);
-    fread(&mix_flag,sizeof(int),1,fp);
-  }
-  MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);
-  MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);
-  MPI_Bcast(&offset_flag,1,MPI_INT,0,world);
-  MPI_Bcast(&mix_flag,1,MPI_INT,0,world);
-}
-
-/* ----------------------------------------------------------------------
-   free memory for tables used in pair computations
-------------------------------------------------------------------------- */
-
-void PairLJCutCoulLong::free_tables()
-{
-  memory->destroy(rtable);
-  memory->destroy(drtable);
-  memory->destroy(ftable);
-  memory->destroy(dftable);
-  memory->destroy(ctable);
-  memory->destroy(dctable);
-  memory->destroy(etable);
-  memory->destroy(detable);
-  memory->destroy(vtable);
-  memory->destroy(dvtable);
-  memory->destroy(ptable);
-  memory->destroy(dptable);
-}
-
-/* ---------------------------------------------------------------------- */
-
-double PairLJCutCoulLong::single(int i, int j, int itype, int jtype,
-                                 double rsq,
-                                 double factor_coul, double factor_lj,
-                                 double &fforce)
-{
-  double r2inv,r6inv,r,grij,expm2,t,erfc,prefactor;
-  double fraction,table,forcecoul,forcelj,phicoul,philj;
-  int itable;
-
-  r2inv = 1.0/rsq;
-  if (rsq < cut_coulsq) {
-    if (!ncoultablebits || rsq <= tabinnersq) {
-      r = sqrt(rsq);
-      grij = g_ewald * r;
-      expm2 = exp(-grij*grij);
-      t = 1.0 / (1.0 + EWALD_P*grij);
-      erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
-      prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r;
-      forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
-      if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
-    } else {
-      union_int_float_t rsq_lookup_single;
-      rsq_lookup_single.f = rsq;
-      itable = rsq_lookup_single.i & ncoulmask;
-      itable >>= ncoulshiftbits;
-      fraction = (rsq_lookup_single.f - rtable[itable]) * drtable[itable];
-      table = ftable[itable] + fraction*dftable[itable];
-      forcecoul = atom->q[i]*atom->q[j] * table;
-      if (factor_coul < 1.0) {
-        table = ctable[itable] + fraction*dctable[itable];
-        prefactor = atom->q[i]*atom->q[j] * table;
-        forcecoul -= (1.0-factor_coul)*prefactor;
-      }
-    }
-  } else forcecoul = 0.0;
-
-  if (rsq < cut_ljsq[itype][jtype]) {
-    r6inv = r2inv*r2inv*r2inv;
-    forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
-  } else forcelj = 0.0;
-
-  fforce = (forcecoul + factor_lj*forcelj) * r2inv;
-
-  double eng = 0.0;
-  if (rsq < cut_coulsq) {
-    if (!ncoultablebits || rsq <= tabinnersq)
-      phicoul = prefactor*erfc;
-    else {
-      table = etable[itable] + fraction*detable[itable];
-      phicoul = atom->q[i]*atom->q[j] * table;
-    }
-    if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor;
-    eng += phicoul;
-  }
-
-  if (rsq < cut_ljsq[itype][jtype]) {
-    philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
-      offset[itype][jtype];
-    eng += factor_lj*philj;
-  }
-
-  return eng;
-}
-
-/* ---------------------------------------------------------------------- */
-
-void *PairLJCutCoulLong::extract(const char *str, int &dim)
-{
-  dim = 0;
-  if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul;
-  dim = 2;
-  if (strcmp(str,"epsilon") == 0) return (void *) epsilon;
-  return NULL;
-}
+/* ----------------------------------------------------------------------
+   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
+   http://lammps.sandia.gov, Sandia National Laboratories
+   Steve Plimpton, sjplimp@sandia.gov
+
+   Copyright (2003) Sandia Corporation.  Under the terms of Contract
+   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
+   certain rights in this software.  This software is distributed under
+   the GNU General Public License.
+
+   See the README file in the top-level LAMMPS directory.
+------------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------
+   Contributing author: Paul Crozier (SNL)
+------------------------------------------------------------------------- */
+
+#include "math.h"
+#include "stdio.h"
+#include "stdlib.h"
+#include "string.h"
+#include "pair_lj_cut_coul_long.h"
+#include "atom.h"
+#include "comm.h"
+#include "force.h"
+#include "kspace.h"
+#include "update.h"
+#include "integrate.h"
+#include "respa.h"
+#include "neighbor.h"
+#include "neigh_list.h"
+#include "neigh_request.h"
+#include "math_const.h"
+#include "memory.h"
+#include "error.h"
+
+using namespace LAMMPS_NS;
+using namespace MathConst;
+
+#define EWALD_F   1.12837917
+#define EWALD_P   0.3275911
+#define A1        0.254829592
+#define A2       -0.284496736
+#define A3        1.421413741
+#define A4       -1.453152027
+#define A5        1.061405429
+
+/* ---------------------------------------------------------------------- */
+
+PairLJCutCoulLong::PairLJCutCoulLong(LAMMPS *lmp) : Pair(lmp)
+{
+  respa_enable = 1;
+  ftable = NULL;
+  qdist = 0.0;
+}
+
+/* ---------------------------------------------------------------------- */
+
+PairLJCutCoulLong::~PairLJCutCoulLong()
+{
+  if (allocated) {
+    memory->destroy(setflag);
+    memory->destroy(cutsq);
+
+    memory->destroy(cut_lj);
+    memory->destroy(cut_ljsq);
+    memory->destroy(epsilon);
+    memory->destroy(sigma);
+    memory->destroy(lj1);
+    memory->destroy(lj2);
+    memory->destroy(lj3);
+    memory->destroy(lj4);
+    memory->destroy(offset);
+  }
+  if (ftable) free_tables();
+}
+
+/* ---------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::compute(int eflag, int vflag)
+{
+  int i,ii,j,jj,inum,jnum,itype,jtype,itable;
+  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair;
+  double fraction,table;
+  double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
+  double grij,expm2,prefactor,t,erfc;
+  int *ilist,*jlist,*numneigh,**firstneigh;
+  double rsq;
+
+  evdwl = ecoul = 0.0;
+  if (eflag || vflag) ev_setup(eflag,vflag);
+  else evflag = vflag_fdotr = 0;
+
+  double **x = atom->x;
+  double **f = atom->f;
+  double *q = atom->q;
+  int *type = atom->type;
+  int nlocal = atom->nlocal;
+  double *special_coul = force->special_coul;
+  double *special_lj = force->special_lj;
+  int newton_pair = force->newton_pair;
+  double qqrd2e = force->qqrd2e;
+
+  inum = list->inum;
+  ilist = list->ilist;
+  numneigh = list->numneigh;
+  firstneigh = list->firstneigh;
+
+  // loop over neighbors of my atoms
+
+  for (ii = 0; ii < inum; ii++) {
+    i = ilist[ii];
+    qtmp = q[i];
+    xtmp = x[i][0];
+    ytmp = x[i][1];
+    ztmp = x[i][2];
+    itype = type[i];
+    jlist = firstneigh[i];
+    jnum = numneigh[i];
+
+    for (jj = 0; jj < jnum; jj++) {
+      j = jlist[jj];
+      factor_lj = special_lj[sbmask(j)];
+      factor_coul = special_coul[sbmask(j)];
+      j &= NEIGHMASK;
+
+      delx = xtmp - x[j][0];
+      dely = ytmp - x[j][1];
+      delz = ztmp - x[j][2];
+      rsq = delx*delx + dely*dely + delz*delz;
+      jtype = type[j];
+
+      if (rsq < cutsq[itype][jtype]) {
+        r2inv = 1.0/rsq;
+
+        if (rsq < cut_coulsq) {
+          if (!ncoultablebits || rsq <= tabinnersq) {
+            r = sqrt(rsq);
+            grij = g_ewald * r;
+            expm2 = exp(-grij*grij);
+            t = 1.0 / (1.0 + EWALD_P*grij);
+            erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
+            prefactor = qqrd2e * qtmp*q[j]/r;
+            forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
+            if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
+          } else {
+            union_int_float_t rsq_lookup;
+            rsq_lookup.f = rsq;
+            itable = rsq_lookup.i & ncoulmask;
+            itable >>= ncoulshiftbits;
+            fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable];
+            table = ftable[itable] + fraction*dftable[itable];
+            forcecoul = qtmp*q[j] * table;
+            if (factor_coul < 1.0) {
+              table = ctable[itable] + fraction*dctable[itable];
+              prefactor = qtmp*q[j] * table;
+              forcecoul -= (1.0-factor_coul)*prefactor;
+            }
+          }
+        } else forcecoul = 0.0;
+
+        if (rsq < cut_ljsq[itype][jtype]) {
+          r6inv = r2inv*r2inv*r2inv;
+          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+        } else forcelj = 0.0;
+
+        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
+
+        f[i][0] += delx*fpair;
+        f[i][1] += dely*fpair;
+        f[i][2] += delz*fpair;
+        if (newton_pair || j < nlocal) {
+          f[j][0] -= delx*fpair;
+          f[j][1] -= dely*fpair;
+          f[j][2] -= delz*fpair;
+        }
+
+        if (eflag) {
+          if (rsq < cut_coulsq) {
+            if (!ncoultablebits || rsq <= tabinnersq)
+              ecoul = prefactor*erfc;
+            else {
+              table = etable[itable] + fraction*detable[itable];
+              ecoul = qtmp*q[j] * table;
+            }
+            if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
+          } else ecoul = 0.0;
+
+          if (rsq < cut_ljsq[itype][jtype]) {
+            evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
+              offset[itype][jtype];
+            evdwl *= factor_lj;
+          } else evdwl = 0.0;
+        }
+
+        if (evflag) ev_tally(i,j,nlocal,newton_pair,
+                             evdwl,ecoul,fpair,delx,dely,delz);
+      }
+    }
+  }
+
+  if (vflag_fdotr) virial_fdotr_compute();
+}
+
+/* ---------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::compute_inner()
+{
+  int i,j,ii,jj,inum,jnum,itype,jtype;
+  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair;
+  double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
+  double rsw;
+  int *ilist,*jlist,*numneigh,**firstneigh;
+
+  double **x = atom->x;
+  double **f = atom->f;
+  double *q = atom->q;
+  int *type = atom->type;
+  int nlocal = atom->nlocal;
+  double *special_coul = force->special_coul;
+  double *special_lj = force->special_lj;
+  int newton_pair = force->newton_pair;
+  double qqrd2e = force->qqrd2e;
+
+  inum = listinner->inum;
+  ilist = listinner->ilist;
+  numneigh = listinner->numneigh;
+  firstneigh = listinner->firstneigh;
+
+  double cut_out_on = cut_respa[0];
+  double cut_out_off = cut_respa[1];
+
+  double cut_out_diff = cut_out_off - cut_out_on;
+  double cut_out_on_sq = cut_out_on*cut_out_on;
+  double cut_out_off_sq = cut_out_off*cut_out_off;
+
+  // loop over neighbors of my atoms
+
+  for (ii = 0; ii < inum; ii++) {
+    i = ilist[ii];
+    qtmp = q[i];
+    xtmp = x[i][0];
+    ytmp = x[i][1];
+    ztmp = x[i][2];
+    itype = type[i];
+    jlist = firstneigh[i];
+    jnum = numneigh[i];
+
+    for (jj = 0; jj < jnum; jj++) {
+      j = jlist[jj];
+      factor_lj = special_lj[sbmask(j)];
+      factor_coul = special_coul[sbmask(j)];
+      j &= NEIGHMASK;
+
+      delx = xtmp - x[j][0];
+      dely = ytmp - x[j][1];
+      delz = ztmp - x[j][2];
+      rsq = delx*delx + dely*dely + delz*delz;
+
+      if (rsq < cut_out_off_sq) {
+        r2inv = 1.0/rsq;
+        forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv);
+        if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul;
+
+        jtype = type[j];
+        if (rsq < cut_ljsq[itype][jtype]) {
+          r6inv = r2inv*r2inv*r2inv;
+          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+        } else forcelj = 0.0;
+
+        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
+        if (rsq > cut_out_on_sq) {
+          rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff;
+          fpair  *= 1.0 + rsw*rsw*(2.0*rsw-3.0);
+        }
+
+        f[i][0] += delx*fpair;
+        f[i][1] += dely*fpair;
+        f[i][2] += delz*fpair;
+        if (newton_pair || j < nlocal) {
+          f[j][0] -= delx*fpair;
+          f[j][1] -= dely*fpair;
+          f[j][2] -= delz*fpair;
+        }
+      }
+    }
+  }
+}
+
+/* ---------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::compute_middle()
+{
+  int i,j,ii,jj,inum,jnum,itype,jtype;
+  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,fpair;
+  double rsq,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
+  double rsw;
+  int *ilist,*jlist,*numneigh,**firstneigh;
+
+  double **x = atom->x;
+  double **f = atom->f;
+  double *q = atom->q;
+  int *type = atom->type;
+  int nlocal = atom->nlocal;
+  double *special_coul = force->special_coul;
+  double *special_lj = force->special_lj;
+  int newton_pair = force->newton_pair;
+  double qqrd2e = force->qqrd2e;
+
+  inum = listmiddle->inum;
+  ilist = listmiddle->ilist;
+  numneigh = listmiddle->numneigh;
+  firstneigh = listmiddle->firstneigh;
+
+  double cut_in_off = cut_respa[0];
+  double cut_in_on = cut_respa[1];
+  double cut_out_on = cut_respa[2];
+  double cut_out_off = cut_respa[3];
+
+  double cut_in_diff = cut_in_on - cut_in_off;
+  double cut_out_diff = cut_out_off - cut_out_on;
+  double cut_in_off_sq = cut_in_off*cut_in_off;
+  double cut_in_on_sq = cut_in_on*cut_in_on;
+  double cut_out_on_sq = cut_out_on*cut_out_on;
+  double cut_out_off_sq = cut_out_off*cut_out_off;
+
+  // loop over neighbors of my atoms
+
+  for (ii = 0; ii < inum; ii++) {
+    i = ilist[ii];
+    qtmp = q[i];
+    xtmp = x[i][0];
+    ytmp = x[i][1];
+    ztmp = x[i][2];
+    itype = type[i];
+    jlist = firstneigh[i];
+    jnum = numneigh[i];
+
+    for (jj = 0; jj < jnum; jj++) {
+      j = jlist[jj];
+      factor_lj = special_lj[sbmask(j)];
+      factor_coul = special_coul[sbmask(j)];
+      j &= NEIGHMASK;
+
+      delx = xtmp - x[j][0];
+      dely = ytmp - x[j][1];
+      delz = ztmp - x[j][2];
+      rsq = delx*delx + dely*dely + delz*delz;
+
+      if (rsq < cut_out_off_sq && rsq > cut_in_off_sq) {
+        r2inv = 1.0/rsq;
+        forcecoul = qqrd2e * qtmp*q[j]*sqrt(r2inv);
+        if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*forcecoul;
+
+        jtype = type[j];
+        if (rsq < cut_ljsq[itype][jtype]) {
+          r6inv = r2inv*r2inv*r2inv;
+          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+        } else forcelj = 0.0;
+
+        fpair = (forcecoul + factor_lj*forcelj) * r2inv;
+        if (rsq < cut_in_on_sq) {
+          rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff;
+          fpair *= rsw*rsw*(3.0 - 2.0*rsw);
+        }
+        if (rsq > cut_out_on_sq) {
+          rsw = (sqrt(rsq) - cut_out_on)/cut_out_diff;
+          fpair *= 1.0 + rsw*rsw*(2.0*rsw - 3.0);
+        }
+
+        f[i][0] += delx*fpair;
+        f[i][1] += dely*fpair;
+        f[i][2] += delz*fpair;
+        if (newton_pair || j < nlocal) {
+          f[j][0] -= delx*fpair;
+          f[j][1] -= dely*fpair;
+          f[j][2] -= delz*fpair;
+        }
+      }
+    }
+  }
+}
+
+/* ---------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::compute_outer(int eflag, int vflag)
+{
+  int i,j,ii,jj,inum,jnum,itype,jtype,itable;
+  double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair;
+  double fraction,table;
+  double r,r2inv,r6inv,forcecoul,forcelj,factor_coul,factor_lj;
+  double grij,expm2,prefactor,t,erfc;
+  double rsw;
+  int *ilist,*jlist,*numneigh,**firstneigh;
+  double rsq;
+
+  evdwl = ecoul = 0.0;
+  if (eflag || vflag) ev_setup(eflag,vflag);
+  else evflag = 0;
+
+  double **x = atom->x;
+  double **f = atom->f;
+  double *q = atom->q;
+  int *type = atom->type;
+  int nlocal = atom->nlocal;
+  double *special_coul = force->special_coul;
+  double *special_lj = force->special_lj;
+  int newton_pair = force->newton_pair;
+  double qqrd2e = force->qqrd2e;
+
+  inum = listouter->inum;
+  ilist = listouter->ilist;
+  numneigh = listouter->numneigh;
+  firstneigh = listouter->firstneigh;
+
+  double cut_in_off = cut_respa[2];
+  double cut_in_on = cut_respa[3];
+
+  double cut_in_diff = cut_in_on - cut_in_off;
+  double cut_in_off_sq = cut_in_off*cut_in_off;
+  double cut_in_on_sq = cut_in_on*cut_in_on;
+
+  // loop over neighbors of my atoms
+
+  for (ii = 0; ii < inum; ii++) {
+    i = ilist[ii];
+    qtmp = q[i];
+    xtmp = x[i][0];
+    ytmp = x[i][1];
+    ztmp = x[i][2];
+    itype = type[i];
+    jlist = firstneigh[i];
+    jnum = numneigh[i];
+
+    for (jj = 0; jj < jnum; jj++) {
+      j = jlist[jj];
+      factor_lj = special_lj[sbmask(j)];
+      factor_coul = special_coul[sbmask(j)];
+      j &= NEIGHMASK;
+
+      delx = xtmp - x[j][0];
+      dely = ytmp - x[j][1];
+      delz = ztmp - x[j][2];
+      rsq = delx*delx + dely*dely + delz*delz;
+      jtype = type[j];
+
+      if (rsq < cutsq[itype][jtype]) {
+        r2inv = 1.0/rsq;
+
+        if (rsq < cut_coulsq) {
+          if (!ncoultablebits || rsq <= tabinnersq) {
+            r = sqrt(rsq);
+            grij = g_ewald * r;
+            expm2 = exp(-grij*grij);
+            t = 1.0 / (1.0 + EWALD_P*grij);
+            erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
+            prefactor = qqrd2e * qtmp*q[j]/r;
+            forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - 1.0);
+            if (rsq > cut_in_off_sq) {
+              if (rsq < cut_in_on_sq) {
+                rsw = (r - cut_in_off)/cut_in_diff;
+                forcecoul += prefactor*rsw*rsw*(3.0 - 2.0*rsw);
+                if (factor_coul < 1.0)
+                  forcecoul -=
+                    (1.0-factor_coul)*prefactor*rsw*rsw*(3.0 - 2.0*rsw);
+              } else {
+                forcecoul += prefactor;
+                if (factor_coul < 1.0)
+                  forcecoul -= (1.0-factor_coul)*prefactor;
+              }
+            }
+          } else {
+            union_int_float_t rsq_lookup;
+            rsq_lookup.f = rsq;
+            itable = rsq_lookup.i & ncoulmask;
+            itable >>= ncoulshiftbits;
+            fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable];
+            table = ftable[itable] + fraction*dftable[itable];
+            forcecoul = qtmp*q[j] * table;
+            if (factor_coul < 1.0) {
+              table = ctable[itable] + fraction*dctable[itable];
+              prefactor = qtmp*q[j] * table;
+              forcecoul -= (1.0-factor_coul)*prefactor;
+            }
+          }
+        } else forcecoul = 0.0;
+
+        if (rsq < cut_ljsq[itype][jtype] && rsq > cut_in_off_sq) {
+          r6inv = r2inv*r2inv*r2inv;
+          forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+          if (rsq < cut_in_on_sq) {
+            rsw = (sqrt(rsq) - cut_in_off)/cut_in_diff;
+            forcelj *= rsw*rsw*(3.0 - 2.0*rsw);
+          }
+        } else forcelj = 0.0;
+
+        fpair = (forcecoul + forcelj) * r2inv;
+
+        f[i][0] += delx*fpair;
+        f[i][1] += dely*fpair;
+        f[i][2] += delz*fpair;
+        if (newton_pair || j < nlocal) {
+          f[j][0] -= delx*fpair;
+          f[j][1] -= dely*fpair;
+          f[j][2] -= delz*fpair;
+        }
+
+        if (eflag) {
+          if (rsq < cut_coulsq) {
+            if (!ncoultablebits || rsq <= tabinnersq) {
+              ecoul = prefactor*erfc;
+              if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
+            } else {
+              table = etable[itable] + fraction*detable[itable];
+              ecoul = qtmp*q[j] * table;
+              if (factor_coul < 1.0) {
+                table = ptable[itable] + fraction*dptable[itable];
+                prefactor = qtmp*q[j] * table;
+                ecoul -= (1.0-factor_coul)*prefactor;
+              }
+            }
+          } else ecoul = 0.0;
+
+          if (rsq < cut_ljsq[itype][jtype]) {
+            r6inv = r2inv*r2inv*r2inv;
+            evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
+              offset[itype][jtype];
+            evdwl *= factor_lj;
+          } else evdwl = 0.0;
+        }
+
+        if (vflag) {
+          if (rsq < cut_coulsq) {
+            if (!ncoultablebits || rsq <= tabinnersq) {
+              forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
+              if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
+            } else {
+              table = vtable[itable] + fraction*dvtable[itable];
+              forcecoul = qtmp*q[j] * table;
+              if (factor_coul < 1.0) {
+                table = ptable[itable] + fraction*dptable[itable];
+                prefactor = qtmp*q[j] * table;
+                forcecoul -= (1.0-factor_coul)*prefactor;
+              }
+            }
+          } else forcecoul = 0.0;
+
+          if (rsq <= cut_in_off_sq) {
+            r6inv = r2inv*r2inv*r2inv;
+            forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+          } else if (rsq <= cut_in_on_sq)
+            forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+
+          fpair = (forcecoul + factor_lj*forcelj) * r2inv;
+        }
+
+        if (evflag) ev_tally(i,j,nlocal,newton_pair,
+                             evdwl,ecoul,fpair,delx,dely,delz);
+      }
+    }
+  }
+}
+
+/* ----------------------------------------------------------------------
+   allocate all arrays
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::allocate()
+{
+  allocated = 1;
+  int n = atom->ntypes;
+
+  memory->create(setflag,n+1,n+1,"pair:setflag");
+  for (int i = 1; i <= n; i++)
+    for (int j = i; j <= n; j++)
+      setflag[i][j] = 0;
+
+  memory->create(cutsq,n+1,n+1,"pair:cutsq");
+
+  memory->create(cut_lj,n+1,n+1,"pair:cut_lj");
+  memory->create(cut_ljsq,n+1,n+1,"pair:cut_ljsq");
+  memory->create(epsilon,n+1,n+1,"pair:epsilon");
+  memory->create(sigma,n+1,n+1,"pair:sigma");
+  memory->create(lj1,n+1,n+1,"pair:lj1");
+  memory->create(lj2,n+1,n+1,"pair:lj2");
+  memory->create(lj3,n+1,n+1,"pair:lj3");
+  memory->create(lj4,n+1,n+1,"pair:lj4");
+  memory->create(offset,n+1,n+1,"pair:offset");
+}
+
+/* ----------------------------------------------------------------------
+   global settings
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::settings(int narg, char **arg)
+{
+ if (narg < 1 || narg > 2) error->all(FLERR,"Illegal pair_style command");
+
+  cut_lj_global = force->numeric(arg[0]);
+  if (narg == 1) cut_coul = cut_lj_global;
+  else cut_coul = force->numeric(arg[1]);
+
+  // reset cutoffs that have been explicitly set
+
+  if (allocated) {
+    int i,j;
+    for (i = 1; i <= atom->ntypes; i++)
+      for (j = i+1; j <= atom->ntypes; j++)
+        if (setflag[i][j]) cut_lj[i][j] = cut_lj_global;
+  }
+}
+
+/* ----------------------------------------------------------------------
+   set coeffs for one or more type pairs
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::coeff(int narg, char **arg)
+{
+  if (narg < 4 || narg > 5)
+    error->all(FLERR,"Incorrect args for pair coefficients");
+  if (!allocated) allocate();
+
+  int ilo,ihi,jlo,jhi;
+  force->bounds(arg[0],atom->ntypes,ilo,ihi);
+  force->bounds(arg[1],atom->ntypes,jlo,jhi);
+
+  double epsilon_one = force->numeric(arg[2]);
+  double sigma_one = force->numeric(arg[3]);
+
+  double cut_lj_one = cut_lj_global;
+  if (narg == 5) cut_lj_one = force->numeric(arg[4]);
+
+  int count = 0;
+  for (int i = ilo; i <= ihi; i++) {
+    for (int j = MAX(jlo,i); j <= jhi; j++) {
+      epsilon[i][j] = epsilon_one;
+      sigma[i][j] = sigma_one;
+      cut_lj[i][j] = cut_lj_one;
+      setflag[i][j] = 1;
+      count++;
+    }
+  }
+
+  if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
+}
+
+/* ----------------------------------------------------------------------
+   init specific to this pair style
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::init_style()
+{
+  if (!atom->q_flag)
+    error->all(FLERR,"Pair style lj/cut/coul/long requires atom attribute q");
+
+  // request regular or rRESPA neighbor lists
+
+  int irequest;
+
+  if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) {
+    int respa = 0;
+    if (((Respa *) update->integrate)->level_inner >= 0) respa = 1;
+    if (((Respa *) update->integrate)->level_middle >= 0) respa = 2;
+
+    if (respa == 0) irequest = neighbor->request(this);
+    else if (respa == 1) {
+      irequest = neighbor->request(this);
+      neighbor->requests[irequest]->id = 1;
+      neighbor->requests[irequest]->half = 0;
+      neighbor->requests[irequest]->respainner = 1;
+      irequest = neighbor->request(this);
+      neighbor->requests[irequest]->id = 3;
+      neighbor->requests[irequest]->half = 0;
+      neighbor->requests[irequest]->respaouter = 1;
+    } else {
+      irequest = neighbor->request(this);
+      neighbor->requests[irequest]->id = 1;
+      neighbor->requests[irequest]->half = 0;
+      neighbor->requests[irequest]->respainner = 1;
+      irequest = neighbor->request(this);
+      neighbor->requests[irequest]->id = 2;
+      neighbor->requests[irequest]->half = 0;
+      neighbor->requests[irequest]->respamiddle = 1;
+      irequest = neighbor->request(this);
+      neighbor->requests[irequest]->id = 3;
+      neighbor->requests[irequest]->half = 0;
+      neighbor->requests[irequest]->respaouter = 1;
+    }
+
+  } else irequest = neighbor->request(this);
+
+  cut_coulsq = cut_coul * cut_coul;
+
+  // set rRESPA cutoffs
+
+  if (strstr(update->integrate_style,"respa") &&
+      ((Respa *) update->integrate)->level_inner >= 0)
+    cut_respa = ((Respa *) update->integrate)->cutoff;
+  else cut_respa = NULL;
+
+  // insure use of KSpace long-range solver, set g_ewald
+
+  if (force->kspace == NULL)
+    error->all(FLERR,"Pair style is incompatible with KSpace style");
+  g_ewald = force->kspace->g_ewald;
+
+  // setup force tables
+
+  if (ncoultablebits) init_tables();
+}
+
+/* ----------------------------------------------------------------------
+   neighbor callback to inform pair style of neighbor list to use
+   regular or rRESPA
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::init_list(int id, NeighList *ptr)
+{
+  if (id == 0) list = ptr;
+  else if (id == 1) listinner = ptr;
+  else if (id == 2) listmiddle = ptr;
+  else if (id == 3) listouter = ptr;
+}
+
+/* ----------------------------------------------------------------------
+   init for one type pair i,j and corresponding j,i
+------------------------------------------------------------------------- */
+
+double PairLJCutCoulLong::init_one(int i, int j)
+{
+  if (setflag[i][j] == 0) {
+    epsilon[i][j] = mix_energy(epsilon[i][i],epsilon[j][j],
+                               sigma[i][i],sigma[j][j]);
+    sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]);
+    cut_lj[i][j] = mix_distance(cut_lj[i][i],cut_lj[j][j]);
+  }
+
+  // include TIP4P qdist in full cutoff, qdist = 0.0 if not TIP4P
+
+  double cut = MAX(cut_lj[i][j],cut_coul+2.0*qdist);
+  cut_ljsq[i][j] = cut_lj[i][j] * cut_lj[i][j];
+
+  lj1[i][j] = 48.0 * epsilon[i][j] * pow(sigma[i][j],12.0);
+  lj2[i][j] = 24.0 * epsilon[i][j] * pow(sigma[i][j],6.0);
+  lj3[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],12.0);
+  lj4[i][j] = 4.0 * epsilon[i][j] * pow(sigma[i][j],6.0);
+
+  if (offset_flag) {
+    double ratio = sigma[i][j] / cut_lj[i][j];
+    offset[i][j] = 4.0 * epsilon[i][j] * (pow(ratio,12.0) - pow(ratio,6.0));
+  } else offset[i][j] = 0.0;
+
+  cut_ljsq[j][i] = cut_ljsq[i][j];
+  lj1[j][i] = lj1[i][j];
+  lj2[j][i] = lj2[i][j];
+  lj3[j][i] = lj3[i][j];
+  lj4[j][i] = lj4[i][j];
+  offset[j][i] = offset[i][j];
+
+  // check interior rRESPA cutoff
+
+  if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3])
+    error->all(FLERR,"Pair cutoff < Respa interior cutoff");
+
+  // compute I,J contribution to long-range tail correction
+  // count total # of atoms of type I and J via Allreduce
+
+  if (tail_flag) {
+    int *type = atom->type;
+    int nlocal = atom->nlocal;
+
+    double count[2],all[2];
+    count[0] = count[1] = 0.0;
+    for (int k = 0; k < nlocal; k++) {
+      if (type[k] == i) count[0] += 1.0;
+      if (type[k] == j) count[1] += 1.0;
+    }
+    MPI_Allreduce(count,all,2,MPI_DOUBLE,MPI_SUM,world);
+
+    double sig2 = sigma[i][j]*sigma[i][j];
+    double sig6 = sig2*sig2*sig2;
+    double rc3 = cut_lj[i][j]*cut_lj[i][j]*cut_lj[i][j];
+    double rc6 = rc3*rc3;
+    double rc9 = rc3*rc6;
+    etail_ij = 8.0*MY_PI*all[0]*all[1]*epsilon[i][j] *
+      sig6 * (sig6 - 3.0*rc6) / (9.0*rc9);
+    ptail_ij = 16.0*MY_PI*all[0]*all[1]*epsilon[i][j] *
+      sig6 * (2.0*sig6 - 3.0*rc6) / (9.0*rc9);
+  }
+
+  return cut;
+}
+
+/* ----------------------------------------------------------------------
+   setup force tables used in compute routines
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::init_tables()
+{
+  int masklo,maskhi;
+  double r,grij,expm2,derfc,rsw;
+  double qqrd2e = force->qqrd2e;
+
+  tabinnersq = tabinner*tabinner;
+  init_bitmap(tabinner,cut_coul,ncoultablebits,
+              masklo,maskhi,ncoulmask,ncoulshiftbits);
+
+  int ntable = 1;
+  for (int i = 0; i < ncoultablebits; i++) ntable *= 2;
+
+  // linear lookup tables of length N = 2^ncoultablebits
+  // stored value = value at lower edge of bin
+  // d values = delta from lower edge to upper edge of bin
+
+  if (ftable) free_tables();
+
+  memory->create(rtable,ntable,"pair:rtable");
+  memory->create(ftable,ntable,"pair:ftable");
+  memory->create(ctable,ntable,"pair:ctable");
+  memory->create(etable,ntable,"pair:etable");
+  memory->create(drtable,ntable,"pair:drtable");
+  memory->create(dftable,ntable,"pair:dftable");
+  memory->create(dctable,ntable,"pair:dctable");
+  memory->create(detable,ntable,"pair:detable");
+
+  if (cut_respa == NULL) {
+    vtable = ptable = dvtable = dptable = NULL;
+  } else {
+    memory->create(vtable,ntable*sizeof(double),"pair:vtable");
+    memory->create(ptable,ntable*sizeof(double),"pair:ptable");
+    memory->create(dvtable,ntable*sizeof(double),"pair:dvtable");
+    memory->create(dptable,ntable*sizeof(double),"pair:dptable");
+  }
+
+  union_int_float_t rsq_lookup;
+  union_int_float_t minrsq_lookup;
+  int itablemin;
+  minrsq_lookup.i = 0 << ncoulshiftbits;
+  minrsq_lookup.i |= maskhi;
+
+  for (int i = 0; i < ntable; i++) {
+    rsq_lookup.i = i << ncoulshiftbits;
+    rsq_lookup.i |= masklo;
+    if (rsq_lookup.f < tabinnersq) {
+      rsq_lookup.i = i << ncoulshiftbits;
+      rsq_lookup.i |= maskhi;
+    }
+    r = sqrtf(rsq_lookup.f);
+    grij = g_ewald * r;
+    expm2 = exp(-grij*grij);
+    derfc = erfc(grij);
+    if (cut_respa == NULL) {
+      rtable[i] = rsq_lookup.f;
+      ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+      ctable[i] = qqrd2e/r;
+      etable[i] = qqrd2e/r * derfc;
+    } else {
+      rtable[i] = rsq_lookup.f;
+      ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2 - 1.0);
+      ctable[i] = 0.0;
+      etable[i] = qqrd2e/r * derfc;
+      ptable[i] = qqrd2e/r;
+      vtable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+      if (rsq_lookup.f > cut_respa[2]*cut_respa[2]) {
+        if (rsq_lookup.f < cut_respa[3]*cut_respa[3]) {
+          rsw = (r - cut_respa[2])/(cut_respa[3] - cut_respa[2]);
+          ftable[i] += qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
+          ctable[i] = qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
+        } else {
+          ftable[i] = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+          ctable[i] = qqrd2e/r;
+        }
+      }
+    }
+    minrsq_lookup.f = MIN(minrsq_lookup.f,rsq_lookup.f);
+  }
+
+  tabinnersq = minrsq_lookup.f;
+
+  int ntablem1 = ntable - 1;
+
+  for (int i = 0; i < ntablem1; i++) {
+    drtable[i] = 1.0/(rtable[i+1] - rtable[i]);
+    dftable[i] = ftable[i+1] - ftable[i];
+    dctable[i] = ctable[i+1] - ctable[i];
+    detable[i] = etable[i+1] - etable[i];
+  }
+
+  if (cut_respa) {
+    for (int i = 0; i < ntablem1; i++) {
+      dvtable[i] = vtable[i+1] - vtable[i];
+      dptable[i] = ptable[i+1] - ptable[i];
+    }
+  }
+
+  // get the delta values for the last table entries
+  // tables are connected periodically between 0 and ntablem1
+
+  drtable[ntablem1] = 1.0/(rtable[0] - rtable[ntablem1]);
+  dftable[ntablem1] = ftable[0] - ftable[ntablem1];
+  dctable[ntablem1] = ctable[0] - ctable[ntablem1];
+  detable[ntablem1] = etable[0] - etable[ntablem1];
+  if (cut_respa) {
+    dvtable[ntablem1] = vtable[0] - vtable[ntablem1];
+    dptable[ntablem1] = ptable[0] - ptable[ntablem1];
+  }
+
+  // get the correct delta values at itablemax
+  // smallest r is in bin itablemin
+  // largest r is in bin itablemax, which is itablemin-1,
+  //   or ntablem1 if itablemin=0
+  // deltas at itablemax only needed if corresponding rsq < cut*cut
+  // if so, compute deltas between rsq and cut*cut
+
+  double f_tmp,c_tmp,e_tmp,p_tmp,v_tmp;
+  itablemin = minrsq_lookup.i & ncoulmask;
+  itablemin >>= ncoulshiftbits;
+  int itablemax = itablemin - 1;
+  if (itablemin == 0) itablemax = ntablem1;
+  rsq_lookup.i = itablemax << ncoulshiftbits;
+  rsq_lookup.i |= maskhi;
+
+  if (rsq_lookup.f < cut_coulsq) {
+    rsq_lookup.f = cut_coulsq;
+    r = sqrtf(rsq_lookup.f);
+    grij = g_ewald * r;
+    expm2 = exp(-grij*grij);
+    derfc = erfc(grij);
+
+    if (cut_respa == NULL) {
+      f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+      c_tmp = qqrd2e/r;
+      e_tmp = qqrd2e/r * derfc;
+    } else {
+      f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2 - 1.0);
+      c_tmp = 0.0;
+      e_tmp = qqrd2e/r * derfc;
+      p_tmp = qqrd2e/r;
+      v_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+      if (rsq_lookup.f > cut_respa[2]*cut_respa[2]) {
+        if (rsq_lookup.f < cut_respa[3]*cut_respa[3]) {
+          rsw = (r - cut_respa[2])/(cut_respa[3] - cut_respa[2]);
+          f_tmp += qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
+          c_tmp = qqrd2e/r * rsw*rsw*(3.0 - 2.0*rsw);
+        } else {
+          f_tmp = qqrd2e/r * (derfc + EWALD_F*grij*expm2);
+          c_tmp = qqrd2e/r;
+        }
+      }
+    }
+
+    drtable[itablemax] = 1.0/(rsq_lookup.f - rtable[itablemax]);
+    dftable[itablemax] = f_tmp - ftable[itablemax];
+    dctable[itablemax] = c_tmp - ctable[itablemax];
+    detable[itablemax] = e_tmp - etable[itablemax];
+    if (cut_respa) {
+      dvtable[itablemax] = v_tmp - vtable[itablemax];
+      dptable[itablemax] = p_tmp - ptable[itablemax];
+    }
+  }
+}
+
+/* ----------------------------------------------------------------------
+  proc 0 writes to restart file
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::write_restart(FILE *fp)
+{
+  write_restart_settings(fp);
+
+  int i,j;
+  for (i = 1; i <= atom->ntypes; i++)
+    for (j = i; j <= atom->ntypes; j++) {
+      fwrite(&setflag[i][j],sizeof(int),1,fp);
+      if (setflag[i][j]) {
+        fwrite(&epsilon[i][j],sizeof(double),1,fp);
+        fwrite(&sigma[i][j],sizeof(double),1,fp);
+        fwrite(&cut_lj[i][j],sizeof(double),1,fp);
+      }
+    }
+}
+
+/* ----------------------------------------------------------------------
+  proc 0 reads from restart file, bcasts
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::read_restart(FILE *fp)
+{
+  read_restart_settings(fp);
+
+  allocate();
+
+  int i,j;
+  int me = comm->me;
+  for (i = 1; i <= atom->ntypes; i++)
+    for (j = i; j <= atom->ntypes; j++) {
+      if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
+      MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
+      if (setflag[i][j]) {
+        if (me == 0) {
+          fread(&epsilon[i][j],sizeof(double),1,fp);
+          fread(&sigma[i][j],sizeof(double),1,fp);
+          fread(&cut_lj[i][j],sizeof(double),1,fp);
+        }
+        MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world);
+        MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world);
+        MPI_Bcast(&cut_lj[i][j],1,MPI_DOUBLE,0,world);
+      }
+    }
+}
+
+/* ----------------------------------------------------------------------
+  proc 0 writes to restart file
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::write_restart_settings(FILE *fp)
+{
+  fwrite(&cut_lj_global,sizeof(double),1,fp);
+  fwrite(&cut_coul,sizeof(double),1,fp);
+  fwrite(&offset_flag,sizeof(int),1,fp);
+  fwrite(&mix_flag,sizeof(int),1,fp);
+}
+
+/* ----------------------------------------------------------------------
+  proc 0 reads from restart file, bcasts
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::read_restart_settings(FILE *fp)
+{
+  if (comm->me == 0) {
+    fread(&cut_lj_global,sizeof(double),1,fp);
+    fread(&cut_coul,sizeof(double),1,fp);
+    fread(&offset_flag,sizeof(int),1,fp);
+    fread(&mix_flag,sizeof(int),1,fp);
+  }
+  MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);
+  MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);
+  MPI_Bcast(&offset_flag,1,MPI_INT,0,world);
+  MPI_Bcast(&mix_flag,1,MPI_INT,0,world);
+}
+
+/* ----------------------------------------------------------------------
+   free memory for tables used in pair computations
+------------------------------------------------------------------------- */
+
+void PairLJCutCoulLong::free_tables()
+{
+  memory->destroy(rtable);
+  memory->destroy(drtable);
+  memory->destroy(ftable);
+  memory->destroy(dftable);
+  memory->destroy(ctable);
+  memory->destroy(dctable);
+  memory->destroy(etable);
+  memory->destroy(detable);
+  memory->destroy(vtable);
+  memory->destroy(dvtable);
+  memory->destroy(ptable);
+  memory->destroy(dptable);
+}
+
+/* ---------------------------------------------------------------------- */
+
+double PairLJCutCoulLong::single(int i, int j, int itype, int jtype,
+                                 double rsq,
+                                 double factor_coul, double factor_lj,
+                                 double &fforce)
+{
+  double r2inv,r6inv,r,grij,expm2,t,erfc,prefactor;
+  double fraction,table,forcecoul,forcelj,phicoul,philj;
+  int itable;
+
+  r2inv = 1.0/rsq;
+  if (rsq < cut_coulsq) {
+    if (!ncoultablebits || rsq <= tabinnersq) {
+      r = sqrt(rsq);
+      grij = g_ewald * r;
+      expm2 = exp(-grij*grij);
+      t = 1.0 / (1.0 + EWALD_P*grij);
+      erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
+      prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r;
+      forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
+      if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor;
+    } else {
+      union_int_float_t rsq_lookup_single;
+      rsq_lookup_single.f = rsq;
+      itable = rsq_lookup_single.i & ncoulmask;
+      itable >>= ncoulshiftbits;
+      fraction = (rsq_lookup_single.f - rtable[itable]) * drtable[itable];
+      table = ftable[itable] + fraction*dftable[itable];
+      forcecoul = atom->q[i]*atom->q[j] * table;
+      if (factor_coul < 1.0) {
+        table = ctable[itable] + fraction*dctable[itable];
+        prefactor = atom->q[i]*atom->q[j] * table;
+        forcecoul -= (1.0-factor_coul)*prefactor;
+      }
+    }
+  } else forcecoul = 0.0;
+
+  if (rsq < cut_ljsq[itype][jtype]) {
+    r6inv = r2inv*r2inv*r2inv;
+    forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
+  } else forcelj = 0.0;
+
+  fforce = (forcecoul + factor_lj*forcelj) * r2inv;
+
+  double eng = 0.0;
+  if (rsq < cut_coulsq) {
+    if (!ncoultablebits || rsq <= tabinnersq)
+      phicoul = prefactor*erfc;
+    else {
+      table = etable[itable] + fraction*detable[itable];
+      phicoul = atom->q[i]*atom->q[j] * table;
+    }
+    if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor;
+    eng += phicoul;
+  }
+
+  if (rsq < cut_ljsq[itype][jtype]) {
+    philj = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
+      offset[itype][jtype];
+    eng += factor_lj*philj;
+  }
+
+  return eng;
+}
+
+/* ---------------------------------------------------------------------- */
+
+void *PairLJCutCoulLong::extract(const char *str, int &dim)
+{
+  dim = 0;
+  if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul;
+  dim = 2;
+  if (strcmp(str,"epsilon") == 0) return (void *) epsilon;
+  return NULL;
+}
diff --git a/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp b/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp
index d66ca1f5f..3a3c2b11e 100644
--- a/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp
+++ b/src/KSPACE/pair_lj_cut_coul_long_tip4p.cpp
@@ -1,617 +1,616 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: Amalie Frischknecht and Ahmed Ismail (SNL)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "string.h"
 #include "pair_lj_cut_coul_long_tip4p.h"
 #include "angle.h"
 #include "atom.h"
 #include "bond.h"
 #include "comm.h"
 #include "domain.h"
 #include "force.h"
 #include "kspace.h"
 #include "update.h"
 #include "respa.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define EWALD_F   1.12837917
 #define EWALD_P   0.3275911
 #define A1        0.254829592
 #define A2       -0.284496736
 #define A3        1.421413741
 #define A4       -1.453152027
 #define A5        1.061405429
 
 /* ---------------------------------------------------------------------- */
 
 PairLJCutCoulLongTIP4P::PairLJCutCoulLongTIP4P(LAMMPS *lmp) :
   PairLJCutCoulLong(lmp)
 {
   single_enable = 0;
   respa_enable = 0;
 
   nmax = 0;
   hneigh = NULL;
   newsite = NULL;
 
   // TIP4P cannot compute virial as F dot r
   // due to finding bonded H atoms which are not near O atom
 
   no_virial_fdotr_compute = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 PairLJCutCoulLongTIP4P::~PairLJCutCoulLongTIP4P()
 {
   memory->destroy(hneigh);
   memory->destroy(newsite);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::compute(int eflag, int vflag)
 {
   int i,j,ii,jj,inum,jnum,itype,jtype,itable;
   int n,vlist[6];
   int iH1,iH2,jH1,jH2;
   double qtmp,xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul;
   double fraction,table;
   double delxOM, delyOM, delzOM;
   double r,r2inv,r6inv,forcecoul,forcelj,cforce;
   double factor_coul,factor_lj;
   double grij,expm2,prefactor,t,erfc,ddotf;
   double xiM[3],xjM[3],fO[3],fH[3],fd[3],f1[3],v[6],xH1[3],xH2[3];
   double *x1,*x2;
   int *ilist,*jlist,*numneigh,**firstneigh;
   double rsq;
 
   evdwl = ecoul = 0.0;
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = 0;
 
   // reallocate hneigh & newsite if necessary
   // initialize hneigh[0] to -1 on steps when reneighboring occurred
   // initialize hneigh[2] to 0 every step
 
   int nlocal = atom->nlocal;
   int nall = nlocal + atom->nghost;
 
   if (atom->nmax > nmax) {
     nmax = atom->nmax;
     memory->destroy(hneigh);
     memory->create(hneigh,nmax,3,"pair:hneigh");
     memory->destroy(newsite);
     memory->create(newsite,nmax,3,"pair:newsite");
   }
   if (neighbor->ago == 0)
     for (i = 0; i < nall; i++) hneigh[i][0] = -1;
   for (i = 0; i < nall; i++) hneigh[i][2] = 0;
 
   double **f = atom->f;
   double **x = atom->x;
   double *q = atom->q;
   int *type = atom->type;
   double *special_coul = force->special_coul;
   double *special_lj = force->special_lj;
   int newton_pair = force->newton_pair;
   double qqrd2e = force->qqrd2e;
   double cut_coulsqplus = (cut_coul+2.0*qdist) * (cut_coul+2.0*qdist);
 
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   // loop over neighbors of my atoms
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     qtmp = q[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
     itype = type[i];
 
     // if atom I = water O, set x1 = offset charge site
     // else x1 = x of atom I
 
     if (itype == typeO) {
       if (hneigh[i][0] < 0) {
         hneigh[i][0] = iH1 = atom->map(atom->tag[i] + 1);
         hneigh[i][1] = iH2 = atom->map(atom->tag[i] + 2);
         hneigh[i][2] = 1;
         if (iH1 == -1 || iH2 == -1)
           error->one(FLERR,"TIP4P hydrogen is missing");
         if (atom->type[iH1] != typeH || atom->type[iH2] != typeH)
           error->one(FLERR,"TIP4P hydrogen has incorrect atom type");
         compute_newsite(x[i],x[iH1],x[iH2],newsite[i]);
       } else {
         iH1 = hneigh[i][0];
         iH2 = hneigh[i][1];
         if (hneigh[i][2] == 0) {
           hneigh[i][2] = 1;
           compute_newsite(x[i],x[iH1],x[iH2],newsite[i]);
         }
       }
       x1 = newsite[i];
     } else x1 = x[i];
 
     jlist = firstneigh[i];
     jnum = numneigh[i];
 
     for (jj = 0; jj < jnum; jj++) {
       j = jlist[jj];
       factor_lj = special_lj[sbmask(j)];
       factor_coul = special_coul[sbmask(j)];
       j &= NEIGHMASK;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
       jtype = type[j];
 
       // LJ interaction based on true rsq
 
       if (rsq < cut_ljsq[itype][jtype]) {
         r2inv = 1.0/rsq;
         r6inv = r2inv*r2inv*r2inv;
         forcelj = r6inv * (lj1[itype][jtype]*r6inv - lj2[itype][jtype]);
         forcelj *= factor_lj * r2inv;
 
         f[i][0] += delx*forcelj;
         f[i][1] += dely*forcelj;
         f[i][2] += delz*forcelj;
         f[j][0] -= delx*forcelj;
         f[j][1] -= dely*forcelj;
         f[j][2] -= delz*forcelj;
 
         if (eflag) {
           evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) -
             offset[itype][jtype];
           evdwl *= factor_lj;
         } else evdwl = 0.0;
 
         if (evflag) ev_tally(i,j,nlocal,newton_pair,
                              evdwl,0.0,forcelj,delx,dely,delz);
       }
 
       // adjust rsq and delxyz for off-site O charge(s) if necessary
       // but only if they are within reach
 
       if (rsq < cut_coulsqplus) {
         if (itype == typeO || jtype == typeO) {
 
           // if atom J = water O, set x2 = offset charge site
           // else x2 = x of atom J
 
           if (jtype == typeO) {
             if (hneigh[j][0] < 0) {
               hneigh[j][0] = jH1 = atom->map(atom->tag[j] + 1);
               hneigh[j][1] = jH2 = atom->map(atom->tag[j] + 2);
               hneigh[j][2] = 1;
               if (jH1 == -1 || jH2 == -1)
                 error->one(FLERR,"TIP4P hydrogen is missing");
               if (atom->type[jH1] != typeH || atom->type[jH2] != typeH)
                 error->one(FLERR,"TIP4P hydrogen has incorrect atom type");
               compute_newsite(x[j],x[jH1],x[jH2],newsite[j]);
             } else {
               jH1 = hneigh[j][0];
               jH2 = hneigh[j][1];
               if (hneigh[j][2] == 0) {
                 hneigh[j][2] = 1;
                 compute_newsite(x[j],x[jH1],x[jH2],newsite[j]);
               }
             }
             x2 = newsite[j];
           } else x2 = x[j];
 
           delx = x1[0] - x2[0];
           dely = x1[1] - x2[1];
           delz = x1[2] - x2[2];
           rsq = delx*delx + dely*dely + delz*delz;
         }
 
         // Coulombic interaction based on modified rsq
 
         if (rsq < cut_coulsq) {
           r2inv = 1 / rsq;
           if (!ncoultablebits || rsq <= tabinnersq) {
             r = sqrt(rsq);
             grij = g_ewald * r;
             expm2 = exp(-grij*grij);
             t = 1.0 / (1.0 + EWALD_P*grij);
             erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2;
             prefactor = qqrd2e * qtmp*q[j]/r;
             forcecoul = prefactor * (erfc + EWALD_F*grij*expm2);
             if (factor_coul < 1.0) {
               forcecoul -= (1.0-factor_coul)*prefactor;
             }
           } else {
             union_int_float_t rsq_lookup;
             rsq_lookup.f = rsq;
             itable = rsq_lookup.i & ncoulmask;
             itable >>= ncoulshiftbits;
             fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable];
             table = ftable[itable] + fraction*dftable[itable];
             forcecoul = qtmp*q[j] * table;
             if (factor_coul < 1.0) {
               table = ctable[itable] + fraction*dctable[itable];
               prefactor = qtmp*q[j] * table;
               forcecoul -= (1.0-factor_coul)*prefactor;
             }
           }
 
           cforce = forcecoul * r2inv;
 
           // if i,j are not O atoms, force is applied directly
           // if i or j are O atoms, force is on fictitious atom & partitioned
           // force partitioning due to Feenstra, J Comp Chem, 20, 786 (1999)
           // f_f = fictitious force, fO = f_f (1 - 2 alpha), fH = alpha f_f
           // preserves total force and torque on water molecule
           // virial = sum(r x F) where each water's atoms are near xi and xj
           // vlist stores 2,4,6 atoms whose forces contribute to virial
 
           n = 0;
 
           if (itype != typeO) {
             f[i][0] += delx * cforce;
             f[i][1] += dely * cforce;
             f[i][2] += delz * cforce;
 
             if (vflag) {
               v[0] = x[i][0] * delx * cforce;
               v[1] = x[i][1] * dely * cforce;
               v[2] = x[i][2] * delz * cforce;
               v[3] = x[i][0] * dely * cforce;
               v[4] = x[i][0] * delz * cforce;
               v[5] = x[i][1] * delz * cforce;
               vlist[n++] = i;
             }
 
           } else {
 
             fd[0] = delx*cforce;
             fd[1] = dely*cforce;
             fd[2] = delz*cforce;
 
             delxOM = x[i][0] - x1[0];
             delyOM = x[i][1] - x1[1];
             delzOM = x[i][2] - x1[2];
 
             ddotf = (delxOM * fd[0] + delyOM * fd[1] + delzOM * fd[2]) /
               (qdist*qdist);
 
             f1[0] = ddotf * delxOM;
             f1[1] = ddotf * delyOM;
             f1[2] = ddotf * delzOM;
 
             fO[0] = fd[0] - alpha * (fd[0] - f1[0]);
             fO[1] = fd[1] - alpha * (fd[1] - f1[1]);
             fO[2] = fd[2] - alpha * (fd[2] - f1[2]);
 
             fH[0] = 0.5 * alpha * (fd[0] - f1[0]);
             fH[1] = 0.5 * alpha * (fd[1] - f1[1]);
             fH[2] = 0.5 * alpha * (fd[2] - f1[2]);
 
             f[i][0] += fO[0];
             f[i][1] += fO[1];
             f[i][2] += fO[2];
 
             f[iH1][0] += fH[0];
             f[iH1][1] += fH[1];
             f[iH1][2] += fH[2];
 
             f[iH2][0] += fH[0];
             f[iH2][1] += fH[1];
             f[iH2][2] += fH[2];
 
             if (vflag) {
               domain->closest_image(x[i],x[iH1],xH1);
               domain->closest_image(x[i],x[iH2],xH2);
 
               v[0] = x[i][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0];
               v[1] = x[i][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1];
               v[2] = x[i][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2];
               v[3] = x[i][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1];
               v[4] = x[i][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2];
               v[5] = x[i][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2];
 
               vlist[n++] = i;
               vlist[n++] = iH1;
               vlist[n++] = iH2;
             }
           }
 
           if (jtype != typeO) {
             f[j][0] -= delx * cforce;
             f[j][1] -= dely * cforce;
             f[j][2] -= delz * cforce;
 
             if (vflag) {
               v[0] -= x[j][0] * delx * cforce;
               v[1] -= x[j][1] * dely * cforce;
               v[2] -= x[j][2] * delz * cforce;
               v[3] -= x[j][0] * dely * cforce;
               v[4] -= x[j][0] * delz * cforce;
               v[5] -= x[j][1] * delz * cforce;
               vlist[n++] = j;
             }
 
           } else {
 
             fd[0] = -delx*cforce;
             fd[1] = -dely*cforce;
             fd[2] = -delz*cforce;
 
             delxOM = x[j][0] - x2[0];
             delyOM = x[j][1] - x2[1];
             delzOM = x[j][2] - x2[2];
 
             ddotf = (delxOM * fd[0] + delyOM * fd[1] + delzOM * fd[2]) /
               (qdist*qdist);
 
             f1[0] = ddotf * delxOM;
             f1[1] = ddotf * delyOM;
             f1[2] = ddotf * delzOM;
 
             fO[0] = fd[0] - alpha * (fd[0] - f1[0]);
             fO[1] = fd[1] - alpha * (fd[1] - f1[1]);
             fO[2] = fd[2] - alpha * (fd[2] - f1[2]);
 
             fH[0] = 0.5 * alpha * (fd[0] - f1[0]);
             fH[1] = 0.5 * alpha * (fd[1] - f1[1]);
             fH[2] = 0.5 * alpha * (fd[2] - f1[2]);
 
             f[j][0] += fO[0];
             f[j][1] += fO[1];
             f[j][2] += fO[2];
 
             f[jH1][0] += fH[0];
             f[jH1][1] += fH[1];
             f[jH1][2] += fH[2];
 
             f[jH2][0] += fH[0];
             f[jH2][1] += fH[1];
             f[jH2][2] += fH[2];
 
             if (vflag) {
               domain->closest_image(x[j],x[jH1],xH1);
               domain->closest_image(x[j],x[jH2],xH2);
 
               v[0] += x[j][0]*fO[0] + xH1[0]*fH[0] + xH2[0]*fH[0];
               v[1] += x[j][1]*fO[1] + xH1[1]*fH[1] + xH2[1]*fH[1];
               v[2] += x[j][2]*fO[2] + xH1[2]*fH[2] + xH2[2]*fH[2];
               v[3] += x[j][0]*fO[1] + xH1[0]*fH[1] + xH2[0]*fH[1];
               v[4] += x[j][0]*fO[2] + xH1[0]*fH[2] + xH2[0]*fH[2];
               v[5] += x[j][1]*fO[2] + xH1[1]*fH[2] + xH2[1]*fH[2];
 
               vlist[n++] = j;
               vlist[n++] = jH1;
               vlist[n++] = jH2;
             }
           }
 
           if (eflag) {
             if (!ncoultablebits || rsq <= tabinnersq)
               ecoul = prefactor*erfc;
             else {
               table = etable[itable] + fraction*detable[itable];
               ecoul = qtmp*q[j] * table;
             }
             if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor;
           } else ecoul = 0.0;
 
           if (evflag) ev_tally_list(n,vlist,ecoul,v);
         }
       }
     }
   }
 }
 
 /* ----------------------------------------------------------------------
    global settings
 ------------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::settings(int narg, char **arg)
 {
   if (narg < 6 || narg > 7) error->all(FLERR,"Illegal pair_style command");
 
   typeO = force->inumeric(arg[0]);
   typeH = force->inumeric(arg[1]);
   typeB = force->inumeric(arg[2]);
   typeA = force->inumeric(arg[3]);
   qdist = force->numeric(arg[4]);
 
   cut_lj_global = force->numeric(arg[5]);
   if (narg == 6) cut_coul = cut_lj_global;
   else cut_coul = force->numeric(arg[6]);
 
   // reset cutoffs that have been explicitly set
 
   if (allocated) {
     int i,j;
     for (i = 1; i <= atom->ntypes; i++)
       for (j = i+1; j <= atom->ntypes; j++)
         if (setflag[i][j]) cut_lj[i][j] = cut_lj_global;
   }
 }
 
 /* ----------------------------------------------------------------------
    init specific to this pair style
 ------------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::init_style()
 {
   if (atom->tag_enable == 0)
     error->all(FLERR,"Pair style lj/cut/coul/long/tip4p requires atom IDs");
   if (!force->newton_pair)
     error->all(FLERR,
                "Pair style lj/cut/coul/long/tip4p requires newton pair on");
   if (!atom->q_flag)
     error->all(FLERR,
                "Pair style lj/cut/coul/long/tip4p requires atom attribute q");
   if ( (strcmp(force->kspace_style,"pppm/tip4p") != 0) &&
        (strcmp(force->kspace_style,"pppm/tip4p/omp") != 0) &&
        (strcmp(force->kspace_style,"pppm/tip4p/proxy") != 0) )
     error->all(FLERR,"Pair style is incompatible with KSpace style");
   if (force->bond == NULL)
     error->all(FLERR,"Must use a bond style with TIP4P potential");
   if (force->angle == NULL)
     error->all(FLERR,"Must use an angle style with TIP4P potential");
 
   PairLJCutCoulLong::init_style();
 
   // set alpha parameter
 
   double theta = force->angle->equilibrium_angle(typeA);
   double blen = force->bond->equilibrium_distance(typeB);
   alpha = qdist / (cos(0.5*theta) * blen);
 }
 
 /* ----------------------------------------------------------------------
    init for one type pair i,j and corresponding j,i
 ------------------------------------------------------------------------- */
 
 double PairLJCutCoulLongTIP4P::init_one(int i, int j)
 {
   double cut = PairLJCutCoulLong::init_one(i,j);
 
   // check that LJ epsilon = 0.0 for water H
   // set LJ cutoff to 0.0 for any interaction involving water H
   // so LJ term isn't calculated in compute()
 
   if ((i == typeH && epsilon[i][i] != 0.0) ||
       (j == typeH && epsilon[j][j] != 0.0))
     error->all(FLERR,"Water H epsilon must be 0.0 for "
                "pair style lj/cut/coul/long/tip4p");
 
   if (i == typeH || j == typeH)
     cut_ljsq[j][i] = cut_ljsq[i][j] = 0.0;
 
   return cut;
 }
 
 /* ----------------------------------------------------------------------
   proc 0 writes to restart file
 ------------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::write_restart_settings(FILE *fp)
 {
   fwrite(&typeO,sizeof(int),1,fp);
   fwrite(&typeH,sizeof(int),1,fp);
   fwrite(&typeB,sizeof(int),1,fp);
   fwrite(&typeA,sizeof(int),1,fp);
   fwrite(&qdist,sizeof(double),1,fp);
 
   fwrite(&cut_lj_global,sizeof(double),1,fp);
   fwrite(&cut_coul,sizeof(double),1,fp);
   fwrite(&offset_flag,sizeof(int),1,fp);
   fwrite(&mix_flag,sizeof(int),1,fp);
 }
 
 /* ----------------------------------------------------------------------
   proc 0 reads from restart file, bcasts
 ------------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::read_restart_settings(FILE *fp)
 {
   if (comm->me == 0) {
     fread(&typeO,sizeof(int),1,fp);
     fread(&typeH,sizeof(int),1,fp);
     fread(&typeB,sizeof(int),1,fp);
     fread(&typeA,sizeof(int),1,fp);
     fread(&qdist,sizeof(double),1,fp);
 
     fread(&cut_lj_global,sizeof(double),1,fp);
     fread(&cut_coul,sizeof(double),1,fp);
     fread(&offset_flag,sizeof(int),1,fp);
     fread(&mix_flag,sizeof(int),1,fp);
   }
 
   MPI_Bcast(&typeO,1,MPI_INT,0,world);
   MPI_Bcast(&typeH,1,MPI_INT,0,world);
   MPI_Bcast(&typeB,1,MPI_INT,0,world);
   MPI_Bcast(&typeA,1,MPI_INT,0,world);
   MPI_Bcast(&qdist,1,MPI_DOUBLE,0,world);
 
   MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&offset_flag,1,MPI_INT,0,world);
   MPI_Bcast(&mix_flag,1,MPI_INT,0,world);
 
 }
 
 /* ----------------------------------------------------------------------
   compute position xM of fictitious charge site for O atom and 2 H atoms
   return it as xM
 ------------------------------------------------------------------------- */
 
 void PairLJCutCoulLongTIP4P::compute_newsite(double *xO, double *xH1,
                                              double *xH2, double *xM)
 {
   double delx1 = xH1[0] - xO[0];
   double dely1 = xH1[1] - xO[1];
   double delz1 = xH1[2] - xO[2];
   domain->minimum_image(delx1,dely1,delz1);
 
   double delx2 = xH2[0] - xO[0];
   double dely2 = xH2[1] - xO[1];
   double delz2 = xH2[2] - xO[2];
   domain->minimum_image(delx2,dely2,delz2);
 
   xM[0] = xO[0] + alpha * 0.5 * (delx1 + delx2);
   xM[1] = xO[1] + alpha * 0.5 * (dely1 + dely2);
   xM[2] = xO[2] + alpha * 0.5 * (delz1 + delz2);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void *PairLJCutCoulLongTIP4P::extract(const char *str, int &dim)
 {
   dim = 0;
   if (strcmp(str,"qdist") == 0) return (void *) &qdist;
   if (strcmp(str,"typeO") == 0) return (void *) &typeO;
   if (strcmp(str,"typeH") == 0) return (void *) &typeH;
   if (strcmp(str,"typeA") == 0) return (void *) &typeA;
   if (strcmp(str,"typeB") == 0) return (void *) &typeB;
   if (strcmp(str,"cut_coul") == 0) return (void *) &cut_coul;
   return NULL;
 }
 
 /* ----------------------------------------------------------------------
    memory usage of hneigh
 ------------------------------------------------------------------------- */
 
 double PairLJCutCoulLongTIP4P::memory_usage()
 {
   double bytes = maxeatom * sizeof(double);
   bytes += maxvatom*6 * sizeof(double);
   bytes += 2 * nmax * sizeof(double);
   return bytes;
 }
-
diff --git a/src/MANYBODY/fix_qeq_comb.cpp b/src/MANYBODY/fix_qeq_comb.cpp
index 364ae03cf..6dbc12c52 100644
--- a/src/MANYBODY/fix_qeq_comb.cpp
+++ b/src/MANYBODY/fix_qeq_comb.cpp
@@ -1,308 +1,307 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Tzu-Ray Shan (U Florida, rayshan@ufl.edu)
 ------------------------------------------------------------------------- */
 
 #include "lmptype.h"
 #include "mpi.h"
 #include "math.h"
 #include "stdlib.h"
 #include "string.h"
 #include "pair_comb.h"
 #include "fix_qeq_comb.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "atom.h"
 #include "comm.h"
 #include "force.h"
 #include "group.h"
 #include "respa.h"
 #include "update.h"
 #include "memory.h"
 #include "error.h"
 #include "iostream"
 using namespace LAMMPS_NS;
 using namespace FixConst;
 
 /* ---------------------------------------------------------------------- */
 
 FixQEQComb::FixQEQComb(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
 {
   if (narg < 5) error->all(FLERR,"Illegal fix qeq/comb command");
 
   peratom_flag = 1;
   size_peratom_cols = 0;
   peratom_freq = 1;
 
   nevery = force->inumeric(arg[3]);
   precision = force->numeric(arg[4]);
 
   if (nevery <= 0 || precision <= 0.0)
     error->all(FLERR,"Illegal fix qeq/comb command");
 
   MPI_Comm_rank(world,&me);
 
   // optional args
 
   fp = NULL;
 
   int iarg = 5;
   while (iarg < narg) {
     if (strcmp(arg[iarg],"file") == 0) {
       if (iarg+2 > narg) error->all(FLERR,"Illegal fix qeq/comb command");
       if (me == 0) {
-	fp = fopen(arg[iarg+1],"w");
-	if (fp == NULL) {
-	  char str[128];
-	  sprintf(str,"Cannot open fix qeq/comb file %s",arg[iarg+1]);
-	  error->one(FLERR,str);
-	}
+        fp = fopen(arg[iarg+1],"w");
+        if (fp == NULL) {
+          char str[128];
+          sprintf(str,"Cannot open fix qeq/comb file %s",arg[iarg+1]);
+          error->one(FLERR,str);
+        }
       }
       iarg += 2;
     } else error->all(FLERR,"Illegal fix qeq/comb command");
   }
-  
+
   nmax = atom->nmax;
   memory->create(qf,nmax,"qeq:qf");
   memory->create(q1,nmax,"qeq:q1");
   memory->create(q2,nmax,"qeq:q2");
   vector_atom = qf;
 
   // zero the vector since dump may access it on timestep 0
   // zero the vector since a variable may access it before first run
 
   int nlocal = atom->nlocal;
   for (int i = 0; i < nlocal; i++) qf[i] = 0.0;
 
   comb = NULL;
 
   comm_forward = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 FixQEQComb::~FixQEQComb()
 {
   if (me == 0 && fp) fclose(fp);
   memory->destroy(qf);
   memory->destroy(q1);
   memory->destroy(q2);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int FixQEQComb::setmask()
 {
   int mask = 0;
   mask |= POST_FORCE;
   mask |= POST_FORCE_RESPA;
   return mask;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQComb::init()
 {
   if (!atom->q_flag)
     error->all(FLERR,"Fix qeq/comb requires atom attribute q");
 
   comb = (PairComb *) force->pair_match("comb",1);
-  if (comb == NULL) 
+  if (comb == NULL)
     error->all(FLERR,"Must use pair_style comb with fix qeq/comb");
 
   if (strstr(update->integrate_style,"respa"))
     nlevels_respa = ((Respa *) update->integrate)->nlevels;
 
   ngroup = group->count(igroup);
   if (ngroup == 0) error->all(FLERR,"Fix qeq/comb group has no atoms");
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->pair = 0;
   neighbor->requests[irequest]->fix = 1;
   neighbor->requests[irequest]->half = 0;
   neighbor->requests[irequest]->full = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQComb::setup(int vflag)
 {
   firstflag = 1;
   if (strstr(update->integrate_style,"verlet"))
     post_force(vflag);
   else {
     ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
     post_force_respa(vflag,nlevels_respa-1,0);
     ((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
   }
   firstflag = 0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQComb::post_force(int vflag)
 {
   int i,ii,iloop,loopmax,inum,*ilist;
   double heatpq,qmass,dtq,dtq2;
   double enegchkall,enegmaxall;
 
   if (update->ntimestep % nevery) return;
 
   // reallocate work arrays if necessary
   // qf = charge force
   // q1 = charge displacement
   // q2 = tmp storage of charge force for next iteration
 
   if (atom->nmax > nmax) {
     memory->destroy(qf);
     memory->destroy(q1);
     memory->destroy(q2);
     nmax = atom->nmax;
     memory->create(qf,nmax,"qeq:qf");
     memory->create(q1,nmax,"qeq:q1");
     memory->create(q2,nmax,"qeq:q2");
     vector_atom = qf;
   }
-  
+
   // more loops for first-time charge equilibrium
 
-  iloop = 0; 
+  iloop = 0;
   if (firstflag) loopmax = 500;
   else loopmax = 200;
 
   // charge-equilibration loop
 
   if (me == 0 && fp)
     fprintf(fp,"Charge equilibration on step " BIGINT_FORMAT "\n",
-	    update->ntimestep);
-  
+            update->ntimestep);
+
   heatpq = 0.05;
   qmass  = 0.016;
   dtq    = 0.01;
   dtq2   = 0.5*dtq*dtq/qmass;
 
   double enegchk = 0.0;
-  double enegtot = 0.0; 
+  double enegtot = 0.0;
   double enegmax = 0.0;
 
   double *q = atom->q;
   int *mask = atom->mask;
   int *tag = atom->tag;
   int nlocal = atom->nlocal;
 
   inum = comb->list->inum;
   ilist = comb->list->ilist;
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     q1[i] = q2[i] = qf[i] = 0.0;
   }
 
   for (iloop = 0; iloop < loopmax; iloop ++ ) {
     for (ii = 0; ii < inum; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit) {
-	q1[i] += qf[i]*dtq2 - heatpq*q1[i];
-	q[i]  += q1[i]; 
+        q1[i] += qf[i]*dtq2 - heatpq*q1[i];
+        q[i]  += q1[i];
       }
     }
     comm->forward_comm_fix(this);
 
     if(comb) enegtot = comb->yasu_char(qf,igroup);
     enegtot /= ngroup;
     enegchk = enegmax = 0.0;
-    
+
     for (ii = 0; ii < inum ; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit) {
-	q2[i] = enegtot-qf[i];
-	enegmax = MAX(enegmax,fabs(q2[i]));
-	enegchk += fabs(q2[i]);
-	qf[i] = q2[i];
+        q2[i] = enegtot-qf[i];
+        enegmax = MAX(enegmax,fabs(q2[i]));
+        enegchk += fabs(q2[i]);
+        qf[i] = q2[i];
       }
     }
 
     MPI_Allreduce(&enegchk,&enegchkall,1,MPI_DOUBLE,MPI_SUM,world);
     enegchk = enegchkall/ngroup;
     MPI_Allreduce(&enegmax,&enegmaxall,1,MPI_DOUBLE,MPI_MAX,world);
     enegmax = enegmaxall;
-  
+
     if (enegchk <= precision && enegmax <= 100.0*precision) break;
 
     if (me == 0 && fp)
       fprintf(fp,"  iteration: %d, enegtot %.6g, "
-	      "enegmax %.6g, fq deviation: %.6g\n",
-	      iloop,enegtot,enegmax,enegchk); 
-    
+              "enegmax %.6g, fq deviation: %.6g\n",
+              iloop,enegtot,enegmax,enegchk);
+
     for (ii = 0; ii < inum; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit)
-	q1[i] += qf[i]*dtq2 - heatpq*q1[i]; 
+        q1[i] += qf[i]*dtq2 - heatpq*q1[i];
     }
-  } 
-  
+  }
+
   if (me == 0 && fp) {
     if (iloop == loopmax)
       fprintf(fp,"Charges did not converge in %d iterations\n",iloop);
     else
       fprintf(fp,"Charges converged in %d iterations to %.10f tolerance\n",
-	      iloop,enegchk);
+              iloop,enegchk);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQComb::post_force_respa(int vflag, int ilevel, int iloop)
 {
   if (ilevel == nlevels_respa-1) post_force(vflag);
 }
 
 /* ----------------------------------------------------------------------
    memory usage of local atom-based arrays
 ------------------------------------------------------------------------- */
 
 double FixQEQComb::memory_usage()
 {
   double bytes = atom->nmax*3 * sizeof(double);
   return bytes;
 }
 /* ---------------------------------------------------------------------- */
 
 int FixQEQComb::pack_comm(int n, int *list, double *buf, int pbc_flag, int *pbc)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i ++) {
     j = list[i];
     buf[m++] = atom->q[j];
   }
   return 1;
-}   
-    
+}
+
 /* ---------------------------------------------------------------------- */
-    
+
 void FixQEQComb::unpack_comm(int n, int first, double *buf)
-{   
+{
   int i,m,last;
-  
-  m = 0; 
+
+  m = 0;
   last = first + n ;
   for (i = first; i < last; i++) atom->q[i] = buf[m++];
-} 
+}
 
 /* ---------------------------------------------------------------------- */
-    
diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp
index 2d027bc83..a66fa34d4 100644
--- a/src/MANYBODY/pair_bop.cpp
+++ b/src/MANYBODY/pair_bop.cpp
@@ -1,9547 +1,9547 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing authors: D.K. Ward (donward@sandia.gov) and X.W. Zhou (Sandia)
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    The formulation for this work follows (a) D.G. Pettifor, et al., Mat.
    Sci. and Eng. A365, 2-13, (2004);(b) D.A. Murdick, et al., Phys.
    Rev. B 73, 045206 (2006);(c) D.G. Pettifor and I.I. Oleinik., Phys
-   Rev. Lett. 84, 4124 (2000); (d) D.K. Ward, et al., Phys. Rev. B 85, 
+   Rev. Lett. 84, 4124 (2000); (d) D.K. Ward, et al., Phys. Rev. B 85,
    115206 (2012).
 
    Copyright (2012) Sandia Corporation.  Under the terms of Contract DE-
    AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    rights in this software.
 
    pairbop v 1.0 comes with no warranty of any kind.  pairbop v 1.0 is a
    copyrighted code that is distributed free-of-charge, under the terms
    of the GNU Public License (GPL).  See "Open-Source
    Rules"_http://lammps.sandia.gov/open_source.html
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "string.h"
 #include "mpi.h"
 #include "pair_bop.h"
 #include "atom.h"
 #include "neighbor.h"
 #include "neigh_request.h"
 #include "force.h"
 #include "timer.h"
 #include "comm.h"
 #include "domain.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define MAXLINE 1024
 #define EPSILON 1.0e-6
 
 /* ---------------------------------------------------------------------- */
 
 PairBOP::PairBOP(LAMMPS *lmp) : Pair(lmp)
 {
   single_enable = 0;
   one_coeff = 1;
   map = NULL;
   pi_a = NULL;
   pro_delta = NULL;
   pi_delta = NULL;
   pi_p = NULL;
   pi_c = NULL;
   sigma_r0 = NULL;
   pi_r0 = NULL;
   phi_r0 = NULL;
   sigma_rc = NULL;
   pi_rc = NULL;
   phi_rc = NULL;
   r1 = NULL;
   sigma_beta0 = NULL;
   pi_beta0 = NULL;
   phi0 = NULL;
   sigma_n = NULL;
   pi_n = NULL;
   phi_m = NULL;
   sigma_nc = NULL;
   pi_nc = NULL;
   phi_nc = NULL;
   pro = NULL;
   sigma_delta = NULL;
   sigma_c = NULL;
   sigma_a = NULL;
   sigma_g0 = NULL;
   sigma_g1 = NULL;
   sigma_g2 = NULL;
   sigma_g3 = NULL;
   sigma_g4 = NULL;
   sigma_f = NULL;
   sigma_k = NULL;
   small3 = NULL;
   rcut = NULL;
   dr = NULL;
   rdr = NULL;
   disij = NULL;
   rij = NULL;
   cosAng = NULL;
   betaS = NULL;
   dBetaS = NULL;
   betaP = NULL;
   dBetaP = NULL;
   repul = NULL;
   dRepul = NULL;
   itypeSigBk = NULL;
   nSigBk = NULL;
   sigB = NULL;
   sigB1 = NULL;
   itypePiBk = NULL;
   nPiBk = NULL;
   piB = NULL;
   pBetaS = NULL;
   pBetaS1 = NULL;
   pBetaS2 = NULL;
   pBetaS3 = NULL;
   pBetaS4 = NULL;
   pBetaS5 = NULL;
   pBetaS6 = NULL;
   pBetaP = NULL;
   pBetaP1 = NULL;
   pBetaP2 = NULL;
   pBetaP3 = NULL;
   pBetaP4 = NULL;
   pBetaP5 = NULL;
   pBetaP6 = NULL;
   pRepul = NULL;
   pRepul1 = NULL;
   pRepul2 = NULL;
   pRepul3 = NULL;
   pRepul4 = NULL;
   pRepul5 = NULL;
   pRepul6 = NULL;
   FsigBO = NULL;
   FsigBO1 = NULL;
   FsigBO2 = NULL;
   FsigBO3 = NULL;
   FsigBO4 = NULL;
   FsigBO5 = NULL;
   FsigBO6 = NULL;
   rcmin = NULL;
   rcmax = NULL;
   rcmaxp = NULL;
   setflag = NULL;
   cutsq = NULL;
   cutghost = NULL;
 
   ghostneigh = 1;
   bt_sg=NULL;
   bt_pi=NULL;
 }
 
 /* ----------------------------------------------------------------------
    check if allocated, since class can be destructed when incomplete
 ------------------------------------------------------------------------- */
 
 PairBOP::~PairBOP()
 {
   int i;
   if(allocated) {
     memory_theta_destroy();
     if (otfly==0) memory->destroy(cos_index);
     delete [] map;
 
     memory->destroy(BOP_index);
     memory->destroy(rcut);
     memory->destroy(dr);
     memory->destroy(rdr);
     memory->destroy(setflag);
     memory->destroy(cutsq);
     memory->destroy(cutghost);
     memory->destroy(pBetaS);
     memory->destroy(pBetaS1);
     memory->destroy(pBetaS2);
     memory->destroy(pBetaS3);
     memory->destroy(pBetaS4);
     memory->destroy(pBetaS5);
     memory->destroy(pBetaS6);
     memory->destroy(pBetaP);
     memory->destroy(pBetaP1);
     memory->destroy(pBetaP2);
     memory->destroy(pBetaP3);
     memory->destroy(pBetaP4);
     memory->destroy(pBetaP5);
     memory->destroy(pBetaP6);
     memory->destroy(pRepul);
     memory->destroy(pRepul1);
     memory->destroy(pRepul2);
     memory->destroy(pRepul3);
     memory->destroy(pRepul4);
     memory->destroy(pRepul5);
     memory->destroy(pRepul6);
     memory->destroy(FsigBO);
     memory->destroy(FsigBO1);
     memory->destroy(FsigBO2);
     memory->destroy(FsigBO3);
     memory->destroy(FsigBO4);
     memory->destroy(FsigBO5);
     memory->destroy(FsigBO6);
     if(table==0) {
       memory->destroy(pi_a);
       memory->destroy(pro_delta);
       memory->destroy(pi_delta);
       memory->destroy(pi_p);
       memory->destroy(pi_c);
       memory->destroy(sigma_r0);
       memory->destroy(pi_r0);
       memory->destroy(phi_r0);
       memory->destroy(sigma_rc);
       memory->destroy(pi_rc);
       memory->destroy(phi_rc);
       memory->destroy(r1);
       memory->destroy(sigma_beta0);
       memory->destroy(pi_beta0);
       memory->destroy(phi0);
       memory->destroy(sigma_n);
       memory->destroy(pi_n);
       memory->destroy(phi_m);
       memory->destroy(sigma_nc);
       memory->destroy(pi_nc);
       memory->destroy(phi_nc);
       memory->destroy(pro);
       memory->destroy(sigma_delta);
       memory->destroy(sigma_c);
       memory->destroy(sigma_a);
       memory->destroy(sigma_g0);
       memory->destroy(sigma_g1);
       memory->destroy(sigma_g2);
       memory->destroy(sigma_g3);
       memory->destroy(sigma_g4);
       memory->destroy(sigma_f);
       memory->destroy(sigma_k);
       memory->destroy(small3);
     }
     else {
       memory->destroy(pi_a);
       memory->destroy(pro_delta);
       memory->destroy(pi_delta);
       memory->destroy(pi_p);
       memory->destroy(pi_c);
       memory->destroy(r1);
       memory->destroy(pro);
       memory->destroy(sigma_delta);
       memory->destroy(sigma_c);
       memory->destroy(sigma_a);
       memory->destroy(sigma_g0);
       memory->destroy(sigma_g1);
       memory->destroy(sigma_g2);
       memory->destroy(sigma_f);
       memory->destroy(sigma_k);
       memory->destroy(small3);
     }
   }
   if(allocate_sigma) {
     destroy_sigma();
   }
   if(allocate_pi) {
     destroy_pi();
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::compute(int eflag, int vflag)
 {
   int ago,delay,every;
   int i,j,ii,jj,iij;
   int n,inum,temp_ij,ks;
   int itype,jtype,i_tag,j_tag;
   int *ilist,*iilist,*numneigh;
   int **firstneigh;
   double dpr1,ps;
   double ftmp1,ftmp2,ftmp3,dE;
   double dis_ij[3],rsq_ij,r_ij;
   double betaS_ij,dBetaS_ij;
   double betaP_ij,dBetaP_ij;
   double repul_ij,dRepul_ij;
   double totE;
 
   double **f = atom->f;
   double **x = atom->x;
   int *type = atom->type;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
   int nlocal = atom->nlocal;
   int nall = nlocal + atom->nghost;
- 
+
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
   ago=neighbor->ago;
   delay=neighbor->delay;
   every=neighbor->every;
 
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = vflag_fdotr = 0;
 
   // BOP Neighbor lists must be updated every time
   // atoms are moved between processors
 
   if ((ago ==0)||bop_step==0||(ago>=delay&&(ago%every)==0)||(nall>maxnall))
     gneigh();
 
   // For non on the fly calculations cos and derivatives
   // are calculated in advance and stored
 
   if(otfly==0) theta();
   else theta_mod();
 
   // Calculate Sigma Bond-Order
 
-  if(a_flag==1) { 
+  if(a_flag==1) {
     if (otfly==0) sigmaBo_noa();
     else sigmaBo_noa_otf();
   }
   else {
     if (otfly==0) sigmaBo();
     else sigmaBo_otf();
   }
 
   // Calculate Pi Bond-Order
 
   if (otfly==0) PiBo();
   else PiBo_otf();
 
-  n=0; 
+  n=0;
   totE=0;
   for (ii = 0; ii < inum; ii++) {
     i=ilist[ii];
     i_tag=tag[i];
     itype=map[type[i]]+1;
     iilist=firstneigh[i];
     for(jj=0;jj<numneigh[i];jj++) {
       temp_ij=BOP_index[i]+jj;
       j=iilist[jj];
       j_tag=tag[j];
       jtype=map[type[j]]+1;
       if(j_tag>=i_tag) {
         if(otfly==0) {
           if(neigh_flag[temp_ij]) {
             dpr1=(dRepul[temp_ij]-2.0*dBetaS[temp_ij]*sigB[n]
                 -2.0*dBetaP[temp_ij]*piB[n])/rij[temp_ij];
             ftmp1=dpr1*disij[0][temp_ij];
             ftmp2=dpr1*disij[1][temp_ij];
             ftmp3=dpr1*disij[2][temp_ij];
             f[i][0]=f[i][0]+ftmp1;
             f[i][1]=f[i][1]+ftmp2;
             f[i][2]=f[i][2]+ftmp3;
             f[j][0]=f[j][0]-ftmp1;
             f[j][1]=f[j][1]-ftmp2;
             f[j][2]=f[j][2]-ftmp3;
 
-            // add repulsive and bond order components to total energy 
+            // add repulsive and bond order components to total energy
             // (d) Eq.1
 
             dE=-2.0*betaS[temp_ij]*sigB[n]-2.0*betaP[temp_ij]*piB[n];
             totE+=dE+repul[temp_ij];
-            if(evflag) { 
+            if(evflag) {
               ev_tally_full(i,repul[temp_ij],dE,0.0,0.0,0.0,0.0);
               ev_tally_full(j,repul[temp_ij],dE,0.0,0.0,0.0,0.0);
               ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,-ftmp1,-ftmp2,-ftmp3,
                   disij[0][temp_ij],disij[1][temp_ij],disij[2][temp_ij]);
             }
             n++;
           }
         }
         else {
           if(itype==jtype)
             iij=itype-1;
           else if(itype<jtype)
             iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
           else
             iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
-          dis_ij[0]=x[j][0]-x[i][0]; 
-          dis_ij[1]=x[j][1]-x[i][1]; 
-          dis_ij[2]=x[j][2]-x[i][2]; 
+          dis_ij[0]=x[j][0]-x[i][0];
+          dis_ij[1]=x[j][1]-x[i][1];
+          dis_ij[2]=x[j][2]-x[i][2];
           rsq_ij=dis_ij[0]*dis_ij[0]
               +dis_ij[1]*dis_ij[1]
               +dis_ij[2]*dis_ij[2];
-          r_ij=sqrt(rsq_ij); 
+          r_ij=sqrt(rsq_ij);
           if(r_ij<=rcut[iij]) {
             ps=r_ij*rdr[iij]+1.0;
             ks=(int)ps;
             if(nr-1<ks)
               ks=nr-1;
             ps=ps-ks;
             if(ps>1.0)
               ps=1.0;
             betaS_ij=((pBetaS3[iij][ks-1]*ps+pBetaS2[iij][ks-1])*ps
                 +pBetaS1[iij][ks-1])*ps+pBetaS[iij][ks-1];
             dBetaS_ij=(pBetaS6[iij][ks-1]*ps+pBetaS5[iij][ks-1])*ps
                 +pBetaS4[iij][ks-1];
             betaP_ij=((pBetaP3[iij][ks-1]*ps+pBetaP2[iij][ks-1])*ps
                 +pBetaP1[iij][ks-1])*ps+pBetaP[iij][ks-1];
             dBetaP_ij=(pBetaP6[iij][ks-1]*ps+pBetaP5[iij][ks-1])*ps
                 +pBetaP4[iij][ks-1];
             repul_ij=((pRepul3[iij][ks-1]*ps+pRepul2[iij][ks-1])*ps
                 +pRepul1[iij][ks-1])*ps+pRepul[iij][ks-1];
             dRepul_ij=(pRepul6[iij][ks-1]*ps+pRepul5[iij][ks-1])*ps
                 +pRepul4[iij][ks-1];
             dpr1=(dRepul_ij-2.0*dBetaS_ij*sigB[n]
                 -2.0*dBetaP_ij*piB[n])/r_ij;
             ftmp1=dpr1*dis_ij[0];
             ftmp2=dpr1*dis_ij[1];
             ftmp3=dpr1*dis_ij[2];
             f[i][0]=f[i][0]+ftmp1;
             f[i][1]=f[i][1]+ftmp2;
             f[i][2]=f[i][2]+ftmp3;
             f[j][0]=f[j][0]-ftmp1;
             f[j][1]=f[j][1]-ftmp2;
             f[j][2]=f[j][2]-ftmp3;
 
-            // add repulsive and bond order components to total energy 
-            // (d) Eq. 1 
+            // add repulsive and bond order components to total energy
+            // (d) Eq. 1
 
             dE=-2.0*betaS_ij*sigB[n]-2.0*betaP_ij*piB[n];
             totE+=dE+repul_ij;
-            if(evflag) { 
+            if(evflag) {
               ev_tally_full(i,repul_ij,dE,0.0,0.0,0.0,0.0);
               ev_tally_full(j,repul_ij,dE,0.0,0.0,0.0,0.0);
               ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,-ftmp1,-ftmp2,-ftmp3,
                   dis_ij[0],dis_ij[1],dis_ij[2]);
             }
             n++;
           }
         }
       }
     }
   }
 
   if (vflag_fdotr) virial_fdotr_compute();
   bop_step = 1;
 }
 
 /* ----------------------------------------------------------------------
    allocate all arrays
 ------------------------------------------------------------------------- */
 
 void PairBOP::allocate()
 {
   allocated = 1;
   int n = atom->ntypes;
-  
+
   memory->create(rcut,npairs,"BOP:rcut");
   memory->create(dr,npairs,"BOP:dr");
   memory->create(rdr,npairs,"BOP:dr");
   memory->create(setflag,n+1,n+1,"pair:setflag");
   memory->create(cutsq,n+1,n+1,"pair:cutsq");
   memory->create(cutghost,n+1,n+1,"pair:cutghost");
   memory->create(pBetaS,npairs,nr,"BOP:pBetaS");
   memory->create(pBetaS1,npairs,nr,"BOP:pBetaS1");
   memory->create(pBetaS2,npairs,nr,"BOP:pBetaS2");
   memory->create(pBetaS3,npairs,nr,"BOP:pBetaS3");
   memory->create(pBetaS4,npairs,nr,"BOP:pBetaS4");
   memory->create(pBetaS5,npairs,nr,"BOP:pBetaS5");
   memory->create(pBetaS6,npairs,nr,"BOP:pBetaS6");
   memory->create(pBetaP,npairs,nr,"BOP:pBetaP");
   memory->create(pBetaP1,npairs,nr,"BOP:pBetaP1");
   memory->create(pBetaP2,npairs,nr,"BOP:pBetaP2");
   memory->create(pBetaP3,npairs,nr,"BOP:pBetaP3");
   memory->create(pBetaP4,npairs,nr,"BOP:pBetaP4");
   memory->create(pBetaP5,npairs,nr,"BOP:pBetaP5");
   memory->create(pBetaP6,npairs,nr,"BOP:pBetaP6");
   memory->create(pRepul,npairs,nr,"BOP:pRepul");
   memory->create(pRepul1,npairs,nr,"BOP:pRepul1");
   memory->create(pRepul2,npairs,nr,"BOP:pRepul2");
   memory->create(pRepul3,npairs,nr,"BOP:pRepul3");
   memory->create(pRepul4,npairs,nr,"BOP:pRepul4");
   memory->create(pRepul5,npairs,nr,"BOP:pRepul5");
   memory->create(pRepul6,npairs,nr,"BOP:pRepul6");
   memory->create(FsigBO,npairs,nBOt,"BOP:FsigBO");
   memory->create(FsigBO1,npairs,nBOt,"BOP:FsigBO1");
   memory->create(FsigBO2,npairs,nBOt,"BOP:FsigBO2");
   memory->create(FsigBO3,npairs,nBOt,"BOP:FsigBO3");
   memory->create(FsigBO4,npairs,nBOt,"BOP:FsigBO4");
   memory->create(FsigBO5,npairs,nBOt,"BOP:FsigBO5");
   memory->create(FsigBO6,npairs,nBOt,"BOP:FsigBO6");
 }
 
 /* ----------------------------------------------------------------------
    global settings
 ------------------------------------------------------------------------- */
 
 void PairBOP::settings(int narg, char **arg)
 {
   table = 0;
   otfly = 1;
   a_flag = 0;
 
   int iarg = 0;
   while (iarg < narg) {
     if (strcmp(arg[iarg],"table") == 0) {
       table = 1;
       iarg++;
     } else if (strcmp(arg[iarg],"save") == 0) {
       otfly = 0;
       iarg++;
     } else if (strcmp(arg[iarg],"sigmaoff") == 0) {
       a_flag = 1;
       iarg++;
     } else error->all(FLERR,"Illegal pair_style command");
   }
 }
 
 /* ----------------------------------------------------------------------
    set coeffs for one or more type pairs(Updated: D.K. Ward 05/06/10)
 ------------------------------------------------------------------------- */
 
 void PairBOP::coeff(int narg, char **arg)
 {
   int i,j,n;
   MPI_Comm_rank(world,&me);
   map = new int[atom->ntypes+1];
 
   if (narg < 3 + atom->ntypes)
     error->all(FLERR,"Incorrect args for pair coefficients");
 
   // ensure I,J args are * *
 
   if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0)
     error->all(FLERR,"Incorrect args for pair coefficients");
 
   // read the potential file
 
   nr=2000;
   nBOt=2000;
   bop_step=0;
   nb_pi=0;
   nb_sg=0;
   allocate_sigma=0;
   allocate_pi=0;
   allocate_neigh=0;
   update_list=0;
 
   if (table == 0) read_file(arg[2]);
   else read_table(arg[2]);
 
   if (table == 0) {
     setPbetaS();
     setPbetaP();
     setPrepul();
     setSign();
   }
 
   // match element names to BOP word types
 
-  if (me == 0) { 
+  if (me == 0) {
     for (i = 3; i < narg; i++) {
       if (strcmp(arg[i],"NULL") == 0) {
         map[i-2] = -1;
         continue;
-      }   
+      }
       for (j = 0; j < bop_types; j++)
         if (strcmp(arg[i],words[j]) == 0) break;
       map[i-2] = j;
     }
   }
 
   MPI_Bcast(&map[1],atom->ntypes,MPI_INT,0,world);
 
   if (me == 0) {
     if (words) {
       for (i = 0; i < bop_types; i++) delete [] words[i];
       delete [] words;
     }
   }
 
   // clear setflag since coeff() called once with I,J = * *
 
   n = atom->ntypes;
   for (int i = 1; i <= n; i++)
     for (int j = i; j <= n; j++)
       setflag[i][j] = 0;
 
   // set setflag i,j for type pairs where both are mapped to elements
 
   int count = 0;
   for (int i = 1; i <= n; i++)
     for (int j = i; j <= n; j++)
       if (map[i] >= 0 && map[j] >= 0) {
         setflag[i][j] = 1;
         count++;
       }
 
   if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
 }
 
 /* ----------------------------------------------------------------------
    init specific to this pair style
 ------------------------------------------------------------------------- */
 
 void PairBOP::init_style()
 {
   if (atom->tag_enable == 0)
     error->all(FLERR,"Pair style BOP requires atom IDs");
   if (force->newton_pair == 0)
     error->all(FLERR,"Pair style BOP requires newton pair on");
 
   // check that user sets comm->cutghostuser to 3x the max BOP cutoff
 
   if (comm->cutghostuser < 3.0*cutmax - EPSILON) {
     char str[128];
     sprintf(str,"Pair style bop requires comm ghost cutoff "
             "at least 3x larger than %g",cutmax);
     error->all(FLERR,str);
   }
 
   // need a full neighbor list and neighbors of ghosts
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->half = 0;
   neighbor->requests[irequest]->full = 1;
   neighbor->requests[irequest]->ghost = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::init_one(int i, int j)
 {
   if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set");
 
   int ii = map[i]+1;
   int jj = map[j]+1;
- 
+
   int ij;
   if (ii==jj) ij=ii-1;
   else if (ii<jj) ij=ii*bop_types-ii*(ii+1)/2+jj-1;
   else ij=jj*bop_types-jj*(jj+1)/2+ii-1;
-    
+
   cutghost[i][j] = rcut[ij];
   cutghost[j][i] = cutghost[i][j];
   cutsq[i][j] = rcut[ij]*rcut[ij];
   cutsq[j][i] = cutsq[i][j];
   return rcut[ij];
 }
 
 /* ----------------------------------------------------------------------
    create BOP neighbor list from main neighbor list
    BOP neighbor list stores neighbors of ghost atoms
    BOP requires neighbor's of k if k is a neighbor of
    j and j is a neighbor of i
 ------------------------------------------------------------------------- */
 
 void PairBOP::gneigh()
 {
   int i,ii;
   int *ilist,*numneigh;
   int **firstneigh;
   int nlocal = atom->nlocal;
   int nall = nlocal + atom->nghost;
 
   if(allocate_neigh==0) {
     memory->create (BOP_index,nall,"BOP_index");
     if (otfly==0) memory->create (cos_index,nall,"cos_index");
     allocate_neigh=1;
   }
   else {
     memory->grow (BOP_index,nall,"BOP_index");
     if (otfly==0) memory->grow (cos_index,nall,"cos_index");
     allocate_neigh=1;
   }
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
   if(bop_step==0) {
     maxneigh=0;
     maxnall=0;
   }
   neigh_total=0;
   cos_total=0;
   for (ii = 0; ii < nall; ii++) {
     if(i<nlocal) {
       i=ilist[ii];
       if(numneigh[i]>maxneigh) maxneigh=numneigh[i];
     }
     else {
       i=ii;
       if(numneigh[i]>maxneigh) maxneigh=numneigh[i];
     }
     BOP_index[i]=neigh_total;
     neigh_total+=numneigh[i];
     if(otfly==0) {
       cos_index[i]=cos_total;
       cos_total+=numneigh[i]*(numneigh[i]-1)/2;
     }
   }
   maxnall=nall;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::theta()
 {
   int i,j,k,ii,jj,kk;
   int itype,jtype,i12;
   int temp_ij,temp_ik,temp_ijk;
   int n,nlocal,nall,ks;
   int *ilist,*numneigh;
   int *iilist;
   int **firstneigh;
   double rj2,rk2,rsq,ps;
   double rj1k1,rj2k2,rj2k1,rj1k2;
   double **x = atom->x;
   int *type = atom->type;
 
   nlocal = atom->nlocal;
   nall = nlocal+atom->nghost;
   ilist = list->ilist;
   firstneigh = list->firstneigh;
   numneigh = list->numneigh;
-  if(update_list!=0) 
+  if(update_list!=0)
     memory_theta_grow();
   else
     memory_theta_create();
   for (ii = 0; ii < nall; ii++) {
     if(ii<nlocal)
       i= ilist[ii];
     else
       i=ii;
     itype = map[type[i]]+1;
-      
+
     iilist=firstneigh[i];
     for(jj=0;jj<numneigh[i];jj++) {
       j=iilist[jj];
       temp_ij=BOP_index[i]+jj;
       jtype = map[type[j]]+1;
 
       if(itype==jtype)
         i12=itype-1;
       else if(itype<jtype)
         i12=itype*bop_types-itype*(itype+1)/2+jtype-1;
       else
         i12=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
       if(i12>=npairs) {
         error->one(FLERR,"Too many atom pairs for pair bop");
       }
-      disij[0][temp_ij]=x[j][0]-x[i][0]; 
-      disij[1][temp_ij]=x[j][1]-x[i][1]; 
-      disij[2][temp_ij]=x[j][2]-x[i][2]; 
+      disij[0][temp_ij]=x[j][0]-x[i][0];
+      disij[1][temp_ij]=x[j][1]-x[i][1];
+      disij[2][temp_ij]=x[j][2]-x[i][2];
       rsq=disij[0][temp_ij]*disij[0][temp_ij]
           +disij[1][temp_ij]*disij[1][temp_ij]
           +disij[2][temp_ij]*disij[2][temp_ij];
-      rij[temp_ij]=sqrt(rsq); 
-      if(rij[temp_ij]<=rcut[i12]) 
+      rij[temp_ij]=sqrt(rsq);
+      if(rij[temp_ij]<=rcut[i12])
         neigh_flag[temp_ij]=1;
       else
         neigh_flag[temp_ij]=0;
       ps=rij[temp_ij]*rdr[i12]+1.0;
       ks=(int)ps;
 
       if(nr-1<ks)
         ks=nr-1;
       ps=ps-ks;
       if(ps>1.0)
         ps=1.0;
       betaS[temp_ij]=((pBetaS3[i12][ks-1]*ps+pBetaS2[i12][ks-1])*ps
           +pBetaS1[i12][ks-1])*ps+pBetaS[i12][ks-1];
       dBetaS[temp_ij]=(pBetaS6[i12][ks-1]*ps+pBetaS5[i12][ks-1])*ps
           +pBetaS4[i12][ks-1];
       betaP[temp_ij]=((pBetaP3[i12][ks-1]*ps+pBetaP2[i12][ks-1])*ps
           +pBetaP1[i12][ks-1])*ps+pBetaP[i12][ks-1];
       dBetaP[temp_ij]=(pBetaP6[i12][ks-1]*ps+pBetaP5[i12][ks-1])*ps
           +pBetaP4[i12][ks-1];
       repul[temp_ij]=((pRepul3[i12][ks-1]*ps+pRepul2[i12][ks-1])*ps
           +pRepul1[i12][ks-1])*ps+pRepul[i12][ks-1];
       dRepul[temp_ij]=(pRepul6[i12][ks-1]*ps+pRepul5[i12][ks-1])*ps
           +pRepul4[i12][ks-1];
     }
   }
   for (ii = 0; ii < nall; ii++) {
     n=0;
     if(ii<nlocal)
       i= ilist[ii];
     else
       i=ii;
     iilist=firstneigh[i];
     for(jj=0;jj<numneigh[i];jj++) {
       j=iilist[jj];
       temp_ij=BOP_index[i]+jj;
       rj2=rij[temp_ij]*rij[temp_ij];
       for(kk=jj+1;kk<numneigh[i];kk++) {
         if(cos_index[i]+n>=cos_total) {
           error->one(FLERR,"Too many atom triplets for pair bop");
         }
         temp_ik=BOP_index[i]+kk;
-        temp_ijk=cos_index[i]+n; 
+        temp_ijk=cos_index[i]+n;
         if(temp_ijk>=cos_total) {
           error->one(FLERR,"Too many atom triplets for pair bop");
         }
         rk2=rij[temp_ik]*rij[temp_ik];
         rj1k1=rij[temp_ij]*rij[temp_ik];
         rj2k2=rj1k1*rj1k1;
         rj2k1=rj1k1*rij[temp_ij];
         rj1k2=rj1k1*rij[temp_ik];
         k=iilist[kk];
         if(temp_ijk>=cos_total) {
           error->one(FLERR,"Too many atom triplets for pair bop");
         }
         cosAng[temp_ijk]=(disij[0][temp_ij]*disij[0][temp_ik]+disij[1][temp_ij]
             *disij[1][temp_ik]+disij[2][temp_ij]*disij[2][temp_ik])/rj1k1;
         dcAng[temp_ijk][0][0]=(disij[0][temp_ik]*rj1k1-cosAng[temp_ijk]
               *disij[0][temp_ij]*rk2)/(rj2k2);
         dcAng[temp_ijk][1][0]=(disij[1][temp_ik]*rj1k1-cosAng[temp_ijk]
             *disij[1][temp_ij]*rk2)/(rj2k2);
         dcAng[temp_ijk][2][0]=(disij[2][temp_ik]*rj1k1-cosAng[temp_ijk]
             *disij[2][temp_ij]*rk2)/(rj2k2);
         dcAng[temp_ijk][0][1]=(disij[0][temp_ij]*rj1k1-cosAng[temp_ijk]
             *disij[0][temp_ik]*rj2)/(rj2k2);
         dcAng[temp_ijk][1][1]=(disij[1][temp_ij]*rj1k1-cosAng[temp_ijk]
             *disij[1][temp_ik]*rj2)/(rj2k2);
         dcAng[temp_ijk][2][1]=(disij[2][temp_ij]*rj1k1-cosAng[temp_ijk]
             *disij[2][temp_ik]*rj2)/(rj2k2);
         n++;
-      } 
+      }
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::theta_mod()
 {
   if(update_list!=0)
     memory_theta_grow();
   else
     memory_theta_create();
 }
 
 /* ---------------------------------------------------------------------- */
 
 /*  The formulation differs slightly to avoid negative square roots
     in the calculation of Sigma^(1/2) of (a) Eq. 6 and (b) Eq. 11 */
- 
+
 void PairBOP::sigmaBo()
 {
   int nb_t,new_n_tot;
   int n,i,j,k,kp,m,pp,kkp;
   int iij,ji,ki;
   int itmp,jtmp,ktmp,ltmp,mtmp;
   int i_tag,j_tag;
   int ngi,ngj,ngk,nglkp,ngli,nglj,ngl;
   int ngji,ngjk,nikj,ngki,ngkj,ngjkp;
   int ngkpk,ngkpj,ngkkp,nglk;
   int njik,nijk,nikkp,nkp,nijkp;
   int nkikp,njikp,nk0;
   int njkpk,nkjkp,njkkp;
   int jNeik,kNeii,kNeij,kNeikp;
   int kpNeij,kpNeik;
   int new1,new2,nlocal;
   int inum,*ilist,*iilist,*jlist,*klist,*kplist;
   int **firstneigh,*numneigh;
   int temp_ji,temp_ikp,temp_ki,temp_kkp;
   int temp_ij,temp_ik,temp_jkp,temp_kk,temp_jk;
   int ang_ijkp,ang_ikkp,ang_jkpk,ang_kjkp;
   int ang_ijk,ang_ikj,ang_jikp,ang_jkkp;
   int ang_jik,ang_kikp;
   int nb_ij,nb_ik,nb_ikp;
   int nb_jk,nb_jkp,nb_kkp;
   int kp_nsearch,nsearch;
   int sig_flag,setting,ncmp,ks;
   int itype,jtype,ktype,kptype;
   int bt_i,bt_j,bt_ij;
   int kp_index,same_ikp,same_jkp;
   int same_kkp,same_jkpj;
   double AA,BB,CC,DD,EE,EE1,FF;
   double AAC,BBC,CCC,DDC,EEC,FFC,GGC;
   double AACFF,UT,bndtmp,UTcom;
   double amean,gmean0,gmean1,gmean2,ps;
   double gfactor1,gprime1,gsqprime,factorsq;
   double gfactorsq,gfactor2,gprime2;
   double gfactorsq2,gsqprime2;
   double gfactor3,gprime3,gfactor,rfactor;
   double drfactor,gfactor4,gprime4,agpdpr3;
   double rfactor0,rfactorrt,rfactor1rt,rfactor1;
   double rcm1,rcm2,gcm1,gcm2,gcm3;
   double agpdpr1,agpdpr2,app1,app2,app3,app4;
   double dsigB1,dsigB2;
   double part0,part1,part2,part3,part4;
   double psign,bndtmp0,pp1;
   double bndtmp1,bndtmp2,bndtmp3,bndtmp4,bndtmp5;
   double ftmp[3];
   double **x = atom->x;
   double **f = atom->f;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
   int *type = atom->type;
 
   nlocal = atom->nlocal;
   int nall = nlocal+atom->nghost;
   firstneigh = list->firstneigh;
   numneigh = list->numneigh;
-  inum = list->inum; 
+  inum = list->inum;
   ilist = list->ilist;
   n=0;
 
 //loop over all local atoms
 
   if(nb_sg>16) {
     nb_sg=16;
   }
   if(nb_sg==0) {
     nb_sg=(maxneigh)*(maxneigh/2);
   }
   if(allocate_sigma) {
     destroy_sigma();
   }
   create_sigma(nb_sg);
   for(itmp=0;itmp<inum;itmp++) {
     i = ilist[itmp];
-    i_tag=tag[i];  
+    i_tag=tag[i];
     itype = map[type[i]]+1;
 
 //j is loop over all neighbors of i
 
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       temp_ij=BOP_index[i]+jtmp;
       if(neigh_flag[temp_ij]) {
         for(m=0;m<nb_sg;m++) {
           for(pp=0;pp<3;pp++) {
             bt_sg[m].dAA[pp]=0.0;
             bt_sg[m].dBB[pp]=0.0;
             bt_sg[m].dCC[pp]=0.0;
             bt_sg[m].dDD[pp]=0.0;
             bt_sg[m].dEE[pp]=0.0;
             bt_sg[m].dEE1[pp]=0.0;
             bt_sg[m].dFF[pp]=0.0;
             bt_sg[m].dAAC[pp]=0.0;
             bt_sg[m].dBBC[pp]=0.0;
             bt_sg[m].dCCC[pp]=0.0;
             bt_sg[m].dDDC[pp]=0.0;
             bt_sg[m].dEEC[pp]=0.0;
             bt_sg[m].dFFC[pp]=0.0;
             bt_sg[m].dGGC[pp]=0.0;
             bt_sg[m].dUT[pp]=0.0;
             bt_sg[m].dSigB1[pp]=0.0;
             bt_sg[m].dSigB[pp]=0.0;
           }
           bt_sg[m].i=-1;
           bt_sg[m].j=-1;
           bt_sg[m].temp=-1;
         }
         nb_t=0;
         iilist=firstneigh[i];
         j=iilist[jtmp];
         jlist=firstneigh[j];
         for(ki=0;ki<numneigh[j];ki++) {
           temp_ki=BOP_index[j]+ki;
           if(x[jlist[ki]][0]==x[i][0]) {
             if(x[jlist[ki]][1]==x[i][1]) {
               if(x[jlist[ki]][2]==x[i][2]) {
                 break;
               }
             }
           }
         }
         j_tag=tag[j];
         jtype = map[type[j]]+1;
         nb_ij=nb_t;
         nb_t++;
         if(nb_t>nb_sg) {
           new_n_tot=nb_sg+maxneigh;
           grow_sigma(nb_sg,new_n_tot);
           nb_sg=new_n_tot;
         }
         bt_sg[nb_ij].temp=temp_ij;
         bt_sg[nb_ij].i=i;
         bt_sg[nb_ij].j=j;
         if(j_tag>=i_tag) {
           if(itype==jtype)
             iij=itype-1;
           else if(itype<jtype)
             iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
           else
             iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
           for(ji=0;ji<numneigh[j];ji++) {
             temp_ji=BOP_index[j]+ji;
             if(x[jlist[ji]][0]==x[i][0]) {
               if(x[jlist[ji]][1]==x[i][1]) {
                 if(x[jlist[ji]][2]==x[i][2]) {
                   break;
                 }
               }
             }
           }
           nSigBk[n]=0;
 
 //AA-EE1 are the components making up Eq. 30 (a)
 
           AA=0.0;
           BB=0.0;
           CC=0.0;
           DD=0.0;
           EE=0.0;
           EE1=0.0;
 
 //FF is the Beta_sigma^2 term
-       
+
           FF=betaS[temp_ij]*betaS[temp_ij];
 
 //agpdpr1 is derivative of FF w.r.t. r_ij
 
           agpdpr1=2.0*betaS[temp_ij]*dBetaS[temp_ij]/rij[temp_ij];
 
 //dXX derivatives are taken with respect to all pairs contributing to the energy
 //nb_ij is derivative w.r.t. ij pair
 
           bt_sg[nb_ij].dFF[0]=agpdpr1*disij[0][temp_ij];
           bt_sg[nb_ij].dFF[1]=agpdpr1*disij[1][temp_ij];
           bt_sg[nb_ij].dFF[2]=agpdpr1*disij[2][temp_ij];
 
-//k is loop over all neighbors of i again with j neighbor of i 
+//k is loop over all neighbors of i again with j neighbor of i
 
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
-            temp_ik=BOP_index[i]+ktmp;       
+            temp_ik=BOP_index[i]+ktmp;
             if(neigh_flag[temp_ik]) {
               if(ktmp!=jtmp) {
                 if(jtmp<ktmp) {
                   njik=jtmp*(2*numneigh[i]-jtmp-1)/2+(ktmp-jtmp)-1;
                   ngj=0;
                   ngk=1;
                 }
                 else {
                   njik=ktmp*(2*numneigh[i]-ktmp-1)/2+(jtmp-ktmp)-1;
                   ngj=1;
                   ngk=0;
                 }
                 k=iilist[ktmp];
                 ktype = map[type[k]]+1;
 
 //find neighbor of k that is equal to i
 
                 klist=firstneigh[k];
                 for(kNeii=0;kNeii<numneigh[k];kNeii++) {
                   temp_ki=BOP_index[k]+kNeii;
                   if(x[klist[kNeii]][0]==x[i][0]) {
                     if(x[klist[kNeii]][1]==x[i][1]) {
                       if(x[klist[kNeii]][2]==x[i][2]) {
                         break;
                       }
                     }
                   }
                 }
 
 //find neighbor of i that is equal to k
 
                 for(jNeik=0;jNeik<numneigh[j];jNeik++) {
                   temp_jk=BOP_index[j]+jNeik;
                   if(x[jlist[jNeik]][0]==x[k][0]) {
                     if(x[jlist[jNeik]][1]==x[k][1]) {
                       if(x[jlist[jNeik]][2]==x[k][2]) {
                         break;
                       }
                     }
                   }
                 }
 
 //find neighbor of k that is equal to j
 
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         nk0=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   nk0=nSigBk[n]-1;
                   itypeSigBk[n][nk0]=k;
                 }
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_ik].temp=temp_ik;
                 bt_sg[nb_ik].i=i;
                 bt_sg[nb_ik].j=k;
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 ang_jik=cos_index[i]+njik;
                 gmean0=sigma_g0[jtype-1][itype-1][ktype-1];
                 gmean1=sigma_g1[jtype-1][itype-1][ktype-1];
                 gmean2=sigma_g2[jtype-1][itype-1][ktype-1];
                 amean=cosAng[ang_jik];
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gsqprime=2.0*gfactor1*gprime1;
 
 //AA is Eq. 34 (a) or Eq. 10 (c) for the i atom
 //1st CC is Eq. 11 (c) for i atom where j & k=neighbor of i
 
                 AA=AA+gfactorsq*betaS[temp_ik]*betaS[temp_ik];
                 CC=CC+gfactorsq*betaS[temp_ik]*betaS[temp_ik]*betaS[temp_ik]*betaS[temp_ik];
 
 //agpdpr1 is derivative of AA w.r.t. Beta(rik)
 //agpdpr2 is derivative of CC 1st term w.r.t. Beta(rik)
 //app1 is derivative of AA w.r.t. cos(theta_jik)
 //app2 is derivative of CC 1st term w.r.t. cos(theta_jik)
 
                 agpdpr1=2.0*gfactorsq*betaS[temp_ik]*dBetaS[temp_ik]/rij[temp_ik];
                 agpdpr1=2.0*betaS[temp_ik]*betaS[temp_ik]*agpdpr1;
                 app1=betaS[temp_ik]*betaS[temp_ik]*gsqprime;
                 app1=betaS[temp_ik]*betaS[temp_ik]*app1;
                 bt_sg[nb_ij].dAA[0]+=
                     app1*dcAng[ang_jik][0][ngj];
                 bt_sg[nb_ij].dAA[1]+=
                     app1*dcAng[ang_jik][1][ngj];
                 bt_sg[nb_ij].dAA[2]+=
                     app1*dcAng[ang_jik][2][ngj];
                 bt_sg[nb_ij].dCC[0]+=
                     app2*dcAng[ang_jik][0][ngj];
                 bt_sg[nb_ij].dCC[1]+=
                     app2*dcAng[ang_jik][1][ngj];
                 bt_sg[nb_ij].dCC[2]+=
                     app2*dcAng[ang_jik][2][ngj];
                 bt_sg[nb_ik].dAA[0]+=
                     app1*dcAng[ang_jik][0][ngk]
                     +agpdpr1*disij[0][temp_ik];
                 bt_sg[nb_ik].dAA[1]+=
                     app1*dcAng[ang_jik][1][ngk]
                     +agpdpr1*disij[1][temp_ik];
                 bt_sg[nb_ik].dAA[2]+=
                     app1*dcAng[ang_jik][2][ngk]
                     +agpdpr1*disij[2][temp_ik];
                 bt_sg[nb_ik].dCC[0]+=
                     app2*dcAng[ang_jik][0][ngk]
                     +agpdpr2*disij[0][temp_ik];
                 bt_sg[nb_ik].dCC[1]+=
                     app2*dcAng[ang_jik][1][ngk]
                     +agpdpr2*disij[1][temp_ik];
                 bt_sg[nb_ik].dCC[2]+=
                     app2*dcAng[ang_jik][2][ngk]
                     +agpdpr2*disij[2][temp_ik];
 
 //k' is loop over neighbors all neighbors of j with k a neighbor
-//of i and j a neighbor of i and determine which k' is k 
+//of i and j a neighbor of i and determine which k' is k
 
                 kp_index=0;
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   temp_jkp=BOP_index[j]+ltmp;
                   kp=jlist[ltmp];
                   if(x[kp][0]==x[k][0]) {
                     if(x[kp][1]==x[k][1]) {
                       if(x[kp][2]==x[k][2]) {
                         kp_index=1;
                         break;
                       }
                     }
                   }
                 }
                 if(kp_index) {
 
 //loop over neighbors of k
 
                   for(mtmp=0;mtmp<numneigh[k];mtmp++) {
                     kp=klist[mtmp];
                     if(x[kp][0]==x[j][0]) {
                       if(x[kp][1]==x[j][1]) {
                         if(x[kp][2]==x[j][2]) {
                           break;
                         }
                       }
                     }
                   }
                   if(ki<ltmp) {
                     nijk=ki*(2*numneigh[j]-ki-1)/2+(ltmp-ki)-1;
                     ngji=0;
                     ngjk=1;
                   }
                   else {
                     nijk=ltmp*(2*numneigh[j]-ltmp-1)/2+(ki-ltmp)-1;
                     ngji=1;
                     ngjk=0;
                   }
                   if(kNeii<mtmp) {
                     nikj=kNeii*(2*numneigh[k]-kNeii-1)/2+(mtmp-kNeii)-1;
                     ngki=0;
                     ngkj=1;
                   }
                   else {
                     nikj=mtmp*(2*numneigh[k]-mtmp-1)/2+(kNeii-mtmp)-1;
                     ngki=1;
                     ngkj=0;
                   }
                   ang_ijk=cos_index[j]+nijk;
                   gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                   gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                   gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                   amean=cosAng[ang_ijk];
                   gfactor2=gmean0+gmean1*amean
                       +gmean2*amean*amean;
                   gprime2=gmean1+2.0*gmean2*amean;
                   gmean0=sigma_g0[itype-1][ktype-1][jtype-1];
                   gmean1=sigma_g1[itype-1][ktype-1][jtype-1];
                   gmean2=sigma_g2[itype-1][ktype-1][jtype-1];
                   ang_ikj=cos_index[k]+nikj;
                   amean=cosAng[ang_ikj];
                   gfactor3=gmean0+gmean1*amean
                       +gmean2*amean*amean;
                   gprime3=gmean1+2.0*gmean2*amean;
                   gfactor=gfactor1*gfactor2*gfactor3;
                   rfactor=betaS[temp_ik]*betaS[temp_jkp];
 
 //EE1 is (b) Eq. 12
 
                   EE1=EE1+gfactor*rfactor;
 
 //rcm2 is derivative of EE1 w.r.t Beta(r_jk')
 //gcm1 is derivative of EE1 w.r.t cos(theta_jik)
 //gcm2 is derivative of EE1 w.r.t cos(theta_ijk)
 //gcm3 is derivative of EE1 w.r.t cos(theta_ikj)
 
                   rcm1=gfactor*betaS[temp_jkp]*dBetaS[temp_ik]/rij[temp_ik];
                   rcm2=gfactor*betaS[temp_ik]*dBetaS[temp_jkp]/rij[temp_jkp];
                   gcm1=rfactor*gprime1*gfactor2*gfactor3;
                   gcm2=rfactor*gfactor1*gprime2*gfactor3;
                   gcm3=rfactor*gfactor1*gfactor2*gprime3;
                   bt_sg[nb_ij].dEE1[0]+=
                       gcm1*dcAng[ang_jik][0][ngj]
                       -gcm2*dcAng[ang_ijk][0][ngji];
                   bt_sg[nb_ij].dEE1[1]+=
                       gcm1*dcAng[ang_jik][1][ngj]
                       -gcm2*dcAng[ang_ijk][1][ngji];
                   bt_sg[nb_ij].dEE1[2]+=
                       gcm1*dcAng[ang_jik][2][ngj]
                       -gcm2*dcAng[ang_ijk][2][ngji];
                   bt_sg[nb_ik].dEE1[0]+=
                       gcm1*dcAng[ang_jik][0][ngk]
                       +rcm1*disij[0][temp_ik]
                       -gcm3*dcAng[ang_ikj][0][ngki];
                   bt_sg[nb_ik].dEE1[1]+=
                       gcm1*dcAng[ang_jik][1][ngk]
                       +rcm1*disij[1][temp_ik]
                       -gcm3*dcAng[ang_ikj][1][ngki];
                   bt_sg[nb_ik].dEE1[2]+=
                       gcm1*dcAng[ang_jik][2][ngk]
                       +rcm1*disij[2][temp_ik]
                       -gcm3*dcAng[ang_ikj][2][ngki];
                   bt_sg[nb_jk].dEE1[0]+=
                       gcm2*dcAng[ang_ijk][0][ngjk]
                       +rcm2*disij[0][temp_jkp]
                       -gcm3*dcAng[ang_ikj][0][ngkj];
                   bt_sg[nb_jk].dEE1[1]+=
                       gcm2*dcAng[ang_ijk][1][ngjk]
                       +rcm2*disij[1][temp_jkp]
                       -gcm3*dcAng[ang_ikj][1][ngkj];
                   bt_sg[nb_jk].dEE1[2]+=
                       gcm2*dcAng[ang_ijk][2][ngjk]
                       +rcm2*disij[2][temp_jkp]
                       -gcm3*dcAng[ang_ikj][2][ngkj];
                 }
 
 // k and k' and j are all different neighbors of i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     if(neigh_flag[temp_ikp]) {
                       kp=iilist[ltmp];
                       kptype = map[type[kp]]+1;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               break;
                             }
                           }
                         }
                       }
                       if(jtmp<ltmp) {
                         njikp=jtmp*(2*numneigh[i]-jtmp-1)/2+(ltmp-jtmp)-1;
                         nglj=0;
                         ngl=1;
                       }
                       else {
                         njikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(jtmp-ltmp)-1;
                         nglj=1;
                         ngl=0;
                       }
                       if(ktmp<ltmp) {
                         nkikp=ktmp*(2*numneigh[i]-ktmp-1)/2+(ltmp-ktmp)-1;
                         nglk=0;
                         nglkp=1;
                       }
                       else {
                         nkikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(ktmp-ltmp)-1;
                         nglk=1;
                         nglkp=0;
                       }
                       ang_jikp=cos_index[i]+njikp;
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_ikp].temp=temp_ikp;
                       bt_sg[nb_ikp].i=i;
                       bt_sg[nb_ikp].j=kp;
                       gmean0=sigma_g0[jtype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][itype-1][kptype-1];
                       amean=cosAng[ang_jikp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][itype-1][kptype-1];
                       ang_kikp=cos_index[i]+nkikp;
                       amean=cosAng[ang_kikp];
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS[temp_ik]*betaS[temp_ikp];
                       rfactor=rfactorrt*rfactorrt;
 
 //2nd CC is second term of Eq. 11 (c) for i atom where j , k & k' =neighbor of i
 
                       CC=CC+2.0*gfactor*rfactor;
 
 //agpdpr1 is derivative of CC 2nd term w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of CC 2nd term w.r.t. Beta(r_ik')
 //app1 is derivative of CC 2nd term w.r.t. cos(theta_jik)
 //app2 is derivative of CC 2nd term w.r.t. cos(theta_jik')
 //app3 is derivative of CC 2nd term w.r.t. cos(theta_kik')
- 
+
                       agpdpr1=4.0*gfactor*rfactorrt*betaS[temp_ikp]
                           *dBetaS[temp_ik]/rij[temp_ik];
                       agpdpr2=4.0*gfactor*rfactorrt*betaS[temp_ik]
                           *dBetaS[temp_ikp]/rij[temp_ikp];
                       app1=2.0*rfactor*gfactor2*gfactor3*gprime1;
                       app2=2.0*rfactor*gfactor1*gfactor3*gprime2;
                       app3=2.0*rfactor*gfactor1*gfactor2*gprime3;
                       bt_sg[nb_ij].dCC[0]+=
                           app1*dcAng[ang_jik][0][ngj]
                           +app2*dcAng[ang_jikp][0][nglj];
                       bt_sg[nb_ij].dCC[1]+=
                           app1*dcAng[ang_jik][1][ngj]
                           +app2*dcAng[ang_jikp][1][nglj];
                       bt_sg[nb_ij].dCC[2]+=
                           app1*dcAng[ang_jik][2][ngj]
                           +app2*dcAng[ang_jikp][2][nglj];
                       bt_sg[nb_ik].dCC[0]+=
                           app1*dcAng[ang_jik][0][ngk]
                           +app3*dcAng[ang_kikp][0][nglk]
                           +agpdpr1*disij[0][temp_ik];
                       bt_sg[nb_ik].dCC[1]+=
                           app1*dcAng[ang_jik][1][ngk]
                           +app3*dcAng[ang_kikp][1][nglk]
                           +agpdpr1*disij[1][temp_ik];
                       bt_sg[nb_ik].dCC[2]+=
                           app1*dcAng[ang_jik][2][ngk]
                           +app3*dcAng[ang_kikp][2][nglk]
                           +agpdpr1*disij[2][temp_ik];
                       bt_sg[nb_ikp].dCC[0]+=
                           app2*dcAng[ang_jikp][0][ngl]
                           +app3*dcAng[ang_kikp][0][nglkp]
                           +agpdpr2*disij[0][temp_ikp];
                       bt_sg[nb_ikp].dCC[1]+=
                           app2*dcAng[ang_jikp][1][ngl]
                           +app3*dcAng[ang_kikp][1][nglkp]
                           +agpdpr2*disij[1][temp_ikp];
                       bt_sg[nb_ikp].dCC[2]+=
                           app2*dcAng[ang_jikp][2][ngl]
                           +app3*dcAng[ang_kikp][2][nglkp]
                           +agpdpr2*disij[2][temp_ikp];
                     }
                   }
                 }
 
 // j and k are different neighbors of i and k' is a neighbor k not equal to i
 
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   if(neigh_flag[temp_kkp]) {
                     kp=klist[ltmp];;
                     kptype = map[type[kp]]+1;
                     same_ikp=0;
                     same_jkp=0;
                     if(x[i][0]==x[kp][0]) {
                       if(x[i][1]==x[kp][1]) {
                         if(x[i][2]==x[kp][2]) {
                           same_ikp=1;
                         }
                       }
                     }
                     if(x[j][0]==x[kp][0]) {
                       if(x[j][1]==x[kp][1]) {
                         if(x[j][2]==x[kp][2]) {
                           same_jkp=1;
                         }
                       }
                     }
                     if(!same_ikp&&!same_jkp) {
                       if(kNeii<ltmp) {
                         nikkp=kNeii*(2*numneigh[k]-kNeii-1)/2+(ltmp-kNeii)-1;
                         nglkp=1;
                         ngli=0;
                       }
                       else {
                         nikkp=ltmp*(2*numneigh[k]-ltmp-1)/2+(kNeii-ltmp)-1;
                         nglkp=0;
                         ngli=1;
                       }
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               sig_flag=1;
                               nkp=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         nkp=nSigBk[n]-1;
                         itypeSigBk[n][nkp]=kp;
                       }
                       ang_ikkp=cos_index[k]+nikkp;
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
-                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];          
-                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];          
-                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];          
+                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
+                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
+                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                       amean=cosAng[ang_ikkp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS[temp_ik]*betaS[temp_kkp];
                       rfactor=rfactorrt*rfactorrt;
 
-//3rd CC is third term of Eq. 11 (c) for i atom 
+//3rd CC is third term of Eq. 11 (c) for i atom
 //where j , k =neighbor of i & k' =neighbor of k
 
                       CC=CC+gfactor*rfactor;
                       agpdpr1=2.0*gfactor*rfactorrt*betaS[temp_kkp]
                           *dBetaS[temp_ik]/rij[temp_ik];
                       agpdpr2=2.0*gfactor*rfactorrt*betaS[temp_ik]
                           *dBetaS[temp_kkp]/rij[temp_kkp];
                       app1=rfactor*gfactorsq2*gsqprime;
                       app2=rfactor*gfactorsq*gsqprime2;
                       bt_sg[nb_ij].dCC[0]+=
                           app1*dcAng[ang_jik][0][ngj];
                       bt_sg[nb_ij].dCC[1]+=
                           app1*dcAng[ang_jik][1][ngj];
                       bt_sg[nb_ij].dCC[2]+=
                           app1*dcAng[ang_jik][2][ngj];
                       bt_sg[nb_ik].dCC[0]+=
                           app1*dcAng[ang_jik][0][ngk]
                           +agpdpr1*disij[0][temp_ik]
                           -app2*dcAng[ang_ikkp][0][ngli];
                       bt_sg[nb_ik].dCC[1]+=
                           app1*dcAng[ang_jik][1][ngk]
                           +agpdpr1*disij[1][temp_ik]
                           -app2*dcAng[ang_ikkp][1][ngli];
                       bt_sg[nb_ik].dCC[2]+=
                           app1*dcAng[ang_jik][2][ngk]
                           +agpdpr1*disij[2][temp_ik]
                           -app2*dcAng[ang_ikkp][2][ngli];
                       bt_sg[nb_kkp].dCC[0]+=
                           app2*dcAng[ang_ikkp][0][nglkp]
                           +agpdpr2*disij[0][temp_kkp];
                       bt_sg[nb_kkp].dCC[1]+=
                           app2*dcAng[ang_ikkp][1][nglkp]
                           +agpdpr2*disij[1][temp_kkp];
                       bt_sg[nb_kkp].dCC[2]+=
                           app2*dcAng[ang_ikkp][2][nglkp]
                           +agpdpr2*disij[2][temp_kkp];
 
                     }
                   }
                 }
 
        //j and k are different neighbors of i and k' is a neighbor j not equal to k
- 
+
                 kplist=firstneigh[kp];
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   sig_flag=0;
                   temp_jkp=BOP_index[j]+ltmp;
                   if(neigh_flag[temp_jkp]) {
                     kp=jlist[ltmp];
                     kptype = map[type[kp]]+1;
                     same_jkp=0;
                     same_kkp=0;
                     for(kpNeij=0;kpNeij<numneigh[kp];kpNeij++) {
                       if(x[j][0]==x[kp][0]) {
                         if(x[j][1]==x[kp][1]) {
                           if(x[j][2]==x[kp][2]) {
                             same_jkp=1;
                             break;
                           }
                         }
                       }
                     }
                     for(kpNeik=0;kpNeik<numneigh[kp];kpNeik++) {
                       if(x[k][0]==x[kp][0]) {
                         if(x[k][1]==x[kp][1]) {
                           if(x[k][2]==x[kp][2]) {
                             same_kkp=1;
                             break;
                           }
                         }
                       }
                     }
                     if(!same_kkp&&!same_jkp) {
                       for(kNeikp=0;kNeikp<numneigh[k];kNeikp++) {
                         temp_kkp=BOP_index[k]+kNeikp;
                         kkp=klist[kNeikp];
                         if(x[kkp][0]==x[kp][0]) {
                           if(x[kkp][1]==x[kp][1]) {
                             if(x[kkp][2]==x[kp][2]) {
                               sig_flag=1;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==1) {
                         for(nsearch=0;nsearch<numneigh[kp];nsearch++) {
                           kp_nsearch=BOP_index[kp]+nsearch;
                           ncmp=kplist[nsearch];
                           if(x[ncmp][0]==x[j][0]) {
                             if(x[ncmp][1]==x[j][1]) {
                               if(x[ncmp][2]==x[j][2]) {
                                 kpNeij=nsearch;
                               }
                             }
                           }
                           if(x[ncmp][0]==x[k][0]) {
                             if(x[ncmp][1]==x[k][1]) {
                               if(x[ncmp][2]==x[k][2]) {
                                 kpNeik=nsearch;
                               }
                             }
                           }
                         }
                         if(ji<ltmp) {
                           nijkp=(ji)*numneigh[j]-(ji+1)*(ji+2)/2+ltmp;
                           ngji=0;
                           ngjkp=1;
                         }
                         else {
                           nijkp=(ltmp)*numneigh[j]-(ltmp+1)*(ltmp+2)/2+ji;
                           ngji=1;
                           ngjkp=0;
                         }
                         if(kNeii<kNeikp) {
                           nikkp=(kNeii)*numneigh[k]-(kNeii+1)*(kNeii+2)/2+kNeikp;
                           ngki=0;
                           ngkkp=1;
                         }
                         else {
                           nikkp=(kNeikp)*numneigh[k]-(kNeikp+1)*(kNeikp+2)/2+kNeii;
                           ngki=1;
                           ngkkp=0;
                         }
                         if(kpNeij<kpNeik) {
                           njkpk=(kpNeij)*numneigh[kp]-(kpNeij+1)*(kpNeij+2)/2+kpNeik;
                           ngkpj=0;
                           ngkpk=1;
                         }
                         else {
                           njkpk=(kpNeik)*numneigh[kp]-(kpNeik+1)*(kpNeik+2)/2+kpNeij;
                           ngkpj=1;
                           ngkpk=0;
                         }
                         sig_flag=0;
                         for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                           ncmp=itypeSigBk[n][nsearch];
                           if(x[ncmp][0]==x[kp][0]) {
                             if(x[ncmp][1]==x[kp][1]) {
                               if(x[ncmp][2]==x[kp][2]) {
                                 nkp=nsearch;
                                 sig_flag=1;
                                 break;
                               }
                             }
                           }
                         }
                         if(sig_flag==0) {
                           nSigBk[n]=nSigBk[n]+1;
                           nkp=nSigBk[n]-1;
                           itypeSigBk[n][nkp]=kp;
                         }
                         ang_ijkp=cos_index[j]+nijkp;
                         ang_ikkp=cos_index[k]+nikkp;
                         ang_jkpk=cos_index[kp]+njkpk;
                         nb_jkp=nb_t;
                         nb_t++;
                         if(nb_t>nb_sg) {
                           new_n_tot=nb_sg+maxneigh;
                           grow_sigma(nb_sg,new_n_tot);
                           nb_sg=new_n_tot;
                         }
                         bt_sg[nb_jkp].temp=temp_jkp;
                         bt_sg[nb_jkp].i=j;
                         bt_sg[nb_jkp].j=kp;
                         nb_kkp=nb_t;
                         nb_t++;
                         if(nb_t>nb_sg) {
                           new_n_tot=nb_sg+maxneigh;
                           grow_sigma(nb_sg,new_n_tot);
                           nb_sg=new_n_tot;
                         }
                         bt_sg[nb_kkp].temp=temp_kkp;
                         bt_sg[nb_kkp].i=k;
                         bt_sg[nb_kkp].j=kp;
                         gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                         gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                         gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                         amean=cosAng[ang_ijkp];
                         gfactor2=gmean0+gmean1*amean
                             +gmean2*amean*amean;
                         gprime2=gmean1+2.0*gmean2*amean;
                         gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
                         gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
                         gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                         amean=cosAng[ang_ikkp];
                         gfactor3=gmean0+gmean1*amean
                             +gmean2*amean*amean;
                         gprime3=gmean1+2.0*gmean2*amean;
                         gmean0=sigma_g0[jtype-1][kptype-1][ktype-1];
                         gmean1=sigma_g1[jtype-1][kptype-1][ktype-1];
                         gmean2=sigma_g2[jtype-1][kptype-1][ktype-1];
                         amean=cosAng[ang_jkpk];
                         gfactor4=gmean0+gmean1*amean
                             +gmean2*amean*amean;
                         gprime4=gmean1+2.0*gmean2*amean;
                         gfactor=gfactor1*gfactor2*gfactor3*gfactor4;
                         rfactor0=(betaS[temp_ik]+small2)*(betaS[temp_jkp]+small2)
                             *(betaS[temp_kkp]+small2);
                         rfactor=pow(rfactor0,2.0/3.0);
                         drfactor=2.0/3.0*pow(rfactor0,-1.0/3.0);
- 
+
 //EE is Eq. 25(notes)
- 
+
                         EE=EE+gfactor*rfactor;
- 
+
 //agpdpr1 is derivative of agpdpr1 w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of agpdpr1 w.r.t. Beta(r_jk')
 //agpdpr3 is derivative of agpdpr1 w.r.t. Beta(r_kk')
 //app1 is derivative of agpdpr1 w.r.t. cos(theta_jik)
 //app2 is derivative of agpdpr1 w.r.t. cos(theta_ijk')
 //app3 is derivative of agpdpr1 w.r.t. cos(theta_ikk')
 //app4 is derivative of agpdpr1 w.r.t. cos(theta_jk'k)
- 
+
                         agpdpr1=gfactor*drfactor*(betaS[temp_jkp]+small2)*(betaS[temp_kkp]
                             +small2)*dBetaS[temp_ik]/rij[temp_ik];
                         agpdpr2=gfactor*drfactor*(betaS[temp_ik]+small2)*(betaS[temp_kkp]
                             +small2)*dBetaS[temp_jkp]/rij[temp_jkp];
                         agpdpr3=gfactor*drfactor*(betaS[temp_ik]+small2)*(betaS[temp_jkp]
                             +small2)*dBetaS[temp_kkp]/rij[temp_kkp];
                         app1=rfactor*gfactor2*gfactor3*gfactor4*gprime1;
                         app2=rfactor*gfactor1*gfactor3*gfactor4*gprime2;
                         app3=rfactor*gfactor1*gfactor2*gfactor4*gprime3;
                         app4=rfactor*gfactor1*gfactor2*gfactor3*gprime4;
                         bt_sg[nb_ij].dEE[0]+=
                             app1*dcAng[ang_jik][0][ngj]
                             -app2*dcAng[ang_ijkp][0][ngji];
                         bt_sg[nb_ij].dEE[1]+=
                             app1*dcAng[ang_jik][1][ngj]
                             -app2*dcAng[ang_ijkp][1][ngji];
                         bt_sg[nb_ij].dEE[2]+=
                             app1*dcAng[ang_jik][2][ngj]
                             -app2*dcAng[ang_ijkp][2][ngji];
                         bt_sg[nb_ik].dEE[0]+=
                             app1*dcAng[ang_jik][0][ngk]
                             +agpdpr1*disij[0][temp_ik]
                             -app3*dcAng[ang_ikkp][0][ngki];
                         bt_sg[nb_ik].dEE[1]+=
                             app1*dcAng[ang_jik][1][ngk]
                             +agpdpr1*disij[1][temp_ik]
                             -app3*dcAng[ang_ikkp][1][ngki];
                         bt_sg[nb_ik].dEE[2]+=
                             app1*dcAng[ang_jik][2][ngk]
                             +agpdpr1*disij[2][temp_ik]
                             -app3*dcAng[ang_ikkp][2][ngki];
                         bt_sg[nb_jkp].dEE[0]+=
                             app2*dcAng[ang_ijkp][0][ngjkp]
                             +agpdpr2*disij[0][temp_jkp]
                             -app4*dcAng[ang_jkpk][0][ngkpj];
                         bt_sg[nb_jkp].dEE[1]+=
                             app2*dcAng[ang_ijkp][1][ngjkp]
                             +agpdpr2*disij[1][temp_jkp]
                             -app4*dcAng[ang_jkpk][1][ngkpj];
                         bt_sg[nb_jkp].dEE[2]+=
                             app2*dcAng[ang_ijkp][2][ngjkp]
                             +agpdpr2*disij[2][temp_jkp]
                             -app4*dcAng[ang_jkpk][2][ngkpj];
                         bt_sg[nb_kkp].dEE[0]+=
                             app3*dcAng[ang_ikkp][0][ngkkp]
                             +agpdpr3*disij[0][temp_kkp]
                             -app4*dcAng[ang_jkpk][0][ngkpk];
                         bt_sg[nb_kkp].dEE[1]+=
                             app3*dcAng[ang_ikkp][1][ngkkp]
                             +agpdpr3*disij[1][temp_kkp]
                             -app4*dcAng[ang_jkpk][1][ngkpk];
                         bt_sg[nb_kkp].dEE[2]+=
                             app3*dcAng[ang_ikkp][2][ngkkp]
                             +agpdpr3*disij[2][temp_kkp]
                             -app4*dcAng[ang_jkpk][2][ngkpk];
                       }
                     }
                   }
                 }
               }
             }
           }
 
 //j is a neighbor of i and k is a neighbor of j not equal to i
 
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ji) {
               if(ktmp<ji) {
                 njik=ktmp*(2*numneigh[j]-ktmp-1)/2+(ji-ktmp)-1;
                 ngi=1;
                 ngk=0;
               }
               else {
                 njik=ji*(2*numneigh[j]-ji-1)/2+(ktmp-ji)-1;
                 ngi=0;
                 ngk=1;
               }
               temp_jk=BOP_index[j]+ktmp;
               if(neigh_flag[temp_jk]) {
                 k=jlist[ktmp];
                 ktype=map[type[k]]+1;
                 klist=firstneigh[k];
 
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         new1=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   new1=nSigBk[n]-1;
                   itypeSigBk[n][new1]=k;
                 }
                 ang_ijk=cos_index[j]+njik;
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                 gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                 gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                 amean=cosAng[ang_ijk];
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gsqprime=2.0*gfactor1*gprime1;
                 rfactor1rt=betaS[temp_jk]*betaS[temp_jk];
                 rfactor1=rfactor1rt*rfactor1rt;
 
 //BB is Eq. 34 (a) or Eq. 10 (c) for the j atom
 //1st DD is Eq. 11 (c) for j atom where i & k=neighbor of j
 
                 BB=BB+gfactorsq*rfactor1rt;
                 DD=DD+gfactorsq*rfactor1;
 
 //agpdpr1 is derivative of BB  w.r.t. Beta(r_jk)
 //app1 is derivative of BB w.r.t. cos(theta_ijk)
 
                 agpdpr1=2.0*gfactorsq*betaS[temp_jk]*dBetaS[temp_jk]/rij[temp_jk];
                 app1=rfactor1rt*gsqprime;
                 bt_sg[nb_ij].dBB[0]-=
                     app1*dcAng[ang_ijk][0][ngi];
                 bt_sg[nb_ij].dBB[1]-=
                     app1*dcAng[ang_ijk][1][ngi];
                 bt_sg[nb_ij].dBB[2]-=
                     app1*dcAng[ang_ijk][2][ngi];
                 bt_sg[nb_ij].dDD[0]-=
                     app2*dcAng[ang_ijk][0][ngi];
                 bt_sg[nb_ij].dDD[1]-=
                     app2*dcAng[ang_ijk][1][ngi];
                 bt_sg[nb_ij].dDD[2]-=
                     app2*dcAng[ang_ijk][2][ngi];
                 bt_sg[nb_jk].dBB[0]+=
                     app1*dcAng[ang_ijk][0][ngk]
                     +agpdpr1*disij[0][temp_jk];
                 bt_sg[nb_jk].dBB[1]+=
                     app1*dcAng[ang_ijk][1][ngk]
                     +agpdpr1*disij[1][temp_jk];
                 bt_sg[nb_jk].dBB[2]+=
                     app1*dcAng[ang_ijk][2][ngk]
                     +agpdpr1*disij[2][temp_jk];
                 bt_sg[nb_jk].dDD[0]+=
                     app2*dcAng[ang_ijk][0][ngk]
                     +agpdpr2*disij[0][temp_jk];
                 bt_sg[nb_jk].dDD[1]+=
                     app2*dcAng[ang_ijk][1][ngk]
                     +agpdpr2*disij[1][temp_jk];
                 bt_sg[nb_jk].dDD[2]+=
                     app2*dcAng[ang_ijk][2][ngk]
                     +agpdpr2*disij[2][temp_jk];
 
 //j is a neighbor of i, k and k' prime different neighbors of j not equal to i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ji) {
                     temp_jkp=BOP_index[j]+ltmp;
                     if(neigh_flag[temp_jkp]) {
                       kp=jlist[ltmp];
                       kptype=map[type[kp]]+1;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               new2=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(ji<ltmp) {
                         nijkp=ji*(2*numneigh[j]-ji-1)/2+(ltmp-ji)-1;
                         ngli=0;
                         ngl=1;
                       }
                       else {
                         nijkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ji-ltmp)-1;
                         ngli=1;
                         ngl=0;
                       }
                       if(ktmp<ltmp) {
                         nkjkp=ktmp*(2*numneigh[j]-ktmp-1)/2+(ltmp-ktmp)-1;
                         ngjk=0;
                         ngjkp=1;
                       }
                       else {
                         nkjkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ktmp-ltmp)-1;
                         ngjk=1;
                         ngjkp=0;
                       }
                       ang_ijkp=cos_index[j]+nijkp;
                       ang_kjkp=cos_index[j]+nkjkp;
                       gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                       amean=cosAng[ang_ijkp];
                       gfactor2=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][jtype-1][kptype-1];
                       amean=cosAng[ang_kjkp];
                       gfactor3=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS[temp_jk]*betaS[temp_jkp];
                       rfactor=rfactorrt*rfactorrt;
 
 //2nd DD is Eq. 11 (c) for j atom where i , k & k'=neighbor of j
 
                       DD=DD+2.0*gfactor*rfactor;
 
 //agpdpr1 is derivative of DD  w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of DD  w.r.t. Beta(r_jk')
 //app1 is derivative of DD  w.r.t. cos(theta_ijk)
 //app2 is derivative of DD  w.r.t. cos(theta_ijkp)
 //app3 is derivative of DD  w.r.t. cos(theta_kjkp)
- 
+
                       agpdpr1=4.0*gfactor*rfactorrt*betaS[temp_jkp]
                           *dBetaS[temp_jk]/rij[temp_jk];
                           agpdpr2=4.0*gfactor*rfactorrt*betaS[temp_jk]
                           *dBetaS[temp_jkp]/rij[temp_jkp];
                       app1=2.0*rfactor*gfactor2*gfactor3*gprime1;
                       app2=2.0*rfactor*gfactor1*gfactor3*gprime2;
                       app3=2.0*rfactor*gfactor1*gfactor2*gprime3;
                       bt_sg[nb_ij].dDD[0]-=
                           app1*dcAng[ang_ijk][0][ngi]
                           +app2*dcAng[ang_ijkp][0][ngli];
                       bt_sg[nb_ij].dDD[1]-=
                           app1*dcAng[ang_ijk][1][ngi]
                           +app2*dcAng[ang_ijkp][1][ngli];
                       bt_sg[nb_ij].dDD[2]-=
                           app1*dcAng[ang_ijk][2][ngi]
                           +app2*dcAng[ang_ijkp][2][ngli];
                       bt_sg[nb_jk].dDD[0]+=
                           app1*dcAng[ang_ijk][0][ngk]
                           +app3*dcAng[ang_kjkp][0][ngjk]
                           +agpdpr1*disij[0][temp_jk];
                       bt_sg[nb_jk].dDD[1]+=
                           app1*dcAng[ang_ijk][1][ngk]
                           +app3*dcAng[ang_kjkp][1][ngjk]
                           +agpdpr1*disij[1][temp_jk];
                       bt_sg[nb_jk].dDD[2]+=
                           app1*dcAng[ang_ijk][2][ngk]
                           +app3*dcAng[ang_kjkp][2][ngjk]
                           +agpdpr1*disij[2][temp_jk];
                       bt_sg[nb_jkp].dDD[0]+=
                           app2*dcAng[ang_ijkp][0][ngl]
                           +app3*dcAng[ang_kjkp][0][ngjkp]
                           +agpdpr2*disij[0][temp_jkp];
                       bt_sg[nb_jkp].dDD[1]+=
                           app2*dcAng[ang_ijkp][1][ngl]
                           +app3*dcAng[ang_kjkp][1][ngjkp]
                           +agpdpr2*disij[1][temp_jkp];
                       bt_sg[nb_jkp].dDD[2]+=
                           app2*dcAng[ang_ijkp][2][ngl]
                           +app3*dcAng[ang_kjkp][2][ngjkp]
                           +agpdpr2*disij[2][temp_jkp];
                     }
                   }
                 }
 
-//j is a neighbor of i, k is a neighbor of j not equal to i and k' 
+//j is a neighbor of i, k is a neighbor of j not equal to i and k'
 //is a neighbor of k not equal to j or i
 
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   if(neigh_flag[temp_kkp]) {
                     kp=klist[ltmp];
                     kptype=map[type[kp]]+1;
                     same_ikp=0;
                     same_jkp=0;
                     if(x[i][0]==x[kp][0]) {
                       if(x[i][1]==x[kp][1]) {
                         if(x[i][2]==x[kp][2]) {
                           same_ikp=1;
                         }
                       }
                     }
                     if(x[j][0]==x[kp][0]) {
                       if(x[j][1]==x[kp][1]) {
                         if(x[j][2]==x[kp][2]) {
                           same_jkp=1;
                         }
                       }
                     }
                     if(!same_ikp&&!same_jkp) {
                       for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                         if(x[klist[kNeij]][0]==x[j][0]) {
                           if(x[klist[kNeij]][1]==x[j][1]) {
                             if(x[klist[kNeij]][2]==x[j][2]) {
                               break;
                             }
                           }
                         }
                       }
                       if(kNeij<ltmp) {
                         njkkp=kNeij*(2*numneigh[k]-kNeij-1)/2+(ltmp-kNeij)-1;
                         nglkp=1;
                         nglj=0;
                       }
                       else {
                         njkkp=ltmp*(2*numneigh[k]-ltmp-1)/2+(kNeij-ltmp)-1;
                         nglkp=0;
                         nglj=1;
                       }
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               new2=nsearch;
                               sig_flag=1;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         new2=nSigBk[n]-1;
                         itypeSigBk[n][new2]=kp;
                       }
                       ang_jkkp=cos_index[k]+njkkp;
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
                       gmean0=sigma_g0[jtype-1][ktype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][ktype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][ktype-1][kptype-1];
                       amean=cosAng[ang_jkkp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS[temp_jk]*betaS[temp_kkp];
                       rfactor=rfactorrt*rfactorrt;
 
 //3rd DD is Eq. 11 (c) for j atom where i & k=neighbor of j & k'=neighbor of k
 
                       DD=DD+gfactor*rfactor;
 
 //agpdpr1 is derivative of DD  3rd term w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of DD  3rd term w.r.t. Beta(r_kk')
 //app1 is derivative of DD  3rd term w.r.t. cos(theta_ijk)
 //app2 is derivative of DD  3rd term w.r.t. cos(theta_jkkp)
- 
+
                       agpdpr1=2.0*gfactor*rfactorrt*betaS[temp_kkp]
                           *dBetaS[temp_jk]/rij[temp_jk];
                       agpdpr2=2.0*gfactor*rfactorrt*betaS[temp_jk]
                           *dBetaS[temp_kkp]/rij[temp_kkp];
                       app1=rfactor*gfactorsq2*gsqprime;
                       app2=rfactor*gfactorsq*gsqprime2;
                       bt_sg[nb_ij].dDD[0]-=
                           app1*dcAng[ang_ijk][0][ngi];
                       bt_sg[nb_ij].dDD[1]-=
                           app1*dcAng[ang_ijk][1][ngi];
                       bt_sg[nb_ij].dDD[2]-=
                           app1*dcAng[ang_ijk][2][ngi];
                       bt_sg[nb_jk].dDD[0]+=
                           app1*dcAng[ang_ijk][0][ngk]
                           +agpdpr1*disij[0][temp_jk]
                           -app2*dcAng[ang_jkkp][0][nglj];
                       bt_sg[nb_jk].dDD[1]+=
                           app1*dcAng[ang_ijk][1][ngk]
                           +agpdpr1*disij[1][temp_jk]
                           -app2*dcAng[ang_jkkp][1][nglj];
                       bt_sg[nb_jk].dDD[2]+=
                           app1*dcAng[ang_ijk][2][ngk]
                           +agpdpr1*disij[2][temp_jk]
                           -app2*dcAng[ang_jkkp][2][nglj];
                       bt_sg[nb_kkp].dDD[0]+=
                           app2*dcAng[ang_jkkp][0][nglkp]
                           +agpdpr2*disij[0][temp_kkp];
                       bt_sg[nb_kkp].dDD[1]+=
                           app2*dcAng[ang_jkkp][1][nglkp]
                           +agpdpr2*disij[1][temp_kkp];
                       bt_sg[nb_kkp].dDD[2]+=
                           app2*dcAng[ang_jkkp][2][nglkp]
                           +agpdpr2*disij[2][temp_kkp];
                     }
                   }
                 }
               }
             }
           }
 
           sig_flag=0;
           if(FF<=0.000001) {
             sigB[n]=0.0;
             sig_flag=1;
           }
           if(sig_flag==0) {
             if(AA<0.0)
               AA=0.0;
             if(BB<0.0)
               BB=0.0;
             if(CC<0.0)
               CC=0.0;
             if(DD<0.0)
               DD=0.0;
 
 // AA and BB are the representations of (a) Eq. 34 and (b) Eq. 9
 // for atoms i and j respectively
 
             AAC=AA+BB;
             BBC=AA*BB;
             CCC=AA*AA+BB*BB;
             DDC=CC+DD;
 
 //EEC is a modified form of (a) Eq. 33
 
             EEC=(DDC-CCC)/(AAC+2.0*small1);
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 bt_sg[m].dAAC[0]=bt_sg[m].dAA[0]
                     +bt_sg[m].dBB[0];
                 bt_sg[m].dAAC[1]=bt_sg[m].dAA[1]
                     +bt_sg[m].dBB[1];
                 bt_sg[m].dAAC[2]=bt_sg[m].dAA[2]
                     +bt_sg[m].dBB[2];
                 bt_sg[m].dBBC[0]=bt_sg[m].dAA[0]*BB
                     +AA*bt_sg[m].dBB[0];
                 bt_sg[m].dBBC[1]=bt_sg[m].dAA[1]*BB
                     +AA*bt_sg[m].dBB[1];
                 bt_sg[m].dBBC[2]=bt_sg[m].dAA[2]*BB
                     +AA*bt_sg[m].dBB[2];
                 bt_sg[m].dCCC[0]=2.0*AA*bt_sg[m].dAA[0]
                     +2.0*BB*bt_sg[m].dBB[0];
                 bt_sg[m].dCCC[1]=2.0*AA*bt_sg[m].dAA[1]
                     +2.0*BB*bt_sg[m].dBB[1];
                 bt_sg[m].dCCC[2]=2.0*AA*bt_sg[m].dAA[2]
                     +2.0*BB*bt_sg[m].dBB[2];
                 bt_sg[m].dDDC[0]=bt_sg[m].dCC[0]
                     +bt_sg[m].dDD[0];
                 bt_sg[m].dDDC[1]=bt_sg[m].dCC[1]
                     +bt_sg[m].dDD[1];
                 bt_sg[m].dDDC[2]=bt_sg[m].dCC[2]
                     +bt_sg[m].dDD[2];
                 bt_sg[m].dEEC[0]=(bt_sg[m].dDDC[0]
                     -bt_sg[m].dCCC[0]
                     -EEC*bt_sg[m].dAAC[0])*AACFF;
                 bt_sg[m].dEEC[1]=(bt_sg[m].dDDC[1]
                     -bt_sg[m].dCCC[1]
                     -EEC*bt_sg[m].dAAC[1])*AACFF;
                 bt_sg[m].dEEC[2]=(bt_sg[m].dDDC[2]
                     -bt_sg[m].dCCC[2]
                     -EEC*bt_sg[m].dAAC[2])*AACFF;
-              } 
+              }
             }
             UT=EEC*FF+BBC+small3[iij];
             UT=1.0/sqrt(UT);
 
 // FFC is slightly modified form of (a) Eq. 31
 // GGC is slightly modified form of (a) Eq. 32
 // bndtmp is a slightly modified form of (a) Eq. 30 and (b) Eq. 8
 
             FFC=BBC*UT;
             GGC=EEC*UT;
             bndtmp=(FF+sigma_delta[iij]*sigma_delta[iij])
                 +sigma_c[iij]*AAC+small4;
             UTcom=-0.5*UT*UT*UT;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_sg[m].dUT[0]=UTcom*(bt_sg[m].dEEC[0]*FF
                     +EEC*bt_sg[m].dFF[0]+bt_sg[m].dBBC[0]);
                 bt_sg[m].dUT[1]=UTcom*(bt_sg[m].dEEC[1]*FF
                     +EEC*bt_sg[m].dFF[1]+bt_sg[m].dBBC[1]);
                 bt_sg[m].dUT[2]=UTcom*(bt_sg[m].dEEC[2]*FF
                     +EEC*bt_sg[m].dFF[2]+bt_sg[m].dBBC[2]);
                 bt_sg[m].dFFC[0]=bt_sg[m].dBBC[0]*UT
                     +BBC*bt_sg[m].dUT[0];
                 bt_sg[m].dFFC[1]=bt_sg[m].dBBC[1]*UT
                     +BBC*bt_sg[m].dUT[1];
                 bt_sg[m].dFFC[2]=bt_sg[m].dBBC[2]*UT
                     +BBC*bt_sg[m].dUT[2];
                 bt_sg[m].dGGC[0]=bt_sg[m].dEEC[0]*UT
                     +EEC*bt_sg[m].dUT[0];
                 bt_sg[m].dGGC[1]=bt_sg[m].dEEC[1]*UT
                     +EEC*bt_sg[m].dUT[1];
                 bt_sg[m].dGGC[2]=bt_sg[m].dEEC[2]*UT
                     +EEC*bt_sg[m].dUT[2];
               }
             }
             psign=1.0;
             if(1.0+sigma_a[iij]*GGC<0.0)
               psign=-1.0;
             bndtmp0=1.0/sqrt(bndtmp);
             sigB1[n]=psign*betaS[temp_ij]*(1.0+sigma_a[iij]*GGC)*bndtmp0;
             bndtmp=-0.5*bndtmp0*bndtmp0*bndtmp0;
             bndtmp1=psign*(1.0+sigma_a[iij]*GGC)*bndtmp0+psign*betaS[temp_ij]
                 *(1.0+sigma_a[iij]*GGC)*bndtmp*2.0*betaS[temp_ij]*(1.0
                 +sigma_a[iij]*GGC)*(1.0+sigma_a[iij]*GGC);
             bndtmp1=bndtmp1*dBetaS[temp_ij]/rij[temp_ij];
             bndtmp2=psign*betaS[temp_ij]*(1.0+sigma_a[iij]*GGC)*bndtmp*sigma_c[iij];
             bndtmp3=psign*betaS[temp_ij]*(1.0+sigma_a[iij]*GGC)
                 *bndtmp*sigma_c[iij]*sigma_a[iij];
             bndtmp4=psign*betaS[temp_ij]*(1.0+sigma_a[iij]*GGC)
                 *bndtmp*sigma_c[iij]*sigma_a[iij]*(2.0+GGC);
             bndtmp5=sigma_a[iij]*psign*betaS[temp_ij]*bndtmp0
                 +psign*betaS[temp_ij]*(1.0+sigma_a[iij]*GGC)*bndtmp
                 *(2.0*(FF+sigma_delta[iij]*sigma_delta[iij])*(1.0
                 +sigma_a[iij]*GGC)*sigma_a[iij]+sigma_c[iij]*sigma_a[iij]*FFC);
             setting=0;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 if(temp_kk==temp_ij&&setting==0) {
                   bt_sg[m].dSigB1[0]=bndtmp1*disij[0][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=bndtmp1*disij[1][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=bndtmp1*disij[2][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                   setting=1;
                 }
                 else if(temp_kk==temp_ji&&setting==0) {
                   bt_sg[m].dSigB1[0]=-bndtmp1*disij[0][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=-bndtmp1*disij[1][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=-bndtmp1*disij[2][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                   setting=1;
                 }
                 else {
                   bt_sg[m].dSigB1[0]=(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                 }
               }
             }
 
 //This loop is to ensure there is not an error for atoms with no neighbors (deposition)
 
             if(nb_t==0) {
               if(j>i) {
                 bt_sg[0].dSigB1[0]=bndtmp1*disij[0][temp_ij];
                 bt_sg[0].dSigB1[1]=bndtmp1*disij[1][temp_ij];
                 bt_sg[0].dSigB1[2]=bndtmp1*disij[2][temp_ij];
               }
               else {
                 bt_sg[0].dSigB1[0]=-bndtmp1*disij[0][temp_ij];
                 bt_sg[0].dSigB1[1]=-bndtmp1*disij[1][temp_ij];
                 bt_sg[0].dSigB1[2]=-bndtmp1*disij[2][temp_ij];
               }
               for(pp=0;pp<3;pp++) {
                 bt_sg[0].dAA[pp]=0.0;
                 bt_sg[0].dBB[pp]=0.0;
                 bt_sg[0].dCC[pp]=0.0;
                 bt_sg[0].dDD[pp]=0.0;
                 bt_sg[0].dEE[pp]=0.0;
                 bt_sg[0].dEE1[pp]=0.0;
                 bt_sg[0].dFF[pp]=0.0;
                 bt_sg[0].dAAC[pp]=0.0;
                 bt_sg[0].dBBC[pp]=0.0;
                 bt_sg[0].dCCC[pp]=0.0;
                 bt_sg[0].dDDC[pp]=0.0;
                 bt_sg[0].dEEC[pp]=0.0;
                 bt_sg[0].dFFC[pp]=0.0;
                 bt_sg[0].dGGC[pp]=0.0;
                 bt_sg[0].dUT[pp]=0.0;
                 bt_sg[0].dSigB1[pp]=0.0;
                 bt_sg[0].dSigB[pp]=0.0;
               }
               bt_sg[0].i=i;
               bt_sg[0].j=j;
               bt_sg[0].temp=temp_ij;
               nb_t++;
               if(nb_t>nb_sg) {
                 new_n_tot=nb_sg+maxneigh;
                 grow_sigma(nb_sg,new_n_tot);
                 nb_sg=new_n_tot;
               }
             }
             ps=sigB1[n]*rdBO+1.0;
             ks=(int)ps;
             if(nBOt-1<ks)
               ks=nBOt-1;
             ps=ps-ks;
             if(ps>1.0)
               ps=1.0;
             dsigB1=((FsigBO3[iij][ks-1]*ps+FsigBO2[iij][ks-1])*ps
                 +FsigBO1[iij][ks-1])*ps+FsigBO[iij][ks-1];
             dsigB2=(FsigBO6[iij][ks-1]*ps+FsigBO5[iij][ks-1])*ps+FsigBO4[iij][ks-1];
             part0=(FF+0.5*AAC+small5);
             part1=(sigma_f[iij]-0.5)*sigma_k[iij];
             part2=1.0-part1*EE1/part0;
             part3=dsigB1*part1/part0;
             part4=part3/part0*EE1;
 
 // sigB is the final expression for (a) Eq. 6 and (b) Eq. 11
 
             sigB[n]=dsigB1*part2;
             pp1=2.0*betaS[temp_ij];
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 bt_ij=bt_sg[m].temp;
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 for(pp=0;pp<3;pp++) {
                   bt_sg[m].dSigB[pp]=dsigB2*part2*bt_sg[m].dSigB1[pp]
                       -part3*bt_sg[m].dEE1[pp]
                       +part4*(bt_sg[m].dFF[pp]
                       +0.5*bt_sg[m].dAAC[pp]);
                 }
                 for(pp=0;pp<3;pp++) {
                   ftmp[pp]=pp1*bt_sg[m].dSigB[pp];
                   f[bt_i][pp]-=ftmp[pp];
                   f[bt_j][pp]+=ftmp[pp];
                 }
                 if(evflag) {
                   ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                       ,ftmp[2],disij[0][bt_ij],disij[1][bt_ij],disij[2][bt_ij]);
                 }
               }
             }
           }
           n++;
         }
       }
     }
   }
   if(allocate_sigma)
     destroy_sigma();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::sigmaBo_noa()
 {
   int nb_t,new_n_tot;
   int n,i,j,k,kp,m,pp;
   int iij,ji,ki;
   int itmp,jtmp,ktmp,ltmp,mtmp;
   int i_tag,j_tag;
   int ngi,ngj,ngk,ngli,nglj,ngl;
   int ngji,ngjk,nikj,ngki,ngkj;
   int njik,nijk,nikkp,nkp,nijkp;
   int nkikp,njikp,nk0,nkjkp,njkkp;
   int jNeik,kNeii,kNeij;
   int new1,new2,nlocal,nsearch;
   int inum,*ilist,*iilist,*jlist,*klist;
   int **firstneigh,*numneigh;
   int temp_ji,temp_ikp,temp_ki,temp_kkp;
   int temp_ij,temp_ik,temp_jkp,temp_kk,temp_jk;
   int ang_ijkp,ang_ikkp,ang_kjkp;
   int ang_ijk,ang_ikj,ang_jikp,ang_jkkp;
   int ang_jik,ang_kikp;
   int nb_ij,nb_ik,nb_jk;
   int sig_flag,setting,ncmp,ks;
   int itype,jtype,ktype,kptype;
   int bt_i,bt_j,bt_ij;
   int kp_index,same_ikp,same_jkp;
   double AA,BB,CC,DD,EE,EE1,FF;
   double AAC,BBC,CCC,DDC,EEC,FFC,GGC;
   double AACFF,UT,bndtmp,UTcom;
   double amean,gmean0,gmean1,gmean2,ps;
   double gfactor1,gprime1,gsqprime,factorsq;
   double gfactorsq,gfactor2,gprime2;
   double gfactorsq2,gsqprime2;
   double gfactor3,gprime3,gfactor,rfactor;
   double drfactor,gfactor4,gprime4,agpdpr3;
   double rfactor0,rfactorrt,rfactor1rt,rfactor1;
   double rcm1,rcm2,gcm1,gcm2,gcm3;
   double agpdpr1,agpdpr2,app1,app2,app3,app4;
   double dsigB1,dsigB2;
   double part0,part1,part2,part3,part4;
   double psign,bndtmp0,pp1,bndtmp1,bndtmp2;
   double ftmp[3];
   double **x = atom->x;
   double **f = atom->f;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
   int *type = atom->type;
- 
+
   nlocal = atom->nlocal;
   int nall = nlocal+atom->nghost;
   firstneigh = list->firstneigh;
   numneigh = list->numneigh;
-  inum = list->inum; 
+  inum = list->inum;
   ilist = list->ilist;
   n=0;
- 
+
 //loop over all local atoms
 
   if(nb_sg>16) {
     nb_sg=16;
   }
   if(nb_sg==0) {
     nb_sg=(maxneigh)*(maxneigh/2);
   }
   if(allocate_sigma) {
     destroy_sigma();
   }
   create_sigma(nb_sg);
   for(itmp=0;itmp<inum;itmp++) {
     i = ilist[itmp];
-    i_tag=tag[i];  
+    i_tag=tag[i];
     itype = map[type[i]]+1;
 
 //j is loop over all neighbors of i
 
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       temp_ij=BOP_index[i]+jtmp;
       if(neigh_flag[temp_ij]) {
         for(m=0;m<nb_sg;m++) {
           for(pp=0;pp<3;pp++) {
             bt_sg[m].dAA[pp]=0.0;
             bt_sg[m].dBB[pp]=0.0;
             bt_sg[m].dEE1[pp]=0.0;
             bt_sg[m].dFF[pp]=0.0;
             bt_sg[m].dAAC[pp]=0.0;
             bt_sg[m].dSigB1[pp]=0.0;
             bt_sg[m].dSigB[pp]=0.0;
           }
           bt_sg[m].i=-1;
           bt_sg[m].j=-1;
         }
         nb_t=0;
         iilist=firstneigh[i];
         j=iilist[jtmp];
         jlist=firstneigh[j];
         for(ki=0;ki<numneigh[j];ki++) {
           temp_ki=BOP_index[j]+ki;
           if(x[jlist[ki]][0]==x[i][0]) {
             if(x[jlist[ki]][1]==x[i][1]) {
               if(x[jlist[ki]][2]==x[i][2]) {
                 break;
               }
             }
           }
-        } 
+        }
         j_tag=tag[j];
         jtype = map[type[j]]+1;
         nb_ij=nb_t;
         nb_t++;
         if(nb_t>nb_sg) {
           new_n_tot=nb_sg+maxneigh;
           grow_sigma(nb_sg,new_n_tot);
           nb_sg=new_n_tot;
         }
         bt_sg[nb_ij].temp=temp_ij;
         bt_sg[nb_ij].i=i;
         bt_sg[nb_ij].j=j;
         if(j_tag>=i_tag) {
           if(itype==jtype)
             iij=itype-1;
           else if(itype<jtype)
             iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
           else
             iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
           for(ji=0;ji<numneigh[j];ji++) {
             temp_ji=BOP_index[j]+ji;
             if(x[jlist[ji]][0]==x[i][0]) {
               if(x[jlist[ji]][1]==x[i][1]) {
                 if(x[jlist[ji]][2]==x[i][2]) {
                   break;
                 }
               }
             }
           }
           nSigBk[n]=0;
- 
+
 //AA-EE1 are the components making up Eq. 30 (a)
- 
+
           AA=0.0;
           BB=0.0;
           CC=0.0;
           DD=0.0;
           EE1=0.0;
- 
+
 //FF is the Beta_sigma^2 term
-       
+
           FF=betaS[temp_ij]*betaS[temp_ij];
- 
+
 //agpdpr1 is derivative of FF w.r.t. r_ij
- 
+
           agpdpr1=2.0*betaS[temp_ij]*dBetaS[temp_ij]/rij[temp_ij];
- 
+
 //dXX derivatives are taken with respect to all pairs contributing to the energy
 //nb_ij is derivative w.r.t. ij pair
- 
+
           bt_sg[nb_ij].dFF[0]=agpdpr1*disij[0][temp_ij];
           bt_sg[nb_ij].dFF[1]=agpdpr1*disij[1][temp_ij];
           bt_sg[nb_ij].dFF[2]=agpdpr1*disij[2][temp_ij];
- 
-//k is loop over all neighbors of i again with j neighbor of i 
+
+//k is loop over all neighbors of i again with j neighbor of i
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
-            temp_ik=BOP_index[i]+ktmp;       
+            temp_ik=BOP_index[i]+ktmp;
             if(neigh_flag[temp_ik]) {
               if(ktmp!=jtmp) {
                 if(jtmp<ktmp) {
                   njik=jtmp*(2*numneigh[i]-jtmp-1)/2+(ktmp-jtmp)-1;
                   ngj=0;
                   ngk=1;
                 }
                 else {
                   njik=ktmp*(2*numneigh[i]-ktmp-1)/2+(jtmp-ktmp)-1;
                   ngj=1;
                   ngk=0;
                 }
                 k=iilist[ktmp];
                 ktype = map[type[k]]+1;
- 
+
 //find neighbor of k that is equal to i
- 
+
                 klist=firstneigh[k];
                 for(kNeii=0;kNeii<numneigh[k];kNeii++) {
                   temp_ki=BOP_index[k]+kNeii;
                   if(x[klist[kNeii]][0]==x[i][0]) {
                     if(x[klist[kNeii]][1]==x[i][1]) {
                       if(x[klist[kNeii]][2]==x[i][2]) {
                         break;
                       }
                     }
                   }
                 }
- 
+
 //find neighbor of i that is equal to k
- 
+
                 for(jNeik=0;jNeik<numneigh[j];jNeik++) {
                   temp_jk=BOP_index[j]+jNeik;
                   if(x[jlist[jNeik]][0]==x[k][0]) {
                     if(x[jlist[jNeik]][1]==x[k][1]) {
                       if(x[jlist[jNeik]][2]==x[k][2]) {
                         break;
                       }
                     }
                   }
                 }
- 
+
 //find neighbor of k that is equal to j
- 
+
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         nk0=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   nk0=nSigBk[n]-1;
                   itypeSigBk[n][nk0]=k;
                 }
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_ik].temp=temp_ik;
                 bt_sg[nb_ik].i=i;
                 bt_sg[nb_ik].j=k;
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 ang_jik=cos_index[i]+njik;
                 if(ang_jik>=cos_total) {
                   error->one(FLERR,"Too many atom triplets for pair bop");
                 }
                 gmean0=sigma_g0[jtype-1][itype-1][ktype-1];
                 gmean1=sigma_g1[jtype-1][itype-1][ktype-1];
                 gmean2=sigma_g2[jtype-1][itype-1][ktype-1];
                 amean=cosAng[ang_jik];
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gsqprime=2.0*gfactor1*gprime1;
- 
+
 //AA is Eq. 34 (a) or Eq. 10 (c) for the i atom
 //1st CC is Eq. 11 (c) for i atom where j & k=neighbor of i
- 
+
                 AA=AA+gfactorsq*betaS[temp_ik]*betaS[temp_ik];
                 CC=CC+gfactorsq*betaS[temp_ik]*betaS[temp_ik]*betaS[temp_ik]*betaS[temp_ik];
 //agpdpr1 is derivative of AA w.r.t. Beta(rik)
 //agpdpr2 is derivative of CC 1st term w.r.t. Beta(rik)
 //app1 is derivative of AA w.r.t. cos(theta_jik)
 //app2 is derivative of CC 1st term w.r.t. cos(theta_jik)
- 
+
                 agpdpr1=2.0*gfactorsq*betaS[temp_ik]*dBetaS[temp_ik]/rij[temp_ik];
                 app1=betaS[temp_ik]*betaS[temp_ik]*gsqprime;
                 bt_sg[nb_ij].dAA[0]+=
                     app1*dcAng[ang_jik][0][ngj];
                 bt_sg[nb_ij].dAA[1]+=
                     app1*dcAng[ang_jik][1][ngj];
                 bt_sg[nb_ij].dAA[2]+=
                     app1*dcAng[ang_jik][2][ngj];
                 bt_sg[nb_ik].dAA[0]+=
                     app1*dcAng[ang_jik][0][ngk]
                     +agpdpr1*disij[0][temp_ik];
                 bt_sg[nb_ik].dAA[1]+=
                     app1*dcAng[ang_jik][1][ngk]
                     +agpdpr1*disij[1][temp_ik];
                 bt_sg[nb_ik].dAA[2]+=
                     app1*dcAng[ang_jik][2][ngk]
                     +agpdpr1*disij[2][temp_ik];
- 
+
 //k' is loop over neighbors all neighbors of j with k a neighbor
-//of i and j a neighbor of i and determine which k' is k 
+//of i and j a neighbor of i and determine which k' is k
 
                 kp_index=0;
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   temp_jkp=BOP_index[j]+ltmp;
                   kp=jlist[ltmp];
                   if(x[kp][0]==x[k][0]) {
                     if(x[kp][1]==x[k][1]) {
                       if(x[kp][2]==x[k][2]) {
                         kp_index=1;
                         break;
                       }
                     }
                   }
                 }
                 if(kp_index) {
- 
+
 //loop over neighbors of k
- 
+
                   for(mtmp=0;mtmp<numneigh[k];mtmp++) {
                     kp=klist[mtmp];
                     if(x[kp][0]==x[j][0]) {
                       if(x[kp][1]==x[j][1]) {
                         if(x[kp][2]==x[j][2]) {
                           break;
                         }
                       }
                     }
                   }
                   if(ki<ltmp) {
                     nijk=ki*(2*numneigh[j]-ki-1)/2+(ltmp-ki)-1;
                     ngji=0;
                     ngjk=1;
                   }
                   else {
                     nijk=ltmp*(2*numneigh[j]-ltmp-1)/2+(ki-ltmp)-1;
                     ngji=1;
                     ngjk=0;
                   }
                   if(kNeii<mtmp) {
                     nikj=kNeii*(2*numneigh[k]-kNeii-1)/2+(mtmp-kNeii)-1;
                     ngki=0;
                     ngkj=1;
                   }
                   else {
                     nikj=mtmp*(2*numneigh[k]-mtmp-1)/2+(kNeii-mtmp)-1;
                     ngki=1;
                     ngkj=0;
                   }
                   ang_ijk=cos_index[j]+nijk;
                   if(ang_ijk>=cos_total) {
                     error->one(FLERR,"Too many atom triplets for pair bop");
                   }
                   gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                   gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                   gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                   amean=cosAng[ang_ijk];
                   gfactor2=gmean0+gmean1*amean
                       +gmean2*amean*amean;
                   gprime2=gmean1+2.0*gmean2*amean;
                   gmean0=sigma_g0[itype-1][ktype-1][jtype-1];
                   gmean1=sigma_g1[itype-1][ktype-1][jtype-1];
                   gmean2=sigma_g2[itype-1][ktype-1][jtype-1];
                   ang_ikj=cos_index[k]+nikj;
                   if(ang_ikj>=cos_total) {
                     error->one(FLERR,"Too many atom triplets for pair bop");
                   }
                   amean=cosAng[ang_ikj];
                   gfactor3=gmean0+gmean1*amean
                       +gmean2*amean*amean;
                   gprime3=gmean1+2.0*gmean2*amean;
                   gfactor=gfactor1*gfactor2*gfactor3;
                   rfactor=betaS[temp_ik]*betaS[temp_jkp];
- 
+
 //EE1 is (b) Eq. 12
- 
+
                   EE1=EE1+gfactor*rfactor;
- 
+
 //rcm2 is derivative of EE1 w.r.t Beta(r_jk')
 //gcm1 is derivative of EE1 w.r.t cos(theta_jik)
 //gcm2 is derivative of EE1 w.r.t cos(theta_ijk)
 //gcm3 is derivative of EE1 w.r.t cos(theta_ikj)
- 
+
                   rcm1=gfactor*betaS[temp_jkp]*dBetaS[temp_ik]/rij[temp_ik];
                   rcm2=gfactor*betaS[temp_ik]*dBetaS[temp_jkp]/rij[temp_jkp];
                   gcm1=rfactor*gprime1*gfactor2*gfactor3;
                   gcm2=rfactor*gfactor1*gprime2*gfactor3;
                   gcm3=rfactor*gfactor1*gfactor2*gprime3;
                   bt_sg[nb_ij].dEE1[0]+=
                       gcm1*dcAng[ang_jik][0][ngj]
                       -gcm2*dcAng[ang_ijk][0][ngji];
                   bt_sg[nb_ij].dEE1[1]+=
                       gcm1*dcAng[ang_jik][1][ngj]
                       -gcm2*dcAng[ang_ijk][1][ngji];
                   bt_sg[nb_ij].dEE1[2]+=
                       gcm1*dcAng[ang_jik][2][ngj]
                       -gcm2*dcAng[ang_ijk][2][ngji];
                   bt_sg[nb_ik].dEE1[0]+=
                       gcm1*dcAng[ang_jik][0][ngk]
                       +rcm1*disij[0][temp_ik]
                       -gcm3*dcAng[ang_ikj][0][ngki];
                   bt_sg[nb_ik].dEE1[1]+=
                       gcm1*dcAng[ang_jik][1][ngk]
                       +rcm1*disij[1][temp_ik]
                       -gcm3*dcAng[ang_ikj][1][ngki];
                   bt_sg[nb_ik].dEE1[2]+=
                       gcm1*dcAng[ang_jik][2][ngk]
                       +rcm1*disij[2][temp_ik]
                       -gcm3*dcAng[ang_ikj][2][ngki];
                   bt_sg[nb_jk].dEE1[0]+=
                       gcm2*dcAng[ang_ijk][0][ngjk]
                       +rcm2*disij[0][temp_jkp]
                       -gcm3*dcAng[ang_ikj][0][ngkj];
                   bt_sg[nb_jk].dEE1[1]+=
                       gcm2*dcAng[ang_ijk][1][ngjk]
                       +rcm2*disij[1][temp_jkp]
                       -gcm3*dcAng[ang_ikj][1][ngkj];
                   bt_sg[nb_jk].dEE1[2]+=
                       gcm2*dcAng[ang_ijk][2][ngjk]
                       +rcm2*disij[2][temp_jkp]
                       -gcm3*dcAng[ang_ikj][2][ngkj];
                 }
- 
+
 // k and k' and j are all different neighbors of i
- 
+
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     if(neigh_flag[temp_ikp]) {
                       kp=iilist[ltmp];
                       kptype = map[type[kp]]+1;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               break;
                             }
                           }
                         }
                       }
                       if(jtmp<ltmp) {
                         njikp=jtmp*(2*numneigh[i]-jtmp-1)/2+(ltmp-jtmp)-1;
                         nglj=0;
                         ngl=1;
                       }
                       else {
                         njikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(jtmp-ltmp)-1;
                         nglj=1;
                         ngl=0;
                       }
                       if(ktmp<ltmp) {
                         nkikp=ktmp*(2*numneigh[i]-ktmp-1)/2+(ltmp-ktmp)-1;
                       }
                       else {
                         nkikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(ktmp-ltmp)-1;
                       }
                       ang_jikp=cos_index[i]+njikp;
                       if(ang_jikp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       gmean0=sigma_g0[jtype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][itype-1][kptype-1];
                       amean=cosAng[ang_jikp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][itype-1][kptype-1];
                       ang_kikp=cos_index[i]+nkikp;
                       if(ang_kikp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       amean=cosAng[ang_kikp];
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS[temp_ik]*betaS[temp_ikp];
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //2nd CC is second term of Eq. 11 (c) for i atom where j , k & k' =neighbor of i
- 
+
                       CC=CC+2.0*gfactor*rfactor;
                     }
                   }
                 }
- 
+
 // j and k are different neighbors of i and k' is a neighbor k not equal to i
- 
+
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   if(neigh_flag[temp_kkp]) {
                     kp=klist[ltmp];;
                     kptype = map[type[kp]]+1;
                     same_ikp=0;
                     same_jkp=0;
                     if(x[i][0]==x[kp][0]) {
                       if(x[i][1]==x[kp][1]) {
                         if(x[i][2]==x[kp][2]) {
                           same_ikp=1;
                         }
                       }
                     }
                     if(x[j][0]==x[kp][0]) {
                       if(x[j][1]==x[kp][1]) {
                         if(x[j][2]==x[kp][2]) {
                           same_jkp=1;
                         }
                       }
                     }
                     if(!same_ikp&&!same_jkp) {
                       if(kNeii<ltmp) {
                         nikkp=kNeii*(2*numneigh[k]-kNeii-1)/2+(ltmp-kNeii)-1;
                         ngli=0;
                       }
                       else {
                         nikkp=ltmp*(2*numneigh[k]-ltmp-1)/2+(kNeii-ltmp)-1;
                         ngli=1;
                       }
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               sig_flag=1;
                               nkp=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         nkp=nSigBk[n]-1;
                         itypeSigBk[n][nkp]=kp;
                       }
                       ang_ikkp=cos_index[k]+nikkp;
                       if(ang_ikkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
-                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];          
-                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];          
-                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];          
+                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
+                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
+                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                       amean=cosAng[ang_ikkp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS[temp_ik]*betaS[temp_kkp];
                       rfactor=rfactorrt*rfactorrt;
- 
-//3rd CC is third term of Eq. 11 (c) for i atom 
+
+//3rd CC is third term of Eq. 11 (c) for i atom
 //where j , k =neighbor of i & k' =neighbor of k
- 
+
                       CC=CC+gfactor*rfactor;
                     }
                   }
                 }
               }
             }
           }
-        
+
 //j is a neighbor of i and k is a neighbor of j not equal to i
- 
+
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ji) {
               if(ktmp<ji) {
                 njik=ktmp*(2*numneigh[j]-ktmp-1)/2+(ji-ktmp)-1;
                 ngi=1;
                 ngk=0;
               }
               else {
                 njik=ji*(2*numneigh[j]-ji-1)/2+(ktmp-ji)-1;
                 ngi=0;
                 ngk=1;
               }
               temp_jk=BOP_index[j]+ktmp;
               if(neigh_flag[temp_jk]) {
                 k=jlist[ktmp];
                 ktype=map[type[k]]+1;
                 klist=firstneigh[k];
- 
+
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         new1=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   new1=nSigBk[n]-1;
                   itypeSigBk[n][new1]=k;
                 }
                 ang_ijk=cos_index[j]+njik;
                 if(ang_ijk>=cos_total) {
                   error->one(FLERR,"Too many atom triplets for pair bop");
                 }
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                 gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                 gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                 amean=cosAng[ang_ijk];
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gsqprime=2.0*gfactor1*gprime1;
                 rfactor1rt=betaS[temp_jk]*betaS[temp_jk];
                 rfactor1=rfactor1rt*rfactor1rt;
- 
+
 //BB is Eq. 34 (a) or Eq. 10 (c) for the j atom
 //1st DD is Eq. 11 (c) for j atom where i & k=neighbor of j
                 BB=BB+gfactorsq*rfactor1rt;
                 DD=DD+gfactorsq*rfactor1;
- 
+
 //agpdpr1 is derivative of BB  w.r.t. Beta(r_jk)
 //app1 is derivative of BB w.r.t. cos(theta_ijk)
- 
+
                 agpdpr1=2.0*gfactorsq*betaS[temp_jk]*dBetaS[temp_jk]/rij[temp_jk];
                 app1=rfactor1rt*gsqprime;
                 bt_sg[nb_ij].dBB[0]-=
                     app1*dcAng[ang_ijk][0][ngi];
                 bt_sg[nb_ij].dBB[1]-=
                     app1*dcAng[ang_ijk][1][ngi];
                 bt_sg[nb_ij].dBB[2]-=
                     app1*dcAng[ang_ijk][2][ngi];
                 bt_sg[nb_jk].dBB[0]+=
                     app1*dcAng[ang_ijk][0][ngk]
                     +agpdpr1*disij[0][temp_jk];
                 bt_sg[nb_jk].dBB[1]+=
                     app1*dcAng[ang_ijk][1][ngk]
                     +agpdpr1*disij[1][temp_jk];
                 bt_sg[nb_jk].dBB[2]+=
                     app1*dcAng[ang_ijk][2][ngk]
                     +agpdpr1*disij[2][temp_jk];
- 
+
 //j is a neighbor of i, k and k' prime different neighbors of j not equal to i
- 
+
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ji) {
                     temp_jkp=BOP_index[j]+ltmp;
                     if(neigh_flag[temp_jkp]) {
                       kp=jlist[ltmp];
                       kptype=map[type[kp]]+1;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               new2=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(ji<ltmp) {
                         nijkp=ji*(2*numneigh[j]-ji-1)/2+(ltmp-ji)-1;
                         ngli=0;
                         ngl=1;
                       }
                       else {
                         nijkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ji-ltmp)-1;
                         ngli=1;
                         ngl=0;
                       }
                       if(ktmp<ltmp) {
                         nkjkp=ktmp*(2*numneigh[j]-ktmp-1)/2+(ltmp-ktmp)-1;
                         ngjk=0;
                       }
                       else {
                         nkjkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ktmp-ltmp)-1;
                         ngjk=1;
                       }
                       ang_ijkp=cos_index[j]+nijkp;
                       if(ang_ijkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       ang_kjkp=cos_index[j]+nkjkp;
                       if(ang_kjkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                       amean=cosAng[ang_ijkp];
                       gfactor2=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][jtype-1][kptype-1];
                       amean=cosAng[ang_kjkp];
                       gfactor3=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS[temp_jk]*betaS[temp_jkp];
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //2nd DD is Eq. 11 (c) for j atom where i , k & k'=neighbor of j
- 
+
                       DD=DD+2.0*gfactor*rfactor;
                     }
                   }
                 }
- 
-//j is a neighbor of i, k is a neighbor of j not equal to i and k' 
+
+//j is a neighbor of i, k is a neighbor of j not equal to i and k'
 //is a neighbor of k not equal to j or i
- 
+
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   if(neigh_flag[temp_kkp]) {
                     kp=klist[ltmp];
                     kptype=map[type[kp]]+1;
                     same_ikp=0;
                     same_jkp=0;
                     if(x[i][0]==x[kp][0]) {
                       if(x[i][1]==x[kp][1]) {
                         if(x[i][2]==x[kp][2]) {
                           same_ikp=1;
                         }
                       }
                     }
                     if(x[j][0]==x[kp][0]) {
                       if(x[j][1]==x[kp][1]) {
                         if(x[j][2]==x[kp][2]) {
                           same_jkp=1;
                         }
                       }
                     }
                     if(!same_ikp&&!same_jkp) {
                       for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                         if(x[klist[kNeij]][0]==x[j][0]) {
                           if(x[klist[kNeij]][1]==x[j][1]) {
                             if(x[klist[kNeij]][2]==x[j][2]) {
                               break;
                             }
                           }
                         }
                       }
                       if(kNeij<ltmp) {
                         njkkp=kNeij*(2*numneigh[k]-kNeij-1)/2+(ltmp-kNeij)-1;
                         nglj=0;
                       }
                       else {
                         njkkp=ltmp*(2*numneigh[k]-ltmp-1)/2+(kNeij-ltmp)-1;
                         nglj=1;
                       }
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               new2=nsearch;
                               sig_flag=1;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         new2=nSigBk[n]-1;
                         itypeSigBk[n][new2]=kp;
                       }
                       ang_jkkp=cos_index[k]+njkkp;
                       if(ang_jkkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       gmean0=sigma_g0[jtype-1][ktype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][ktype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][ktype-1][kptype-1];
                       amean=cosAng[ang_jkkp];
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS[temp_jk]*betaS[temp_kkp];
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //3rd DD is Eq. 11 (c) for j atom where i & k=neighbor of j & k'=neighbor of k
- 
+
                       DD=DD+gfactor*rfactor;
                     }
                   }
                 }
               }
             }
           }
- 
+
           sig_flag=0;
           if(sig_flag==0) {
- 
+
 // AA and BB are the representations of (a) Eq. 34 and (b) Eq. 9
 // for atoms i and j respectively
- 
+
             AAC=AA+BB;
             BBC=AA*BB;
             CCC=AA*AA+BB*BB;
             DDC=CC+DD;
- 
+
 //EEC is a modified form of (a) Eq. 33
- 
+
             EEC=(DDC-CCC)/(AAC+2.0*small1);
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 bt_sg[m].dAAC[0]=bt_sg[m].dAA[0]
                     +bt_sg[m].dBB[0];
                 bt_sg[m].dAAC[1]=bt_sg[m].dAA[1]
                     +bt_sg[m].dBB[1];
                 bt_sg[m].dAAC[2]=bt_sg[m].dAA[2]
                     +bt_sg[m].dBB[2];
-              } 
+              }
             }
             UT=EEC*FF+BBC+small3[iij];
             UT=1.0/sqrt(UT);
 
 // FFC is slightly modified form of (a) Eq. 31
 // GGC is slightly modified form of (a) Eq. 32
 // bndtmp is a slightly modified form of (a) Eq. 30 and (b) Eq. 8
- 
+
             bndtmp=(FF+sigma_delta[iij]*sigma_delta[iij])
                 +sigma_c[iij]*AAC+small4;
             UTcom=-0.5*UT*UT*UT;
             psign=1.0;
             bndtmp0=1.0/sqrt(bndtmp);
             sigB1[n]=psign*betaS[temp_ij]*bndtmp0;
             bndtmp=-0.5*bndtmp0*bndtmp0*bndtmp0;
             bndtmp1=psign*bndtmp0+psign*betaS[temp_ij]
                 *bndtmp*2.0*betaS[temp_ij];
             bndtmp1=bndtmp1*dBetaS[temp_ij]/rij[temp_ij];
             bndtmp2=psign*betaS[temp_ij]*bndtmp*sigma_c[iij];
             setting=0;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 if(temp_kk==temp_ij&&setting==0) {
                   bt_sg[m].dSigB1[0]=bndtmp1*disij[0][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=bndtmp1*disij[1][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=bndtmp1*disij[2][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[2]);
                   setting=1;
                 }
                 else if(temp_kk==temp_ji&&setting==0) {
                   bt_sg[m].dSigB1[0]=-bndtmp1*disij[0][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=-bndtmp1*disij[1][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=-bndtmp1*disij[2][temp_ij]
                       +(bndtmp2*bt_sg[m].dAAC[2]);
                   setting=1;
                 }
                 else {
                   bt_sg[m].dSigB1[0]=(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=(bndtmp2*bt_sg[m].dAAC[2]);
                 }
               }
             }
- 
+
 //This loop is to ensure there is not an error for atoms with no neighbors (deposition)
 
             if(nb_t==0) {
               if(j>i) {
                 bt_sg[0].dSigB1[0]=bndtmp1*disij[0][temp_ij];
                 bt_sg[0].dSigB1[1]=bndtmp1*disij[1][temp_ij];
                 bt_sg[0].dSigB1[2]=bndtmp1*disij[2][temp_ij];
               }
               else {
                 bt_sg[0].dSigB1[0]=-bndtmp1*disij[0][temp_ij];
                 bt_sg[0].dSigB1[1]=-bndtmp1*disij[1][temp_ij];
                 bt_sg[0].dSigB1[2]=-bndtmp1*disij[2][temp_ij];
               }
               for(pp=0;pp<3;pp++) {
                 bt_sg[0].dAA[pp]=0.0;
                 bt_sg[0].dBB[pp]=0.0;
                 bt_sg[0].dEE1[pp]=0.0;
                 bt_sg[0].dFF[pp]=0.0;
                 bt_sg[0].dAAC[pp]=0.0;
                 bt_sg[0].dSigB[pp]=0.0;
               }
               bt_sg[0].i=i;
               bt_sg[0].j=j;
               bt_sg[0].temp=temp_ij;
               nb_t++;
               if(nb_t>nb_sg) {
                 new_n_tot=nb_sg+maxneigh;
                 grow_sigma(nb_sg,new_n_tot);
                 nb_sg=new_n_tot;
               }
             }
             ps=sigB1[n]*rdBO+1.0;
             ks=(int)ps;
             if(nBOt-1<ks)
               ks=nBOt-1;
             ps=ps-ks;
             if(ps>1.0)
               ps=1.0;
             dsigB1=((FsigBO3[iij][ks-1]*ps+FsigBO2[iij][ks-1])*ps
                 +FsigBO1[iij][ks-1])*ps+FsigBO[iij][ks-1];
             dsigB2=(FsigBO6[iij][ks-1]*ps+FsigBO5[iij][ks-1])*ps+FsigBO4[iij][ks-1];
             part0=(FF+0.5*AAC+small5);
             part1=(sigma_f[iij]-0.5)*sigma_k[iij];
             part2=1.0-part1*EE1/part0;
             part3=dsigB1*part1/part0;
             part4=part3/part0*EE1;
- 
+
 // sigB is the final expression for (a) Eq. 6 and (b) Eq. 11
- 
+
             sigB[n]=dsigB1*part2;
             pp1=2.0*betaS[temp_ij];
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 bt_ij=bt_sg[m].temp;
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 for(pp=0;pp<3;pp++) {
                   bt_sg[m].dSigB[pp]=dsigB2*part2*bt_sg[m].dSigB1[pp]
                       -part3*bt_sg[m].dEE1[pp]
                       +part4*(bt_sg[m].dFF[pp]
                       +0.5*bt_sg[m].dAAC[pp]);
                 }
                 for(pp=0;pp<3;pp++) {
                   ftmp[pp]=pp1*bt_sg[m].dSigB[pp];
                   f[bt_i][pp]-=ftmp[pp];
                   f[bt_j][pp]+=ftmp[pp];
                 }
                 if(evflag) {
                   ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                       ,ftmp[2],disij[0][bt_ij],disij[1][bt_ij],disij[2][bt_ij]);
                 }
               }
             }
           }
           n++;
         }
       }
     }
   }
   destroy_sigma();
 }
 
 /* ---------------------------------------------------------------------- */
- 
+
 /*  The formulation differs slightly to avoid negative square roots
     in the calculation of Theta_pi,ij of (a) Eq. 36 and (b) Eq. 18 */
 
 void PairBOP::sigmaBo_otf()
 {
   int nb_t,new_n_tot;
   int n,i,j,k,kp,m,pp,kpj,kpk,kkp;
   int itmp,jtmp,ktmp,ltmp,mtmp;
   int i_tag,j_tag;
   int kp1,kp2,kp1type;
   int iij,iik,ijk,ikkp,ji,iikp,ijkp;
   int nkp;
   int nk0;
   int jNeik,kNeii,kNeij,kNeikp;
   int kpNeij,kpNeik;
   int new1,new2,nlocal;
   int inum,*ilist,*iilist,*jlist,*klist,*kplist;
-  int **firstneigh,*numneigh; 
+  int **firstneigh,*numneigh;
   int temp_ij,temp_ik,temp_jkp,temp_kk,temp_jk;
   int temp_ji,temp_kpj,temp_kkp;
   int temp_ikp,temp_kpk;
   int nb_ij,nb_ik,nb_ikp;
   int nb_jk,nb_jkp,nb_kkp;
   int kp_nsearch,nsearch;
   int sig_flag,setting,ncmp,ks;
   int itype,jtype,ktype,kptype;
   int bt_i,bt_j;
   int same_ikp,same_jkp,same_kpk;
   int same_jkpj,same_kkpk;
   double AA,BB,CC,DD,EE,EE1,FF;
   double AAC,BBC,CCC,DDC,EEC,FFC,GGC;
   double AACFF,UT,bndtmp,UTcom;
   double amean,gmean0,gmean1,gmean2,ps;
   double gfactor1,gprime1,gsqprime,factorsq;
   double gfactorsq,gfactor2,gprime2;
   double gfactorsq2,gsqprime2;
   double gfactor3,gprime3,gfactor,rfactor;
   double drfactor,gfactor4,gprime4,agpdpr3;
   double rfactor0,rfactorrt,rfactor1rt,rfactor1;
   double rcm1,rcm2,gcm1,gcm2,gcm3;
   double agpdpr1,agpdpr2,app1,app2,app3,app4;
   double dsigB1,dsigB2;
   double part0,part1,part2,part3,part4;
   double psign,bndtmp0,pp1;
   double bndtmp1,bndtmp2,bndtmp3,bndtmp4,bndtmp5;
   double dis_ij[3],rsq_ij,r_ij;
   double betaS_ij,dBetaS_ij;
   double betaP_ij,dBetaP_ij;
   double dis_ik[3],rsq_ik,r_ik;
   double betaS_ik,dBetaS_ik;
   double betaP_ik,dBetaP_ik;
   double dis_ikp[3],rsq_ikp,r_ikp;
   double betaS_ikp,dBetaS_ikp;
   double betaP_ikp,dBetaP_ikp;
   double dis_jk[3],rsq_jk,r_jk;
   double betaS_jk,dBetaS_jk;
   double betaP_jk,dBetaP_jk;
   double dis_jkp[3],rsq_jkp,r_jkp;
   double betaS_jkp,dBetaS_jkp;
   double betaP_jkp,dBetaP_jkp;
   double dis_kkp[3],rsq_kkp,r_kkp;
   double betaS_kkp,dBetaS_kkp;
   double betaP_kkp,dBetaP_kkp;
   double cosAng_jik,dcA_jik[3][2];
   double cosAng_jikp,dcA_jikp[3][2];
   double cosAng_kikp,dcA_kikp[3][2];
   double cosAng_ijk,dcA_ijk[3][2];
   double cosAng_ijkp,dcA_ijkp[3][2];
   double cosAng_kjkp,dcA_kjkp[3][2];
   double cosAng_ikj,dcA_ikj[3][2];
   double cosAng_ikkp,dcA_ikkp[3][2];
   double cosAng_jkkp,dcA_jkkp[3][2];
   double cosAng_jkpk,dcA_jkpk[3][2];
 
   double ftmp[3],xtmp[3];
   double **x = atom->x;
   double **f = atom->f;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
   int *type = atom->type;
 
   nlocal = atom->nlocal;
   int nall = nlocal + atom->nghost;
-  inum = list->inum; 
+  inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   n=0;
   if(nb_sg==0) {
     nb_sg=(maxneigh)*(maxneigh/2);
   }
   if(allocate_sigma) {
     destroy_sigma();
   }
-  
+
   create_sigma(nb_sg);
 
   for(itmp=0;itmp<inum;itmp++) {
     i = ilist[itmp];
-    i_tag=tag[i];  
+    i_tag=tag[i];
     itype = map[type[i]]+1;
 
 //j is loop over all neighbors of i
 
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       for(m=0;m<nb_sg;m++) {
         for(pp=0;pp<3;pp++) {
           bt_sg[m].dAA[pp]=0.0;
           bt_sg[m].dBB[pp]=0.0;
           bt_sg[m].dCC[pp]=0.0;
           bt_sg[m].dDD[pp]=0.0;
           bt_sg[m].dEE[pp]=0.0;
           bt_sg[m].dEE1[pp]=0.0;
           bt_sg[m].dFF[pp]=0.0;
           bt_sg[m].dAAC[pp]=0.0;
           bt_sg[m].dBBC[pp]=0.0;
           bt_sg[m].dCCC[pp]=0.0;
           bt_sg[m].dDDC[pp]=0.0;
           bt_sg[m].dEEC[pp]=0.0;
           bt_sg[m].dFFC[pp]=0.0;
           bt_sg[m].dGGC[pp]=0.0;
           bt_sg[m].dUT[pp]=0.0;
           bt_sg[m].dSigB1[pp]=0.0;
           bt_sg[m].dSigB[pp]=0.0;
         }
         bt_sg[m].i=-1;
         bt_sg[m].j=-1;
         bt_sg[m].temp=-1;
       }
       nb_t=0;
       iilist=firstneigh[i];
       temp_ij=BOP_index[i]+jtmp;
       j=iilist[jtmp];
       jlist=firstneigh[j];
       j_tag=tag[j];
       jtype = map[type[j]]+1;
       nb_ij=nb_t;
       nb_t++;
       if(nb_t>nb_sg) {
         new_n_tot=nb_sg+maxneigh;
         grow_sigma(nb_sg,new_n_tot);
         nb_sg=new_n_tot;
       }
       bt_sg[nb_ij].temp=temp_ij;
       bt_sg[nb_ij].i=i;
       bt_sg[nb_ij].j=j;
       if(j_tag>=i_tag) {
         if(itype==jtype)
           iij=itype-1;
         else if(itype<jtype)
           iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
         else
           iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
         for(ji=0;ji<numneigh[j];ji++) {
           temp_ji=BOP_index[j]+ji;
           if(x[jlist[ji]][0]==x[i][0]) {
             if(x[jlist[ji]][1]==x[i][1]) {
               if(x[jlist[ji]][2]==x[i][2]) {
                 break;
               }
             }
           }
         }
-        dis_ij[0]=x[j][0]-x[i][0]; 
-        dis_ij[1]=x[j][1]-x[i][1]; 
-        dis_ij[2]=x[j][2]-x[i][2]; 
+        dis_ij[0]=x[j][0]-x[i][0];
+        dis_ij[1]=x[j][1]-x[i][1];
+        dis_ij[2]=x[j][2]-x[i][2];
         rsq_ij=dis_ij[0]*dis_ij[0]
             +dis_ij[1]*dis_ij[1]
             +dis_ij[2]*dis_ij[2];
-        r_ij=sqrt(rsq_ij); 
+        r_ij=sqrt(rsq_ij);
 
         if(r_ij<rcut[iij]) {
           ps=r_ij*rdr[iij]+1.0;
           ks=(int)ps;
           if(nr-1<ks)
             ks=nr-1;
           ps=ps-ks;
           if(ps>1.0)
             ps=1.0;
           betaS_ij=((pBetaS3[iij][ks-1]*ps+pBetaS2[iij][ks-1])*ps
               +pBetaS1[iij][ks-1])*ps+pBetaS[iij][ks-1];
           dBetaS_ij=(pBetaS6[iij][ks-1]*ps+pBetaS5[iij][ks-1])*ps
               +pBetaS4[iij][ks-1];
           betaP_ij=((pBetaP3[iij][ks-1]*ps+pBetaP2[iij][ks-1])*ps
               +pBetaP1[iij][ks-1])*ps+pBetaP[iij][ks-1];
           dBetaP_ij=(pBetaP6[iij][ks-1]*ps+pBetaP5[iij][ks-1])*ps
               +pBetaP4[iij][ks-1];
           nSigBk[n]=0;
 
 //AA-EE1 are the components making up Eq. 30 (a)
 
           AA=0.0;
           BB=0.0;
           CC=0.0;
           DD=0.0;
           EE=0.0;
           EE1=0.0;
 
 //FF is the Beta_sigma^2 term
-       
+
           FF=betaS_ij*betaS_ij;
 
 //agpdpr1 is derivative of FF w.r.t. r_ij
 
           agpdpr1=2.0*betaS_ij*dBetaS_ij/r_ij;
 
 //dXX derivatives are taken with respect to all pairs contributing to the energy
 //nb_ij is derivative w.r.t. ij pair
 
           bt_sg[nb_ij].dFF[0]=agpdpr1*dis_ij[0];
           bt_sg[nb_ij].dFF[1]=agpdpr1*dis_ij[1];
           bt_sg[nb_ij].dFF[2]=agpdpr1*dis_ij[2];
 
-//k is loop over all neighbors of i again with j neighbor of i 
+//k is loop over all neighbors of i again with j neighbor of i
 
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
             temp_ik=BOP_index[i]+ktmp;
             if(ktmp!=jtmp) {
               k=iilist[ktmp];
               klist=firstneigh[k];
               ktype = map[type[k]]+1;
               if(itype==ktype)
                 iik=itype-1;
               else if(itype<ktype)
                 iik=itype*bop_types-itype*(itype+1)/2+ktype-1;
               else
                 iik=ktype*bop_types-ktype*(ktype+1)/2+itype-1;
-  
+
 //find neighbor of k that is equal to i
 
               for(kNeii=0;kNeii<numneigh[k];kNeii++) {
                 if(x[klist[kNeii]][0]==x[i][0]) {
                   if(x[klist[kNeii]][1]==x[i][1]) {
                     if(x[klist[kNeii]][2]==x[i][2]) {
                       break;
                     }
                   }
                 }
               }
-              dis_ik[0]=x[k][0]-x[i][0]; 
-              dis_ik[1]=x[k][1]-x[i][1]; 
-              dis_ik[2]=x[k][2]-x[i][2]; 
+              dis_ik[0]=x[k][0]-x[i][0];
+              dis_ik[1]=x[k][1]-x[i][1];
+              dis_ik[2]=x[k][2]-x[i][2];
               rsq_ik=dis_ik[0]*dis_ik[0]
                   +dis_ik[1]*dis_ik[1]
                   +dis_ik[2]*dis_ik[2];
-              r_ik=sqrt(rsq_ik); 
+              r_ik=sqrt(rsq_ik);
               if(r_ik<=rcut[iik]) {
                 ps=r_ik*rdr[iik]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_ik=((pBetaS3[iik][ks-1]*ps+pBetaS2[iik][ks-1])*ps
                     +pBetaS1[iik][ks-1])*ps+pBetaS[iik][ks-1];
                 dBetaS_ik=(pBetaS6[iik][ks-1]*ps+pBetaS5[iik][ks-1])*ps
                     +pBetaS4[iik][ks-1];
                 betaP_ik=((pBetaP3[iik][ks-1]*ps+pBetaP2[iik][ks-1])*ps
                     +pBetaP1[iik][ks-1])*ps+pBetaP[iik][ks-1];
                 dBetaP_ik=(pBetaP6[iik][ks-1]*ps+pBetaP5[iik][ks-1])*ps
                     +pBetaP4[iik][ks-1];
 
 //find neighbor of i that is equal to k
 
                 for(jNeik=0;jNeik<numneigh[j];jNeik++) {
                   temp_jk=BOP_index[j]+jNeik;
                   if(x[jlist[jNeik]][0]==x[k][0]) {
                     if(x[jlist[jNeik]][1]==x[k][1]) {
                       if(x[jlist[jNeik]][2]==x[k][2]) {
                         break;
                       }
                     }
                   }
                 }
 
 //find neighbor of k that is equal to j
 
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
-                dis_jk[0]=x[k][0]-x[j][0]; 
-                dis_jk[1]=x[k][1]-x[j][1]; 
-                dis_jk[2]=x[k][2]-x[j][2]; 
+                dis_jk[0]=x[k][0]-x[j][0];
+                dis_jk[1]=x[k][1]-x[j][1];
+                dis_jk[2]=x[k][2]-x[j][2];
                 rsq_jk=dis_jk[0]*dis_jk[0]
                     +dis_jk[1]*dis_jk[1]
                     +dis_jk[2]*dis_jk[2];
-                r_jk=sqrt(rsq_jk); 
+                r_jk=sqrt(rsq_jk);
 
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         nk0=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   nk0=nSigBk[n]-1;
                   itypeSigBk[n][nk0]=k;
                 }
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_ik].temp=temp_ik;
                 bt_sg[nb_ik].i=i;
                 bt_sg[nb_ik].j=k;
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 cosAng_jik=(dis_ij[0]*dis_ik[0]+dis_ij[1]*dis_ik[1]
-                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik); 
+                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik);
                 dcA_jik[0][0]=(dis_ik[0]*r_ij*r_ik-cosAng_jik
                     *dis_ij[0]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][0]=(dis_ik[1]*r_ij*r_ik-cosAng_jik
                     *dis_ij[1]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][0]=(dis_ik[2]*r_ij*r_ik-cosAng_jik
                     *dis_ij[2]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[0][1]=(dis_ij[0]*r_ij*r_ik-cosAng_jik
                     *dis_ik[0]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][1]=(dis_ij[1]*r_ij*r_ik-cosAng_jik
                     *dis_ik[1]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][1]=(dis_ij[2]*r_ij*r_ik-cosAng_jik
                     *dis_ik[2]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 gmean0=sigma_g0[jtype-1][itype-1][ktype-1];
                 gmean1=sigma_g1[jtype-1][itype-1][ktype-1];
                 gmean2=sigma_g2[jtype-1][itype-1][ktype-1];
                 amean=cosAng_jik;
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gsqprime=2.0*gfactor1*gprime1;
 
 //AA is Eq. 34 (a) or Eq. 10 (c) for the i atom
 //1st CC is Eq. 11 (c) for i atom where j & k=neighbor of i
 
                 AA=AA+gfactorsq*betaS_ik*betaS_ik;
                 CC=CC+gfactorsq*betaS_ik*betaS_ik*betaS_ik*betaS_ik;
 
 //agpdpr1 is derivative of AA w.r.t. Beta(rik)
 //app1 is derivative of AA w.r.t. cos(theta_jik)
 
                 agpdpr1=2.0*gfactorsq*betaS_ik*dBetaS_ik/r_ik;
                 app1=betaS_ik*betaS_ik*gsqprime;
                 bt_sg[nb_ij].dAA[0]+=
                     app1*dcA_jik[0][0];
                 bt_sg[nb_ij].dAA[1]+=
                     app1*dcA_jik[1][0];
                 bt_sg[nb_ij].dAA[2]+=
                     app1*dcA_jik[2][0];
                 bt_sg[nb_ij].dCC[0]+=
                     app2*dcA_jik[0][0];
                 bt_sg[nb_ij].dCC[1]+=
                     app2*dcA_jik[1][0];
                 bt_sg[nb_ij].dCC[2]+=
                     app2*dcA_jik[2][0];
                 bt_sg[nb_ik].dAA[0]+=
                     app1*dcA_jik[0][1]
                     +agpdpr1*dis_ik[0];
                 bt_sg[nb_ik].dAA[1]+=
                     app1*dcA_jik[1][1]
                     +agpdpr1*dis_ik[1];
                 bt_sg[nb_ik].dAA[2]+=
                     app1*dcA_jik[2][1]
                     +agpdpr1*dis_ik[2];
                 bt_sg[nb_ik].dCC[0]+=
                     app2*dcA_jik[0][1]
                     +agpdpr2*dis_ik[0];
                 bt_sg[nb_ik].dCC[1]+=
                     app2*dcA_jik[1][1]
                     +agpdpr2*dis_ik[1];
                 bt_sg[nb_ik].dCC[2]+=
                     app2*dcA_jik[2][1]
                     +agpdpr2*dis_ik[2];
 
 //k' is loop over neighbors all neighbors of j with k a neighbor
-//of i and j a neighbor of i and determine which k' is k 
-                
-                same_kpk=0; 
+//of i and j a neighbor of i and determine which k' is k
+
+                same_kpk=0;
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   temp_jkp=BOP_index[j]+ltmp;
                   kp1=jlist[ltmp];
                   kp1type=map[type[kp1]]+1;
                   if(x[kp1][0]==x[k][0]) {
                     if(x[kp1][1]==x[k][1]) {
                       if(x[kp1][2]==x[k][2]) {
                         same_kpk=1;
                         break;
                       }
                     }
                   }
                 }
                 if(same_kpk){
 
 //loop over neighbors of k
 
                   for(mtmp=0;mtmp<numneigh[k];mtmp++) {
                     temp_kpj=BOP_index[k]+mtmp;
                     kp2=klist[mtmp];
                     if(x[kp2][0]==x[k][0]) {
                       if(x[kp2][1]==x[k][1]) {
                         if(x[kp2][2]==x[k][2]) {
                           break;
                         }
                       }
                     }
                   }
                   if(jtype==ktype)
                     ijk=jtype-1;
                   else if(jtype < ktype)
                     ijk=jtype*bop_types-jtype*(jtype+1)/2+ktype-1;
                   else
                     ijk=ktype*bop_types-ktype*(ktype+1)/2+jtype-1;
                   if(jtype==kp1type)
                     ijkp=jtype-1;
                   else if(jtype<kp1type)
                     ijkp=jtype*bop_types-jtype*(jtype+1)/2+kp1type-1;
                   else
                     ijkp=kp1type*bop_types-kp1type*(kp1type+1)/2+jtype-1;
 
-                  dis_jkp[0]=x[kp1][0]-x[j][0]; 
-                  dis_jkp[1]=x[kp1][1]-x[j][1]; 
-                  dis_jkp[2]=x[kp1][2]-x[j][2]; 
+                  dis_jkp[0]=x[kp1][0]-x[j][0];
+                  dis_jkp[1]=x[kp1][1]-x[j][1];
+                  dis_jkp[2]=x[kp1][2]-x[j][2];
                   rsq_jkp=dis_jkp[0]*dis_jkp[0]
                       +dis_jkp[1]*dis_jkp[1]
                       +dis_jkp[2]*dis_jkp[2];
-                  r_jkp=sqrt(rsq_jkp); 
+                  r_jkp=sqrt(rsq_jkp);
                   if(r_jkp<=rcut[ijkp]) {
                     ps=r_jkp*rdr[ijkp]+1.0;
                     ks=(int)ps;
                     if(nr-1<ks)
                       ks=nr-1;
                     ps=ps-ks;
                     if(ps>1.0)
                       ps=1.0;
                     betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                         +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                     dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                         +pBetaS4[ijkp][ks-1];
                     betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                         +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                     dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                         +pBetaP4[ijkp][ks-1];
                     cosAng_ijk=(-dis_ij[0]*dis_jk[0]-dis_ij[1]*dis_jk[1]
-                        -dis_ij[2]*dis_jk[2])/(r_ij*r_jk); 
+                        -dis_ij[2]*dis_jk[2])/(r_ij*r_jk);
                     dcA_ijk[0][0]=(dis_jk[0]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[0]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[1][0]=(dis_jk[1]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[1]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[2][0]=(dis_jk[2]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[2]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[0][1]=(-dis_ij[0]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[0]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[1][1]=(-dis_ij[1]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[1]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[2][1]=(-dis_ij[2]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[2]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                     gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                     gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                     amean=cosAng_ijk;
                     gfactor2=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                     gprime2=gmean1+2.0*gmean2*amean;
                     gmean0=sigma_g0[itype-1][ktype-1][jtype-1];
                     gmean1=sigma_g1[itype-1][ktype-1][jtype-1];
                     gmean2=sigma_g2[itype-1][ktype-1][jtype-1];
                     cosAng_ikj=(dis_ik[0]*dis_jk[0]+dis_ik[1]*dis_jk[1]
-                        +dis_ik[2]*dis_jk[2])/(r_ik*r_jk); 
+                        +dis_ik[2]*dis_jk[2])/(r_ik*r_jk);
                     dcA_ikj[0][0]=(-dis_jk[0]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[0]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[1][0]=(-dis_jk[1]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[1]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[2][0]=(-dis_jk[2]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[2]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[0][1]=(-dis_ik[0]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[0]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[1][1]=(-dis_ik[1]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[1]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[2][1]=(-dis_ik[2]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[2]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     amean=cosAng_ikj;
                     gfactor3=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                     gprime3=gmean1+2.0*gmean2*amean;
                     gfactor=gfactor1*gfactor2*gfactor3;
                     rfactor=betaS_ik*betaS_jkp;
 
 //EE1 is (b) Eq. 12
 
                     EE1=EE1+gfactor*rfactor;
 
 //rcm1 is derivative of EE1 w.r.t Beta(r_ik)
 //rcm2 is derivative of EE1 w.r.t Beta(r_jk')
 //gcm1 is derivative of EE1 w.r.t cos(theta_jik)
 //gcm2 is derivative of EE1 w.r.t cos(theta_ijk)
 //gcm3 is derivative of EE1 w.r.t cos(theta_ikj)
 
                     rcm1=gfactor*betaS_jkp*dBetaS_ik/r_ik;
                     rcm2=gfactor*betaS_ik*dBetaS_jkp/r_jkp;
                     gcm1=rfactor*gprime1*gfactor2*gfactor3;
                     gcm2=rfactor*gfactor1*gprime2*gfactor3;
                     gcm3=rfactor*gfactor1*gfactor2*gprime3;
                     bt_sg[nb_ij].dEE1[0]+=
                         gcm1*dcA_jik[0][0]
                         -gcm2*dcA_ijk[0][0];
                     bt_sg[nb_ij].dEE1[1]+=
                         gcm1*dcA_jik[1][0]
                         -gcm2*dcA_ijk[1][0];
                     bt_sg[nb_ij].dEE1[2]+=
                         gcm1*dcA_jik[2][0]
                         -gcm2*dcA_ijk[2][0];
                     bt_sg[nb_ik].dEE1[0]+=
                         gcm1*dcA_jik[0][1]
                         +rcm1*dis_ik[0]
                         -gcm3*dcA_ikj[0][0];
                     bt_sg[nb_ik].dEE1[1]+=
                         gcm1*dcA_jik[1][1]
                         +rcm1*dis_ik[1]
                         -gcm3*dcA_ikj[1][0];
                     bt_sg[nb_ik].dEE1[2]+=
                         gcm1*dcA_jik[2][1]
                         +rcm1*dis_ik[2]
                         -gcm3*dcA_ikj[2][0];
                     bt_sg[nb_jk].dEE1[0]+=
                         gcm2*dcA_ijk[0][1]
                         +rcm2*dis_jkp[0]
                         -gcm3*dcA_ikj[0][1];
                     bt_sg[nb_jk].dEE1[1]+=
                         gcm2*dcA_ijk[1][1]
                         +rcm2*dis_jkp[1]
                         -gcm3*dcA_ikj[1][1];
                     bt_sg[nb_jk].dEE1[2]+=
                         gcm2*dcA_ijk[2][1]
                         +rcm2*dis_jkp[2]
                         -gcm3*dcA_ikj[2][1];
                   }
                 }
 
 // k and k' and j are all different neighbors of i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     kp=iilist[ltmp];;
                     kptype = map[type[kp]]+1;
                     if(itype==kptype)
                       iikp=itype-1;
                     else if(itype<kptype)
                       iikp=itype*bop_types-itype*(itype+1)/2+kptype-1;
                     else
                       iikp=kptype*bop_types-kptype*(kptype+1)/2+itype-1;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             break;
                           }
                         }
                       }
                     }
-                    dis_ikp[0]=x[kp][0]-x[i][0]; 
-                    dis_ikp[1]=x[kp][1]-x[i][1]; 
-                    dis_ikp[2]=x[kp][2]-x[i][2]; 
+                    dis_ikp[0]=x[kp][0]-x[i][0];
+                    dis_ikp[1]=x[kp][1]-x[i][1];
+                    dis_ikp[2]=x[kp][2]-x[i][2];
                     rsq_ikp=dis_ikp[0]*dis_ikp[0]
                         +dis_ikp[1]*dis_ikp[1]
                         +dis_ikp[2]*dis_ikp[2];
-                    r_ikp=sqrt(rsq_ikp); 
+                    r_ikp=sqrt(rsq_ikp);
                     if(r_ikp<=rcut[iikp]) {
                       ps=r_ikp*rdr[iikp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_ikp=((pBetaS3[iikp][ks-1]*ps+pBetaS2[iikp][ks-1])*ps
                           +pBetaS1[iikp][ks-1])*ps+pBetaS[iikp][ks-1];
                       dBetaS_ikp=(pBetaS6[iikp][ks-1]*ps+pBetaS5[iikp][ks-1])*ps
                           +pBetaS4[iikp][ks-1];
                       betaP_ikp=((pBetaP3[iikp][ks-1]*ps+pBetaP2[iikp][ks-1])*ps
                           +pBetaP1[iikp][ks-1])*ps+pBetaP[iikp][ks-1];
                       dBetaP_ikp=(pBetaP6[iikp][ks-1]*ps+pBetaP5[iikp][ks-1])*ps
                           +pBetaP4[iikp][ks-1];
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_ikp].temp=temp_ikp;
                       bt_sg[nb_ikp].i=i;
                       bt_sg[nb_ikp].j=kp;
                       gmean0=sigma_g0[jtype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][itype-1][kptype-1];
                       cosAng_jikp=(dis_ij[0]*dis_ikp[0]+dis_ij[1]*dis_ikp[1]
-                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp); 
+                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp);
                       dcA_jikp[0][0]=(dis_ikp[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[0]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][0]=(dis_ikp[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[1]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][0]=(dis_ikp[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[2]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[0][1]=(dis_ij[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[0]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][1]=(dis_ij[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[1]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][1]=(dis_ij[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[2]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       cosAng_kikp=(dis_ik[0]*dis_ikp[0]+dis_ik[1]*dis_ikp[1]
-                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp); 
+                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp);
                       dcA_kikp[0][0]=(dis_ikp[0]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[0]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[1][0]=(dis_ikp[1]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[1]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[2][0]=(dis_ikp[2]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[2]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[0][1]=(dis_ik[0]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[0]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[1][1]=(dis_ik[1]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[1]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[2][1]=(dis_ik[2]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[2]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       amean=cosAng_jikp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][itype-1][kptype-1];
                       amean=cosAng_kikp;
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS_ik*betaS_ikp;
                       rfactor=rfactorrt*rfactorrt;
 
 //2nd CC is second term of Eq. 11 (c) for i atom where j , k & k' =neighbor of i
 
                       CC=CC+2.0*gfactor*rfactor;
 
 //agpdpr1 is derivative of CC 2nd term w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of CC 2nd term w.r.t. Beta(r_ik')
 //app1 is derivative of CC 2nd term w.r.t. cos(theta_jik)
 //app2 is derivative of CC 2nd term w.r.t. cos(theta_jik')
 //app3 is derivative of CC 2nd term w.r.t. cos(theta_kik')
- 
+
                       agpdpr1=4.0*gfactor*rfactorrt*betaS_ikp
                           *dBetaS_ik/r_ik;
                       agpdpr2=4.0*gfactor*rfactorrt*betaS_ik
                           *dBetaS_ikp/r_ikp;
                       app1=2.0*rfactor*gfactor2*gfactor3*gprime1;
                       app2=2.0*rfactor*gfactor1*gfactor3*gprime2;
                       app3=2.0*rfactor*gfactor1*gfactor2*gprime3;
                       bt_sg[nb_ij].dCC[0]+=
                           app1*dcA_jik[0][0]
                           +app2*dcA_jikp[0][0];
                       bt_sg[nb_ij].dCC[1]+=
                           app1*dcA_jik[1][0]
                           +app2*dcA_jikp[1][0];
                       bt_sg[nb_ij].dCC[2]+=
                           app1*dcA_jik[2][0]
                           +app2*dcA_jikp[2][0];
                       bt_sg[nb_ik].dCC[0]+=
                           app1*dcA_jik[0][1]
                           +app3*dcA_kikp[0][0]
                           +agpdpr1*dis_ik[0];
                       bt_sg[nb_ik].dCC[1]+=
                           app1*dcA_jik[1][1]
                           +app3*dcA_kikp[1][0]
                           +agpdpr1*dis_ik[1];
                       bt_sg[nb_ik].dCC[2]+=
                           app1*dcA_jik[2][1]
                           +app3*dcA_kikp[2][0]
                           +agpdpr1*dis_ik[2];
                       bt_sg[nb_ikp].dCC[0]=
                           app2*dcA_jikp[0][1]
                           +app3*dcA_kikp[0][1]
                           +agpdpr2*dis_ikp[0];
                       bt_sg[nb_ikp].dCC[1]=
                           app2*dcA_jikp[1][1]
                           +app3*dcA_kikp[1][1]
                           +agpdpr2*dis_ikp[1];
                       bt_sg[nb_ikp].dCC[2]=
                           app2*dcA_jikp[2][1]
                           +app3*dcA_kikp[2][1]
                           +agpdpr2*dis_ikp[2];
                     }
                   }
                 }
 
 // j and k are different neighbors of i and k' is a neighbor k not equal to i
 
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   kp=klist[ltmp];;
                   kptype = map[type[kp]]+1;
                   same_ikp=0;
                   same_jkp=0;
                   if(x[i][0]==x[kp][0]) {
                     if(x[i][1]==x[kp][1]) {
                       if(x[i][2]==x[kp][2]) {
                         same_ikp=1;
                       }
                     }
                   }
                   if(x[j][0]==x[kp][0]) {
                     if(x[j][1]==x[kp][1]) {
                       if(x[j][2]==x[kp][2]) {
                         same_jkp=1;
                       }
                     }
                   }
                   if(!same_ikp&&!same_jkp) {
                     if(ktype==kptype)
                       ikkp=ktype-1;
                     else if(ktype<kptype)
                       ikkp=ktype*bop_types-ktype*(ktype+1)/2+kptype-1;
                     else
                       ikkp=kptype*bop_types-kptype*(kptype+1)/2+ktype-1;
-                    dis_kkp[0]=x[kp][0]-x[k][0]; 
-                    dis_kkp[1]=x[kp][1]-x[k][1]; 
-                    dis_kkp[2]=x[kp][2]-x[k][2]; 
+                    dis_kkp[0]=x[kp][0]-x[k][0];
+                    dis_kkp[1]=x[kp][1]-x[k][1];
+                    dis_kkp[2]=x[kp][2]-x[k][2];
                     rsq_kkp=dis_kkp[0]*dis_kkp[0]
                         +dis_kkp[1]*dis_kkp[1]
                         +dis_kkp[2]*dis_kkp[2];
-                    r_kkp=sqrt(rsq_kkp); 
+                    r_kkp=sqrt(rsq_kkp);
                     if(r_kkp<=rcut[ikkp]) {
                       ps=r_kkp*rdr[ikkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_kkp=((pBetaS3[ikkp][ks-1]*ps+pBetaS2[ikkp][ks-1])*ps
                           +pBetaS1[ikkp][ks-1])*ps+pBetaS[ikkp][ks-1];
                       dBetaS_kkp=(pBetaS6[ikkp][ks-1]*ps+pBetaS5[ikkp][ks-1])*ps
                           +pBetaS4[ikkp][ks-1];
                       betaP_kkp=((pBetaP3[ikkp][ks-1]*ps+pBetaP2[ikkp][ks-1])*ps
                           +pBetaP1[ikkp][ks-1])*ps+pBetaP[ikkp][ks-1];
                       dBetaP_kkp=(pBetaP6[ikkp][ks-1]*ps+pBetaP5[ikkp][ks-1])*ps
                           +pBetaP4[ikkp][ks-1];
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               sig_flag=1;
                               nkp=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         nkp=nSigBk[n]-1;
                         itypeSigBk[n][nkp]=kp;
                       }
                       cosAng_ikkp=(-dis_ik[0]*dis_kkp[0]-dis_ik[1]*dis_kkp[1]
-                          -dis_ik[2]*dis_kkp[2])/(r_ik*r_kkp); 
+                          -dis_ik[2]*dis_kkp[2])/(r_ik*r_kkp);
                       dcA_ikkp[0][0]=(dis_kkp[0]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[0]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[1][0]=(dis_kkp[1]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[1]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[2][0]=(dis_kkp[2]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[2]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[0][1]=(-dis_ik[0]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[0]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[1][1]=(-dis_ik[1]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[1]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[2][1]=(-dis_ik[2]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[2]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
-                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];          
-                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];          
-                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];          
+                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
+                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
+                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                       amean=cosAng_ikkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS_ik*betaS_kkp;
                       rfactor=rfactorrt*rfactorrt;
 
-//3rd CC is third term of Eq. 11 (c) for i atom 
+//3rd CC is third term of Eq. 11 (c) for i atom
 //where j , k =neighbor of i & k' =neighbor of k
 
                       CC=CC+gfactor*rfactor;
 
 //agpdpr1 is derivative of CC 3rd term w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of CC 3rd term w.r.t. Beta(r_kk')
 //app1 is derivative of CC 3rd term w.r.t. cos(theta_jik)
 //app2 is derivative of CC 3rd term w.r.t. cos(theta_ikk')
- 
+
                       agpdpr1=2.0*gfactor*rfactorrt*betaS_kkp
                           *dBetaS_ik/r_ik;
                       agpdpr2=2.0*gfactor*rfactorrt*betaS_ik
                           *dBetaS_kkp/r_kkp;
                       app1=rfactor*gfactorsq2*gsqprime;
                       app2=rfactor*gfactorsq*gsqprime2;
                       bt_sg[nb_ij].dCC[0]+=
                           app1*dcA_jik[0][0];
                       bt_sg[nb_ij].dCC[1]+=
                           app1*dcA_jik[1][0];
                       bt_sg[nb_ij].dCC[2]+=
                           app1*dcA_jik[2][0];
                       bt_sg[nb_ik].dCC[0]+=
                           app1*dcA_jik[0][1]
                           +agpdpr1*dis_ik[0]
                           -app2*dcA_ikkp[0][0];
                       bt_sg[nb_ik].dCC[1]+=
                           app1*dcA_jik[1][1]
                           +agpdpr1*dis_ik[1]
                           -app2*dcA_ikkp[1][0];
                       bt_sg[nb_ik].dCC[2]+=
                           app1*dcA_jik[2][1]
                           +agpdpr1*dis_ik[2]
                           -app2*dcA_ikkp[2][0];
                       bt_sg[nb_kkp].dCC[0]+=
                           app2*dcA_ikkp[0][1]
                           +agpdpr2*dis_kkp[0];
                       bt_sg[nb_kkp].dCC[1]+=
                           app2*dcA_ikkp[1][1]
                           +agpdpr2*dis_kkp[1];
                       bt_sg[nb_kkp].dCC[2]+=
                           app2*dcA_ikkp[2][1]
                           +agpdpr2*dis_kkp[2];
                     }
                   }
                 }
 
 //j and k are different neighbors of i and k' is a neighbor j not equal to k
 
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   sig_flag=0;
                   temp_jkp=BOP_index[j]+ltmp;
                   kp=jlist[ltmp];
                   kptype = map[type[kp]]+1;
                   kplist=firstneigh[kp];
 
                   same_kkpk=0;
                   same_jkpj=0;
 
                   for(kpNeij=0;kpNeij<numneigh[kp];kpNeij++) {
                     temp_kpj=BOP_index[kp]+kpNeij;
                     kpj=kplist[kpNeij];
                     if(x[j][0]==x[kpj][0]) {
                       if(x[j][1]==x[kpj][1]) {
                         if(x[j][2]==x[kpj][2]) {
                           same_jkpj=1;
                           break;
                         }
                       }
                     }
                   }
                   for(kpNeik=0;kpNeik<numneigh[kp];kpNeik++) {
                     temp_kpk=BOP_index[kp]+kpNeik;
                     kpk=kplist[kpNeik];
                     if(x[k][0]==x[kpk][0]) {
                       if(x[k][1]==x[kpk][1]) {
                         if(x[k][2]==x[kpk][2]) {
                           same_kkpk=1;
                           break;
                         }
                       }
                     }
                   }
                   if(!same_jkpj&&!same_kkpk) {
                     same_kkpk=0;
                     for(kNeikp=0;kNeikp<numneigh[k];kNeikp++) {
                       temp_kkp=BOP_index[k]+kNeikp;
                       kkp=kplist[kNeikp];
                       if(x[kp][0]==x[kkp][0]) {
                         if(x[kp][1]==x[kkp][1]) {
                           if(x[kp][2]==x[kkp][2]) {
                             sig_flag=1;
                             break;
                           }
                         }
                       }
                     }
                     if(sig_flag==1) {
                       for(nsearch=0;nsearch<numneigh[kp];nsearch++) {
                         kp_nsearch=BOP_index[kp]+nsearch;
                         ncmp=kplist[nsearch];
                         if(x[ncmp][0]==x[j][0]) {
                           if(x[ncmp][1]==x[j][1]) {
                             if(x[ncmp][2]==x[j][2]) {
                               kpNeij=nsearch;
                             }
                           }
                         }
                         if(x[ncmp][0]==x[k][0]) {
                           if(x[ncmp][1]==x[k][1]) {
                             if(x[ncmp][2]==x[k][2]) {
                               kpNeik=nsearch;
                             }
                           }
                         }
                       }
                       if(jtype==kptype)
                         ijkp=jtype-1;
                       else if(jtype<kptype)
                         ijkp=jtype*bop_types-jtype*(jtype+1)/2+kptype-1;
                       else
                         ijkp=kptype*bop_types-kptype*(kptype+1)/2+jtype-1;
                       if(ktype==kptype)
                         ikkp=ktype-1;
                       else if(ktype<kptype)
                         ikkp=ktype*bop_types-ktype*(ktype+1)/2+kptype-1;
                       else
                         ikkp=kptype*bop_types-kptype*(kptype+1)/2+ktype-1;
- 
+
                       dis_jkp[0]=x[kp][0]-x[j][0];
                       dis_jkp[1]=x[kp][1]-x[j][1];
                       dis_jkp[2]=x[kp][2]-x[j][2];
                       rsq_jkp=dis_jkp[0]*dis_jkp[0]
                           +dis_jkp[1]*dis_jkp[1]
                           +dis_jkp[2]*dis_jkp[2];
                       r_jkp=sqrt(rsq_jkp);
                       ps=r_jkp*rdr[ijkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                           +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                       dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                           +pBetaS4[ijkp][ks-1];
                       betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                           +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                       dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                           +pBetaP4[ijkp][ks-1];
                       dis_kkp[0]=x[kp][0]-x[k][0];
                       dis_kkp[1]=x[kp][1]-x[k][1];
                       dis_kkp[2]=x[kp][2]-x[k][2];
                       rsq_kkp=dis_kkp[0]*dis_kkp[0]
                           +dis_kkp[1]*dis_kkp[1]
                           +dis_kkp[2]*dis_kkp[2];
                       r_kkp=sqrt(rsq_kkp);
                       ps=r_kkp*rdr[ikkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_kkp=((pBetaS3[ikkp][ks-1]*ps+pBetaS2[ikkp][ks-1])*ps
                           +pBetaS1[ikkp][ks-1])*ps+pBetaS[ikkp][ks-1];
                       dBetaS_kkp=(pBetaS6[ikkp][ks-1]*ps+pBetaS5[ikkp][ks-1])*ps
                           +pBetaS4[ikkp][ks-1];
                       betaP_kkp=((pBetaP3[ikkp][ks-1]*ps+pBetaP2[ikkp][ks-1])*ps
                           +pBetaP1[ikkp][ks-1])*ps+pBetaP[ikkp][ks-1];
                       dBetaP_kkp=(pBetaP6[ikkp][ks-1]*ps+pBetaP5[ikkp][ks-1])*ps
                           +pBetaP4[ikkp][ks-1];
                       cosAng_ijkp=(-dis_ij[0]*dis_jkp[0]-dis_ij[1]*dis_jkp[1]
                           -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp);
                       dcA_ijkp[0][0]=(dis_jkp[0]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[0]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][0]=(dis_jkp[1]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[1]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][0]=(dis_jkp[2]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[2]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[0][1]=(-dis_ij[0]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[0]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][1]=(-dis_ij[1]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[1]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][1]=(-dis_ij[2]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[2]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       cosAng_ikkp=(-dis_ik[0]*dis_kkp[0]-dis_ik[1]*dis_kkp[1]
                           -dis_ik[2]*dis_kkp[2])/(r_ik*r_kkp);
                       dcA_ikkp[0][0]=(dis_kkp[0]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[0]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[1][0]=(dis_kkp[1]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[1]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[2][0]=(dis_kkp[2]*r_ik*r_kkp-cosAng_ikkp
                           *-dis_ik[2]*r_kkp*r_kkp)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[0][1]=(-dis_ik[0]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[0]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[1][1]=(-dis_ik[1]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[1]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       dcA_ikkp[2][1]=(-dis_ik[2]*r_ik*r_kkp-cosAng_ikkp
                           *dis_kkp[2]*r_ik*r_ik)/(r_ik*r_ik*r_kkp*r_kkp);
                       cosAng_jkpk=(dis_jkp[0]*dis_kkp[0]+dis_jkp[1]*dis_kkp[1]
                           +dis_jkp[2]*dis_kkp[2])/(r_jkp*r_kkp);
                       dcA_jkpk[0][0]=(-dis_kkp[0]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_jkp[0]*r_kkp*r_kkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       dcA_jkpk[1][0]=(-dis_kkp[1]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_jkp[1]*r_kkp*r_kkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       dcA_jkpk[2][0]=(-dis_kkp[2]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_jkp[2]*r_kkp*r_kkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       dcA_jkpk[0][1]=(-dis_jkp[0]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_kkp[0]*r_jkp*r_jkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       dcA_jkpk[1][1]=(-dis_jkp[1]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_kkp[1]*r_jkp*r_jkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       dcA_jkpk[2][1]=(-dis_jkp[2]*r_jkp*r_kkp-cosAng_jkpk
                           *-dis_kkp[2]*r_jkp*r_jkp)/(r_jkp*r_jkp*r_kkp*r_kkp);
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               nkp=nsearch;
                               sig_flag=1;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         nkp=nSigBk[n]-1;
                         itypeSigBk[n][nkp]=kp;
                       }
                       temp_kpk=BOP_index[kp]+kpNeik;
                       nb_jkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_jkp].temp=temp_jkp;
                       bt_sg[nb_jkp].i=j;
                       bt_sg[nb_jkp].j=kp;
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
                       gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                       amean=cosAng_ijkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                       amean=cosAng_ikkp;
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[jtype-1][kptype-1][ktype-1];
                       gmean1=sigma_g1[jtype-1][kptype-1][ktype-1];
                       gmean2=sigma_g2[jtype-1][kptype-1][ktype-1];
                       amean=cosAng_jkpk;
                       gfactor4=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime4=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3*gfactor4;
                       rfactor0=(betaS_ik+small2)*(betaS_jkp+small2)
                           *(betaS_kkp+small2);
                       rfactor=pow(rfactor0,2.0/3.0);
                       drfactor=2.0/3.0*pow(rfactor0,-1.0/3.0);
- 
+
 //EE is Eq. 25(notes)
- 
+
                       EE=EE+gfactor*rfactor;
- 
+
 //agpdpr1 is derivative of agpdpr1 w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of agpdpr1 w.r.t. Beta(r_jk')
 //agpdpr3 is derivative of agpdpr1 w.r.t. Beta(r_kk')
 //app1 is derivative of agpdpr1 w.r.t. cos(theta_jik)
 //app2 is derivative of agpdpr1 w.r.t. cos(theta_ijk')
 //app3 is derivative of agpdpr1 w.r.t. cos(theta_ikk')
 //app4 is derivative of agpdpr1 w.r.t. cos(theta_jk'k)
- 
+
                       agpdpr1=gfactor*drfactor*(betaS_jkp+small2)*(betaS_kkp
                           +small2)*dBetaS_ik/r_ik;
                       agpdpr2=gfactor*drfactor*(betaS_ik+small2)*(betaS_kkp
                           +small2)*dBetaS_jkp/r_jkp;
                       agpdpr3=gfactor*drfactor*(betaS_ik+small2)*(betaS_jkp
                           +small2)*dBetaS_kkp/r_kkp;
                       app1=rfactor*gfactor2*gfactor3*gfactor4*gprime1;
                       app2=rfactor*gfactor1*gfactor3*gfactor4*gprime2;
                       app3=rfactor*gfactor1*gfactor2*gfactor4*gprime3;
                       app4=rfactor*gfactor1*gfactor2*gfactor3*gprime4;
                       bt_sg[nb_ij].dEE[0]+=
                           app1*dcA_jik[0][0]
                           -app2*dcA_ijkp[0][0];
                       bt_sg[nb_ij].dEE[1]+=
                           app1*dcA_jik[1][0]
                           -app2*dcA_ijkp[1][0];
                       bt_sg[nb_ij].dEE[2]+=
                           app1*dcA_jik[2][0]
                           -app2*dcA_ijkp[2][0];
                       bt_sg[nb_ik].dEE[0]+=
                           app1*dcA_jik[0][1]
                           +agpdpr1*dis_ik[0]
                           -app3*dcA_ikkp[0][0];
                       bt_sg[nb_ik].dEE[1]+=
                           app1*dcA_jik[1][1]
                           +agpdpr1*dis_ik[1]
                           -app3*dcA_ikkp[1][0];
                       bt_sg[nb_ik].dEE[2]+=
                           app1*dcA_jik[2][1]
                           +agpdpr1*dis_ik[2]
                           -app3*dcA_ikkp[2][0];
                       bt_sg[nb_jkp].dEE[0]+=
                           app2*dcA_ijkp[0][1]
                           +agpdpr2*dis_jkp[0]
                           -app4*dcA_jkpk[0][0];
                       bt_sg[nb_jkp].dEE[1]+=
                           app2*dcA_ijkp[1][1]
                           +agpdpr2*dis_jkp[1]
                           -app4*dcA_jkpk[1][0];
                       bt_sg[nb_jkp].dEE[2]+=
                           app2*dcA_ijkp[2][1]
                           +agpdpr2*dis_jkp[2]
                           -app4*dcA_jkpk[2][0];
                       bt_sg[nb_kkp].dEE[0]+=
                           app3*dcA_ikkp[0][1]
                           +agpdpr3*dis_kkp[0]
                           -app4*dcA_jkpk[0][1];
                       bt_sg[nb_kkp].dEE[1]+=
                           app3*dcA_ikkp[1][1]
                           +agpdpr3*dis_kkp[1]
                           -app4*dcA_jkpk[1][1];
                       bt_sg[nb_kkp].dEE[2]+=
                           app3*dcA_ikkp[2][1]
                           +agpdpr3*dis_kkp[2]
                           -app4*dcA_jkpk[2][1];
                     }
                   }
                 }
               }
             }
           }
-        
+
 //j is a neighbor of i and k is a neighbor of j not equal to i
 
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ji) {
               temp_jk=BOP_index[j]+ktmp;
               k=jlist[ktmp];
               klist=firstneigh[k];
               ktype=map[type[k]]+1;
               for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                 if(x[klist[kNeij]][0]==x[j][0]) {
                   if(x[klist[kNeij]][1]==x[j][1]) {
                     if(x[klist[kNeij]][2]==x[j][2]) {
                       break;
                     }
                   }
                 }
               }
               if(jtype==ktype)
                 ijk=jtype-1;
               else if(jtype<ktype)
                 ijk=jtype*bop_types-jtype*(jtype+1)/2+ktype-1;
               else
                 ijk=ktype*bop_types-ktype*(ktype+1)/2+jtype-1;
               sig_flag=0;
               for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                 ncmp=itypeSigBk[n][nsearch];
                 if(x[ncmp][0]==x[k][0]) {
                   if(x[ncmp][1]==x[k][1]) {
                     if(x[ncmp][2]==x[k][2]) {
                       new1=nsearch;
                       sig_flag=1;
                       break;
                     }
                   }
                 }
               }
               if(sig_flag==0) {
                 nSigBk[n]=nSigBk[n]+1;
                 new1=nSigBk[n]-1;
                 itypeSigBk[n][new1]=k;
               }
-              dis_jk[0]=x[k][0]-x[j][0]; 
-              dis_jk[1]=x[k][1]-x[j][1]; 
-              dis_jk[2]=x[k][2]-x[j][2]; 
+              dis_jk[0]=x[k][0]-x[j][0];
+              dis_jk[1]=x[k][1]-x[j][1];
+              dis_jk[2]=x[k][2]-x[j][2];
               rsq_jk=dis_jk[0]*dis_jk[0]
                   +dis_jk[1]*dis_jk[1]
                   +dis_jk[2]*dis_jk[2];
-              r_jk=sqrt(rsq_jk); 
+              r_jk=sqrt(rsq_jk);
               if(r_jk<=rcut[ijk]) {
                 ps=r_jk*rdr[ijk]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_jk=((pBetaS3[ijk][ks-1]*ps+pBetaS2[ijk][ks-1])*ps
                     +pBetaS1[ijk][ks-1])*ps+pBetaS[ijk][ks-1];
                 dBetaS_jk=(pBetaS6[ijk][ks-1]*ps+pBetaS5[ijk][ks-1])*ps
                     +pBetaS4[ijk][ks-1];
                 betaP_jk=((pBetaP3[ijk][ks-1]*ps+pBetaP2[ijk][ks-1])*ps
                     +pBetaP1[ijk][ks-1])*ps+pBetaP[ijk][ks-1];
                 dBetaP_jk=(pBetaP6[ijk][ks-1]*ps+pBetaP5[ijk][ks-1])*ps
                     +pBetaP4[ijk][ks-1];
                 cosAng_ijk=(-dis_ij[0]*dis_jk[0]-dis_ij[1]*dis_jk[1]
-                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk); 
+                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk);
                 dcA_ijk[0][0]=(dis_jk[0]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[0]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][0]=(dis_jk[1]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[1]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][0]=(dis_jk[2]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[2]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[0][1]=(-dis_ij[0]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[0]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][1]=(-dis_ij[1]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[1]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][1]=(-dis_ij[2]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[2]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                 gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                 gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                 amean=cosAng_ijk;
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gsqprime=2.0*gfactor1*gprime1;
                 rfactor1rt=betaS_jk*betaS_jk;
                 rfactor1=rfactor1rt*rfactor1rt;
 
 //BB is Eq. 34 (a) or Eq. 10 (c) for the j atom
 //1st DD is Eq. 11 (c) for j atom where i & k=neighbor of j
 
                 BB=BB+gfactorsq*rfactor1rt;
                 DD=DD+gfactorsq*rfactor1;
 
 //agpdpr1 is derivative of BB  w.r.t. Beta(r_jk)
 //app1 is derivative of BB w.r.t. cos(theta_ijk)
 
                 agpdpr1=2.0*gfactorsq*betaS_jk*dBetaS_jk/r_jk;
                 agpdpr2=2.0*rfactor1rt*agpdpr1;
                 app1=rfactor1rt*gsqprime;
                 app2=rfactor1rt*app1;
                 bt_sg[nb_ij].dBB[0]-=
                     app1*dcA_ijk[0][0];
                 bt_sg[nb_ij].dBB[1]-=
                     app1*dcA_ijk[1][0];
                 bt_sg[nb_ij].dBB[2]-=
                     app1*dcA_ijk[2][0];
                 bt_sg[nb_ij].dDD[0]-=
                     app2*dcA_ijk[0][0];
                 bt_sg[nb_ij].dDD[1]-=
                     app2*dcA_ijk[1][0];
                 bt_sg[nb_ij].dDD[2]-=
                     app2*dcA_ijk[2][0];
                 bt_sg[nb_jk].dBB[0]+=
                     app1*dcA_ijk[0][1]
                     +agpdpr1*dis_jk[0];
                 bt_sg[nb_jk].dBB[1]+=
                     app1*dcA_ijk[1][1]
                     +agpdpr1*dis_jk[1];
                 bt_sg[nb_jk].dBB[2]+=
                     app1*dcA_ijk[2][1]
                     +agpdpr1*dis_jk[2];
                 bt_sg[nb_jk].dDD[0]+=
                     app2*dcA_ijk[0][1]
                     +agpdpr2*dis_jk[0];
                 bt_sg[nb_jk].dDD[1]+=
                     app2*dcA_ijk[1][1]
                     +agpdpr2*dis_jk[1];
                 bt_sg[nb_jk].dDD[2]+=
                     app2*dcA_ijk[2][1]
                     +agpdpr2*dis_jk[2];
 
 //j is a neighbor of i, k and k' prime different neighbors of j not equal to i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ji) {
                     temp_jkp=BOP_index[j]+ltmp;
                     kp=jlist[ltmp];
                     kptype=map[type[kp]]+1;
                     if(jtype==kptype)
                       ijkp=jtype-1;
                     else if(jtype<kptype)
                       ijkp=jtype*bop_types-jtype*(jtype+1)/2+kptype-1;
                     else
                       ijkp=kptype*bop_types-kptype*(kptype+1)/2+jtype-1;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             new2=nsearch;
                             break;
                           }
                         }
                       }
                     }
-                    dis_jkp[0]=x[kp][0]-x[j][0]; 
-                    dis_jkp[1]=x[kp][1]-x[j][1]; 
-                    dis_jkp[2]=x[kp][2]-x[j][2]; 
+                    dis_jkp[0]=x[kp][0]-x[j][0];
+                    dis_jkp[1]=x[kp][1]-x[j][1];
+                    dis_jkp[2]=x[kp][2]-x[j][2];
                     rsq_jkp=dis_jkp[0]*dis_jkp[0]
                         +dis_jkp[1]*dis_jkp[1]
                         +dis_jkp[2]*dis_jkp[2];
-                    r_jkp=sqrt(rsq_jkp); 
+                    r_jkp=sqrt(rsq_jkp);
                     if(r_jkp<=rcut[ijkp]) {
                       ps=r_jkp*rdr[ijkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                         +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                       dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                         +pBetaS4[ijkp][ks-1];
                       betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                         +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                       dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                         +pBetaP4[ijkp][ks-1];
                       cosAng_ijkp=(-dis_ij[0]*dis_jkp[0]-dis_ij[1]*dis_jkp[1]
-                        -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp); 
+                        -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp);
                       dcA_ijkp[0][0]=(dis_jkp[0]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[0]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][0]=(dis_jkp[1]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[1]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][0]=(dis_jkp[2]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[2]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[0][1]=(-dis_ij[0]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[0]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][1]=(-dis_ij[1]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[1]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][1]=(-dis_ij[2]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[2]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       cosAng_kjkp=(dis_jk[0]*dis_jkp[0]+dis_jk[1]*dis_jkp[1]
-                        +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp); 
+                        +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp);
                       dcA_kjkp[0][0]=(dis_jkp[0]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[0]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][0]=(dis_jkp[1]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[1]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][0]=(dis_jkp[2]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[2]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[0][1]=(dis_jk[0]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[0]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][1]=(dis_jk[1]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[1]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][1]=(dis_jk[2]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[2]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       nb_jkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_jkp].temp=temp_jkp;
                       bt_sg[nb_jkp].i=j;
                       bt_sg[nb_jkp].j=kp;
                       gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                       amean=cosAng_ijkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][jtype-1][kptype-1];
                       amean=cosAng_kjkp;
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS_jk*betaS_jkp;
                       rfactor=rfactorrt*rfactorrt;
 
 //2nd DD is Eq. 11 (c) for j atom where i , k & k'=neighbor of j
 
                       DD=DD+2.0*gfactor*rfactor;
 
 //agpdpr1 is derivative of DD  w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of DD  w.r.t. Beta(r_jk')
 //app1 is derivative of DD  w.r.t. cos(theta_ijk)
 //app2 is derivative of DD  w.r.t. cos(theta_ijkp)
 //app3 is derivative of DD  w.r.t. cos(theta_kjkp)
- 
+
                       agpdpr1=4.0*gfactor*rfactorrt*betaS_jkp
                           *dBetaS_jk/r_jk;
                       agpdpr2=4.0*gfactor*rfactorrt*betaS_jk
                           *dBetaS_jkp/r_jkp;
                       app1=2.0*rfactor*gfactor2*gfactor3*gprime1;
                       app2=2.0*rfactor*gfactor1*gfactor3*gprime2;
                       app3=2.0*rfactor*gfactor1*gfactor2*gprime3;
                       bt_sg[nb_ij].dDD[0]-=
                           app1*dcA_ijk[0][0]
                           +app2*dcA_ijkp[0][0];
                       bt_sg[nb_ij].dDD[1]-=
                           app1*dcA_ijk[1][0]
                           +app2*dcA_ijkp[1][0];
                       bt_sg[nb_ij].dDD[2]-=
                           app1*dcA_ijk[2][0]
                           +app2*dcA_ijkp[2][0];
                       bt_sg[nb_jk].dDD[0]+=
                           app1*dcA_ijk[0][1]
                           +app3*dcA_kjkp[0][0]
                           +agpdpr1*dis_jk[0];
                       bt_sg[nb_jk].dDD[1]+=
                           app1*dcA_ijk[1][1]
                           +app3*dcA_kjkp[1][0]
                           +agpdpr1*dis_jk[1];
                       bt_sg[nb_jk].dDD[2]+=
                           app1*dcA_ijk[2][1]
                           +app3*dcA_kjkp[2][0]
                           +agpdpr1*dis_jk[2];
                       bt_sg[nb_jkp].dDD[0]+=
                           app2*dcA_ijkp[0][1]
                           +app3*dcA_kjkp[0][1]
                           +agpdpr2*dis_jkp[0];
                       bt_sg[nb_jkp].dDD[1]+=
                           app2*dcA_ijkp[1][1]
                           +app3*dcA_kjkp[1][1]
                           +agpdpr2*dis_jkp[1];
                       bt_sg[nb_jkp].dDD[2]+=
                           app2*dcA_ijkp[2][1]
                           +app3*dcA_kjkp[2][1]
                           +agpdpr2*dis_jkp[2];
 
                     }
                   }
                 }
 
-//j is a neighbor of i, k is a neighbor of j not equal to i and k' 
+//j is a neighbor of i, k is a neighbor of j not equal to i and k'
 //is a neighbor of k not equal to j or i
 
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   kp=klist[ltmp];
                   kptype=map[type[kp]]+1;
                   same_ikp=0;
                   same_jkp=0;
                   if(x[i][0]==x[kp][0]) {
                     if(x[i][1]==x[kp][1]) {
                       if(x[i][2]==x[kp][2]) {
                         same_ikp=1;
                       }
                     }
                   }
                   if(x[j][0]==x[kp][0]) {
                     if(x[j][1]==x[kp][1]) {
                       if(x[j][2]==x[kp][2]) {
                         same_jkp=1;
                       }
                     }
                   }
                   if(!same_ikp&&!same_jkp) {
                     if(ktype==kptype)
                       ikkp=ktype-1;
                     else if(ktype<kptype)
                       ikkp=ktype*bop_types-ktype*(ktype+1)/2+kptype-1;
                     else
                       ikkp=kptype*bop_types-kptype*(kptype+1)/2+ktype-1;
                     for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                       if(x[klist[kNeij]][0]==x[j][0]) {
                         if(x[klist[kNeij]][1]==x[j][1]) {
                           if(x[klist[kNeij]][2]==x[j][2]) {
                             break;
                           }
                         }
                       }
                     }
                     sig_flag=0;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             new2=nsearch;
                             sig_flag=1;
                             break;
                           }
                         }
                       }
                     }
                     if(sig_flag==0) {
                       nSigBk[n]=nSigBk[n]+1;
                       new2=nSigBk[n]-1;
                       itypeSigBk[n][new2]=kp;
                     }
-                    dis_kkp[0]=x[kp][0]-x[k][0]; 
-                    dis_kkp[1]=x[kp][1]-x[k][1]; 
-                    dis_kkp[2]=x[kp][2]-x[k][2]; 
+                    dis_kkp[0]=x[kp][0]-x[k][0];
+                    dis_kkp[1]=x[kp][1]-x[k][1];
+                    dis_kkp[2]=x[kp][2]-x[k][2];
                     rsq_kkp=dis_kkp[0]*dis_kkp[0]
                         +dis_kkp[1]*dis_kkp[1]
                         +dis_kkp[2]*dis_kkp[2];
-                    r_kkp=sqrt(rsq_kkp); 
+                    r_kkp=sqrt(rsq_kkp);
                     if(r_kkp<=rcut[ikkp]) {
                       ps=r_kkp*rdr[ikkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_kkp=((pBetaS3[ikkp][ks-1]*ps+pBetaS2[ikkp][ks-1])*ps
                           +pBetaS1[ikkp][ks-1])*ps+pBetaS[ikkp][ks-1];
                       dBetaS_kkp=(pBetaS6[ikkp][ks-1]*ps+pBetaS5[ikkp][ks-1])*ps
                           +pBetaS4[ikkp][ks-1];
                       betaP_kkp=((pBetaP3[ikkp][ks-1]*ps+pBetaP2[ikkp][ks-1])*ps
                           +pBetaP1[ikkp][ks-1])*ps+pBetaP[ikkp][ks-1];
                       dBetaP_kkp=(pBetaP6[ikkp][ks-1]*ps+pBetaP5[ikkp][ks-1])*ps
                           +pBetaP4[ikkp][ks-1];
                       cosAng_jkkp=(-dis_jk[0]*dis_kkp[0]-dis_jk[1]*dis_kkp[1]
-                          -dis_jk[2]*dis_kkp[2])/(r_jk*r_kkp); 
+                          -dis_jk[2]*dis_kkp[2])/(r_jk*r_kkp);
                       dcA_jkkp[0][0]=(dis_kkp[0]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[0]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[1][0]=(dis_kkp[1]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[1]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[2][0]=(dis_kkp[2]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[2]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[0][1]=(-dis_jk[0]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[0]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[1][1]=(-dis_jk[1]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[1]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[2][1]=(-dis_jk[2]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[2]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
                       gmean0=sigma_g0[jtype-1][ktype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][ktype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][ktype-1][kptype-1];
                       amean=cosAng_jkkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS_jk*betaS_kkp;
                       rfactor=rfactorrt*rfactorrt;
 
 //3rd DD is Eq. 11 (c) for j atom where i & k=neighbor of j & k'=neighbor of k
 
                       DD=DD+gfactor*rfactor;
 
 //agpdpr1 is derivative of DD  3rd term w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of DD  3rd term w.r.t. Beta(r_kk')
 //app1 is derivative of DD  3rd term w.r.t. cos(theta_ijk)
 //app2 is derivative of DD  3rd term w.r.t. cos(theta_jkkp)
- 
+
                       agpdpr1=2.0*gfactor*rfactorrt*betaS_kkp
                           *dBetaS_jk/r_jk;
                       agpdpr2=2.0*gfactor*rfactorrt*betaS_jk
                           *dBetaS_kkp/r_kkp;
                       app1=rfactor*gfactorsq2*gsqprime;
                       app2=rfactor*gfactorsq*gsqprime2;
                       bt_sg[nb_ij].dDD[0]-=
                           app1*dcA_ijk[0][0];
                       bt_sg[nb_ij].dDD[1]-=
                           app1*dcA_ijk[1][0];
                       bt_sg[nb_ij].dDD[2]-=
                           app1*dcA_ijk[2][0];
                       bt_sg[nb_jk].dDD[0]+=
                           app1*dcA_ijk[0][1]
                           +agpdpr1*dis_jk[0]
                           -app2*dcA_jkkp[0][0];
                       bt_sg[nb_jk].dDD[1]+=
                           app1*dcA_ijk[1][1]
                           +agpdpr1*dis_jk[1]
                           -app2*dcA_jkkp[1][0];
                       bt_sg[nb_jk].dDD[2]+=
                           app1*dcA_ijk[2][1]
                           +agpdpr1*dis_jk[2]
                           -app2*dcA_jkkp[2][0];
                       bt_sg[nb_kkp].dDD[0]+=
                           app2*dcA_jkkp[0][1]
                           +agpdpr2*dis_kkp[0];
                       bt_sg[nb_kkp].dDD[1]+=
                           app2*dcA_jkkp[1][1]
                           +agpdpr2*dis_kkp[1];
                       bt_sg[nb_kkp].dDD[2]+=
                           app2*dcA_jkkp[2][1]
                           +agpdpr2*dis_kkp[2];
 
                     }
                   }
                 }
               }
             }
           }
 
           sig_flag=0;
           if(FF<=0.000001) {
             sigB[n]=0.0;
             sig_flag=1;
           }
           if(sig_flag==0) {
             if(AA<0.0)
               AA=0.0;
             if(BB<0.0)
               BB=0.0;
             if(CC<0.0)
               CC=0.0;
             if(DD<0.0)
               DD=0.0;
 
 // AA and BB are the representations of (a) Eq. 34 and (b) Eq. 9
 // for atoms i and j respectively
 
             AAC=AA+BB;
             BBC=AA*BB;
             CCC=AA*AA+BB*BB;
             DDC=CC+DD;
 
 //EEC is a modified form of (a) Eq. 33
 
             EEC=(DDC-CCC)/(AAC+2.0*small1);
             AACFF=1.0/(AAC+2.0*small1);
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_sg[m].dAAC[0]=bt_sg[m].dAA[0]
                     +bt_sg[m].dBB[0];
                 bt_sg[m].dAAC[1]=bt_sg[m].dAA[1]
                     +bt_sg[m].dBB[1];
                 bt_sg[m].dAAC[2]=bt_sg[m].dAA[2]
                     +bt_sg[m].dBB[2];
                 bt_sg[m].dBBC[0]=bt_sg[m].dAA[0]*BB
                     +AA*bt_sg[m].dBB[0];
                 bt_sg[m].dBBC[1]=bt_sg[m].dAA[1]*BB
                     +AA*bt_sg[m].dBB[1];
                 bt_sg[m].dBBC[2]=bt_sg[m].dAA[2]*BB
                     +AA*bt_sg[m].dBB[2];
                 bt_sg[m].dCCC[0]=2.0*AA*bt_sg[m].dAA[0]
                     +2.0*BB*bt_sg[m].dBB[0];
                 bt_sg[m].dCCC[1]=2.0*AA*bt_sg[m].dAA[1]
                     +2.0*BB*bt_sg[m].dBB[1];
                 bt_sg[m].dCCC[2]=2.0*AA*bt_sg[m].dAA[2]
                     +2.0*BB*bt_sg[m].dBB[2];
                 bt_sg[m].dDDC[0]=bt_sg[m].dCC[0]
                     +bt_sg[m].dDD[0];
                 bt_sg[m].dDDC[1]=bt_sg[m].dCC[1]
                     +bt_sg[m].dDD[1];
                 bt_sg[m].dDDC[2]=bt_sg[m].dCC[2]
                     +bt_sg[m].dDD[2];
                 bt_sg[m].dEEC[0]=(bt_sg[m].dDDC[0]
                     -bt_sg[m].dCCC[0]
                     -EEC*bt_sg[m].dAAC[0])*AACFF;
                 bt_sg[m].dEEC[1]=(bt_sg[m].dDDC[1]
                     -bt_sg[m].dCCC[1]
                     -EEC*bt_sg[m].dAAC[1])*AACFF;
                 bt_sg[m].dEEC[2]=(bt_sg[m].dDDC[2]
                     -bt_sg[m].dCCC[2]
                     -EEC*bt_sg[m].dAAC[2])*AACFF;
-              } 
+              }
             }
             UT=EEC*FF+BBC+small3[iij];
             UT=1.0/sqrt(UT);
 
 // FFC is slightly modified form of (a) Eq. 31
 // GGC is slightly modified form of (a) Eq. 32
 // bndtmp is a slightly modified form of (a) Eq. 30 and (b) Eq. 8
 
             FFC=BBC*UT;
             GGC=EEC*UT;
             bndtmp=(FF+sigma_delta[iij]*sigma_delta[iij])*(1.0+sigma_a[iij]*GGC)
                 *(1.0+sigma_a[iij]*GGC)+sigma_c[iij]*(AAC+sigma_a[iij]*EE
                 +sigma_a[iij]*FFC*(2.0+GGC))+small4;
             UTcom=-0.5*UT*UT*UT;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_sg[m].dUT[0]=UTcom*(bt_sg[m].dEEC[0]*FF
                     +EEC*bt_sg[m].dFF[0]+bt_sg[m].dBBC[0]);
                 bt_sg[m].dUT[1]=UTcom*(bt_sg[m].dEEC[1]*FF
                     +EEC*bt_sg[m].dFF[1]+bt_sg[m].dBBC[1]);
                 bt_sg[m].dUT[2]=UTcom*(bt_sg[m].dEEC[2]*FF
                     +EEC*bt_sg[m].dFF[2]+bt_sg[m].dBBC[2]);
                 bt_sg[m].dFFC[0]=bt_sg[m].dBBC[0]*UT
                     +BBC*bt_sg[m].dUT[0];
                 bt_sg[m].dFFC[1]=bt_sg[m].dBBC[1]*UT
                     +BBC*bt_sg[m].dUT[1];
                 bt_sg[m].dFFC[2]=bt_sg[m].dBBC[2]*UT
                     +BBC*bt_sg[m].dUT[2];
                 bt_sg[m].dGGC[0]=bt_sg[m].dEEC[0]*UT
                     +EEC*bt_sg[m].dUT[0];
                 bt_sg[m].dGGC[1]=bt_sg[m].dEEC[1]*UT
                     +EEC*bt_sg[m].dUT[1];
                 bt_sg[m].dGGC[2]=bt_sg[m].dEEC[2]*UT
                     +EEC*bt_sg[m].dUT[2];
               }
             }
             psign=1.0;
             if(1.0+sigma_a[iij]*GGC<0.0)
               psign=-1.0;
             bndtmp0=1.0/sqrt(bndtmp);
             sigB1[n]=psign*betaS_ij*(1.0+sigma_a[iij]*GGC)*bndtmp0;
             bndtmp=-0.5*bndtmp0*bndtmp0*bndtmp0;
             bndtmp1=psign*(1.0+sigma_a[iij]*GGC)*bndtmp0+psign*betaS_ij
                 *(1.0+sigma_a[iij]*GGC)*bndtmp*2.0*betaS_ij*(1.0
                 +sigma_a[iij]*GGC)*(1.0+sigma_a[iij]*GGC);
             bndtmp1=bndtmp1*dBetaS_ij/r_ij;
             bndtmp2=psign*betaS_ij*(1.0+sigma_a[iij]*GGC)*bndtmp*sigma_c[iij];
             bndtmp3=psign*betaS_ij*(1.0+sigma_a[iij]*GGC)
                 *bndtmp*sigma_c[iij]*sigma_a[iij];
             bndtmp4=psign*betaS_ij*(1.0+sigma_a[iij]*GGC)
                 *bndtmp*sigma_c[iij]*sigma_a[iij]*(2.0+GGC);
             bndtmp5=sigma_a[iij]*psign*betaS_ij*bndtmp0
                 +psign*betaS_ij*(1.0+sigma_a[iij]*GGC)*bndtmp
                 *(2.0*(FF+sigma_delta[iij]*sigma_delta[iij])*(1.0
                 +sigma_a[iij]*GGC)*sigma_a[iij]+sigma_c[iij]*sigma_a[iij]*FFC);
             setting=0;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 if(temp_kk==temp_ij&&setting==0) {
                   bt_sg[m].dSigB1[0]=bndtmp1*dis_ij[0]
                       +(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=bndtmp1*dis_ij[1]
                       +(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=bndtmp1*dis_ij[2]
                       +(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                   setting=1;
                 }
                 else if(temp_kk==temp_ji&&setting==0) {
                   bt_sg[m].dSigB1[0]=-bndtmp1*dis_ij[0]
                       +(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=-bndtmp1*dis_ij[1]
                       +(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=-bndtmp1*dis_ij[2]
                       +(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                   setting=1;
                 }
                 else {
                   bt_sg[m].dSigB1[0]=(bndtmp2*bt_sg[m].dAAC[0]
                       +bndtmp3*bt_sg[m].dEE[0]
                       +bndtmp4*bt_sg[m].dFFC[0]
                       +bndtmp5*bt_sg[m].dGGC[0]);
                   bt_sg[m].dSigB1[1]=(bndtmp2*bt_sg[m].dAAC[1]
                       +bndtmp3*bt_sg[m].dEE[1]
                       +bndtmp4*bt_sg[m].dFFC[1]
                       +bndtmp5*bt_sg[m].dGGC[1]);
                   bt_sg[m].dSigB1[2]=(bndtmp2*bt_sg[m].dAAC[2]
                       +bndtmp3*bt_sg[m].dEE[2]
                       +bndtmp4*bt_sg[m].dFFC[2]
                       +bndtmp5*bt_sg[m].dGGC[2]);
                 }
               }
             }
 
 //This loop is to ensure there is not an error for atoms with no neighbors (deposition)
 
             if(nb_t==0) {
               if(j>i) {
                 bt_sg[0].dSigB1[0]=bndtmp1*dis_ij[0];
                 bt_sg[0].dSigB1[1]=bndtmp1*dis_ij[1];
                 bt_sg[0].dSigB1[2]=bndtmp1*dis_ij[2];
               }
               else {
                 bt_sg[0].dSigB1[0]=-bndtmp1*dis_ij[0];
                 bt_sg[0].dSigB1[1]=-bndtmp1*dis_ij[1];
                 bt_sg[0].dSigB1[2]=-bndtmp1*dis_ij[2];
               }
               for(pp=0;pp<3;pp++) {
                 bt_sg[0].dAA[pp]=0.0;
                 bt_sg[0].dBB[pp]=0.0;
                 bt_sg[0].dCC[pp]=0.0;
                 bt_sg[0].dDD[pp]=0.0;
                 bt_sg[0].dEE[pp]=0.0;
                 bt_sg[0].dEE1[pp]=0.0;
                 bt_sg[0].dFF[pp]=0.0;
                 bt_sg[0].dAAC[pp]=0.0;
                 bt_sg[0].dBBC[pp]=0.0;
                 bt_sg[0].dCCC[pp]=0.0;
                 bt_sg[0].dDDC[pp]=0.0;
                 bt_sg[0].dEEC[pp]=0.0;
                 bt_sg[0].dFFC[pp]=0.0;
                 bt_sg[0].dGGC[pp]=0.0;
                 bt_sg[0].dUT[pp]=0.0;
                 bt_sg[0].dSigB1[pp]=0.0;
                 bt_sg[0].dSigB[pp]=0.0;
               }
               bt_sg[0].i=i;
               bt_sg[0].j=j;
               bt_sg[0].temp=temp_ij;
               nb_t++;
               if(nb_t>nb_sg) {
                 new_n_tot=nb_sg+maxneigh;
                 grow_sigma(nb_sg,new_n_tot);
                 nb_sg=new_n_tot;
               }
             }
             ps=sigB1[n]*rdBO+1.0;
             ks=(int)ps;
             if(nBOt-1<ks)
               ks=nBOt-1;
             ps=ps-ks;
             if(ps>1.0)
               ps=1.0;
             dsigB1=((FsigBO3[iij][ks-1]*ps+FsigBO2[iij][ks-1])*ps
                 +FsigBO1[iij][ks-1])*ps+FsigBO[iij][ks-1];
             dsigB2=(FsigBO6[iij][ks-1]*ps+FsigBO5[iij][ks-1])*ps+FsigBO4[iij][ks-1];
             part0=(FF+0.5*AAC+small5);
             part1=(sigma_f[iij]-0.5)*sigma_k[iij];
             part2=1.0-part1*EE1/part0;
             part3=dsigB1*part1/part0;
             part4=part3/part0*EE1;
 
 // sigB is the final expression for (a) Eq. 6 and (b) Eq. 11
 
             sigB[n]=dsigB1*part2;
             pp1=2.0*betaS_ij;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 xtmp[0]=x[bt_j][0]-x[bt_i][0];
                 xtmp[1]=x[bt_j][1]-x[bt_i][1];
                 xtmp[2]=x[bt_j][2]-x[bt_i][2];
                 for(pp=0;pp<3;pp++) {
                   bt_sg[m].dSigB[pp]=dsigB2*part2*bt_sg[m].dSigB1[pp]
                       -part3*bt_sg[m].dEE1[pp]
                       +part4*(bt_sg[m].dFF[pp]
                       +0.5*bt_sg[m].dAAC[pp]);
                 }
                 for(pp=0;pp<3;pp++) {
                   ftmp[pp]=pp1*bt_sg[m].dSigB[pp];
                   f[bt_i][pp]-=ftmp[pp];
                   f[bt_j][pp]+=ftmp[pp];
                 }
                 if(evflag) {
                   ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                       ,ftmp[2],xtmp[0],xtmp[1],xtmp[2]);
                 }
               }
             }
           }
           n++;
         }
       }
     }
   }
   destroy_sigma();
 }
 
 /* ---------------------------------------------------------------------- */
 
 /*  The formulation differs slightly to avoid negative square roots
-    in the calculation of Theta_pi,ij of (a) Eq. 36 and (b) Eq. 18 
+    in the calculation of Theta_pi,ij of (a) Eq. 36 and (b) Eq. 18
     see (d) */
- 
+
 void PairBOP::sigmaBo_noa_otf()
 {
   int nb_t,new_n_tot;
   int n,i,j,k,kp,m,pp;
   int itmp,jtmp,ktmp,ltmp,mtmp;
   int i_tag,j_tag;
   int kp1,kp2,kp1type;
   int iij,iik,ijk,ikkp,ji,iikp,ijkp;
   int nkp;
   int nk0;
   int jNeik,kNeii,kNeij;
   int new1,new2,nlocal;
   int inum,*ilist,*iilist,*jlist,*klist;
-  int **firstneigh,*numneigh; 
+  int **firstneigh,*numneigh;
   int temp_ij,temp_ik,temp_jkp,temp_kk,temp_jk;
   int temp_ji,temp_kkp;
   int temp_kpk;
   int nb_ij,nb_ik,nb_ikp;
   int nb_jk,nb_jkp,nb_kkp;
   int kp_nsearch,nsearch;
   int sig_flag,setting,ncmp,ks;
   int itype,jtype,ktype,kptype;
   int bt_i,bt_j,bt_ij;
   int kp_index,same_ikp,same_jkp,same_kpk;
   double AA,BB,CC,DD,EE,EE1,FF;
   double AAC,BBC,CCC,DDC,EEC,FFC,GGC;
   double AACFF,UT,bndtmp,UTcom;
   double amean,gmean0,gmean1,gmean2,ps;
   double gfactor1,gprime1,gsqprime,factorsq;
   double gfactorsq,gfactor2,gprime2;
   double gfactorsq2,gsqprime2;
   double gfactor3,gprime3,gfactor,rfactor;
   double drfactor,gfactor4,gprime4,agpdpr3;
   double rfactor0,rfactorrt,rfactor1rt,rfactor1;
   double rcm1,rcm2,gcm1,gcm2,gcm3;
   double agpdpr1,agpdpr2,app1,app2,app3,app4;
   double dsigB1,dsigB2;
   double part0,part1,part2,part3,part4;
   double psign,bndtmp0,pp1;
   double bndtmp1,bndtmp2;
   double dis_ij[3],rsq_ij,r_ij;
   double betaS_ij,dBetaS_ij;
   double betaP_ij,dBetaP_ij;
   double dis_ik[3],rsq_ik,r_ik;
   double betaS_ik,dBetaS_ik;
   double betaP_ik,dBetaP_ik;
   double dis_ikp[3],rsq_ikp,r_ikp;
   double betaS_ikp,dBetaS_ikp;
   double betaP_ikp,dBetaP_ikp;
   double dis_jk[3],rsq_jk,r_jk;
   double betaS_jk,dBetaS_jk;
   double betaP_jk,dBetaP_jk;
   double dis_jkp[3],rsq_jkp,r_jkp;
   double betaS_jkp,dBetaS_jkp;
   double betaP_jkp,dBetaP_jkp;
   double dis_kkp[3],rsq_kkp,r_kkp;
   double betaS_kkp,dBetaS_kkp;
   double betaP_kkp,dBetaP_kkp;
   double cosAng_jik,dcA_jik[3][2];
   double cosAng_jikp,dcA_jikp[3][2];
   double cosAng_kikp,dcA_kikp[3][2];
   double cosAng_ijk,dcA_ijk[3][2];
   double cosAng_ijkp,dcA_ijkp[3][2];
   double cosAng_kjkp,dcA_kjkp[3][2];
   double cosAng_ikj,dcA_ikj[3][2];
   double cosAng_ikkp,dcA_ikkp[3][2];
   double cosAng_jkkp,dcA_jkkp[3][2];
   double cosAng_jkpk,dcA_jkpk[3][2];
- 
- 
+
+
   double ftmp[3],xtmp[3];
   double **x = atom->x;
   double **f = atom->f;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
   int *type = atom->type;
 
   nlocal = atom->nlocal;
   int nall = nlocal + atom->nghost;
-  inum = list->inum; 
+  inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   n=0;
   if(nb_sg==0) {
     nb_sg=4;
   }
   if(allocate_sigma) {
     destroy_sigma();
   }
     create_sigma(nb_sg);
   for(itmp=0;itmp<inum;itmp++) {
- 
+
     i = ilist[itmp];
-    i_tag=tag[i];  
+    i_tag=tag[i];
     itype = map[type[i]]+1;
 
 //j is loop over all neighbors of i
- 
+
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       for(m=0;m<nb_sg;m++) {
         for(pp=0;pp<3;pp++) {
           bt_sg[m].dAA[pp]=0.0;
           bt_sg[m].dBB[pp]=0.0;
           bt_sg[m].dEE1[pp]=0.0;
           bt_sg[m].dFF[pp]=0.0;
           bt_sg[m].dAAC[pp]=0.0;
           bt_sg[m].dSigB1[pp]=0.0;
           bt_sg[m].dSigB[pp]=0.0;
         }
         bt_sg[m].i=-1;
         bt_sg[m].j=-1;
       }
       nb_t=0;
       iilist=firstneigh[i];
       temp_ij=BOP_index[i]+jtmp;
       j=iilist[jtmp];
       jlist=firstneigh[j];
       j_tag=tag[j];
       jtype = map[type[j]]+1;
       nb_ij=nb_t;
       nb_t++;
       if(nb_t>nb_sg) {
         new_n_tot=nb_sg+maxneigh;
         grow_sigma(nb_sg,new_n_tot);
         nb_sg=new_n_tot;
       }
       bt_sg[nb_ij].temp=temp_ij;
       bt_sg[nb_ij].i=i;
       bt_sg[nb_ij].j=j;
       if(j_tag>=i_tag) {
         if(itype==jtype)
           iij=itype-1;
         else if(itype<jtype)
           iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
         else
           iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
         for(ji=0;ji<numneigh[j];ji++) {
           temp_ji=BOP_index[j]+ji;
           if(x[jlist[ji]][0]==x[i][0]) {
             if(x[jlist[ji]][1]==x[i][1]) {
               if(x[jlist[ji]][2]==x[i][2]) {
                 break;
               }
             }
           }
         }
-        dis_ij[0]=x[j][0]-x[i][0]; 
-        dis_ij[1]=x[j][1]-x[i][1]; 
-        dis_ij[2]=x[j][2]-x[i][2]; 
+        dis_ij[0]=x[j][0]-x[i][0];
+        dis_ij[1]=x[j][1]-x[i][1];
+        dis_ij[2]=x[j][2]-x[i][2];
         rsq_ij=dis_ij[0]*dis_ij[0]
             +dis_ij[1]*dis_ij[1]
             +dis_ij[2]*dis_ij[2];
-        r_ij=sqrt(rsq_ij); 
- 
+        r_ij=sqrt(rsq_ij);
+
         if(r_ij<rcut[iij]) {
- 
+
           ps=r_ij*rdr[iij]+1.0;
           ks=(int)ps;
           if(nr-1<ks)
             ks=nr-1;
           ps=ps-ks;
           if(ps>1.0)
             ps=1.0;
           betaS_ij=((pBetaS3[iij][ks-1]*ps+pBetaS2[iij][ks-1])*ps
               +pBetaS1[iij][ks-1])*ps+pBetaS[iij][ks-1];
           dBetaS_ij=(pBetaS6[iij][ks-1]*ps+pBetaS5[iij][ks-1])*ps
               +pBetaS4[iij][ks-1];
           betaP_ij=((pBetaP3[iij][ks-1]*ps+pBetaP2[iij][ks-1])*ps
               +pBetaP1[iij][ks-1])*ps+pBetaP[iij][ks-1];
           dBetaP_ij=(pBetaP6[iij][ks-1]*ps+pBetaP5[iij][ks-1])*ps
               +pBetaP4[iij][ks-1];
           nSigBk[n]=0;
- 
+
 //AA-EE1 are the components making up Eq. 30 (a)
- 
+
           AA=0.0;
           BB=0.0;
           CC=0.0;
           DD=0.0;
           EE=0.0;
           EE1=0.0;
- 
+
 //FF is the Beta_sigma^2 term
-       
+
           FF=betaS_ij*betaS_ij;
- 
+
 //agpdpr1 is derivative of FF w.r.t. r_ij
- 
+
           agpdpr1=2.0*betaS_ij*dBetaS_ij/r_ij;
- 
+
 //dXX derivatives are taken with respect to all pairs contributing to the energy
 //nb_ij is derivative w.r.t. ij pair
- 
+
           bt_sg[nb_ij].dFF[0]=agpdpr1*dis_ij[0];
           bt_sg[nb_ij].dFF[1]=agpdpr1*dis_ij[1];
           bt_sg[nb_ij].dFF[2]=agpdpr1*dis_ij[2];
- 
-//k is loop over all neighbors of i again with j neighbor of i 
- 
+
+//k is loop over all neighbors of i again with j neighbor of i
+
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
             temp_ik=BOP_index[i]+ktmp;
             if(ktmp!=jtmp) {
               k=iilist[ktmp];
               klist=firstneigh[k];
               ktype = map[type[k]]+1;
               if(itype==ktype)
                 iik=itype-1;
               else if(itype<ktype)
                 iik=itype*bop_types-itype*(itype+1)/2+ktype-1;
               else
                 iik=ktype*bop_types-ktype*(ktype+1)/2+itype-1;
-  
+
 //find neighbor of k that is equal to i
- 
+
               for(kNeii=0;kNeii<numneigh[k];kNeii++) {
                 if(x[klist[kNeii]][0]==x[i][0]) {
                   if(x[klist[kNeii]][1]==x[i][1]) {
                     if(x[klist[kNeii]][2]==x[i][2]) {
                       break;
                     }
                   }
                 }
               }
-              dis_ik[0]=x[k][0]-x[i][0]; 
-              dis_ik[1]=x[k][1]-x[i][1]; 
-              dis_ik[2]=x[k][2]-x[i][2]; 
+              dis_ik[0]=x[k][0]-x[i][0];
+              dis_ik[1]=x[k][1]-x[i][1];
+              dis_ik[2]=x[k][2]-x[i][2];
               rsq_ik=dis_ik[0]*dis_ik[0]
                   +dis_ik[1]*dis_ik[1]
                   +dis_ik[2]*dis_ik[2];
-              r_ik=sqrt(rsq_ik); 
+              r_ik=sqrt(rsq_ik);
               if(r_ik<=rcut[iik]) {
                 ps=r_ik*rdr[iik]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_ik=((pBetaS3[iik][ks-1]*ps+pBetaS2[iik][ks-1])*ps
                     +pBetaS1[iik][ks-1])*ps+pBetaS[iik][ks-1];
                 dBetaS_ik=(pBetaS6[iik][ks-1]*ps+pBetaS5[iik][ks-1])*ps
                     +pBetaS4[iik][ks-1];
                 betaP_ik=((pBetaP3[iik][ks-1]*ps+pBetaP2[iik][ks-1])*ps
                     +pBetaP1[iik][ks-1])*ps+pBetaP[iik][ks-1];
                 dBetaP_ik=(pBetaP6[iik][ks-1]*ps+pBetaP5[iik][ks-1])*ps
                     +pBetaP4[iik][ks-1];
- 
+
 //find neighbor of i that is equal to k
- 
+
                 for(jNeik=0;jNeik<numneigh[j];jNeik++) {
                   temp_jk=BOP_index[j]+jNeik;
                   if(x[jlist[jNeik]][0]==x[k][0]) {
                     if(x[jlist[jNeik]][1]==x[k][1]) {
                       if(x[jlist[jNeik]][2]==x[k][2]) {
                         break;
                       }
                     }
                   }
                 }
- 
+
 //find neighbor of k that is equal to j
- 
+
                 for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                   if(x[klist[kNeij]][0]==x[j][0]) {
                     if(x[klist[kNeij]][1]==x[j][1]) {
                       if(x[klist[kNeij]][2]==x[j][2]) {
                         break;
                       }
                     }
                   }
                 }
-                dis_jk[0]=x[k][0]-x[j][0]; 
-                dis_jk[1]=x[k][1]-x[j][1]; 
-                dis_jk[2]=x[k][2]-x[j][2]; 
+                dis_jk[0]=x[k][0]-x[j][0];
+                dis_jk[1]=x[k][1]-x[j][1];
+                dis_jk[2]=x[k][2]-x[j][2];
                 rsq_jk=dis_jk[0]*dis_jk[0]
                     +dis_jk[1]*dis_jk[1]
                     +dis_jk[2]*dis_jk[2];
-                r_jk=sqrt(rsq_jk); 
- 
+                r_jk=sqrt(rsq_jk);
+
                 sig_flag=0;
                 for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                   ncmp=itypeSigBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         nk0=nsearch;
                         sig_flag=1;
                         break;
                       }
                     }
                   }
                 }
                 if(sig_flag==0) {
                   nSigBk[n]=nSigBk[n]+1;
                   nk0=nSigBk[n]-1;
                   itypeSigBk[n][nk0]=k;
                 }
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_ik].temp=temp_ik;
                 bt_sg[nb_ik].i=i;
                 bt_sg[nb_ik].j=k;
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 cosAng_jik=(dis_ij[0]*dis_ik[0]+dis_ij[1]*dis_ik[1]
-                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik); 
+                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik);
                 dcA_jik[0][0]=(dis_ik[0]*r_ij*r_ik-cosAng_jik
                     *dis_ij[0]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][0]=(dis_ik[1]*r_ij*r_ik-cosAng_jik
                     *dis_ij[1]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][0]=(dis_ik[2]*r_ij*r_ik-cosAng_jik
                     *dis_ij[2]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[0][1]=(dis_ij[0]*r_ij*r_ik-cosAng_jik
                     *dis_ik[0]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][1]=(dis_ij[1]*r_ij*r_ik-cosAng_jik
                     *dis_ik[1]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][1]=(dis_ij[2]*r_ij*r_ik-cosAng_jik
                     *dis_ik[2]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 gmean0=sigma_g0[jtype-1][itype-1][ktype-1];
                 gmean1=sigma_g1[jtype-1][itype-1][ktype-1];
                 gmean2=sigma_g2[jtype-1][itype-1][ktype-1];
                 amean=cosAng_jik;
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gsqprime=2.0*gfactor1*gprime1;
- 
+
 //AA is Eq. 34 (a) or Eq. 10 (c) for the i atom
 //1st CC is Eq. 11 (c) for i atom where j & k=neighbor of i
- 
+
                 AA=AA+gfactorsq*betaS_ik*betaS_ik;
                 CC=CC+gfactorsq*betaS_ik*betaS_ik*betaS_ik*betaS_ik;
- 
+
 //agpdpr1 is derivative of AA w.r.t. Beta(rik)
 //app1 is derivative of AA w.r.t. cos(theta_jik)
- 
+
                 agpdpr1=2.0*gfactorsq*betaS_ik*dBetaS_ik/r_ik;
                 app1=betaS_ik*betaS_ik*gsqprime;
                 bt_sg[nb_ij].dAA[0]+=
                     app1*dcA_jik[0][0];
                 bt_sg[nb_ij].dAA[1]+=
                     app1*dcA_jik[1][0];
                 bt_sg[nb_ij].dAA[2]+=
                     app1*dcA_jik[2][0];
                 bt_sg[nb_ik].dAA[0]+=
                     app1*dcA_jik[0][1]
                     +agpdpr1*dis_ik[0];
                 bt_sg[nb_ik].dAA[1]+=
                     app1*dcA_jik[1][1]
                     +agpdpr1*dis_ik[1];
                 bt_sg[nb_ik].dAA[2]+=
                     app1*dcA_jik[2][1]
                     +agpdpr1*dis_ik[2];
- 
+
 //k' is loop over neighbors all neighbors of j with k a neighbor
-//of i and j a neighbor of i and determine which k' is k 
-                
-                same_kpk=0; 
+//of i and j a neighbor of i and determine which k' is k
+
+                same_kpk=0;
                 for(ltmp=0;ltmp<numneigh[j];ltmp++) {
                   temp_jkp=BOP_index[j]+ltmp;
                   kp1=jlist[ltmp];
                   kp1type=map[type[kp1]]+1;
                   if(x[kp1][0]==x[k][0]) {
                     if(x[kp1][1]==x[k][1]) {
                       if(x[kp1][2]==x[k][2]) {
                         same_kpk=1;
                         break;
                       }
                     }
                   }
                 }
                 if(same_kpk){
- 
+
 //loop over neighbors of k
- 
+
                   for(mtmp=0;mtmp<numneigh[k];mtmp++) {
                     kp2=klist[mtmp];
                     if(x[kp2][0]==x[k][0]) {
                       if(x[kp2][1]==x[k][1]) {
                         if(x[kp2][2]==x[k][2]) {
                           break;
                         }
                       }
                     }
                   }
                   if(jtype==ktype)
                     ijk=jtype-1;
                   else if(jtype < ktype)
                     ijk=jtype*bop_types-jtype*(jtype+1)/2+ktype-1;
                   else
                     ijk=ktype*bop_types-ktype*(ktype+1)/2+jtype-1;
                   if(jtype==kp1type)
                     ijkp=jtype-1;
                   else if(jtype<kp1type)
                     ijkp=jtype*bop_types-jtype*(jtype+1)/2+kp1type-1;
                   else
                     ijkp=kp1type*bop_types-kp1type*(kp1type+1)/2+jtype-1;
- 
-                  dis_jkp[0]=x[kp1][0]-x[j][0]; 
-                  dis_jkp[1]=x[kp1][1]-x[j][1]; 
-                  dis_jkp[2]=x[kp1][2]-x[j][2]; 
+
+                  dis_jkp[0]=x[kp1][0]-x[j][0];
+                  dis_jkp[1]=x[kp1][1]-x[j][1];
+                  dis_jkp[2]=x[kp1][2]-x[j][2];
                   rsq_jkp=dis_jkp[0]*dis_jkp[0]
                       +dis_jkp[1]*dis_jkp[1]
                       +dis_jkp[2]*dis_jkp[2];
-                  r_jkp=sqrt(rsq_jkp); 
+                  r_jkp=sqrt(rsq_jkp);
                   if(r_jkp<=rcut[ijkp]) {
                     ps=r_jkp*rdr[ijkp]+1.0;
                     ks=(int)ps;
                     if(nr-1<ks)
                       ks=nr-1;
                     ps=ps-ks;
                     if(ps>1.0)
                       ps=1.0;
                     betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                         +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                     dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                         +pBetaS4[ijkp][ks-1];
                     betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                         +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                     dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                         +pBetaP4[ijkp][ks-1];
                     cosAng_ijk=(-dis_ij[0]*dis_jk[0]-dis_ij[1]*dis_jk[1]
-                        -dis_ij[2]*dis_jk[2])/(r_ij*r_jk); 
+                        -dis_ij[2]*dis_jk[2])/(r_ij*r_jk);
                     dcA_ijk[0][0]=(dis_jk[0]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[0]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[1][0]=(dis_jk[1]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[1]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[2][0]=(dis_jk[2]*r_ij*r_jk-cosAng_ijk
                         *-dis_ij[2]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[0][1]=(-dis_ij[0]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[0]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[1][1]=(-dis_ij[1]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[1]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     dcA_ijk[2][1]=(-dis_ij[2]*r_ij*r_jk-cosAng_ijk
                         *dis_jk[2]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                     gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                     gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                     gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                     amean=cosAng_ijk;
                     gfactor2=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                     gprime2=gmean1+2.0*gmean2*amean;
                     gmean0=sigma_g0[itype-1][ktype-1][jtype-1];
                     gmean1=sigma_g1[itype-1][ktype-1][jtype-1];
                     gmean2=sigma_g2[itype-1][ktype-1][jtype-1];
                     cosAng_ikj=(dis_ik[0]*dis_jk[0]+dis_ik[1]*dis_jk[1]
-                        +dis_ik[2]*dis_jk[2])/(r_ik*r_jk); 
+                        +dis_ik[2]*dis_jk[2])/(r_ik*r_jk);
                     dcA_ikj[0][0]=(-dis_jk[0]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[0]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[1][0]=(-dis_jk[1]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[1]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[2][0]=(-dis_jk[2]*r_ik*r_jk-cosAng_ikj
                         *-dis_ik[2]*r_jk*r_jk)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[0][1]=(-dis_ik[0]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[0]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[1][1]=(-dis_ik[1]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[1]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     dcA_ikj[2][1]=(-dis_ik[2]*r_ik*r_jk-cosAng_ikj
                         *-dis_jk[2]*r_ik*r_ik)/(r_ik*r_ik*r_jk*r_jk);
                     amean=cosAng_ikj;
                     gfactor3=gmean0+gmean1*amean
                         +gmean2*amean*amean;
                     gprime3=gmean1+2.0*gmean2*amean;
                     gfactor=gfactor1*gfactor2*gfactor3;
                     rfactor=betaS_ik*betaS_jkp;
- 
+
 //EE1 is (b) Eq. 12
- 
+
                     EE1=EE1+gfactor*rfactor;
- 
+
 //rcm1 is derivative of EE1 w.r.t Beta(r_ik)
 //rcm2 is derivative of EE1 w.r.t Beta(r_jk')
 //gcm1 is derivative of EE1 w.r.t cos(theta_jik)
 //gcm2 is derivative of EE1 w.r.t cos(theta_ijk)
 //gcm3 is derivative of EE1 w.r.t cos(theta_ikj)
- 
+
                     rcm1=gfactor*betaS_jkp*dBetaS_ik/r_ik;
                     rcm2=gfactor*betaS_ik*dBetaS_jkp/r_jkp;
                     gcm1=rfactor*gprime1*gfactor2*gfactor3;
                     gcm2=rfactor*gfactor1*gprime2*gfactor3;
                     gcm3=rfactor*gfactor1*gfactor2*gprime3;
                     bt_sg[nb_ij].dEE1[0]+=
                         gcm1*dcA_jik[0][0]
                         -gcm2*dcA_ijk[0][0];
                     bt_sg[nb_ij].dEE1[1]+=
                         gcm1*dcA_jik[1][0]
                         -gcm2*dcA_ijk[1][0];
                     bt_sg[nb_ij].dEE1[2]+=
                         gcm1*dcA_jik[2][0]
                         -gcm2*dcA_ijk[2][0];
                     bt_sg[nb_ik].dEE1[0]+=
                         gcm1*dcA_jik[0][1]
                         +rcm1*dis_ik[0]
                         -gcm3*dcA_ikj[0][0];
                     bt_sg[nb_ik].dEE1[1]+=
                         gcm1*dcA_jik[1][1]
                         +rcm1*dis_ik[1]
                         -gcm3*dcA_ikj[1][0];
                     bt_sg[nb_ik].dEE1[2]+=
                         gcm1*dcA_jik[2][1]
                         +rcm1*dis_ik[2]
                         -gcm3*dcA_ikj[2][0];
                     bt_sg[nb_jk].dEE1[0]+=
                         gcm2*dcA_ijk[0][1]
                         +rcm2*dis_jkp[0]
                         -gcm3*dcA_ikj[0][1];
                     bt_sg[nb_jk].dEE1[1]+=
                         gcm2*dcA_ijk[1][1]
                         +rcm2*dis_jkp[1]
                         -gcm3*dcA_ikj[1][1];
                     bt_sg[nb_jk].dEE1[2]+=
                         gcm2*dcA_ijk[2][1]
                         +rcm2*dis_jkp[2]
                         -gcm3*dcA_ikj[2][1];
                   }
                 }
- 
+
 // k and k' and j are all different neighbors of i
- 
+
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     kp=iilist[ltmp];;
                     kptype = map[type[kp]]+1;
                     if(itype==kptype)
                       iikp=itype-1;
                     else if(itype<kptype)
                       iikp=itype*bop_types-itype*(itype+1)/2+kptype-1;
                     else
                       iikp=kptype*bop_types-kptype*(kptype+1)/2+itype-1;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             break;
                           }
                         }
                       }
                     }
-                    dis_ikp[0]=x[kp][0]-x[i][0]; 
-                    dis_ikp[1]=x[kp][1]-x[i][1]; 
-                    dis_ikp[2]=x[kp][2]-x[i][2]; 
+                    dis_ikp[0]=x[kp][0]-x[i][0];
+                    dis_ikp[1]=x[kp][1]-x[i][1];
+                    dis_ikp[2]=x[kp][2]-x[i][2];
                     rsq_ikp=dis_ikp[0]*dis_ikp[0]
                         +dis_ikp[1]*dis_ikp[1]
                         +dis_ikp[2]*dis_ikp[2];
-                    r_ikp=sqrt(rsq_ikp); 
+                    r_ikp=sqrt(rsq_ikp);
                     if(r_ikp<=rcut[iikp]) {
                       ps=r_ikp*rdr[iikp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_ikp=((pBetaS3[iikp][ks-1]*ps+pBetaS2[iikp][ks-1])*ps
                           +pBetaS1[iikp][ks-1])*ps+pBetaS[iikp][ks-1];
                       dBetaS_ikp=(pBetaS6[iikp][ks-1]*ps+pBetaS5[iikp][ks-1])*ps
                           +pBetaS4[iikp][ks-1];
                       betaP_ikp=((pBetaP3[iikp][ks-1]*ps+pBetaP2[iikp][ks-1])*ps
                           +pBetaP1[iikp][ks-1])*ps+pBetaP[iikp][ks-1];
                       dBetaP_ikp=(pBetaP6[iikp][ks-1]*ps+pBetaP5[iikp][ks-1])*ps
                           +pBetaP4[iikp][ks-1];
                       gmean0=sigma_g0[jtype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][itype-1][kptype-1];
                       cosAng_jikp=(dis_ij[0]*dis_ikp[0]+dis_ij[1]*dis_ikp[1]
-                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp); 
+                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp);
                       cosAng_kikp=(dis_ik[0]*dis_ikp[0]+dis_ik[1]*dis_ikp[1]
-                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp); 
+                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp);
                       amean=cosAng_jikp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][itype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][itype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][itype-1][kptype-1];
                       amean=cosAng_kikp;
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS_ik*betaS_ikp;
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //2nd CC is second term of Eq. 11 (c) for i atom where j , k & k' =neighbor of i
- 
+
                       CC=CC+2.0*gfactor*rfactor;
                     }
                   }
                 }
- 
+
 // j and k are different neighbors of i and k' is a neighbor k not equal to i
- 
+
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   kp=klist[ltmp];;
                   kptype = map[type[kp]]+1;
                   same_ikp=0;
                   same_jkp=0;
                   if(x[i][0]==x[kp][0]) {
                     if(x[i][1]==x[kp][1]) {
                       if(x[i][2]==x[kp][2]) {
                         same_ikp=1;
                       }
                     }
                   }
                   if(x[j][0]==x[kp][0]) {
                     if(x[j][1]==x[kp][1]) {
                       if(x[j][2]==x[kp][2]) {
                         same_jkp=1;
                       }
                     }
                   }
                   if(!same_ikp&&!same_jkp) {
                     if(ktype==kptype)
                       ikkp=ktype-1;
                     else if(ktype<kptype)
                       ikkp=ktype*bop_types-ktype*(ktype+1)/2+kptype-1;
                     else
                       ikkp=kptype*bop_types-kptype*(kptype+1)/2+ktype-1;
-                    dis_kkp[0]=x[kp][0]-x[k][0]; 
-                    dis_kkp[1]=x[kp][1]-x[k][1]; 
-                    dis_kkp[2]=x[kp][2]-x[k][2]; 
+                    dis_kkp[0]=x[kp][0]-x[k][0];
+                    dis_kkp[1]=x[kp][1]-x[k][1];
+                    dis_kkp[2]=x[kp][2]-x[k][2];
                     rsq_kkp=dis_kkp[0]*dis_kkp[0]
                         +dis_kkp[1]*dis_kkp[1]
                         +dis_kkp[2]*dis_kkp[2];
-                    r_kkp=sqrt(rsq_kkp); 
+                    r_kkp=sqrt(rsq_kkp);
                     if(r_kkp<=rcut[ikkp]) {
                       ps=r_kkp*rdr[ikkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_kkp=((pBetaS3[ikkp][ks-1]*ps+pBetaS2[ikkp][ks-1])*ps
                           +pBetaS1[ikkp][ks-1])*ps+pBetaS[ikkp][ks-1];
                       dBetaS_kkp=(pBetaS6[ikkp][ks-1]*ps+pBetaS5[ikkp][ks-1])*ps
                           +pBetaS4[ikkp][ks-1];
                       betaP_kkp=((pBetaP3[ikkp][ks-1]*ps+pBetaP2[ikkp][ks-1])*ps
                           +pBetaP1[ikkp][ks-1])*ps+pBetaP[ikkp][ks-1];
                       dBetaP_kkp=(pBetaP6[ikkp][ks-1]*ps+pBetaP5[ikkp][ks-1])*ps
                           +pBetaP4[ikkp][ks-1];
                       sig_flag=0;
                       for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                         ncmp=itypeSigBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               sig_flag=1;
                               nkp=nsearch;
                               break;
                             }
                           }
                         }
                       }
                       if(sig_flag==0) {
                         nSigBk[n]=nSigBk[n]+1;
                         nkp=nSigBk[n]-1;
                         itypeSigBk[n][nkp]=kp;
                       }
                       cosAng_ikkp=(-dis_ik[0]*dis_kkp[0]-dis_ik[1]*dis_kkp[1]
-                          -dis_ik[2]*dis_kkp[2])/(r_ik*r_kkp); 
-                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];          
-                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];          
-                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];          
+                          -dis_ik[2]*dis_kkp[2])/(r_ik*r_kkp);
+                      gmean0=sigma_g0[itype-1][ktype-1][kptype-1];
+                      gmean1=sigma_g1[itype-1][ktype-1][kptype-1];
+                      gmean2=sigma_g2[itype-1][ktype-1][kptype-1];
                       amean=cosAng_ikkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS_ik*betaS_kkp;
                       rfactor=rfactorrt*rfactorrt;
- 
-//3rd CC is third term of Eq. 11 (c) for i atom 
+
+//3rd CC is third term of Eq. 11 (c) for i atom
 //where j , k =neighbor of i & k' =neighbor of k
- 
+
                       CC=CC+gfactor*rfactor;
                     }
                   }
                 }
               }
             }
           }
-        
+
 //j is a neighbor of i and k is a neighbor of j not equal to i
- 
+
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ji) {
               temp_jk=BOP_index[j]+ktmp;
               k=jlist[ktmp];
               klist=firstneigh[k];
               ktype=map[type[k]]+1;
               for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                 if(x[klist[kNeij]][0]==x[j][0]) {
                   if(x[klist[kNeij]][1]==x[j][1]) {
                     if(x[klist[kNeij]][2]==x[j][2]) {
                       break;
                     }
                   }
                 }
               }
               if(jtype==ktype)
                 ijk=jtype-1;
               else if(jtype<ktype)
                 ijk=jtype*bop_types-jtype*(jtype+1)/2+ktype-1;
               else
                 ijk=ktype*bop_types-ktype*(ktype+1)/2+jtype-1;
               sig_flag=0;
               for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                 ncmp=itypeSigBk[n][nsearch];
                 if(x[ncmp][0]==x[k][0]) {
                   if(x[ncmp][1]==x[k][1]) {
                     if(x[ncmp][2]==x[k][2]) {
                       new1=nsearch;
                       sig_flag=1;
                       break;
                     }
                   }
                 }
               }
               if(sig_flag==0) {
                 nSigBk[n]=nSigBk[n]+1;
                 new1=nSigBk[n]-1;
                 itypeSigBk[n][new1]=k;
               }
-              dis_jk[0]=x[k][0]-x[j][0]; 
-              dis_jk[1]=x[k][1]-x[j][1]; 
-              dis_jk[2]=x[k][2]-x[j][2]; 
+              dis_jk[0]=x[k][0]-x[j][0];
+              dis_jk[1]=x[k][1]-x[j][1];
+              dis_jk[2]=x[k][2]-x[j][2];
               rsq_jk=dis_jk[0]*dis_jk[0]
                   +dis_jk[1]*dis_jk[1]
                   +dis_jk[2]*dis_jk[2];
-              r_jk=sqrt(rsq_jk); 
+              r_jk=sqrt(rsq_jk);
               if(r_jk<=rcut[ijk]) {
                 ps=r_jk*rdr[ijk]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_jk=((pBetaS3[ijk][ks-1]*ps+pBetaS2[ijk][ks-1])*ps
                     +pBetaS1[ijk][ks-1])*ps+pBetaS[ijk][ks-1];
                 dBetaS_jk=(pBetaS6[ijk][ks-1]*ps+pBetaS5[ijk][ks-1])*ps
                     +pBetaS4[ijk][ks-1];
                 betaP_jk=((pBetaP3[ijk][ks-1]*ps+pBetaP2[ijk][ks-1])*ps
                     +pBetaP1[ijk][ks-1])*ps+pBetaP[ijk][ks-1];
                 dBetaP_jk=(pBetaP6[ijk][ks-1]*ps+pBetaP5[ijk][ks-1])*ps
                     +pBetaP4[ijk][ks-1];
                 cosAng_ijk=(-dis_ij[0]*dis_jk[0]-dis_ij[1]*dis_jk[1]
-                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk); 
+                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk);
                 dcA_ijk[0][0]=(dis_jk[0]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[0]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][0]=(dis_jk[1]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[1]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][0]=(dis_jk[2]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[2]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[0][1]=(-dis_ij[0]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[0]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][1]=(-dis_ij[1]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[1]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][1]=(-dis_ij[2]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[2]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_sg) {
                   new_n_tot=nb_sg+maxneigh;
                   grow_sigma(nb_sg,new_n_tot);
                   nb_sg=new_n_tot;
                 }
                 bt_sg[nb_jk].temp=temp_jk;
                 bt_sg[nb_jk].i=j;
                 bt_sg[nb_jk].j=k;
                 gmean0=sigma_g0[itype-1][jtype-1][ktype-1];
                 gmean1=sigma_g1[itype-1][jtype-1][ktype-1];
                 gmean2=sigma_g2[itype-1][jtype-1][ktype-1];
                 amean=cosAng_ijk;
                 gfactor1=gmean0+gmean1*amean
                     +gmean2*amean*amean;
                 gprime1=gmean1+2.0*gmean2*amean;
                 gfactorsq=gfactor1*gfactor1;
                 gsqprime=2.0*gfactor1*gprime1;
                 rfactor1rt=betaS_jk*betaS_jk;
                 rfactor1=rfactor1rt*rfactor1rt;
- 
+
 //BB is Eq. 34 (a) or Eq. 10 (c) for the j atom
 //1st DD is Eq. 11 (c) for j atom where i & k=neighbor of j
- 
+
                 BB=BB+gfactorsq*rfactor1rt;
                 DD=DD+gfactorsq*rfactor1;
- 
+
 //agpdpr1 is derivative of BB  w.r.t. Beta(r_jk)
 //app1 is derivative of BB w.r.t. cos(theta_ijk)
- 
+
                 agpdpr1=2.0*gfactorsq*betaS_jk*dBetaS_jk/r_jk;
                 app1=rfactor1rt*gsqprime;
                 bt_sg[nb_ij].dBB[0]-=
                     app1*dcA_ijk[0][0];
                 bt_sg[nb_ij].dBB[1]-=
                     app1*dcA_ijk[1][0];
                 bt_sg[nb_ij].dBB[2]-=
                     app1*dcA_ijk[2][0];
                 bt_sg[nb_jk].dBB[0]+=
                     app1*dcA_ijk[0][1]
                     +agpdpr1*dis_jk[0];
                 bt_sg[nb_jk].dBB[1]+=
                     app1*dcA_ijk[1][1]
                     +agpdpr1*dis_jk[1];
                 bt_sg[nb_jk].dBB[2]+=
                     app1*dcA_ijk[2][1]
                     +agpdpr1*dis_jk[2];
- 
+
 //j is a neighbor of i, k and k' prime different neighbors of j not equal to i
- 
+
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ji) {
                     temp_jkp=BOP_index[j]+ltmp;
                     kp=jlist[ltmp];
                     kptype=map[type[kp]]+1;
                     if(jtype==kptype)
                       ijkp=jtype-1;
                     else if(jtype<kptype)
                       ijkp=jtype*bop_types-jtype*(jtype+1)/2+kptype-1;
                     else
                       ijkp=kptype*bop_types-kptype*(kptype+1)/2+jtype-1;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             new2=nsearch;
                             break;
                           }
                         }
                       }
                     }
-                    dis_jkp[0]=x[kp][0]-x[j][0]; 
-                    dis_jkp[1]=x[kp][1]-x[j][1]; 
-                    dis_jkp[2]=x[kp][2]-x[j][2]; 
+                    dis_jkp[0]=x[kp][0]-x[j][0];
+                    dis_jkp[1]=x[kp][1]-x[j][1];
+                    dis_jkp[2]=x[kp][2]-x[j][2];
                     rsq_jkp=dis_jkp[0]*dis_jkp[0]
                         +dis_jkp[1]*dis_jkp[1]
                         +dis_jkp[2]*dis_jkp[2];
-                    r_jkp=sqrt(rsq_jkp); 
+                    r_jkp=sqrt(rsq_jkp);
                     if(r_jkp<=rcut[ijkp]) {
                       ps=r_jkp*rdr[ijkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                         +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                       dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                         +pBetaS4[ijkp][ks-1];
                       betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                         +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                       dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                         +pBetaP4[ijkp][ks-1];
                       cosAng_ijkp=(-dis_ij[0]*dis_jkp[0]-dis_ij[1]*dis_jkp[1]
-                        -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp); 
+                        -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp);
                       dcA_ijkp[0][0]=(dis_jkp[0]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[0]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][0]=(dis_jkp[1]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[1]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][0]=(dis_jkp[2]*r_ij*r_jkp-cosAng_ijkp
                         *-dis_ij[2]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[0][1]=(-dis_ij[0]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[0]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][1]=(-dis_ij[1]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[1]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][1]=(-dis_ij[2]*r_ij*r_jkp-cosAng_ijkp
                         *dis_jkp[2]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       cosAng_kjkp=(dis_jk[0]*dis_jkp[0]+dis_jk[1]*dis_jkp[1]
-                        +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp); 
+                        +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp);
                       dcA_kjkp[0][0]=(dis_jkp[0]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[0]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][0]=(dis_jkp[1]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[1]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][0]=(dis_jkp[2]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jk[2]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[0][1]=(dis_jk[0]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[0]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][1]=(dis_jk[1]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[1]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][1]=(dis_jk[2]*r_jk*r_jkp-cosAng_kjkp
                         *dis_jkp[2]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       nb_jkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_jkp].temp=temp_jkp;
                       bt_sg[nb_jkp].i=j;
                       bt_sg[nb_jkp].j=kp;
                       gmean0=sigma_g0[itype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[itype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[itype-1][jtype-1][kptype-1];
                       amean=cosAng_ijkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gmean0=sigma_g0[ktype-1][jtype-1][kptype-1];
                       gmean1=sigma_g1[ktype-1][jtype-1][kptype-1];
                       gmean2=sigma_g2[ktype-1][jtype-1][kptype-1];
                       amean=cosAng_kjkp;
                       gfactor3=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime3=gmean1+2.0*gmean2*amean;
                       gfactor=gfactor1*gfactor2*gfactor3;
                       rfactorrt=betaS_jk*betaS_jkp;
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //2nd DD is Eq. 11 (c) for j atom where i , k & k'=neighbor of j
- 
+
                       DD=DD+2.0*gfactor*rfactor;
                     }
                   }
                 }
- 
-//j is a neighbor of i, k is a neighbor of j not equal to i and k' 
+
+//j is a neighbor of i, k is a neighbor of j not equal to i and k'
 //is a neighbor of k not equal to j or i
- 
+
                 for(ltmp=0;ltmp<numneigh[k];ltmp++) {
                   temp_kkp=BOP_index[k]+ltmp;
                   kp=klist[ltmp];
                   kptype=map[type[kp]]+1;
                   same_ikp=0;
                   same_jkp=0;
                   if(x[i][0]==x[kp][0]) {
                     if(x[i][1]==x[kp][1]) {
                       if(x[i][2]==x[kp][2]) {
                         same_ikp=1;
                       }
                     }
                   }
                   if(x[j][0]==x[kp][0]) {
                     if(x[j][1]==x[kp][1]) {
                       if(x[j][2]==x[kp][2]) {
                         same_jkp=1;
                       }
                     }
                   }
                   if(!same_ikp&&!same_jkp) {
                     if(ktype==kptype)
                       ikkp=ktype-1;
                     else if(ktype<kptype)
                       ikkp=ktype*bop_types-ktype*(ktype+1)/2+kptype-1;
                     else
                       ikkp=kptype*bop_types-kptype*(kptype+1)/2+ktype-1;
                     for(kNeij=0;kNeij<numneigh[k];kNeij++) {
                       if(x[klist[kNeij]][0]==x[j][0]) {
                         if(x[klist[kNeij]][1]==x[j][1]) {
                           if(x[klist[kNeij]][2]==x[j][2]) {
                             break;
                           }
                         }
                       }
                     }
                     sig_flag=0;
                     for(nsearch=0;nsearch<nSigBk[n];nsearch++) {
                       ncmp=itypeSigBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             new2=nsearch;
                             sig_flag=1;
                             break;
                           }
                         }
                       }
                     }
                     if(sig_flag==0) {
                       nSigBk[n]=nSigBk[n]+1;
                       new2=nSigBk[n]-1;
                       itypeSigBk[n][new2]=kp;
                     }
-                    dis_kkp[0]=x[kp][0]-x[k][0]; 
-                    dis_kkp[1]=x[kp][1]-x[k][1]; 
-                    dis_kkp[2]=x[kp][2]-x[k][2]; 
+                    dis_kkp[0]=x[kp][0]-x[k][0];
+                    dis_kkp[1]=x[kp][1]-x[k][1];
+                    dis_kkp[2]=x[kp][2]-x[k][2];
                     rsq_kkp=dis_kkp[0]*dis_kkp[0]
                         +dis_kkp[1]*dis_kkp[1]
                         +dis_kkp[2]*dis_kkp[2];
-                    r_kkp=sqrt(rsq_kkp); 
+                    r_kkp=sqrt(rsq_kkp);
                     if(r_kkp<=rcut[ikkp]) {
                       ps=r_kkp*rdr[ikkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_kkp=((pBetaS3[ikkp][ks-1]*ps+pBetaS2[ikkp][ks-1])*ps
                           +pBetaS1[ikkp][ks-1])*ps+pBetaS[ikkp][ks-1];
                       dBetaS_kkp=(pBetaS6[ikkp][ks-1]*ps+pBetaS5[ikkp][ks-1])*ps
                           +pBetaS4[ikkp][ks-1];
                       betaP_kkp=((pBetaP3[ikkp][ks-1]*ps+pBetaP2[ikkp][ks-1])*ps
                           +pBetaP1[ikkp][ks-1])*ps+pBetaP[ikkp][ks-1];
                       dBetaP_kkp=(pBetaP6[ikkp][ks-1]*ps+pBetaP5[ikkp][ks-1])*ps
                           +pBetaP4[ikkp][ks-1];
                       cosAng_jkkp=(-dis_jk[0]*dis_kkp[0]-dis_jk[1]*dis_kkp[1]
-                          -dis_jk[2]*dis_kkp[2])/(r_jk*r_kkp); 
+                          -dis_jk[2]*dis_kkp[2])/(r_jk*r_kkp);
                       dcA_jkkp[0][0]=(dis_kkp[0]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[0]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[1][0]=(dis_kkp[1]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[1]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[2][0]=(dis_kkp[2]*r_jk*r_kkp-cosAng_jkkp
                           *-dis_jk[2]*r_kkp*r_kkp)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[0][1]=(-dis_jk[0]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[0]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[1][1]=(-dis_jk[1]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[1]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       dcA_jkkp[2][1]=(-dis_jk[2]*r_jk*r_kkp-cosAng_jkkp
                           *dis_kkp[2]*r_jk*r_jk)/(r_jk*r_jk*r_kkp*r_kkp);
                       nb_kkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_sg) {
                         new_n_tot=nb_sg+maxneigh;
                         grow_sigma(nb_sg,new_n_tot);
                         nb_sg=new_n_tot;
                       }
                       bt_sg[nb_kkp].temp=temp_kkp;
                       bt_sg[nb_kkp].i=k;
                       bt_sg[nb_kkp].j=kp;
                       gmean0=sigma_g0[jtype-1][ktype-1][kptype-1];
                       gmean1=sigma_g1[jtype-1][ktype-1][kptype-1];
                       gmean2=sigma_g2[jtype-1][ktype-1][kptype-1];
                       amean=cosAng_jkkp;
                       gfactor2=gmean0+gmean1*amean
                           +gmean2*amean*amean;
                       gprime2=gmean1+2.0*gmean2*amean;
                       gfactorsq2=gfactor2*gfactor2;
                       gsqprime2=2.0*gfactor2*gprime2;
                       gfactor=gfactorsq*gfactorsq2;
                       rfactorrt=betaS_jk*betaS_kkp;
                       rfactor=rfactorrt*rfactorrt;
- 
+
 //3rd DD is Eq. 11 (c) for j atom where i & k=neighbor of j & k'=neighbor of k
- 
+
                       DD=DD+gfactor*rfactor;
                     }
                   }
                 }
               }
             }
           }
- 
+
           sig_flag=0;
           if(FF<=0.000001) {
             sigB[n]=0.0;
             sig_flag=1;
           }
           if(sig_flag==0) {
             if(AA<0.0)
               AA=0.0;
             if(BB<0.0)
               BB=0.0;
             if(CC<0.0)
               CC=0.0;
             if(DD<0.0)
               DD=0.0;
- 
+
 // AA and BB are the representations of (a) Eq. 34 and (b) Eq. 9
 // for atoms i and j respectively
- 
+
             AAC=AA+BB;
             BBC=AA*BB;
             CCC=AA*AA+BB*BB;
             DDC=CC+DD;
- 
+
 //EEC is a modified form of (a) Eq. 33
- 
+
             EEC=(DDC-CCC)/(AAC+2.0*small1);
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 bt_sg[m].dAAC[0]=bt_sg[m].dAA[0]
                     +bt_sg[m].dBB[0];
                 bt_sg[m].dAAC[1]=bt_sg[m].dAA[1]
                     +bt_sg[m].dBB[1];
                 bt_sg[m].dAAC[2]=bt_sg[m].dAA[2]
                     +bt_sg[m].dBB[2];
-              } 
+              }
             }
             UT=EEC*FF+BBC+small3[iij];
             UT=1.0/sqrt(UT);
- 
+
 // FFC is slightly modified form of (a) Eq. 31
 // GGC is slightly modified form of (a) Eq. 32
 // bndtmp is a slightly modified form of (a) Eq. 30 and (b) Eq. 8
- 
+
             FFC=BBC*UT;
             GGC=EEC*UT;
             bndtmp=(FF+sigma_delta[iij]*sigma_delta[iij])
                 +sigma_c[iij]*AAC+small4;
             UTcom=-0.5*UT*UT*UT;
             psign=1.0;
             bndtmp0=1.0/sqrt(bndtmp);
             sigB1[n]=psign*betaS_ij*bndtmp0;
             bndtmp=-0.5*bndtmp0*bndtmp0*bndtmp0;
             bndtmp1=psign*bndtmp0+psign*betaS_ij
                 *bndtmp*2.0*betaS_ij;
             bndtmp1=bndtmp1*dBetaS_ij/r_ij;
             bndtmp2=psign*betaS_ij*bndtmp*sigma_c[iij];
             setting=0;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 if(temp_kk==temp_ij&&setting==0) {
                   bt_sg[m].dSigB1[0]=bndtmp1*dis_ij[0]
                       +(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=bndtmp1*dis_ij[1]
                       +(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=bndtmp1*dis_ij[2]
                       +(bndtmp2*bt_sg[m].dAAC[2]);
                   setting=1;
                 }
                 else if(temp_kk==temp_ji&&setting==0) {
                   bt_sg[m].dSigB1[0]=-bndtmp1*dis_ij[0]
                       +(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=-bndtmp1*dis_ij[1]
                       +(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=-bndtmp1*dis_ij[2]
                       +(bndtmp2*bt_sg[m].dAAC[2]);
                   setting=1;
                 }
                 else {
                   bt_sg[m].dSigB1[0]=(bndtmp2*bt_sg[m].dAAC[0]);
                   bt_sg[m].dSigB1[1]=(bndtmp2*bt_sg[m].dAAC[1]);
                   bt_sg[m].dSigB1[2]=(bndtmp2*bt_sg[m].dAAC[2]);
                 }
               }
             }
- 
+
 //This loop is to ensure there is not an error for atoms with no neighbors (deposition)
- 
+
             if(nb_t==0) {
               if(j>i) {
                 bt_sg[0].dSigB1[0]=bndtmp1*dis_ij[0];
                 bt_sg[0].dSigB1[1]=bndtmp1*dis_ij[1];
                 bt_sg[0].dSigB1[2]=bndtmp1*dis_ij[2];
               }
               else {
                 bt_sg[0].dSigB1[0]=-bndtmp1*dis_ij[0];
                 bt_sg[0].dSigB1[1]=-bndtmp1*dis_ij[1];
                 bt_sg[0].dSigB1[2]=-bndtmp1*dis_ij[2];
               }
               for(pp=0;pp<3;pp++) {
                 bt_sg[0].dAA[pp]=0.0;
                 bt_sg[0].dBB[pp]=0.0;
                 bt_sg[0].dEE1[pp]=0.0;
                 bt_sg[0].dFF[pp]=0.0;
                 bt_sg[0].dAAC[pp]=0.0;
                 bt_sg[0].dSigB[pp]=0.0;
               }
               bt_sg[0].i=i;
               bt_sg[0].j=j;
               bt_sg[0].temp=temp_ij;
               nb_t++;
               if(nb_t>nb_sg) {
                 new_n_tot=nb_sg+maxneigh;
                 grow_sigma(nb_sg,new_n_tot);
                 nb_sg=new_n_tot;
               }
             }
             ps=sigB1[n]*rdBO+1.0;
             ks=(int)ps;
             if(nBOt-1<ks)
               ks=nBOt-1;
             ps=ps-ks;
             if(ps>1.0)
               ps=1.0;
             dsigB1=((FsigBO3[iij][ks-1]*ps+FsigBO2[iij][ks-1])*ps
                 +FsigBO1[iij][ks-1])*ps+FsigBO[iij][ks-1];
             dsigB2=(FsigBO6[iij][ks-1]*ps+FsigBO5[iij][ks-1])*ps+FsigBO4[iij][ks-1];
             part0=(FF+0.5*AAC+small5);
             part1=(sigma_f[iij]-0.5)*sigma_k[iij];
             part2=1.0-part1*EE1/part0;
             part3=dsigB1*part1/part0;
             part4=part3/part0*EE1;
- 
+
 // sigB is the final expression for (a) Eq. 6 and (b) Eq. 11
- 
+
             sigB[n]=dsigB1*part2;
             pp1=2.0*betaS_ij;
             for(m=0;m<nb_t;m++) {
               if((bt_sg[m].i>-1)&&(bt_sg[m].j>-1)) {
                 temp_kk=bt_sg[m].temp;
                 bt_ij=bt_sg[m].temp;
                 bt_i=bt_sg[m].i;
                 bt_j=bt_sg[m].j;
                 xtmp[0]=x[bt_j][0]-x[bt_i][0];
                 xtmp[1]=x[bt_j][1]-x[bt_i][1];
                 xtmp[2]=x[bt_j][2]-x[bt_i][2];
                 for(pp=0;pp<3;pp++) {
                   bt_sg[m].dSigB[pp]=dsigB2*part2*bt_sg[m].dSigB1[pp]
                       -part3*bt_sg[m].dEE1[pp]
                       +part4*(bt_sg[m].dFF[pp]
                       +0.5*bt_sg[m].dAAC[pp]);
                 }
                 for(pp=0;pp<3;pp++) {
                   ftmp[pp]=pp1*bt_sg[m].dSigB[pp];
                   f[bt_i][pp]-=ftmp[pp];
                   f[bt_j][pp]+=ftmp[pp];
                 }
                 if(evflag) {
                   ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                       ,ftmp[2],xtmp[0],xtmp[1],xtmp[2]);
                 }
               }
             }
           }
           n++;
         }
       }
     }
   }
   destroy_sigma();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::PiBo()
 {
   int new_n_tot;
   int i,j,k,kp,m,n,pp,nb_t;
   int iij,ji,ki;
   int nsearch,ncmp;
   int i_tag,j_tag;
   int njik,ngj,ngk,nglj,ngl,ngi;
   int nkjkp,nijkp,ngli,nkikp,njikp;
   int itmp,ltmp,jtmp,ktmp;
   int nlocal,pi_flag;
   int inum,*ilist,*iilist,*jlist;
-  int **firstneigh,*numneigh; 
+  int **firstneigh,*numneigh;
   int itype,jtype;
   int temp_ij,temp_ik,temp_ikp;
   int temp_ji,temp_jki,temp_jk,temp_jkp;
   int ang_jikp,ang_kikp,ang_ijk;
   int ang_ijkp,ang_kjkp,ang_jik;
   int nb_ij,nb_ik,nb_jk,nb_ikp,nb_jkp;
   int bt_ij,bt_i,bt_j;
   double AA,BB,CC,DD,EE,FF;
   double cosSq,sinFactor,cosFactor;
   double cosSq1,dotV,BBrt,AB1,AB2;
   double BBrtR,ABrtR,ABrtR1,ABrtR2;
   double angFactor,angFactor1,angFactor2;
   double angFactor3,angFactor4,angRfactor;
   double dAngR1,dAngR2,agpdpr3;
   double agpdpr1,agpdpr2,app1,app2,app3;
   double betaCapSq1,dbetaCapSq1;
   double betaCapSq2,dbetaCapSq2;
   double betaCapSum,ftmp[3];
   double dPiB1,dPiB2,dPiB3,pp2;
   double **f = atom->f;
   double **x = atom->x;
   int *type = atom->type;
   int *tag = atom->tag;
   int newton_pair = force->newton_pair;
 
   nlocal = atom->nlocal;
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
-  
+
   n=0;
 
 // Loop over all local atoms for i
 
   if(nb_pi>16) {
     nb_pi=16;
   }
   if(nb_pi==0) {
     nb_pi=(maxneigh)*(maxneigh/2);
   }
   if(allocate_pi) {
     destroy_pi();
   }
-  create_pi(nb_pi);   
+  create_pi(nb_pi);
   for(itmp=0;itmp<inum;itmp++) {
     nb_t=0;
     i = ilist[itmp];
     itype = map[type[i]]+1;
     i_tag=tag[i];
 
 // j is a loop over all neighbors of i
 
     iilist=firstneigh[i];
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       temp_ij=BOP_index[i]+jtmp;
       if(neigh_flag[temp_ij]) {
         for(m=0;m<nb_pi;m++) {
-          for(pp=0;pp<3;pp++) { 
-            bt_pi[m].dAA[pp]=0.0; 
-            bt_pi[m].dBB[pp]=0.0; 
-            bt_pi[m].dPiB[pp]=0.0; 
+          for(pp=0;pp<3;pp++) {
+            bt_pi[m].dAA[pp]=0.0;
+            bt_pi[m].dBB[pp]=0.0;
+            bt_pi[m].dPiB[pp]=0.0;
           }
           bt_pi[m].i=-1;
           bt_pi[m].j=-1;
         }
         j=iilist[jtmp];
         jlist=firstneigh[j];
         jtype=map[type[j]]+1;
         j_tag=tag[j];
         nb_t=0;
         ftmp[0]=0.0;
         ftmp[1]=0.0;
         ftmp[2]=0.0;
         nb_ij=nb_t;
         nb_t++;
-        if(nb_t>nb_pi) { 
+        if(nb_t>nb_pi) {
           new_n_tot=nb_pi+maxneigh;
           grow_pi(nb_pi,new_n_tot);
           nb_pi=new_n_tot;
         }
         bt_pi[nb_ij].i=i;
         bt_pi[nb_ij].j=j;
         bt_pi[nb_ij].temp=temp_ij;
         if(j_tag>=i_tag) {
           if(itype==jtype)
             iij=itype-1;
           else if(itype<jtype)
             iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
           else
             iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
           AA=0.0;
           BB=0.0;
           nPiBk[n]=0;
           for(ji=0;ji<numneigh[j];ji++) {
             temp_ji=BOP_index[j]+ji;
             if(x[jlist[ji]][0]==x[i][0]) {
               if(x[jlist[ji]][1]==x[i][1]) {
                 if(x[jlist[ji]][2]==x[i][2]) {
                   break;
                 }
               }
             }
           }
 
 // j and k are different neighbors of i
 
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
             if(ktmp!=jtmp) {
               temp_ik=BOP_index[i]+ktmp;
               if(neigh_flag[temp_ik]) {
                 k=iilist[ktmp];
                 if(jtmp<ktmp) {
                   njik=jtmp*(2*numneigh[i]-jtmp-1)/2+(ktmp-jtmp)-1;
                   ngj=0;
                   ngk=1;
                 }
                 else {
                   njik=ktmp*(2*numneigh[i]-ktmp-1)/2+(jtmp-ktmp)-1;
                   ngj=1;
                   ngk=0;
                 }
                 ang_jik=cos_index[i]+njik;
                 if(ang_jik>=cos_total) {
                   error->one(FLERR,"Too many atom triplets for pair bop");
                 }
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_pi) {
                   new_n_tot=nb_pi+maxneigh;
                   grow_pi(nb_pi,new_n_tot);
                   nb_pi=new_n_tot;
                 }
                 bt_pi[nb_ik].i=i;
                 bt_pi[nb_ik].j=k;
                 bt_pi[nb_ik].temp=temp_ik;
                 cosSq=cosAng[ang_jik]*cosAng[ang_jik];
                 sinFactor=.5*(1.0-cosSq)*pi_p[itype-1]*betaS[temp_ik];
                 cosFactor=.5*(1.0+cosSq)*betaP[temp_ik];
                 betaCapSq1=pi_p[itype-1]*betaS[temp_ik]*betaS[temp_ik]-betaP[temp_ik]
                     *betaP[temp_ik];
                 dbetaCapSq1=2.0*pi_p[itype-1]*betaS[temp_ik]*dBetaS[temp_ik]
                     -2.0*betaP[temp_ik]*dBetaP[temp_ik];
 
-//AA is Eq. 37 (a) and Eq. 19 (b) or i atoms 
+//AA is Eq. 37 (a) and Eq. 19 (b) or i atoms
 //1st BB is first term of Eq. 38 (a) where j and k =neighbors i
 
                 AA=AA+sinFactor*betaS[temp_ik]+cosFactor*betaP[temp_ik];
                 BB=BB+.25*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*betaCapSq1;
 
 //agpdpr1 is derivative of AA w.r.t. for atom i w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik)
 //app1 is derivative of AA w.r.t. for atom i w.r.t. cos(theta_jik)
 //app2 is derivative of BB w.r.t. for atom i w.r.t. cos(theta_jik)
 
                 agpdpr1=(2.0*sinFactor*dBetaS[temp_ik]+2.0*cosFactor
                     *dBetaP[temp_ik])/rij[temp_ik];
                 app1=cosAng[ang_jik]*(-pi_p[itype-1]*betaS[temp_ik]*betaS[temp_ik]
                     +betaP[temp_ik]*betaP[temp_ik]);
                 app2=-(1.0-cosSq)*cosAng[ang_jik]*betaCapSq1*betaCapSq1;
                 agpdpr2=.5*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*dbetaCapSq1/rij[temp_ik];
                 itypePiBk[n][nPiBk[n]]=k;
                 bt_pi[nb_ij].dAA[0]+=
                     app1*dcAng[ang_jik][0][ngj];
                 bt_pi[nb_ij].dAA[1]+=
                     app1*dcAng[ang_jik][1][ngj];
                 bt_pi[nb_ij].dAA[2]+=
                     app1*dcAng[ang_jik][2][ngj];
                 bt_pi[nb_ij].dBB[0]+=
                     app2*dcAng[ang_jik][0][ngj];
                 bt_pi[nb_ij].dBB[1]+=
                     app2*dcAng[ang_jik][1][ngj];
                 bt_pi[nb_ij].dBB[2]+=
                     app2*dcAng[ang_jik][2][ngj];
                 bt_pi[nb_ik].dAA[0]+=
                     agpdpr1*disij[0][temp_ik]
                     +app1*dcAng[ang_jik][0][ngk];
                 bt_pi[nb_ik].dAA[1]+=
                     agpdpr1*disij[1][temp_ik]
                     +app1*dcAng[ang_jik][1][ngk];
                 bt_pi[nb_ik].dAA[2]+=
                     agpdpr1*disij[2][temp_ik]
                     +app1*dcAng[ang_jik][2][ngk];
                 bt_pi[nb_ik].dBB[0]+=
                     app2*dcAng[ang_jik][0][ngk]
                     +agpdpr2*disij[0][temp_ik];
                 bt_pi[nb_ik].dBB[1]+=
                     app2*dcAng[ang_jik][1][ngk]
                     +agpdpr2*disij[1][temp_ik];
                 bt_pi[nb_ik].dBB[2]+=
                     app2*dcAng[ang_jik][2][ngk]
                     +agpdpr2*disij[2][temp_ik];
 
-// j and k and k' are different neighbors of i 
+// j and k and k' are different neighbors of i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     if(neigh_flag[temp_ikp]) {
                       kp=iilist[ltmp];
                       for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                         ncmp=itypePiBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               break;
                             }
                           }
                         }
                       }
                       nkikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(ktmp-ltmp)-1;
                       if(jtmp<ltmp) {
                         njikp=jtmp*(2*numneigh[i]-jtmp-1)/2+(ltmp-jtmp)-1;
                         nglj=0;
                         ngl=1;
                       }
                       else {
                         njikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(jtmp-ltmp)-1;
                         nglj=1;
                         ngl=0;
                       }
                       ang_jikp=cos_index[i]+njikp;
                       if(ang_jikp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                       bt_pi[nb_ikp].i=i;
                       bt_pi[nb_ikp].j=kp;
                       bt_pi[nb_ikp].temp=temp_ikp;
                       ang_kikp=cos_index[i]+nkikp;
                       if(ang_kikp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       betaCapSq2=pi_p[itype-1]*betaS[temp_ikp]*betaS[temp_ikp]
                           -betaP[temp_ikp]*betaP[temp_ikp];
                       dbetaCapSq2=2.0*pi_p[itype-1]*betaS[temp_ikp]*dBetaS[temp_ikp]
                           -2.0*betaP[temp_ikp]*dBetaP[temp_ikp];
                       cosSq1=cosAng[ang_jikp]*cosAng[ang_jikp];
                       angFactor=cosAng[ang_kikp]-cosAng[ang_jikp]*cosAng[ang_jik];
                       angFactor1=4.0*angFactor;
                       angFactor2=-angFactor1*cosAng[ang_jikp]
                           +2.0*cosAng[ang_jik]*(1.0-cosSq1);
                       angFactor3=-angFactor1*cosAng[ang_jik]
                           +2.0*cosAng[ang_jikp]*(1.0-cosSq);
                       angFactor4=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //2nd BB is third term of Eq. 38 (a) where j , k and k'=neighbors i
 
                       BB=BB+betaCapSum*angFactor4;
 
 //agpdpr1 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik')
 //app1 is derivative of BB 3rd term w.r.t. cos(theta_kik')
 //app2 is derivative of BB 3rd term w.r.t. cos(theta_jik)
 //app3 is derivative of BB 3rd term w.r.t. cos(theta_jik')
 
                       app1=betaCapSum*angFactor1;
                       app2=betaCapSum*angFactor2;
                       app3=betaCapSum*angFactor3;
                       agpdpr1=.5*angFactor4*dbetaCapSq1*betaCapSq2/rij[temp_ik];
                       agpdpr2=.5*angFactor4*betaCapSq1*dbetaCapSq2/rij[temp_ikp];
 
                       bt_pi[nb_ij].dBB[0]+=
                           app2*dcAng[ang_jik][0][ngj]
-                          +app3*dcAng[ang_jikp][0][nglj]; 
+                          +app3*dcAng[ang_jikp][0][nglj];
                       bt_pi[nb_ij].dBB[1]+=
                           app2*dcAng[ang_jik][1][ngj]
-                          +app3*dcAng[ang_jikp][1][nglj]; 
+                          +app3*dcAng[ang_jikp][1][nglj];
                       bt_pi[nb_ij].dBB[2]+=
                           app2*dcAng[ang_jik][2][ngj]
-                          +app3*dcAng[ang_jikp][2][nglj]; 
+                          +app3*dcAng[ang_jikp][2][nglj];
                       bt_pi[nb_ik].dBB[0]+=
                           agpdpr1*disij[0][temp_ik]
                           +app1*dcAng[ang_kikp][0][1]
                           +app2*dcAng[ang_jik][0][ngk];
                       bt_pi[nb_ik].dBB[1]+=
                           agpdpr1*disij[1][temp_ik]
                           +app1*dcAng[ang_kikp][1][1]
                           +app2*dcAng[ang_jik][1][ngk];
                       bt_pi[nb_ik].dBB[2]+=
                           agpdpr1*disij[2][temp_ik]
                           +app1*dcAng[ang_kikp][2][1]
                           +app2*dcAng[ang_jik][2][ngk];
                       bt_pi[nb_ikp].dBB[0]+=
                           agpdpr2*disij[0][temp_ikp]
                           +app1*dcAng[ang_kikp][0][0]
                           +app3*dcAng[ang_jikp][0][ngl];
                       bt_pi[nb_ikp].dBB[1]+=
                           agpdpr2*disij[1][temp_ikp]
                           +app1*dcAng[ang_kikp][1][0]
                           +app3*dcAng[ang_jikp][1][ngl];
                       bt_pi[nb_ikp].dBB[2]+=
                           agpdpr2*disij[2][temp_ikp]
                           +app1*dcAng[ang_kikp][2][0]
                           +app3*dcAng[ang_jikp][2][ngl];
                     }
                   }
                 }
                 nPiBk[n]=nPiBk[n]+1;
               }
             }
           }
 
 //j is a neighbor of i and k is a neighbor of j and equal to i
 
           for(ki=0;ki<numneigh[j];ki++) {
             temp_jki=BOP_index[j]+ki;
             k=jlist[ki];
             if(x[k][0]==x[i][0]) {
               if(x[k][1]==x[i][1]) {
                 if(x[k][2]==x[i][2]) {
                   break;
                 }
               }
             }
           }
 
 //j is a neighbor of i and k is a neighbor of j not equal to i
 
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ki) {
               temp_jk=BOP_index[j]+ktmp;
               if(neigh_flag[temp_jk]) {
                 k=jlist[ktmp];
                 pi_flag=0;
                 for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                   ncmp=itypePiBk[n][nsearch];
                   if(x[ncmp][0]==x[k][0]) {
                     if(x[ncmp][1]==x[k][1]) {
                       if(x[ncmp][2]==x[k][2]) {
                         pi_flag=1;
                         break;
-                      } 
-                    } 
-                  } 
-                } 
+                      }
+                    }
+                  }
+                }
                 if(pi_flag==0) {
                   itypePiBk[n][nPiBk[n]]=k;
-                } 
+                }
                 if(ktmp<ki) {
                   njik=ktmp*(2*numneigh[j]-ktmp-1)/2+(ki-ktmp)-1;
                   ngi=1;
                   ngk=0;
-                } 
+                }
                 else {
                   njik=ki*(2*numneigh[j]-ki-1)/2+(ktmp-ki)-1;
                   ngi=0;
                   ngk=1;
                 }
                 ang_ijk=cos_index[j]+njik;
                 if(ang_ijk>=cos_total) {
                   error->one(FLERR,"Too many atom triplets for pair bop");
                 }
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_pi) {
                   new_n_tot=nb_pi+maxneigh;
                   grow_pi(nb_pi,new_n_tot);
                   nb_pi=new_n_tot;
                 }
                 bt_pi[nb_jk].i=j;
                 bt_pi[nb_jk].j=k;
                 bt_pi[nb_jk].temp=temp_jk;
                 cosSq=cosAng[ang_ijk]*cosAng[ang_ijk];
                 sinFactor=.5*(1.0-cosSq)*pi_p[jtype-1]*betaS[temp_jk];
                 cosFactor=.5*(1.0+cosSq)*betaP[temp_jk];
                 betaCapSq1=pi_p[jtype-1]*betaS[temp_jk]*betaS[temp_jk]
                     -betaP[temp_jk]*betaP[temp_jk];
                 dbetaCapSq1=2.0*pi_p[jtype-1]*betaS[temp_jk]*dBetaS[temp_jk]
                     -2.0*betaP[temp_jk]*dBetaP[temp_jk];
 
-//AA is Eq. 37 (a) and Eq. 19 (b) for j atoms 
+//AA is Eq. 37 (a) and Eq. 19 (b) for j atoms
 //3rd BB is 2nd term of Eq. 38 (a) where i and k =neighbors j
 
                 AA=AA+sinFactor*betaS[temp_jk]+cosFactor*betaP[temp_jk];
                 BB=BB+.25*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*betaCapSq1;
 
 //agpdpr1 is derivative of AA for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB for atom j w.r.t. Beta(r_jk)
 //app1 is derivative of AA for j atom w.r.t. cos(theta_ijk)
-//app2 is derivative of BB 2nd term w.r.t. cos(theta_ijk) 
+//app2 is derivative of BB 2nd term w.r.t. cos(theta_ijk)
 
                 agpdpr1=(2.0*sinFactor*dBetaS[temp_jk]+2.0*cosFactor
                     *dBetaP[temp_jk])/rij[temp_jk];
                 agpdpr2=.5*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*dbetaCapSq1/rij[temp_jk];
                 app1=cosAng[ang_ijk]*(-pi_p[jtype-1]*betaS[temp_jk]*betaS[temp_jk]
                     +betaP[temp_jk]*betaP[temp_jk]);
                 app2=-(1.0-cosSq)*cosAng[ang_ijk]*betaCapSq1*betaCapSq1;
                 bt_pi[nb_ij].dAA[0]-=
                     app1*dcAng[ang_ijk][0][ngi];
                 bt_pi[nb_ij].dAA[1]-=
                     app1*dcAng[ang_ijk][1][ngi];
                 bt_pi[nb_ij].dAA[2]-=
                     app1*dcAng[ang_ijk][2][ngi];
                 bt_pi[nb_ij].dBB[0]-=
                     app2*dcAng[ang_ijk][0][ngi];
                 bt_pi[nb_ij].dBB[1]-=
                     app2*dcAng[ang_ijk][1][ngi];
                 bt_pi[nb_ij].dBB[2]-=
                     app2*dcAng[ang_ijk][2][ngi];
                 bt_pi[nb_jk].dAA[0]+=
                     agpdpr1*disij[0][temp_jk]
                     +app1*dcAng[ang_ijk][0][ngk];
                 bt_pi[nb_jk].dAA[1]+=
                     agpdpr1*disij[1][temp_jk]
                     +app1*dcAng[ang_ijk][1][ngk];
                 bt_pi[nb_jk].dAA[2]+=
                     agpdpr1*disij[2][temp_jk]
                     +app1*dcAng[ang_ijk][2][ngk];
                 bt_pi[nb_jk].dBB[0]+=
                     app2*dcAng[ang_ijk][0][ngk]
                     +agpdpr2*disij[0][temp_jk];
                 bt_pi[nb_jk].dBB[1]+=
                     app2*dcAng[ang_ijk][1][ngk]
                     +agpdpr2*disij[1][temp_jk];
                 bt_pi[nb_jk].dBB[2]+=
                     app2*dcAng[ang_ijk][2][ngk]
                     +agpdpr2*disij[2][temp_jk];
-            
+
 //j is a neighbor of i and k and k' are different neighbors of j not equal to i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ki) {
                     temp_jkp=BOP_index[j]+ltmp;
                     if(neigh_flag[temp_jkp]) {
                       kp=jlist[ltmp];
                       for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                         ncmp=itypePiBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               break;
                             }
                           }
                         }
                       }
                       nkjkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ktmp-ltmp)-1;
                       if(ki<ltmp) {
                         nijkp=ki*(2*numneigh[j]-ki-1)/2+(ltmp-ki)-1;
                         ngli=0;
                         ngl=1;
                       }
                       else {
                         nijkp=ltmp*(2*numneigh[j]-ltmp-1)/2+(ki-ltmp)-1;
                         ngli=1;
                         ngl=0;
                       }
                       ang_ijkp=cos_index[j]+nijkp;
                       if(ang_ijkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       ang_kjkp=cos_index[j]+nkjkp;
                       if(ang_kjkp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       nb_jkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                       bt_pi[nb_jkp].i=j;
                       bt_pi[nb_jkp].j=kp;
                       bt_pi[nb_jkp].temp=temp_jkp;
                       betaCapSq2=pi_p[jtype-1]*betaS[temp_jkp]*betaS[temp_jkp]
                           -betaP[temp_jkp]*betaP[temp_jkp];
                       dbetaCapSq2=2.0*pi_p[jtype-1]*betaS[temp_jkp]*dBetaS[temp_jkp]
                           -2.0*betaP[temp_jkp]*dBetaP[temp_jkp];
                       cosSq1=cosAng[ang_ijkp]*cosAng[ang_ijkp];
                       angFactor=cosAng[ang_kjkp]-cosAng[ang_ijkp]*cosAng[ang_ijk];
                       angFactor1=4.0*angFactor;
                       angFactor2=-angFactor1*cosAng[ang_ijkp]
                           +2.0*cosAng[ang_ijk]*(1.0-cosSq1);
                       angFactor3=-angFactor1*cosAng[ang_ijk]
                           +2.0*cosAng[ang_ijkp]*(1.0-cosSq);
                       angFactor4=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //4th BB is 4th term of Eq. 38 (a) where i , k and k' =neighbors j
 
                       BB=BB+betaCapSum*angFactor4;
 
-//app1 is derivative of BB 4th term w.r.t. cos(theta_kjk') 
-//app2 is derivative of BB 4th term w.r.t. cos(theta_ijk) 
-//app3 is derivative of BB 4th term w.r.t. cos(theta_ijk') 
+//app1 is derivative of BB 4th term w.r.t. cos(theta_kjk')
+//app2 is derivative of BB 4th term w.r.t. cos(theta_ijk)
+//app3 is derivative of BB 4th term w.r.t. cos(theta_ijk')
 //agpdpr1 is derivative of BB 4th term for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB 4th term for atom j w.r.t. Beta(r_jk')
 
                       app1=betaCapSum*angFactor1;
                       app2=betaCapSum*angFactor2;
                       app3=betaCapSum*angFactor3;
                       agpdpr1=.5*angFactor4*dbetaCapSq1*betaCapSq2/rij[temp_jk];
                       agpdpr2=.5*angFactor4*betaCapSq1*dbetaCapSq2/rij[temp_jkp];
 
                       bt_pi[nb_ij].dBB[0]-=
                           app3*dcAng[ang_ijkp][0][ngli]
-                          +app2*dcAng[ang_ijk][0][ngi]; 
+                          +app2*dcAng[ang_ijk][0][ngi];
                       bt_pi[nb_ij].dBB[1]-=
                           app3*dcAng[ang_ijkp][1][ngli]
-                          +app2*dcAng[ang_ijk][1][ngi]; 
+                          +app2*dcAng[ang_ijk][1][ngi];
                       bt_pi[nb_ij].dBB[2]-=
                           app3*dcAng[ang_ijkp][2][ngli]
-                          +app2*dcAng[ang_ijk][2][ngi]; 
+                          +app2*dcAng[ang_ijk][2][ngi];
                       bt_pi[nb_jk].dBB[0]+=
                           agpdpr1*disij[0][temp_jk]
                           +app1*dcAng[ang_kjkp][0][1]
                           +app2*dcAng[ang_ijk][0][ngk];
                       bt_pi[nb_jk].dBB[1]+=
                           agpdpr1*disij[1][temp_jk]
                           +app1*dcAng[ang_kjkp][1][1]
                           +app2*dcAng[ang_ijk][1][ngk];
                       bt_pi[nb_jk].dBB[2]+=
                           agpdpr1*disij[2][temp_jk]
                           +app1*dcAng[ang_kjkp][2][1]
                           +app2*dcAng[ang_ijk][2][ngk];
                       bt_pi[nb_jkp].dBB[0]+=
                           agpdpr2*disij[0][temp_jkp]
                           +app1*dcAng[ang_kjkp][0][0]
                           +app3*dcAng[ang_ijkp][0][ngl];
                       bt_pi[nb_jkp].dBB[1]+=
                           agpdpr2*disij[1][temp_jkp]
                           +app1*dcAng[ang_kjkp][1][0]
                           +app3*dcAng[ang_ijkp][1][ngl];
                       bt_pi[nb_jkp].dBB[2]+=
                           agpdpr2*disij[2][temp_jkp]
                           +app1*dcAng[ang_kjkp][2][0]
                           +app3*dcAng[ang_ijkp][2][ngl];
                     }
                   }
                 }
 
 //j and k' are different neighbors of i and k is a neighbor of j not equal to i
 
                 for(ltmp=0;ltmp<numneigh[i];ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     if(neigh_flag[temp_ikp]) {
                       kp=iilist[ltmp];
                       for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                         ncmp=itypePiBk[n][nsearch];
                         if(x[ncmp][0]==x[kp][0]) {
                           if(x[ncmp][1]==x[kp][1]) {
                             if(x[ncmp][2]==x[kp][2]) {
                               break;
                             }
                           }
                         }
                       }
                       if(ltmp<jtmp) {
                         njikp=ltmp*(2*numneigh[i]-ltmp-1)/2+(jtmp-ltmp)-1;
                         ngl=1;
                         nglj=0;
                       }
                       else {
                         njikp=jtmp*(2*numneigh[i]-jtmp-1)/2+(ltmp-jtmp)-1;
                         ngl=0;
                         nglj=1;
                       }
                       ang_jikp=cos_index[i]+njikp;
                       if(ang_jikp>=cos_total) {
                         error->one(FLERR,"Too many atom triplets for pair bop");
                       }
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                       bt_pi[nb_ikp].i=i;
                       bt_pi[nb_ikp].j=kp;
                       bt_pi[nb_ikp].temp=temp_ikp;
                       betaCapSq2=pi_p[itype-1]*betaS[temp_ikp]*betaS[temp_ikp]
                           -betaP[temp_ikp]*betaP[temp_ikp];
                       dbetaCapSq2=2.0*pi_p[itype-1]*betaS[temp_ikp]*dBetaS[temp_ikp]
                           -2.0*betaP[temp_ikp]*dBetaP[temp_ikp];
                       dotV=(disij[0][temp_jk]*disij[0][temp_ikp]+disij[1][temp_jk]
                           *disij[1][temp_ikp]+disij[2][temp_jk]*disij[2][temp_ikp])
                           /(rij[temp_jk]*rij[temp_ikp]);
                       cosSq1=cosAng[ang_jikp]*cosAng[ang_jikp];
                       angFactor=dotV+cosAng[ang_jikp]*cosAng[ang_ijk];
                       angRfactor=4.0*angFactor*dotV;
                       dAngR1=-angRfactor/rij[temp_jk];
                       dAngR2=-angRfactor/rij[temp_ikp];
                       angFactor1=4.0*angFactor*cosAng[ang_jikp]
                           +2.0*cosAng[ang_ijk]*(1.0-cosSq1);
                       angFactor2=4.0*angFactor*cosAng[ang_ijk]
                           +2.0*cosAng[ang_jikp]*(1.0-cosSq);
                       angFactor3=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //5th BB is 5th term of Eq. 38 (a) Eq. 21 (b) where i , k and k' =neighbors j
 
                       BB=BB+betaCapSum*angFactor3;
 
-//app1 is derivative of BB 5th term w.r.t. cos(theta_ijk) 
-//app2 is derivative of BB 5th term w.r.t. cos(theta_jik') 
+//app1 is derivative of BB 5th term w.r.t. cos(theta_ijk)
+//app2 is derivative of BB 5th term w.r.t. cos(theta_jik')
 //agpdpr1 is derivative of BB 5th term for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB 5th term for atom j w.r.t. Beta(r_ik')
 //agpdpr3 is derivative of BB 5th term for atom j w.r.t. dot(r_ik',r_ij)
 
                       app1=betaCapSum*angFactor1;
                       app2=betaCapSum*angFactor2;
                       agpdpr1=(.5*angFactor3*dbetaCapSq1*betaCapSq2
                           +betaCapSum*dAngR1)/rij[temp_jk];
                       agpdpr2=(.5*angFactor3*betaCapSq1*dbetaCapSq2
                           +betaCapSum*dAngR2)/rij[temp_ikp];
                       agpdpr3=4.0*betaCapSum*angFactor/(rij[temp_ikp]*rij[temp_jk]);
 
                       bt_pi[nb_ij].dBB[0]+=
                           +app2*dcAng[ang_jikp][0][ngl]
                           -app1*dcAng[ang_ijk][0][ngi];
                       bt_pi[nb_ij].dBB[1]+=
                           +app2*dcAng[ang_jikp][1][ngl]
                           -app1*dcAng[ang_ijk][1][ngi];
                       bt_pi[nb_ij].dBB[2]+=
                           +app2*dcAng[ang_jikp][2][ngl]
                           -app1*dcAng[ang_ijk][2][ngi];
                       bt_pi[nb_ikp].dBB[0]+=
                           agpdpr2*disij[0][temp_ikp]
                           +agpdpr3*disij[0][temp_jk]
                           +app2*dcAng[ang_jikp][0][nglj];
                       bt_pi[nb_ikp].dBB[1]+=
                           agpdpr2*disij[1][temp_ikp]
                           +agpdpr3*disij[1][temp_jk]
                           +app2*dcAng[ang_jikp][1][nglj];
                       bt_pi[nb_ikp].dBB[2]+=
                           agpdpr2*disij[2][temp_ikp]
                           +agpdpr3*disij[2][temp_jk]
                           +app2*dcAng[ang_jikp][2][nglj];
                       bt_pi[nb_jk].dBB[0]+=
                           agpdpr1*disij[0][temp_jk]
                           +agpdpr3*disij[0][temp_ikp]
                           +app1*dcAng[ang_ijk][0][ngk];
                       bt_pi[nb_jk].dBB[1]+=
                           agpdpr1*disij[1][temp_jk]
                           +agpdpr3*disij[1][temp_ikp]
                           +app1*dcAng[ang_ijk][1][ngk];
                       bt_pi[nb_jk].dBB[2]+=
                           agpdpr1*disij[2][temp_jk]
                           +agpdpr3*disij[2][temp_ikp]
                           +app1*dcAng[ang_ijk][2][ngk];
                     }
                   }
                 }
                 if(pi_flag==0)
                   nPiBk[n]=nPiBk[n]+1;
               }
             }
           }
           CC=betaP[temp_ij]*betaP[temp_ij]+pi_delta[iij]*pi_delta[iij];
           BBrt=sqrt(BB+small6);
           AB1=CC+pi_c[iij]*(AA+BBrt)+small7;
           AB2=CC+pi_c[iij]*(AA-BBrt+sqrt(small6))+small7;
           BBrtR=1.0/BBrt;
           ABrtR1=1.0/sqrt(AB1);
           ABrtR2=1.0/sqrt(AB2);
 
 // piB is similary formulation to (a) Eq. 36 and (b) Eq. 18
 
           piB[n]=(ABrtR1+ABrtR2)*pi_a[iij]*betaP[temp_ij];
           dPiB1=-.5*(pow(ABrtR1,3)+pow(ABrtR2,3))*pi_c[iij]*pi_a[iij]*betaP[temp_ij];
           dPiB2=.25*BBrtR*(pow(ABrtR2,3)-pow(ABrtR1,3))*pi_c[iij]*pi_a[iij]*betaP[temp_ij];
           dPiB3=((ABrtR1+ABrtR2)*pi_a[iij]-(pow(ABrtR1,3)+pow(ABrtR2,3))*pi_a[iij]
               *betaP[temp_ij]*betaP[temp_ij])*dBetaP[temp_ij]/rij[temp_ij];
           n++;
           pp2=2.0*betaP[temp_ij];
           for(m=0;m<nb_t;m++) {
             bt_ij=bt_pi[m].temp;
             bt_i=bt_pi[m].i;
             bt_j=bt_pi[m].j;
-            for(pp=0;pp<3;pp++) { 
+            for(pp=0;pp<3;pp++) {
               bt_pi[m].dPiB[pp]=
                   +dPiB1*bt_pi[m].dAA[pp]
                   +dPiB2*bt_pi[m].dBB[pp];
               ftmp[pp]=pp2*bt_pi[m].dPiB[pp];
               f[bt_i][pp]-=ftmp[pp];
               f[bt_j][pp]+=ftmp[pp];
-           
+
             }
             if(evflag) {
               ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                   ,ftmp[2],disij[0][bt_ij],disij[1][bt_ij],disij[2][bt_ij]);
             }
           }
-          for(pp=0;pp<3;pp++) { 
+          for(pp=0;pp<3;pp++) {
             ftmp[pp]=pp2*dPiB3*disij[pp][temp_ij];
             f[i][pp]-=ftmp[pp];
             f[j][pp]+=ftmp[pp];
           }
           if(evflag) {
             ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                 ,ftmp[2],disij[0][temp_ij],disij[1][temp_ij],disij[2][temp_ij]);
           }
         }
       }
     }
   }
   destroy_pi();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::PiBo_otf()
 {
   int new_n_tot;
   int i,j,k,kp,m,n,pp,nb_t;
   int iij,iik,iikp,ji,ki,ijkp,ijk;
   int nsearch,ncmp;
   int i_tag,j_tag;
   int itmp,ltmp,jtmp,ktmp;
   int pi_flag,ks;
   int nlocal;
   int inum,*ilist,*iilist,*jlist;
-  int **firstneigh,*numneigh; 
+  int **firstneigh,*numneigh;
   int itype,jtype,ktype,kptype;
   int temp_ij,temp_ik,temp_ikp;
   int temp_jk,temp_jkp;
   int nb_ij,nb_ik,nb_jk,nb_ikp,nb_jkp;
   int bt_i,bt_j;
   double AA,BB,CC,DD,EE,FF;
   double cosSq,sinFactor,cosFactor;
   double cosSq1,dotV,BBrt,AB1,AB2;
   double BBrtR,ABrtR,ABrtR1,ABrtR2;
   double angFactor,angFactor1,angFactor2;
   double angFactor3,angFactor4,angRfactor;
   double dAngR1,dAngR2,agpdpr3;
   double agpdpr1,agpdpr2,app1,app2,app3;
   double betaCapSq1,dbetaCapSq1;
   double betaCapSq2,dbetaCapSq2;
   double betaCapSum,ps;
   double ftmp[3],xtmp[3];
   double dPiB1,dPiB2,dPiB3,pp2;
 
   double dis_ij[3],rsq_ij,r_ij;
   double betaP_ij,dBetaP_ij;
   double dis_ik[3],rsq_ik,r_ik;
   double betaS_ik,dBetaS_ik;
   double betaP_ik,dBetaP_ik;
   double dis_ikp[3],rsq_ikp,r_ikp;
   double betaS_ikp,dBetaS_ikp;
   double betaP_ikp,dBetaP_ikp;
   double dis_jk[3],rsq_jk,r_jk;
   double betaS_jk,dBetaS_jk;
   double betaP_jk,dBetaP_jk;
   double dis_jkp[3],rsq_jkp,r_jkp;
   double betaS_jkp,dBetaS_jkp;
   double betaP_jkp,dBetaP_jkp;
 
   double cosAng_jik,dcA_jik[3][2];
   double cosAng_jikp,dcA_jikp[3][2];
   double cosAng_kikp,dcA_kikp[3][2];
   double cosAng_ijk,dcA_ijk[3][2];
   double cosAng_ijkp,dcA_ijkp[3][2];
   double cosAng_kjkp,dcA_kjkp[3][2];
 
   int newton_pair = force->newton_pair;
 
   double **f = atom->f;
   double **x = atom->x;
   int *type = atom->type;
   int *tag = atom->tag;
 
   nlocal = atom->nlocal;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
   inum = list->inum;
   ilist = list->ilist;
   n=0;
   if(nb_pi>16) {
     nb_pi=16;
   }
   if(nb_pi==0) {
     nb_pi=(maxneigh)*(maxneigh/2);
   }
 
 // Loop over all local atoms for i
 
   if(allocate_pi) {
-    destroy_pi();   
+    destroy_pi();
   }
-  create_pi(nb_pi);   
+  create_pi(nb_pi);
 
   for(itmp=0;itmp<inum;itmp++) {
     nb_t=0;
     i = ilist[itmp];
     itype = map[type[i]]+1;
     i_tag=tag[i];
 
 // j is a loop over all neighbors of i
 
     iilist=firstneigh[i];
     for(jtmp=0;jtmp<numneigh[i];jtmp++) {
       for(m=0;m<nb_pi;m++) {
-        for(pp=0;pp<3;pp++) { 
-          bt_pi[m].dAA[pp]=0.0; 
-          bt_pi[m].dBB[pp]=0.0; 
-          bt_pi[m].dPiB[pp]=0.0; 
+        for(pp=0;pp<3;pp++) {
+          bt_pi[m].dAA[pp]=0.0;
+          bt_pi[m].dBB[pp]=0.0;
+          bt_pi[m].dPiB[pp]=0.0;
         }
         bt_pi[m].i=-1;
         bt_pi[m].j=-1;
       }
       temp_ij=BOP_index[i]+jtmp;
       j=iilist[jtmp];
       jlist=firstneigh[j];
       jtype=map[type[j]]+1;
       j_tag=tag[j];
       nb_t=0;
       ftmp[0]=0.0;
       ftmp[1]=0.0;
       ftmp[2]=0.0;
       if(j_tag>=i_tag) {
         if(itype==jtype)
           iij=itype-1;
         else if(itype<jtype)
           iij=itype*bop_types-itype*(itype+1)/2+jtype-1;
         else
           iij=jtype*bop_types-jtype*(jtype+1)/2+itype-1;
         AA=0.0;
         BB=0.0;
         nPiBk[n]=0;
         for(ji=0;ji<numneigh[j];ji++) {
           if(x[jlist[ji]][0]==x[i][0]) {
             if(x[jlist[ji]][1]==x[i][1]) {
               if(x[jlist[ji]][2]==x[i][2]) {
                   break;
               }
             }
           }
         }
         nb_ij=nb_t;
         nb_t++;
         if(nb_t>nb_pi) {
           new_n_tot=nb_pi+maxneigh;
           grow_pi(nb_pi,new_n_tot);
           nb_pi=new_n_tot;
         }
         bt_pi[nb_ij].i=i;
         bt_pi[nb_ij].j=j;
         bt_pi[nb_ij].temp=temp_ij;
-        dis_ij[0]=x[j][0]-x[i][0]; 
-        dis_ij[1]=x[j][1]-x[i][1]; 
-        dis_ij[2]=x[j][2]-x[i][2]; 
+        dis_ij[0]=x[j][0]-x[i][0];
+        dis_ij[1]=x[j][1]-x[i][1];
+        dis_ij[2]=x[j][2]-x[i][2];
         rsq_ij=dis_ij[0]*dis_ij[0]
             +dis_ij[1]*dis_ij[1]
             +dis_ij[2]*dis_ij[2];
-        r_ij=sqrt(rsq_ij); 
+        r_ij=sqrt(rsq_ij);
         if(r_ij<=rcut[iij]) {
           ps=r_ij*rdr[iij]+1.0;
           ks=(int)ps;
           if(nr-1<ks)
             ks=nr-1;
           ps=ps-ks;
           if(ps>1.0)
             ps=1.0;
           betaP_ij=((pBetaP3[iij][ks-1]*ps+pBetaP2[iij][ks-1])*ps
               +pBetaP1[iij][ks-1])*ps+pBetaP[iij][ks-1];
           dBetaP_ij=(pBetaP6[iij][ks-1]*ps+pBetaP5[iij][ks-1])*ps
               +pBetaP4[iij][ks-1];
 
 // j and k are different neighbors of i
 
           for(ktmp=0;ktmp<numneigh[i];ktmp++) {
             if(ktmp!=jtmp) {
               temp_ik=BOP_index[i]+ktmp;
               k=iilist[ktmp];
               ktype=map[type[k]]+1;
-              if(itype==ktype) 
+              if(itype==ktype)
                 iik=itype-1;
-              else if(itype<ktype) 
+              else if(itype<ktype)
                 iik=itype*bop_types-itype*(itype+1)/2+ktype-1;
-              else 
-                iik=ktype*bop_types-ktype*(ktype+1)/2+itype-1; 
-              dis_ik[0]=x[k][0]-x[i][0]; 
-              dis_ik[1]=x[k][1]-x[i][1]; 
-              dis_ik[2]=x[k][2]-x[i][2]; 
+              else
+                iik=ktype*bop_types-ktype*(ktype+1)/2+itype-1;
+              dis_ik[0]=x[k][0]-x[i][0];
+              dis_ik[1]=x[k][1]-x[i][1];
+              dis_ik[2]=x[k][2]-x[i][2];
               rsq_ik=dis_ik[0]*dis_ik[0]
                   +dis_ik[1]*dis_ik[1]
                   +dis_ik[2]*dis_ik[2];
               r_ik=sqrt(rsq_ik);
               if(r_ik<=rcut[iik]) {
                 ps=r_ik*rdr[iik]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_ik=((pBetaS3[iik][ks-1]*ps+pBetaS2[iik][ks-1])*ps
                     +pBetaS1[iik][ks-1])*ps+pBetaS[iik][ks-1];
                 dBetaS_ik=(pBetaS6[iik][ks-1]*ps+pBetaS5[iik][ks-1])*ps
                     +pBetaS4[iik][ks-1];
                 betaP_ik=((pBetaP3[iik][ks-1]*ps+pBetaP2[iik][ks-1])*ps
                     +pBetaP1[iik][ks-1])*ps+pBetaP[iik][ks-1];
                 dBetaP_ik=(pBetaP6[iik][ks-1]*ps+pBetaP5[iik][ks-1])*ps
                     +pBetaP4[iik][ks-1];
                 cosAng_jik=(dis_ij[0]*dis_ik[0]+dis_ij[1]*dis_ik[1]
-                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik); 
+                    +dis_ij[2]*dis_ik[2])/(r_ij*r_ik);
                 dcA_jik[0][0]=(dis_ik[0]*r_ij*r_ik-cosAng_jik
                     *dis_ij[0]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][0]=(dis_ik[1]*r_ij*r_ik-cosAng_jik
                     *dis_ij[1]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][0]=(dis_ik[2]*r_ij*r_ik-cosAng_jik
                     *dis_ij[2]*r_ik*r_ik)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[0][1]=(dis_ij[0]*r_ij*r_ik-cosAng_jik
                     *dis_ik[0]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[1][1]=(dis_ij[1]*r_ij*r_ik-cosAng_jik
                     *dis_ik[1]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 dcA_jik[2][1]=(dis_ij[2]*r_ij*r_ik-cosAng_jik
                     *dis_ik[2]*r_ij*r_ij)/(r_ij*r_ij*r_ik*r_ik);
                 nb_ik=nb_t;
                 nb_t++;
                 if(nb_t>nb_pi) {
                   new_n_tot=nb_pi+maxneigh;
                   grow_pi(nb_pi,new_n_tot);
                   nb_pi=new_n_tot;
                 }
                 bt_pi[nb_ik].i=i;
                 bt_pi[nb_ik].j=k;
                 bt_pi[nb_ik].temp=temp_ik;
                 cosSq=cosAng_jik*cosAng_jik;
                 sinFactor=.5*(1.0-cosSq)*pi_p[itype-1]*betaS_ik;
                 cosFactor=.5*(1.0+cosSq)*betaP_ik;
                 betaCapSq1=pi_p[itype-1]*betaS_ik*betaS_ik-betaP_ik
                     *betaP_ik;
                 dbetaCapSq1=2.0*pi_p[itype-1]*betaS_ik*dBetaS_ik
                     -2.0*betaP_ik*dBetaP_ik;
 
-//AA is Eq. 37 (a) and Eq. 19 (b) or i atoms 
+//AA is Eq. 37 (a) and Eq. 19 (b) or i atoms
 //1st BB is first term of Eq. 38 (a) where j and k =neighbors i
 
                 AA=AA+sinFactor*betaS_ik+cosFactor*betaP_ik;
                 BB=BB+.25*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*betaCapSq1;
 
 //agpdpr1 is derivative of AA w.r.t. for atom i w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik)
 //app1 is derivative of AA w.r.t. for atom i w.r.t. cos(theta_jik)
 //app2 is derivative of BB w.r.t. for atom i w.r.t. cos(theta_jik)
 
                 agpdpr1=(2.0*sinFactor*dBetaS_ik+2.0*cosFactor
                     *dBetaP_ik)/r_ik;
                 app1=cosAng_jik*(-pi_p[itype-1]*betaS_ik*betaS_ik
                     +betaP_ik*betaP_ik);
                 app2=-(1.0-cosSq)*cosAng_jik*betaCapSq1*betaCapSq1;
                 agpdpr2=.5*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*dbetaCapSq1/r_ik;
                 itypePiBk[n][nPiBk[n]]=k;
                 bt_pi[nb_ij].dAA[0]+=
                     app1*dcA_jik[0][0];
                 bt_pi[nb_ij].dAA[1]+=
                     app1*dcA_jik[1][0];
                 bt_pi[nb_ij].dAA[2]+=
                     app1*dcA_jik[2][0];
                 bt_pi[nb_ij].dBB[0]+=
                     app2*dcA_jik[0][0];
                 bt_pi[nb_ij].dBB[1]+=
                     app2*dcA_jik[1][0];
                 bt_pi[nb_ij].dBB[2]+=
                     app2*dcA_jik[2][0];
                 bt_pi[nb_ik].dAA[0]+=
                     agpdpr1*dis_ik[0]
                     +app1*dcA_jik[0][1];
                 bt_pi[nb_ik].dAA[1]+=
                     agpdpr1*dis_ik[1]
                     +app1*dcA_jik[1][1];
                 bt_pi[nb_ik].dAA[2]+=
                     agpdpr1*dis_ik[2]
                     +app1*dcA_jik[2][1];
                 bt_pi[nb_ik].dBB[0]+=
                     app2*dcA_jik[0][1]
                     +agpdpr2*dis_ik[0];
                 bt_pi[nb_ik].dBB[1]+=
                     app2*dcA_jik[1][1]
                     +agpdpr2*dis_ik[1];
                 bt_pi[nb_ik].dBB[2]+=
                     app2*dcA_jik[2][1]
                     +agpdpr2*dis_ik[2];
 
-// j and k and k' are different neighbors of i 
+// j and k and k' are different neighbors of i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     kp=iilist[ltmp];
                     kptype=map[type[kp]]+1;
                     for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                       ncmp=itypePiBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             break;
                           }
                         }
                       }
                     }
                     if(itype==kptype)
                       iikp=itype-1;
                     else if(itype<kptype)
                       iikp=itype*bop_types-itype*(itype+1)/2+kptype-1;
                     else
                       iikp=kptype*bop_types-kptype*(kptype+1)/2+itype-1;
-                    dis_ikp[0]=x[kp][0]-x[i][0]; 
-                    dis_ikp[1]=x[kp][1]-x[i][1]; 
-                    dis_ikp[2]=x[kp][2]-x[i][2]; 
+                    dis_ikp[0]=x[kp][0]-x[i][0];
+                    dis_ikp[1]=x[kp][1]-x[i][1];
+                    dis_ikp[2]=x[kp][2]-x[i][2];
                     rsq_ikp=dis_ikp[0]*dis_ikp[0]
                         +dis_ikp[1]*dis_ikp[1]
                         +dis_ikp[2]*dis_ikp[2];
                     r_ikp=sqrt(rsq_ikp);
                     if(r_ikp<=rcut[iikp]) {
                       ps=r_ikp*rdr[iikp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_ikp=((pBetaS3[iikp][ks-1]*ps+pBetaS2[iikp][ks-1])*ps
                           +pBetaS1[iikp][ks-1])*ps+pBetaS[iikp][ks-1];
                       dBetaS_ikp=(pBetaS6[iikp][ks-1]*ps+pBetaS5[iikp][ks-1])*ps
                           +pBetaS4[iikp][ks-1];
                       betaP_ikp=((pBetaP3[iikp][ks-1]*ps+pBetaP2[iikp][ks-1])*ps
                           +pBetaP1[iikp][ks-1])*ps+pBetaP[iikp][ks-1];
                       dBetaP_ikp=(pBetaP6[iikp][ks-1]*ps+pBetaP5[iikp][ks-1])*ps
                           +pBetaP4[iikp][ks-1];
                       cosAng_jikp=(dis_ij[0]*dis_ikp[0]+dis_ij[1]*dis_ikp[1]
-                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp); 
+                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp);
                       dcA_jikp[0][0]=(dis_ikp[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[0]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][0]=(dis_ikp[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[1]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][0]=(dis_ikp[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[2]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[0][1]=(dis_ij[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[0]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][1]=(dis_ij[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[1]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][1]=(dis_ij[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[2]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       cosAng_kikp=(dis_ik[0]*dis_ikp[0]+dis_ik[1]*dis_ikp[1]
-                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp); 
+                          +dis_ik[2]*dis_ikp[2])/(r_ik*r_ikp);
                       dcA_kikp[0][0]=(dis_ikp[0]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[0]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[1][0]=(dis_ikp[1]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[1]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[2][0]=(dis_ikp[2]*r_ik*r_ikp-cosAng_kikp
                           *dis_ik[2]*r_ikp*r_ikp)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[0][1]=(dis_ik[0]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[0]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[1][1]=(dis_ik[1]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[1]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       dcA_kikp[2][1]=(dis_ik[2]*r_ik*r_ikp-cosAng_kikp
                           *dis_ikp[2]*r_ik*r_ik)/(r_ik*r_ik*r_ikp*r_ikp);
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                       bt_pi[nb_ikp].i=i;
                       bt_pi[nb_ikp].j=kp;
                       bt_pi[nb_ikp].temp=temp_ikp;
                       betaCapSq2=pi_p[itype-1]*betaS_ikp*betaS_ikp
                           -betaP_ikp*betaP_ikp;
                       dbetaCapSq2=2.0*pi_p[itype-1]*betaS_ikp*dBetaS_ikp
                           -2.0*betaP_ikp*dBetaP_ikp;
                       cosSq1=cosAng_jikp*cosAng_jikp;
                       angFactor=cosAng_kikp-cosAng_jikp*cosAng_jik;
                       angFactor1=4.0*angFactor;
                       angFactor2=-angFactor1*cosAng_jikp
                           +2.0*cosAng_jik*(1.0-cosSq1);
                       angFactor3=-angFactor1*cosAng_jik
                           +2.0*cosAng_jikp*(1.0-cosSq);
                       angFactor4=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //2nd BB is third term of Eq. 38 (a) where j , k and k'=neighbors i
 
                       BB=BB+betaCapSum*angFactor4;
 
 //agpdpr1 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik)
 //agpdpr2 is derivative of BB w.r.t. for atom i w.r.t. Beta(r_ik')
 //app1 is derivative of BB 3rd term w.r.t. cos(theta_kik')
 //app2 is derivative of BB 3rd term w.r.t. cos(theta_jik)
 //app3 is derivative of BB 3rd term w.r.t. cos(theta_jik')
 
                       app1=betaCapSum*angFactor1;
                       app2=betaCapSum*angFactor2;
                       app3=betaCapSum*angFactor3;
                       agpdpr1=.5*angFactor4*dbetaCapSq1*betaCapSq2/r_ik;
                       agpdpr2=.5*angFactor4*betaCapSq1*dbetaCapSq2/r_ikp;
                       bt_pi[nb_ij].dBB[0]+=
                           app2*dcA_jik[0][0]
-                          +app3*dcA_jikp[0][0]; 
+                          +app3*dcA_jikp[0][0];
                       bt_pi[nb_ij].dBB[1]+=
                           app2*dcA_jik[1][0]
-                          +app3*dcA_jikp[1][0]; 
+                          +app3*dcA_jikp[1][0];
                       bt_pi[nb_ij].dBB[2]+=
                           app2*dcA_jik[2][0]
-                          +app3*dcA_jikp[2][0]; 
+                          +app3*dcA_jikp[2][0];
                       bt_pi[nb_ik].dBB[0]+=
                           agpdpr1*dis_ik[0]
                           +app1*dcA_kikp[0][0]
                           +app2*dcA_jik[0][1];
                       bt_pi[nb_ik].dBB[1]+=
                           agpdpr1*dis_ik[1]
                           +app1*dcA_kikp[1][0]
                           +app2*dcA_jik[1][1];
                       bt_pi[nb_ik].dBB[2]+=
                           agpdpr1*dis_ik[2]
                           +app1*dcA_kikp[2][0]
                           +app2*dcA_jik[2][1];
                       bt_pi[nb_ikp].dBB[0]+=
                           agpdpr2*dis_ikp[0]
                           +app1*dcA_kikp[0][1]
                           +app3*dcA_jikp[0][1];
                       bt_pi[nb_ikp].dBB[1]+=
                           agpdpr2*dis_ikp[1]
                           +app1*dcA_kikp[1][1]
                           +app3*dcA_jikp[1][1];
                       bt_pi[nb_ikp].dBB[2]+=
                           agpdpr2*dis_ikp[2]
                           +app1*dcA_kikp[2][1]
                           +app3*dcA_jikp[2][1];
                       }
                     }
                   }
                 nPiBk[n]=nPiBk[n]+1;
                 }
               }
             }
 
 //j is a neighbor of i and k is a neighbor of j and equal to i
 
           for(ki=0;ki<numneigh[j];ki++) {
             k=jlist[ki];
             if(x[k][0]==x[i][0]) {
               if(x[k][1]==x[i][1]) {
                 if(x[k][2]==x[i][2]) {
                   break;
                 }
               }
             }
           }
 
 //j is a neighbor of i and k is a neighbor of j not equal to i
 
           for(ktmp=0;ktmp<numneigh[j];ktmp++) {
             if(ktmp!=ki) {
               temp_jk=BOP_index[j]+ktmp;
               k=jlist[ktmp];
               ktype=map[type[k]]+1;
               pi_flag=0;
               for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                 ncmp=itypePiBk[n][nsearch];
                 if(x[ncmp][0]==x[k][0]) {
                   if(x[ncmp][1]==x[k][1]) {
                     if(x[ncmp][2]==x[k][2]) {
                       pi_flag=1;
                       break;
-                    } 
-                  } 
-                } 
-              } 
+                    }
+                  }
+                }
+              }
               if(pi_flag==0) {
                 itypePiBk[n][nPiBk[n]]=k;
-              } 
-              if(jtype==ktype) 
+              }
+              if(jtype==ktype)
                 ijk=jtype-1;
               else if(jtype<ktype)
                 ijk=jtype*bop_types-jtype*(jtype+1)/2+ktype-1;
               else
                 ijk=ktype*bop_types-ktype*(ktype+1)/2+jtype-1;
-              dis_jk[0]=x[k][0]-x[j][0]; 
-              dis_jk[1]=x[k][1]-x[j][1]; 
-              dis_jk[2]=x[k][2]-x[j][2]; 
+              dis_jk[0]=x[k][0]-x[j][0];
+              dis_jk[1]=x[k][1]-x[j][1];
+              dis_jk[2]=x[k][2]-x[j][2];
               rsq_jk=dis_jk[0]*dis_jk[0]
                   +dis_jk[1]*dis_jk[1]
                   +dis_jk[2]*dis_jk[2];
-              r_jk=sqrt(rsq_jk); 
-              if(r_jk<=rcut[ijk]) { 
+              r_jk=sqrt(rsq_jk);
+              if(r_jk<=rcut[ijk]) {
                 ps=r_jk*rdr[ijk]+1.0;
                 ks=(int)ps;
                 if(nr-1<ks)
                   ks=nr-1;
                 ps=ps-ks;
                 if(ps>1.0)
                   ps=1.0;
                 betaS_jk=((pBetaS3[ijk][ks-1]*ps+pBetaS2[ijk][ks-1])*ps
                     +pBetaS1[ijk][ks-1])*ps+pBetaS[ijk][ks-1];
                 dBetaS_jk=(pBetaS6[ijk][ks-1]*ps+pBetaS5[ijk][ks-1])*ps
                     +pBetaS4[ijk][ks-1];
                 betaP_jk=((pBetaP3[ijk][ks-1]*ps+pBetaP2[ijk][ks-1])*ps
                     +pBetaP1[ijk][ks-1])*ps+pBetaP[ijk][ks-1];
                 dBetaP_jk=(pBetaP6[ijk][ks-1]*ps+pBetaP5[ijk][ks-1])*ps
                     +pBetaP4[ijk][ks-1];
                 cosAng_ijk=(-dis_ij[0]*dis_jk[0]-dis_ij[1]*dis_jk[1]
-                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk); 
+                    -dis_ij[2]*dis_jk[2])/(r_ij*r_jk);
                 dcA_ijk[0][0]=(dis_jk[0]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[0]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][0]=(dis_jk[1]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[1]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][0]=(dis_jk[2]*r_ij*r_jk-cosAng_ijk
                     *-dis_ij[2]*r_jk*r_jk)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[0][1]=(-dis_ij[0]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[0]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[1][1]=(-dis_ij[1]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[1]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 dcA_ijk[2][1]=(-dis_ij[2]*r_ij*r_jk-cosAng_ijk
                     *dis_jk[2]*r_ij*r_ij)/(r_ij*r_ij*r_jk*r_jk);
                 nb_jk=nb_t;
                 nb_t++;
                 if(nb_t>nb_pi) {
                   new_n_tot=nb_pi+maxneigh;
                   grow_pi(nb_pi,new_n_tot);
                   nb_pi=new_n_tot;
                 }
                 bt_pi[nb_jk].i=j;
                 bt_pi[nb_jk].j=k;
                 bt_pi[nb_jk].temp=temp_jk;
                 cosSq=cosAng_ijk*cosAng_ijk;
                 sinFactor=.5*(1.0-cosSq)*pi_p[jtype-1]*betaS_jk;
                 cosFactor=.5*(1.0+cosSq)*betaP_jk;
                 betaCapSq1=pi_p[jtype-1]*betaS_jk*betaS_jk
                     -betaP_jk*betaP_jk;
                 dbetaCapSq1=2.0*pi_p[jtype-1]*betaS_jk*dBetaS_jk
                     -2.0*betaP_jk*dBetaP_jk;
 
-//AA is Eq. 37 (a) and Eq. 19 (b) for j atoms 
+//AA is Eq. 37 (a) and Eq. 19 (b) for j atoms
 //3rd BB is 2nd term of Eq. 38 (a) where i and k =neighbors j
 
                 AA=AA+sinFactor*betaS_jk+cosFactor*betaP_jk;
                 BB=BB+.25*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*betaCapSq1;
 
                 agpdpr1=(2.0*sinFactor*dBetaS_jk+2.0*cosFactor
                     *dBetaP_jk)/r_jk;
 
 //agpdpr1 is derivative of AA for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB for atom j w.r.t. Beta(r_jk)
 //app1 is derivative of AA for j atom w.r.t. cos(theta_ijk)
-//app2 is derivative of BB 2nd term w.r.t. cos(theta_ijk) 
+//app2 is derivative of BB 2nd term w.r.t. cos(theta_ijk)
 
                 agpdpr2=.5*(1.0-cosSq)*(1.0-cosSq)*betaCapSq1*dbetaCapSq1/r_jk;
                 app1=cosAng_ijk*(-pi_p[jtype-1]*betaS_jk*betaS_jk
                     +betaP_jk*betaP_jk);
                 app2=-(1.0-cosSq)*cosAng_ijk*betaCapSq1*betaCapSq1;
                 bt_pi[nb_ij].dAA[0]-=
                     app1*dcA_ijk[0][0];
                 bt_pi[nb_ij].dAA[1]-=
                     app1*dcA_ijk[1][0];
                 bt_pi[nb_ij].dAA[2]-=
                     app1*dcA_ijk[2][0];
                 bt_pi[nb_ij].dBB[0]-=
                     app2*dcA_ijk[0][0];
                 bt_pi[nb_ij].dBB[1]-=
                     app2*dcA_ijk[1][0];
                 bt_pi[nb_ij].dBB[2]-=
                     app2*dcA_ijk[2][0];
                 bt_pi[nb_jk].dAA[0]+=
                     agpdpr1*dis_jk[0]
                     +app1*dcA_ijk[0][1];
                 bt_pi[nb_jk].dAA[1]+=
                     agpdpr1*dis_jk[1]
                     +app1*dcA_ijk[1][1];
                 bt_pi[nb_jk].dAA[2]+=
                     agpdpr1*dis_jk[2]
                     +app1*dcA_ijk[2][1];
                 bt_pi[nb_jk].dBB[0]+=
                     app2*dcA_ijk[0][1]
                     +agpdpr2*dis_jk[0];
                 bt_pi[nb_jk].dBB[1]+=
                     app2*dcA_ijk[1][1]
                     +agpdpr2*dis_jk[1];
                 bt_pi[nb_jk].dBB[2]+=
                     app2*dcA_ijk[2][1]
                     +agpdpr2*dis_jk[2];
-            
+
 //j is a neighbor of i and k and k' are different neighbors of j not equal to i
 
                 for(ltmp=0;ltmp<ktmp;ltmp++) {
                   if(ltmp!=ki) {
                     temp_jkp=BOP_index[j]+ltmp;
                     kp=jlist[ltmp];
                     kptype=map[type[kp]]+1;
                     for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                       ncmp=itypePiBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             break;
                           }
                         }
                       }
                     }
                     if(jtype==kptype)
                       ijkp=jtype-1;
                     else if(jtype<kptype)
                       ijkp=jtype*bop_types-jtype*(jtype+1)/2+kptype-1;
                     else
                       ijkp=kptype*bop_types-kptype*(kptype+1)/2+jtype-1;
-                    dis_jkp[0]=x[kp][0]-x[j][0]; 
-                    dis_jkp[1]=x[kp][1]-x[j][1]; 
-                    dis_jkp[2]=x[kp][2]-x[j][2]; 
+                    dis_jkp[0]=x[kp][0]-x[j][0];
+                    dis_jkp[1]=x[kp][1]-x[j][1];
+                    dis_jkp[2]=x[kp][2]-x[j][2];
                     rsq_jkp=dis_jkp[0]*dis_jkp[0]
                         +dis_jkp[1]*dis_jkp[1]
                         +dis_jkp[2]*dis_jkp[2];
-                    r_jkp=sqrt(rsq_jkp); 
+                    r_jkp=sqrt(rsq_jkp);
                     if(r_jkp<=rcut[ijkp]) {
                       ps=r_jkp*rdr[ijkp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_jkp=((pBetaS3[ijkp][ks-1]*ps+pBetaS2[ijkp][ks-1])*ps
                           +pBetaS1[ijkp][ks-1])*ps+pBetaS[ijkp][ks-1];
                       dBetaS_jkp=(pBetaS6[ijkp][ks-1]*ps+pBetaS5[ijkp][ks-1])*ps
                           +pBetaS4[ijkp][ks-1];
                       betaP_jkp=((pBetaP3[ijkp][ks-1]*ps+pBetaP2[ijkp][ks-1])*ps
                           +pBetaP1[ijkp][ks-1])*ps+pBetaP[ijkp][ks-1];
                       dBetaP_jkp=(pBetaP6[ijkp][ks-1]*ps+pBetaP5[ijkp][ks-1])*ps
                           +pBetaP4[ijkp][ks-1];
                       cosAng_ijkp=(-dis_ij[0]*dis_jkp[0]-dis_ij[1]*dis_jkp[1]
-                          -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp); 
+                          -dis_ij[2]*dis_jkp[2])/(r_ij*r_jkp);
                       dcA_ijkp[0][0]=(dis_jkp[0]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[0]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][0]=(dis_jkp[1]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[1]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][0]=(dis_jkp[2]*r_ij*r_jkp-cosAng_ijkp
                           *-dis_ij[2]*r_jkp*r_jkp)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[0][1]=(-dis_ij[0]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[0]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[1][1]=(-dis_ij[1]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[1]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       dcA_ijkp[2][1]=(-dis_ij[2]*r_ij*r_jkp-cosAng_ijkp
                           *dis_jkp[2]*r_ij*r_ij)/(r_ij*r_ij*r_jkp*r_jkp);
                       cosAng_kjkp=(dis_jk[0]*dis_jkp[0]+dis_jk[1]*dis_jkp[1]
-                          +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp); 
+                          +dis_jk[2]*dis_jkp[2])/(r_jk*r_jkp);
                       dcA_kjkp[0][0]=(dis_jkp[0]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jk[0]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][0]=(dis_jkp[1]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jk[1]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][0]=(dis_jkp[2]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jk[2]*r_jkp*r_jkp)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[0][1]=(dis_jk[0]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jkp[0]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[1][1]=(dis_jk[1]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jkp[1]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       dcA_kjkp[2][1]=(dis_jk[2]*r_jk*r_jkp-cosAng_kjkp
                           *dis_jkp[2]*r_jk*r_jk)/(r_jk*r_jk*r_jkp*r_jkp);
                       nb_jkp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                     bt_pi[nb_jkp].i=j;
                     bt_pi[nb_jkp].j=kp;
                     bt_pi[nb_jkp].temp=temp_jkp;
                     betaCapSq2=pi_p[jtype-1]*betaS_jkp*betaS_jkp
                       -betaP_jkp*betaP_jkp;
                     dbetaCapSq2=2.0*pi_p[jtype-1]*betaS_jkp*dBetaS_jkp
                       -2.0*betaP_jkp*dBetaP_jkp;
                     cosSq1=cosAng_ijkp*cosAng_ijkp;
                     angFactor=cosAng_kjkp-cosAng_ijkp*cosAng_ijk;
                     angFactor1=4.0*angFactor;
                     angFactor2=-angFactor1*cosAng_ijkp
                       +2.0*cosAng_ijk*(1.0-cosSq1);
                     angFactor3=-angFactor1*cosAng_ijk
                       +2.0*cosAng_ijkp*(1.0-cosSq);
                     angFactor4=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //4th BB is 4th term of Eq. 38 (a) where i , k and k' =neighbors j
 
                     BB=BB+betaCapSum*angFactor4;
 
-//app1 is derivative of BB 4th term w.r.t. cos(theta_kjk') 
-//app2 is derivative of BB 4th term w.r.t. cos(theta_ijk) 
-//app3 is derivative of BB 4th term w.r.t. cos(theta_ijk') 
+//app1 is derivative of BB 4th term w.r.t. cos(theta_kjk')
+//app2 is derivative of BB 4th term w.r.t. cos(theta_ijk)
+//app3 is derivative of BB 4th term w.r.t. cos(theta_ijk')
 //agpdpr1 is derivative of BB 4th term for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB 4th term for atom j w.r.t. Beta(r_jk')
 
                     app1=betaCapSum*angFactor1;
                     app2=betaCapSum*angFactor2;
                     app3=betaCapSum*angFactor3;
                     agpdpr1=.5*angFactor4*dbetaCapSq1*betaCapSq2/r_jk;
                     agpdpr2=.5*angFactor4*betaCapSq1*dbetaCapSq2/r_jkp;
                     bt_pi[nb_ij].dBB[0]-=
                       app3*dcA_ijkp[0][0]
-                      +app2*dcA_ijk[0][0]; 
+                      +app2*dcA_ijk[0][0];
                     bt_pi[nb_ij].dBB[1]-=
                       app3*dcA_ijkp[1][0]
-                      +app2*dcA_ijk[1][0]; 
+                      +app2*dcA_ijk[1][0];
                     bt_pi[nb_ij].dBB[2]-=
                       app3*dcA_ijkp[2][0]
-                      +app2*dcA_ijk[2][0]; 
+                      +app2*dcA_ijk[2][0];
                     bt_pi[nb_jk].dBB[0]+=
                       agpdpr1*dis_jk[0]
                       +app1*dcA_kjkp[0][0]
                       +app2*dcA_ijk[0][1];
                     bt_pi[nb_jk].dBB[1]+=
                       agpdpr1*dis_jk[1]
                       +app1*dcA_kjkp[1][0]
                       +app2*dcA_ijk[1][1];
                     bt_pi[nb_jk].dBB[2]+=
                       agpdpr1*dis_jk[2]
                       +app1*dcA_kjkp[2][0]
                       +app2*dcA_ijk[2][1];
                     bt_pi[nb_jkp].dBB[0]+=
                       agpdpr2*dis_jkp[0]
                       +app1*dcA_kjkp[0][1]
                       +app3*dcA_ijkp[0][1];
                     bt_pi[nb_jkp].dBB[1]+=
                       agpdpr2*dis_jkp[1]
                       +app1*dcA_kjkp[1][1]
                       +app3*dcA_ijkp[1][1];
                     bt_pi[nb_jkp].dBB[2]+=
                       agpdpr2*dis_jkp[2]
                       +app1*dcA_kjkp[2][1]
                       +app3*dcA_ijkp[2][1];
                     }
                   }
                 }
 
 //j and k' are different neighbors of i and k is a neighbor of j not equal to i
 
                 for(ltmp=0;ltmp<numneigh[i];ltmp++) {
                   if(ltmp!=jtmp) {
                     temp_ikp=BOP_index[i]+ltmp;
                     kp=iilist[ltmp];
                     kptype=map[type[kp]]+1;
                     for(nsearch=0;nsearch<nPiBk[n];nsearch++) {
                       ncmp=itypePiBk[n][nsearch];
                       if(x[ncmp][0]==x[kp][0]) {
                         if(x[ncmp][1]==x[kp][1]) {
                           if(x[ncmp][2]==x[kp][2]) {
                             break;
                           }
                         }
                       }
                     }
                     if(itype==kptype)
                       iikp=itype-1;
                     else if(itype<kptype)
                       iikp=itype*bop_types-itype*(itype+1)/2+kptype-1;
                     else
                       iikp=kptype*bop_types-kptype*(kptype+1)/2+itype-1;
-                    dis_ikp[0]=x[kp][0]-x[i][0]; 
-                    dis_ikp[1]=x[kp][1]-x[i][1]; 
-                    dis_ikp[2]=x[kp][2]-x[i][2]; 
+                    dis_ikp[0]=x[kp][0]-x[i][0];
+                    dis_ikp[1]=x[kp][1]-x[i][1];
+                    dis_ikp[2]=x[kp][2]-x[i][2];
                     rsq_ikp=dis_ikp[0]*dis_ikp[0]
                         +dis_ikp[1]*dis_ikp[1]
                         +dis_ikp[2]*dis_ikp[2];
-                    r_ikp=sqrt(rsq_ikp); 
+                    r_ikp=sqrt(rsq_ikp);
                     if(r_ikp<=rcut[iikp]) {
                       ps=r_ikp*rdr[iikp]+1.0;
                       ks=(int)ps;
                       if(nr-1<ks)
                         ks=nr-1;
                       ps=ps-ks;
                       if(ps>1.0)
                         ps=1.0;
                       betaS_ikp=((pBetaS3[iikp][ks-1]*ps+pBetaS2[iikp][ks-1])*ps
                           +pBetaS1[iikp][ks-1])*ps+pBetaS[iikp][ks-1];
                       dBetaS_ikp=(pBetaS6[iikp][ks-1]*ps+pBetaS5[iikp][ks-1])*ps
                           +pBetaS4[iikp][ks-1];
                       betaP_ikp=((pBetaP3[iikp][ks-1]*ps+pBetaP2[iikp][ks-1])*ps
                           +pBetaP1[iikp][ks-1])*ps+pBetaP[iikp][ks-1];
                       dBetaP_ikp=(pBetaP6[iikp][ks-1]*ps+pBetaP5[iikp][ks-1])*ps
                           +pBetaP4[iikp][ks-1];
                       cosAng_jikp=(dis_ij[0]*dis_ikp[0]+dis_ij[1]*dis_ikp[1]
-                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp); 
+                          +dis_ij[2]*dis_ikp[2])/(r_ij*r_ikp);
                       dcA_jikp[0][0]=(dis_ikp[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[0]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][0]=(dis_ikp[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[1]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][0]=(dis_ikp[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ij[2]*r_ikp*r_ikp)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[0][1]=(dis_ij[0]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[0]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[1][1]=(dis_ij[1]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[1]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       dcA_jikp[2][1]=(dis_ij[2]*r_ij*r_ikp-cosAng_jikp
                           *dis_ikp[2]*r_ij*r_ij)/(r_ij*r_ij*r_ikp*r_ikp);
                       nb_ikp=nb_t;
                       nb_t++;
                       if(nb_t>nb_pi) {
                         new_n_tot=nb_pi+maxneigh;
                         grow_pi(nb_pi,new_n_tot);
                         nb_pi=new_n_tot;
                       }
                       bt_pi[nb_ikp].i=i;
                       bt_pi[nb_ikp].j=kp;
                       bt_pi[nb_ikp].temp=temp_ikp;
-                
+
                       betaCapSq2=pi_p[itype-1]*betaS_ikp*betaS_ikp
                           -betaP_ikp*betaP_ikp;
                       dbetaCapSq2=2.0*pi_p[itype-1]*betaS_ikp*dBetaS_ikp
                           -2.0*betaP_ikp*dBetaP_ikp;
                       dotV=(dis_jk[0]*dis_ikp[0]+dis_jk[1]
                           *dis_ikp[1]+dis_jk[2]*dis_ikp[2])
                           /(r_jk*r_ikp);
                       cosSq1=cosAng_jikp*cosAng_jikp;
                       angFactor=dotV+cosAng_jikp*cosAng_ijk;
                       angRfactor=4.0*angFactor*dotV;
                       dAngR1=-angRfactor/r_jk;
                       dAngR2=-angRfactor/r_ikp;
                       angFactor1=4.0*angFactor*cosAng_jikp
                           +2.0*cosAng_ijk*(1.0-cosSq1);
                       angFactor2=4.0*angFactor*cosAng_ijk
                           +2.0*cosAng_jikp*(1.0-cosSq);
                       angFactor3=2.0*angFactor*angFactor-(1.0-cosSq)*(1.0-cosSq1);
                       betaCapSum=.5*betaCapSq1*betaCapSq2;
 
 //5th BB is 5th term of Eq. 38 (a) Eq. 21 (b) where i , k and k' =neighbors j
 
                       BB=BB+betaCapSum*angFactor3;
 
-//app1 is derivative of BB 5th term w.r.t. cos(theta_ijk) 
-//app2 is derivative of BB 5th term w.r.t. cos(theta_jik') 
+//app1 is derivative of BB 5th term w.r.t. cos(theta_ijk)
+//app2 is derivative of BB 5th term w.r.t. cos(theta_jik')
 //agpdpr1 is derivative of BB 5th term for atom j w.r.t. Beta(r_jk)
 //agpdpr2 is derivative of BB 5th term for atom j w.r.t. Beta(r_ik')
 //agpdpr3 is derivative of BB 5th term for atom j w.r.t. dot(r_ik',r_ij)
 
                       app1=betaCapSum*angFactor1;
                       app2=betaCapSum*angFactor2;
                       agpdpr1=(.5*angFactor3*dbetaCapSq1*betaCapSq2
                           +betaCapSum*dAngR1)/r_jk;
                       agpdpr2=(.5*angFactor3*betaCapSq1*dbetaCapSq2
                           +betaCapSum*dAngR2)/r_ikp;
                       agpdpr3=4.0*betaCapSum*angFactor/(r_ikp*r_jk);
                       bt_pi[nb_ij].dBB[0]+=
                           +app2*dcA_jikp[0][0]
                           -app1*dcA_ijk[0][0];
                       bt_pi[nb_ij].dBB[1]+=
                           +app2*dcA_jikp[1][0]
                           -app1*dcA_ijk[1][0];
                       bt_pi[nb_ij].dBB[2]+=
                           +app2*dcA_jikp[2][0]
                           -app1*dcA_ijk[2][0];
                       bt_pi[nb_ikp].dBB[0]+=
                           agpdpr2*dis_ikp[0]
                           +agpdpr3*dis_jk[0]
                           +app2*dcA_jikp[0][1];
                       bt_pi[nb_ikp].dBB[1]+=
                           agpdpr2*dis_ikp[1]
                           +agpdpr3*dis_jk[1]
                           +app2*dcA_jikp[1][1];
                       bt_pi[nb_ikp].dBB[2]+=
                           agpdpr2*dis_ikp[2]
                           +agpdpr3*dis_jk[2]
                           +app2*dcA_jikp[2][1];
                       bt_pi[nb_jk].dBB[0]+=
                           agpdpr1*dis_jk[0]
                           +agpdpr3*dis_ikp[0]
                           +app1*dcA_ijk[0][1];
                       bt_pi[nb_jk].dBB[1]+=
                           agpdpr1*dis_jk[1]
                           +agpdpr3*dis_ikp[1]
                           +app1*dcA_ijk[1][1];
                       bt_pi[nb_jk].dBB[2]+=
                           agpdpr1*dis_jk[2]
                           +agpdpr3*dis_ikp[2]
                           +app1*dcA_ijk[2][1];
                     }
                   }
                 }
                 if(pi_flag==0)
                   nPiBk[n]=nPiBk[n]+1;
               }
             }
           }
           CC=betaP_ij*betaP_ij+pi_delta[iij]*pi_delta[iij];
           BBrt=sqrt(BB+small6);
           AB1=CC+pi_c[iij]*(AA+BBrt)+small7;
           AB2=CC+pi_c[iij]*(AA-BBrt+sqrt(small6))+small7;
           BBrtR=1.0/BBrt;
           ABrtR1=1.0/sqrt(AB1);
           ABrtR2=1.0/sqrt(AB2);
 
 // piB is similary formulation to (a) Eq. 36 and (b) Eq. 18
 
           piB[n]=(ABrtR1+ABrtR2)*pi_a[iij]*betaP_ij;
           dPiB1=-.5*(pow(ABrtR1,3)+pow(ABrtR2,3))*pi_c[iij]*pi_a[iij]*betaP_ij;
           dPiB2=.25*BBrtR*(pow(ABrtR2,3)-pow(ABrtR1,3))*pi_c[iij]*pi_a[iij]*betaP_ij;
           dPiB3=((ABrtR1+ABrtR2)*pi_a[iij]-(pow(ABrtR1,3)+pow(ABrtR2,3))*pi_a[iij]
               *betaP_ij*betaP_ij)*dBetaP_ij/r_ij;
           n++;
-          
+
           pp2=2.0*betaP_ij;
           for(m=0;m<nb_t;m++) {
             bt_i=bt_pi[m].i;
             bt_j=bt_pi[m].j;
             xtmp[0]=x[bt_j][0]-x[bt_i][0];
             xtmp[1]=x[bt_j][1]-x[bt_i][1];
             xtmp[2]=x[bt_j][2]-x[bt_i][2];
-            for(pp=0;pp<3;pp++) { 
+            for(pp=0;pp<3;pp++) {
               bt_pi[m].dPiB[pp]=
                   +dPiB1*bt_pi[m].dAA[pp]
                   +dPiB2*bt_pi[m].dBB[pp];
               ftmp[pp]=pp2*bt_pi[m].dPiB[pp];
               f[bt_i][pp]-=ftmp[pp];
               f[bt_j][pp]+=ftmp[pp];
             }
             if(evflag) {
               ev_tally_xyz(bt_i,bt_j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                   ,ftmp[2],xtmp[0],xtmp[1],xtmp[2]);
             }
           }
-          for(pp=0;pp<3;pp++) { 
+          for(pp=0;pp<3;pp++) {
             ftmp[pp]=pp2*dPiB3*dis_ij[pp];
             f[i][pp]-=ftmp[pp];
             f[j][pp]+=ftmp[pp];
           }
           if(evflag) {
             ev_tally_xyz(i,j,nlocal,newton_pair,0.0,0.0,ftmp[0],ftmp[1]
                 ,ftmp[2],dis_ij[0],dis_ij[1],dis_ij[2]);
           }
         }
       }
     }
   }
   destroy_pi();
 }
- 
+
 /* ----------------------------------------------------------------------
    read BOP potential file
 ------------------------------------------------------------------------- */
 
 void PairBOP::read_file(char *filename)
 {
   int i,j,k;
   int ij,ii,jj;
   int buf1;
   int n;
   double buf2;
   char s[MAXLINE];
   char buf[2];
 
   MPI_Comm_rank(world,&me);
-  
+
 // read file on proc 0
 
   rcore=0.1;
 
   if (me == 0) {
     FILE *fp = fopen(filename,"r");
     if (fp == NULL) {
       char str[128];
       sprintf(str,"Cannot open BOP potential file %s",filename);
       error->one(FLERR,str);
     }
 
 // read parameters
 
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%d",&bop_types);
     fclose(fp);
     npairs=bop_types*(bop_types+1)/2;
   }
   MPI_Bcast(&bop_types,1,MPI_INT,0,world);
   MPI_Bcast(&npairs,1,MPI_INT,0,world);
   allocate();
   memory->create(pi_a,npairs,"BOP:pi_a");
   memory->create(pro_delta,bop_types,"BOP:pro_delta");
   memory->create(pi_delta,npairs,"BOP:pi_delta");
   memory->create(pi_p,bop_types,"BOP:pi_p");
   memory->create(pi_c,npairs,"BOP:pi_c");
   memory->create(sigma_r0,npairs,"BOP:sigma_r0");
   memory->create(pi_r0,npairs,"BOP:pi_r0");
   memory->create(phi_r0,npairs,"BOP:phi_r0");
   memory->create(sigma_rc,npairs,"BOP:sigma_rc");
   memory->create(pi_rc,npairs,"BOP:pi_rc");
   memory->create(phi_rc,npairs,"BOP:phi_rc");
   memory->create(r1,npairs,"BOP:r1");
   memory->create(sigma_beta0,npairs,"BOP:sigma_beta0");
   memory->create(pi_beta0,npairs,"BOP:pi_beta0");
   memory->create(phi0,npairs,"BOP:phi0");
   memory->create(sigma_n,npairs,"BOP:sigma_n");
   memory->create(pi_n,npairs,"BOP:pi_n");
   memory->create(phi_m,npairs,"BOP:phi_m");
   memory->create(sigma_nc,npairs,"BOP:sigma_nc");
   memory->create(pi_nc,npairs,"BOP:pi_nc");
   memory->create(phi_nc,npairs,"BOP:phi_nc");
   memory->create(pro,bop_types,"BOP:pro");
   memory->create(sigma_delta,npairs,"BOP:sigma_delta");
   memory->create(sigma_c,npairs,"BOP:sigma_c");
   memory->create(sigma_a,npairs,"BOP:sigma_a");
   memory->create(sigma_g0,bop_types
       ,bop_types,bop_types,"BOP:sigma_g0");
   memory->create(sigma_g1,bop_types
       ,bop_types,bop_types,"BOP:sigma_g1");
   memory->create(sigma_g2,bop_types
       ,bop_types,bop_types,"BOP:sigma_g2");
   memory->create(sigma_g3,bop_types
       ,bop_types,bop_types,"BOP:sigma_g3");
   memory->create(sigma_g4,bop_types
       ,bop_types,bop_types,"BOP:sigma_g4");
   memory->create(sigma_f,npairs,"BOP:sigma_f");
   memory->create(sigma_k,npairs,"BOP:sigma_k");
   memory->create(small3,npairs,"BOP:small3");
 
   if (me == 0) {
     words = new char*[bop_types];
     for(i=0;i<bop_types;i++) words[i]=NULL;
     FILE *fp = fopen(filename,"r");
     if (fp == NULL) {
       char str[128];
       sprintf(str,"Cannot open BOP potential file %s",filename);
       error->one(FLERR,str);
     }
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     for(i=0;i<bop_types;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%d %lf %s",&buf1,&buf2,buf);
       n= strlen(buf)+1;
       words[i] = new char[n];
       strcpy(words[i],buf);
     }
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf%lf%lf%lf%lf%lf",&small1,&small2,&small3g,&small4
         ,&small5,&small6,&small7);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%d%lf%lf",&ncutoff,&rbig,&rsmall);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf%d",&which,&alpha,&nfunc);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf%lf",&alpha1,&beta1,&gamma1);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf",&alpha2,&beta2);
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf",&alpha3,&beta3);
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     for(i=0;i<bop_types;i++) {
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&pro[i],&pro_delta[i],&pi_p[i]);
     }
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     cutmax=0;
-    
+
     for(i=0;i<bop_types;i++) {
       ii=i+1;
       for(j=i;j<bop_types;j++) {
         jj=j+1;
         if(ii==jj)
           ij=ii-1;
         else if(ii<jj)
           ij=ii*bop_types-ii*(ii+1)/2+jj-1;
         else
           ij=jj*bop_types-jj*(jj+1)/2+ii-1;
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf%lf",&sigma_r0[ij],&sigma_rc[ij],&r1[ij],&rcut[ij]);
         if(rcut[ij]>cutmax)
           cutmax=rcut[ij];
         pi_r0[ij]=sigma_r0[ij];
         phi_r0[ij]=sigma_r0[ij];
         pi_rc[ij]=sigma_rc[ij];
         phi_rc[ij]=sigma_rc[ij];
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&phi_m[ij],&sigma_n[ij],&sigma_nc[ij]);
         pi_n[ij]=sigma_n[ij];
         pi_nc[ij]=sigma_nc[ij];
         phi_nc[ij]=sigma_nc[ij];
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&phi0[ij],&sigma_beta0[ij],&pi_beta0[ij]);
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&sigma_a[ij],&sigma_c[ij],&sigma_delta[ij]);
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&pi_a[ij],&pi_c[ij],&pi_delta[ij]);
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf",&sigma_f[ij],&sigma_k[ij],&small3[ij]);
       }
     }
     fgets(s,MAXLINE,fp);
     fgets(s,MAXLINE,fp);
     for(i=0;i<bop_types;i++) {
       for(j=0;j<bop_types;j++) {
         for(k=j;k<bop_types;k++) {
           fgets(s,MAXLINE,fp);
           sscanf(s,"%lf%lf%lf",&sigma_g0[j][i][k],&sigma_g1[j][i][k]
               ,&sigma_g2[j][i][k]);
           sigma_g0[k][i][j]=sigma_g0[j][i][k];
           sigma_g1[k][i][j]=sigma_g1[j][i][k];
           sigma_g2[k][i][j]=sigma_g2[j][i][k];
         }
       }
     }
     for(i=0;i<npairs;i++) {
       dr[i]=rcut[i]/(nr-1.0);
       rdr[i]=1.0/dr[i];
     }
     fclose(fp);
   }
   MPI_Bcast(&small1,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small2,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small3g,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small4,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small5,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small6,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small7,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&ncutoff,1,MPI_INT,0,world);
   MPI_Bcast(&rbig,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&rsmall,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&which,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&alpha,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&nfunc,1,MPI_INT,0,world);
   MPI_Bcast(&alpha1,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&beta1,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&gamma1,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&alpha2,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&beta2,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&alpha3,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&beta3,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&pro[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&pro_delta[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_p[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_r0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_rc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&r1[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&rcut[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&cutmax,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_r0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&phi_r0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_rc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&phi_rc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&phi_m[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_n[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_nc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_n[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_nc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&phi_nc[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&phi0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_beta0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_beta0[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_a[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_c[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_delta[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_a[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_c[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_delta[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_f[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_k[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&small3[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g0[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g1[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g2[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g3[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g4[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&dr[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&rdr[0],npairs,MPI_DOUBLE,0,world);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::read_table(char *filename)
 {
   int i,j,k,n;
   int buf1;
   double buf2;
   char s[MAXLINE],buf[2];
 
   MPI_Comm_rank(world,&me);
 
   if (me == 0) {
     FILE *fp = fopen(filename,"r");
     if (fp == NULL) {
       char str[128];
       sprintf(str,"Cannot open BOP potential file %s",filename);
       error->one(FLERR,str);
     }
     fgets(s,MAXLINE,fp);
     sscanf(s,"%d",&bop_types);
     words = new char*[bop_types];
     for(i=0;i<bop_types;i++) words[i]=NULL;
     for(i=0;i<bop_types;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%d %lf %s",&buf1,&buf2,buf);
       n= strlen(buf)+1;
       words[i] = new char[n];
       strcpy(words[i],buf);
     }
     fgets(s,MAXLINE,fp);
     sscanf(s,"%d %d",&nr,&nBOt);
     fclose(fp);
     npairs=bop_types*(bop_types+1)/2;
   }
 
   MPI_Bcast(&nr,1,MPI_INT,0,world);
   MPI_Bcast(&nBOt,1,MPI_INT,0,world);
   MPI_Bcast(&bop_types,1,MPI_INT,0,world);
   MPI_Bcast(&npairs,1,MPI_INT,0,world);
   memory->create(pi_a,npairs,"BOP:pi_a");
   memory->create(pro_delta,bop_types,"BOP:pro_delta");
   memory->create(pi_delta,npairs,"BOP:pi_delta");
   memory->create(pi_p,bop_types,"BOP:pi_p");
   memory->create(pi_c,npairs,"BOP:pi_c");
   memory->create(r1,npairs,"BOP:r1");
   memory->create(pro,bop_types,"BOP:pro");
   memory->create(sigma_delta,npairs,"BOP:sigma_delta");
   memory->create(sigma_c,npairs,"BOP:sigma_c");
   memory->create(sigma_a,npairs,"BOP:sigma_a");
   memory->create(sigma_g0,bop_types
       ,bop_types,bop_types,"BOP:sigma_g0");
   memory->create(sigma_g1,bop_types
       ,bop_types,bop_types,"BOP:sigma_g1");
   memory->create(sigma_g2,bop_types
       ,bop_types,bop_types,"BOP:sigma_g2");
   memory->create(sigma_f,npairs,"BOP:sigma_f");
   memory->create(sigma_k,npairs,"BOP:sigma_k");
   memory->create(small3,npairs,"BOP:small3");
   allocate();
 
   if (me == 0) {
     FILE *fp = fopen(filename,"r");
     if (fp == NULL) {
       char str[128];
       sprintf(str,"Cannot open BOP potential file %s",filename);
       error->one(FLERR,str);
     }
     for(i=0;i<bop_types+2;i++) {
       fgets(s,MAXLINE,fp);
     }
     fgets(s,MAXLINE,fp);
     sscanf(s,"%lf%lf%lf%lf%lf%lf%lf",&small1,&small2,&small3g
         ,&small4,&small5,&small6,&small7);
     for(i=0;i<bop_types;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf",&pi_p[i]);
     }
     cutmax=0;
     for(i=0;i<npairs;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf",&rcut[i]);
       if(rcut[i]>cutmax)
         cutmax=rcut[i];
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf%lf%lf%lf",&sigma_c[i],&sigma_a[i],&pi_c[i],&pi_a[i]);
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf%lf",&sigma_delta[i],&pi_delta[i]);
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf%lf%lf",&sigma_f[i],&sigma_k[i],&small3[i]);
-    }    
-    for(i=0;i<bop_types;i++) 
+    }
+    for(i=0;i<bop_types;i++)
       for(j=0;j<bop_types;j++)
         for(k=0;k<bop_types;k++) {
           fgets(s,MAXLINE,fp);
           sscanf(s,"%lf%lf%lf",&sigma_g0[i][j][k],&sigma_g1[i][j][k],&sigma_g2[i][j][k]);
         }
     for(i=0;i<npairs;i++) {
-      for(j=0;j<nr;j++) { 
+      for(j=0;j<nr;j++) {
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf%lf%lf",&pRepul[i][j],&pRepul[i][j+1]
             ,&pRepul[i][j+2],&pRepul[i][j+3],&pRepul[i][j+4]);
         j+=4;
       }
     }
     for(i=0;i<npairs;i++) {
-      for(j=0;j<nr;j++) { 
+      for(j=0;j<nr;j++) {
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf%lf%lf",&pBetaS[i][j],&pBetaS[i][j+1]
             ,&pBetaS[i][j+2],&pBetaS[i][j+3],&pBetaS[i][j+4]);
         j+=4;
       }
     }
     for(i=0;i<npairs;i++) {
-      for(j=0;j<nr;j++) { 
+      for(j=0;j<nr;j++) {
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf%lf%lf",&pBetaP[i][j],&pBetaP[i][j+1]
             ,&pBetaP[i][j+2],&pBetaP[i][j+3],&pBetaP[i][j+4]);
         j+=4;
       }
     }
     for(i=0;i<npairs;i++) {
-      for(j=0;j<nBOt;j++) { 
+      for(j=0;j<nBOt;j++) {
         fgets(s,MAXLINE,fp);
         sscanf(s,"%lf%lf%lf%lf%lf",&FsigBO[i][j],&FsigBO[i][j+1]
             ,&FsigBO[i][j+2],&FsigBO[i][j+3],&FsigBO[i][j+4]);
         j+=4;
       }
     }
     for(i=0;i<bop_types;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf",&pro_delta[i]);
     }
     for(i=0;i<bop_types;i++) {
       fgets(s,MAXLINE,fp);
       sscanf(s,"%lf",&pro[i]);
     }
     for(i=0;i<npairs;i++) {
-      dr[i]=rcut[i]/((double)nr-1.0); 
+      dr[i]=rcut[i]/((double)nr-1.0);
       rdr[i]=1.0/dr[i];
     }
     dBO=1.0/((double)nBOt-1.0);
     rdBO=1.0/(double)dBO;
 
     for(i=0;i<npairs;i++) {
       pBetaS1[i][0]=pBetaS[i][1]-pBetaS[i][0];
       pBetaS1[i][1]=0.5*(pBetaS[i][2]-pBetaS[i][0]);
       pBetaS1[i][nr-2]=0.5*(pBetaS[i][nr-1]-pBetaS[i][nr-3]);
       pBetaS1[i][nr-1]=pBetaS[i][nr-1]-pBetaS[i][nr-2];
       pBetaP1[i][0]=pBetaP[i][1]-pBetaP[i][0];
       pBetaP1[i][1]=0.5*(pBetaP[i][2]-pBetaP[i][0]);
       pBetaP1[i][nr-2]=0.5*(pBetaP[i][nr-1]-pBetaP[i][nr-3]);
       pBetaP1[i][nr-1]=pBetaP[i][nr-1]-pBetaP[i][nr-2];
       pRepul1[i][0]=pRepul[i][1]-pRepul[i][0];
       pRepul1[i][1]=0.5*(pRepul[i][2]-pRepul[i][0]);
       pRepul1[i][nr-2]=0.5*(pRepul[i][nr-1]-pRepul[i][nr-3]);
       pRepul1[i][nr-1]=pRepul[i][nr-1]-pRepul[i][nr-2];
       FsigBO1[i][0]=FsigBO[i][1]-FsigBO[i][0];
       FsigBO1[i][1]=0.5*(FsigBO[i][2]-FsigBO[i][0]);
       FsigBO1[i][nBOt-2]=0.5*(FsigBO[i][nBOt-1]-FsigBO[i][nBOt-3]);
       FsigBO1[i][nBOt-1]=FsigBO[i][nBOt-1]-FsigBO[i][nBOt-2];
       for(k=2;k<nr-2;k++) {
         pBetaS1[i][k]=((pBetaS[i][k-2]-pBetaS[i][k+2])
             +8.0*(pBetaS[i][k+1]-pBetaS[i][k-1]))/12.0;
         pBetaP1[i][k]=((pBetaP[i][k-2]-pBetaP[i][k+2])
             +8.0*(pBetaP[i][k+1]-pBetaP[i][k-1]))/12.0;
         pRepul1[i][k]=((pRepul[i][k-2]-pRepul[i][k+2])
             +8.0*(pRepul[i][k+1]-pRepul[i][k-1]))/12.0;
       }
       for(k=2;k<nr-2;k++) {
         FsigBO1[i][k]=((FsigBO[i][k-2]-FsigBO[i][k+2])
             +8.0*(FsigBO[i][k+1]-FsigBO[i][k-1]))/12.0;
       }
       for(k=0;k<nr-1;k++) {
         pBetaS2[i][k]=3.0*(pBetaS[i][k+1]-pBetaS[i][k])
             -2.0*pBetaS1[i][k]-pBetaS1[i][k+1];
         pBetaS3[i][k]=pBetaS1[i][k]+pBetaS1[i][k+1]
             -2.0*(pBetaS[i][k+1]-pBetaS[i][k]);
         pBetaP2[i][k]=3.0*(pBetaP[i][k+1]-pBetaP[i][k])
             -2.0*pBetaP1[i][k]-pBetaP1[i][k+1];
         pBetaP3[i][k]=pBetaP1[i][k]+pBetaP1[i][k+1]
             -2.0*(pBetaP[i][k+1]-pBetaP[i][k]);
         pRepul2[i][k]=3.0*(pRepul[i][k+1]-pRepul[i][k])
             -2.0*pRepul1[i][k]-pRepul1[i][k+1];
         pRepul3[i][k]=pRepul1[i][k]+pRepul1[i][k+1]
             -2.0*(pRepul[i][k+1]-pRepul[i][k]);
       }
       for(k=0;k<nBOt-1;k++) {
         FsigBO2[i][k]=3.0*(FsigBO[i][k+1]-FsigBO[i][k])
             -2.0*FsigBO1[i][k]-FsigBO1[i][k+1];
         FsigBO3[i][k]=FsigBO1[i][k]+FsigBO1[i][k+1]
             -2.0*(FsigBO[i][k+1]-FsigBO[i][k]);
       }
       pBetaS2[i][nr-1]=0.0;
       pBetaS3[i][nr-1]=0.0;
       pBetaP2[i][nr-1]=0.0;
       pBetaP3[i][nr-1]=0.0;
       pRepul2[i][nr-1]=0.0;
       pRepul3[i][nr-1]=0.0;
       FsigBO2[i][nBOt-1]=0.0;
       FsigBO3[i][nBOt-1]=0.0;
       for(k=0;k<nr;k++) {
         pBetaS4[i][k]=pBetaS1[i][k]/dr[i];
         pBetaS5[i][k]=2.0*pBetaS2[i][k]/dr[i];
         pBetaS6[i][k]=3.0*pBetaS3[i][k]/dr[i];
         pBetaP4[i][k]=pBetaP1[i][k]/dr[i];
         pBetaP5[i][k]=2.0*pBetaP2[i][k]/dr[i];
         pBetaP6[i][k]=3.0*pBetaP3[i][k]/dr[i];
         pRepul4[i][k]=pRepul1[i][k]/dr[i];
         pRepul5[i][k]=2.0*pRepul2[i][k]/dr[i];
         pRepul6[i][k]=3.0*pRepul3[i][k]/dr[i];
       }
       for(k=0;k<nBOt;k++) {
         FsigBO4[i][k]=FsigBO1[i][k]/dBO;
         FsigBO5[i][k]=2.0*FsigBO2[i][k]/dBO;
         FsigBO6[i][k]=3.0*FsigBO3[i][k]/dBO;
       }
     }
     fclose(fp);
   }
   MPI_Bcast(&rdBO,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&dBO,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&bop_types,1,MPI_INT,0,world);
   MPI_Bcast(&small1,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small2,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small3g,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small4,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small5,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small6,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&small7,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&pro[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&pro_delta[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_p[0],bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&r1[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&rcut[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&cutmax,1,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_a[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_c[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_delta[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_a[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_c[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pi_delta[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_f[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_k[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&small3[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g0[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g1[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&sigma_g2[0][0][0],bop_types*bop_types*bop_types,MPI_DOUBLE,0,world);
   MPI_Bcast(&dr[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&rdr[0],npairs,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS1[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS2[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS3[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS4[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS5[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaS6[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP1[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP2[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP3[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP4[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP5[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pBetaP6[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul1[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul2[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul3[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul4[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul5[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&pRepul6[0][0],npairs*nr,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO1[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO2[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO3[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO4[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO5[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
   MPI_Bcast(&FsigBO6[0][0],npairs*nBOt,MPI_DOUBLE,0,world);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::setPbetaS()
 {
   int i,j,k;
   double r,value,dvalue;
- 
+
   for(i=0;i<npairs;i++) {
     for(j=0;j<nr;j++) {
       r=(double)j*dr[i];
       if(r<rcore)
         r=rcore;
       if(ncutoff==3) {
         if(r>=rcut[i])
           pBetaS[i][j]=0.0;
         else if(r<=r1[i]) {
           value=betaSfunc(i,r);
           dvalue=dBetaSfunc(i,r,value,1.0);
           pBetaS[i][j]=value;
         }
         else {
           value=betaSfunc(i,r1[i]);
           dvalue=dBetaSfunc(i,r1[i],value,1.0);
           pBetaS[i][j]=-(r-rcut[i])*(r-rcut[i])*(value*(2.0*r-3.0*r1[i]+rcut[i])
               -dvalue*(r-r1[i])*(r1[i]-rcut[i]))/((r1[i]-rcut[i])
               *(r1[i]-rcut[i])*(r1[i]-rcut[i]));
         }
       }
       else {
         if(r>=rcut[i])
           pBetaS[i][j]=0.0;
         else {
           value=betaSfunc(i,r);
           dvalue=dBetaSfunc(i,r,value,0.0);
           pBetaS[i][j]=value*cutoff(r1[i],rcut[i],ncutoff,r);
         }
       }
     }
     pBetaS[i][nr-1]=0.0;
     pBetaS1[i][0]=pBetaS[i][1]-pBetaS[i][0];
     pBetaS1[i][1]=0.5*(pBetaS[i][2]-pBetaS[i][0]);
     pBetaS1[i][nr-2]=0.5*(pBetaS[i][nr-1]-pBetaS[i][nr-3]);
     pBetaS1[i][nr-1]=pBetaS[i][nr-1]-pBetaS[i][nr-2];
-     
+
     for(k=2;k<nr-2;k++) {
       pBetaS1[i][k]=((pBetaS[i][k-2]-pBetaS[i][k+2])+8.0*(pBetaS[i][k+1]
           -pBetaS[i][k-1]))/12.0;
     }
     for(k=0;k<nr-1;k++) {
       pBetaS2[i][k]=3.0*(pBetaS[i][k+1]-pBetaS[i][k])-2.0*pBetaS1[i][k]-pBetaS1[i][k+1];
       pBetaS3[i][k]=pBetaS1[i][k]+pBetaS1[i][k+1]-2.0*(pBetaS[i][k+1]-pBetaS[i][k]);
     }
     pBetaS2[i][nr-1]=0.0;
     pBetaS3[i][nr-1]=0.0;
     for(k=0;k<nr;k++) {
       pBetaS4[i][k]=pBetaS1[i][k]/dr[i];
       pBetaS5[i][k]=2.0*pBetaS2[i][k]/dr[i];
       pBetaS6[i][k]=3.0*pBetaS3[i][k]/dr[i];
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::setPbetaP()
 {
   int i,j,k;
   double r,value,dvalue;
 
   for(i=0;i<npairs;i++) {
     for(j=0;j<nr;j++) {
       r=(double)j*dr[i];
       if(r<rcore)
         r=rcore;
       if(ncutoff==3) {
         if(r>=rcut[i])
           pBetaP[i][j]=0.0;
         else if(r<=r1[i]) {
           value=betaPfunc(i,r);
           dvalue=dBetaPfunc(i,r,value,0.0);
           pBetaP[i][j]=value;
         }
         else {
           value=betaPfunc(i,r1[i]);
           dvalue=dBetaPfunc(i,r1[i],value,1.0);
           pBetaP[i][j]=-(r-rcut[i])*(r-rcut[i])*(value*(2.0*r-3.0*r1[i]
               +rcut[i])-dvalue*(r-r1[1])*(r1[i]-rcut[i]))/((r1[i]-rcut[i])
               *(r1[i]-rcut[i])*(r1[i]-rcut[i]));
         }
       }
       else {
         if(r>=rcut[i])
           pBetaP[i][j]=0.0;
         else {
           value=betaPfunc(i,r);
           dvalue=dBetaPfunc(i,r,value,0.0);
           pBetaP[i][j]=value*cutoff(r1[i],rcut[i],ncutoff,r);
         }
       }
     }
     pBetaP[i][nr-1]=0.0;
     pBetaP1[i][0]=pBetaP[i][1]-pBetaP[i][0];
     pBetaP1[i][1]=0.5*(pBetaP[i][2]-pBetaP[i][0]);
     pBetaP1[i][nr-2]=0.5*(pBetaP[i][nr-1]-pBetaP[i][nr-3]);
     pBetaP1[i][nr-1]=pBetaP[i][nr-1]-pBetaP[i][nr-2];
-    for(k=2;k<nr-2;k++) 
+    for(k=2;k<nr-2;k++)
       pBetaP1[i][k]=((pBetaP[i][k-2]-pBetaP[i][k+2])+8.0*(pBetaP[i][k+1]
           -pBetaP[i][k-1]))/12.0;
     for(k=0;k<nr-1;k++) {
       pBetaP2[i][k]=3.0*(pBetaP[i][k+1]-pBetaP[i][k])-2.0*pBetaP1[i][k]-pBetaP1[i][k+1];
       pBetaP3[i][k]=pBetaP1[i][k]+pBetaP1[i][k+1]-2.0*(pBetaP[i][k+1]-pBetaP[i][k]);
     }
     pBetaP2[i][nr-1]=0.0;
     pBetaP3[i][nr-1]=0.0;
     for(k=0;k<nr;k++) {
       pBetaP4[i][k]=pBetaP1[i][k]/dr[i];
       pBetaP5[i][k]=2.0*pBetaP2[i][k]/dr[i];
       pBetaP6[i][k]=3.0*pBetaP3[i][k]/dr[i];
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::setPrepul()
 {
   int i,j,k;
   double r,value,dvalue;
- 
+
   for(i=0;i<npairs;i++) {
     for(j=0;j<nr;j++) {
       r=(double)j*dr[i];
       if(r<rcore)
         r=rcore;
       if(ncutoff==3) {
         if(r>=rcut[i])
           pRepul[i][j]=0.0;
         else if(r<=r1[i]) {
           value=repulfunc(i,r);
           dvalue=dRepulfunc(i,r,value,0.0);
           pRepul[i][j]=value;
         }
         else {
           value=repulfunc(i,r1[i]);
           dvalue=dRepulfunc(i,r1[i],value,1.0);
           pRepul[i][j]=-(r-rcut[i])*(r-rcut[i])*(value*(2.0*r-3.0*r1[i]+rcut[i])
               -dvalue*(r-r1[i])*(r1[i]-rcut[i]))/((r1[i]-rcut[i])
               *(r1[i]-rcut[i])*(r1[i]-rcut[i]));
         }
       }
       else {
         if(r>=rcut[i])
           pRepul[i][j]=0.0;
         else {
           value=repulfunc(i,r);
           dvalue=dRepulfunc(i,r,value,0.0);
           pRepul[i][j]=value*cutoff(r1[i],rcut[i],ncutoff,r);
         }
       }
     }
     pRepul[i][nr-1]=0.0;
     pRepul1[i][0]=pRepul[i][1]-pRepul[i][0];
     pRepul1[i][1]=0.5*(pRepul[i][2]-pRepul[i][0]);
     pRepul1[i][nr-2]=0.5*(pRepul[i][nr-1]-pRepul[i][nr-3]);
     pRepul1[i][nr-1]=pRepul[i][nr-1]-pRepul[i][nr-2];
     for(k=2;k<nr-2;k++)
       pRepul1[i][k]=((pRepul[i][k-2]-pRepul[i][k+2])+8.0*(pRepul[i][k+1]
           -pRepul[i][k-1]))/12.0;
     for(k=0;k<nr-1;k++) {
       pRepul2[i][k]=3.0*(pRepul[i][k+1]-pRepul[i][k])-2.0*pRepul1[i][k]-pRepul1[i][k+1];
       pRepul3[i][k]=pRepul1[i][k]+pRepul1[i][k+1]-2.0*(pRepul[i][k+1]-pRepul[i][k]);
     }
     pRepul2[i][nr-1]=0.0;
     pRepul3[i][nr-1]=0.0;
     for(k=0;k<nr;k++) {
       pRepul4[i][k]=pRepul1[i][k]/dr[i];
       pRepul5[i][k]=2.0*pRepul2[i][k]/dr[i];
       pRepul6[i][k]=3.0*pRepul3[i][k]/dr[i];
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::betaSfunc(int i,double r)
 {
   double temp_value;
 
   if(nfunc==1) {
     temp_value=pow(sigma_r0[i]/r,sigma_n[i])*exp(sigma_n[i]*pow(sigma_r0[i]
         /sigma_rc[i],sigma_nc[i])-sigma_n[i]*pow(r/sigma_rc[i],sigma_nc[i]));
     temp_value=sigma_beta0[i]*temp_value;
   }
   if(nfunc==2)
     temp_value=sigma_beta0[i]*exp(-sigma_n[i]*r);
   if(nfunc==3)
     temp_value=sigma_beta0[i]/pow(r,sigma_n[i]);
   return(temp_value);
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::dBetaSfunc(int i,double r,double value,double dmore)
 {
   double temp_dvalue;
-  
+
   if(nfunc==1)
     if(dmore==1.0)
       temp_dvalue=-sigma_n[i]*value/r*(1.0+sigma_nc[i]
           *pow(r/sigma_rc[i],sigma_nc[i]));
   if(nfunc==2)
     if(dmore==1.0)
       temp_dvalue=-sigma_n[i]*value;
   if(nfunc==3)
     if(dmore==1.0)
       temp_dvalue=-sigma_n[i]*value/r;
   return(temp_dvalue);
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::betaPfunc(int i,double r)
 {
   double temp_value;
 
   if(nfunc==1) {
     temp_value=pow(pi_r0[i]/r,pi_n[i])*exp(pi_n[i]*pow(pi_r0[i]
         /pi_rc[i],pi_nc[i])-pi_n[i]*pow(r/pi_rc[i],pi_nc[i]));
         temp_value=pi_beta0[i]*temp_value;
   }
   if(nfunc==2)
     temp_value=pi_beta0[i]*exp(-pi_n[i]*r);
   if(nfunc==3)
     temp_value=pi_beta0[i]/pow(r,pi_n[i]);
   return(temp_value);
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::dBetaPfunc(int i,double r,double value,double dmore)
 {
   double temp_dvalue;
 
   if(nfunc==1)
     if(dmore==1.0)
       temp_dvalue=-pi_n[i]*value/r*(1.0+pi_nc[i]*pow(r/pi_rc[i],pi_nc[i]));
   if(nfunc==2)
-    if(dmore==1.0) 
+    if(dmore==1.0)
       temp_dvalue=-pi_n[i]*value;
   if(nfunc==3)
     if(dmore==1.0)
       temp_dvalue=-pi_n[i]*value/r;
   return(temp_dvalue);
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::repulfunc(int i,double r)
 {
   double temp_value;
 
   if(nfunc==1) {
     temp_value=pow(phi_r0[i]/r,phi_m[i])*exp(phi_m[i]*pow(phi_r0[i]/phi_rc[i]
         ,phi_nc[i])-phi_m[i]*pow(r/phi_rc[i],phi_nc[i]));
     temp_value=phi0[i]*temp_value;
   }
   if(nfunc==2)
     temp_value=phi0[i]*exp(-phi_m[i]*r);
   if(nfunc==3)
     temp_value=phi0[i]/pow(r,phi_m[i]);
   return(temp_value);
-} 
+}
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::dRepulfunc(int i,double r,double value,double dmore)
 {
   double temp_dvalue;
 
   if(nfunc==1)
     if(dmore==1.0)
       temp_dvalue=-phi_m[i]*value/r*(1.0+phi_nc[i]*pow(r/phi_rc[i],phi_nc[i]));
   if(nfunc==2)
     if(dmore==1.0)
       temp_dvalue=-phi_m[i]*value;
   if(nfunc==3)
     if(dmore==1.0)
       temp_dvalue=-phi_m[i]*value/r;
   return(temp_dvalue);
-} 
+}
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::setSign()
 {
   int i,j,k;
   double y0,tmp,xBO,fth,cs,bigF;
   double epsilon,fsigma1,slope,sat;
-  
+
   dBO=1.0/(nBOt-1.0);
   rdBO=1.0/dBO;
   for(i=0;i<npairs;i++) {
     for(j=0;j<nBOt;j++) {
       xBO=(double)j*dBO;
       if(which==1.0) {
         fth=0.0;
         if(xBO>alpha)
           fth=4.0/3.0*(xBO-alpha);
         if(sigma_f[i]<=fth)
           FsigBO[i][j]=2.0*sigma_f[i];
         else if(sigma_f[i]>=1.0-fth)
           FsigBO[i][j]=2.0*(1.0-sigma_f[i]);
         else {
           cs=0.0;
           if(xBO<alpha)
             cs=32.0*(alpha-xBO);
           bigF=(sigma_f[i]*(1.0-sigma_f[i])-fth*(1.0-fth))/pow(1.0-2.0*fth,2);
           FsigBO[i][j]=2.0*fth+2.0*bigF*(1.0-2.0*fth)*(1.0+bigF*(1.0-cs*bigF));
         }
       }
       else if(which==2.0) {
         epsilon=0.0000000001;
         fsigma1=sigma_f[i];
         if(fsigma1>0.5)
           fsigma1=1.0-fsigma1;
         y0=alpha1*pow(fsigma1,beta1)*pow(0.5-fsigma1,gamma1);
         slope=(1.0-exp(-alpha2*pow(fsigma1,beta2)))/(1.0-exp(-alpha2*pow(0.5,beta2)));
         sat=alpha3*fsigma1+beta3;
         tmp=y0+slope*xBO+sat;
         FsigBO[i][j]=(tmp-sqrt(tmp*tmp-4.0*(-epsilon*sqrt(1.0+slope*slope)
             +y0*sat+slope*sat*xBO)))/2.0;
       }
     }
     FsigBO1[i][0]=FsigBO[i][1]-FsigBO[i][0];
     FsigBO1[i][1]=0.5*(FsigBO[i][2]-FsigBO[i][0]);
     FsigBO1[i][nBOt-2]=0.5*(FsigBO[i][nBOt-1]-FsigBO[i][nBOt-3]);
     FsigBO1[i][nBOt-1]=FsigBO[i][nBOt-1]-FsigBO[i][nBOt-2];
     for(k=2;k<nBOt-2;k++)
       FsigBO1[i][k]=((FsigBO[i][k-2]-FsigBO[i][k+2])+8.0*(FsigBO[i][k+1]
           -FsigBO[i][k-1]))/12.0;
     for(k=0;k<nBOt-1;k++) {
       FsigBO2[i][k]=3.0*(FsigBO[i][k+1]-FsigBO[i][k])-2.0*FsigBO1[i][k]-FsigBO1[i][k+1];
       FsigBO3[i][k]=FsigBO1[i][k]+FsigBO1[i][k+1]-2.0*(FsigBO[i][k+1]-FsigBO[i][k]);
     }
     FsigBO2[i][nBOt-1]=0.0;
     FsigBO3[i][nBOt-1]=0.0;
     for(k=0;k<nBOt;k++) {
       FsigBO4[i][k]=FsigBO1[i][k]/dBO;
       FsigBO5[i][k]=2.0*FsigBO2[i][k]/dBO;
       FsigBO6[i][k]=3.0*FsigBO3[i][k]/dBO;
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairBOP::cutoff(double rp,double vrcut,int mode,double r)
 {
   double tmp,tmp_beta,tmp_alpha,cut_store;
-  
+
   if(mode==1) {
     tmp=(rsmall-rbig)*(r-rp)/(vrcut-rp)+rbig;
     cut_store=(erfc(tmp)-erfc(rsmall))/(erfc(rbig)-erfc(rsmall));
   }
   else {
     tmp_beta=log(log(rbig)/log(rsmall))/log(rp/vrcut);
     tmp_alpha=-log(rbig)/pow(rp,tmp_beta);
     cut_store=(exp(-tmp_alpha*pow(r,tmp_beta))-exp(-tmp_alpha*pow(vrcut
         ,tmp_beta)))/(exp(-tmp_alpha*pow(rp,tmp_beta))-exp(-tmp_alpha
         *pow(vrcut,tmp_beta)));
   }
   return(cut_store);
 }
 
 /* ----------------------------------------------------------------------
-   memory usage of local atom-based arrays 
+   memory usage of local atom-based arrays
 ------------------------------------------------------------------------- */
 
 double PairBOP::memory_usage()
 {
   int nlocal,nghost,nall;
-  int n = atom->ntypes; 
+  int n = atom->ntypes;
   nlocal = atom->nlocal;
   nghost = atom->nghost;
   nall = nlocal + nghost;
   double bytes = 0.0;
 
 // rcut
   bytes += npairs * sizeof (double);
 // dr
   bytes += npairs * sizeof (double);
 // rdr
   bytes += npairs * sizeof (double);
 // setflag
   bytes += (n+1) * (n+1) * sizeof (int);
 // cutsq
   bytes += (n+1) * (n+1) * sizeof (double);
 // cutghost
   bytes += (n+1) * (n+1) * sizeof (double);
 // cutghost
   bytes += (n+1) * (n+1) * sizeof (double);
 // pBetaS
   bytes += npairs * nr * sizeof (double);
 // pBetaS1
   bytes += npairs * nr * sizeof (double);
 // pBetaS2
   bytes += npairs * nr * sizeof (double);
 // pBetaS3
   bytes += npairs * nr * sizeof (double);
 // pBetaS4
   bytes += npairs * nr * sizeof (double);
 // pBetaS5
   bytes += npairs * nr * sizeof (double);
 // pBetaS6
   bytes += npairs * nr * sizeof (double);
 // pBetaP
   bytes += npairs * nr * sizeof (double);
 // pBetaP1
   bytes += npairs * nr * sizeof (double);
 // pBetaP2
   bytes += npairs * nr * sizeof (double);
 // pBetaP3
   bytes += npairs * nr * sizeof (double);
 // pBetaP4
   bytes += npairs * nr * sizeof (double);
 // pBetaP5
   bytes += npairs * nr * sizeof (double);
 // pBetaP6
   bytes += npairs * nr * sizeof (double);
 // pRepul
   bytes += npairs * nr * sizeof (double);
 // pRepul1
   bytes += npairs * nr * sizeof (double);
 // pRepul2
   bytes += npairs * nr * sizeof (double);
 // pRepul3
   bytes += npairs * nr * sizeof (double);
 // pRepul4
   bytes += npairs * nr * sizeof (double);
 // pRepul5
   bytes += npairs * nr * sizeof (double);
 // pRepul6
   bytes += npairs * nr * sizeof (double);
 // FsigBO
   bytes += npairs * nr * sizeof (double);
 // FsigBO1
   bytes += npairs * nr * sizeof (double);
 // FsigBO2
   bytes += npairs * nr * sizeof (double);
 // FsigBO3
   bytes += npairs * nr * sizeof (double);
 // FsigBO4
   bytes += npairs * nr * sizeof (double);
 // FsigBO5
   bytes += npairs * nr * sizeof (double);
 // FsigBO6
   bytes += npairs * nr * sizeof (double);
 // itypeSigBk
   bytes += neigh_total *neigh_ct* sizeof(int);
 // nSigBk
   bytes += neigh_total * sizeof(int);
 // sigB
   bytes += neigh_total * sizeof(int);
 // sigB1
   bytes += neigh_total * sizeof(int);
 // nPiBk
   bytes += neigh_total * sizeof(int);
 // piB
   bytes += neigh_total * sizeof(int);
 // itypePiBk
   bytes += neigh_total *neigh_ct* sizeof(int);
 // BOP_index
     bytes += nall * sizeof(double);
   if(otfly==0) {
 // cosAng
     bytes += cos_total* sizeof(double);
 // dcAng
     bytes += cos_total * 3 * 2 * sizeof(double);
 // disij
     bytes += neigh_total * 3 * sizeof(double);
 // rij
     bytes += neigh_total * sizeof(double);
 // betaS
     bytes += neigh_total * sizeof(double);
 // dBetaS
     bytes += neigh_total * sizeof(double);
 // betaP
     bytes += neigh_total * sizeof(double);
 // dBetaP
     bytes += neigh_total * sizeof(double);
 // repul
     bytes += neigh_total * sizeof(double);
 // dRepul
     bytes += neigh_total * sizeof(double);
 // cos_index
     bytes += nall * sizeof(double);
-  }    
+  }
 // pi_a
   bytes += npairs * sizeof(double);
 // pro_delta
   bytes += npairs * sizeof(double);
 // pi_delta
   bytes += npairs * sizeof(double);
 // pi_p
   bytes += npairs * sizeof(double);
 // pi_c
   bytes += npairs * sizeof(double);
 // sigma_r0
   bytes += npairs * sizeof(double);
 // pi_r0
   bytes += npairs * sizeof(double);
 // phi_r0
   bytes += npairs * sizeof(double);
 // sigma_rc
   bytes += npairs * sizeof(double);
 // pi_rc
   bytes += npairs * sizeof(double);
 // pi_a
   bytes += npairs * sizeof(double);
 // pro_delta
   bytes += npairs * sizeof(double);
 // pi_delta
   bytes += npairs * sizeof(double);
 // pi_p
   bytes += npairs * sizeof(double);
 // pi_c
   bytes += npairs * sizeof(double);
 // sigma_r0
   bytes += npairs * sizeof(double);
 // pi_r0
   bytes += npairs * sizeof(double);
 // phi_r0
   bytes += npairs * sizeof(double);
 // sigma_rc
   bytes += npairs * sizeof(double);
 // pi_rc
   bytes += npairs * sizeof(double);
 // phi_rc
   bytes += npairs * sizeof(double);
 // r1
   bytes += npairs * sizeof(double);
-// sigma_beta0 
+// sigma_beta0
   bytes += npairs * sizeof(double);
-// pi_beta0 
+// pi_beta0
   bytes += npairs * sizeof(double);
 // phi0
   bytes += npairs * sizeof(double);
 // sigma_n
   bytes += npairs * sizeof(double);
 // pi_n
   bytes += npairs * sizeof(double);
 // phi_m
   bytes += npairs * sizeof(double);
 // sigma_nc
   bytes += npairs * sizeof(double);
 // pi_nc
   bytes += npairs * sizeof(double);
 // phi_nc
   bytes += npairs * sizeof(double);
 // pro
   bytes += npairs * sizeof(double);
 // sigma_delta
   bytes += npairs * sizeof(double);
 // sigma_c
   bytes += npairs * sizeof(double);
 // sigma_a
   bytes += npairs * sizeof(double);
 // sigma_g0
   bytes += bop_types * bop_types *bop_types * sizeof(double);
 // sigma_g1
   bytes += bop_types * bop_types *bop_types * sizeof(double);
 // sigma_g2
   bytes += bop_types * bop_types *bop_types * sizeof(double);
 // sigma_g3
   bytes += bop_types * bop_types *bop_types * sizeof(double);
 // sigma_g4
   bytes += bop_types * bop_types *bop_types * sizeof(double);
 // sigma_f
   bytes += npairs * sizeof(double);
 // sigma_k
   bytes += npairs * sizeof(double);
 // small3
   bytes += npairs * sizeof(double);
 // bt_pi
   bytes += maxneigh*(maxneigh/2) *sizeof(B_PI);
 // bt_sigma
   bytes += maxneigh*(maxneigh/2) *sizeof(B_SG);
 
   return bytes;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::memory_theta_create()
 {
   int nlocal,nghost,nall;
- 
+
   nlocal = atom->nlocal;
   nghost = atom->nghost;
   nall = nlocal + nghost;
-  if(maxneigh<8) 
+  if(maxneigh<8)
     neigh_ct=(maxneigh-1)*(maxneigh-1)*(maxneigh-1);
   else
     neigh_ct=(maxneigh-1)*(maxneigh-1);
   memory->create(itypeSigBk,neigh_total
       ,neigh_ct,"itypeSigBk");
   memory->create(nSigBk,neigh_total,"nSigBk");
   memory->create(sigB,neigh_total,"sigB");
   memory->create(sigB1,neigh_total,"sigB1");
   memory->create(itypePiBk,neigh_total
       ,neigh_ct,"itypePiBk");
   memory->create(nPiBk,neigh_total,"nPiBk");
   memory->create(piB,neigh_total,"piB");
   memory->create(neigh_flag,neigh_total,"neigh_flag");
   if(otfly==0) {
     memory->create(cosAng,cos_total,"BOP:cosAng");
     memory->create(dcAng,cos_total*2,3,2,"BOP:dcAng");
     memory->create(disij,3,neigh_total,"disij");
     memory->create(rij,neigh_total,"rij");
     memory->create(betaS,neigh_total,"betaS");
     memory->create(dBetaS,neigh_total,"dBetaS");
     memory->create(betaP,neigh_total,"betaP");
     memory->create(dBetaP,neigh_total,"dBetaP");
     memory->create(repul,neigh_total,"repul");
     memory->create(dRepul,neigh_total,"dRepul");
   }
   update_list=1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::memory_theta_grow()
 {
   int nlocal,nghost,nall;
- 
+
   nlocal = atom->nlocal;
   nghost = atom->nghost;
   nall = nlocal + nghost;
-  if(maxneigh<8) 
+  if(maxneigh<8)
     neigh_ct=(maxneigh-1)*(maxneigh-1)*(maxneigh-1);
   else
     neigh_ct=(maxneigh-1)*(maxneigh-1);
   memory->grow(itypeSigBk,neigh_total
       ,neigh_ct,"itypeSigBk");
   memory->grow(nSigBk,neigh_total,"nSigBk");
   memory->grow(sigB,neigh_total,"sigB");
   memory->grow(sigB1,neigh_total,"sigB1");
   memory->grow(itypePiBk,neigh_total
       ,neigh_ct,"itypePiBk");
   memory->grow(nPiBk,neigh_total,"nPiBk");
   memory->grow(piB,neigh_total,"piB");
   memory->grow(neigh_flag,neigh_total,"neigh_flag");
   if(otfly==0) {
     memory->grow(cosAng,cos_total,"BOP:cosAng");
     memory->grow(dcAng,cos_total*2,3,2,"BOP:dcAng");
     memory->grow(disij,3,neigh_total,"disij");
     memory->grow(rij,neigh_total,"rij");
     memory->grow(betaS,neigh_total,"betaS");
     memory->grow(dBetaS,neigh_total,"dBetaS");
     memory->grow(betaP,neigh_total,"betaP");
     memory->grow(dBetaP,neigh_total,"dBetaP");
     memory->grow(repul,neigh_total,"repul");
     memory->grow(dRepul,neigh_total,"dRepul");
   }
   update_list=1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::memory_theta_destroy()
 {
 
   memory->destroy(itypeSigBk);
   memory->destroy(nSigBk);
   memory->destroy(sigB);
   memory->destroy(sigB1);
   memory->destroy(itypePiBk);
   memory->destroy(nPiBk);
   memory->destroy(piB);
   memory->destroy(neigh_flag);
   if(otfly==0) {
     memory->destroy(cosAng);
     memory->destroy(dcAng);
     memory->destroy(disij);
     memory->destroy(rij);
     memory->destroy(betaS);
     memory->destroy(dBetaS);
     memory->destroy(betaP);
     memory->destroy(dBetaP);
     memory->destroy(repul);
     memory->destroy(dRepul);
   }
  update_list=0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::create_pi(int n_tot)
 {
   bt_pi = (B_PI *) memory->smalloc(n_tot*sizeof(B_PI),"BOP:bt_pi");
   allocate_pi=1;
 }
 
 void PairBOP::create_sigma(int n_tot)
 {
   bt_sg = (B_SG *) memory->smalloc(n_tot*sizeof(B_SG),"BOP:bt_sg");
   allocate_sigma=1;
 }
 
 void PairBOP::destroy_pi()
 {
   memory->destroy(bt_pi);
   allocate_pi=0;
 }
 
 void PairBOP::destroy_sigma()
 {
   memory->destroy(bt_sg);
   allocate_sigma=0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::grow_pi(int n1, int n2)
 {
   int i,j;
   B_PI *bt_temp;
   bt_temp = (B_PI *) memory->smalloc(n1*sizeof(B_PI),"BOP:b_temp");
   for(i=0;i<n1;i++) {
     bt_temp[i].temp = bt_pi[i].temp;
     bt_temp[i].i = bt_pi[i].i;
     bt_temp[i].j = bt_pi[i].j;
     for(j=0;j<3;j++) {
       bt_temp[i].dAA[j] = bt_pi[i].dAA[j];
       bt_temp[i].dBB[j] = bt_pi[i].dBB[j];
       bt_temp[i].dPiB[j] = bt_pi[i].dPiB[j];
     }
   }
   memory->destroy(bt_pi);
   bt_pi=NULL;
   bt_pi = (B_PI *) memory->smalloc(n2*sizeof(B_PI),"BOP:bt_pi");
   for(i=0;i<n1;i++) {
     bt_pi[i].temp = bt_temp[i].temp;
     bt_pi[i].i = bt_temp[i].i;
     bt_pi[i].j = bt_temp[i].j;
     for(j=0;j<3;j++) {
       bt_pi[i].dAA[j] = bt_temp[i].dAA[j];
       bt_pi[i].dBB[j] = bt_temp[i].dBB[j];
       bt_pi[i].dPiB[j] = bt_temp[i].dPiB[j];
     }
   }
   for(i=n1;i<n2;i++) {
     bt_pi[i].i = -1;
     bt_pi[i].j = -1;
     for(j=0;j<3;j++) {
       bt_pi[i].dAA[j] = 0.0;
       bt_pi[i].dBB[j] = 0.0;
       bt_pi[i].dPiB[j] = 0.0;
     }
   }
   memory->destroy(bt_temp);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairBOP::grow_sigma(int n1,int n2)
 {
   int i,j;
   B_SG *bt_temp;
   bt_temp = (B_SG *) memory->smalloc(n1*sizeof(B_SG),"BOP:bt_temp");
   for(i=0;i<n1;i++) {
     bt_temp[i].temp = bt_sg[i].temp;
     bt_temp[i].i = bt_sg[i].i;
     bt_temp[i].j = bt_sg[i].j;
     for(j=0;j<3;j++) {
       bt_temp[i].dAA[j] = bt_sg[i].dAA[j];
       bt_temp[i].dBB[j] = bt_sg[i].dBB[j];
       bt_temp[i].dCC[j] = bt_sg[i].dCC[j];
       bt_temp[i].dDD[j] = bt_sg[i].dDD[j];
       bt_temp[i].dEE[j] = bt_sg[i].dEE[j];
       bt_temp[i].dEE1[j] = bt_sg[i].dEE1[j];
       bt_temp[i].dFF[j] = bt_sg[i].dFF[j];
       bt_temp[i].dAAC[j] = bt_sg[i].dAAC[j];
       bt_temp[i].dBBC[j] = bt_sg[i].dBBC[j];
       bt_temp[i].dCCC[j] = bt_sg[i].dCCC[j];
       bt_temp[i].dDDC[j] = bt_sg[i].dDDC[j];
       bt_temp[i].dEEC[j] = bt_sg[i].dEEC[j];
       bt_temp[i].dFFC[j] = bt_sg[i].dFFC[j];
       bt_temp[i].dGGC[j] = bt_sg[i].dGGC[j];
       bt_temp[i].dUT[j] = bt_sg[i].dUT[j];
       bt_temp[i].dSigB1[j] = bt_sg[i].dSigB1[j];
       bt_temp[i].dSigB[j] = bt_sg[i].dSigB[j];
     }
   }
   memory->destroy(bt_sg);
   bt_sg=NULL;
   bt_sg = (B_SG *) memory->smalloc(n2*sizeof(B_SG),"BOP:bt_sg");
   for(i=0;i<n1;i++) {
     bt_sg[i].temp = bt_temp[i].temp;
     bt_sg[i].i = bt_temp[i].i;
     bt_sg[i].j = bt_temp[i].j;
     for(j=0;j<3;j++) {
       bt_sg[i].dAA[j] = bt_temp[i].dAA[j];
       bt_sg[i].dBB[j] = bt_temp[i].dBB[j];
       bt_sg[i].dCC[j] = bt_temp[i].dCC[j];
       bt_sg[i].dDD[j] = bt_temp[i].dDD[j];
       bt_sg[i].dEE[j] = bt_temp[i].dEE[j];
       bt_sg[i].dEE1[j] = bt_temp[i].dEE1[j];
       bt_sg[i].dFF[j] = bt_temp[i].dFF[j];
       bt_sg[i].dAAC[j] = bt_temp[i].dAAC[j];
       bt_sg[i].dBBC[j] = bt_temp[i].dBBC[j];
       bt_sg[i].dCCC[j] = bt_temp[i].dCCC[j];
       bt_sg[i].dDDC[j] = bt_temp[i].dDDC[j];
       bt_sg[i].dEEC[j] = bt_temp[i].dEEC[j];
       bt_sg[i].dFFC[j] = bt_temp[i].dFFC[j];
       bt_sg[i].dGGC[j] = bt_temp[i].dGGC[j];
       bt_sg[i].dUT[j] = bt_temp[i].dUT[j];
       bt_sg[i].dSigB1[j] = bt_temp[i].dSigB1[j];
       bt_sg[i].dSigB[j] = bt_temp[i].dSigB[j];
     }
   }
   for(i=n1;i<n2;i++) {
     bt_sg[i].i = -1;
     bt_sg[i].j = -1;
     for(j=0;j<3;j++) {
       bt_sg[i].dAA[j] = 0.0;
       bt_sg[i].dBB[j] = 0.0;
       bt_sg[i].dCC[j] = 0.0;
       bt_sg[i].dDD[j] = 0.0;
       bt_sg[i].dEE[j] = 0.0;
       bt_sg[i].dEE1[j] = 0.0;
       bt_sg[i].dFF[j] = 0.0;
       bt_sg[i].dAAC[j] = 0.0;
       bt_sg[i].dBBC[j] = 0.0;
       bt_sg[i].dCCC[j] = 0.0;
       bt_sg[i].dDDC[j] = 0.0;
       bt_sg[i].dEEC[j] = 0.0;
       bt_sg[i].dFFC[j] = 0.0;
       bt_sg[i].dGGC[j] = 0.0;
       bt_sg[i].dUT[j] = 0.0;
       bt_sg[i].dSigB1[j] = 0.0;
       bt_sg[i].dSigB[j] = 0.0;
     }
   }
   memory->destroy(bt_temp);
 }
diff --git a/src/MANYBODY/pair_bop.h b/src/MANYBODY/pair_bop.h
index c6a4557fc..6fee56c29 100644
--- a/src/MANYBODY/pair_bop.h
+++ b/src/MANYBODY/pair_bop.h
@@ -1,270 +1,270 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    The this work follows the formulation from (a) D.G. Pettifor, et al., Mat.
    Sci. and Eng. A365, 2-13, (2004) and (b) D.A. Murdick, et al., Phys.
-   Rev. B 73, 045206 (2006). (c) D.K. Ward, et al., Phys. Rev. B 85, 115206 
+   Rev. B 73, 045206 (2006). (c) D.K. Ward, et al., Phys. Rev. B 85, 115206
    (2012)
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #ifdef PAIR_CLASS
 
 PairStyle(bop,PairBOP)
 
 #else
 
 #ifndef LMP_PAIR_BOP_H
 #define LMP_PAIR_BOP_H
 
 #include "pair.h"
 #include "update.h"
 
 namespace LAMMPS_NS {
 
 class PairBOP : public Pair {
  public:
   PairBOP(class LAMMPS *);
   virtual ~PairBOP();
   void compute(int, int);
   void settings(int, char **);
   void coeff(int, char **);
   void init_style();
   double init_one(int, int);
   double memory_usage();
 
  private:
   int me;
   int maxneigh;                    // maximum size of neighbor list on this processor
   int update_list;                 // check for changing maximum size of neighbor list
   int maxbopn;                     // maximum size of bop neighbor list for allocation
   int maxnall;                     // maximum size of bop neighbor list for allocation
   int *map;                        // mapping from atom types to elements
-  int nelements;		   // # of unique elments
+  int nelements;                   // # of unique elments
   int nr;                     // increments for the BOP potential
   int nBOt;                   // second BO increments
   int bop_types;                   // number of elments in potential
   int npairs;                      // number of element pairs
-  char **elements;		   // names of unique elements 
-  int ***elem2param;		   
+  char **elements;                   // names of unique elements
+  int ***elem2param;
   int nparams;
   int bop_step;
   int allocate_pi;
   int allocate_sigma;
   int allocate_neigh;
   int nb_pi,nb_sg;
 
   int *BOP_index;                 // index for neighbor list position
   int neigh_total;                // total number of neighbors stored
   int *cos_index;                 // index for neighbor cosine if not using on the fly
   int *neigh_flag;                 // index for neighbor cosine if not using on the fly
   int cos_total;                  // number of cosines stored if not using on the fly
   int neigh_ct;                  //  limit for large arrays
 
-/*Parameters variables*/ 
+/*Parameters variables*/
 
   int ncutoff,nfunc;
   int a_flag;
   double *pi_a,*pro_delta,*pi_delta;
   double *pi_p,*pi_c,*sigma_r0,*pi_r0,*phi_r0;
   double *sigma_rc,*pi_rc,*phi_rc,*r1,*sigma_beta0;
   double *pi_beta0,*phi0,*sigma_n,*pi_n,*phi_m;
   double *sigma_nc,*pi_nc,*phi_nc;
   double *pro,*sigma_delta,*sigma_c,*sigma_a;
   double ***sigma_g0,***sigma_g1,***sigma_g2,***sigma_g3;
   double ***sigma_g4,*sigma_f,*sigma_k,*small3;
   double small1,small2,small3g,small4,small5,small6,small7;
   double which,alpha,alpha1,beta1,gamma1,alpha2,beta2,alpha3;
   double beta3,rsmall,rbig,rcore;
   char **words;
- 
-  double cutmax;		//max cutoff for all elements 
-  int otfly;			//Defines whether to do on the fly
+
+  double cutmax;                //max cutoff for all elements
+  int otfly;                        //Defines whether to do on the fly
                                 //calculations of angles and distances
                                 //on the fly will slow down calculations
                                 //but requires less memory on = 1, off=0
 
-  int table;			//determines the method for reading in 
+  int table;                        //determines the method for reading in
                                 //potential parameters a preset table
                                 //or generate the tables using a spline
 
 /* Neigh variables */
- 
+
   double *rcut,*dr,*rdr;
   double **disij,*rij;
 
 /*Triple variables */
- 
+
   double *cosAng,***dcosAng,***dcAng;
- 
+
 /*Double variables */
- 
+
   double *betaS,*dBetaS,*betaP;
   double *dBetaP,*repul,*dRepul;
-  
+
 /*Sigma variables */
- 
+
   int **itypeSigBk,*nSigBk;
   double *sigB;
   double *sigB1;
 
-  
+
 /*Pi variables */
- 
+
   int **itypePiBk,*nPiBk;
   double *piB;
-   
+
 /*Grids1 variables */
- 
+
   double **pBetaS,**pBetaS1,**pBetaS2,**pBetaS3;
   double **pBetaS4,**pBetaS5,**pBetaS6;
- 
+
 /*Grids2 variables */
- 
+
   double **pBetaP,**pBetaP1,**pBetaP2,**pBetaP3;
   double **pBetaP4,**pBetaP5,**pBetaP6;
- 
+
 /*Grids3 variables */
- 
+
   double **pRepul,**pRepul1,**pRepul2,**pRepul3;
   double **pRepul4,**pRepul5,**pRepul6;
- 
+
 /*Grids4 variables */
- 
+
   double **FsigBO,**FsigBO1,**FsigBO2,**FsigBO3;
   double **FsigBO4,**FsigBO5,**FsigBO6;
-  double dBO,rdBO; 
-  
+  double dBO,rdBO;
+
 /* End of BOP variables */
 
   double **rcmin,**rcmax,**rcmaxp;
   struct B_PI{
     double dAA[3];
     double dBB[3];
     double dPiB[3];
     int temp;
     int i;
     int j;
   };
   B_PI *bt_pi;
 
   struct B_SG{
     double dAA[3];
     double dBB[3];
     double dCC[3];
     double dDD[3];
     double dEE[3];
     double dEE1[3];
     double dFF[3];
     double dAAC[3];
     double dBBC[3];
     double dCCC[3];
     double dDDC[3];
     double dEEC[3];
     double dFFC[3];
     double dGGC[3];
     double dUT[3];
     double dSigB1[3];
     double dSigB[3];
     int temp;
     int i;
     int j;
   };
   B_SG *bt_sg;
 
   void setPbetaS();
   void setPbetaP();
   void setPrepul();
   void setSign();
   void gneigh();
   void theta();
   void theta_mod();
   void sigmaBo();
   void PiBo();
   void sigmaBo_otf();
   void PiBo_otf();
   void sigmaBo_noa();
   void sigmaBo_noa_otf();
   void memory_theta_create();
   void memory_theta_destroy();
   void memory_theta_grow();
   double cutoff(double, double, int, double);
   double betaSfunc(int, double);
   double dBetaSfunc(int, double, double, double);
   double betaPfunc(int, double);
   double dBetaPfunc(int, double, double, double);
   double repulfunc(int, double);
   double dRepulfunc(int, double, double, double);
 
   void read_file(char *);
   void read_table(char *);
   void allocate();
   void create_pi(int);
   void create_sigma(int);
   void destroy_pi();
   void destroy_sigma();
   void grow_pi(int,int);
   void grow_sigma(int,int);
 };
 
 }
 
 #endif
 #endif
 
 /* ERROR/WARNING messages:
 
 E: Illegal ... command
 
 Self-explanatory.  Check the input script syntax and compare to the
 documentation for the command.  You can use -echo screen as a
 command-line option when running LAMMPS to see the offending line.
 
 E: Incorrect args for pair coefficients
 
 Self-explanatory.  Check the input script or data file.
 
 E: Pair style BOP requires atom IDs
 
 This is a requirement to use the BOP potential.
 
 E: Pair style BOP requires newton pair on
 
 See the newton command.  This is a restriction to use the BOP
 potential.
 
 E: Pair style bop requires comm ghost cutoff at least 3x larger than %g
 
 Use the communicate ghost command to set this.  See the pair bop
 doc page for more details.
 
 E: All pair coeffs are not set
 
 All pair coefficients must be set in the data file or by the
 pair_coeff command before running a simulation.
 
 E: Too many atom pairs for pair bop
 
 The number of atomic pairs exceeds the expected number.  Check your
 atomic structure to ensure that it is realistic.
 
 E: Too many atom triplets for pair bop
 
 The number of three atom groups for angle determinations exceeds the
 expected number.  Check your atomic structrure to ensure that it is
 realistic.
 
 E: Cannot open BOP potential file %s
 
 The specified BOP potential file cannot be opened.  Check that the
 path and name are correct.
 
 */
diff --git a/src/MOLECULE/atom_vec_angle.cpp b/src/MOLECULE/atom_vec_angle.cpp
index ceac39e34..8b1d2cd2f 100644
--- a/src/MOLECULE/atom_vec_angle.cpp
+++ b/src/MOLECULE/atom_vec_angle.cpp
@@ -1,854 +1,854 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "atom_vec_angle.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecAngle::AtomVecAngle(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 1;
   bonds_allow = angles_allow = 1;
   mass_type = 1;
 
   comm_x_only = comm_f_only = 1;
   size_forward = 3;
   size_reverse = 3;
   size_border = 7;
   size_velocity = 3;
   size_data_atom = 6;
   size_data_vel = 4;
   xcol_data = 4;
 
   atom->molecule_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecAngle::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   molecule = memory->grow(atom->molecule,nmax,"atom:molecule");
 
   nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial");
   special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special");
 
   num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond");
   bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom,
                            "atom:bond_type");
   bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom,
                            "atom:bond_atom");
 
   num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle");
   angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom,
                             "atom:angle_type");
   angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom,
                              "atom:angle_atom1");
   angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom,
                              "atom:angle_atom2");
   angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom,
                              "atom:angle_atom3");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecAngle::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   molecule = atom->molecule;
   nspecial = atom->nspecial; special = atom->special;
   num_bond = atom->num_bond; bond_type = atom->bond_type;
   bond_atom = atom->bond_atom;
   num_angle = atom->num_angle; angle_type = atom->angle_type;
   angle_atom1 = atom->angle_atom1; angle_atom2 = atom->angle_atom2;
   angle_atom3 = atom->angle_atom3;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecAngle::copy(int i, int j, int delflag)
 {
   int k;
 
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   molecule[j] = molecule[i];
 
   num_bond[j] = num_bond[i];
   for (k = 0; k < num_bond[j]; k++) {
     bond_type[j][k] = bond_type[i][k];
     bond_atom[j][k] = bond_atom[i][k];
   }
 
   num_angle[j] = num_angle[i];
   for (k = 0; k < num_angle[j]; k++) {
     angle_type[j][k] = angle_type[i][k];
     angle_atom1[j][k] = angle_atom1[i][k];
     angle_atom2[j][k] = angle_atom2[i][k];
     angle_atom3[j][k] = angle_atom3[i][k];
   }
 
   nspecial[j][0] = nspecial[i][0];
   nspecial[j][1] = nspecial[i][1];
   nspecial[j][2] = nspecial[i][2];
   for (k = 0; k < nspecial[j][2]; k++) special[j][k] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_comm(int n, int *list, double *buf,
                             int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_comm_vel(int n, int *list, double *buf,
                                 int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecAngle::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecAngle::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecAngle::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_border(int n, int *list, double *buf,
                               int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_border_vel(int n, int *list, double *buf,
                                   int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = molecule[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecAngle::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecAngle::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     molecule[i] = static_cast<int> (buf[m++]);
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_exchange(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = bond_type[i][k];
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = angle_type[i][k];
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   buf[m++] = nspecial[i][0];
   buf[m++] = nspecial[i][1];
   buf[m++] = nspecial[i][2];
   for (k = 0; k < nspecial[i][2]; k++) buf[m++] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecAngle::unpack_exchange(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   nspecial[nlocal][0] = static_cast<int> (buf[m++]);
   nspecial[nlocal][1] = static_cast<int> (buf[m++]);
   nspecial[nlocal][2] = static_cast<int> (buf[m++]);
   for (k = 0; k < nspecial[nlocal][2]; k++)
     special[nlocal][k] = static_cast<int> (buf[m++]);
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecAngle::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 0;
   for (i = 0; i < nlocal; i++)
     n += 14 + 2*num_bond[i] + 4*num_angle[i];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecAngle::pack_restart(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = MAX(bond_type[i][k],-bond_type[i][k]);
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = MAX(angle_type[i][k],-angle_type[i][k]);
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecAngle::unpack_restart(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecAngle::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   molecule[nlocal] = 0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   nspecial[nlocal][0] = nspecial[nlocal][1] = nspecial[nlocal][2] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecAngle::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   molecule[nlocal] = atoi(values[1]);
 
   type[nlocal] = atoi(values[2]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecAngle::data_atom_hybrid(int nlocal, char **values)
 {
   molecule[nlocal] = atoi(values[0]);
 
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
 
   return 1;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecAngle::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax);
   if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3);
   if (atom->memcheck("special"))
     bytes += memory->usage(special,nmax,atom->maxspecial);
 
   if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax);
   if (atom->memcheck("bond_type"))
     bytes += memory->usage(bond_type,nmax,atom->bond_per_atom);
   if (atom->memcheck("bond_atom"))
     bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom);
 
   if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax);
   if (atom->memcheck("angle_type"))
     bytes += memory->usage(angle_type,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom1"))
     bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom2"))
     bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom3"))
     bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom);
 
   return bytes;
 }
diff --git a/src/MOLECULE/atom_vec_bond.cpp b/src/MOLECULE/atom_vec_bond.cpp
index 16a2577bd..375c0dc77 100644
--- a/src/MOLECULE/atom_vec_bond.cpp
+++ b/src/MOLECULE/atom_vec_bond.cpp
@@ -1,788 +1,788 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "atom_vec_bond.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecBond::AtomVecBond(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 1;
   bonds_allow = 1;
   mass_type = 1;
 
   comm_x_only = comm_f_only = 1;
   size_forward = 3;
   size_reverse = 3;
   size_border = 7;
   size_velocity = 3;
   size_data_atom = 6;
   size_data_vel = 4;
   xcol_data = 4;
 
   atom->molecule_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecBond::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   molecule = memory->grow(atom->molecule,nmax,"atom:molecule");
 
   nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial");
   special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special");
 
   num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond");
   bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom,
                            "atom:bond_type");
   bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom,
                            "atom:bond_atom");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecBond::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   molecule = atom->molecule;
   nspecial = atom->nspecial; special = atom->special;
   num_bond = atom->num_bond; bond_type = atom->bond_type;
   bond_atom = atom->bond_atom;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecBond::copy(int i, int j, int delflag)
 {
   int k;
 
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   molecule[j] = molecule[i];
 
   num_bond[j] = num_bond[i];
   for (k = 0; k < num_bond[j]; k++) {
     bond_type[j][k] = bond_type[i][k];
     bond_atom[j][k] = bond_atom[i][k];
   }
 
   nspecial[j][0] = nspecial[i][0];
   nspecial[j][1] = nspecial[i][1];
   nspecial[j][2] = nspecial[i][2];
   for (k = 0; k < nspecial[j][2]; k++) special[j][k] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_comm(int n, int *list, double *buf,
                            int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_comm_vel(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecBond::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecBond::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecBond::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_border(int n, int *list, double *buf,
                              int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_border_vel(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = molecule[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecBond::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecBond::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     molecule[i] = static_cast<int> (buf[m++]);
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecBond::pack_exchange(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = bond_type[i][k];
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = nspecial[i][0];
   buf[m++] = nspecial[i][1];
   buf[m++] = nspecial[i][2];
   for (k = 0; k < nspecial[i][2]; k++) buf[m++] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecBond::unpack_exchange(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   nspecial[nlocal][0] = static_cast<int> (buf[m++]);
   nspecial[nlocal][1] = static_cast<int> (buf[m++]);
   nspecial[nlocal][2] = static_cast<int> (buf[m++]);
   for (k = 0; k < nspecial[nlocal][2]; k++)
     special[nlocal][k] = static_cast<int> (buf[m++]);
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecBond::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 0;
   for (i = 0; i < nlocal; i++)
     n += 13 + 2*num_bond[i];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecBond::pack_restart(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = MAX(bond_type[i][k],-bond_type[i][k]);
     buf[m++] = bond_atom[i][k];
   }
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecBond::unpack_restart(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecBond::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   molecule[nlocal] = 0;
   num_bond[nlocal] = 0;
   nspecial[nlocal][0] = nspecial[nlocal][1] = nspecial[nlocal][2] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecBond::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   molecule[nlocal] = atoi(values[1]);
 
   type[nlocal] = atoi(values[2]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   num_bond[nlocal] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecBond::data_atom_hybrid(int nlocal, char **values)
 {
   molecule[nlocal] = atoi(values[0]);
 
   num_bond[nlocal] = 0;
 
   return 1;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecBond::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax);
   if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3);
   if (atom->memcheck("special"))
     bytes += memory->usage(special,nmax,atom->maxspecial);
 
   if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax);
   if (atom->memcheck("bond_type"))
     bytes += memory->usage(bond_type,nmax,atom->bond_per_atom);
   if (atom->memcheck("bond_atom"))
     bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom);
 
   return bytes;
 }
diff --git a/src/MOLECULE/atom_vec_full.cpp b/src/MOLECULE/atom_vec_full.cpp
index 2e180714b..e7f009c56 100644
--- a/src/MOLECULE/atom_vec_full.cpp
+++ b/src/MOLECULE/atom_vec_full.cpp
@@ -1,1035 +1,1035 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "atom_vec_full.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecFull::AtomVecFull(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 1;
   bonds_allow = angles_allow = dihedrals_allow = impropers_allow = 1;
   mass_type = 1;
 
   comm_x_only = comm_f_only = 1;
   size_forward = 3;
   size_reverse = 3;
   size_border = 8;
   size_velocity = 3;
   size_data_atom = 7;
   size_data_vel = 4;
   xcol_data = 5;
 
   atom->molecule_flag = atom->q_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecFull::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   q = memory->grow(atom->q,nmax,"atom:q");
   molecule = memory->grow(atom->molecule,nmax,"atom:molecule");
 
   nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial");
   special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special");
 
   num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond");
   bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom,
                            "atom:bond_type");
   bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom,
                            "atom:bond_atom");
 
   num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle");
   angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom,
                             "atom:angle_type");
   angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom,
                              "atom:angle_atom1");
   angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom,
                              "atom:angle_atom2");
   angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom,
                              "atom:angle_atom3");
 
   num_dihedral = memory->grow(atom->num_dihedral,nmax,"atom:num_dihedral");
   dihedral_type = memory->grow(atom->dihedral_type,nmax,
                                atom->dihedral_per_atom,"atom:dihedral_type");
   dihedral_atom1 =
     memory->grow(atom->dihedral_atom1,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom1");
   dihedral_atom2 =
     memory->grow(atom->dihedral_atom2,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom2");
   dihedral_atom3 =
     memory->grow(atom->dihedral_atom3,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom3");
   dihedral_atom4 =
     memory->grow(atom->dihedral_atom4,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom4");
 
   num_improper = memory->grow(atom->num_improper,nmax,"atom:num_improper");
   improper_type =
     memory->grow(atom->improper_type,nmax,atom->improper_per_atom,
                  "atom:improper_type");
   improper_atom1 =
     memory->grow(atom->improper_atom1,nmax,atom->improper_per_atom,
                  "atom:improper_atom1");
   improper_atom2 =
     memory->grow(atom->improper_atom2,nmax,atom->improper_per_atom,
                  "atom:improper_atom2");
   improper_atom3 =
     memory->grow(atom->improper_atom3,nmax,atom->improper_per_atom,
                  "atom:improper_atom3");
   improper_atom4 =
     memory->grow(atom->improper_atom4,nmax,atom->improper_per_atom,
                  "atom:improper_atom4");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecFull::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   q = atom->q; molecule = atom->molecule;
   nspecial = atom->nspecial; special = atom->special;
   num_bond = atom->num_bond; bond_type = atom->bond_type;
   bond_atom = atom->bond_atom;
   num_angle = atom->num_angle; angle_type = atom->angle_type;
   angle_atom1 = atom->angle_atom1; angle_atom2 = atom->angle_atom2;
   angle_atom3 = atom->angle_atom3;
   num_dihedral = atom->num_dihedral; dihedral_type = atom->dihedral_type;
   dihedral_atom1 = atom->dihedral_atom1; dihedral_atom2 = atom->dihedral_atom2;
   dihedral_atom3 = atom->dihedral_atom3; dihedral_atom4 = atom->dihedral_atom4;
   num_improper = atom->num_improper; improper_type = atom->improper_type;
   improper_atom1 = atom->improper_atom1; improper_atom2 = atom->improper_atom2;
   improper_atom3 = atom->improper_atom3; improper_atom4 = atom->improper_atom4;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecFull::copy(int i, int j, int delflag)
 {
   int k;
 
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   q[j] = q[i];
   molecule[j] = molecule[i];
 
   num_bond[j] = num_bond[i];
   for (k = 0; k < num_bond[j]; k++) {
     bond_type[j][k] = bond_type[i][k];
     bond_atom[j][k] = bond_atom[i][k];
   }
 
   num_angle[j] = num_angle[i];
   for (k = 0; k < num_angle[j]; k++) {
     angle_type[j][k] = angle_type[i][k];
     angle_atom1[j][k] = angle_atom1[i][k];
     angle_atom2[j][k] = angle_atom2[i][k];
     angle_atom3[j][k] = angle_atom3[i][k];
   }
 
   num_dihedral[j] = num_dihedral[i];
   for (k = 0; k < num_dihedral[j]; k++) {
     dihedral_type[j][k] = dihedral_type[i][k];
     dihedral_atom1[j][k] = dihedral_atom1[i][k];
     dihedral_atom2[j][k] = dihedral_atom2[i][k];
     dihedral_atom3[j][k] = dihedral_atom3[i][k];
     dihedral_atom4[j][k] = dihedral_atom4[i][k];
   }
 
   num_improper[j] = num_improper[i];
   for (k = 0; k < num_improper[j]; k++) {
     improper_type[j][k] = improper_type[i][k];
     improper_atom1[j][k] = improper_atom1[i][k];
     improper_atom2[j][k] = improper_atom2[i][k];
     improper_atom3[j][k] = improper_atom3[i][k];
     improper_atom4[j][k] = improper_atom4[i][k];
   }
 
   nspecial[j][0] = nspecial[i][0];
   nspecial[j][1] = nspecial[i][1];
   nspecial[j][2] = nspecial[i][2];
   for (k = 0; k < nspecial[j][2]; k++) special[j][k] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_comm(int n, int *list, double *buf,
                            int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_comm_vel(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecFull::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecFull::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecFull::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_border(int n, int *list, double *buf,
                              int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = molecule[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = molecule[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_border_vel(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = molecule[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = molecule[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = molecule[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = q[j];
     buf[m++] = molecule[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecFull::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     molecule[i] = static_cast<int> (buf[m++]);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecFull::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     molecule[i] = static_cast<int> (buf[m++]);
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     q[i] = buf[m++];
     molecule[i] = static_cast<int> (buf[m++]);
   }
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecFull::pack_exchange(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = q[i];
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = bond_type[i][k];
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = angle_type[i][k];
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   buf[m++] = num_dihedral[i];
   for (k = 0; k < num_dihedral[i]; k++) {
     buf[m++] = dihedral_type[i][k];
     buf[m++] = dihedral_atom1[i][k];
     buf[m++] = dihedral_atom2[i][k];
     buf[m++] = dihedral_atom3[i][k];
     buf[m++] = dihedral_atom4[i][k];
   }
 
   buf[m++] = num_improper[i];
   for (k = 0; k < num_improper[i]; k++) {
     buf[m++] = improper_type[i][k];
     buf[m++] = improper_atom1[i][k];
     buf[m++] = improper_atom2[i][k];
     buf[m++] = improper_atom3[i][k];
     buf[m++] = improper_atom4[i][k];
   }
 
   buf[m++] = nspecial[i][0];
   buf[m++] = nspecial[i][1];
   buf[m++] = nspecial[i][2];
   for (k = 0; k < nspecial[i][2]; k++) buf[m++] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecFull::unpack_exchange(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   q[nlocal] = buf[m++];
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_dihedral[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_dihedral[nlocal]; k++) {
     dihedral_type[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_improper[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_improper[nlocal]; k++) {
     improper_type[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   nspecial[nlocal][0] = static_cast<int> (buf[m++]);
   nspecial[nlocal][1] = static_cast<int> (buf[m++]);
   nspecial[nlocal][2] = static_cast<int> (buf[m++]);
   for (k = 0; k < nspecial[nlocal][2]; k++)
     special[nlocal][k] = static_cast<int> (buf[m++]);
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecFull::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 0;
   for (i = 0; i < nlocal; i++)
     n += 17 + 2*num_bond[i] + 4*num_angle[i] +
       5*num_dihedral[i] + 5*num_improper[i];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecFull::pack_restart(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = q[i];
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = MAX(bond_type[i][k],-bond_type[i][k]);
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = MAX(angle_type[i][k],-angle_type[i][k]);
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   buf[m++] = num_dihedral[i];
   for (k = 0; k < num_dihedral[i]; k++) {
     buf[m++] = MAX(dihedral_type[i][k],-dihedral_type[i][k]);
     buf[m++] = dihedral_atom1[i][k];
     buf[m++] = dihedral_atom2[i][k];
     buf[m++] = dihedral_atom3[i][k];
     buf[m++] = dihedral_atom4[i][k];
   }
 
   buf[m++] = num_improper[i];
   for (k = 0; k < num_improper[i]; k++) {
     buf[m++] = MAX(improper_type[i][k],-improper_type[i][k]);
     buf[m++] = improper_atom1[i][k];
     buf[m++] = improper_atom2[i][k];
     buf[m++] = improper_atom3[i][k];
     buf[m++] = improper_atom4[i][k];
   }
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecFull::unpack_restart(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   q[nlocal] = buf[m++];
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_dihedral[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_dihedral[nlocal]; k++) {
     dihedral_type[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_improper[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_improper[nlocal]; k++) {
     improper_type[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecFull::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   q[nlocal] = 0.0;
   molecule[nlocal] = 0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
   nspecial[nlocal][0] = nspecial[nlocal][1] = nspecial[nlocal][2] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecFull::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   molecule[nlocal] = atoi(values[1]);
 
   type[nlocal] = atoi(values[2]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   q[nlocal] = atof(values[3]);
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecFull::data_atom_hybrid(int nlocal, char **values)
 {
   molecule[nlocal] = atoi(values[1]);
   q[nlocal] = atof(values[3]);
 
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
 
   return 2;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecFull::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("q")) bytes += memory->usage(q,nmax);
   if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax);
   if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3);
   if (atom->memcheck("special"))
     bytes += memory->usage(special,nmax,atom->maxspecial);
 
   if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax);
   if (atom->memcheck("bond_type"))
     bytes += memory->usage(bond_type,nmax,atom->bond_per_atom);
   if (atom->memcheck("bond_atom"))
     bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom);
 
   if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax);
   if (atom->memcheck("angle_type"))
     bytes += memory->usage(angle_type,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom1"))
     bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom2"))
     bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom3"))
     bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom);
 
   if (atom->memcheck("num_dihedral")) bytes += memory->usage(num_dihedral,nmax);
   if (atom->memcheck("dihedral_type"))
     bytes += memory->usage(dihedral_type,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom1"))
     bytes += memory->usage(dihedral_atom1,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom2"))
     bytes += memory->usage(dihedral_atom2,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom3"))
     bytes += memory->usage(dihedral_atom3,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom4"))
     bytes += memory->usage(dihedral_atom4,nmax,atom->dihedral_per_atom);
 
   if (atom->memcheck("num_improper")) bytes += memory->usage(num_improper,nmax);
   if (atom->memcheck("improper_type"))
     bytes += memory->usage(improper_type,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom1"))
     bytes += memory->usage(improper_atom1,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom2"))
     bytes += memory->usage(improper_atom2,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom3"))
     bytes += memory->usage(improper_atom3,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom4"))
     bytes += memory->usage(improper_atom4,nmax,atom->improper_per_atom);
 
   return bytes;
 }
diff --git a/src/MOLECULE/atom_vec_molecular.cpp b/src/MOLECULE/atom_vec_molecular.cpp
index 5d5cb0df2..bb21e5b0f 100644
--- a/src/MOLECULE/atom_vec_molecular.cpp
+++ b/src/MOLECULE/atom_vec_molecular.cpp
@@ -1,1014 +1,1014 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "atom_vec_molecular.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecMolecular::AtomVecMolecular(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 1;
   bonds_allow = angles_allow = dihedrals_allow = impropers_allow = 1;
   mass_type = 1;
 
   comm_x_only = comm_f_only = 1;
   size_forward = 3;
   size_reverse = 3;
   size_border = 7;
   size_velocity = 3;
   size_data_atom = 6;
   size_data_vel = 4;
   xcol_data = 4;
 
   atom->molecule_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecMolecular::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   molecule = memory->grow(atom->molecule,nmax,"atom:molecule");
 
   nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial");
   special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special");
 
   num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond");
   bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom,
                            "atom:bond_type");
   bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom,
                            "atom:bond_atom");
 
   num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle");
   angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom,
                             "atom:angle_type");
   angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom,
                              "atom:angle_atom1");
   angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom,
                              "atom:angle_atom2");
   angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom,
                              "atom:angle_atom3");
 
   num_dihedral = memory->grow(atom->num_dihedral,nmax,"atom:num_dihedral");
   dihedral_type = memory->grow(atom->dihedral_type,nmax,
                                atom->dihedral_per_atom,"atom:dihedral_type");
   dihedral_atom1 =
     memory->grow(atom->dihedral_atom1,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom1");
   dihedral_atom2 =
     memory->grow(atom->dihedral_atom2,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom2");
   dihedral_atom3 =
     memory->grow(atom->dihedral_atom3,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom3");
   dihedral_atom4 =
     memory->grow(atom->dihedral_atom4,nmax,atom->dihedral_per_atom,
                  "atom:dihedral_atom4");
 
   num_improper = memory->grow(atom->num_improper,nmax,"atom:num_improper");
   improper_type =
     memory->grow(atom->improper_type,nmax,atom->improper_per_atom,
                  "atom:improper_type");
   improper_atom1 =
     memory->grow(atom->improper_atom1,nmax,atom->improper_per_atom,
                  "atom:improper_atom1");
   improper_atom2 =
     memory->grow(atom->improper_atom2,nmax,atom->improper_per_atom,
                  "atom:improper_atom2");
   improper_atom3 =
     memory->grow(atom->improper_atom3,nmax,atom->improper_per_atom,
                  "atom:improper_atom3");
   improper_atom4 =
     memory->grow(atom->improper_atom4,nmax,atom->improper_per_atom,
                  "atom:improper_atom4");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecMolecular::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   molecule = atom->molecule;
   nspecial = atom->nspecial; special = atom->special;
   num_bond = atom->num_bond; bond_type = atom->bond_type;
   bond_atom = atom->bond_atom;
   num_angle = atom->num_angle; angle_type = atom->angle_type;
   angle_atom1 = atom->angle_atom1; angle_atom2 = atom->angle_atom2;
   angle_atom3 = atom->angle_atom3;
   num_dihedral = atom->num_dihedral; dihedral_type = atom->dihedral_type;
   dihedral_atom1 = atom->dihedral_atom1; dihedral_atom2 = atom->dihedral_atom2;
   dihedral_atom3 = atom->dihedral_atom3; dihedral_atom4 = atom->dihedral_atom4;
   num_improper = atom->num_improper; improper_type = atom->improper_type;
   improper_atom1 = atom->improper_atom1; improper_atom2 = atom->improper_atom2;
   improper_atom3 = atom->improper_atom3; improper_atom4 = atom->improper_atom4;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecMolecular::copy(int i, int j, int delflag)
 {
   int k;
 
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   molecule[j] = molecule[i];
 
   num_bond[j] = num_bond[i];
   for (k = 0; k < num_bond[j]; k++) {
     bond_type[j][k] = bond_type[i][k];
     bond_atom[j][k] = bond_atom[i][k];
   }
 
   num_angle[j] = num_angle[i];
   for (k = 0; k < num_angle[j]; k++) {
     angle_type[j][k] = angle_type[i][k];
     angle_atom1[j][k] = angle_atom1[i][k];
     angle_atom2[j][k] = angle_atom2[i][k];
     angle_atom3[j][k] = angle_atom3[i][k];
   }
 
   num_dihedral[j] = num_dihedral[i];
   for (k = 0; k < num_dihedral[j]; k++) {
     dihedral_type[j][k] = dihedral_type[i][k];
     dihedral_atom1[j][k] = dihedral_atom1[i][k];
     dihedral_atom2[j][k] = dihedral_atom2[i][k];
     dihedral_atom3[j][k] = dihedral_atom3[i][k];
     dihedral_atom4[j][k] = dihedral_atom4[i][k];
   }
 
   num_improper[j] = num_improper[i];
   for (k = 0; k < num_improper[j]; k++) {
     improper_type[j][k] = improper_type[i][k];
     improper_atom1[j][k] = improper_atom1[i][k];
     improper_atom2[j][k] = improper_atom2[i][k];
     improper_atom3[j][k] = improper_atom3[i][k];
     improper_atom4[j][k] = improper_atom4[i][k];
   }
 
   nspecial[j][0] = nspecial[i][0];
   nspecial[j][1] = nspecial[i][1];
   nspecial[j][2] = nspecial[i][2];
   for (k = 0; k < nspecial[j][2]; k++) special[j][k] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_comm(int n, int *list, double *buf,
                                 int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_comm_vel(int n, int *list, double *buf,
                                     int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMolecular::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMolecular::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMolecular::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_border(int n, int *list, double *buf,
                                   int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_border_vel(int n, int *list, double *buf,
                                       int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = molecule[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = molecule[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = molecule[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMolecular::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMolecular::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     molecule[i] = static_cast<int> (buf[m++]);
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     molecule[i] = static_cast<int> (buf[m++]);
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_exchange(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = bond_type[i][k];
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = angle_type[i][k];
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   buf[m++] = num_dihedral[i];
   for (k = 0; k < num_dihedral[i]; k++) {
     buf[m++] = dihedral_type[i][k];
     buf[m++] = dihedral_atom1[i][k];
     buf[m++] = dihedral_atom2[i][k];
     buf[m++] = dihedral_atom3[i][k];
     buf[m++] = dihedral_atom4[i][k];
   }
 
   buf[m++] = num_improper[i];
   for (k = 0; k < num_improper[i]; k++) {
     buf[m++] = improper_type[i][k];
     buf[m++] = improper_atom1[i][k];
     buf[m++] = improper_atom2[i][k];
     buf[m++] = improper_atom3[i][k];
     buf[m++] = improper_atom4[i][k];
   }
 
   buf[m++] = nspecial[i][0];
   buf[m++] = nspecial[i][1];
   buf[m++] = nspecial[i][2];
   for (k = 0; k < nspecial[i][2]; k++) buf[m++] = special[i][k];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMolecular::unpack_exchange(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_dihedral[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_dihedral[nlocal]; k++) {
     dihedral_type[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_improper[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_improper[nlocal]; k++) {
     improper_type[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   nspecial[nlocal][0] = static_cast<int> (buf[m++]);
   nspecial[nlocal][1] = static_cast<int> (buf[m++]);
   nspecial[nlocal][2] = static_cast<int> (buf[m++]);
   for (k = 0; k < nspecial[nlocal][2]; k++)
     special[nlocal][k] = static_cast<int> (buf[m++]);
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecMolecular::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 0;
   for (i = 0; i < nlocal; i++)
     n += 16 + 2*num_bond[i] + 4*num_angle[i] +
       5*num_dihedral[i] + 5*num_improper[i];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecMolecular::pack_restart(int i, double *buf)
 {
   int k;
 
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = molecule[i];
 
   buf[m++] = num_bond[i];
   for (k = 0; k < num_bond[i]; k++) {
     buf[m++] = MAX(bond_type[i][k],-bond_type[i][k]);
     buf[m++] = bond_atom[i][k];
   }
 
   buf[m++] = num_angle[i];
   for (k = 0; k < num_angle[i]; k++) {
     buf[m++] = MAX(angle_type[i][k],-angle_type[i][k]);
     buf[m++] = angle_atom1[i][k];
     buf[m++] = angle_atom2[i][k];
     buf[m++] = angle_atom3[i][k];
   }
 
   buf[m++] = num_dihedral[i];
   for (k = 0; k < num_dihedral[i]; k++) {
     buf[m++] = MAX(dihedral_type[i][k],-dihedral_type[i][k]);
     buf[m++] = dihedral_atom1[i][k];
     buf[m++] = dihedral_atom2[i][k];
     buf[m++] = dihedral_atom3[i][k];
     buf[m++] = dihedral_atom4[i][k];
   }
 
   buf[m++] = num_improper[i];
   for (k = 0; k < num_improper[i]; k++) {
     buf[m++] = MAX(improper_type[i][k],-improper_type[i][k]);
     buf[m++] = improper_atom1[i][k];
     buf[m++] = improper_atom2[i][k];
     buf[m++] = improper_atom3[i][k];
     buf[m++] = improper_atom4[i][k];
   }
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecMolecular::unpack_restart(double *buf)
 {
   int k;
 
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   molecule[nlocal] = static_cast<int> (buf[m++]);
 
   num_bond[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_bond[nlocal]; k++) {
     bond_type[nlocal][k] = static_cast<int> (buf[m++]);
     bond_atom[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_angle[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_angle[nlocal]; k++) {
     angle_type[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     angle_atom3[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_dihedral[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_dihedral[nlocal]; k++) {
     dihedral_type[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     dihedral_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   num_improper[nlocal] = static_cast<int> (buf[m++]);
   for (k = 0; k < num_improper[nlocal]; k++) {
     improper_type[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom1[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom2[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom3[nlocal][k] = static_cast<int> (buf[m++]);
     improper_atom4[nlocal][k] = static_cast<int> (buf[m++]);
   }
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecMolecular::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   molecule[nlocal] = 0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
   nspecial[nlocal][0] = nspecial[nlocal][1] = nspecial[nlocal][2] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecMolecular::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   molecule[nlocal] = atoi(values[1]);
 
   type[nlocal] = atoi(values[2]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecMolecular::data_atom_hybrid(int nlocal, char **values)
 {
   molecule[nlocal] = atoi(values[0]);
 
   num_bond[nlocal] = 0;
   num_angle[nlocal] = 0;
   num_dihedral[nlocal] = 0;
   num_improper[nlocal] = 0;
 
   return 1;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecMolecular::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax);
   if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3);
   if (atom->memcheck("special"))
     bytes += memory->usage(special,nmax,atom->maxspecial);
 
   if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax);
   if (atom->memcheck("bond_type"))
     bytes += memory->usage(bond_type,nmax,atom->bond_per_atom);
   if (atom->memcheck("bond_atom"))
     bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom);
 
   if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax);
   if (atom->memcheck("angle_type"))
     bytes += memory->usage(angle_type,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom1"))
     bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom2"))
     bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom);
   if (atom->memcheck("angle_atom3"))
     bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom);
 
   if (atom->memcheck("num_dihedral")) bytes += memory->usage(num_dihedral,nmax);
   if (atom->memcheck("dihedral_type"))
     bytes += memory->usage(dihedral_type,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom1"))
     bytes += memory->usage(dihedral_atom1,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom2"))
     bytes += memory->usage(dihedral_atom2,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom3"))
     bytes += memory->usage(dihedral_atom3,nmax,atom->dihedral_per_atom);
   if (atom->memcheck("dihedral_atom4"))
     bytes += memory->usage(dihedral_atom4,nmax,atom->dihedral_per_atom);
 
   if (atom->memcheck("num_improper")) bytes += memory->usage(num_improper,nmax);
   if (atom->memcheck("improper_type"))
     bytes += memory->usage(improper_type,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom1"))
     bytes += memory->usage(improper_atom1,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom2"))
     bytes += memory->usage(improper_atom2,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom3"))
     bytes += memory->usage(improper_atom3,nmax,atom->improper_per_atom);
   if (atom->memcheck("improper_atom4"))
     bytes += memory->usage(improper_atom4,nmax,atom->improper_per_atom);
 
   return bytes;
 }
diff --git a/src/PERI/atom_vec_peri.cpp b/src/PERI/atom_vec_peri.cpp
index 6c3992d77..8bccaf5de 100644
--- a/src/PERI/atom_vec_peri.cpp
+++ b/src/PERI/atom_vec_peri.cpp
@@ -1,835 +1,835 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Mike Parks (SNL)
 ------------------------------------------------------------------------- */
 
 #include "float.h"
 #include "stdlib.h"
 #include "atom_vec_peri.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecPeri::AtomVecPeri(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   molecular = 0;
 
   comm_x_only = 0;
   comm_f_only = 1;
   size_forward = 4;
   size_reverse = 3;
   size_border = 11;
   size_velocity = 3;
   size_data_atom = 7;
   size_data_vel = 4;
   xcol_data = 5;
 
   atom->peri_flag = 1;
   atom->vfrac_flag = atom->rmass_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecPeri::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   vfrac = memory->grow(atom->vfrac,nmax,"atom:vfrac");
   rmass = memory->grow(atom->rmass,nmax,"atom:rmass");
   s0 = memory->grow(atom->s0,nmax,"atom:s0");
   x0 = memory->grow(atom->x0,nmax,3,"atom:x0");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecPeri::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   vfrac = atom->vfrac; rmass = atom->rmass;
   s0 = atom->s0; x0 = atom->x0;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecPeri::copy(int i, int j, int delflag)
 {
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   vfrac[j] = vfrac[i];
   rmass[j] = rmass[i];
   s0[j] = s0[i];
   x0[j][0] = x0[i][0];
   x0[j][1] = x0[i][1];
   x0[j][2] = x0[i][2];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_comm(int n, int *list, double *buf,
                            int pbc_flag, int *pbc)
 
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = s0[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = s0[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_comm_vel(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = s0[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = s0[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = s0[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_comm_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = s0[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecPeri::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     s0[i] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecPeri::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     s0[i] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::unpack_comm_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     s0[i] = buf[m++];
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecPeri::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_border(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = vfrac[j];
       buf[m++] = s0[j];
       buf[m++] = x0[j][0];
       buf[m++] = x0[j][1];
       buf[m++] = x0[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = vfrac[j];
       buf[m++] = s0[j];
       buf[m++] = x0[j][0];
       buf[m++] = x0[j][1];
       buf[m++] = x0[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_border_vel(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = vfrac[j];
       buf[m++] = s0[j];
       buf[m++] = x0[j][0];
       buf[m++] = x0[j][1];
       buf[m++] = x0[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = vfrac[j];
         buf[m++] = s0[j];
         buf[m++] = x0[j][0];
         buf[m++] = x0[j][1];
         buf[m++] = x0[j][2];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = vfrac[j];
         buf[m++] = s0[j];
         buf[m++] = x0[j][0];
         buf[m++] = x0[j][1];
         buf[m++] = x0[j][2];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = vfrac[j];
     buf[m++] = s0[j];
     buf[m++] = x0[j][0];
     buf[m++] = x0[j][1];
     buf[m++] = x0[j][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecPeri::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     vfrac[i] = buf[m++];
     s0[i] = buf[m++];
     x0[i][0] = buf[m++];
     x0[i][1] = buf[m++];
     x0[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecPeri::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     vfrac[i] = buf[m++];
     s0[i] = buf[m++];
     x0[i][0] = buf[m++];
     x0[i][1] = buf[m++];
     x0[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     vfrac[i] = buf[m++];
     s0[i] = buf[m++];
     x0[i][0] = buf[m++];
     x0[i][1] = buf[m++];
     x0[i][2] = buf[m++];
   }
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_exchange(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = vfrac[i];
   buf[m++] = rmass[i];
   buf[m++] = s0[i];
   buf[m++] = x0[i][0];
   buf[m++] = x0[i][1];
   buf[m++] = x0[i][2];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecPeri::unpack_exchange(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   vfrac[nlocal] = buf[m++];
   rmass[nlocal] = buf[m++];
   s0[nlocal] = buf[m++];
   x0[nlocal][0] = buf[m++];
   x0[nlocal][1] = buf[m++];
   x0[nlocal][2] = buf[m++];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecPeri::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 17 * nlocal;
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecPeri::pack_restart(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = vfrac[i];
   buf[m++] = rmass[i];
   buf[m++] = s0[i];
   buf[m++] = x0[i][0];
   buf[m++] = x0[i][1];
   buf[m++] = x0[i][2];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecPeri::unpack_restart(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   vfrac[nlocal] = buf[m++];
   rmass[nlocal] = buf[m++];
   s0[nlocal] = buf[m++];
   x0[nlocal][0] = buf[m++];
   x0[nlocal][1] = buf[m++];
   x0[nlocal][2] = buf[m++];
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecPeri::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   vfrac[nlocal] = 1.0;
   rmass[nlocal] = 1.0;
   s0[nlocal] = DBL_MAX;
   x0[nlocal][0] = coord[0];
   x0[nlocal][1] = coord[1];
   x0[nlocal][2] = coord[2];
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecPeri::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   type[nlocal] = atoi(values[1]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   vfrac[nlocal] = atof(values[2]);
   rmass[nlocal] = atof(values[3]);
   if (rmass[nlocal] <= 0.0) error->one(FLERR,"Invalid mass value");
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   s0[nlocal] = DBL_MAX;
   x0[nlocal][0] = coord[0];
   x0[nlocal][1] = coord[1];
   x0[nlocal][2] = coord[2];
 
   atom->nlocal++;
 }
 
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecPeri::data_atom_hybrid(int nlocal, char **values)
 {
   vfrac[nlocal] = atof(values[0]);
   rmass[nlocal] = atof(values[1]);
   if (rmass[nlocal] <= 0.0) error->one(FLERR,"Invalid mass value");
 
   s0[nlocal] = DBL_MAX;
   x0[nlocal][0] = x[nlocal][0];
   x0[nlocal][1] = x[nlocal][1];
   x0[nlocal][2] = x[nlocal][2];
 
   return 2;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecPeri::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("vfrac")) bytes += memory->usage(vfrac,nmax);
   if (atom->memcheck("rmass")) bytes += memory->usage(rmass,nmax);
   if (atom->memcheck("s0")) bytes += memory->usage(s0,nmax);
   if (atom->memcheck("x0")) bytes += memory->usage(x0,nmax,3);
 
   return bytes;
 }
diff --git a/src/REPLICA/fix_event.cpp b/src/REPLICA/fix_event.cpp
index c8d0273f2..f62f2983d 100644
--- a/src/REPLICA/fix_event.cpp
+++ b/src/REPLICA/fix_event.cpp
@@ -1,264 +1,264 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Mike Brown (SNL), Aidan Thompson (SNL)
 ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "string.h"
 #include "fix_event.h"
 #include "atom.h"
 #include "update.h"
 #include "domain.h"
 #include "neighbor.h"
 #include "comm.h"
 #include "universe.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 using namespace FixConst;
 
 /* ---------------------------------------------------------------------- */
 
 FixEvent::FixEvent(LAMMPS *lmp, int narg, char **arg) :
   Fix(lmp, narg, arg)
 {
   if (narg != 3) error->all(FLERR,"Illegal fix event command");
 
   restart_global = 1;
 
   // perform initial allocation of atom-based array
   // register with Atom class
 
   xevent = NULL;
   xold = NULL;
   vold = NULL;
   imageold = NULL;
   grow_arrays(atom->nmax);
   atom->add_callback(0);
 }
 
 /* ---------------------------------------------------------------------- */
 
 FixEvent::~FixEvent()
 {
   // unregister callbacks to this fix from Atom class
 
   atom->delete_callback(id,0);
 
   // delete locally stored array
 
   memory->destroy(xevent);
   memory->destroy(xold);
   memory->destroy(vold);
   memory->destroy(imageold);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int FixEvent::setmask()
 {
   return 0;
 }
 
 /* ----------------------------------------------------------------------
    save current atom coords as an event
    called when an event occurs
 ------------------------------------------------------------------------- */
 
 void FixEvent::store_event()
 {
   double **x = atom->x;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
 
   for (int i = 0; i < nlocal; i++)
     domain->unmap(x[i],image[i],xevent[i]);
 
 }
 
 /* ----------------------------------------------------------------------
    restore atom coords to quenched initial state
    called prior to NEB calculation
 ------------------------------------------------------------------------- */
 
 void FixEvent::restore_event()
 {
   double **x = atom->x;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
 
   for (int i = 0; i < nlocal; i++) {
     x[i][0] = xevent[i][0];
     x[i][1] = xevent[i][1];
     x[i][2] = xevent[i][2];
 
     // Since xevent is unwrapped coordinate, need to
     // adjust image flags when remapping
 
-    image[i] = ((tagint) IMGMAX << IMG2BITS) | 
+    image[i] = ((tagint) IMGMAX << IMG2BITS) |
       ((tagint) IMGMAX << IMGBITS) | IMGMASK;
     domain->remap(x[i],image[i]);
   }
 
 }
 
 /* ----------------------------------------------------------------------
    store state of all atoms
    called before quench and subsequent check for event
    so can later restore pre-quench state if no event occurs
 ------------------------------------------------------------------------- */
 
 void FixEvent::store_state()
 {
   double **x = atom->x;
   double **v = atom->v;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
 
   for (int i = 0; i < nlocal; i++) {
     xold[i][0] = x[i][0];
     xold[i][1] = x[i][1];
     xold[i][2] = x[i][2];
     vold[i][0] = v[i][0];
     vold[i][1] = v[i][1];
     vold[i][2] = v[i][2];
     imageold[i] = image[i];
   }
 }
 
 /* ----------------------------------------------------------------------
    restore state of all atoms to pre-quench state
    called after no event detected so can continue
 ------------------------------------------------------------------------- */
 
 void FixEvent::restore_state()
 {
   double **x = atom->x;
   double **v = atom->v;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
 
   for (int i = 0; i < nlocal; i++) {
     x[i][0] = xold[i][0];
     x[i][1] = xold[i][1];
     x[i][2] = xold[i][2];
     v[i][0] = vold[i][0];
     v[i][1] = vold[i][1];
     v[i][2] = vold[i][2];
     image[i] = imageold[i];
   }
 }
 
 /* ----------------------------------------------------------------------
    memory usage of local atom-based array
 ------------------------------------------------------------------------- */
 
 double FixEvent::memory_usage()
 {
   double bytes = 6*atom->nmax * sizeof(double);
   bytes += atom->nmax*sizeof(int);
   return bytes;
 }
 
 /* ----------------------------------------------------------------------
    allocate atom-based array
 ------------------------------------------------------------------------- */
 
 void FixEvent::grow_arrays(int nmax)
 {
   memory->grow(xevent,nmax,3,"event:xevent");
   memory->grow(xold,nmax,3,"event:xold");
   memory->grow(vold,nmax,3,"event:vold");
   memory->grow(imageold,nmax,"event:imageold");
 
   // allow compute event to access stored event coords
 
   array_atom = xevent;
 }
 
 /* ----------------------------------------------------------------------
    copy values within local atom-based array
 ------------------------------------------------------------------------- */
 
 void FixEvent::copy_arrays(int i, int j)
 {
   xevent[j][0] = xevent[i][0];
   xevent[j][1] = xevent[i][1];
   xevent[j][2] = xevent[i][2];
   xold[j][0] = xold[i][0];
   xold[j][1] = xold[i][1];
   xold[j][2] = xold[i][2];
   vold[j][0] = vold[i][0];
   vold[j][1] = vold[i][1];
   vold[j][2] = vold[i][2];
   imageold[j] = imageold[i];
 }
 
 /* ----------------------------------------------------------------------
    pack values in local atom-based array for exchange with another proc
 ------------------------------------------------------------------------- */
 
 int FixEvent::pack_exchange(int i, double *buf)
 {
   buf[0] = xevent[i][0];
   buf[1] = xevent[i][1];
   buf[2] = xevent[i][2];
   buf[3] = xold[i][0];
   buf[4] = xold[i][1];
   buf[5] = xold[i][2];
   buf[6] = vold[i][0];
   buf[7] = vold[i][1];
   buf[8] = vold[i][2];
   buf[9] = imageold[i];
 
   return 10;
 }
 
 /* ----------------------------------------------------------------------
    unpack values in local atom-based array from exchange with another proc
 ------------------------------------------------------------------------- */
 
 int FixEvent::unpack_exchange(int nlocal, double *buf)
 {
   xevent[nlocal][0] = buf[0];
   xevent[nlocal][1] = buf[1];
   xevent[nlocal][2] = buf[2];
   xold[nlocal][0] = buf[3];
   xold[nlocal][1] = buf[4];
   xold[nlocal][2] = buf[5];
   vold[nlocal][0] = buf[6];
   vold[nlocal][1] = buf[7];
   vold[nlocal][2] = buf[8];
   imageold[nlocal] = static_cast<int>(buf[9]);
 
   return 10;
 }
 
 /* ----------------------------------------------------------------------
    pack entire state of Fix into one write
 ------------------------------------------------------------------------- */
 
 void FixEvent::write_restart(FILE *fp)
 {
 }
 
 /* ----------------------------------------------------------------------
    use state info from restart file to restart the Fix
 ------------------------------------------------------------------------- */
 
 void FixEvent::restart(char *buf)
 {
 }
diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp
index 05170719a..bd736607b 100644
--- a/src/REPLICA/tad.cpp
+++ b/src/REPLICA/tad.cpp
@@ -1,1021 +1,1021 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Aidan Thompson (SNL)
 ------------------------------------------------------------------------- */
 
 #include "lmptype.h"
 #include "mpi.h"
 #include "math.h"
 #include "stdlib.h"
 #include "string.h"
 #include "tad.h"
 #include "universe.h"
 #include "update.h"
 #include "atom.h"
 #include "domain.h"
 #include "region.h"
 #include "comm.h"
 #include "velocity.h"
 #include "integrate.h"
 #include "min.h"
 #include "neighbor.h"
 #include "modify.h"
 #include "neb.h"
 #include "compute.h"
 #include "fix.h"
 #include "fix_event_tad.h"
 #include "fix_store_state.h"
 #include "force.h"
 #include "pair.h"
 #include "random_park.h"
 #include "random_mars.h"
 #include "output.h"
 #include "dump.h"
 #include "finish.h"
 #include "timer.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 TAD::TAD(LAMMPS *lmp) : Pointers(lmp) {}
 
 /* ---------------------------------------------------------------------- */
 
 TAD::~TAD()
 {
   memory->sfree(fix_event_list);
   if (neb_logfilename != NULL) delete [] neb_logfilename;
   delete [] min_style;
   delete [] min_style_neb;
 }
 
 /* ----------------------------------------------------------------------
    perform TAD simulation on root proc
    other procs only used for NEB calcs
 ------------------------------------------------------------------------- */
 
 void TAD::command(int narg, char **arg)
 {
 
   fix_event_list = NULL;
   n_event_list = 0;
   nmax_event_list = 0;
   nmin_event_list = 10;
 
   // error checks
 
   if (domain->box_exist == 0)
     error->all(FLERR,"Tad command before simulation box is defined");
   if (universe->nworlds == 1)
     error->all(FLERR,"Cannot use TAD with a single replica for NEB");
   if (universe->nworlds != universe->nprocs)
     error->all(FLERR,"Can only use TAD with 1-processor replicas for NEB");
   if (atom->sortfreq > 0)
     error->all(FLERR,"Cannot use TAD with atom_modify sort enabled for NEB");
   if (atom->map_style == 0)
     error->all(FLERR,"Cannot use TAD unless atom map exists for NEB");
 
   if (narg < 7) error->universe_all(FLERR,"Illegal tad command");
 
   nsteps = atoi(arg[0]);
   t_event = atoi(arg[1]);
   templo = atof(arg[2]);
   temphi = atof(arg[3]);
   delta_conf = atof(arg[4]);
   tmax = atof(arg[5]);
 
   char *id_compute = new char[strlen(arg[6])+1];
   strcpy(id_compute,arg[6]);
 
   options(narg-7,&arg[7]);
 
   // total # of timesteps must be multiple of t_event
 
   if (t_event <= 0) error->universe_all(FLERR,"Invalid t_event in tad command");
   if (nsteps % t_event)
     error->universe_all(FLERR,"TAD nsteps must be multiple of t_event");
 
   if (delta_conf <= 0.0 || delta_conf >= 1.0)
     error->universe_all(FLERR,"Invalid delta_conf in tad command");
 
   if (tmax <= 0.0)
     error->universe_all(FLERR,"Invalid tmax in tad command");
 
   // deltconf = (ln(1/delta))/freq_min (timestep units)
 
   deltconf = -log(delta_conf)*tmax/update->dt;
 
   // local storage
 
   int me_universe = universe->me;
   int nprocs_universe = universe->nprocs;
 
   MPI_Comm_rank(world,&me);
   MPI_Comm_size(world,&nprocs);
 
   delta_beta = (1.0/templo - 1.0/temphi) / force->boltz;
   ratio_beta = templo/temphi;
 
   // create FixEventTAD object to store last event
 
   int narg2 = 3;
   char **args = new char*[narg2];
   args[0] = (char *) "tad_event";
   args[1] = (char *) "all";
   args[2] = (char *) "EVENT/TAD";
   modify->add_fix(narg2,args);
   fix_event = (FixEventTAD *) modify->fix[modify->nfix-1];
   delete [] args;
 
   // create FixStoreState object to store revert state
 
   narg2 = 13;
   args = new char*[narg2];
   args[0] = (char *) "tad_revert";
   args[1] = (char *) "all";
   args[2] = (char *) "store/state";
   args[3] = (char *) "0";
   args[4] = (char *) "x";
   args[5] = (char *) "y";
   args[6] = (char *) "z";
   args[7] = (char *) "ix";
   args[8] = (char *) "iy";
   args[9] = (char *) "iz";
   args[10] = (char *) "vx";
   args[11] = (char *) "vy";
   args[12] = (char *) "vz";
   modify->add_fix(narg2,args);
   fix_revert = (FixStoreState *) modify->fix[modify->nfix-1];
   delete [] args;
 
   // create Finish for timing output
 
   finish = new Finish(lmp);
 
   // assign FixEventTAD to event-detection compute
   // necessary so it will know atom coords at last event
 
   int icompute = modify->find_compute(id_compute);
   if (icompute < 0) error->all(FLERR,"Could not find compute ID for TAD");
   compute_event = modify->compute[icompute];
   compute_event->reset_extra_compute_fix("tad_event");
 
   // reset reneighboring criteria since will perform minimizations
 
   neigh_every = neighbor->every;
   neigh_delay = neighbor->delay;
   neigh_dist_check = neighbor->dist_check;
 
   if (neigh_every != 1 || neigh_delay != 0 || neigh_dist_check != 1) {
     if (me_universe == 0)
       error->warning(FLERR,"Resetting reneighboring criteria during TAD");
   }
 
   neighbor->every = 1;
   neighbor->delay = 0;
   neighbor->dist_check = 1;
 
   // initialize TAD as if one long dynamics run
 
   update->whichflag = 1;
   update->nsteps = nsteps;
   update->beginstep = update->firststep = update->ntimestep;
   update->endstep = update->laststep = update->firststep + nsteps;
   update->restrict_output = 1;
   if (update->laststep < 0 || update->laststep > MAXBIGINT)
     error->all(FLERR,"Too many timesteps");
 
   lmp->init();
 
   // set minimize style for quench
 
   narg2 = 1;
   args = new char*[narg2];
   args[0] = min_style;
 
   update->create_minimize(narg2,args);
 
   delete [] args;
 
   // init minimizer settings and minimizer itself
 
   update->etol = etol;
   update->ftol = ftol;
   update->max_eval = maxeval;
 
   update->minimize->init();
 
   // perform TAD simulation
 
   if (me_universe == 0 && universe->uscreen)
     fprintf(universe->uscreen,"Setting up TAD ...\n");
 
   if (me_universe == 0) {
     if (universe->uscreen)
       fprintf(universe->uscreen,
               "Step CPU N M Status Barrier Margin t_lo delt_lo\n"
               );
     if (universe->ulogfile)
       fprintf(universe->ulogfile,
               "Step CPU N M Status Barrier Margin t_lo delt_lo\n"
               );
   }
 
   ulogfile_lammps = universe->ulogfile;
   uscreen_lammps = universe->uscreen;
   ulogfile_neb = NULL;
   uscreen_neb = NULL;
   if (me_universe == 0 && neb_logfilename)
     ulogfile_neb = fopen(neb_logfilename,"w");
 
   // store hot state and quenched event, only on replica 0
 
   // need this line if quench() does only setup_minimal()
   // update->minimize->setup();
 
   // This should work with if uncommented, but does not
   // if (universe->iworld == 0) {
 
   fix_event->store_state();
   quench();
 
   timer->init();
   timer->barrier_start(TIME_LOOP);
   time_start = timer->array[TIME_LOOP];
   fix_event->store_event_tad(update->ntimestep);
   log_event(0);
   fix_event->restore_state();
 
   // do full init/setup
 
   update->whichflag = 1;
   lmp->init();
   update->integrate->setup();
   //   }
 
   // main loop: look for events until out of time
   // (1) dynamics, store state, quench, check event, restore state
   // (2) if event, perform NEB, record in fix_event_list
   // (3) if confident, pick earliest event
 
   nbuild = ndanger = 0;
   time_neb = time_dynamics = time_quench = time_comm = time_output = 0.0;
 
   timer->barrier_start(TIME_LOOP);
   time_start = timer->array[TIME_LOOP];
 
   int confident_flag, event_flag;
 
   if (universe->iworld == 0) {
     while (update->ntimestep < update->endstep) {
 
       // initialize list of possible events
 
       initialize_event_list();
       confident_flag = 0;
 
       while (update->ntimestep < update->endstep) {
         event_flag = 0;
         while (update->ntimestep < update->endstep) {
 
           dynamics();
 
 
           fix_event->store_state();
 
 
           quench();
 
 
           event_flag = check_event();
           MPI_Bcast(&event_flag,1,MPI_INT,0,universe->uworld);
 
           if (event_flag) break;
 
           // restore hot state
 
           fix_event->restore_state();
 
           // store hot state in revert
 
           fix_revert->end_of_step();
         }
         if (!event_flag) break;
 
         add_event();
 
         perform_neb(n_event_list-1);
         compute_tlo(n_event_list-1);
         confident_flag = check_confidence();
         MPI_Bcast(&confident_flag,1,MPI_INT,0,universe->uworld);
         if (confident_flag) break;
         if (universe->iworld == 0) revert();
       }
       if (!confident_flag) break;
 
       perform_event(event_first);
 
       // need to sync timestep with TAD
 
       MPI_Bcast(&(update->ntimestep),1,MPI_INT,0,universe->uworld);
 
       int restart_flag = 0;
       if (output->restart_flag && universe->iworld == 0) {
         if (output->restart_every_single &&
             fix_event->event_number % output->restart_every_single == 0)
           restart_flag = 1;
         if (output->restart_every_double &&
             fix_event->event_number % output->restart_every_double == 0)
           restart_flag = 1;
       }
 
       // full init/setup since are starting after event
 
       update->whichflag = 1;
       lmp->init();
       update->integrate->setup();
 
     // write restart file of hot coords
 
       if (restart_flag) {
         timer->barrier_start(TIME_LOOP);
         output->write_restart(update->ntimestep);
         timer->barrier_stop(TIME_LOOP);
         time_output += timer->array[TIME_LOOP];
       }
     }
 
   } else {
 
     while (update->ntimestep < update->endstep) {
       confident_flag = 0;
       while (update->ntimestep < update->endstep) {
         event_flag = 0;
         while (update->ntimestep < update->endstep) {
           update->ntimestep += t_event;
           MPI_Bcast(&event_flag,1,MPI_INT,0,universe->uworld);
 
           if (event_flag) break;
         }
         if (!event_flag) break;
         perform_neb(-1);
         MPI_Bcast(&confident_flag,1,MPI_INT,0,universe->uworld);
         if (confident_flag) break;
       }
       if (!confident_flag) break;
 
       // need to sync timestep with TAD
 
       MPI_Bcast(&(update->ntimestep),1,MPI_INT,0,universe->uworld);
     }
   }
 
   // set total timers and counters so Finish() will process them
 
   timer->array[TIME_LOOP] = time_start;
   timer->barrier_stop(TIME_LOOP);
 
   timer->array[TIME_PAIR] = time_neb;
   timer->array[TIME_BOND] = time_dynamics;
   timer->array[TIME_KSPACE] = time_quench;
   timer->array[TIME_COMM] = time_comm;
   timer->array[TIME_OUTPUT] = time_output;
 
   neighbor->ncalls = nbuild;
   neighbor->ndanger = ndanger;
 
   if (me_universe == 0) {
     if (universe->uscreen)
       fprintf(universe->uscreen,
               "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT
               " atoms\n",
               timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms);
     if (universe->ulogfile)
       fprintf(universe->ulogfile,
               "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT
               " atoms\n",
               timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms);
   }
 
   if (me_universe == 0) fclose(ulogfile_neb);
 
   finish->end(3);
 
   update->whichflag = 0;
   update->firststep = update->laststep = 0;
   update->beginstep = update->endstep = 0;
   update->restrict_output = 0;
 
   // reset reneighboring criteria
 
   neighbor->every = neigh_every;
   neighbor->delay = neigh_delay;
   neighbor->dist_check = neigh_dist_check;
 
 
   delete [] id_compute;
   delete finish;
   modify->delete_fix("tad_event");
   modify->delete_fix("tad_revert");
   delete_event_list();
 
   compute_event->reset_extra_compute_fix(NULL);
 }
 
 /* ----------------------------------------------------------------------
    single short dynamics run
 ------------------------------------------------------------------------- */
 
 void TAD::dynamics()
 {
   update->whichflag = 1;
   update->nsteps = t_event;
 
   lmp->init();
   update->integrate->setup();
   // this may be needed if don't do full init
   //modify->addstep_compute_all(update->ntimestep);
   int ncalls = neighbor->ncalls;
 
   timer->barrier_start(TIME_LOOP);
   update->integrate->run(t_event);
   timer->barrier_stop(TIME_LOOP);
   time_dynamics += timer->array[TIME_LOOP];
 
   nbuild += neighbor->ncalls - ncalls;
   ndanger += neighbor->ndanger;
 
   update->integrate->cleanup();
   finish->end(0);
 }
 
 /* ----------------------------------------------------------------------
    quench minimization
 ------------------------------------------------------------------------- */
 
 void TAD::quench()
 {
   bigint ntimestep_hold = update->ntimestep;
   bigint endstep_hold = update->endstep;
 
   // need to change whichflag so that minimize->setup() calling
   // modify->setup() will call fix->min_setup()
 
   update->whichflag = 2;
   update->nsteps = maxiter;
   update->endstep = update->laststep = update->firststep + maxiter;
   if (update->laststep < 0 || update->laststep > MAXBIGINT)
     error->all(FLERR,"Too many iterations");
 
   // full init works
 
   lmp->init();
   update->minimize->setup();
 
   // partial init does not work
 
   //modify->addstep_compute_all(update->ntimestep);
   //update->minimize->setup_minimal(1);
 
   int ncalls = neighbor->ncalls;
 
   timer->barrier_start(TIME_LOOP);
   update->minimize->run(maxiter);
   timer->barrier_stop(TIME_LOOP);
   time_quench += timer->array[TIME_LOOP];
 
   if (neighbor->ncalls == ncalls) quench_reneighbor = 0;
   else quench_reneighbor = 1;
 
   update->minimize->cleanup();
   finish->end(1);
 
   // reset timestep as if quench did not occur
   // clear timestep storage from computes, since now invalid
 
   update->ntimestep = ntimestep_hold;
   update->endstep = update->laststep = endstep_hold;
   for (int i = 0; i < modify->ncompute; i++)
     if (modify->compute[i]->timeflag) modify->compute[i]->clearstep();
 }
 
 /* ----------------------------------------------------------------------
    check for an event
    return 0 if no event
    return 1 if event
 ------------------------------------------------------------------------- */
 
 int TAD::check_event()
 {
   int flag;
 
   flag = 0;
   if (compute_event->compute_scalar() > 0.0) flag = 1;
 
   return flag;
 }
 
 /* ----------------------------------------------------------------------
    universe proc 0 prints event info
 ------------------------------------------------------------------------- */
 
 void TAD::log_event(int ievent)
 {
   timer->array[TIME_LOOP] = time_start;
   if (universe->me == 0) {
     double tfrac = 0.0;
     if (universe->uscreen)
       fprintf(universe->uscreen,
               BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n",
               fix_event->event_timestep,
               timer->elapsed(TIME_LOOP),
               fix_event->event_number,ievent,
               "E ",
               fix_event->ebarrier,tfrac,
               fix_event->tlo,deltfirst);
     if (universe->ulogfile)
       fprintf(universe->ulogfile,
               BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n",
               fix_event->event_timestep,
               timer->elapsed(TIME_LOOP),
               fix_event->event_number,ievent,
               "E ",
               fix_event->ebarrier,tfrac,
               fix_event->tlo,deltfirst);
   }
 
   // dump snapshot of quenched coords
   // must reneighbor and compute forces before dumping
   // addstep_compute_all insures eng/virial are calculated if needed
 
   if (output->ndump && universe->iworld == 0) {
     timer->barrier_start(TIME_LOOP);
     modify->addstep_compute_all(update->ntimestep);
     update->integrate->setup_minimal(1);
     output->write_dump(update->ntimestep);
     timer->barrier_stop(TIME_LOOP);
     time_output += timer->array[TIME_LOOP];
   }
 
 }
 
 /* ----------------------------------------------------------------------
    parse optional parameters at end of TAD input line
 ------------------------------------------------------------------------- */
 
 void TAD::options(int narg, char **arg)
 {
   if (narg < 0) error->all(FLERR,"Illegal tad command");
 
   // set defaults
 
   etol = 0.1;
   ftol = 0.1;
   maxiter = 40;
   maxeval = 50;
 
   etol_neb = 0.01;
   ftol_neb = 0.01;
   n1steps_neb = 100;
   n2steps_neb = 100;
   nevery_neb = 10;
 
   min_style = new char[3];
   strcpy(min_style,"cg");
   min_style_neb = new char[9];
   strcpy(min_style_neb,"quickmin");
   neb_logfilename = NULL;
 
   int iarg = 0;
   while (iarg < narg) {
     if (strcmp(arg[iarg],"min") == 0) {
       if (iarg+5 > narg) error->all(FLERR,"Illegal tad command");
       etol = atof(arg[iarg+1]);
       ftol = atof(arg[iarg+2]);
       maxiter = atoi(arg[iarg+3]);
       maxeval = atoi(arg[iarg+4]);
       if (maxiter < 0 || maxeval < 0 ||
           etol < 0.0 || ftol < 0.0 )
         error->all(FLERR,"Illegal tad command");
       iarg += 5;
 
     } else if (strcmp(arg[iarg],"neb") == 0) {
       if (iarg+6 > narg) error->all(FLERR,"Illegal tad command");
       etol_neb = atof(arg[iarg+1]);
       ftol_neb = atof(arg[iarg+2]);
       n1steps_neb = atoi(arg[iarg+3]);
       n2steps_neb = atoi(arg[iarg+4]);
       nevery_neb = atoi(arg[iarg+5]);
       if (etol_neb < 0.0 || ftol_neb < 0.0 ||
           n1steps_neb < 0 || n2steps_neb < 0 ||
           nevery_neb < 0) error->all(FLERR,"Illegal tad command");
       iarg += 6;
 
     } else if (strcmp(arg[iarg],"min_style") == 0) {
       if (iarg+2 > narg) error->all(FLERR,"Illegal tad command");
       int n = strlen(arg[iarg+1]) + 1;
       delete [] min_style;
       min_style = new char[n];
       strcpy(min_style,arg[iarg+1]);
       iarg += 2;
 
     } else if (strcmp(arg[iarg],"neb_style") == 0) {
       if (iarg+2 > narg) error->all(FLERR,"Illegal tad command");
       int n = strlen(arg[iarg+1]) + 1;
       delete [] min_style_neb;
       min_style_neb = new char[n];
       strcpy(min_style_neb,arg[iarg+1]);
       iarg += 2;
 
     } else if (strcmp(arg[iarg],"neb_log") == 0) {
       delete [] neb_logfilename;
       if (iarg+2 > narg) error->all(FLERR,"Illegal tad command");
       if (strcmp(arg[iarg+1],"none") == 0) neb_logfilename = NULL;
       else {
         int n = strlen(arg[iarg+1]) + 1;
         neb_logfilename = new char[n];
         strcpy(neb_logfilename,arg[iarg+1]);
       }
       iarg += 2;
     } else error->all(FLERR,"Illegal tad command");
   }
 }
 
 /* ----------------------------------------------------------------------
    perform NEB calculation
 ------------------------------------------------------------------------- */
 
 void TAD::perform_neb(int ievent)
 {
 
   double **x = atom->x;
   int nlocal = atom->nlocal;
 
   double *buf_final;
   memory->create(buf_final,3*nlocal,"tad:buffinal");
 
   // set system to quenched state of event ievent
 
   if (universe->iworld == 0) {
 
     fix_event_list[ievent]->restore_event();
 
     int ii = 0;
     for (int i = 0; i < nlocal; i++) {
       buf_final[ii++] = x[i][0];
       buf_final[ii++] = x[i][1];
       buf_final[ii++] = x[i][2];
     }
   }
 
   MPI_Bcast(buf_final,3*nlocal,MPI_DOUBLE,universe->root_proc[0],
             universe->uworld);
 
   double *buf_init;
   memory->create(buf_init,3*nlocal,"tad:bufinit");
 
   // set system to quenched state of fix_event
 
   if (universe->iworld == 0) {
 
     fix_event->restore_event();
 
     int ii = 0;
     for (int i = 0; i < nlocal; i++) {
       buf_init[ii++] = x[i][0];
       buf_init[ii++] = x[i][1];
       buf_init[ii++] = x[i][2];
     }
   }
 
   MPI_Bcast(buf_init,3*nlocal,MPI_DOUBLE,universe->root_proc[0],
             universe->uworld);
 
   // create FixNEB object to support NEB
 
   int narg2 = 4;
   char **args = new char*[narg2];
   args[0] = (char *) "neb";
   args[1] = (char *) "all";
   args[2] = (char *) "neb";
   char str[128];
   args[3] = str;
   double kspring = 1.0;
   sprintf(args[3],"%f",kspring);
   modify->add_fix(narg2,args);
   fix_neb = (Fix *) modify->fix[modify->nfix-1];
   delete [] args;
 
   // switch minimize style to quickmin for NEB
 
   narg2 = 1;
   args = new char*[narg2];
   args[0] = min_style_neb;
 
   update->create_minimize(narg2,args);
 
   delete [] args;
 
   // create NEB object
 
   neb = new NEB(lmp,etol_neb,ftol_neb,n1steps_neb,
                 n2steps_neb,nevery_neb,buf_init,buf_final);
 
   // free up temporary arrays
 
   memory->destroy(buf_init);
   memory->destroy(buf_final);
 
   // run NEB
 
   int beginstep_hold = update->beginstep;
   int endstep_hold = update->endstep;
   int ntimestep_hold = update->ntimestep;
   int nsteps_hold = update->nsteps;
 
   if (universe->me == 0) {
     universe->ulogfile = ulogfile_neb;
     universe->uscreen = uscreen_neb;
   }
 
   // Had to bypass timer interface
   // because timer->array is reset
   // inside neb->run()
 
 //    timer->barrier_start(TIME_LOOP);
 //    neb->run();
 //    timer->barrier_stop(TIME_LOOP);
 //    time_neb += timer->array[TIME_LOOP];
 
   MPI_Barrier(world);
   double time_tmp = MPI_Wtime();
   neb->run();
   MPI_Barrier(world);
   time_neb += MPI_Wtime() - time_tmp;
 
   if (universe->me == 0) {
     universe->ulogfile = ulogfile_lammps;
     universe->uscreen = uscreen_lammps;
   }
 
   // extract barrier energy from NEB
 
   if (universe->iworld == 0)
     fix_event_list[ievent]->ebarrier = neb->ebf;
 
   update->beginstep = update->firststep = beginstep_hold;
   update->endstep = update->laststep = endstep_hold;
   update->ntimestep = ntimestep_hold;
   update->nsteps = nsteps_hold;
 
   // switch minimize style back for quench
 
   narg2 = 1;
   args = new char*[narg2];
   args[0] = min_style;
 
   update->create_minimize(narg2,args);
 
   update->etol = etol;
   update->ftol = ftol;
 
   delete [] args;
 
   // clean up
 
   modify->delete_fix("neb");
   delete neb;
 }
 
 /* ----------------------------------------------------------------------
    check if confidence criterion for tstop is satisfied
    return 0 if not satisfied
    return 1 if satisfied
 ------------------------------------------------------------------------- */
 
 int TAD::check_confidence()
 {
   int flag;
 
   // update stopping time
 
   deltstop = deltconf*pow(deltfirst/deltconf, ratio_beta);
 
   flag = 0;
   if (deltstop < update->ntimestep - fix_event->event_timestep) flag = 1;
 
   return flag;
 }
 
 /* ----------------------------------------------------------------------
    reflect back in to starting state
 ------------------------------------------------------------------------- */
 
 void TAD::revert()
 {
   double **x = atom->x;
   double **v = atom->v;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
 
   double **array_atom = fix_revert->array_atom;
 
   for (int i = 0; i < nlocal; i++) {
     x[i][0] = array_atom[i][0];
     x[i][1] = array_atom[i][1];
     x[i][2] = array_atom[i][2];
-    image[i] = 
+    image[i] =
       ((int(array_atom[i][5]) + (tagint) IMGMAX & IMGMASK) << IMG2BITS) |
       ((int(array_atom[i][4]) + (tagint) IMGMAX & IMGMASK) << IMGBITS) |
       (int(array_atom[i][3]) + IMGMAX & IMGMASK);
     v[i][0] = -array_atom[i][6];
     v[i][1] = -array_atom[i][7];
     v[i][2] = -array_atom[i][8];
   }
 }
 
 /* ----------------------------------------------------------------------
    Initialize list of possible events
 ------------------------------------------------------------------------- */
 
 void TAD::initialize_event_list() {
 
   // First delete old events, if any
 
   delete_event_list();
 
   // Create new list
 
   n_event_list = 0;
   grow_event_list(nmin_event_list);
 }
 
 /* ----------------------------------------------------------------------
    Delete list of possible events
 ------------------------------------------------------------------------- */
 
 void TAD::delete_event_list() {
 
   for (int i = 0; i < n_event_list; i++) {
     char str[128];
     sprintf(str,"tad_event_%d",i);
     modify->delete_fix(str);
   }
   memory->sfree(fix_event_list);
   fix_event_list = NULL;
   n_event_list = 0;
   nmax_event_list = 0;
 
 }
 
 /* ----------------------------------------------------------------------
    add event
 ------------------------------------------------------------------------- */
 
 void TAD::add_event()
 {
 
   // create FixEventTAD object to store possible event
 
   int narg = 3;
   char **args = new char*[narg];
 
   char str[128];
   sprintf(str,"tad_event_%d",n_event_list);
 
   args[0] = str;
   args[1] = (char *) "all";
   args[2] = (char *) "EVENT/TAD";
   modify->add_fix(narg,args);
 
   if (n_event_list == nmax_event_list)
     grow_event_list(nmax_event_list+nmin_event_list);
   n_event_list += 1;
   int ievent = n_event_list-1;
   fix_event_list[ievent] = (FixEventTAD *) modify->fix[modify->nfix-1];
 
   // store quenched state for new event
 
   fix_event_list[ievent]->store_event_tad(update->ntimestep);
 
   // store hot state for new event
 
   fix_event->restore_state();
   fix_event_list[ievent]->store_state();
 
   // string clean-up
 
   delete [] args;
 
 }
 
 /* ----------------------------------------------------------------------
    compute cold time for event ievent
 ------------------------------------------------------------------------- */
 
 void TAD::compute_tlo(int ievent)
 {
   double deltlo,delthi,ebarrier;
 
   ebarrier = fix_event_list[ievent]->ebarrier;
   delthi = fix_event_list[ievent]->event_timestep
     - fix_event->event_timestep;
   deltlo = delthi*exp(ebarrier*delta_beta);
   fix_event_list[ievent]->tlo = fix_event->tlo + deltlo;
 
   // update first event
 
   char* statstr = (char *) "D ";
 
   if (ievent == 0) {
     deltfirst = deltlo;
     event_first = ievent;
     statstr = (char *) "DF";
   } else if (deltlo < deltfirst) {
     deltfirst = deltlo;
     event_first = ievent;
     statstr = (char *) "DF";
   }
 
   // first-replica output about each event
 
   timer->array[TIME_LOOP] = time_start;
   if (universe->me == 0) {
     double tfrac = 0.0;
     if (ievent > 0) tfrac = delthi/deltstop;
 
     if (universe->uscreen)
       fprintf(universe->uscreen,
               BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n",
               fix_event_list[ievent]->event_timestep,
               timer->elapsed(TIME_LOOP),
               fix_event->event_number,
               ievent,statstr,ebarrier,tfrac,
               fix_event->tlo,deltlo);
 
     if (universe->ulogfile)
       fprintf(universe->ulogfile,
               BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n",
               fix_event_list[ievent]->event_timestep,
               timer->elapsed(TIME_LOOP),
               fix_event->event_number,
               ievent,statstr,ebarrier,tfrac,
               fix_event->tlo,deltlo);
   }
 
 }
 
 /* ----------------------------------------------------------------------
    perform event
 ------------------------------------------------------------------------- */
 
 void TAD::perform_event(int ievent)
 {
   // reset timestep to that of event
 
   update->ntimestep = fix_event_list[ievent]->event_timestep;
 
   // Copy event to current event
   // Should really use copy constructor for this
   fix_event->tlo = fix_event_list[ievent]->tlo;
   fix_event->ebarrier = fix_event_list[ievent]->ebarrier;
   fix_event->event_number++;
   fix_event->event_timestep = update->ntimestep;
   fix_event_list[ievent]->restore_event();
   fix_event->store_event_tad(fix_event_list[ievent]->event_timestep);
 
   // output stats and dump for quenched state
 
   log_event(ievent);
 
   // load and store hot state
 
   fix_event_list[ievent]->restore_state();
   fix_event->store_state();
 }
 
 /* ----------------------------------------------------------------------
    Allocate list of pointers to events
 ------------------------------------------------------------------------- */
 
 void TAD::grow_event_list(int nmax) {
   if (nmax_event_list > nmax) return;
   fix_event_list = (FixEventTAD **)
     memory->srealloc(fix_event_list,nmax*sizeof(FixEventTAD *),"tad:eventlist");
   nmax_event_list = nmax;
 }
diff --git a/src/USER-AWPMD/atom_vec_wavepacket.cpp b/src/USER-AWPMD/atom_vec_wavepacket.cpp
index 538245d07..e36741e59 100644
--- a/src/USER-AWPMD/atom_vec_wavepacket.cpp
+++ b/src/USER-AWPMD/atom_vec_wavepacket.cpp
@@ -1,1014 +1,1014 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Ilya Valuev (JIHT, Moscow, Russia)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "atom_vec_wavepacket.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "force.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecWavepacket::AtomVecWavepacket(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   comm_x_only = comm_f_only = 0;
 
   mass_type = 1;
   molecular = 0;
 
   size_forward = 4; // coords[3]+radius[1]
   size_reverse = 10; // force[3]+erforce[1]+ervelforce[1]+vforce[3]+csforce[2]
   size_border = 10; // coords[3]+tag[1]+type[1]+mask[1]+q[1]+spin[1]+eradius[1]+etag[1]
   size_velocity = 6; // +velocities[3]+ ervel[1]+cs[2]
   size_data_atom = 11; // for input file: 1-tag 2-type 3-q 4-spin 5-eradius 6-etag 7-cs_re 8-cs_im 9-x 10-y 11-z
   size_data_vel = 5; // for input file: vx vy vz ervel <??>
   xcol_data = 9; // starting column for x data
 
   atom->wavepacket_flag = 1;
   atom->electron_flag = 1; // compatible with eff
   atom->q_flag = atom->spin_flag = atom->eradius_flag =
     atom->ervel_flag = atom->erforce_flag = 1;
 
   atom->cs_flag = atom->csforce_flag = atom->vforce_flag = atom->ervelforce_flag = atom->etag_flag = 1;
 
 
 }
 
 /* ----------------------------------------------------------------------
    grow atom-electron arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   q = memory->grow(atom->q,nmax,"atom:q");
   spin = memory->grow(atom->spin,nmax,"atom:spin");
   eradius = memory->grow(atom->eradius,nmax,"atom:eradius");
   ervel = memory->grow(atom->ervel,nmax,"atom:ervel");
   erforce = memory->grow(atom->erforce,nmax*comm->nthreads,"atom:erforce");
 
   cs = memory->grow(atom->cs,2*nmax,"atom:cs");
   csforce = memory->grow(atom->csforce,2*nmax,"atom:csforce");
   vforce = memory->grow(atom->vforce,3*nmax,"atom:vforce");
   ervelforce = memory->grow(atom->ervelforce,nmax,"atom:ervelforce");
   etag = memory->grow(atom->etag,nmax,"atom:etag");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   q = atom->q;
   eradius = atom->eradius; ervel = atom->ervel; erforce = atom->erforce;
 
   cs = atom->cs;
   csforce = atom->csforce;
   vforce = atom->vforce;
   ervelforce = atom->ervelforce;
   etag = atom->etag;
 
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::copy(int i, int j, int delflag)
 {
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   q[j] = q[i];
   spin[j] = spin[i];
   eradius[j] = eradius[i];
   ervel[j] = ervel[i];
 
   cs[2*j] = cs[2*i];
   cs[2*j+1] = cs[2*i+1];
   etag[j] = etag[i];
 
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 // this will be used as partial pack for unsplit Hartree packets (v, ervel not regarded as separate variables)
 
 int AtomVecWavepacket::pack_comm(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = eradius[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = eradius[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 // this is a complete pack of all 'position' variables of AWPMD
 
 int AtomVecWavepacket::pack_comm_vel(int n, int *list, double *buf,
                                    int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = eradius[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
 
       buf[m++] = ervel[j];
       buf[m++] = cs[2*j];
       buf[m++] = cs[2*j+1];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = eradius[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
 
         buf[m++] = ervel[j];
         buf[m++] = cs[2*j];
         buf[m++] = cs[2*j+1];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = eradius[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
         buf[m++] = ervel[j];
         buf[m++] = cs[2*j];
         buf[m++] = cs[2*j+1];
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_comm_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = eradius[j];
     buf[m++] = ervel[j];
     buf[m++] = cs[2*j];
     buf[m++] = cs[2*j+1];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecWavepacket::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     eradius[i] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecWavepacket::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     eradius[i] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
 
     ervel[i] = buf[m++];
     cs[2*i] =  buf[m++];
     cs[2*i+1] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::unpack_comm_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++){
     eradius[i] = buf[m++];
     ervel[i] = buf[m++];
     cs[2*i] =  buf[m++];
     cs[2*i+1] = buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) { //10
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
     buf[m++] = erforce[i];
 
     buf[m++] = ervelforce[i];
     buf[m++] = vforce[3*i];
     buf[m++] = vforce[3*i+1];
     buf[m++] = vforce[3*i+2];
     buf[m++] = csforce[2*i];
     buf[m++] = csforce[2*i+1];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_reverse_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++){
     buf[m++] = erforce[i];
 
     buf[m++] = ervelforce[i];
     buf[m++] = vforce[3*i];
     buf[m++] = vforce[3*i+1];
     buf[m++] = vforce[3*i+2];
     buf[m++] = csforce[2*i];
     buf[m++] = csforce[2*i+1];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecWavepacket::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
     erforce[j] += buf[m++];
 
     ervelforce[j] += buf[m++];
     vforce[3*j] += buf[m++];
     vforce[3*j+1] += buf[m++];
     vforce[3*j+2] += buf[m++];
     csforce[2*j] += buf[m++];
     csforce[2*j+1] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::unpack_reverse_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     erforce[j] += buf[m++];
 
     ervelforce[j] += buf[m++];
     vforce[3*j] += buf[m++];
     vforce[3*j+1] += buf[m++];
     vforce[3*j+2] += buf[m++];
     csforce[2*j] += buf[m++];
     csforce[2*j+1] += buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 // will be used for Hartree unsplit version (the etag is added however)
 int AtomVecWavepacket::pack_border(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
       buf[m++] = etag[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
       buf[m++] = etag[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_border_vel(int n, int *list, double *buf,
                                      int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
       buf[m++] = etag[j];
 
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
 
 
       buf[m++] = ervel[j];
       buf[m++] = cs[2*j];
       buf[m++] = cs[2*j+1];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (domain->triclinic == 0) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = spin[j];
         buf[m++] = eradius[j];
         buf[m++] = etag[j];
 
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
 
 
         buf[m++] = ervel[j];
         buf[m++] = cs[2*j];
         buf[m++] = cs[2*j+1];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = spin[j];
         buf[m++] = eradius[j];
         buf[m++] = etag[j];
 
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
 
         buf[m++] = ervel[j];
         buf[m++] = cs[2*j];
         buf[m++] = cs[2*j+1];
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = q[j];
     buf[m++] = spin[j];
     buf[m++] = eradius[j];
 
     buf[m++] = etag[j];
     buf[m++] = ervel[j];
     buf[m++] = cs[2*j];
     buf[m++] = cs[2*j+1];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecWavepacket::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
     etag[i] = (int)buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecWavepacket::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
     etag[i] = (int)buf[m++];
 
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
 
 
     ervel[i] = buf[m++];
     cs[2*i] = buf[m++];
     cs[2*i+1] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
 
     etag[i] = (int)buf[m++];
     ervel[i] = buf[m++];
     cs[2*i] = buf[m++];
     cs[2*i+1] = buf[m++];
   }
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_exchange(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
 
   buf[m++] = q[i];
   buf[m++] = spin[i];
   buf[m++] = eradius[i];
   buf[m++] = ervel[i];
 
   buf[m++] = etag[i];
   buf[m++] = cs[2*i];
   buf[m++] = cs[2*i+1];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecWavepacket::unpack_exchange(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
 
   q[nlocal] = buf[m++];
   spin[nlocal] = static_cast<int> (buf[m++]);
   eradius[nlocal] = buf[m++];
   ervel[nlocal] = buf[m++];
 
   etag[nlocal] = buf[m++];
   cs[2*nlocal] = buf[m++];
   cs[2*nlocal+1] = buf[m++];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 18 * nlocal;        // Associated with pack_restart
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::pack_restart(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = q[i];
   buf[m++] = spin[i];
   buf[m++] = eradius[i];
   buf[m++] = ervel[i];
 
   buf[m++] = etag[i];
   buf[m++] = cs[2*i];
   buf[m++] = cs[2*i+1];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::unpack_restart(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   q[nlocal] = buf[m++];
   spin[nlocal] = static_cast<int> (buf[m++]);
   eradius[nlocal] = buf[m++];
   ervel[nlocal] = buf[m++];
 
   etag[nlocal] = buf[m++];
   cs[2*nlocal] = buf[m++];
   cs[2*nlocal+1] = buf[m++];
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
    AWPMD: creates a proton
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   q[nlocal] = 1.;
   spin[nlocal] = 0.;
   eradius[nlocal] = 0.0;
   ervel[nlocal] = 0.0;
 
   etag[nlocal]= 0.;
   cs[2*nlocal] = 0.;
   cs[2*nlocal+1] = 0.;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
    AWPMD: 0-tag 1-type 2-q 3-spin 4-eradius 5-etag 6-cs_re 7-cs_im
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
 
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of "
                "data file (ID tag must be >0)");
 
   type[nlocal] = atoi(values[1]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   q[nlocal] = atof(values[2]);
   spin[nlocal] = atoi(values[3]);
   eradius[nlocal] = atof(values[4]);
   if (eradius[nlocal] < 0.0)
     error->one(FLERR,"Invalid eradius in Atoms section of data file");
 
 
   etag[nlocal] = atoi(values[5]);
   cs[2*nlocal] = atoi(values[6]);
   cs[2*nlocal+1] = atof(values[7]);
 
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   ervel[nlocal] = 0.0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::data_atom_hybrid(int nlocal, char **values)
 {
   q[nlocal] = atof(values[0]);
   spin[nlocal] = atoi(values[1]);
   eradius[nlocal] = atof(values[2]);
   if (eradius[nlocal] < 0.0)
     error->one(FLERR,"Invalid eradius in Atoms section of data file");
 
   etag[nlocal] = atoi(values[3]);
   cs[2*nlocal] = atoi(values[4]);
   cs[2*nlocal+1] = atof(values[5]);
 
 
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   ervel[nlocal] = 0.0;
 
   return 3;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Velocities section of data file
 ------------------------------------------------------------------------- */
 
 void AtomVecWavepacket::data_vel(int m, char **values)
 {
   v[m][0] = atof(values[0]);
   v[m][1] = atof(values[1]);
   v[m][2] = atof(values[2]);
   ervel[m] = atof(values[3]);
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Velocities section of data file
 ------------------------------------------------------------------------- */
 
 int AtomVecWavepacket::data_vel_hybrid(int m, char **values)
 {
   ervel[m] = atof(values[0]);
   return 1;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecWavepacket::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("q")) bytes += memory->usage(q,nmax);
   if (atom->memcheck("spin")) bytes += memory->usage(spin,nmax);
   if (atom->memcheck("eradius")) bytes += memory->usage(eradius,nmax);
   if (atom->memcheck("ervel")) bytes += memory->usage(ervel,nmax);
-  if (atom->memcheck("erforce")) 
+  if (atom->memcheck("erforce"))
     bytes += memory->usage(erforce,nmax*comm->nthreads);
 
   if (atom->memcheck("ervelforce")) bytes += memory->usage(ervelforce,nmax);
   if (atom->memcheck("cs")) bytes += memory->usage(cs,2*nmax);
   if (atom->memcheck("csforce")) bytes += memory->usage(csforce,2*nmax);
   if (atom->memcheck("vforce")) bytes += memory->usage(vforce,3*nmax);
   if (atom->memcheck("etag")) bytes += memory->usage(etag,nmax);
 
   return bytes;
 }
diff --git a/src/USER-EFF/atom_vec_electron.cpp b/src/USER-EFF/atom_vec_electron.cpp
index ff1c47274..e1e3bc410 100644
--- a/src/USER-EFF/atom_vec_electron.cpp
+++ b/src/USER-EFF/atom_vec_electron.cpp
@@ -1,852 +1,852 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Andres Jaramillo-Botero (Caltech)
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "atom_vec_electron.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "force.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecElectron::AtomVecElectron(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg)
 {
   comm_x_only = comm_f_only = 0;
 
   mass_type = 1;
   molecular = 0;
 
   size_forward = 4;
   size_reverse = 4;
   size_border = 9;
   size_velocity = 3;
   size_data_atom = 8;
   size_data_vel = 5;
   xcol_data = 6;
 
   atom->electron_flag = 1;
   atom->q_flag = atom->spin_flag = atom->eradius_flag =
     atom->ervel_flag = atom->erforce_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom-electron arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::grow(int n)
 {
   if (n == 0) nmax += DELTA;
   else nmax = n;
   atom->nmax = nmax;
 
   tag = memory->grow(atom->tag,nmax,"atom:tag");
   type = memory->grow(atom->type,nmax,"atom:type");
   mask = memory->grow(atom->mask,nmax,"atom:mask");
   image = memory->grow(atom->image,nmax,"atom:image");
   x = memory->grow(atom->x,nmax,3,"atom:x");
   v = memory->grow(atom->v,nmax,3,"atom:v");
   f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f");
 
   q = memory->grow(atom->q,nmax,"atom:q");
   spin = memory->grow(atom->spin,nmax,"atom:spin");
   eradius = memory->grow(atom->eradius,nmax,"atom:eradius");
   ervel = memory->grow(atom->ervel,nmax,"atom:ervel");
   erforce = memory->grow(atom->erforce,nmax*comm->nthreads,"atom:erforce");
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::grow_reset()
 {
   tag = atom->tag; type = atom->type;
   mask = atom->mask; image = atom->image;
   x = atom->x; v = atom->v; f = atom->f;
   q = atom->q;
   eradius = atom->eradius; ervel = atom->ervel; erforce = atom->erforce;
 }
 
 /* ----------------------------------------------------------------------
    copy atom I info to atom J
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::copy(int i, int j, int delflag)
 {
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
 
   q[j] = q[i];
   spin[j] = spin[i];
   eradius[j] = eradius[i];
   ervel[j] = ervel[i];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_comm(int n, int *list, double *buf,
                                int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = eradius[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = eradius[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_comm_vel(int n, int *list, double *buf,
                                    int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = eradius[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz;
       dy = pbc[1]*domain->yprd + pbc[3]*domain->yz;
       dz = pbc[2]*domain->zprd;
     }
     if (!deform_vremap) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = eradius[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = eradius[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_comm_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = eradius[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecElectron::unpack_comm(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     eradius[i] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecElectron::unpack_comm_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     eradius[i] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::unpack_comm_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     eradius[i] = buf[m++];
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_reverse(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
     buf[m++] = erforce[i];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_reverse_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++)
     buf[m++] = erforce[i];
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecElectron::unpack_reverse(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
     erforce[j] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::unpack_reverse_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     erforce[j] += buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_border(int n, int *list, double *buf,
                                  int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_border_vel(int n, int *list, double *buf,
                                      int pbc_flag, int *pbc)
 {
   int i,j,m;
   double dx,dy,dz,dvx,dvy,dvz;
 
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = q[j];
       buf[m++] = spin[j];
       buf[m++] = eradius[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0]*domain->xprd;
       dy = pbc[1]*domain->yprd;
       dz = pbc[2]*domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     if (domain->triclinic == 0) {
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = spin[j];
         buf[m++] = eradius[j];
         buf[m++] = v[j][0];
         buf[m++] = v[j][1];
         buf[m++] = v[j][2];
       }
     } else {
       dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4];
       dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3];
       dvz = pbc[2]*h_rate[2];
       for (i = 0; i < n; i++) {
         j = list[i];
         buf[m++] = x[j][0] + dx;
         buf[m++] = x[j][1] + dy;
         buf[m++] = x[j][2] + dz;
         buf[m++] = tag[j];
         buf[m++] = type[j];
         buf[m++] = mask[j];
         buf[m++] = q[j];
         buf[m++] = spin[j];
         buf[m++] = eradius[j];
         if (mask[i] & deform_groupbit) {
           buf[m++] = v[j][0] + dvx;
           buf[m++] = v[j][1] + dvy;
           buf[m++] = v[j][2] + dvz;
         } else {
           buf[m++] = v[j][0];
           buf[m++] = v[j][1];
           buf[m++] = v[j][2];
         }
       }
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_border_hybrid(int n, int *list, double *buf)
 {
   int i,j,m;
 
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = q[j];
     buf[m++] = spin[j];
     buf[m++] = eradius[j];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecElectron::unpack_border(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecElectron::unpack_border_vel(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax) grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::unpack_border_hybrid(int n, int first, double *buf)
 {
   int i,m,last;
 
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     q[i] = buf[m++];
     spin[i] = static_cast<int> (buf[m++]);
     eradius[i] = buf[m++];
   }
   return m;
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_exchange(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = q[i];
   buf[m++] = spin[i];
   buf[m++] = eradius[i];
   buf[m++] = ervel[i];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecElectron::unpack_exchange(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   q[nlocal] = buf[m++];
   spin[nlocal] = static_cast<int> (buf[m++]);
   eradius[nlocal] = buf[m++];
   ervel[nlocal] = buf[m++];
 
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->
         unpack_exchange(nlocal,&buf[m]);
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::size_restart()
 {
   int i;
 
   int nlocal = atom->nlocal;
   int n = 15 * nlocal;        // Associated with pack_restart
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
 
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::pack_restart(int i, double *buf)
 {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
 
   buf[m++] = q[i];
   buf[m++] = spin[i];
   buf[m++] = eradius[i];
   buf[m++] = ervel[i];
 
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]);
 
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::unpack_restart(double *buf)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra");
   }
 
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
 
   q[nlocal] = buf[m++];
   spin[nlocal] = static_cast<int> (buf[m++]);
   eradius[nlocal] = buf[m++];
   ervel[nlocal] = buf[m++];
 
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++];
   }
 
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::create_atom(int itype, double *coord)
 {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
 
   q[nlocal] = 0.0;
   spin[nlocal] = 1;
   eradius[nlocal] = 1.0;
   ervel[nlocal] = 0.0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::data_atom(double *coord, tagint imagetmp, char **values)
 {
   int nlocal = atom->nlocal;
 
   if (nlocal == nmax) grow(0);
 
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
 
   type[nlocal] = atoi(values[1]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
 
   q[nlocal] = atof(values[2]);
   spin[nlocal] = atoi(values[3]);
   eradius[nlocal] = atof(values[4]);
 
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
 
   image[nlocal] = imagetmp;
 
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   ervel[nlocal] = 0.0;
 
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::data_atom_hybrid(int nlocal, char **values)
 {
   q[nlocal] = atof(values[0]);
   spin[nlocal] = atoi(values[1]);
   eradius[nlocal] = atof(values[2]);
   if (eradius[nlocal] < 0.0)
     error->one(FLERR,"Invalid eradius in Atoms section of data file");
 
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   ervel[nlocal] = 0.0;
 
   return 3;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Velocities section of data file
 ------------------------------------------------------------------------- */
 
 void AtomVecElectron::data_vel(int m, char **values)
 {
   v[m][0] = atof(values[0]);
   v[m][1] = atof(values[1]);
   v[m][2] = atof(values[2]);
   ervel[m] = atof(values[3]);
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Velocities section of data file
 ------------------------------------------------------------------------- */
 
 int AtomVecElectron::data_vel_hybrid(int m, char **values)
 {
   ervel[m] = atof(values[0]);
   return 1;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
 ------------------------------------------------------------------------- */
 
 bigint AtomVecElectron::memory_usage()
 {
   bigint bytes = 0;
 
   if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax);
   if (atom->memcheck("type")) bytes += memory->usage(type,nmax);
   if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax);
   if (atom->memcheck("image")) bytes += memory->usage(image,nmax);
   if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3);
   if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3);
   if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3);
 
   if (atom->memcheck("q")) bytes += memory->usage(q,nmax);
   if (atom->memcheck("spin")) bytes += memory->usage(spin,nmax);
   if (atom->memcheck("eradius")) bytes += memory->usage(eradius,nmax);
   if (atom->memcheck("ervel")) bytes += memory->usage(ervel,nmax);
   if (atom->memcheck("erforce")) bytes += memory->usage(erforce,nmax*comm->nthreads);
 
   return bytes;
 }
diff --git a/src/USER-MISC/bond_harmonic_shift.cpp b/src/USER-MISC/bond_harmonic_shift.cpp
index 21b0ff40a..3c2a06083 100644
--- a/src/USER-MISC/bond_harmonic_shift.cpp
+++ b/src/USER-MISC/bond_harmonic_shift.cpp
@@ -1,199 +1,199 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Carsten Svaneborg, science@zqex.dk
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "bond_harmonic_shift.h"
 #include "atom.h"
 #include "neighbor.h"
 #include "domain.h"
 #include "comm.h"
 #include "force.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShift::BondHarmonicShift(LAMMPS *lmp) : Bond(lmp) {}
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShift::~BondHarmonicShift()
 {
   if (allocated) {
     memory->destroy(setflag);
     memory->destroy(k);
     memory->destroy(r0);
     memory->destroy(r1);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShift::compute(int eflag, int vflag)
 {
   int i1,i2,n,type;
   double delx,dely,delz,ebond,fbond;
   double rsq,r,dr,rk;
 
   ebond = 0.0;
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = 0;
 
   double **x = atom->x;
   double **f = atom->f;
   int **bondlist = neighbor->bondlist;
   int nbondlist = neighbor->nbondlist;
   int nlocal = atom->nlocal;
   int newton_bond = force->newton_bond;
 
   for (n = 0; n < nbondlist; n++) {
     i1 = bondlist[n][0];
     i2 = bondlist[n][1];
     type = bondlist[n][2];
 
     delx = x[i1][0] - x[i2][0];
     dely = x[i1][1] - x[i2][1];
     delz = x[i1][2] - x[i2][2];
 
     rsq = delx*delx + dely*dely + delz*delz;
     r = sqrt(rsq);
 
     dr = r - r0[type];
     rk = k[type] * dr;
 
     // force & energy
 
     if (r > 0.0) fbond = -2.0*rk/r;
     else fbond = 0.0;
 
-    if (eflag) 
+    if (eflag)
       ebond = k[type]*(dr*dr -(r0[type]-r1[type])*(r0[type]-r1[type]) );
 
     // apply force to each of 2 atoms
 
     if (newton_bond || i1 < nlocal) {
       f[i1][0] += delx*fbond;
       f[i1][1] += dely*fbond;
       f[i1][2] += delz*fbond;
     }
 
     if (newton_bond || i2 < nlocal) {
       f[i2][0] -= delx*fbond;
       f[i2][1] -= dely*fbond;
       f[i2][2] -= delz*fbond;
     }
 
     if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShift::allocate()
 {
   allocated = 1;
   int n = atom->nbondtypes;
 
   memory->create(k ,    n+1,"bond:k");
   memory->create(r0,    n+1,"bond:r0");
   memory->create(r1,    n+1,"bond:r1");
   memory->create(setflag,n+1,"bond:setflag");
 
   for (int i = 1; i <= n; i++) setflag[i] = 0;
 }
 
 /* ----------------------------------------------------------------------
    set coeffs for one or more types
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShift::coeff(int narg, char **arg)
 {
   if (narg != 4) error->all(FLERR,"Incorrect args for bond coefficients");
   if (!allocated) allocate();
 
   int ilo,ihi;
   force->bounds(arg[0],atom->nbondtypes,ilo,ihi);
 
   double Umin = force->numeric(arg[1]);   // energy at minimum
   double r0_one = force->numeric(arg[2]); // position of minimum
   double r1_one = force->numeric(arg[3]);  // position where energy = 0
 
   int count = 0;
   for (int i = ilo; i <= ihi; i++) {
     k[i] = Umin/((r0_one-r1_one)*(r0_one-r1_one));
     r0[i] = r0_one;
     r1[i] = r1_one;
     setflag[i] = 1;
     count++;
   }
 
   if (count == 0) error->all(FLERR,"Incorrect args for bond coefficients");
 }
 
 /* ----------------------------------------------------------------------
    return an equilbrium bond length
 ------------------------------------------------------------------------- */
 
 double BondHarmonicShift::equilibrium_distance(int i)
 {
   return r0[i];
 }
 
 /* ----------------------------------------------------------------------
    proc 0 writes out coeffs to restart file
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShift::write_restart(FILE *fp)
 {
   fwrite(&k[1],sizeof(double),atom->nbondtypes,fp);
   fwrite(&r0[1],sizeof(double),atom->nbondtypes,fp);
   fwrite(&r1[1],sizeof(double),atom->nbondtypes,fp);
 }
 
 /* ----------------------------------------------------------------------
    proc 0 reads coeffs from restart file, bcasts them
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShift::read_restart(FILE *fp)
 {
   allocate();
 
   if (comm->me == 0) {
     fread(&k[1],sizeof(double),atom->nbondtypes,fp);
     fread(&r0[1],sizeof(double),atom->nbondtypes,fp);
     fread(&r1[1],sizeof(double),atom->nbondtypes,fp);
   }
   MPI_Bcast(&k[1],atom->nbondtypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&r0[1],atom->nbondtypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&r1[1],atom->nbondtypes,MPI_DOUBLE,0,world);
 
   for (int i = 1; i <= atom->nbondtypes; i++) setflag[i] = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double BondHarmonicShift::single(int type, double rsq, int i, int j)
 {
   double r = sqrt(rsq);
   double dr = r - r0[type];
   double dr2=r0[type]-r1[type];
 
   return k[type]*(dr*dr - dr2*dr2);
 }
diff --git a/src/USER-MISC/bond_harmonic_shift_cut.cpp b/src/USER-MISC/bond_harmonic_shift_cut.cpp
index d867b5e0c..bcaac0990 100644
--- a/src/USER-MISC/bond_harmonic_shift_cut.cpp
+++ b/src/USER-MISC/bond_harmonic_shift_cut.cpp
@@ -1,202 +1,202 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Carsten Svaneborg, science@zqex.dk
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdlib.h"
 #include "bond_harmonic_shift_cut.h"
 #include "atom.h"
 #include "neighbor.h"
 #include "domain.h"
 #include "comm.h"
 #include "force.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShiftCut::BondHarmonicShiftCut(LAMMPS *lmp) : Bond(lmp) {}
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShiftCut::~BondHarmonicShiftCut()
 {
   if (allocated) {
     memory->destroy(setflag);
     memory->destroy(k);
     memory->destroy(r0);
     memory->destroy(r1);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShiftCut::compute(int eflag, int vflag)
 {
   int i1,i2,n,type;
   double delx,dely,delz,ebond,fbond;
   double rsq,r,dr,rk;
 
   ebond = 0.0;
   if (eflag || vflag) ev_setup(eflag,vflag);
   else evflag = 0;
 
   double **x = atom->x;
   double **f = atom->f;
   int **bondlist = neighbor->bondlist;
   int nbondlist = neighbor->nbondlist;
   int nlocal = atom->nlocal;
   int newton_bond = force->newton_bond;
 
   for (n = 0; n < nbondlist; n++) {
     i1 = bondlist[n][0];
     i2 = bondlist[n][1];
     type = bondlist[n][2];
 
     delx = x[i1][0] - x[i2][0];
     dely = x[i1][1] - x[i2][1];
     delz = x[i1][2] - x[i2][2];
 
     rsq = delx*delx + dely*dely + delz*delz;
     r = sqrt(rsq);
 
     if (r>r1[type]) continue;
 
     dr = r - r0[type];
     rk = k[type] * dr;
 
     // force & energy
 
     if (r > 0.0) fbond = -2.0*rk/r;
     else fbond = 0.0;
 
-    if (eflag) 
+    if (eflag)
       ebond = k[type]*(dr*dr -(r0[type]-r1[type])*(r0[type]-r1[type]));
 
     // apply force to each of 2 atoms
 
     if (newton_bond || i1 < nlocal) {
       f[i1][0] += delx*fbond;
       f[i1][1] += dely*fbond;
       f[i1][2] += delz*fbond;
     }
 
     if (newton_bond || i2 < nlocal) {
       f[i2][0] -= delx*fbond;
       f[i2][1] -= dely*fbond;
       f[i2][2] -= delz*fbond;
     }
 
     if (evflag) ev_tally(i1,i2,nlocal,newton_bond,ebond,fbond,delx,dely,delz);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShiftCut::allocate()
 {
   allocated = 1;
   int n = atom->nbondtypes;
 
   memory->create(k ,    n+1,"bond:k");
   memory->create(r0,    n+1,"bond:r0");
   memory->create(r1,    n+1,"bond:r1");
   memory->create(setflag,n+1,"bond:setflag");
   for (int i = 1; i <= n; i++) setflag[i] = 0;
 }
 
 /* ----------------------------------------------------------------------
    set coeffs for one or more types
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShiftCut::coeff(int narg, char **arg)
 {
   if (narg != 4) error->all(FLERR,"Incorrect args for bond coefficients");
   if (!allocated) allocate();
 
   int ilo,ihi;
   force->bounds(arg[0],atom->nbondtypes,ilo,ihi);
 
   double Umin = force->numeric(arg[1]);   // energy at minimum
   double r0_one = force->numeric(arg[2]); // position of minimum
   double r1_one = force->numeric(arg[3]);  // position where energy = 0 = cutoff
 
   int count = 0;
   for (int i = ilo; i <= ihi; i++) {
     k[i] = Umin/((r0_one-r1_one)*(r0_one-r1_one));
     r0[i] = r0_one;
     r1[i] = r1_one;
     setflag[i] = 1;
     count++;
   }
 
   if (count == 0) error->all(FLERR,"Incorrect args for bond coefficients");
 }
 
 /* ----------------------------------------------------------------------
    return an equilbrium bond length
 ------------------------------------------------------------------------- */
 
 double BondHarmonicShiftCut::equilibrium_distance(int i)
 {
   return r0[i];
 }
 
 /* ----------------------------------------------------------------------
    proc 0 writes out coeffs to restart file
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShiftCut::write_restart(FILE *fp)
 {
   fwrite(&k[1],sizeof(double),atom->nbondtypes,fp);
   fwrite(&r0[1],sizeof(double),atom->nbondtypes,fp);
   fwrite(&r1[1],sizeof(double),atom->nbondtypes,fp);
 }
 
 /* ----------------------------------------------------------------------
    proc 0 reads coeffs from restart file, bcasts them
 ------------------------------------------------------------------------- */
 
 void BondHarmonicShiftCut::read_restart(FILE *fp)
 {
   allocate();
 
   if (comm->me == 0) {
     fread(&k[1],sizeof(double),atom->nbondtypes,fp);
     fread(&r0[1],sizeof(double),atom->nbondtypes,fp);
     fread(&r1[1],sizeof(double),atom->nbondtypes,fp);
   }
   MPI_Bcast(&k[1],atom->nbondtypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&r0[1],atom->nbondtypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&r1[1],atom->nbondtypes,MPI_DOUBLE,0,world);
 
   for (int i = 1; i <= atom->nbondtypes; i++) setflag[i] = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double BondHarmonicShiftCut::single(int type, double rsq, int i, int j)
 {
   double r = sqrt(rsq);
 
   if (r>r1[type]) return 0;
 
   double dr = r - r0[type];
   double dr2=r0[type]-r1[type];
   return k[type]*(dr*dr - dr2*dr2);
 }
diff --git a/src/USER-MOLFILE/dump_molfile.cpp b/src/USER-MOLFILE/dump_molfile.cpp
index 1d0188430..90d15f677 100644
--- a/src/USER-MOLFILE/dump_molfile.cpp
+++ b/src/USER-MOLFILE/dump_molfile.cpp
@@ -1,461 +1,461 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include "dump_molfile.h"
 #include "domain.h"
 #include "atom.h"
 #include "comm.h"
 #include "update.h"
 #include "output.h"
 #include "group.h"
 #include "memory.h"
 #include "error.h"
 
 #include "molfile_interface.h"
 
 using namespace LAMMPS_NS;
 typedef MolfileInterface MFI;
 
 // syntax:
 // dump <id> <groupid> molfile <every> <filename> <type> [<path>]
 // path defaults to "." -> will look for .so files in CWD.
 //
 // XXX: potential change: add more options and make them optional
 // path <path>
 // template <file> <type> (import name and topology information from file)
 // bonds <yes|no>         (write out bond information)
-// topology <yes|no>      (write out all topology information) 
+// topology <yes|no>      (write out all topology information)
 
 /* ---------------------------------------------------------------------- */
 
-DumpMolfile::DumpMolfile(LAMMPS *lmp, int narg, char **arg) 
+DumpMolfile::DumpMolfile(LAMMPS *lmp, int narg, char **arg)
   : Dump(lmp, narg, arg)
 {
   if (narg < 6) error->all(FLERR,"Illegal dump molfile command");
 
   if (binary || compressed || multiproc)
     error->all(FLERR,"Invalid dump molfile filename");
 
   // required settings
 
   sort_flag = 1;
   sortcol = 0;
 
   // storage for collected information
 
   size_one = 4;
   if (atom->molecule_flag)  ++size_one;
   if (atom->q_flag)         ++size_one;
   if (atom->rmass_flag)     ++size_one;
   if (atom->radius_flag)    ++size_one;
 
   need_structure = 0;
   unwrap_flag = 0;
   velocity_flag = 0;
   topology_flag = 0;
   ntotal = 0;
   me = comm->me;
 
   coords = vels = masses = charges = radiuses = NULL;
   types = molids = NULL;
   ntypes = atom->ntypes;
   typenames = NULL;
 
   // allocate global array for atom coords
 
   bigint n = group->count(igroup);
-  if (n > MAXSMALLINT/sizeof(float)) 
+  if (n > MAXSMALLINT/sizeof(float))
     error->all(FLERR,"Too many atoms for dump molfile");
-  if (n < 1) 
+  if (n < 1)
     error->all(FLERR,"Not enough atoms for dump molfile");
   natoms = static_cast<int>(n);
 
   if (me == 0) {
     memory->create(types,natoms,"dump:types");
     memory->create(coords,3*natoms,"dump:coords");
     if (atom->molecule_flag) memory->create(molids,natoms,"dump:molids");
     if (atom->q_flag) memory->create(charges,natoms,"dump:charges");
     if (atom->rmass_flag) memory->create(masses,natoms,"dump:masses");
     if (atom->radius_flag) memory->create(radiuses,natoms,"dump:radiuses");
 
     mf = new MolfileInterface(arg[5],MFI::M_WRITE);
 
     const char *path = (const char *) ".";
     if (narg > 6)
       path=arg[6];
 
     if (mf->find_plugin(path)!= MFI::E_MATCH)
       error->one(FLERR,"No suitable molfile plugin found");
 
     if (screen)
       fprintf(screen,"Dump '%s' uses molfile plugin: %s\n",
               id, mf->get_plugin_name());
     if (logfile)
       fprintf(logfile,"Dump '%s' uses molfile plugin: %s\n",
               id,mf->get_plugin_name());
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 DumpMolfile::~DumpMolfile()
 {
   if (me == 0) {
     mf->close();
     memory->destroy(types);
     memory->destroy(coords);
     memory->destroy(vels);
     memory->destroy(masses);
     memory->destroy(charges);
     memory->destroy(radiuses);
     delete mf;
   }
-  
+
   if (typenames) {
     for (int i = 1; i <= ntypes; i++)
       delete [] typenames[i];
 
     delete [] typenames;
     typenames = NULL;
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void DumpMolfile::init_style()
 {
   if (sort_flag == 0 || sortcol != 0)
     error->all(FLERR,"Dump molfile requires sorting by atom ID");
 
   if (me == 0) {
 
-    /* initialize typenames array to numeric types by default */ 
+    /* initialize typenames array to numeric types by default */
     if (typenames == NULL) {
       typenames = new char*[ntypes+1];
       for (int itype = 1; itype <= ntypes; itype++) {
         /* a 32-bit int can be maximally 10 digits plus sign */
         typenames[itype] = new char[12];
         sprintf(typenames[itype],"%d",itype);
       }
     }
 
     // open single file, one time only
     if (multifile == 0) openfile();
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void DumpMolfile::write()
 {
   // simulation box dimensions
 
   if (domain->triclinic == 1) {
     double *h = domain->h;
     double alen = h[0];
     double blen = sqrt(h[5]*h[5] + h[1]*h[1]);
     double clen = sqrt(h[4]*h[4] + h[3]*h[3] + h[2]*h[2]);
     cell[0] = alen;
     cell[1] = blen;
     cell[2] = clen;
     cell[3] = (90.0 - asin((h[5]*h[4] + h[1]*h[3]) / blen/clen)); // alpha
     cell[4] = (90.0 - asin((h[0]*h[4]) / alen/clen));             // beta
     cell[5] = (90.0 - asin((h[0]*h[5]) / alen/blen));             // gamma
   } else {
     cell[0] = domain->xprd;
     cell[1] = domain->yprd;
     cell[2] = domain->zprd;
     cell[3] = cell[4] = cell[5] = 90.0f;
   }
 
   // nme = # of dump lines this proc will contribute to dump
 
   nme = count();
   bigint bnme = nme;
 
   // ntotal = total # of dump lines
   // nmax = max # of dump lines on any proc
 
   int nmax;
   MPI_Allreduce(&bnme,&ntotal,1,MPI_LMP_BIGINT,MPI_SUM,world);
   MPI_Allreduce(&nme,&nmax,1,MPI_INT,MPI_MAX,world);
 
   // for single file output, the number of atoms must not change.
   if (natoms != ntotal) {
     if (multifile == 0) {
       error->all(FLERR,"Single file molfile dump needs constant #atoms");
     } else {
       natoms = ntotal;
     }
   }
   ntotal = 0;
 
   // if file per timestep, open new file
 
   if (multifile) openfile();
 
   // insure proc 0 can receive everyone's info
   // limit nmax*size_one to int since used as arg in MPI_Rsend() below
   // pack my data into buf
   // if sorting on IDs also request ID list from pack()
   // sort buf as needed
 
   if (nmax > maxbuf) {
     if ((bigint) nmax * size_one > MAXSMALLINT)
       error->all(FLERR,"Too much per-proc info for dump");
     maxbuf = nmax;
     memory->destroy(buf);
     memory->create(buf,maxbuf*size_one,"dump:buf");
   }
   if (nmax > maxids) {
     maxids = nmax;
     memory->destroy(ids);
     memory->create(ids,maxids,"dump:ids");
   }
 
   pack(ids);
   sort();
 
   int tmp,nlines;
   MPI_Status status;
   MPI_Request request;
 
   if (me == 0) {
     for (int iproc = 0; iproc < nprocs; iproc++) {
       if (iproc) {
         MPI_Irecv(buf,maxbuf*size_one,MPI_DOUBLE,iproc,0,world,&request);
         MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
         MPI_Wait(&request,&status);
         MPI_Get_count(&status,MPI_DOUBLE,&nlines);
         nlines /= size_one;
       } else nlines = nme;
 
       write_data(nlines,buf);
     }
-      
+
   } else {
     MPI_Recv(&tmp,0,MPI_INT,0,0,world,&status);
     MPI_Rsend(buf,nme*size_one,MPI_DOUBLE,0,0,world);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void DumpMolfile::openfile()
 {
   // single file, already opened, so just return
 
   if (singlefile_opened) return;
   if (multifile == 0) singlefile_opened = 1;
   need_structure = 1;
 
   if (me == 0) {
 
     // close open file, if needed.
     if (mf->is_open()) mf->close();
 
     // if one file per timestep, replace '*' with current timestep
 
     char *filecurrent = new char[strlen(filename) + 16];
     if (multifile == 0) {
       strcpy(filecurrent,filename);
     } else {
       char *ptr = strchr(filename,'*');
       char *p1 = filename;
       char *p2 = filecurrent;
       while (p1 != ptr)
         *p2++ = *p1++;
-      
+
       if (padflag == 0) {
         sprintf(p2,BIGINT_FORMAT "%s",update->ntimestep,ptr+1);
       } else {
         char bif[8],pad[16];
         strcpy(bif,BIGINT_FORMAT);
         sprintf(pad,"%%0%d%s%%s",padflag,&bif[1]);
         sprintf(p2,pad,update->ntimestep,ptr+1);
       }
     }
 
     if (mf->open(filecurrent,&natoms))
       error->one(FLERR,"Cannot open dump file");
     delete[] filecurrent;
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void DumpMolfile::pack(int *ids)
 {
   int m,n;
 
   int *tag = atom->tag;
   int *type = atom->type;
   double **x = atom->x;
   tagint *image = atom->image;
   int *mask = atom->mask;
   int nlocal = atom->nlocal;
 
   m = n = 0;
   if (unwrap_flag) {
     double xprd = domain->xprd;
     double yprd = domain->yprd;
     double zprd = domain->zprd;
     double xy = domain->xy;
     double xz = domain->xz;
     double yz = domain->yz;
 
     for (int i = 0; i < nlocal; i++) {
       if (mask[i] & groupbit) {
         int ix = (image[i] & IMGMASK) - IMGMAX;
         int iy = (image[i] >> IMGBITS & IMGMASK) - IMGMAX;
         int iz = (image[i] >> IMG2BITS) - IMGMAX;
 
         buf[m++] = type[i];
         if (domain->triclinic) {
           buf[m++] = x[i][0] + ix * xprd + iy * xy + iz * xz;
           buf[m++] = x[i][1] + iy * yprd + iz * yz;
           buf[m++] = x[i][2] + iz * zprd;
         } else {
           buf[m++] = x[i][0] + ix * xprd;
           buf[m++] = x[i][1] + iy * yprd;
           buf[m++] = x[i][2] + iz * zprd;
         }
         if (atom->molecule_flag) buf[m++] = atom->molecule[i];
         if (atom->q_flag)        buf[m++] = atom->q[i];
         if (atom->rmass_flag)    buf[m++] = atom->mass[i];
         if (atom->radius_flag)   buf[m++] = atom->radius[i];
         ids[n++] = tag[i];
       }
     }
 
   } else {
     for (int i = 0; i < nlocal; i++)
       if (mask[i] & groupbit) {
         buf[m++] = type[i];
         buf[m++] = x[i][0];
         buf[m++] = x[i][1];
         buf[m++] = x[i][2];
         if (atom->molecule_flag) buf[m++] = atom->molecule[i];
         if (atom->q_flag)        buf[m++] = atom->q[i];
         if (atom->rmass_flag)    buf[m++] = atom->mass[i];
         if (atom->radius_flag)   buf[m++] = atom->radius[i];
         ids[n++] = tag[i];
       }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void DumpMolfile::write_data(int n, double *mybuf)
 {
   if (me == 0) {
     // copy buf atom coords into global arrays
     int m = 0;
     for (int i = 0; i < n; i++) {
       types[ntotal] = static_cast<int>(mybuf[m++]);
       coords[3*ntotal + 0] = mybuf[m++];
       coords[3*ntotal + 1] = mybuf[m++];
       coords[3*ntotal + 2] = mybuf[m++];
       if (atom->molecule_flag) molids[ntotal]   = static_cast<int>(mybuf[m++]);
       if (atom->q_flag)        charges[ntotal]  = mybuf[m++];
       if (atom->rmass_flag)    masses[ntotal]   = mybuf[m++];
       if (atom->radius_flag)   radiuses[ntotal] = mybuf[m++];
       ++ntotal;
     }
 
     // if last chunk of atoms in this snapshot, write global arrays to file
 
     if (ntotal == natoms) {
       ntotal = 0;
 
       if (need_structure) {
         mf->property(MFI::P_NAME,types,typenames);
 
         if (atom->molecule_flag)
           mf->property(MFI::P_RESI,molids);
 
         if (atom->rmass_flag) {
           mf->property(MFI::P_MASS,masses);
-        } else { 
+        } else {
           mf->property(MFI::P_MASS,types,atom->mass);
         }
 
         if (atom->q_flag)
           mf->property(MFI::P_CHRG,charges);
 
         if (atom->radius_flag)
           mf->property(MFI::P_RADS,radiuses);
 
         // update/write structure information in plugin
         mf->structure();
         need_structure = 0;
       }
       double simtime = update->ntimestep * update->dt;
       mf->timestep(coords,NULL,cell,&simtime);
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int DumpMolfile::modify_param(int narg, char **arg)
 {
   if (strcmp(arg[0],"unwrap") == 0) {
     if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
     if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1;
     else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0;
     else error->all(FLERR,"Illegal dump_modify command");
     return 2;
 
   } else if (strcmp(arg[0],"element") == 0) {
     if (narg < ntypes+1)
       error->all(FLERR, "Dump modify element names do not match atom types");
 
     if (typenames) {
       for (int i = 1; i <= ntypes; i++)
         delete [] typenames[i];
 
       delete [] typenames;
       typenames = NULL;
     }
 
     typenames = new char*[ntypes+1];
     for (int itype = 1; itype <= ntypes; itype++) {
       int n = strlen(arg[itype]) + 1;
       typenames[itype] = new char[n];
       strcpy(typenames[itype],arg[itype]);
     }
 
     return ntypes+1;
   }
   return 0;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory in buf and global coords array
 ------------------------------------------------------------------------- */
 
 bigint DumpMolfile::memory_usage()
 {
   bigint bytes = Dump::memory_usage();
   bytes += memory->usage(coords,natoms*3);
   bytes += sizeof(MFI);
   return bytes;
 }
diff --git a/src/USER-MOLFILE/dump_molfile.h b/src/USER-MOLFILE/dump_molfile.h
index 964ff349b..d14b4f58c 100644
--- a/src/USER-MOLFILE/dump_molfile.h
+++ b/src/USER-MOLFILE/dump_molfile.h
@@ -1,107 +1,107 @@
 /* -*- c++ -*- ----------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #ifdef DUMP_CLASS
 
 DumpStyle(molfile,DumpMolfile)
 
 #else
 
 #ifndef LMP_DUMP_MOLFILE_H
 #define LMP_DUMP_MOLFILE_H
 
 #include "dump.h"
 
 namespace LAMMPS_NS {
 
 class DumpMolfile : public Dump {
  public:
   DumpMolfile(LAMMPS *, int, char**);
   virtual ~DumpMolfile();
   virtual void write();
 
  protected:
   class MolfileInterface *mf; //< handles low-level I/O
   // per-atom data
   float *coords, *vels, *masses, *charges, *radiuses;
   int   *types, *molids;
   char **typenames;
 
   int natoms,me,ntotal,ntypes;
   int need_structure;
   int unwrap_flag;   // 1 if writing unwrapped atom coords, 0 if not
   int velocity_flag; // 1 if writing velocities, 0 if not
   int topology_flag; // 1 if writing topology data, 0 if not
   float cell[6];     // cell parameters: A, B, C, alpha, beta, gamma
 
   virtual void init_style();
   virtual int modify_param(int, char **);
   virtual void write_header(bigint) {};
   virtual void pack(int *);
   virtual void write_data(int, double *);
   virtual bigint memory_usage();
   virtual void openfile();
 };
 
 }
 
 #endif
 #endif
 
 /* ERROR/WARNING messages:
 
 E: Illegal ... command
 
 Self-explanatory.  Check the input script syntax and compare to the
 documentation for the command.  You can use -echo screen as a
 command-line option when running LAMMPS to see the offending line.
 
 E: Invalid dump dcd filename
 
 Filenames used with the dump dcd style cannot be binary or compressed
 or cause multiple files to be written.
 
 E: Too many atoms for dump dcd
 
 The system size must fit in a 32-bit integer to use this dump
 style.
 
 E: Dump dcd requires sorting by atom ID
 
 Use the dump_modify sort command to enable this.
 
 E: Cannot use variable every setting for dump dcd
 
 The format of Molfile dump files requires snapshots be output
 at a constant frequency.
 
 E: Cannot change dump_modify every for dump dcd
 
 The frequency of writing dump dcd snapshots cannot be changed.
 
 E: Cannot open dump file
 
 The output file for the dump command cannot be opened.  Check that the
 path and name are correct.
 
 E: Dump dcd of non-matching # of atoms
 
 Every snapshot written by dump dcd must contain the same # of atoms.
 
 E: Too big a timestep for dump dcd
 
 The timestep must fit in a 32-bit integer to use this dump style.
 
 */
diff --git a/src/USER-MOLFILE/molfile_interface.cpp b/src/USER-MOLFILE/molfile_interface.cpp
index 13bb49fd5..f3b63e7ed 100644
--- a/src/USER-MOLFILE/molfile_interface.cpp
+++ b/src/USER-MOLFILE/molfile_interface.cpp
@@ -1,1225 +1,1223 @@
 /* -*- c++ -*- ----------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple)
 ------------------------------------------------------------------------- */
 
 #include "molfile_interface.h"
 
 #include <sys/types.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
 
 #if defined(_WIN32)
 #include <windows.h>
 #else
 #include <dirent.h>
 #include <dlfcn.h>
 #endif
 
 #include "molfile_plugin.h"
 
 #if vmdplugin_ABIVERSION < 16
 #error "unsupported VMD molfile plugin ABI version"
 #endif
 
 #define DEBUG 0
 
 extern "C" {
   typedef int (*initfunc)(void);
   typedef int (*regfunc)(void *, vmdplugin_register_cb);
   typedef int (*finifunc)(void);
 
   typedef struct {
     void *p;
     const char *name;
   } plugin_reginfo_t;
 
   // callback function for plugin registration.
-  static int plugin_register_cb(void *v, vmdplugin_t *p) 
+  static int plugin_register_cb(void *v, vmdplugin_t *p)
   {
     plugin_reginfo_t *r = static_cast<plugin_reginfo_t *>(v);
     // make sure we have the proper plugin type (native reader)
     // for the desired file type (called "name" at this level)
     if ((strcmp(MOLFILE_PLUGIN_TYPE,p->type) == 0)
         && (strcmp(r->name, p->name) == 0) ) {
       r->p = static_cast<void *>(p);
     }
     return 0;
   }
 
   /* periodic table of elements for translation of ordinal to atom type */
-  static const char *pte_label[] = { 
+  static const char *pte_label[] = {
     "X",  "H",  "He", "Li", "Be", "B",  "C",  "N",  "O",  "F",  "Ne",
     "Na", "Mg", "Al", "Si", "P" , "S",  "Cl", "Ar", "K",  "Ca", "Sc",
-    "Ti", "V",  "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", 
+    "Ti", "V",  "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge",
     "As", "Se", "Br", "Kr", "Rb", "Sr", "Y",  "Zr", "Nb", "Mo", "Tc",
     "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I",  "Xe",
     "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb",
     "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W",  "Re", "Os",
     "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
     "Ra", "Ac", "Th", "Pa", "U",  "Np", "Pu", "Am", "Cm", "Bk", "Cf",
     "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt",
     "Ds", "Rg"
   };
   static const int nr_pte_entries = sizeof(pte_label) / sizeof(char *);
 
   /* corresponding table of masses. */
-  static const float pte_mass[] = { 
-    /* X  */ 0.00000, 1.00794, 4.00260, 6.941, 9.012182, 10.811,  
-    /* C  */ 12.0107, 14.0067, 15.9994, 18.9984032, 20.1797, 
+  static const float pte_mass[] = {
+    /* X  */ 0.00000, 1.00794, 4.00260, 6.941, 9.012182, 10.811,
+    /* C  */ 12.0107, 14.0067, 15.9994, 18.9984032, 20.1797,
     /* Na */ 22.989770, 24.3050, 26.981538, 28.0855, 30.973761,
     /* S  */ 32.065, 35.453, 39.948, 39.0983, 40.078, 44.955910,
     /* Ti */ 47.867, 50.9415, 51.9961, 54.938049, 55.845, 58.9332,
-    /* Ni */ 58.6934, 63.546, 65.409, 69.723, 72.64, 74.92160, 
-    /* Se */ 78.96, 79.904, 83.798, 85.4678, 87.62, 88.90585, 
+    /* Ni */ 58.6934, 63.546, 65.409, 69.723, 72.64, 74.92160,
+    /* Se */ 78.96, 79.904, 83.798, 85.4678, 87.62, 88.90585,
     /* Zr */ 91.224, 92.90638, 95.94, 98.0, 101.07, 102.90550,
-    /* Pd */ 106.42, 107.8682, 112.411, 114.818, 118.710, 121.760, 
-    /* Te */ 127.60, 126.90447, 131.293, 132.90545, 137.327, 
+    /* Pd */ 106.42, 107.8682, 112.411, 114.818, 118.710, 121.760,
+    /* Te */ 127.60, 126.90447, 131.293, 132.90545, 137.327,
     /* La */ 138.9055, 140.116, 140.90765, 144.24, 145.0, 150.36,
-    /* Eu */ 151.964, 157.25, 158.92534, 162.500, 164.93032, 
+    /* Eu */ 151.964, 157.25, 158.92534, 162.500, 164.93032,
     /* Er */ 167.259, 168.93421, 173.04, 174.967, 178.49, 180.9479,
-    /* W  */ 183.84, 186.207, 190.23, 192.217, 195.078, 196.96655, 
-    /* Hg */ 200.59, 204.3833, 207.2, 208.98038, 209.0, 210.0, 222.0, 
+    /* W  */ 183.84, 186.207, 190.23, 192.217, 195.078, 196.96655,
+    /* Hg */ 200.59, 204.3833, 207.2, 208.98038, 209.0, 210.0, 222.0,
     /* Fr */ 223.0, 226.0, 227.0, 232.0381, 231.03588, 238.02891,
     /* Np */ 237.0, 244.0, 243.0, 247.0, 247.0, 251.0, 252.0, 257.0,
     /* Md */ 258.0, 259.0, 262.0, 261.0, 262.0, 266.0, 264.0, 269.0,
     /* Mt */ 268.0, 271.0, 272.0
   };
 
   /*
    * corresponding table of VDW radii.
-   * van der Waals radii are taken from A. Bondi, 
-   * J. Phys. Chem., 68, 441 - 452, 1964, 
-   * except the value for H, which is taken from R.S. Rowland & R. Taylor, 
-   * J.Phys.Chem., 100, 7384 - 7391, 1996. Radii that are not available in 
+   * van der Waals radii are taken from A. Bondi,
+   * J. Phys. Chem., 68, 441 - 452, 1964,
+   * except the value for H, which is taken from R.S. Rowland & R. Taylor,
+   * J.Phys.Chem., 100, 7384 - 7391, 1996. Radii that are not available in
    * either of these publications have RvdW = 2.00 �.
-   * The radii for Ions (Na, K, Cl, Ca, Mg, and Cs are based on the CHARMM27 
+   * The radii for Ions (Na, K, Cl, Ca, Mg, and Cs are based on the CHARMM27
    * Rmin/2 parameters for (SOD, POT, CLA, CAL, MG, CES) by default.
    */
-  static const float pte_vdw_radius[] = { 
-    /* X  */ 1.5, 1.2, 1.4, 1.82, 2.0, 2.0,  
-    /* C  */ 1.7, 1.55, 1.52, 1.47, 1.54, 
+  static const float pte_vdw_radius[] = {
+    /* X  */ 1.5, 1.2, 1.4, 1.82, 2.0, 2.0,
+    /* C  */ 1.7, 1.55, 1.52, 1.47, 1.54,
     /* Na */ 1.36, 1.18, 2.0, 2.1, 1.8,
     /* S  */ 1.8, 2.27, 1.88, 1.76, 1.37, 2.0,
     /* Ti */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     /* Ni */ 1.63, 1.4, 1.39, 1.07, 2.0, 1.85,
-    /* Se */ 1.9, 1.85, 2.02, 2.0, 2.0, 2.0, 
+    /* Se */ 1.9, 1.85, 2.02, 2.0, 2.0, 2.0,
     /* Zr */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
-    /* Pd */ 1.63, 1.72, 1.58, 1.93, 2.17, 2.0, 
+    /* Pd */ 1.63, 1.72, 1.58, 1.93, 2.17, 2.0,
     /* Te */ 2.06, 1.98, 2.16, 2.1, 2.0,
     /* La */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     /* Eu */ 2.0, 2.0, 2.0, 2.0, 2.0,
     /* Er */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     /* W  */ 2.0, 2.0, 2.0, 2.0, 1.72, 1.66,
     /* Hg */ 1.55, 1.96, 2.02, 2.0, 2.0, 2.0, 2.0,
     /* Fr */ 2.0, 2.0, 2.0, 2.0, 2.0, 1.86,
     /* Np */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     /* Md */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     /* Mt */ 2.0, 2.0, 2.0
   };
 
   /* lookup functions */
 
   static const char *get_pte_label(const int idx)
   {
     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_label[0];
 
     return pte_label[idx];
   }
 
   static float get_pte_mass(const int idx)
   {
     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_mass[0];
 
     return pte_mass[idx];
   }
 
   static float get_pte_vdw_radius(const int idx)
   {
     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_vdw_radius[0];
 
 #if 1
     /* Replace with Hydrogen radius with an "all-atom" radius */
     if (idx == 1)
       return 1.0;    /* H  */
 #else
     /* Replace with old VMD atom radii values */
     switch (idx) {
     case  1: return 1.0;    /* H  */
     case  6: return 1.5;    /* C  */
     case  7: return 1.4;    /* N  */
     case  8: return 1.3;    /* O  */
     case  9: return 1.2;    /* F  */
     case 15: return 1.5;    /* P  */
-    case 16: return 1.9;    /* S  */ 
+    case 16: return 1.9;    /* S  */
     }
 #endif
 
     return pte_vdw_radius[idx];
   }
 
   static int get_pte_idx(const char *label)
   {
     int i;
     char atom[3];
-    
+
     /* zap string */
     atom[0] = (char) 0;
     atom[1] = (char) 0;
     atom[2] = (char) 0;
-    /* if we don't have a null-pointer, there must be at least two 
-     * chars, which is all we need. we convert to the capitalization 
+    /* if we don't have a null-pointer, there must be at least two
+     * chars, which is all we need. we convert to the capitalization
      * convention of the table above during assignment. */
     if (label != NULL) {
       atom[0] = (char) toupper((int) label[0]);
       atom[1] = (char) tolower((int) label[1]);
     }
     /* discard numbers in atom label */
     if (isdigit(atom[1])) atom[1] = (char) 0;
-    
+
     for (i=0; i < nr_pte_entries; ++i) {
       if ( (pte_label[i][0] == atom[0])
            && (pte_label[i][1] == atom[1]) ) return i;
     }
-    
+
     return 0;
   }
 
   static int get_pte_idx_from_string(const char *label) {
     int i, ind;
     char atom[3];
 
     if (label != NULL) {
       /* zap string */
       atom[0] = atom[1] = atom[2] = '\0';
 
       for (ind=0,i=0; (ind<2) && (label[i]!='\0'); i++) {
         if (label[i] != ' ') {
           atom[ind] = toupper(label[i]);
           ind++;
         }
       }
 
       if (ind < 1)
         return 0; /* no non-whitespace characters */
- 
+
       for (i=0; i < nr_pte_entries; ++i) {
-        if ((toupper(pte_label[i][0]) == atom[0]) && (toupper(pte_label[i][1]) == atom[1])) 
+        if ((toupper(pte_label[i][0]) == atom[0]) && (toupper(pte_label[i][1]) == atom[1]))
           return i;
       }
-    }  
+    }
 
     return 0;
   }
 
   // directory traversal helper functions
 
 #if defined(_WIN32)
 
   // Win32 directory traversal handle
   typedef struct {
     HANDLE h;
     WIN32_FIND_DATA fd;
     char *name;
     char *searchname;
     int dlen;
   } dirhandle_t;
 
   // open a directory handle
   static dirhandle_t *my_opendir(const char *dirname)
   {
     dirhandle_t *d;
     int len;
 
-    if (dirname == NULL) 
+    if (dirname == NULL)
       return NULL;
     d = new dirhandle_t;
 
     len = 2 + strlen(dirname);
     d->name = new char[len];
     strcpy(d->name, dirname);
     strcat(d->name, "\\");
     d->dlen = len;
 
     len += 1;
     d->searchname = new char[len];
     strcpy(d->searchname, dirname);
     strcat(d->searchname, "\\*");
 
     d->h = FindFirstFile(d->searchname, &(d->fd));
     if (d->h == ((HANDLE)(-1))) {
       delete[] d->searchname;
       delete[] d->name;
       delete d;
       return NULL;
     }
     return d;
   }
 
   // get next file name from directory handle
   static char *my_readdir(dirhandle_t *d)
   {
     if (FindNextFile(d->h, &(d->fd))) {
-      return d->fd.cFileName; 
+      return d->fd.cFileName;
     }
-    return NULL;     
+    return NULL;
   }
 
   // close directory handle
   static void my_closedir(dirhandle_t *d)
   {
     if (d->h != NULL) {
       FindClose(d->h);
     }
     delete[] d->searchname;
     delete[] d->name;
     delete d;
   }
 
   // open a shared object file
   static void *my_dlopen(const char *fname) {
     return (void *)LoadLibrary(fname);
   }
 
   // report error message from dlopen
   static const char *my_dlerror(void) {
-    static CHAR szBuf[80]; 
+    static CHAR szBuf[80];
     DWORD dw = GetLastError();
 
-    sprintf(szBuf, "my_dlopen failed: GetLastError returned %u\n", dw); 
+    sprintf(szBuf, "my_dlopen failed: GetLastError returned %u\n", dw);
     return szBuf;
   }
 
   // resolve a symbol in shared object
   static void *my_dlsym(void *h, const char *sym) {
     return (void *)GetProcAddress((HINSTANCE)h, sym);
   }
 
   // close a shared object
   static int my_dlclose(void *h) {
     /* FreeLibrary returns nonzero on success */
     return !FreeLibrary((HINSTANCE)h);
   }
 
 #else
 
   // Unix directory traversal handle
   typedef struct {
     DIR *d;
     char *name;
     int dlen;
   } dirhandle_t;
 
   // open a directory handle
   static dirhandle_t *my_opendir(const char *dirname)
   {
     dirhandle_t *d;
     int len;
 
     if (dirname == NULL) return NULL;
 
     d = new dirhandle_t;
     len = 2 + strlen(dirname);
     d->name = new char[len];
     strcpy(d->name,dirname);
     strcat(d->name,"/");
     d->dlen = len;
 
     d->d = opendir(d->name);
     if (d->d == NULL) {
       delete[] d->name;
       delete d;
       return NULL;
     }
     return d;
   }
 
   // get next file name from directory handle
   static char *my_readdir(dirhandle_t *d)
   {
     struct dirent *p;
 
     if ((p = readdir(d->d)) != NULL) {
       return p->d_name;
     }
 
     return NULL;
   }
 
   // close directory handle
   static void my_closedir(dirhandle_t *d)
   {
     if (d->d != NULL) {
       closedir(d->d);
     }
     delete[] d->name;
     delete d;
     return;
   }
 
   // open a shared object file
   static void *my_dlopen(const char *fname) {
     return dlopen(fname, RTLD_NOW);
   }
 
   // report error message from dlopen
   static const char *my_dlerror(void) {
     return dlerror();
   }
 
   // resolve a symbol in shared object
   static void *my_dlsym(void *h, const char *sym) {
     return dlsym(h, sym);
   }
 
   // close a shared object
   static int my_dlclose(void *h) {
     return dlclose(h);
   }
 
 #endif
 
 } // end of extern "C" region
 
 using namespace LAMMPS_NS;
 
 // constructor.
 MolfileInterface::MolfileInterface(const char *type, const int mode)
   : _plugin(0), _dso(0), _ptr(0), _info(0), _natoms(0),
     _mode(mode), _caps(M_NONE)
 {
   _name = new char[5];
   strcpy(_name,"none");
   _type = new char[1+strlen(type)];
   strcpy(_type,type);
 }
 
 // destructor.
 MolfileInterface::~MolfileInterface()
 {
   forget_plugin();
 
   if (_info) {
     molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
     delete[] a;
     _info = NULL;
   }
   delete[] _name;
   delete[] _type;
 }
 
 // register the best matching plugin in a given directory
 int MolfileInterface::find_plugin(const char *pluginpath)
 {
   dirhandle_t *dir;
   char *filename, *ext, *next, *path, *plugindir;
   int retval = E_NONE;
 
 #if defined(_WIN32)
 #define MY_PATHSEP ';'
 #else
 #define MY_PATHSEP ':'
 #endif
   if (pluginpath == NULL) return E_DIR;
   plugindir = path = strdup(pluginpath);
 
   while (plugindir) {
     // check if this a single directory or path.
     next = strchr(plugindir,MY_PATHSEP);
     if (next) {
       *next = '\0';
       ++next;
     }
 
     dir = my_opendir(plugindir);
     if (!dir)
       retval = (retval > E_DIR) ? retval : E_DIR;
 
     // search for suitable file names and try to inspect them
     while(dir) {
       char *fullname;
       int len;
 
       filename = my_readdir(dir);
       if (filename == NULL) break;
 
       // only look at .so files
       ext = strrchr(filename, '.');
       if (ext == NULL) continue;
       if (strcasecmp(ext,".so") != 0) continue;
 
       // construct full pathname of potential DSO
       len = dir->dlen;
       len += strlen(filename);
       fullname = new char[len];
       strcpy(fullname,dir->name);
       strcat(fullname,filename);
 
       // try to register plugin at file name.
       int rv = load_plugin(fullname);
       if (rv > retval) retval = rv;
 
       delete[] fullname;
     }
     if (dir)
       my_closedir(dir);
 
     plugindir = next;
   }
   free(path);
   return retval;
 }
 
 // register the best matching plugin in a given directory
 int MolfileInterface::load_plugin(const char *filename)
 {
   void *dso;
   int len, retval = E_NONE;
 
   // access shared object
   dso = my_dlopen(filename);
   if (dso == NULL)
     return E_FILE;
 
   // check for required plugin symbols
   void *ifunc = my_dlsym(dso,"vmdplugin_init");
   void *rfunc = my_dlsym(dso,"vmdplugin_register");
   void *ffunc = my_dlsym(dso,"vmdplugin_fini");
   if (ifunc == NULL || rfunc == NULL || ffunc == NULL) {
     my_dlclose(dso);
     return E_SYMBOL;
   }
 
   // intialize plugin. skip plugin if it fails.
   if (((initfunc)(ifunc))()) {
     my_dlclose(dso);
     return E_SYMBOL;
   }
 
   // pre-register plugin.
   // the callback will be called for each plugin in the DSO and
   // check the file type. plugin->name will change if successful.
   plugin_reginfo_t reginfo;
   reginfo.p = NULL;
   reginfo.name=_type;
   ((regfunc)rfunc)(&reginfo, plugin_register_cb);
 
   // make some checks to see if the plugin is suitable or not.
   molfile_plugin_t *plugin = static_cast<molfile_plugin_t *>(reginfo.p);
 
   // if the callback found a matching plugin and copied the struct,
   // its name element will point to a different location now.
   if (plugin == NULL) {
     retval = E_TYPE;
 
     // check if the ABI matches the one used to compile this code
   } else if (plugin->abiversion != vmdplugin_ABIVERSION) {
     retval = E_ABI;
 
     // check if (basic) reading is supported
   } else if ((_mode & M_READ) &&
              ( (plugin->open_file_read == NULL) ||
                (plugin->read_next_timestep  == NULL) ||
                (plugin->close_file_read == NULL) )) {
     retval = E_MODE;
 
     // check if (basic) writing is supported
   } else if ( (_mode & M_WRITE) &&
               ( (plugin->open_file_write == NULL) ||
                 (plugin->write_timestep  == NULL) ||
                 (plugin->close_file_write == NULL) )) {
     retval = E_MODE;
 
     // make some additional check, if we
     // already have a plugin registered.
     // NOTE: this has to come last.
   } else if (_dso && _plugin) {
     molfile_plugin_t *p;
     p = static_cast<molfile_plugin_t *>(_plugin);
 
     // check if the new plugin is of a newer major version
     if (p->majorv > plugin->majorv) {
       retval = E_VERSION;
 
     // check if the new plugin is of a newer minor version
     } else if ( (p->majorv == plugin->majorv) &&
                 (p->minorv >= plugin->minorv) ) {
       retval = E_VERSION;
     }
   }
 
   // bingo! this one is a keeper.
   if (retval == E_NONE) {
 
     // make sure any existing plugin is wiped out
     forget_plugin();
 
     delete[] _name;
     len = 16;
     len += strlen(plugin->prettyname);
     len += strlen(plugin->author);
     _name = new char[len];
     sprintf(_name,"%s v%d.%d by %s",plugin->prettyname,
             plugin->majorv, plugin->minorv, plugin->author);
 
     // determine plugin capabilities
     _caps = M_NONE;
     if (plugin->read_next_timestep)      _caps |= M_READ;
     if (plugin->write_timestep)          _caps |= M_WRITE;
 #if vmdplugin_ABIVERSION > 10
     // required to tell if velocities are present
     if (plugin->read_timestep_metadata)  _caps |= M_RVELS;
     // we can always offer velocities. we may not know if
     // they will be written by the plugin though.
     if (plugin->write_timestep)          _caps |= M_WVELS;
 #endif
     if (plugin->read_structure)          _caps |= M_RSTRUCT;
     if (plugin->write_structure)         _caps |= M_WSTRUCT;
     if (plugin->read_bonds)              _caps |= M_RBONDS;
     if (plugin->write_bonds)             _caps |= M_WBONDS;
     if (plugin->read_angles)             _caps |= M_RANGLES;
     if (plugin->write_angles)            _caps |= M_WANGLES;
     if (plugin->read_volumetric_data)    _caps |= M_RVOL;
     if (plugin->write_volumetric_data)   _caps |= M_WVOL;
 
     if (_mode & M_WRITE) {
       _mode |= (_caps & M_WSTRUCT);
       _mode |= (_caps & M_WVELS);
     } else if (_mode & M_READ) {
       _mode |= (_caps & M_RSTRUCT);
       _mode |= (_caps & M_RVELS);
     }
 
     _plugin = plugin;
     _dso = dso;
     return E_MATCH;
   }
 
   // better luck next time. clean up and return.
   my_dlclose(dso);
   return retval;
 }
 
 // deregister a plugin and close or reset all associated objects.
 void MolfileInterface::forget_plugin()
 {
   if (_ptr)
     close();
 
   if (_plugin)
     _plugin = NULL;
 
   if (_dso) {
     void *ffunc = my_dlsym(_dso,"vmdplugin_fini");
     if (ffunc)
       ((finifunc)ffunc)();
     my_dlclose(_dso);
   }
   _dso = NULL;
 
   delete[] _name;
     _name = new char[5];
   strcpy(_name,"none");
 
   _caps = M_NONE;
 }
 
 // open file for reading or writing
 int MolfileInterface::open(const char *name, int *natoms)
 {
   if (!_plugin || !_dso || !natoms)
     return E_FILE;
   molfile_plugin_t *p = static_cast<molfile_plugin_t *>(_plugin);
-  
+
   if (_mode & M_WRITE)
     _ptr = p->open_file_write(name,_type,*natoms);
   else if (_mode & M_READ)
     _ptr = p->open_file_read(name,_type,natoms);
 
   if (_ptr == NULL)
     return E_FILE;
 
   _natoms = *natoms;
   // we need to deal with structure information,
   // so we allocate and initialize storage for it.
   if (_mode & (M_RSTRUCT|M_WSTRUCT)) {
     molfile_atom_t *a = new molfile_atom_t[_natoms];
     _info = a;
     memset(_info,0,_natoms*sizeof(molfile_atom_t));
     for (int i=0; i < _natoms; ++i) {
       a[i].name[0] = 'X';
       a[i].type[0] = a[i].resname[0] = a[i].segid[0] = 'U';
       a[i].type[1] = a[i].resname[1] = a[i].segid[1] = 'N';
       a[i].type[2] = a[i].resname[2] = a[i].segid[2] = 'K';
       a[i].chain[0] = 'X';
     }
   }
   return E_NONE;
 }
 
 // get of set atom structure information
 int MolfileInterface::structure()
 {
   if (!_plugin || !_dso)
     return E_FILE;
   molfile_plugin_t *p = static_cast<molfile_plugin_t *>(_plugin);
 
   int optflags = MOLFILE_NOOPTIONS;
 
   if (_mode & M_WSTRUCT) {
     optflags |= (_props & P_BFAC) ? MOLFILE_BFACTOR : 0;
     optflags |= (_props & P_OCCP) ? MOLFILE_OCCUPANCY : 0;
     optflags |= (_props & P_MASS) ? MOLFILE_MASS : 0;
     optflags |= (_props & P_CHRG) ? MOLFILE_CHARGE : 0;
     optflags |= (_props & P_RADS) ? MOLFILE_RADIUS : 0;
     optflags |= (_props & P_ATMN) ? MOLFILE_ATOMICNUMBER : 0;
-  
+
     molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
     p->write_structure(_ptr,optflags,a);
   } else if (_mode & M_RSTRUCT) {
     molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
     p->read_structure(_ptr,&optflags,a);
     // mandatory properties
     _props = P_NAME|P_TYPE|P_RESN|P_RESI|P_SEGN|P_CHAI;
     // optional properties
     _props |= (optflags & MOLFILE_BFACTOR) ? P_BFAC : 0;
     _props |= (optflags & MOLFILE_OCCUPANCY) ? P_OCCP : 0;
     _props |= (optflags & MOLFILE_MASS) ? P_MASS : 0;
     _props |= (optflags & MOLFILE_CHARGE) ? P_CHRG : 0;
     _props |= (optflags & MOLFILE_RADIUS) ? P_RADS : 0;
     _props |= (optflags & MOLFILE_ATOMICNUMBER) ? P_ATMN : 0;
   }
   return 0;
 }
 
 // safely close file
 int MolfileInterface::close()
 {
   if (!_plugin || !_dso || !_ptr)
     return E_FILE;
 
   molfile_plugin_t *p = static_cast<molfile_plugin_t *>(_plugin);
 
   if (_mode & M_WRITE) {
     p->close_file_write(_ptr);
   } else if (_mode & M_READ) {
     p->close_file_read(_ptr);
   }
 
   if (_info) {
     molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
     delete[] a;
     _info = NULL;
   }
   _ptr = NULL;
   _natoms = 0;
 
   return E_NONE;
 }
 
 
 // read or write timestep
 int MolfileInterface::timestep(float *coords, float *vels,
                                float *cell, double *simtime)
 {
   if (!_plugin || !_dso || !_ptr)
     return 1;
 
   molfile_plugin_t *p = static_cast<molfile_plugin_t *>(_plugin);
   molfile_timestep_t *t = new molfile_timestep_t;
   int rv;
-  
+
   if (_mode & M_WRITE) {
     t->coords = coords;
     t->velocities = vels;
     if (cell != NULL) {
       t->A = cell[0];
       t->B = cell[1];
       t->C = cell[2];
       t->alpha = cell[3];
       t->beta = cell[4];
       t->gamma = cell[5];
     } else {
       t->A = 0.0f;
       t->B = 0.0f;
       t->C = 0.0f;
       t->alpha = 90.0f;
       t->beta = 90.0f;
       t->gamma = 90.0f;
     }
 
     if (simtime)
       t->physical_time = *simtime;
     else
       t->physical_time = 0.0;
 
     rv = p->write_timestep(_ptr,t);
 
   } else {
     // no coordinate storage => skip step
     if (coords == NULL) {
       rv = p->read_next_timestep(_ptr, _natoms, NULL);
     } else {
       t->coords = coords;
       t->velocities = vels;
       t->A = 0.0f;
       t->B = 0.0f;
       t->C = 0.0f;
       t->alpha = 90.0f;
       t->beta = 90.0f;
       t->gamma = 90.0f;
       t->physical_time = 0.0;
       rv = p->read_next_timestep(_ptr, _natoms, t);
       if (cell != NULL) {
         cell[0] = t->A;
         cell[1] = t->B;
         cell[2] = t->C;
         cell[3] = t->alpha;
         cell[4] = t->beta;
         cell[5] = t->gamma;
       }
       if (simtime)
         *simtime = t->physical_time;
     }
 
     if (rv == MOLFILE_EOF)
       return 1;
   }
 
   return 0;
 }
 
 // functions to read properties from molfile structure
 
 #define PROPUPDATE(PROP,ENTRY,VAL)              \
   if (propid == PROP) { VAL = a.ENTRY; }
 
 #define PROPSTRCPY(PROP,ENTRY,VAL)              \
   if (propid == PROP) { strcpy(VAL,a.ENTRY); }
 
 // single precision floating point props
 static float read_float_property(molfile_atom_t &a, const int propid)
 {
   float prop = 0.0f;
   int iprop = 0;
   PROPUPDATE(MolfileInterface::P_OCCP,occupancy,prop);
   PROPUPDATE(MolfileInterface::P_BFAC,bfactor,prop);
   PROPUPDATE(MolfileInterface::P_MASS,mass,prop);
   PROPUPDATE(MolfileInterface::P_CHRG,charge,prop);
   PROPUPDATE(MolfileInterface::P_RADS,radius,prop);
 
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_MASS),
              atomicnumber,iprop);
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_RADS),
              atomicnumber,iprop);
   if (propid & MolfileInterface::P_ATMN) {
     if (propid & MolfileInterface::P_MASS)
       prop = get_pte_mass(iprop);
     if (propid & MolfileInterface::P_RADS)
       prop = get_pte_vdw_radius(iprop);
   }
 
   return prop;
 }
 
 // integer and derived props
 static int read_int_property(molfile_atom_t &a, const int propid)
 {
   int prop = 0;
   const char * sprop;
 
   PROPUPDATE(MolfileInterface::P_RESI,resid,prop);
   PROPUPDATE(MolfileInterface::P_ATMN,atomicnumber,prop);
-  
+
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_NAME),
              name,sprop);
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_TYPE),
              type,sprop);
 
   if (propid & MolfileInterface::P_ATMN) {
     if (propid & (MolfileInterface::P_NAME|MolfileInterface::P_TYPE))
       prop = get_pte_idx_from_string(sprop);
   }
 
   return prop;
 }
 
 // string and derived props
 static const char *read_string_property(molfile_atom_t &a,
                                         const int propid)
 {
   const char *prop = NULL;
   int iprop = 0;
   PROPUPDATE(MolfileInterface::P_NAME,name,prop);
   PROPUPDATE(MolfileInterface::P_TYPE,type,prop);
   PROPUPDATE(MolfileInterface::P_RESN,resname,prop);
   PROPUPDATE(MolfileInterface::P_SEGN,segid,prop);
 
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_NAME),
              atomicnumber,iprop);
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_TYPE),
              atomicnumber,iprop);
 
   if (propid & MolfileInterface::P_ATMN) {
     if (propid & (MolfileInterface::P_NAME|MolfileInterface::P_TYPE))
       prop = get_pte_label(iprop);
   }
 
   return prop;
 }
 #undef PROPUPDATE
 #undef PROPSTRCPY
 
 // functions to store properties into molfile structure
 
 #define PROPUPDATE(PROP,ENTRY,VAL)                                  \
   if ((propid & PROP) == PROP) { a.ENTRY = VAL; plist |= PROP; }
 
 #define PROPSTRCPY(PROP,ENTRY,VAL)                                      \
   if ((propid & PROP) == PROP) { strcpy(a.ENTRY,VAL); plist |= PROP; }
 
 // floating point props
 static int write_atom_property(molfile_atom_t &a,
                                const int propid,
-                               const float prop) 
+                               const float prop)
 {
   int plist = MolfileInterface::P_NONE;
   PROPUPDATE(MolfileInterface::P_OCCP,occupancy,prop);
   PROPUPDATE(MolfileInterface::P_BFAC,bfactor,prop);
   PROPUPDATE(MolfileInterface::P_MASS,mass,prop);
   PROPUPDATE(MolfileInterface::P_CHRG,charge,prop);
   PROPUPDATE(MolfileInterface::P_RADS,radius,prop);
   return plist;
 }
 
 // double precision floating point props
 static int write_atom_property(molfile_atom_t &a,
                                const int propid,
-                               const double prop) 
+                               const double prop)
 {
   return write_atom_property(a,propid,static_cast<float>(prop));
 }
 
 // integer and derived props
 static int write_atom_property(molfile_atom_t &a,
                                const int propid,
-                               const int prop) 
+                               const int prop)
 {
   int plist = MolfileInterface::P_NONE;
   PROPUPDATE(MolfileInterface::P_RESI,resid,prop);
   PROPUPDATE(MolfileInterface::P_ATMN,atomicnumber,prop);
   PROPUPDATE((MolfileInterface::P_ATMN|MolfileInterface::P_MASS),
              mass,get_pte_mass(prop));
   PROPSTRCPY((MolfileInterface::P_ATMN|MolfileInterface::P_NAME),
              name,get_pte_label(prop));
   PROPSTRCPY((MolfileInterface::P_ATMN|MolfileInterface::P_TYPE),
              type,get_pte_label(prop));
   return plist;
 }
 
 // integer and derived props
 static int write_atom_property(molfile_atom_t &a,
                                const int propid,
-                               const char *prop) 
+                               const char *prop)
 {
   int plist = MolfileInterface::P_NONE;
   PROPSTRCPY(MolfileInterface::P_NAME,name,prop);
   PROPSTRCPY(MolfileInterface::P_TYPE,type,prop);
   PROPSTRCPY(MolfileInterface::P_RESN,resname,prop);
   PROPSTRCPY(MolfileInterface::P_SEGN,segid,prop);
   return plist;
 }
 #undef PROPUPDATE
 #undef PROPSTRCPY
 
 // set/get atom floating point property
 int MolfileInterface::property(int propid, int idx, float *prop)
 {
   if ((_info == NULL) || (prop == NULL) || (idx < 0) || (idx >= _natoms))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT)
     _props |= write_atom_property(a[idx], propid, *prop);
 
   if (_mode & M_RSTRUCT)
     *prop = read_float_property(a[idx], propid);
 
   return _props;
 }
 
 // set/get per type floating point property
 int MolfileInterface::property(int propid, int *types, float *prop)
 {
   if ((_info == NULL) || (types == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i], propid, prop[types[i]]);
   }
 
   // useless for reading.
   if (_mode & M_RSTRUCT)
     return P_NONE;
 
   return _props;
 }
 
 // set/get per atom floating point property
 int MolfileInterface::property(int propid, float *prop)
 {
   if ((_info == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i], propid, prop[i]);
   }
 
   if (_mode & M_RSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       prop[i] = read_float_property(a[i], propid);
   }
 
   return _props;
 }
 
 // set/get atom floating point property
 int MolfileInterface::property(int propid, int idx, double *prop)
 {
   if ((_info == NULL) || (prop == NULL) || (idx < 0) || (idx >= _natoms))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT)
     return write_atom_property(a[idx], propid, *prop);
 
   if (_mode & M_RSTRUCT)
     *prop = static_cast<double>(read_float_property(a[idx], propid));
 
   return _props;
 }
 
 // set/get per type floating point property
 int MolfileInterface::property(int propid, int *types, double *prop)
 {
   if ((_info == NULL) || (types == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i], propid, prop[types[i]]);
   }
 
   // useless for reading
   if (_mode & M_RSTRUCT)
     return P_NONE;
 
   return _props;
 }
 
 // set/get per atom floating point property
 int MolfileInterface::property(int propid, double *prop)
 {
   if ((_info == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
 
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i], propid, prop[i]);
   }
   if (_mode & M_RSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       prop[i] = static_cast<double>(read_float_property(a[i], propid));
   }
 
   return _props;
 }
 
 #define INT_TO_STRING_BODY(IDX)                         \
   buf[15] = 0;                                          \
   if (propid & P_NAME)                                  \
     _props |= write_atom_property(a[IDX],P_NAME,buf);   \
   if (propid & P_TYPE)                                  \
     _props |= write_atom_property(a[IDX],P_TYPE,buf);   \
   buf[7] = 0;                                           \
   if (propid & P_RESN)                                  \
     _props |= write_atom_property(a[IDX],P_RESN,buf);   \
   if (propid & P_SEGN)                                  \
     _props |= write_atom_property(a[IDX],P_SEGN,buf);   \
   buf[1] = 0;                                           \
   if (propid & P_CHAI)                                  \
     _props |= write_atom_property(a[IDX],P_CHAI,buf)
 
 // set/get atom integer property
-int MolfileInterface::property(int propid, int idx, int *prop) 
+int MolfileInterface::property(int propid, int idx, int *prop)
 {
   if ((_info == NULL) || (prop == NULL) || (idx < 0) || (idx >= _natoms))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     char buf[64];
 
     _props |= write_atom_property(a[idx], propid, *prop);
 
     if (propid & (P_NAME|P_TYPE|P_RESN|P_SEGN|P_CHAI)) {
       sprintf(buf,"%d",*prop);
       INT_TO_STRING_BODY(idx);
     }
   }
 
   if (_mode & M_RSTRUCT)
     *prop = read_int_property(a[idx], propid);
 
   return _props;
 }
 
 // set/get per type integer property
-int MolfileInterface::property(int propid, int *types, int *prop) 
+int MolfileInterface::property(int propid, int *types, int *prop)
 {
   if ((_info == NULL) || (types == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     char buf[64];
 
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i], propid, prop[types[i]]);
 
     if (propid & (P_NAME|P_TYPE|P_RESN|P_SEGN|P_CHAI)) {
       for (int i=0; i < _natoms; ++i) {
         sprintf(buf,"%d",prop[types[i]]);
         INT_TO_STRING_BODY(i);
       }
     }
   }
 
   // useless when reading
   if (_mode & M_RSTRUCT)
     return P_NONE;
 
   return _props;
 }
 
 // set/get per atom integer property
-int MolfileInterface::property(int propid, int *prop) 
+int MolfileInterface::property(int propid, int *prop)
 {
   if ((_info == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     char buf[64];
 
     for (int i=0; i < _natoms; ++i)
       _props |= write_atom_property(a[i],propid,prop[i]);
 
     if (propid & (P_NAME|P_TYPE|P_RESN|P_SEGN|P_CHAI)) {
       for (int i=0; i < _natoms; ++i) {
         sprintf(buf,"%d",prop[i]);
         INT_TO_STRING_BODY(i);
       }
-    } 
+    }
   }
 
   if (_mode & M_RSTRUCT) {
     for (int i=0; i < _natoms; ++i)
       prop[i] = read_int_property(a[i], propid);
   }
 
   return _props;
 }
 #undef INT_TO_STRING_BODY
 
 // set/get atom string property
 int MolfileInterface::property(int propid, int idx, char *prop)
 {
   if ((_info == NULL) || (prop == NULL) || (idx < 0) || (idx >= _natoms))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     _props |= write_atom_property(a[idx], propid, prop);
   }
 
   if (_mode & M_RSTRUCT)
     strcpy(prop,read_string_property(a[idx], propid));
 
   return _props;
 }
 
 // set/get per type string property
 int MolfileInterface::property(int propid, int *types, char **prop)
 {
   if ((_info == NULL) || (types == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i) {
       _props |= write_atom_property(a[i], propid, prop[types[i]]);
     }
   }
 
   // useless when reading
   if (_mode & M_RSTRUCT)
     return P_NONE;
 
   return _props;
 }
 
 // set/get per atom string property
 int MolfileInterface::property(int propid, char **prop)
 {
   if ((_info == NULL) || (prop == NULL))
     return P_NONE;
 
   molfile_atom_t *a = static_cast<molfile_atom_t *>(_info);
-  
+
   if (_mode & M_WSTRUCT) {
     for (int i=0; i < _natoms; ++i) {
       _props |= write_atom_property(a[i], propid, prop[i]);
     }
   }
 
   // not supported right now. XXX: should we use strdup() here?
   if (_mode & M_RSTRUCT)
     return P_NONE;
 
   return _props;
 }
-
-
diff --git a/src/USER-MOLFILE/molfile_interface.h b/src/USER-MOLFILE/molfile_interface.h
index f7dc4f522..1146fb825 100644
--- a/src/USER-MOLFILE/molfile_interface.h
+++ b/src/USER-MOLFILE/molfile_interface.h
@@ -1,161 +1,161 @@
 /* -*- c++ -*- ----------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #ifndef LMP_MOLFILE_INTERFACE_H
 #define LMP_MOLFILE_INTERFACE_H
 
 namespace LAMMPS_NS {
 
 // This class provides an abstract interface
 // to the VMD plugin library.
 
-class MolfileInterface 
+class MolfileInterface
 {
  public:
   // plugin modes.
   enum {M_NONE=0,
         M_READ    = 1<<0,  M_WRITE   = 1<<1,
         M_RSTRUCT = 1<<2,  M_WSTRUCT = 1<<3,
         M_RBONDS  = 1<<4,  M_WBONDS  = 1<<5,
         M_RANGLES = 1<<6,  M_WANGLES = 1<<7,
         M_RVOL    = 1<<8,  M_WVOL    = 1<<9,
         M_RVELS   = 1<<10, M_WVELS   = 1<<11,
         M_LAST    = 1<<12 };
 
   // plugin finder return values.
   enum {E_NONE=0,  //< nothing happened
         E_DIR,     //< path is not a directory or not readable
         E_FILE,    //< file not a DSO or not readable
         E_SYMBOL,  //< DSO is not a VMD plugin
         E_TYPE,    //< plugin is not of the correct type
         E_ABI,     //< plugin ABI does not match
         E_MODE,    //< plugin does not support desired mode
         E_VERSION, //< plugin is not newer as the current one
         E_MATCH,   //< plugin matches
         E_LAST     //< last entry
   };
 
   // atom structure properties. deliberately not complete.
   enum {P_NONE=0,     //< no structure information available
         P_NAME=1<<0,  //< atom name,    char[16]
         P_TYPE=1<<1,  //< atom type,    char[16]
         P_RESN=1<<2,  //< residue name, char[ 8]
         P_RESI=1<<3,  //< residue index, int
         P_SEGN=1<<4,  //< segment name, char[ 8]
         P_CHAI=1<<5,  //< chain id,     char[ 2]
         P_OCCP=1<<6,  //< occupancy,    float
         P_BFAC=1<<7,  //< B factor,     float
         P_MASS=1<<8,  //< atom mass,    float
         P_CHRG=1<<9,  //< atom charge,  float
         P_RADS=1<<10, //< atom radius,  float
         P_ATMN=1<<11, //< atomic number, int
         P_LAST=1<<12  //< last entry
   };
 
   MolfileInterface(const char *type, const int mode);
   ~MolfileInterface();
 
   // disallowed default methods
  private:
   MolfileInterface() {};
   MolfileInterface(const MolfileInterface &) {};
   MolfileInterface &operator =(const MolfileInterface &) {return *this;};
 
  public:
   // search in the given directory path for a molfile plugin that
   // is of the right type and supports the desired mode.
   // if a plugin is already registered and a newer version is
   // found, this new version will override the old one.
   int find_plugin(const char *path);
   // try to register the plugin at given file name
   int load_plugin(const char *name);
   // deregister the current plugin/DSO and clean up.
   void forget_plugin();
   // return formatted string describing plugin
   char *get_plugin_name() const { return _name; };
   // return canonical plugin name (= file type)
   char *get_plugin_type() const { return _type; };
 
   // file operations
 
   // open file through plugin
   int open(const char *name, int *natoms);
   // read/write structure info
   int structure();
   // read/write timestep
   int timestep(float *coords, float *vels, float *cell, double *simtime);
   // close file managed by plugin
   int close();
 
   // inquire on interface status
 
   // true if file stream is active.
   bool is_open() const { return (_ptr != 0); };
   // true if file format requires or provides atom properties
   bool has_props() const { return (_mode & (M_RSTRUCT|M_WSTRUCT)) != 0; };
   // true if file format can read or write velocities
   bool has_vels() const { return (_mode & (M_RVELS|M_WVELS)) != 0; };
 
   // return number of atoms in current file. -1 if closed/invalid;
   bool get_natoms() const { return _natoms; };
   // return property bitmask
   bool get_props() const { return _props; };
 
   // atom property operations
 
   // set/get atom floating point property
   int property(int propid, int idx, float *prop);
   // set/get per type floating point property
   int property(int propid, int *types, float *prop);
   // set/get per atom floating point property
   int property(int propid, float *prop);
   // set/get atom floating point property
   int property(int propid, int idx, double *prop);
   // set/get per type floating point property
   int property(int propid, int *types, double *prop);
   // set/get per atom floating point property
   int property(int propid, double *prop);
   // set/get atom integer property
   int property(int propid, int idx, int *prop);
   // set/get per type integer property
   int property(int propid, int *types, int *prop);
   // set/get per atom integer property
   int property(int propid, int *prop);
   // set/get atom string property
   int property(int propid, int idx, char *prop);
   // set/get per type string property
   int property(int propid, int *types, char **prop);
   // set/get per atom string property
   int property(int propid, char **prop);
 
   // internal data
  protected:
   void *_plugin; // pointer to plugin struct
   void *_dso;    // handle to DSO
   void *_ptr;    // pointer to plugin data handle
   void *_info;   // pointer to atomic info data
   char *_type;   // canonical plugin name
   char *_name;   // plugin formatted name
   int   _natoms; // number of atoms
   int   _mode;   // plugin mode of operation
   int   _caps;   // plugin capabilities
   int   _props;  // accumulated/available properties
 };
 
 }
 
 #endif
diff --git a/src/USER-MOLFILE/molfile_plugin.h b/src/USER-MOLFILE/molfile_plugin.h
index 94f6dc36a..7a2d7ca42 100644
--- a/src/USER-MOLFILE/molfile_plugin.h
+++ b/src/USER-MOLFILE/molfile_plugin.h
@@ -1,891 +1,890 @@
 /***************************************************************************
  *cr
  *cr            (C) Copyright 1995-2006 The Board of Trustees of the
  *cr                        University of Illinois
  *cr                         All Rights Reserved
  *cr
  ***************************************************************************/
 
 /***************************************************************************
  * RCS INFORMATION:
  *
  *      $RCSfile: molfile_plugin.h,v $
  *      $Author: johns $       $Locker:  $             $State: Exp $
  *      $Revision: 1.103 $       $Date: 2011/03/05 03:56:11 $
  *
  ***************************************************************************/
 
-/** @file 
+/** @file
  * API for C extensions to define a way to load structure, coordinate,
- * trajectory, and volumetric data files  
- */ 
+ * trajectory, and volumetric data files
+ */
 
 #ifndef MOL_FILE_PLUGIN_H
 #define MOL_FILE_PLUGIN_H
 
 #include "vmdplugin.h"
 
 #if defined(DESRES_READ_TIMESTEP2)
 /* includes needed for large integer types used for frame counts */
 #include <sys/types.h>
 typedef ssize_t molfile_ssize_t;      /**< for frame counts */
 #endif
 
 /**
  * Define a common plugin type to be used when registering the plugin.
  */
 #define MOLFILE_PLUGIN_TYPE "mol file reader"
 
 /**
  * File converter plugins use the same API  but register under a different
  * type so that regular file readers can have priority.
  */
 #define MOLFILE_CONVERTER_PLUGIN_TYPE "mol file converter"
 
 /* File plugin symbolic constants for better code readability */
 #define MOLFILE_SUCCESS           0   /**< succeeded in reading file      */
 #define MOLFILE_EOF              -1   /**< end of file                    */
 #define MOLFILE_ERROR            -1   /**< error reading/opening a file   */
 #define MOLFILE_NOSTRUCTUREDATA  -2   /**< no structure data in this file */
 
 #define MOLFILE_NUMATOMS_UNKNOWN -1   /**< unknown number of atoms       */
 #define MOLFILE_NUMATOMS_NONE     0   /**< no atoms in this file type    */
 
 /**
  * Maximum string size macro
  */
 #define MOLFILE_BUFSIZ           81   /**< maximum chars in string data  */
 #define MOLFILE_BIGBUFSIZ        4096 /**< maximum chars in long strings */
 
 #define MOLFILE_MAXWAVEPERTS     25   /**< maximum number of wavefunctions
                                        *   per timestep */
 
 
 /**
  * File level comments, origin information, and annotations.
  */
 typedef struct {
   char database[81];   /**< database of origin, if any        */
   char accession[81];  /**< database accession code, if any   */
   char date[81];       /**< date/time stamp for this data     */
   char title[81];      /**< brief title for this data         */
   int remarklen;       /**< length of remarks string          */
   char *remarks;       /**< free-form remarks about data      */
 } molfile_metadata_t;
 
 
-/* 
- * Struct for specifying atoms in a molecular structure.  The first 
- * six components are required, the rest are optional and their presence is 
+/*
+ * Struct for specifying atoms in a molecular structure.  The first
+ * six components are required, the rest are optional and their presence is
  * indicating by setting the corresponding bit in optsflag.  When omitted,
- * the application (for read_structure) or plugin (for write_structure) 
- * must be able to supply default values if the missing parameters are 
+ * the application (for read_structure) or plugin (for write_structure)
+ * must be able to supply default values if the missing parameters are
  * part of its internal data structure.
  * Note that it is not possible to specify coordinates with this structure.
- * This is intentional; all coordinate I/O is done with the read_timestep and 
- * write_timestep functions. 
+ * This is intentional; all coordinate I/O is done with the read_timestep and
+ * write_timestep functions.
  */
 
 /**
  * Per-atom attributes and information.
  */
 typedef struct {
   /* these fields absolutely must be set or initialized to empty */
   char name[16];      /**< required atom name string             */
   char type[16];      /**< required atom type string             */
   char resname[8];    /**< required residue name string          */
   int resid;          /**< required integer residue ID           */
   char segid[8];      /**< required segment name string, or ""   */
   char chain[2];      /**< required chain name, or ""            */
 
   /* rest are optional; use optflags to specify what's present   */
   char altloc[2];     /**< optional PDB alternate location code  */
   char insertion[2];  /**< optional PDB insertion code           */
   float occupancy;    /**< optional occupancy value              */
   float bfactor;      /**< optional B-factor value               */
   float mass;         /**< optional mass value                   */
   float charge;       /**< optional charge value                 */
   float radius;       /**< optional radius value                 */
   int atomicnumber;   /**< optional element atomic number        */
 #if defined(DESRES_CTNUMBER)
   int ctnumber;       /**< mae ct block, 0-based, including meta */
 #endif
 } molfile_atom_t;
 
 /*@{*/
 /** Plugin optional data field availability flag */
 #define MOLFILE_NOOPTIONS     0x0000 /**< no optional data                 */
 #define MOLFILE_INSERTION     0x0001 /**< insertion codes provided         */
 #define MOLFILE_OCCUPANCY     0x0002 /**< occupancy data provided          */
 #define MOLFILE_BFACTOR       0x0004 /**< B-factor data provided           */
 #define MOLFILE_MASS          0x0008 /**< Atomic mass provided             */
 #define MOLFILE_CHARGE        0x0010 /**< Atomic charge provided           */
 #define MOLFILE_RADIUS        0x0020 /**< Atomic VDW radius provided       */
 #define MOLFILE_ALTLOC        0x0040 /**< Multiple conformations present   */
 #define MOLFILE_ATOMICNUMBER  0x0080 /**< Atomic element number provided   */
 #define MOLFILE_BONDSSPECIAL  0x0100 /**< Only non-standard bonds provided */
 #if defined(DESRES_CTNUMBER)
 #define MOLFILE_CTNUMBER      0x0200 /**< ctnumber provided */
 #endif
 #define MOLFILE_BADOPTIONS    0xFFFFFFFF /**< Detect badly behaved plugins */
-                              
+
 /*@}*/
 
 /*@{*/
 /** Flags indicating availability of optional data fields
  *  for QM timesteps
  */
 #define MOLFILE_QMTS_NOOPTIONS     0x0000 /**< no optional data               */
 #define MOLFILE_QMTS_GRADIENT      0x0001 /**< energy gradients provided      */
 #define MOLFILE_QMTS_SCFITER       0x0002
 /*@}*/
 
 #if vmdplugin_ABIVERSION > 10
 typedef struct molfile_timestep_metadata {
   unsigned int count;                  /**< total # timesteps; -1 if unknown */
   unsigned int avg_bytes_per_timestep; /** bytes per timestep                */
   int has_velocities;                  /**< if timesteps have velocities     */
 } molfile_timestep_metadata_t;
 #endif
 
 /*
  * Per-timestep atom coordinates and periodic cell information
- */ 
+ */
 typedef struct {
   float *coords;        /**< coordinates of all atoms, arranged xyzxyzxyz   */
 #if vmdplugin_ABIVERSION > 10
   float *velocities;    /**< space for velocities of all atoms; same layout */
                         /**< NULL unless has_velocities is set              */
 #endif
 
-  /*@{*/   
+  /*@{*/
   /**
    * Unit cell specification of the form A, B, C, alpha, beta, gamma.
    * notes: A, B, C are side lengths of the unit cell
    * alpha = angle between b and c
    *  beta = angle between a and c
    * gamma = angle between a and b
-   */ 
-  float A, B, C, alpha, beta, gamma; 
-  /*@}*/   
+   */
+  float A, B, C, alpha, beta, gamma;
+  /*@}*/
 
 #if vmdplugin_ABIVERSION > 10
   double physical_time; /**< physical time point associated with this frame */
 #endif
 
 #if defined(DESRES_READ_TIMESTEP2)
   /* HACK to support generic trajectory information */
   double total_energy;
   double potential_energy;
   double kinetic_energy;
   double extended_energy;
   double force_energy;
   double total_pressure;
 #endif
 
 } molfile_timestep_t;
 
 
 /**
  * Metadata for volumetric datasets, read initially and used for subsequent
- * memory allocations and file loading.  
+ * memory allocations and file loading.
  */
 typedef struct {
   char dataname[256];   /**< name of volumetric data set                    */
   float origin[3];      /**< origin: origin of volume (x=0, y=0, z=0 corner */
 
   /*
    * x/y/z axis:
    * These the three cell sides, providing both direction and length
    * (not unit vectors) for the x, y, and z axes.  In the simplest
-   * case, these would be <size,0,0> <0,size,0> and <0,0,size) for 
+   * case, these would be <size,0,0> <0,size,0> and <0,0,size) for
    * an orthogonal cubic volume set.  For other cell shapes these
    * axes can be oriented non-orthogonally, and the parallelpiped
    * may have different side lengths, not just a cube/rhombus.
    */
-  float xaxis[3];       /**< direction (and length) for X axis              */ 
+  float xaxis[3];       /**< direction (and length) for X axis              */
   float yaxis[3];       /**< direction (and length) for Y axis              */
   float zaxis[3];       /**< direction (and length) for Z axis              */
 
   /*
-   * x/y/z size: 
+   * x/y/z size:
    * Number of grid cells along each axis.  This is _not_ the
    * physical size of the box, this is the number of voxels in each
-   * direction, independent of the shape of the volume set. 
+   * direction, independent of the shape of the volume set.
    */
   int xsize;            /**< number of grid cells along the X axis          */
   int ysize;            /**< number of grid cells along the Y axis          */
   int zsize;            /**< number of grid cells along the Z axis          */
 
   int has_color;        /**< flag indicating presence of voxel color data   */
 } molfile_volumetric_t;
 
 
 
 
 /**************************************************************
  **************************************************************
  ****                                                      ****
  ****          Data structures for QM files                ****
  ****                                                      ****
  **************************************************************
  **************************************************************/
 
 #if vmdplugin_ABIVERSION > 9
 
 
 /* macros for the convergence status of a QM calculation. */
 #define MOLFILE_QMSTATUS_UNKNOWN       -1 /* don't know yet */
 #define MOLFILE_QMSTATUS_OPT_CONV       0 /* optimization converged */
 #define MOLFILE_QMSTATUS_SCF_NOT_CONV   1 /* SCF convergence failed */
 #define MOLFILE_QMSTATUS_OPT_NOT_CONV   2 /* optimization not converged */
 #define MOLFILE_QMSTATUS_FILE_TRUNCATED 3 /* file was truncated */
 
 /* macros describing the SCF method (SCFTYP in GAMESS) */
 #define MOLFILE_SCFTYPE_UNKNOWN -1 /* no info about the method  */
 #define MOLFILE_SCFTYPE_NONE     0 /* calculation didn't make use of SCF */
 #define MOLFILE_SCFTYPE_RHF      1 /* restricted Hartree-Fock   */
 #define MOLFILE_SCFTYPE_UHF      2 /* unrestricted Hartree-Fock */
 #define MOLFILE_SCFTYPE_ROHF     3 /* restricted open-shell Hartree-Fock */
 #define MOLFILE_SCFTYPE_GVB      4 /* generalized valence bond orbitals  */
 #define MOLFILE_SCFTYPE_MCSCF    5 /* multi-configuration SCF   */
 #define MOLFILE_SCFTYPE_FF       6 /* classical force-field based sim.   */
 
 /* macros describing the type of calculation (RUNTYP in GAMESS) */
 #define MOLFILE_RUNTYPE_UNKNOWN    0  /* single point run */
 #define MOLFILE_RUNTYPE_ENERGY     1  /* single point run */
 #define MOLFILE_RUNTYPE_OPTIMIZE   2  /* geometry optimization */
 #define MOLFILE_RUNTYPE_SADPOINT   3  /* saddle point search */
 #define MOLFILE_RUNTYPE_HESSIAN    4  /* Hessian/frequency calculation */
 #define MOLFILE_RUNTYPE_SURFACE    5  /* potential surface scan */
 #define MOLFILE_RUNTYPE_GRADIENT   6  /* energy gradient calculation */
 #define MOLFILE_RUNTYPE_MEX        7  /* minimum energy crossing */
 #define MOLFILE_RUNTYPE_DYNAMICS   8  /* Any type of molecular dynamics
                                        * e.g. Born-Oppenheimer, Car-Parinello,
                                        * or classical MD */
 #define MOLFILE_RUNTYPE_PROPERTIES 9  /* Properties were calculated from a
                                        * wavefunction that was read from file */
 
 
 /**
  * Sizes of various QM-related, timestep independent data arrays
  * which must be allocated by the caller (VMD) so that the plugin
  * can fill in the arrays with data.
  */
 typedef struct {
   /* hessian data */
   int nimag;                    /**< number of imaginary modes */
   int nintcoords;               /**< number internal coordinates */
   int ncart;                    /**< number cartesian coordinates */
 
   /* orbital/basisset data */
   int num_basis_funcs;          /**< number of uncontracted basis functions in basis array */
   int num_basis_atoms;          /**< number of atoms in basis set */
   int num_shells;               /**< total number of atomic shells */
   int wavef_size;               /**< size of the wavefunction
                                  *   i.e. size of secular eq. or
                                  *   # of cartesian contracted
                                  *   gaussian basis functions */
 
   /* everything else */
   int have_sysinfo;
   int have_carthessian;         /**< hessian in cartesian coords available  */
   int have_inthessian;          /**< hessian in internal coords available  */
   int have_normalmodes;         /**< normal modes available  */
 } molfile_qm_metadata_t;
 
 
 /**
  * QM run info. Parameters that stay unchanged during a single file.
- */ 
+ */
 typedef struct {
   int nproc;             /**< number of processors used. */
-  int memory;            /**< amount of memory used in Mbyte. */ 
+  int memory;            /**< amount of memory used in Mbyte. */
   int runtype;           /**< flag indicating the calculation method. */
   int scftype;           /**< SCF type: RHF, UHF, ROHF, GVB or MCSCF wfn. */
   int status;            /**< indicates wether SCF and geometry optimization
                           *   have converged properly. */
   int num_electrons;     /**< number of electrons.    XXX: can be fractional in some DFT codes */
   int totalcharge;       /**< total charge of system. XXX: can be fractional in some DFT codes */
   int num_occupied_A;    /**< number of occupied alpha orbitals */
   int num_occupied_B;    /**< number of occupied beta orbitals */
 
   double *nuc_charge;    /**< array(natom) containing the nuclear charge of atom i */
 
   char basis_string[MOLFILE_BUFSIZ];    /**< basis name as "nice" string. */
   char runtitle[MOLFILE_BIGBUFSIZ];     /**< title of run.                */
   char geometry[MOLFILE_BUFSIZ];        /**< type of provided geometry,   XXX: remove?
                                          * e.g. UNIQUE, ZMT, CART, ...    */
   char version_string[MOLFILE_BUFSIZ];  /**< QM code version information. */
 } molfile_qm_sysinfo_t;
 
 
 /**
  * Data for QM basis set
  */
 typedef struct {
   int *num_shells_per_atom; /**< number of shells per atom */
   int *num_prim_per_shell;  /**< number of shell primitives shell */
 
   float *basis;             /**< contraction coeffients and exponents for
                              *   the basis functions in the form
                              *   {exp(1), c-coeff(1), exp(2), c-coeff(2), ...};
                              *   array size = 2*num_basis_funcs
                              *   The basis must NOT be normalized. */
   int *atomic_number;       /**< atomic numbers (chem. element) of atoms in basis set */
-  int *angular_momentum;    /**< 3 ints per wave function coefficient do describe the 
+  int *angular_momentum;    /**< 3 ints per wave function coefficient do describe the
                              *   cartesian components of the angular momentum.
-                             *   E.g. S={0 0 0}, Px={1 0 0}, Dxy={1 1 0}, or Fyyz={0 2 1}. 
+                             *   E.g. S={0 0 0}, Px={1 0 0}, Dxy={1 1 0}, or Fyyz={0 2 1}.
                              */
   int *shell_types;         /**< type for each shell in basis */
 } molfile_qm_basis_t;
 
 
 /**
  * Data from QM Hessian/normal mode runs
  *
  * A noteworthy comment from one of Axel's emails:
  * The molfile_qm_hessian_t, I'd rename to molfile_hessian_t (one
  * can do vibrational analysis without QM) and would make this a
  * completely separate entity. This could then be also used to
  * read in data from, say, principal component analysis or normal
  * mode analysis and VMD could contain code to either project a
  * trajectory on the contained eigenvectors or animate them and
  * so on. There is a bunch of possible applications...
  */
 typedef struct {
   double *carthessian;  /**< hessian matrix in cartesian coordinates (ncart)*(ncart)
                          *   as a single array of doubles (row(1), ...,row(natoms)) */
   int    *imag_modes;   /**< list(nimag) of imaginary modes */
   double *inthessian;   /**< hessian matrix in internal coordinates
                          *   (nintcoords*nintcoords) as a single array of
                          *   doubles (row(1), ...,row(nintcoords)) */
   float *wavenumbers;   /**< array(ncart) of wavenumbers of normal modes */
   float *intensities;   /**< array(ncart) of intensities of normal modes */
   float *normalmodes;   /**< matrix(ncart*ncart) of normal modes  */
 } molfile_qm_hessian_t;
 
 
 /**
  * QM related information that is timestep independent
  */
 typedef struct {
   molfile_qm_sysinfo_t run;             /* system info  */
   molfile_qm_basis_t   basis;           /* basis set info */
   molfile_qm_hessian_t hess;            /* hessian info */
 } molfile_qm_t;
 
 
 
 /**
  *  Enumeration of all of the wavefunction types that can be read
  *  from QM file reader plugins.
  *
  *  CANON    = canonical (i.e diagonalized) wavefunction
  *  GEMINAL  = GVB-ROHF geminal pairs
  *  MCSCFNAT = Multi-Configuration SCF natural orbitals
  *  MCSCFOPT = Multi-Configuration SCF optimized orbitals
  *  CINATUR  = Configuration-Interaction natural orbitals
  *  BOYS     = Boys localization
  *  RUEDEN   = Ruedenberg localization
  *  PIPEK    = Pipek-Mezey population localization
  *
  *  NBO related localizations:
  *  --------------------------
  *  NAO      = Natural Atomic Orbitals
  *  PNAO     = pre-orthogonal NAOs
  *  NBO      = Natural Bond Orbitals
  *  PNBO     = pre-orthogonal NBOs
  *  NHO      = Natural Hybrid Orbitals
  *  PNHO     = pre-orthogonal NHOs
  *  NLMO     = Natural Localized Molecular Orbitals
  *  PNLMO    = pre-orthogonal NLMOs
  *
  *  UNKNOWN  = Use this for any type not listed here
  *             You can use the string field for description
  */
 enum molfile_qm_wavefunc_type {
   MOLFILE_WAVE_CANON,    MOLFILE_WAVE_GEMINAL,
   MOLFILE_WAVE_MCSCFNAT, MOLFILE_WAVE_MCSCFOPT,
   MOLFILE_WAVE_CINATUR,
   MOLFILE_WAVE_PIPEK,  MOLFILE_WAVE_BOYS, MOLFILE_WAVE_RUEDEN,
-  MOLFILE_WAVE_NAO,    MOLFILE_WAVE_PNAO, MOLFILE_WAVE_NHO, 
-  MOLFILE_WAVE_PNHO,   MOLFILE_WAVE_NBO,  MOLFILE_WAVE_PNBO, 
-  MOLFILE_WAVE_PNLMO,  MOLFILE_WAVE_NLMO, MOLFILE_WAVE_MOAO, 
+  MOLFILE_WAVE_NAO,    MOLFILE_WAVE_PNAO, MOLFILE_WAVE_NHO,
+  MOLFILE_WAVE_PNHO,   MOLFILE_WAVE_NBO,  MOLFILE_WAVE_PNBO,
+  MOLFILE_WAVE_PNLMO,  MOLFILE_WAVE_NLMO, MOLFILE_WAVE_MOAO,
   MOLFILE_WAVE_NATO,   MOLFILE_WAVE_UNKNOWN
 };
 
 
 /**
  *  Enumeration of all of the supported QM related charge
  *  types
  */
 enum molfile_qm_charge_type {
   MOLFILE_QMCHARGE_UNKNOWN,
   MOLFILE_QMCHARGE_MULLIKEN, MOLFILE_QMCHARGE_LOWDIN,
   MOLFILE_QMCHARGE_ESP, MOLFILE_QMCHARGE_NPA
 };
 
 
 
 /**
  * Sizes of various QM-related, per-timestep data arrays
  * which must be allocated by the caller (VMD) so that the plugin
  * can fill in the arrays with data.
  */
 typedef struct molfile_qm_timestep_metadata {
   unsigned int count;                  /**< total # timesteps; -1 if unknown */
   unsigned int avg_bytes_per_timestep; /**< bytes per timestep                */
   int has_gradient;                    /**< if timestep contains gradient    */
   int num_scfiter;                     /**< # scf iterations for this ts     */
   int num_orbitals_per_wavef[MOLFILE_MAXWAVEPERTS]; /**< # orbitals for each wavefunction */
   int has_orben_per_wavef[MOLFILE_MAXWAVEPERTS]; /**< orbital energy flags */
   int has_occup_per_wavef[MOLFILE_MAXWAVEPERTS]; /**< orbital occupancy flags */
   int num_wavef ;                      /**< # wavefunctions in this ts     */
-  int wavef_size;                      /**< size of one wavefunction 
+  int wavef_size;                      /**< size of one wavefunction
                                         *   (# of gaussian basis fctns)    */
   int num_charge_sets;                 /**< # of charge values per atom */
 } molfile_qm_timestep_metadata_t;
 
 
 /**
  * QM wavefunction
  */
 typedef struct {
   int   type;               /**< MOLFILE_WAVE_CANON, MOLFILE_WAVE_MCSCFNAT, ... */
   int   spin;               /**< 1 for alpha, -1 for beta */
   int   excitation;         /**< 0 for ground state, 1,2,3,... for excited states */
   int   multiplicity;       /**< spin multiplicity of the state, zero if unknown */
   char info[MOLFILE_BUFSIZ]; /**< string for additional type info */
 
   double energy;            /**< energy of the electronic state.
                              *   i.e. HF-SCF energy, CI state energy,
                              *   MCSCF energy, etc. */
 
   float *wave_coeffs;       /**< expansion coefficients for wavefunction in the
                              *   form {orbital1(c1),orbital1(c2),.....,orbitalM(cN)} */
   float *orbital_energies;  /**< list of orbital energies for wavefunction */
   float *occupancies;       /**< orbital occupancies */
   int   *orbital_ids;       /**< orbital ID numbers; If NULL then VMD will
                              *   assume 1,2,3,...num_orbs.     */
 } molfile_qm_wavefunction_t;
 
 
 /**
  * QM per trajectory timestep info
  * Note that each timestep can contain multiple wavefunctions.
  */
 typedef struct {
   molfile_qm_wavefunction_t *wave; /**< array of wavefunction objects */
   float  *gradient;         /**< force on each atom (=gradient of energy) */
 
   double *scfenergies;      /**< energies from the SCF cycles */
   double *charges;          /**< per-atom charges */
   int    *charge_types;     /**< type of each charge set */
 } molfile_qm_timestep_t;
 
 
 #endif
 
 /**************************************************************
  **************************************************************/
 
 
 
 
 /**
  *  Enumeration of all of the supported graphics objects that can be read
  *  from graphics file reader plugins.
  */
 enum molfile_graphics_type {
-  MOLFILE_POINT,  MOLFILE_TRIANGLE, MOLFILE_TRINORM, MOLFILE_NORMS, 
-  MOLFILE_LINE,   MOLFILE_CYLINDER, MOLFILE_CAPCYL,  MOLFILE_CONE,    
+  MOLFILE_POINT,  MOLFILE_TRIANGLE, MOLFILE_TRINORM, MOLFILE_NORMS,
+  MOLFILE_LINE,   MOLFILE_CYLINDER, MOLFILE_CAPCYL,  MOLFILE_CONE,
   MOLFILE_SPHERE, MOLFILE_TEXT,     MOLFILE_COLOR,   MOLFILE_TRICOLOR
 };
 
 /**
  *  Individual graphics object/element data
- */ 
+ */
 typedef struct {
   int type;             /* One of molfile_graphics_type */
   int style;            /* A general style parameter    */
   float size;           /* A general size parameter     */
   float data[9];        /* All data for the element     */
 } molfile_graphics_t;
 
 
 /*
  * Types for raw graphics elements stored in files.  Data for each type
  * should be stored by the plugin as follows:
 
 type        data                                     style       size
 ----        ----                                     -----       ----
 point       x, y, z                                              pixel size
-triangle    x1,y1,z1,x2,y2,z2,x3,y3,z3                 
-trinorm     x1,y1,z1,x2,y2,z2,x3,y3,z3                 
+triangle    x1,y1,z1,x2,y2,z2,x3,y3,z3
+trinorm     x1,y1,z1,x2,y2,z2,x3,y3,z3
             the next array element must be NORMS
-tricolor    x1,y1,z1,x2,y2,z2,x3,y3,z3                 
+tricolor    x1,y1,z1,x2,y2,z2,x3,y3,z3
             the next array elements must be NORMS
             the following element must be COLOR, with three RGB triples
-norms       x1,y1,z1,x2,y2,z2,x3,y3,z3                 
+norms       x1,y1,z1,x2,y2,z2,x3,y3,z3
 line        x1,y1,z1,x2,y2,z2                        0=solid     pixel width
                                                      1=stippled
 cylinder    x1,y1,z1,x2,y2,z2                        resolution  radius
 capcyl      x1,y1,z1,x2,y2,z2                        resolution  radius
 sphere      x1,y1,z1                                 resolution  radius
 text        x, y, z, up to 24 bytes of text                      pixel size
 color       r, g, b
 */
 
 
 /**
  * Main file reader API.  Any function in this struct may be NULL
  * if not implemented by the plugin; the application checks this to determine
- * what functionality is present in the plugin. 
- */ 
+ * what functionality is present in the plugin.
+ */
 typedef struct {
   /**
-   * Required header 
+   * Required header
    */
   vmdplugin_HEAD
 
   /**
-   * Filename extension for this file type.  May be NULL if no filename 
+   * Filename extension for this file type.  May be NULL if no filename
    * extension exists and/or is known.  For file types that match several
    * common extensions, list them in a comma separated list such as:
    *  "pdb,ent,foo,bar,baz,ban"
    * The comma separated list will be expanded when filename extension matching
    * is performed.  If multiple plugins solicit the same filename extensions,
-   * the one that lists the extension earliest in its list is selected. In the 
+   * the one that lists the extension earliest in its list is selected. In the
    * case of a "tie", the first one tried/checked "wins".
    */
   const char *filename_extension;
 
   /**
    * Try to open the file for reading.  Return an opaque handle, or NULL on
-   * failure. Set the number of atoms; if the number of atoms cannot be 
-   * determined, set natoms to MOLFILE_NUMATOMS_UNKNOWN. 
+   * failure. Set the number of atoms; if the number of atoms cannot be
+   * determined, set natoms to MOLFILE_NUMATOMS_UNKNOWN.
    * Filetype should be the name under which this plugin was registered;
    * this is provided so that plugins can provide the same function pointer
    * to handle multiple file types.
    */
-  void *(* open_file_read)(const char *filepath, const char *filetype, 
+  void *(* open_file_read)(const char *filepath, const char *filetype,
       int *natoms);
-  
+
   /**
    * Read molecular structure from the given file handle.  atoms is allocated
    * by the caller and points to space for natoms.
-   * On success, place atom information in the passed-in pointer.  
+   * On success, place atom information in the passed-in pointer.
    * optflags specifies which optional fields in the atoms will be set by
    * the plugin.
    */
   int (*read_structure)(void *, int *optflags, molfile_atom_t *atoms);
 
   /**
    * Read bond information for the molecule.  On success the arrays from
    * and to should point to the (one-based) indices of bonded atoms.
    * Each unique bond should be specified only once, so file formats that list
    * bonds twice will need post-processing before the results are returned to
    * the caller.
-   * If the plugin provides bond information, but the file loaded doesn't 
+   * If the plugin provides bond information, but the file loaded doesn't
    * actually contain any bond info, the nbonds parameter should be
    * set to 0 and from/to should be set to NULL to indicate that no bond
    * information was actually present, and automatic bond search should be
-   * performed.  
+   * performed.
    *
    * If the plugin provides bond order information, the bondorder array
    * will contain the bond order for each from/to pair.  If not, the bondorder
-   * pointer should be set to NULL, in which case the caller will provide a 
+   * pointer should be set to NULL, in which case the caller will provide a
    * default bond order value of 1.0.
    *
    * If the plugin provides bond type information, the bondtype array
    * will contain the bond type index for each from/to pair. These numbers
    * are consecutive integers starting from 0.
    * the bondtypenames list, contains the corresponding names, if available,
    * as a NULL string terminated list. nbondtypes is provided for convenience
    * and consistency checking.
    *
    * These arrays must be freed by the plugin in the close_file_read function.
-   * This function can be called only after read_structure().  
-   * Return MOLFILE_SUCCESS if no errors occur. 
+   * This function can be called only after read_structure().
+   * Return MOLFILE_SUCCESS if no errors occur.
    */
 #if vmdplugin_ABIVERSION > 14
-  int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder, 
+  int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder,
                     int **bondtype, int *nbondtypes, char ***bondtypename);
 #else
   int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder);
 #endif
 
   /**
-   * XXX this function will be augmented and possibly superceded by a 
+   * XXX this function will be augmented and possibly superceded by a
    *     new QM-capable version named read_timestep(), when finished.
    *
-   * Read the next timestep from the file.  Return MOLFILE_SUCCESS, or 
-   * MOLFILE_EOF on EOF.  If the molfile_timestep_t argument is NULL, then 
-   * the frame should be skipped.  Otherwise, the application must prepare 
-   * molfile_timestep_t by allocating space in coords for the corresponding 
-   * number of coordinates.  
-   * The natoms parameter exists because some coordinate file formats 
-   * (like CRD) cannot determine for themselves how many atoms are in a 
+   * Read the next timestep from the file.  Return MOLFILE_SUCCESS, or
+   * MOLFILE_EOF on EOF.  If the molfile_timestep_t argument is NULL, then
+   * the frame should be skipped.  Otherwise, the application must prepare
+   * molfile_timestep_t by allocating space in coords for the corresponding
+   * number of coordinates.
+   * The natoms parameter exists because some coordinate file formats
+   * (like CRD) cannot determine for themselves how many atoms are in a
    * timestep; the app must therefore obtain this information elsewhere
    * and provide it to the plugin.
    */
   int (* read_next_timestep)(void *, int natoms, molfile_timestep_t *);
 
   /**
    * Close the file and release all data.  The handle cannot be reused.
    */
   void (* close_file_read)(void *);
-   
+
   /**
    * Open a coordinate file for writing using the given header information.
    * Return an opaque handle, or NULL on failure.  The application must
-   * specify the number of atoms to be written. 
+   * specify the number of atoms to be written.
    * filetype should be the name under which this plugin was registered.
    */
-  void *(* open_file_write)(const char *filepath, const char *filetype, 
+  void *(* open_file_write)(const char *filepath, const char *filetype,
       int natoms);
-  
+
   /**
    * Write structure information.  Return success.
    */
   int (* write_structure)(void *, int optflags, const molfile_atom_t *atoms);
 
   /**
    * Write a timestep to the coordinate file.  Return MOLFILE_SUCCESS if no
-   * errors occur.  If the file contains structure information in each 
-   * timestep (like a multi-entry PDB), it will have to cache the information 
+   * errors occur.  If the file contains structure information in each
+   * timestep (like a multi-entry PDB), it will have to cache the information
    * from the initial calls from write_structure.
    */
   int (* write_timestep)(void *, const molfile_timestep_t *);
-  
+
   /**
    * Close the file and release all data.  The handle cannot be reused.
    */
   void (* close_file_write)(void *);
 
   /**
    * Retrieve metadata pertaining to volumetric datasets in this file.
    * Set nsets to the number of volumetric data sets, and set *metadata
    * to point to an array of molfile_volumetric_t.  The array is owned by
    * the plugin and should be freed by close_file_read().  The application
    * may call this function any number of times.
    */
-  int (* read_volumetric_metadata)(void *, int *nsets, 
+  int (* read_volumetric_metadata)(void *, int *nsets,
         molfile_volumetric_t **metadata);
 
-  /** 
-   * Read the specified volumetric data set into the space pointed to by 
-   * datablock.  The set is specified with a zero-based index.  The space 
+  /**
+   * Read the specified volumetric data set into the space pointed to by
+   * datablock.  The set is specified with a zero-based index.  The space
    * allocated for the datablock must be equal to
-   * xsize * ysize * zsize.  No space will be allocated for colorblock 
+   * xsize * ysize * zsize.  No space will be allocated for colorblock
    * unless has_color is nonzero; in that case, colorblock should be
    * filled in with three RGB floats per datapoint.
    */
-  int (* read_volumetric_data)(void *, int set, float *datablock, 
+  int (* read_volumetric_data)(void *, int set, float *datablock,
         float *colorblock);
 
   /**
    * Read raw graphics data stored in this file.   Return the number of data
-   * elements and the data itself as an array of molfile_graphics_t in the 
-   * pointer provided by the application.  The plugin is responsible for 
+   * elements and the data itself as an array of molfile_graphics_t in the
+   * pointer provided by the application.  The plugin is responsible for
    * freeing the data when the file is closed.
    */
   int (* read_rawgraphics)(void *, int *nelem, const molfile_graphics_t **data);
 
   /**
    * Read molecule metadata such as what database (if any) this file/data
    * came from, what the accession code for the database is, textual remarks
    * and other notes pertaining to the contained structure/trajectory/volume
    * and anything else that's informative at the whole file level.
-   */ 
+   */
   int (* read_molecule_metadata)(void *, molfile_metadata_t **metadata);
-  
+
   /**
    * Write bond information for the molecule.  The arrays from
    * and to point to the (one-based) indices of bonded atoms.
-   * Each unique bond will be specified only once by the caller. 
-   * File formats that list bonds twice will need to emit both the 
+   * Each unique bond will be specified only once by the caller.
+   * File formats that list bonds twice will need to emit both the
    * from/to and to/from versions of each.
-   * This function must be called before write_structure().  
+   * This function must be called before write_structure().
    *
    * Like the read_bonds() routine, the bondorder pointer is set to NULL
-   * if the caller doesn't have such information, in which case the 
+   * if the caller doesn't have such information, in which case the
    * plugin should assume a bond order of 1.0 if the file format requires
    * bond order information.
    *
    * Support for bond types follows the bondorder rules. bondtype is
    * an integer array of the size nbonds that contains the bond type
    * index (consecutive integers starting from 0) and bondtypenames
    * contain the corresponding strings, in case the naming/numbering
    * scheme is different from the index numbers.
    * if the pointers are set to NULL, then this information is not available.
    * bondtypenames can only be used of bondtypes is also given.
-   * Return MOLFILE_SUCCESS if no errors occur. 
+   * Return MOLFILE_SUCCESS if no errors occur.
    */
 #if vmdplugin_ABIVERSION > 14
-  int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder, 
+  int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder,
                      int *bondtype, int nbondtypes, char **bondtypename);
 #else
   int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder);
 #endif
 
 #if vmdplugin_ABIVERSION > 9
   /**
-   * Write the specified volumetric data set into the space pointed to by 
+   * Write the specified volumetric data set into the space pointed to by
    * datablock.  The * allocated for the datablock must be equal to
-   * xsize * ysize * zsize.  No space will be allocated for colorblock 
+   * xsize * ysize * zsize.  No space will be allocated for colorblock
    * unless has_color is nonzero; in that case, colorblock should be
    * filled in with three RGB floats per datapoint.
    */
   int (* write_volumetric_data)(void *, molfile_volumetric_t *metadata,
                                 float *datablock, float *colorblock);
 
 #if vmdplugin_ABIVERSION > 15
-  /** 
+  /**
    * Read in Angles, Dihedrals, Impropers, and Cross Terms and optionally types.
-   * (Cross terms pertain to the CHARMM/NAMD CMAP feature) 
+   * (Cross terms pertain to the CHARMM/NAMD CMAP feature)
    */
   int (* read_angles)(void *handle, int *numangles, int **angles, int **angletypes,
                       int *numangletypes, char ***angletypenames, int *numdihedrals,
                       int **dihedrals, int **dihedraltypes, int *numdihedraltypes,
-                      char ***dihedraltypenames, int *numimpropers, int **impropers,        
+                      char ***dihedraltypenames, int *numimpropers, int **impropers,
                       int **impropertypes, int *numimpropertypes, char ***impropertypenames,
                       int *numcterms, int **cterms, int *ctermcols, int *ctermrows);
 
-  /** 
+  /**
    * Write out Angles, Dihedrals, Impropers, and Cross Terms
-   * (Cross terms pertain to the CHARMM/NAMD CMAP feature) 
+   * (Cross terms pertain to the CHARMM/NAMD CMAP feature)
    */
   int (* write_angles)(void *handle, int numangles, const int *angles, const int *angletypes,
                        int numangletypes, const char **angletypenames, int numdihedrals,
                        const int *dihedrals, const int *dihedraltypes, int numdihedraltypes,
-                       const char **dihedraltypenames, int numimpropers, 
+                       const char **dihedraltypenames, int numimpropers,
                        const int *impropers, const int *impropertypes, int numimpropertypes,
-                       const char **impropertypenames, int numcterms,  const int *cterms, 
+                       const char **impropertypenames, int numcterms,  const int *cterms,
                        int ctermcols, int ctermrows);
 #else
-  /** 
+  /**
    * Read in Angles, Dihedrals, Impropers, and Cross Terms
    * Forces are in Kcal/mol
    * (Cross terms pertain to the CHARMM/NAMD CMAP feature, forces are given
    *  as a 2-D matrix)
    */
   int (* read_angles)(void *,
                 int *numangles,    int **angles,    double **angleforces,
                 int *numdihedrals, int **dihedrals, double **dihedralforces,
                 int *numimpropers, int **impropers, double **improperforces,
-                int *numcterms,    int **cterms, 
+                int *numcterms,    int **cterms,
                 int *ctermcols,    int *ctermrows,  double **ctermforces);
 
-  /** 
+  /**
    * Write out Angles, Dihedrals, Impropers, and Cross Terms
    * Forces are in Kcal/mol
    * (Cross terms pertain to the CHARMM/NAMD CMAP feature, forces are given
    *  as a 2-D matrix)
    */
   int (* write_angles)(void *,
         int numangles,    const int *angles,    const double *angleforces,
         int numdihedrals, const int *dihedrals, const double *dihedralforces,
         int numimpropers, const int *impropers, const double *improperforces,
-        int numcterms,   const int *cterms,    
+        int numcterms,   const int *cterms,
         int ctermcols, int ctermrows, const double *ctermforces);
 #endif
 
 
   /**
    * Retrieve metadata pertaining to timestep independent
    * QM datasets in this file.
    *
    * The metadata are the sizes of the QM related data structure
-   * arrays that will be populated by the plugin when 
+   * arrays that will be populated by the plugin when
    * read_qm_rundata() is called. Since the allocation of these
    * arrays is done by VMD rather than the plugin, VMD needs to
    * know the sizes beforehand. Consequently read_qm_metadata()
    * has to be called before read_qm_rundata().
    */
   int (* read_qm_metadata)(void *, molfile_qm_metadata_t *metadata);
 
 
   /**
    * Read timestep independent QM data.
    *
    * Typical data that are defined only once per trajectory are
-   * general info about the calculation (such as the used method), 
+   * general info about the calculation (such as the used method),
    * the basis set and normal modes.
    * The data structures to be populated must have been allocated
    * before by VMD according to sizes obtained through
    * read_qm_metadata().
    */
   int (* read_qm_rundata)(void *, molfile_qm_t *qmdata);
 
 
   /**
-   * Read the next timestep from the file.  Return MOLFILE_SUCCESS, or 
+   * Read the next timestep from the file.  Return MOLFILE_SUCCESS, or
    * MOLFILE_EOF on EOF.  If the molfile_timestep_t or molfile_qm_metadata_t
-   * arguments are NULL, then the coordinate or qm data should be skipped.  
-   * Otherwise, the application must prepare molfile_timestep_t and 
-   * molfile_qm_timestep_t by allocating space for the corresponding 
+   * arguments are NULL, then the coordinate or qm data should be skipped.
+   * Otherwise, the application must prepare molfile_timestep_t and
+   * molfile_qm_timestep_t by allocating space for the corresponding
    * number of coordinates, orbital wavefunction coefficients, etc.
-   * Since it is common for users to want to load only the final timestep 
+   * Since it is common for users to want to load only the final timestep
    * data from a QM run, the application may provide any combination of
-   * valid, or NULL pointers for the molfile_timestep_t and 
+   * valid, or NULL pointers for the molfile_timestep_t and
    * molfile_qm_timestep_t parameters, depending on what information the
    * user is interested in.
-   * The natoms and qm metadata parameters exist because some file formats 
-   * cannot determine for themselves how many atoms etc are in a 
+   * The natoms and qm metadata parameters exist because some file formats
+   * cannot determine for themselves how many atoms etc are in a
    * timestep; the app must therefore obtain this information elsewhere
    * and provide it to the plugin.
    */
   int (* read_timestep)(void *, int natoms, molfile_timestep_t *,
                         molfile_qm_metadata_t *, molfile_qm_timestep_t *);
 #endif
 
 #if vmdplugin_ABIVERSION > 10
   int (* read_timestep_metadata)(void *, molfile_timestep_metadata_t *);
 #endif
 #if vmdplugin_ABIVERSION > 11
   int (* read_qm_timestep_metadata)(void *, molfile_qm_timestep_metadata_t *);
 #endif
 
 #if defined(DESRES_READ_TIMESTEP2)
   /**
     * Read a specified timestep!
     */
   int (* read_timestep2)(void *, molfile_ssize_t index, molfile_timestep_t *);
 
   /**
     * write up to count times beginning at index start into the given
     * space.  Return the number read, or -1 on error.
     */
   molfile_ssize_t (* read_times)( void *,
                                   molfile_ssize_t start,
                                   molfile_ssize_t count,
                                   double * times );
 #endif
 
 #if vmdplugin_ABIVERSION > 13
   /**
    *  Console output, READ-ONLY function pointer.
    *  Function pointer that plugins can use for printing to the host
    *  application's text console.  This provides a clean way for plugins
    *  to send message strings back to the calling application, giving the
    *  caller the ability to prioritize, buffer, and redirect console messages
    *  to an appropriate output channel, window, etc.  This enables the use of
    *  graphical consoles like TkCon without losing console output from plugins.
    *  If the function pointer is NULL, no console output service is provided
    *  by the calling application, and the output should default to stdout
    *  stream.  If the function pointer is non-NULL, all output will be
    *  subsequently dealt with by the calling application.
    *
    *  XXX this should really be put into a separate block of
    *      application-provided read-only function pointers for any
    *      application-provided services
    */
   int (* cons_fputs)(const int, const char*);
 #endif
 
 } molfile_plugin_t;
 
 #endif
-
diff --git a/src/USER-MOLFILE/reader_molfile.cpp b/src/USER-MOLFILE/reader_molfile.cpp
index 8f4522db6..a1156efc6 100644
--- a/src/USER-MOLFILE/reader_molfile.cpp
+++ b/src/USER-MOLFILE/reader_molfile.cpp
@@ -1,362 +1,362 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #include "string.h"
 #include "stdlib.h"
 #include "math.h"
 #include "reader_molfile.h"
 #include "atom.h"
 #include "comm.h"
 #include "memory.h"
 #include "error.h"
 
 #include "molfile_interface.h"
 #include "math_const.h"
 
 using namespace LAMMPS_NS;
 typedef MolfileInterface MFI;
 using namespace MathConst;
 
 enum{ID,TYPE,X,Y,Z,VX,VY,VZ};
 #define SMALL 1.0e-6
 
 // true if the difference between two floats is "small".
 // cannot use fabsf() since it is not fully portable.
-static bool is_smalldiff(const float &val1, const float &val2) 
+static bool is_smalldiff(const float &val1, const float &val2)
 {
   return (fabs(static_cast<double>(val1-val2)) < SMALL);
 }
 
 /* ---------------------------------------------------------------------- */
 
 ReaderMolfile::ReaderMolfile(LAMMPS *lmp) : Reader(lmp)
 {
   mf = NULL;
   coords = NULL;
   vels = NULL;
   types = NULL;
   fieldindex = NULL;
   nstep = 0;
   needvels = 0;
   me = comm->me;
 }
 
 /* ---------------------------------------------------------------------- */
 
 ReaderMolfile::~ReaderMolfile()
 {
   if (me == 0) {
     memory->destroy(fieldindex);
 
     memory->destroy(types);
     memory->destroy(coords);
     memory->destroy(vels);
     if (mf) delete mf;
   }
 }
 
 /* ----------------------------------------------------------------------
    pass on settings to find and load the proper plugin
    called by all processors.
 ------------------------------------------------------------------------- */
 void ReaderMolfile::settings(int narg, char **arg)
 {
   if (narg < 1) error->all(FLERR,"Illegal molfile reader command");
 
   if (me == 0) {
     mf = new MolfileInterface(arg[0],MFI::M_READ);
 
     const char *path = (const char *) ".";
     if (narg > 1)
       path=arg[1];
 
     if (mf->find_plugin(path)!= MFI::E_MATCH)
       error->one(FLERR,"No suitable molfile plugin found");
 
     if (screen)
       fprintf(screen,"Dump reader uses molfile plugin: %s\n",
               mf->get_plugin_name());
 
     if (logfile)
       fprintf(logfile,"Dump reader uses molfile plugin: %s\n",
               mf->get_plugin_name());
   }
 }
 
 /* ----------------------------------------------------------------------
    try to open given file through plugin interface
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 void ReaderMolfile::open_file(const char *file)
 {
   int rv;
   char str[1024];
 
   // close open file, if needed.
   if (mf->is_open()) mf->close();
 
   rv = mf->open(file,&natoms);
 
   if (rv != MFI::E_NONE) {
     sprintf(str,"Cannot open file %s",file);
     error->one(FLERR,str);
   }
 
   if (natoms < 1) {
     sprintf(str,"No atoms in file %s",file);
     error->one(FLERR,str);
   }
 
   memory->create(types,natoms,"reader:types");
   memory->create(coords,3*natoms,"reader:coords");
   if (mf->has_vels())
     memory->create(vels,3*natoms,"reader:vels");
 
   // initialize system properties, if available
   if (mf->has_props()) {
     mf->structure();
     mf->property(MFI::P_TYPE,types);
 
   } else {
     for (int i=0; i < natoms; ++i)
       types[i] = 1;
   }
 }
 
 /* ----------------------------------------------------------------------
    close current file
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 void ReaderMolfile::close_file()
 {
   mf->close();
 }
 
 /* ----------------------------------------------------------------------
    read and return time stamp from dump file
    if first read reaches end-of-file, return 1 so caller can open next file
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 int ReaderMolfile::read_time(bigint &ntimestep)
 {
   int rv;
 
   // try to read in the time step (coordinates, velocities and cell only)
   rv = mf->timestep(coords, vels, cell, NULL);
   if (rv != 0) return 1;
 
   // we fake time step numbers.
   ntimestep = nstep;
   nstep++;
 
   return 0;
 }
 
 /* ----------------------------------------------------------------------
    skip snapshot from timestamp onward
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 void ReaderMolfile::skip()
 {
   // since we can only signal EOF to the caller in ::read_time(), we
   // have to read the entire timestep always there and this is a NOP.
   ;
 }
 
 /* ----------------------------------------------------------------------
    read remaining header info:
      return natoms
      box bounds, triclinic (inferred), fieldflag (1 if any fields not found),
      xyz flag = UNSET (not a requested field), SCALED, UNSCALED
    if fieldflag set:
      match Nfield fields to per-atom column labels
      allocate and set fieldindex = which column each field maps to
      fieldtype = X,VX,IZ etc
      fieldlabel = user-specified label or NULL if use fieldtype default
    xyz flag = scaledflag if has fieldlabel name, else set by x,xs,xu,xsu
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
                                   int fieldinfo, int nfield,
                                   int *fieldtype, char **fieldlabel,
                                   int scaledflag, int &fieldflag,
                                   int &xflag, int &yflag, int &zflag)
 {
   nid = 0;
 
   // signal that we have no box info at all so far.
   triclinic = -1;
 
   // heuristics to determine if we have boxinfo (first if)
   // and whether we have an orthogonal box (second if)
   if (!is_smalldiff(cell[0]*cell[1]*cell[2], 0.0f)) {
     if (is_smalldiff(cell[3],90.0f) && is_smalldiff(cell[4],90.0f) &&
         is_smalldiff(cell[5],90.0f)) {
       triclinic = 0;
       // we have no information about the absolute location
       // of the box, so we assume that the origin is in the middle.
       // also we cannot tell periodicity. we assume, yes.
       box[0][0] = -0.5*static_cast<double>(cell[0]);
       box[0][1] =  0.5*static_cast<double>(cell[0]);
       box[0][2] =  0.0;
       box[1][0] = -0.5*static_cast<double>(cell[1]);
       box[1][1] =  0.5*static_cast<double>(cell[1]);
       box[1][2] =  0.0;
       box[2][0] = -0.5*static_cast<double>(cell[2]);
       box[2][1] =  0.5*static_cast<double>(cell[2]);
       box[2][2] =  0.0;
     } else {
 
       triclinic = 1;
 
       const double la = static_cast<double>(cell[0]);
       const double lb = static_cast<double>(cell[1]);
       const double lc = static_cast<double>(cell[2]);
       const double alpha = static_cast<double>(cell[3]);
       const double beta  = static_cast<double>(cell[4]);
       const double gamma = static_cast<double>(cell[5]);
-      
+
       const double lx = la;
       const double xy = lb * cos(gamma/90.0*MY_PI2);
       const double xz = lc * cos(beta/90.0*MY_PI2);
       const double ly = sqrt(lb*lb - xy*xy);
       const double yz = (fabs(ly) > SMALL) ?
         (lb*lc*cos(alpha/90.0*MY_PI2) - xy*xz) / ly : 0.0;
       const double lz = sqrt(lc*lc - xz*xz - yz*yz);
 
       /* go from box length to boundary */
       double xbnd;
 
       xbnd = 0.0;
       xbnd = (xy < xbnd) ? xy : xbnd;
       xbnd = (xz < xbnd) ? xz : xbnd;
       xbnd = (xy+xz < xbnd) ? (xy + xz) : xbnd;
       box[0][0] = -0.5*lx + xbnd;
 
       xbnd = 0.0;
       xbnd = (xy > xbnd) ? xy : xbnd;
       xbnd = (xz > xbnd) ? xz : xbnd;
       xbnd = (xy+xz > xbnd) ? (xy + xz) : xbnd;
       box[0][1] =  0.5*lx+xbnd;
       box[0][2] =  xy;
 
       xbnd = 0.0;
       xbnd = (yz < xbnd) ? yz : xbnd;
       box[1][0] = -0.5*ly+xbnd;
 
       xbnd = 0.0;
       xbnd = (yz > xbnd) ? yz : xbnd;
       box[1][1] =  0.5*ly+xbnd;
       box[1][2] =  xz;
 
       box[2][0] = -0.5*lz;
       box[2][1] =  0.5*lz;
       box[2][2] =  yz;
     }
   }
 
   // if no field info requested, just return
   if (!fieldinfo) return natoms;
 
   memory->create(fieldindex,nfield,"read_dump:fieldindex");
 
-  // we know nothing about the scaling style of coordinates, 
+  // we know nothing about the scaling style of coordinates,
   // so the caller has to set the proper flag.
   xflag = scaledflag;
   yflag = scaledflag;
   zflag = scaledflag;
 
   // copy fieldtype list for supported fields
   fieldflag = 0;
   needvels = 0;
   for (int i = 0; i < nfield; i++) {
     if ( (fieldtype[i] == X) ||
          (fieldtype[i] == Y) ||
          (fieldtype[i] == Z) ||
          (fieldtype[i] == ID) ||
          (fieldtype[i] == TYPE) ) {
       fieldindex[i] = fieldtype[i];
     } else if ( (fieldtype[i] == VX) ||
                 (fieldtype[i] == VY) ||
                 (fieldtype[i] == VZ) ) {
       fieldindex[i] = fieldtype[i];
       needvels = 1;
     } else {
       fieldflag = 1;
     }
   }
 
   if ((needvels > 0) && (!mf->has_vels()))
     error->one(FLERR,"Molfile plugin does not support reading velocities");
 
   return natoms;
 }
 
 /* ----------------------------------------------------------------------
    read N atom lines from dump file
    stores appropriate values in fields array
    return 0 if success, 1 if error
    only called by proc 0
 ------------------------------------------------------------------------- */
 
 void ReaderMolfile::read_atoms(int n, int nfield, double **fields)
 {
   int i,m,mytype;
   char buf[16];
 
   for (i = 0; i < n; i++) {
     ++nid;
 
     if (mf->property(MFI::P_TYPE,nid-1,buf) != MFI::P_NONE) {
       mytype = atoi(buf);
     } else mytype = 0;
 
     for (m = 0; m < nfield; m++) {
       switch (fieldindex[m]) {
       case X:
         fields[i][m] = static_cast<double>(coords[3*nid-3]);
         break;
       case Y:
         fields[i][m] = static_cast<double>(coords[3*nid-2]);
         break;
       case Z:
         fields[i][m] = static_cast<double>(coords[3*nid-1]);
         break;
       case VX:
         fields[i][m] = static_cast<double>(vels[3*nid-3]);
         break;
       case VY:
         fields[i][m] = static_cast<double>(vels[3*nid-2]);
         break;
       case VZ:
         fields[i][m] = static_cast<double>(vels[3*nid-1]);
         break;
       case ID:
         fields[i][m] = nid;
         break;
       case TYPE:
         fields[i][m] = mytype;
         break;
       }
     }
   }
 }
diff --git a/src/USER-MOLFILE/vmdplugin.h b/src/USER-MOLFILE/vmdplugin.h
index f58a5e435..37299408f 100644
--- a/src/USER-MOLFILE/vmdplugin.h
+++ b/src/USER-MOLFILE/vmdplugin.h
@@ -1,191 +1,191 @@
 /***************************************************************************
  *cr
  *cr            (C) Copyright 1995-2006 The Board of Trustees of the
  *cr                        University of Illinois
  *cr                         All Rights Reserved
  *cr
  ***************************************************************************/
 
 /***************************************************************************
  * RCS INFORMATION:
  *
  *      $RCSfile: vmdplugin.h,v $
  *      $Author: johns $       $Locker:  $             $State: Exp $
  *      $Revision: 1.32 $       $Date: 2009/02/24 05:12:35 $
  *
  ***************************************************************************/
 
 /** @file
  * This header must be included by every VMD plugin library.  It defines the
- * API for every plugin so that VMD can organize the plugins it finds.  
+ * API for every plugin so that VMD can organize the plugins it finds.
  */
 
 #ifndef VMD_PLUGIN_H
 #define VMD_PLUGIN_H
 
 
-/* 
+/*
  * Preprocessor tricks to make it easier for us to redefine the names of
  * functions when building static plugins.
  */
 #if !defined(VMDPLUGIN)
-/** 
-  * macro defining VMDPLUGIN if it hasn't already been set to the name of 
+/**
+  * macro defining VMDPLUGIN if it hasn't already been set to the name of
   * a static plugin that is being compiled.  This is the catch-all case.
   */
 #define VMDPLUGIN vmdplugin
 #endif
 /** concatenation macro, joins args x and y together as a single string */
 #define xcat(x, y) cat(x, y)
 /** concatenation macro, joins args x and y together as a single string */
-#define cat(x, y) x ## y 
+#define cat(x, y) x ## y
 
 /*
- *  macros to correctly define plugin function names depending on whether 
- *  the plugin is being compiled for static linkage or dynamic loading. 
+ *  macros to correctly define plugin function names depending on whether
+ *  the plugin is being compiled for static linkage or dynamic loading.
  *  When compiled for static linkage, each plugin needs to have unique
  *  function names for all of its entry points.  When compiled for dynamic
  *  loading, the plugins must name their entry points consistently so that
  *  the plugin loading mechanism can find the register, register_tcl, init,
  *  and fini routines via dlopen() or similar operating system interfaces.
  */
 /*@{*/
 /** Macro names entry points correctly for static linkage or dynamic loading */
 #define VMDPLUGIN_register     xcat(VMDPLUGIN, _register)
 #define VMDPLUGIN_register_tcl xcat(VMDPLUGIN, _register_tcl)
 #define VMDPLUGIN_init         xcat(VMDPLUGIN, _init)
 #define VMDPLUGIN_fini         xcat(VMDPLUGIN, _fini)
 /*@}*/
 
 
 /** "WIN32" is defined on both WIN32 and WIN64 platforms... */
-#if (defined(WIN32)) 
+#if (defined(WIN32))
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 #if !defined(STATIC_PLUGIN)
 #if defined(VMDPLUGIN_EXPORTS)
-/** 
+/**
  *  Only define DllMain for plugins, not in VMD or in statically linked plugins
  *  VMDPLUGIN_EXPORTS is only defined when compiling dynamically loaded plugins
  */
 BOOL APIENTRY DllMain( HANDLE hModule,
                        DWORD ul_reason_for_call,
                        LPVOID lpReserved
                      )
 {
   return TRUE;
 }
 
 #define VMDPLUGIN_API __declspec(dllexport)
 #else
 #define VMDPLUGIN_API __declspec(dllimport)
 #endif /* VMDPLUGIN_EXPORTS */
 #else  /* ! STATIC_PLUGIN */
 #define VMDPLUGIN_API
 #endif /* ! STATIC_PLUGIN */
 #else
 /** If we're not compiling on Windows, then this macro is defined empty */
-#define VMDPLUGIN_API 
+#define VMDPLUGIN_API
 #endif
 
 /** define plugin linkage correctly for both C and C++ based plugins */
 #ifdef __cplusplus
 #define VMDPLUGIN_EXTERN extern "C" VMDPLUGIN_API
 #else
 #define VMDPLUGIN_EXTERN extern VMDPLUGIN_API
 #endif  /* __cplusplus */
 
-/* 
- * Plugin API functions start here 
+/*
+ * Plugin API functions start here
  */
 
 
-/** 
- * Init routine: called the first time the library is loaded by the 
+/**
+ * Init routine: called the first time the library is loaded by the
  * application and before any other API functions are referenced.
  * Return 0 on success.
  */
 VMDPLUGIN_EXTERN int VMDPLUGIN_init(void);
 
 /**
  * Macro for creating a struct header used in all plugin structures.
- * 
- * This header should be placed at the top of every plugin API definition 
+ *
+ * This header should be placed at the top of every plugin API definition
  * so that it can be treated as a subtype of the base plugin type.
  *
  * abiversion: Defines the ABI for the base plugin type (not for other plugins)
  * type: A string descriptor of the plugin type.
  * name: A name for the plugin.
  * author: A string identifier, possibly including newlines.
- * Major and minor version.  
+ * Major and minor version.
  * is_reentrant: Whether this library can be run concurrently with itself.
  */
 #define vmdplugin_HEAD \
   int abiversion; \
   const char *type; \
   const char *name; \
   const char *prettyname; \
   const char *author; \
   int majorv; \
   int minorv; \
-  int is_reentrant; 
+  int is_reentrant;
 
-/** 
+/**
   * Typedef for generic plugin header, individual plugins can
-  * make their own structures as long as the header info remains 
-  * the same as the generic plugin header, most easily done by 
+  * make their own structures as long as the header info remains
+  * the same as the generic plugin header, most easily done by
   * using the vmdplugin_HEAD macro.
   */
 typedef struct {
   vmdplugin_HEAD
 } vmdplugin_t;
 
 /**
  * Use this macro to initialize the abiversion member of each plugin
  */
 #define vmdplugin_ABIVERSION  16
 
 /*@{*/
 /** Use this macro to indicate a plugin's thread-safety at registration time */
 #define VMDPLUGIN_THREADUNSAFE 0
 #define VMDPLUGIN_THREADSAFE   1
 /*@}*/
 
 /*@{*/
 /** Error return code for use in the plugin registration and init functions */
 #define VMDPLUGIN_SUCCESS      0
 #define VMDPLUGIN_ERROR       -1
 /*@}*/
 
-/** 
+/**
  * Function pointer typedef for register callback functions
  */
 typedef int (*vmdplugin_register_cb)(void *, vmdplugin_t *);
 
 /**
  * Allow the library to register plugins with the application.
  * The callback should be called using the passed-in void pointer, which
  * should not be interpreted in any way by the library.  Each vmdplugin_t
  * pointer passed to the application should point to statically-allocated
  * or heap-allocated memory and should never be later modified by the plugin.
  * Applications must be permitted to retain only a copy of the the plugin
  * pointer, without making any deep copy of the items in the struct.
  */
 VMDPLUGIN_EXTERN int VMDPLUGIN_register(void *, vmdplugin_register_cb);
 
 /**
- * Allow the library to register Tcl extensions.  
+ * Allow the library to register Tcl extensions.
  * This API is optional; if found by dlopen, it will be called after first
- * calling init and register.  
+ * calling init and register.
  */
-VMDPLUGIN_EXTERN int VMDPLUGIN_register_tcl(void *, void *tcl_interp, 
+VMDPLUGIN_EXTERN int VMDPLUGIN_register_tcl(void *, void *tcl_interp,
     vmdplugin_register_cb);
 
 /**
- * The Fini method is called when the application will no longer use 
- * any plugins in the library.  
+ * The Fini method is called when the application will no longer use
+ * any plugins in the library.
  */
 VMDPLUGIN_EXTERN int VMDPLUGIN_fini(void);
 
 #endif   /* VMD_PLUGIN_H */
diff --git a/src/USER-OMP/bond_harmonic_shift_cut_omp.cpp b/src/USER-OMP/bond_harmonic_shift_cut_omp.cpp
index 6ea5f6c2c..97f7715bf 100644
--- a/src/USER-OMP/bond_harmonic_shift_cut_omp.cpp
+++ b/src/USER-OMP/bond_harmonic_shift_cut_omp.cpp
@@ -1,132 +1,132 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #include "bond_harmonic_shift_cut_omp.h"
 #include "atom.h"
 #include "comm.h"
 #include "force.h"
 #include "neighbor.h"
 #include "domain.h"
 
 #include <math.h>
 
 #include "suffix.h"
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShiftCutOMP::BondHarmonicShiftCutOMP(class LAMMPS *lmp)
   : BondHarmonicShiftCut(lmp), ThrOMP(lmp,THR_BOND)
 {
   suffix_flag |= Suffix::OMP;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShiftCutOMP::compute(int eflag, int vflag)
 {
 
   if (eflag || vflag) {
     ev_setup(eflag,vflag);
   } else evflag = 0;
 
   const int nall = atom->nlocal + atom->nghost;
   const int nthreads = comm->nthreads;
   const int inum = neighbor->nbondlist;
 
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(eflag,vflag)
 #endif
   {
     int ifrom, ito, tid;
 
     loop_setup_thr(ifrom, ito, tid, inum, nthreads);
     ThrData *thr = fix->get_thr(tid);
     ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr);
 
     if (evflag) {
       if (eflag) {
         if (force->newton_bond) eval<1,1,1>(ifrom, ito, thr);
         else eval<1,1,0>(ifrom, ito, thr);
       } else {
         if (force->newton_bond) eval<1,0,1>(ifrom, ito, thr);
         else eval<1,0,0>(ifrom, ito, thr);
       }
     } else {
       if (force->newton_bond) eval<0,0,1>(ifrom, ito, thr);
       else eval<0,0,0>(ifrom, ito, thr);
     }
 
     reduce_thr(this, eflag, vflag, thr);
   } // end of omp parallel region
 }
 
 template <int EVFLAG, int EFLAG, int NEWTON_BOND>
 void BondHarmonicShiftCutOMP::eval(int nfrom, int nto, ThrData * const thr)
 {
   int i1,i2,n,type;
   double delx,dely,delz,ebond,fbond;
   double rsq,r,dr,rk;
 
   const double * const * const x = atom->x;
   double * const * const f = thr->get_f();
   const int * const * const bondlist = neighbor->bondlist;
   const int nlocal = atom->nlocal;
 
   for (n = nfrom; n < nto; n++) {
     i1 = bondlist[n][0];
     i2 = bondlist[n][1];
     type = bondlist[n][2];
 
     delx = x[i1][0] - x[i2][0];
     dely = x[i1][1] - x[i2][1];
     delz = x[i1][2] - x[i2][2];
 
     rsq = delx*delx + dely*dely + delz*delz;
     r = sqrt(rsq);
 
     if (r>r1[type]) continue;
 
     dr = r - r0[type];
     rk = k[type] * dr;
 
     // force & energy
 
     if (r > 0.0) fbond = -2.0*rk/r;
     else fbond = 0.0;
 
-    if (EFLAG) 
+    if (EFLAG)
       ebond = k[type]*(dr*dr -(r0[type]-r1[type])*(r0[type]-r1[type]) );
 
     // apply force to each of 2 atoms
 
     if (NEWTON_BOND || i1 < nlocal) {
       f[i1][0] += delx*fbond;
       f[i1][1] += dely*fbond;
       f[i1][2] += delz*fbond;
     }
 
     if (NEWTON_BOND || i2 < nlocal) {
       f[i2][0] -= delx*fbond;
       f[i2][1] -= dely*fbond;
       f[i2][2] -= delz*fbond;
     }
 
     if (EVFLAG) ev_tally_thr(this,i1,i2,nlocal,NEWTON_BOND,
                              ebond,fbond,delx,dely,delz,thr);
   }
 }
diff --git a/src/USER-OMP/bond_harmonic_shift_omp.cpp b/src/USER-OMP/bond_harmonic_shift_omp.cpp
index 2f6f1d37b..49d985b87 100644
--- a/src/USER-OMP/bond_harmonic_shift_omp.cpp
+++ b/src/USER-OMP/bond_harmonic_shift_omp.cpp
@@ -1,129 +1,129 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #include "bond_harmonic_shift_omp.h"
 #include "atom.h"
 #include "comm.h"
 #include "force.h"
 #include "neighbor.h"
 #include "domain.h"
 
 #include <math.h>
 
 #include "suffix.h"
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 BondHarmonicShiftOMP::BondHarmonicShiftOMP(class LAMMPS *lmp)
   : BondHarmonicShift(lmp), ThrOMP(lmp,THR_BOND)
 {
   suffix_flag |= Suffix::OMP;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void BondHarmonicShiftOMP::compute(int eflag, int vflag)
 {
 
   if (eflag || vflag) {
     ev_setup(eflag,vflag);
   } else evflag = 0;
 
   const int nall = atom->nlocal + atom->nghost;
   const int nthreads = comm->nthreads;
   const int inum = neighbor->nbondlist;
 
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(eflag,vflag)
 #endif
   {
     int ifrom, ito, tid;
 
     loop_setup_thr(ifrom, ito, tid, inum, nthreads);
     ThrData *thr = fix->get_thr(tid);
     ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr);
 
     if (evflag) {
       if (eflag) {
         if (force->newton_bond) eval<1,1,1>(ifrom, ito, thr);
         else eval<1,1,0>(ifrom, ito, thr);
       } else {
         if (force->newton_bond) eval<1,0,1>(ifrom, ito, thr);
         else eval<1,0,0>(ifrom, ito, thr);
       }
     } else {
       if (force->newton_bond) eval<0,0,1>(ifrom, ito, thr);
       else eval<0,0,0>(ifrom, ito, thr);
     }
 
     reduce_thr(this, eflag, vflag, thr);
   } // end of omp parallel region
 }
 
 template <int EVFLAG, int EFLAG, int NEWTON_BOND>
 void BondHarmonicShiftOMP::eval(int nfrom, int nto, ThrData * const thr)
 {
   int i1,i2,n,type;
   double delx,dely,delz,ebond,fbond;
   double rsq,r,dr,rk;
 
   const double * const * const x = atom->x;
   double * const * const f = thr->get_f();
   const int * const * const bondlist = neighbor->bondlist;
   const int nlocal = atom->nlocal;
 
   for (n = nfrom; n < nto; n++) {
     i1 = bondlist[n][0];
     i2 = bondlist[n][1];
     type = bondlist[n][2];
 
     delx = x[i1][0] - x[i2][0];
     dely = x[i1][1] - x[i2][1];
     delz = x[i1][2] - x[i2][2];
 
     rsq = delx*delx + dely*dely + delz*delz;
     r = sqrt(rsq);
     dr = r - r0[type];
     rk = k[type] * dr;
 
     // force & energy
 
     if (r > 0.0) fbond = -2.0*rk/r;
     else fbond = 0.0;
 
-    if (EFLAG) 
+    if (EFLAG)
       ebond = k[type]*(dr*dr -(r0[type]-r1[type])*(r0[type]-r1[type]) );
 
     // apply force to each of 2 atoms
 
     if (NEWTON_BOND || i1 < nlocal) {
       f[i1][0] += delx*fbond;
       f[i1][1] += dely*fbond;
       f[i1][2] += delz*fbond;
     }
 
     if (NEWTON_BOND || i2 < nlocal) {
       f[i2][0] -= delx*fbond;
       f[i2][1] -= dely*fbond;
       f[i2][2] -= delz*fbond;
     }
 
     if (EVFLAG) ev_tally_thr(this,i1,i2,nlocal,NEWTON_BOND,
                              ebond,fbond,delx,dely,delz,thr);
   }
 }
diff --git a/src/USER-OMP/fix_qeq_comb_omp.cpp b/src/USER-OMP/fix_qeq_comb_omp.cpp
index dbf073db5..18b9b5305 100644
--- a/src/USER-OMP/fix_qeq_comb_omp.cpp
+++ b/src/USER-OMP/fix_qeq_comb_omp.cpp
@@ -1,192 +1,192 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Axel Kohlmeyer (Temple U)
 ------------------------------------------------------------------------- */
 
 #include "lmptype.h"
 #include "mpi.h"
 #include "math.h"
 #include "fix_qeq_comb_omp.h"
 #include "fix_omp.h"
 #include "atom.h"
 #include "comm.h"
 #include "force.h"
 #include "group.h"
 #include "memory.h"
 #include "modify.h"
 #include "error.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "respa.h"
 #include "update.h"
 #include "pair_comb_omp.h"
 
 #include <string.h>
 
 using namespace LAMMPS_NS;
 using namespace FixConst;
 
 /* ---------------------------------------------------------------------- */
 
 FixQEQCombOMP::FixQEQCombOMP(LAMMPS *lmp, int narg, char **arg)
   : FixQEQComb(lmp, narg, arg)
 {
   if (narg < 5) error->all(FLERR,"Illegal fix qeq/comb/omp command");
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQCombOMP::init()
 {
   if (!atom->q_flag)
     error->all(FLERR,"Fix qeq/comb/omp requires atom attribute q");
 
   comb = (PairComb *) force->pair_match("comb/omp",1);
   if (comb == NULL)
     comb = (PairComb *) force->pair_match("comb",1);
   if (comb == NULL) error->all(FLERR,"Must use pair_style comb or comb/omp with fix qeq/comb");
 
   if (strstr(update->integrate_style,"respa"))
     nlevels_respa = ((Respa *) update->integrate)->nlevels;
 
   ngroup = group->count(igroup);
   if (ngroup == 0) error->all(FLERR,"Fix qeq/comb group has no atoms");
 
   // determine status of neighbor flag of the omp package command
   int ifix = modify->find_fix("package_omp");
   int use_omp = 0;
   if (ifix >=0) {
      FixOMP * fix = static_cast<FixOMP *>(lmp->modify->fix[ifix]);
      if (fix->get_neighbor()) use_omp = 1;
   }
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->pair = 0;
   neighbor->requests[irequest]->fix = 1;
   neighbor->requests[irequest]->half = 0;
   neighbor->requests[irequest]->full = 1;
   neighbor->requests[irequest]->omp = use_omp;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEQCombOMP::post_force(int vflag)
 {
   int i,ii,iloop,loopmax,inum,*ilist;
   double heatpq,qmass,dtq,dtq2;
   double enegchkall,enegmaxall;
 
   if (update->ntimestep % nevery) return;
 
   // reallocate work arrays if necessary
   // qf = charge force
   // q1 = charge displacement
   // q2 = tmp storage of charge force for next iteration
 
   if (atom->nmax > nmax) {
     memory->destroy(qf);
     memory->destroy(q1);
     memory->destroy(q2);
     nmax = atom->nmax;
     memory->create(qf,nmax,"qeq:qf");
     memory->create(q1,nmax,"qeq:q1");
     memory->create(q2,nmax,"qeq:q2");
     vector_atom = qf;
   }
 
   // more loops for first-time charge equilibrium
 
-  iloop = 0; 
+  iloop = 0;
   if (firstflag) loopmax = 500;
   else loopmax = 200;
 
   // charge-equilibration loop
 
   if (me == 0 && fp)
     fprintf(fp,"Charge equilibration on step " BIGINT_FORMAT "\n",
             update->ntimestep);
 
   heatpq = 0.05;
   qmass  = 0.016;
   dtq    = 0.01;
   dtq2   = 0.5*dtq*dtq/qmass;
 
   double enegchk = 0.0;
   double enegtot = 0.0;
   double enegmax = 0.0;
 
   double *q = atom->q;
   int *mask = atom->mask;
 
   inum = comb->list->inum;
   ilist = comb->list->ilist;
 
   for (ii = 0; ii < inum; ii++) {
     i = ilist[ii];
     q1[i] = q2[i] = qf[i] = 0.0;
   }
 
   for (iloop = 0; iloop < loopmax; iloop ++ ) {
     for (ii = 0; ii < inum; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit) {
         q1[i] += qf[i]*dtq2 - heatpq*q1[i];
-        q[i]  += q1[i]; 
+        q[i]  += q1[i];
       }
     }
     comm->forward_comm_fix(this);
 
     if(comb) enegtot = comb->yasu_char(qf,igroup);
     enegtot /= ngroup;
     enegchk = enegmax = 0.0;
-    
+
     for (ii = 0; ii < inum ; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit) {
         q2[i] = enegtot-qf[i];
         enegmax = MAX(enegmax,fabs(q2[i]));
         enegchk += fabs(q2[i]);
         qf[i] = q2[i];
       }
     }
 
     MPI_Allreduce(&enegchk,&enegchkall,1,MPI_DOUBLE,MPI_SUM,world);
     enegchk = enegchkall/ngroup;
     MPI_Allreduce(&enegmax,&enegmaxall,1,MPI_DOUBLE,MPI_MAX,world);
     enegmax = enegmaxall;
 
     if (enegchk <= precision && enegmax <= 100.0*precision) break;
 
     if (me == 0 && fp)
       fprintf(fp,"  iteration: %d, enegtot %.6g, "
               "enegmax %.6g, fq deviation: %.6g\n",
-              iloop,enegtot,enegmax,enegchk); 
-    
+              iloop,enegtot,enegmax,enegchk);
+
     for (ii = 0; ii < inum; ii++) {
       i = ilist[ii];
       if (mask[i] & groupbit)
-        q1[i] += qf[i]*dtq2 - heatpq*q1[i]; 
+        q1[i] += qf[i]*dtq2 - heatpq*q1[i];
     }
-  } 
-  
+  }
+
   if (me == 0 && fp) {
     if (iloop == loopmax)
       fprintf(fp,"Charges did not converge in %d iterations\n",iloop);
     else
       fprintf(fp,"Charges converged in %d iterations to %.10f tolerance\n",
               iloop,enegchk);
   }
 }
diff --git a/src/USER-OMP/neigh_half_bin_omp.cpp b/src/USER-OMP/neigh_half_bin_omp.cpp
index 45dd79d09..ba0a18041 100644
--- a/src/USER-OMP/neigh_half_bin_omp.cpp
+++ b/src/USER-OMP/neigh_half_bin_omp.cpp
@@ -1,522 +1,522 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "neighbor.h"
 #include "neighbor_omp.h"
 #include "neigh_list.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ----------------------------------------------------------------------
    binned neighbor list construction with partial Newton's 3rd law
    each owned atom i checks own bin and other bins in stencil
    pair stored once if i,j are both owned and i < j
    pair stored by me if j is ghost (also stored by proc owning j)
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_bin_no_newton_omp(NeighList *list)
 {
   // bin local & ghost atoms
 
   bin_atoms();
 
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nlocal);
 
   int i,j,k,n,itype,jtype,ibin,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   // loop over each atom, storing neighbors
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
   int nstencil = list->nstencil;
   int *stencil = list->stencil;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over all atoms in other bins in stencil including self
     // only store pair if i < j
     // stores own/own pairs only once
     // stores own/ghost pairs on both procs
 
     ibin = coord2bin(x[i]);
 
     for (k = 0; k < nstencil; k++) {
       for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
         if (j <= i) continue;
 
         jtype = type[j];
         if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
         delx = xtmp - x[j][0];
         dely = ytmp - x[j][1];
         delz = ztmp - x[j][2];
         rsq = delx*delx + dely*dely + delz*delz;
 
         if (rsq <= cutneighsq[itype][jtype]) {
           if (molecular) {
             which = find_special(special[i],nspecial[i],tag[j]);
             if (which == 0) neighptr[n++] = j;
             else if (domain->minimum_image_check(delx,dely,delz))
               neighptr[n++] = j;
             else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
           } else neighptr[n++] = j;
         }
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
 }
 
 /* ----------------------------------------------------------------------
    binned neighbor list construction with partial Newton's 3rd law
    include neighbors of ghost atoms, but no "special neighbors" for ghosts
    owned and ghost atoms check own bin and other bins in stencil
    pair stored once if i,j are both owned and i < j
    pair stored by me if i owned and j ghost (also stored by proc owning j)
    pair stored once if i,j are both ghost and i < j
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_bin_no_newton_ghost_omp(NeighList *list)
 {
   const int nlocal = atom->nlocal;
   const int nall = nlocal + atom->nghost;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nall);
 
   int i,j,k,n,itype,jtype,ibin,which;
   int xbin,ybin,zbin,xbin2,ybin2,zbin2;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   // bin local & ghost atoms
 
   bin_atoms();
 
   // loop over each atom, storing neighbors
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
   int nstencil = list->nstencil;
   int *stencil = list->stencil;
   int **stencilxyz = list->stencilxyz;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over all atoms in other bins in stencil including self
     // when i is a ghost atom, must check if stencil bin is out of bounds
     // only store pair if i < j
     // stores own/own pairs only once
     // stores own/ghost pairs with owned atom only, on both procs
     // stores ghost/ghost pairs only once
     // no molecular test when i = ghost atom
 
     if (i < nlocal) {
       ibin = coord2bin(x[i]);
 
       for (k = 0; k < nstencil; k++) {
         for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
           if (j <= i) continue;
 
           jtype = type[j];
           if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
           delx = xtmp - x[j][0];
           dely = ytmp - x[j][1];
           delz = ztmp - x[j][2];
           rsq = delx*delx + dely*dely + delz*delz;
-          
+
           if (rsq <= cutneighsq[itype][jtype]) {
             if (molecular) {
               which = find_special(special[i],nspecial[i],tag[j]);
               if (which == 0) neighptr[n++] = j;
               else if (domain->minimum_image_check(delx,dely,delz))
                 neighptr[n++] = j;
               else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
             } else neighptr[n++] = j;
           }
         }
       }
 
     } else {
       ibin = coord2bin(x[i],xbin,ybin,zbin);
       for (k = 0; k < nstencil; k++) {
         xbin2 = xbin + stencilxyz[k][0];
         ybin2 = ybin + stencilxyz[k][1];
         zbin2 = zbin + stencilxyz[k][2];
         if (xbin2 < 0 || xbin2 >= mbinx ||
             ybin2 < 0 || ybin2 >= mbiny ||
             zbin2 < 0 || zbin2 >= mbinz) continue;
         for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
           if (j <= i) continue;
 
           jtype = type[j];
           if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
           delx = xtmp - x[j][0];
           dely = ytmp - x[j][1];
           delz = ztmp - x[j][2];
           rsq = delx*delx + dely*dely + delz*delz;
 
           if (rsq <= cutneighghostsq[itype][jtype]) neighptr[n++] = j;
         }
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
   list->gnum = nall - atom->nlocal;
 }
 
 /* ----------------------------------------------------------------------
    binned neighbor list construction with full Newton's 3rd law
    each owned atom i checks its own bin and other bins in Newton stencil
    every pair stored exactly once by some processor
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_bin_newton_omp(NeighList *list)
 {
   // bin local & ghost atoms
 
   bin_atoms();
 
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nlocal);
 
   int i,j,k,n,itype,jtype,ibin,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   // loop over each atom, storing neighbors
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
   int nstencil = list->nstencil;
   int *stencil = list->stencil;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over rest of atoms in i's bin, ghosts are at end of linked list
     // if j is owned atom, store it, since j is beyond i in linked list
     // if j is ghost, only store if j coords are "above and to the right" of i
 
     for (j = bins[i]; j >= 0; j = bins[j]) {
       if (j >= nlocal) {
         if (x[j][2] < ztmp) continue;
         if (x[j][2] == ztmp) {
           if (x[j][1] < ytmp) continue;
           if (x[j][1] == ytmp && x[j][0] < xtmp) continue;
         }
       }
 
       jtype = type[j];
       if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
 
       if (rsq <= cutneighsq[itype][jtype]) {
         if (molecular) {
           which = find_special(special[i],nspecial[i],tag[j]);
           if (which == 0) neighptr[n++] = j;
           else if (domain->minimum_image_check(delx,dely,delz))
             neighptr[n++] = j;
           else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
           // OLD: if (which >= 0) neighptr[n++] = j ^ (which << SBBITS);
         } else neighptr[n++] = j;
       }
     }
 
     // loop over all atoms in other bins in stencil, store every pair
 
     ibin = coord2bin(x[i]);
     for (k = 0; k < nstencil; k++) {
       for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
         jtype = type[j];
         if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
         delx = xtmp - x[j][0];
         dely = ytmp - x[j][1];
         delz = ztmp - x[j][2];
         rsq = delx*delx + dely*dely + delz*delz;
 
         if (rsq <= cutneighsq[itype][jtype]) {
           if (molecular) {
             which = find_special(special[i],nspecial[i],tag[j]);
             if (which == 0) neighptr[n++] = j;
             else if (domain->minimum_image_check(delx,dely,delz))
               neighptr[n++] = j;
             else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
             // OLD: if (which >= 0) neighptr[n++] = j ^ (which << SBBITS);
           } else neighptr[n++] = j;
         }
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
 }
 
 /* ----------------------------------------------------------------------
    binned neighbor list construction with Newton's 3rd law for triclinic
    each owned atom i checks its own bin and other bins in triclinic stencil
    every pair stored exactly once by some processor
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_bin_newton_tri_omp(NeighList *list)
 {
   // bin local & ghost atoms
 
   bin_atoms();
 
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nlocal);
 
   int i,j,k,n,itype,jtype,ibin,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   // loop over each atom, storing neighbors
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
   int nstencil = list->nstencil;
   int *stencil = list->stencil;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over all atoms in bins in stencil
     // pairs for atoms j "below" i are excluded
     // below = lower z or (equal z and lower y) or (equal zy and lower x)
     //         (equal zyx and j <= i)
     // latter excludes self-self interaction but allows superposed atoms
 
     ibin = coord2bin(x[i]);
     for (k = 0; k < nstencil; k++) {
       for (j = binhead[ibin+stencil[k]]; j >= 0; j = bins[j]) {
         if (x[j][2] < ztmp) continue;
         if (x[j][2] == ztmp) {
           if (x[j][1] < ytmp) continue;
           if (x[j][1] == ytmp) {
             if (x[j][0] < xtmp) continue;
             if (x[j][0] == xtmp && j <= i) continue;
           }
         }
 
         jtype = type[j];
         if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
         delx = xtmp - x[j][0];
         dely = ytmp - x[j][1];
         delz = ztmp - x[j][2];
         rsq = delx*delx + dely*dely + delz*delz;
 
         if (rsq <= cutneighsq[itype][jtype]) {
           if (molecular) {
             which = find_special(special[i],nspecial[i],tag[j]);
             if (which == 0) neighptr[n++] = j;
             else if (domain->minimum_image_check(delx,dely,delz))
               neighptr[n++] = j;
             else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
           } else neighptr[n++] = j;
         }
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
 }
diff --git a/src/USER-OMP/neigh_half_nsq_omp.cpp b/src/USER-OMP/neigh_half_nsq_omp.cpp
index 44b777273..6a8bee491 100644
--- a/src/USER-OMP/neigh_half_nsq_omp.cpp
+++ b/src/USER-OMP/neigh_half_nsq_omp.cpp
@@ -1,350 +1,350 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
    certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 #include "neighbor.h"
 #include "neighbor_omp.h"
 #include "neigh_list.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "group.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 /* ----------------------------------------------------------------------
    N^2 / 2 search for neighbor pairs with partial Newton's 3rd law
    pair stored once if i,j are both owned and i < j
    pair stored by me if j is ghost (also stored by proc owning j)
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_nsq_no_newton_omp(NeighList *list)
 {
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
   const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0;
   const int nall = atom->nlocal + atom->nghost;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nlocal);
 
   int i,j,n,itype,jtype,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   // loop over owned atoms, storing neighbors
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over remaining atoms, owned and ghost
     // only store pair if i < j
 
     for (j = i+1; j < nall; j++) {
       if (includegroup && !(mask[j] & bitmask)) continue;
       jtype = type[j];
       if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
 
       if (rsq <= cutneighsq[itype][jtype]) {
         if (molecular) {
           which = find_special(special[i],nspecial[i],tag[j]);
           if (which == 0) neighptr[n++] = j;
           else if (domain->minimum_image_check(delx,dely,delz))
             neighptr[n++] = j;
           else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
         } else neighptr[n++] = j;
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
 }
 
 /* ----------------------------------------------------------------------
    N^2 / 2 search for neighbor pairs with partial Newton's 3rd law
    include neighbors of ghost atoms, but no "special neighbors" for ghosts
    pair stored once if i,j are both owned and i < j
    pair stored by me if i owned and j ghost (also stored by proc owning j)
    pair stored once if i,j are both ghost and i < j
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_nsq_no_newton_ghost_omp(NeighList *list)
 {
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
   const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0;
   const int nall = nlocal + atom->nghost;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nall);
 
   int i,j,n,itype,jtype,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
 
   // each thread works on its own page
   int npage = tid;
   int npnt = 0;
 
   // loop over owned & ghost atoms, storing neighbors
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over remaining atoms, owned and ghost
     // only store pair if i < j
     // stores own/own pairs only once
     // stores own/ghost pairs with owned atom only, on both procs
     // stores ghost/ghost pairs only once
     // no molecular test when i = ghost atom
 
     if (i < nlocal) {
       for (j = i+1; j < nall; j++) {
         if (includegroup && !(mask[j] & bitmask)) continue;
         jtype = type[j];
         if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
-        
+
         delx = xtmp - x[j][0];
         dely = ytmp - x[j][1];
         delz = ztmp - x[j][2];
         rsq = delx*delx + dely*dely + delz*delz;
-        
+
         if (rsq <= cutneighsq[itype][jtype]) {
           if (molecular) {
             which = find_special(special[i],nspecial[i],tag[j]);
             if (which == 0) neighptr[n++] = j;
             else if (domain->minimum_image_check(delx,dely,delz))
               neighptr[n++] = j;
             else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
           } else neighptr[n++] = j;
         }
       }
 
     } else {
       for (j = i+1; j < nall; j++) {
         if (includegroup && !(mask[j] & bitmask)) continue;
         jtype = type[j];
         if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
-        
+
         delx = xtmp - x[j][0];
         dely = ytmp - x[j][1];
         delz = ztmp - x[j][2];
         rsq = delx*delx + dely*dely + delz*delz;
-        
+
         if (rsq <= cutneighsq[itype][jtype]) neighptr[n++] = j;
       }
     }
-    
+
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = atom->nlocal;
   list->gnum = nall - atom->nlocal;
 }
 
 /* ----------------------------------------------------------------------
    N^2 / 2 search for neighbor pairs with full Newton's 3rd law
    every pair stored exactly once by some processor
    decision on ghost atoms based on itag,jtag tests
 ------------------------------------------------------------------------- */
 
 void Neighbor::half_nsq_newton_omp(NeighList *list)
 {
   const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal;
   const int bitmask = (includegroup) ? group->bitmask[includegroup] : 0;
 
   NEIGH_OMP_INIT;
 #if defined(_OPENMP)
 #pragma omp parallel default(none) shared(list)
 #endif
   NEIGH_OMP_SETUP(nlocal);
 
   int i,j,n,itype,jtype,itag,jtag,which;
   double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
   int *neighptr;
 
   // loop over each atom, storing neighbors
 
   int **special = atom->special;
   int **nspecial = atom->nspecial;
   int *tag = atom->tag;
 
   double **x = atom->x;
   int *type = atom->type;
   int *mask = atom->mask;
   int *molecule = atom->molecule;
   int nall = atom->nlocal + atom->nghost;
   int molecular = atom->molecular;
 
   int *ilist = list->ilist;
   int *numneigh = list->numneigh;
   int **firstneigh = list->firstneigh;
 
   int npage = tid;
   int npnt = 0;
 
   for (i = ifrom; i < ito; i++) {
 
 #if defined(_OPENMP)
 #pragma omp critical
 #endif
     if (pgsize - npnt < oneatom) {
       npnt = 0;
       npage += nthreads;
       if (npage >= list->maxpage) list->add_pages(nthreads);
     }
 
     neighptr = &(list->pages[npage][npnt]);
     n = 0;
 
     itag = tag[i];
     itype = type[i];
     xtmp = x[i][0];
     ytmp = x[i][1];
     ztmp = x[i][2];
 
     // loop over remaining atoms, owned and ghost
     // itag = jtag is possible for long cutoffs that include images of self
 
     for (j = i+1; j < nall; j++) {
       if (includegroup && !(mask[j] & bitmask)) continue;
 
       if (j >= nlocal) {
         jtag = tag[j];
         if (itag > jtag) {
           if ((itag+jtag) % 2 == 0) continue;
         } else if (itag < jtag) {
           if ((itag+jtag) % 2 == 1) continue;
         } else {
           if (x[j][2] < ztmp) continue;
           if (x[j][2] == ztmp) {
             if (x[j][1] < ytmp) continue;
             if (x[j][1] == ytmp && x[j][0] < xtmp) continue;
           }
         }
       }
 
       jtype = type[j];
       if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
 
       delx = xtmp - x[j][0];
       dely = ytmp - x[j][1];
       delz = ztmp - x[j][2];
       rsq = delx*delx + dely*dely + delz*delz;
 
       if (rsq <= cutneighsq[itype][jtype]) {
         if (molecular) {
           which = find_special(special[i],nspecial[i],tag[j]);
           if (which == 0) neighptr[n++] = j;
           else if (domain->minimum_image_check(delx,dely,delz))
             neighptr[n++] = j;
           else if (which > 0) neighptr[n++] = j ^ (which << SBBITS);
         } else neighptr[n++] = j;
       }
     }
 
     ilist[i] = i;
     firstneigh[i] = neighptr;
     numneigh[i] = n;
     npnt += n;
     if (n > oneatom)
       error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
   }
   NEIGH_OMP_CLOSE;
   list->inum = nlocal;
 }
diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp
index becd5ffc5..18fba083d 100644
--- a/src/USER-REAXC/fix_qeq_reax.cpp
+++ b/src/USER-REAXC/fix_qeq_reax.cpp
@@ -1,870 +1,870 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Hasan Metin Aktulga, Purdue University
    (now at Lawrence Berkeley National Laboratory, hmaktulga@lbl.gov)
 
    Please cite the related publication:
    H. M. Aktulga, J. C. Fogarty, S. A. Pandit, A. Y. Grama,
    "Parallel Reactive Molecular Dynamics: Numerical Methods and
    Algorithmic Techniques", Parallel Computing, in press.
 ------------------------------------------------------------------------- */
 
 #include "math.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "string.h"
 #include "fix_qeq_reax.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "update.h"
 #include "force.h"
 #include "pair.h"
 #include "respa.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 using namespace FixConst;
 
 #define EV_TO_KCAL_PER_MOL 14.4
 #define SAFE_ZONE       1.2
 #define DANGER_ZONE     0.95
 #define LOOSE_ZONE      0.7
 #define SQR(x) ((x)*(x))
 #define CUBE(x) ((x)*(x)*(x))
 #define MIN_CAP 50
 #define MIN_NBRS 100
 
 /* ---------------------------------------------------------------------- */
 
-FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : 
+FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) :
   Fix(lmp, narg, arg)
 {
-  if (narg != 8) error->all(FLERR,"Illegal fix qeq/reax command"); 
-  
+  if (narg != 8) error->all(FLERR,"Illegal fix qeq/reax command");
+
   nevery = atoi(arg[3]);
   swa = atof(arg[4]);
   swb = atof(arg[5]);
   tolerance = atof(arg[6]);
   pertype_parameters(arg[7]);
 
   shld = NULL;
 
   n = n_cap = 0;
   N = nmax = 0;
   m_fill = m_cap = 0;
   pack_flag = 0;
   s = NULL;
   t = NULL;
   nprev = 5;
-  
+
   Hdia_inv = NULL;
   b_s = NULL;
   b_t = NULL;
   b_prc = NULL;
   b_prm = NULL;
 
   // CG
   p = NULL;
   q = NULL;
   r = NULL;
   d = NULL;
 
   // GMRES
   //g = NULL;
   //y = NULL;
   //hstr = NULL;
   //v = NULL;
   //h = NULL;
   //hc = NULL;
   //hs = NULL;
 
   // perform initial allocation of atom-based arrays
   // register with Atom class
 
   s_hist = t_hist = NULL;
   grow_arrays(atom->nmax);
   atom->add_callback(0);
   for( int i = 0; i < atom->nmax; i++ )
     for (int j = 0; j < nprev; ++j )
       s_hist[i][j] = t_hist[i][j] = 0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 FixQEqReax::~FixQEqReax()
 {
   // unregister callbacks to this fix from Atom class
- 
+
   atom->delete_callback(id,0);
 
   memory->destroy(s_hist);
   memory->destroy(t_hist);
 
   deallocate_storage();
   deallocate_matrix();
 
   memory->destroy(shld);
 
   if (!reaxflag) {
     memory->destroy(chi);
     memory->destroy(eta);
     memory->destroy(gamma);
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int FixQEqReax::setmask()
 {
   int mask = 0;
   mask |= PRE_FORCE;
   mask |= MIN_PRE_FORCE;
   return mask;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::pertype_parameters(char *arg)
 {
   if (strcmp(arg,"reax/c") == 0) {
     reaxflag = 1;
     Pair *pair = force->pair_match("reax/c",1);
     if (pair == NULL) error->all(FLERR,"No pair reax/c for fix qeq/reax");
     int tmp;
     chi = (double *) pair->extract("chi",tmp);
     eta = (double *) pair->extract("eta",tmp);
     gamma = (double *) pair->extract("gamma",tmp);
     if (chi == NULL || eta == NULL || gamma == NULL)
       error->all(FLERR,
-		 "Fix qeq/reax could not extract params from pair reax/c");
+                 "Fix qeq/reax could not extract params from pair reax/c");
     return;
   }
 
   int i,itype,ntypes;
   double v1,v2,v3;
   FILE *pf;
 
   reaxflag = 0;
   ntypes = atom->ntypes;
 
   memory->create(chi,ntypes+1,"qeq/reax:chi");
   memory->create(eta,ntypes+1,"qeq/reax:eta");
   memory->create(gamma,ntypes+1,"qeq/reax:gamma");
 
   if (comm->me == 0) {
     if ((pf = fopen(arg,"r")) == NULL)
       error->one(FLERR,"Fix qeq/reax parameter file could not be found");
-    
+
     for (i = 1; i <= ntypes && !feof(pf); i++) {
       fscanf(pf,"%d %lg %lg %lg",&itype,&v1,&v2,&v3);
       if (itype < 1 || itype > ntypes)
-	error->one(FLERR,"Fix qeq/reax invalid atom type in param file");
+        error->one(FLERR,"Fix qeq/reax invalid atom type in param file");
       chi[itype] = v1;
       eta[itype] = v2;
       gamma[itype] = v3;
     }
     if (i <= ntypes) error->one(FLERR,"Invalid param file for fix qeq/reax");
     fclose(pf);
   }
 
   MPI_Bcast(&chi[1],ntypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&eta[1],ntypes,MPI_DOUBLE,0,world);
   MPI_Bcast(&gamma[1],ntypes,MPI_DOUBLE,0,world);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::allocate_storage()
 {
   nmax = atom->nmax;
 
   memory->create(s,nmax,"qeq:s");
   memory->create(t,nmax,"qeq:t");
 
   memory->create(Hdia_inv,nmax,"qeq:Hdia_inv");
   memory->create(b_s,nmax,"qeq:b_s");
   memory->create(b_t,nmax,"qeq:b_t");
   memory->create(b_prc,nmax,"qeq:b_prc");
   memory->create(b_prm,nmax,"qeq:b_prm");
 
   memory->create(p,nmax,"qeq:p");
   memory->create(q,nmax,"qeq:q");
   memory->create(r,nmax,"qeq:r");
   memory->create(d,nmax,"qeq:d");
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::deallocate_storage()
 {
   memory->destroy(s);
   memory->destroy(t);
 
   memory->destroy( Hdia_inv );
   memory->destroy( b_s );
   memory->destroy( b_t );
   memory->destroy( b_prc );
   memory->destroy( b_prm );
 
   memory->destroy( p );
   memory->destroy( q );
   memory->destroy( r );
   memory->destroy( d );
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::reallocate_storage()
 {
   deallocate_storage();
   allocate_storage();
   init_storage();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::allocate_matrix()
 {
   int i,ii;
 
   n = atom->nlocal;
   n_cap = MAX( (int)(n * SAFE_ZONE), MIN_CAP );
 
   // determine the total space for the H matrix
 
   int m = 0;
   for( ii = 0; ii < list->inum; ii++ ) {
     i = list->ilist[ii];
     m += list->numneigh[i];
   }
   m_cap = MAX( (int)(m * SAFE_ZONE), MIN_CAP * MIN_NBRS );
-  
+
   H.n = n_cap;
   H.m = m_cap;
   memory->create(H.firstnbr,n_cap,"qeq:H.firstnbr");
   memory->create(H.numnbrs,n_cap,"qeq:H.numnbrs");
   memory->create(H.jlist,m_cap,"qeq:H.jlist");
   memory->create(H.val,m_cap,"qeq:H.val");
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::deallocate_matrix()
 {
   memory->destroy( H.firstnbr );
   memory->destroy( H.numnbrs );
   memory->destroy( H.jlist );
-  memory->destroy( H.val ); 
+  memory->destroy( H.val );
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::reallocate_matrix()
 {
   deallocate_matrix();
   allocate_matrix();
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init()
 {
   if (!atom->q_flag) error->all(FLERR,"Fix qeq/reax requires atom attribute q");
-	
+
   // need a half neighbor list w/ Newton off and ghost neighbors
   // built whenever re-neighboring occurs
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->pair = 0;
   neighbor->requests[irequest]->fix = 1;
   neighbor->requests[irequest]->newton = 2;
   neighbor->requests[irequest]->ghost = 1;
 
   init_shielding();
   init_taper();
 
   if (strstr(update->integrate_style,"respa"))
     nlevels_respa = ((Respa *) update->integrate)->nlevels;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init_list(int id, NeighList *ptr)
 {
   list = ptr;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init_shielding()
 {
   int i,j;
   int ntypes;
 
   ntypes = atom->ntypes;
   memory->create(shld,ntypes+1,ntypes+1,"qeq:shileding");
-  
+
   for( i = 1; i <= ntypes; ++i )
     for( j = 1; j <= ntypes; ++j )
       shld[i][j] = pow( gamma[i] * gamma[j], -1.5 );
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init_taper()
 {
   double d7, swa2, swa3, swb2, swb3;
 
   if (fabs(swa) > 0.01 && comm->me == 0)
     error->warning(FLERR,"Fix qeq/reax has non-zero lower Taper radius cutoff");
   if (swb < 0)
     error->all(FLERR, "Fix qeq/reax has negative upper Taper radius cutoff");
   else if (swb < 5 && comm->me == 0)
     error->warning(FLERR,"Fix qeq/reax has very low Taper radius cutoff");
 
   d7 = pow( swb - swa, 7 );
   swa2 = SQR( swa );
   swa3 = CUBE( swa );
   swb2 = SQR( swb );
   swb3 = CUBE( swb );
 
   Tap[7] =  20.0 / d7;
   Tap[6] = -70.0 * (swa + swb) / d7;
   Tap[5] =  84.0 * (swa2 + 3.0*swa*swb + swb2) / d7;
   Tap[4] = -35.0 * (swa3 + 9.0*swa2*swb + 9.0*swa*swb2 + swb3 ) / d7;
   Tap[3] = 140.0 * (swa3*swb + 3.0*swa2*swb2 + swa*swb3 ) / d7;
   Tap[2] =-210.0 * (swa3*swb2 + swa2*swb3) / d7;
   Tap[1] = 140.0 * swa3 * swb3 / d7;
   Tap[0] = (-35.0*swa3*swb2*swb2 + 21.0*swa2*swb3*swb2 +
-	    7.0*swa*swb3*swb3 + swb3*swb3*swb ) / d7;
+            7.0*swa*swb3*swb3 + swb3*swb3*swb ) / d7;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::setup_pre_force(int vflag)
 {
   neighbor->build_one(list->index);
   allocate_storage();
   init_storage();
   allocate_matrix();
 
   pre_force(vflag);
-}  
+}
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::setup_pre_force_respa(int vflag, int ilevel)
 {
   if (ilevel < nlevels_respa-1) return;
   setup_pre_force(vflag);
-}  
+}
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::min_setup_pre_force(int vflag)
 {
   setup_pre_force(vflag);
-}  
+}
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init_storage()
 {
   N = atom->nlocal + atom->nghost;
   for( int i = 0; i < N; i++ ) {
-    Hdia_inv[i] = 1. / eta[atom->type[i]]; 
+    Hdia_inv[i] = 1. / eta[atom->type[i]];
     b_s[i] = -chi[atom->type[i]];
     b_t[i] = -1.0;
     b_prc[i] = 0;
     b_prm[i] = 0;
     s[i] = t[i] = 0;
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::pre_force(int vflag)
 {
   double t_start, t_end;
 
   if (update->ntimestep % nevery) return;
   if( comm->me == 0 ) t_start = MPI_Wtime();
 
   n = atom->nlocal;
   N = atom->nlocal + atom->nghost;
   // grow arrays if necessary
   // need to be atom->nmax in length
   if( atom->nmax > nmax ) reallocate_storage();
   if( n > n_cap*DANGER_ZONE || m_fill > m_cap*DANGER_ZONE )
     reallocate_matrix();
-  
+
   init_matvec();
-  matvecs = CG(b_s, s);	// CG on s - parallel
+  matvecs = CG(b_s, s);        // CG on s - parallel
   matvecs += CG(b_t, t); // CG on t - parallel
   calculate_Q();
 
   if( comm->me == 0 ) {
     t_end = MPI_Wtime();
     qeq_time = t_end - t_start;
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::pre_force_respa(int vflag, int ilevel, int iloop)
 {
   if (ilevel == nlevels_respa-1) pre_force(vflag);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::min_pre_force(int vflag)
 {
   pre_force(vflag);
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::init_matvec()
 {
   /* fill-in H matrix */
   compute_H();
 
   for( int i = 0; i < n; ++i ) {
     /* init pre-conditioner for H and init solution vectors */
     Hdia_inv[i] = 1. / eta[ atom->type[i] ];
     b_s[i]      = -chi[ atom->type[i] ];
     b_t[i]      = -1.0;
 
     /* linear extrapolation for s & t from previous solutions */
     //s[i] = 2 * s_hist[i][0] - s_hist[i][1];
     //t[i] = 2 * t_hist[i][0] - t_hist[i][1];
 
     /* quadratic extrapolation for s & t from previous solutions */
-    //s[i] = s_hist[i][2] + 3 * ( s_hist[i][0] - s_hist[i][1] );        
+    //s[i] = s_hist[i][2] + 3 * ( s_hist[i][0] - s_hist[i][1] );
     t[i] = t_hist[i][2] + 3 * ( t_hist[i][0] - t_hist[i][1] );
 
     /* cubic extrapolation for s & t from previous solutions */
     s[i] = 4*(s_hist[i][0]+s_hist[i][2])-(6*s_hist[i][1]+s_hist[i][3]);
     //t[i] = 4*(t_hist[i][0]+t_hist[i][2])-(6*t_hist[i][1]+t_hist[i][3]);
   }
 
   pack_flag = 2;
   comm->forward_comm_fix(this); //Dist_vector( s );
   pack_flag = 3;
   comm->forward_comm_fix(this); //Dist_vector( t );
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::compute_H()
 {
   int inum, jnum, *ilist, *jlist, *numneigh, **firstneigh;
   int i, j, ii, jj, temp, newnbr, flag;
   int *type, *tag;
   double **x, SMALL = 0.0001;
   double dx, dy, dz, r_sqr;
 
   type = atom->type;
   tag = atom->tag;
   x = atom->x;
 
   inum = list->inum;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
-  
+
   // fill in the H matrix
   m_fill = 0;
   r_sqr = 0;
   for( ii = 0; ii < inum; ii++ ) {
     i = ilist[ii];
     jlist = firstneigh[i];
     jnum = numneigh[i];
     H.firstnbr[i] = m_fill;
-    
+
     for( jj = 0; jj < jnum; jj++ ) {
       j = jlist[jj];
-      
+
       dx = x[j][0] - x[i][0];
       dy = x[j][1] - x[i][1];
       dz = x[j][2] - x[i][2];
       r_sqr = SQR(dx) + SQR(dy) + SQR(dz);
-      
+
       flag = 0;
       if (r_sqr <= SQR(swb)) {
         if (j < n) flag = 1;
         else if (tag[i] < tag[j]) flag = 1;
-	else if (tag[i] == tag[j]) {
+        else if (tag[i] == tag[j]) {
           if (dz > SMALL) flag = 1;
           else if (fabs(dz) < SMALL) {
             if (dy > SMALL) flag = 1;
             else if (fabs(dy) < SMALL && dx > SMALL)
               flag = 1;
           }
         }
       }
-      
+
       if( flag ) {
-	H.jlist[m_fill] = j;
-	H.val[m_fill] = calculate_H( sqrt(r_sqr), shld[type[i]][type[j]] );
-	m_fill++;
+        H.jlist[m_fill] = j;
+        H.val[m_fill] = calculate_H( sqrt(r_sqr), shld[type[i]][type[j]] );
+        m_fill++;
       }
     }
-    
+
     H.numnbrs[i] = m_fill - H.firstnbr[i];
   }
 
   if (m_fill >= H.m) {
     char str[128];
     sprintf(str,"H matrix size has been exceeded: m_fill=%d H.m=%d\n",
-	     m_fill, H.m );
+             m_fill, H.m );
     error->warning(FLERR,str);
     error->all(FLERR,"Fix qeq/reax has insufficient QEq matrix size");
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::calculate_H( double r, double gamma )
 {
   double Taper, denom;
 
   Taper = Tap[7] * r + Tap[6];
   Taper = Taper * r + Tap[5];
   Taper = Taper * r + Tap[4];
   Taper = Taper * r + Tap[3];
   Taper = Taper * r + Tap[2];
   Taper = Taper * r + Tap[1];
   Taper = Taper * r + Tap[0];
 
   denom = r * r * r + gamma;
   denom = pow(denom,0.3333333333333);
 
   return Taper * EV_TO_KCAL_PER_MOL / denom;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int FixQEqReax::CG( double *b, double *x )
 {
   int  i, j;
   double tmp, alpha, beta, b_norm;
   double sig_old, sig_new, sig0;
 
   pack_flag = 1;
   sparse_matvec( &H, x, q );
   comm->reverse_comm_fix( this ); //Coll_Vector( q );
 
   vector_sum( r , 1.,  b, -1., q, n );
   for( j = 0; j < n; ++j )
     d[j] = r[j] * Hdia_inv[j]; //pre-condition
 
   b_norm = parallel_norm( b, n );
   sig_new = parallel_dot( r, d, n );
   sig0 = sig_new;
 
   for( i = 1; i < 100 && sqrt(sig_new) / b_norm > tolerance; ++i ) {
     comm->forward_comm_fix(this); //Dist_vector( d );
     sparse_matvec( &H, d, q );
     comm->reverse_comm_fix(this); //Coll_vector( q );
-    
+
     tmp = parallel_dot( d, q, n );
     alpha = sig_new / tmp;
     //  comm->me, i, parallel_norm( d, n ), parallel_norm( q, n ), tmp );
-    
+
     vector_add( x, alpha, d, n );
     vector_add( r, -alpha, q, n );
-    
+
     // pre-conditioning
     for( j = 0; j < n; ++j )
       p[j] = r[j] * Hdia_inv[j];
-    
+
     sig_old = sig_new;
     sig_new = parallel_dot( r, p, n );
-    
+
 
     beta = sig_new / sig_old;
     vector_sum( d, 1., p, beta, d, n );
   }
 
   if (i >= 100 && comm->me == 0)
     error->warning(FLERR,"Fix qeq/reax CG convergence failed");
 
   return i;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::sparse_matvec( sparse_matrix *A, double *x, double *b )
 {
   int i, j, itr_j;
 
   for( i = 0; i < n; ++i )
     b[i] = eta[ atom->type[i] ] * x[i];
   for( i = n; i < N; ++i )
     b[i] = 0;
-  
+
   for( i = 0; i < n; ++i ) {
     for( itr_j=A->firstnbr[i]; itr_j<A->firstnbr[i]+A->numnbrs[i]; itr_j++) {
       j = A->jlist[itr_j];
       b[i] += A->val[itr_j] * x[j];
       b[j] += A->val[itr_j] * x[i];
     }
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::calculate_Q()
 {
   int i, k;
   double u, s_sum, t_sum;
   double *q = atom->q;
 
   s_sum = parallel_vector_acc( s, n );
   t_sum = parallel_vector_acc( t, n);
   u = s_sum / t_sum;
-  
+
   for( i = 0; i < n; ++i ) {
     q[i] = s[i] - u * t[i];
-  
+
     /* backup s & t */
     for( k = 4; k > 0; --k ) {
       s_hist[i][k] = s_hist[i][k-1];
       t_hist[i][k] = t_hist[i][k-1];
     }
     s_hist[i][0] = s[i];
     t_hist[i][0] = t[i];
   }
 
   pack_flag = 4;
   comm->forward_comm_fix( this ); //Dist_vector( atom->q );
 }
 
 /* ---------------------------------------------------------------------- */
 
-int FixQEqReax::pack_comm(int n, int *list, double *buf, 
-			  int pbc_flag, int *pbc)
+int FixQEqReax::pack_comm(int n, int *list, double *buf,
+                          int pbc_flag, int *pbc)
 {
   int m;
 
-  if( pack_flag == 1) 
+  if( pack_flag == 1)
     for(m = 0; m < n; m++) buf[m] = d[list[m]];
   else if( pack_flag == 2 )
     for(m = 0; m < n; m++) buf[m] = s[list[m]];
   else if( pack_flag == 3 )
     for(m = 0; m < n; m++) buf[m] = t[list[m]];
   else if( pack_flag == 4 )
     for(m = 0; m < n; m++) buf[m] = atom->q[list[m]];
 
   return 1;
 }
- 
+
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::unpack_comm(int n, int first, double *buf)
 {
   int i, m;
-  
-  if( pack_flag == 1) 
+
+  if( pack_flag == 1)
     for(m = 0, i = first; m < n; m++, i++) d[i] = buf[m];
-  else if( pack_flag == 2) 
+  else if( pack_flag == 2)
     for(m = 0, i = first; m < n; m++, i++) s[i] = buf[m];
-  else if( pack_flag == 3) 
+  else if( pack_flag == 3)
     for(m = 0, i = first; m < n; m++, i++) t[i] = buf[m];
-  else if( pack_flag == 4) 
+  else if( pack_flag == 4)
     for(m = 0, i = first; m < n; m++, i++) atom->q[i] = buf[m];
 }
- 
+
 /* ---------------------------------------------------------------------- */
 
 int FixQEqReax::pack_reverse_comm(int n, int first, double *buf)
 {
   int i, m;
   for(m = 0, i = first; m < n; m++, i++) buf[m] = q[i];
   return 1;
 }
- 
+
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::unpack_reverse_comm(int n, int *list, double *buf)
 {
   for(int m = 0; m < n; m++) q[list[m]] += buf[m];
 }
 
 /* ----------------------------------------------------------------------
    memory usage of local atom-based arrays
 ------------------------------------------------------------------------- */
 
 double FixQEqReax::memory_usage()
 {
   double bytes;
 
   bytes = atom->nmax*nprev*2 * sizeof(double); // s_hist & t_hist
   bytes += atom->nmax*11 * sizeof(double); // storage
   bytes += n_cap*2 * sizeof(int); // matrix...
   bytes += m_cap * sizeof(int);
-  bytes += m_cap * sizeof(double); 
+  bytes += m_cap * sizeof(double);
 
   return bytes;
 }
 
 /* ----------------------------------------------------------------------
    allocate fictitious charge arrays
 ------------------------------------------------------------------------- */
 
 void FixQEqReax::grow_arrays(int nmax)
 {
   memory->grow(s_hist,nmax,nprev,"qeq:s_hist");
   memory->grow(t_hist,nmax,nprev,"qeq:t_hist");
 }
 
 /* ----------------------------------------------------------------------
    copy values within fictitious charge arrays
 ------------------------------------------------------------------------- */
 
 void FixQEqReax::copy_arrays(int i, int j)
 {
   for (int m = 0; m < nprev; m++) {
     s_hist[j][m] = s_hist[i][m];
     t_hist[j][m] = t_hist[i][m];
   }
 }
 
 /* ----------------------------------------------------------------------
    pack values in local atom-based array for exchange with another proc
 ------------------------------------------------------------------------- */
 
 int FixQEqReax::pack_exchange(int i, double *buf)
 {
   for (int m = 0; m < nprev; m++) buf[m] = s_hist[i][m];
   for (int m = 0; m < nprev; m++) buf[nprev+m] = t_hist[i][m];
   return nprev*2;
 }
 
 /* ----------------------------------------------------------------------
    unpack values in local atom-based array from exchange with another proc
 ------------------------------------------------------------------------- */
 
 int FixQEqReax::unpack_exchange(int nlocal, double *buf)
 {
   for (int m = 0; m < nprev; m++) s_hist[nlocal][m] = buf[m];
   for (int m = 0; m < nprev; m++) t_hist[nlocal][m] = buf[nprev+m];
   return nprev*2;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::parallel_norm( double *v, int n )
 {
   int  i;
   double my_sum, norm_sqr;
 
   my_sum = 0;
   for( i = 0; i < n; ++i )
     my_sum += SQR( v[i] );
 
   MPI_Allreduce( &my_sum, &norm_sqr, 1, MPI_DOUBLE, MPI_SUM, world );
 
   return sqrt( norm_sqr );
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::parallel_dot( double *v1, double *v2, int n )
 {
   int  i;
   double my_dot, res;
 
   my_dot = 0;
   res = 0;
   for( i = 0; i < n; ++i )
     my_dot += v1[i] * v2[i];
 
   MPI_Allreduce( &my_dot, &res, 1, MPI_DOUBLE, MPI_SUM, world );
 
   return res;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::parallel_vector_acc( double *v, int n )
 {
   int  i;
   double my_acc, res;
 
   my_acc = 0;
   for( i = 0; i < n; ++i )
     my_acc += v[i];
 
   MPI_Allreduce( &my_acc, &res, 1, MPI_DOUBLE, MPI_SUM, world );
 
   return res;
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::norm( double* v1, int k )
 {
   double ret = 0;
-  
+
   for( --k; k>=0; --k )
     ret +=  ( v1[k] * v1[k] );
 
   return sqrt( ret );
 }
 
 /* ---------------------------------------------------------------------- */
 
-void FixQEqReax::vector_sum( double* dest, double c, double* v, 
-				double d, double* y, int k )
+void FixQEqReax::vector_sum( double* dest, double c, double* v,
+                                double d, double* y, int k )
 {
   for( --k; k>=0; --k )
     dest[k] = c * v[k] + d * y[k];
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::vector_scale( double* dest, double c, double* v, int k )
 {
   for( --k; k>=0; --k )
     dest[k] = c * v[k];
 }
 
 /* ---------------------------------------------------------------------- */
 
 double FixQEqReax::dot( double* v1, double* v2, int k )
 {
   double ret = 0;
-  
+
   for( --k; k>=0; --k )
     ret +=  v1[k] * v2[k];
 
   return ret;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void FixQEqReax::vector_add( double* dest, double c, double* v, int k )
 {
   for( --k; k>=0; --k )
     dest[k] += c * v[k];
 }
diff --git a/src/USER-REAXC/pair_reax_c.cpp b/src/USER-REAXC/pair_reax_c.cpp
index cddf6d8a9..47821b105 100644
--- a/src/USER-REAXC/pair_reax_c.cpp
+++ b/src/USER-REAXC/pair_reax_c.cpp
@@ -1,721 +1,721 @@
 /* ----------------------------------------------------------------------
    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
    http://lammps.sandia.gov, Sandia National Laboratories
    Steve Plimpton, sjplimp@sandia.gov
 
    Copyright (2003) Sandia Corporation.  Under the terms of Contract
    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
-   certain rights in this software.  This software is distributed under 
+   certain rights in this software.  This software is distributed under
    the GNU General Public License.
 
    See the README file in the top-level LAMMPS directory.
 ------------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
    Contributing author: Hasan Metin Aktulga, Purdue University
    (now at Lawrence Berkeley National Laboratory, hmaktulga@lbl.gov)
 
    Please cite the related publication:
    H. M. Aktulga, J. C. Fogarty, S. A. Pandit, A. Y. Grama,
    "Parallel Reactive Molecular Dynamics: Numerical Methods and
    Algorithmic Techniques", Parallel Computing, in press.
 ------------------------------------------------------------------------- */
 
 #include "pair_reax_c.h"
 #include "atom.h"
 #include "update.h"
 #include "force.h"
 #include "comm.h"
 #include "neighbor.h"
 #include "neigh_list.h"
 #include "neigh_request.h"
 #include "modify.h"
 #include "fix.h"
 #include "fix_reax_c.h"
 #include "memory.h"
 #include "error.h"
 
 #include "reaxc_types.h"
 #include "reaxc_allocate.h"
 #include "reaxc_control.h"
 #include "reaxc_ffield.h"
 #include "reaxc_forces.h"
 #include "reaxc_init_md.h"
 #include "reaxc_io_tools.h"
 #include "reaxc_list.h"
 #include "reaxc_lookup.h"
 #include "reaxc_reset_tools.h"
 #include "reaxc_traj.h"
 #include "reaxc_vector.h"
 #include "fix_reaxc_bonds.h"
 
 using namespace LAMMPS_NS;
 
 /* ---------------------------------------------------------------------- */
 
 PairReaxC::PairReaxC(LAMMPS *lmp) : Pair(lmp)
 {
   single_enable = 0;
   restartinfo = 0;
   one_coeff = 1;
   ghostneigh = 1;
 
   system = (reax_system *)
     memory->smalloc(sizeof(reax_system),"reax:system");
-  control = (control_params *) 
+  control = (control_params *)
     memory->smalloc(sizeof(control_params),"reax:control");
   data = (simulation_data *)
     memory->smalloc(sizeof(simulation_data),"reax:data");
   workspace = (storage *)
     memory->smalloc(sizeof(storage),"reax:storage");
-  lists = (reax_list *) 
+  lists = (reax_list *)
     memory->smalloc(LIST_N * sizeof(reax_list),"reax:lists");
   out_control = (output_controls *)
     memory->smalloc(sizeof(output_controls),"reax:out_control");
   mpi_data = (mpi_datatypes *)
     memory->smalloc(sizeof(mpi_datatypes),"reax:mpi");
 
   MPI_Comm_rank(world,&system->my_rank);
 
   system->my_coords[0] = 0;
   system->my_coords[1] = 0;
   system->my_coords[2] = 0;
   system->num_nbrs = 0;
   system->n = 0; // my atoms
   system->N = 0; // mine + ghosts
   system->bigN = 0;  // all atoms in the system
   system->local_cap = 0;
   system->total_cap = 0;
   system->gcell_cap = 0;
   system->bndry_cuts.ghost_nonb = 0;
   system->bndry_cuts.ghost_hbond = 0;
   system->bndry_cuts.ghost_bond = 0;
   system->bndry_cuts.ghost_cutoff = 0;
   system->my_atoms = NULL;
   system->pair_ptr = this;
 
   fix_reax = NULL;
 
   nextra = 14;
   pvector = new double[nextra];
 
   setup_flag = 0;
 
   fixbond_flag = fixspecies_flag = 0;
 }
 
 /* ---------------------------------------------------------------------- */
 
 PairReaxC::~PairReaxC()
 {
   if (fix_reax) modify->delete_fix("REAXC");
 
   if (setup_flag) {
     Close_Output_Files( system, control, out_control, mpi_data );
 
     // deallocate reax data-structures
 
     if( control->tabulate ) Deallocate_Lookup_Tables( system );
 
     if( control->hbond_cut > 0 )  Delete_List( lists+HBONDS, world );
     Delete_List( lists+BONDS, world );
     Delete_List( lists+THREE_BODIES, world );
     Delete_List( lists+FAR_NBRS, world );
     // fprintf( stderr, "3\n" );
 
 
     DeAllocate_Workspace( control, workspace );
     DeAllocate_System( system );
   }
   //fprintf( stderr, "4\n" );
-  
+
   memory->destroy( system );
   memory->destroy( control );
   memory->destroy( data );
   memory->destroy( workspace );
   memory->destroy( lists );
   memory->destroy( out_control );
   memory->destroy( mpi_data );
   //fprintf( stderr, "5\n" );
 
   // deallocate interface storage
   if( allocated ) {
     memory->destroy(setflag);
     memory->destroy(cutsq);
     memory->destroy(cutghost);
     delete [] map;
 
     delete [] chi;
     delete [] eta;
     delete [] gamma;
   }
 
   delete [] pvector;
 
   //fprintf( stderr, "6\n" );
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::allocate( )
 {
   allocated = 1;
   int n = atom->ntypes;
 
   memory->create(setflag,n+1,n+1,"pair:setflag");
   memory->create(cutsq,n+1,n+1,"pair:cutsq");
   memory->create(cutghost,n+1,n+1,"pair:cutghost");
   map = new int[n+1];
 
   chi = new double[n+1];
   eta = new double[n+1];
   gamma = new double[n+1];
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::settings(int narg, char **arg)
 {
   if (narg < 1) error->all(FLERR,"Illegal pair_style command");
 
   // read name of control file or use default controls
 
   if (strcmp(arg[0],"NULL") == 0) {
     strcpy( control->sim_name, "simulate" );
     control->ensemble = 0;
     out_control->energy_update_freq = 0;
     control->tabulate = 0;
 
     control->reneighbor = 1;
     control->vlist_cut = control->nonb_cut;
     control->bond_cut = 5.;
     control->hbond_cut = 7.50;
     control->thb_cut = 0.001;
     control->thb_cutsq = 0.00001;
-   
+
     out_control->write_steps = 0;
     out_control->traj_method = 0;
     strcpy( out_control->traj_title, "default_title" );
     out_control->atom_info = 0;
     out_control->bond_info = 0;
     out_control->angle_info = 0;
   } else Read_Control_File(arg[0], control, out_control);
 
   // default values
 
   qeqflag = 1;
   control->lgflag = 0;
 
   // process optional keywords
 
   int iarg = 1;
 
   while (iarg < narg) {
     if (strcmp(arg[iarg],"checkqeq") == 0) {
       if (iarg+2 > narg) error->all(FLERR,"Illegal pair_style reax/c command");
       if (strcmp(arg[iarg+1],"yes") == 0) qeqflag = 1;
       else if (strcmp(arg[iarg+1],"no") == 0) qeqflag = 0;
       else error->all(FLERR,"Illegal pair_style reax/c command");
       iarg += 2;
     } else if (strcmp(arg[iarg],"lgvdw") == 0) {
       if (iarg+2 > narg) error->all(FLERR,"Illegal pair_style reax/c command");
       if (strcmp(arg[iarg+1],"yes") == 0) control->lgflag = 1;
       else if (strcmp(arg[iarg+1],"no") == 0) control->lgflag = 0;
       else error->all(FLERR,"Illegal pair_style reax/c command");
       iarg += 2;
     } else error->all(FLERR,"Illegal pair_style reax/c command");
   }
 
   // LAMMPS is responsible for generating nbrs
 
   control->reneighbor = 1;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::coeff( int nargs, char **args )
 {
   if (!allocated) allocate();
 
   if (nargs != 3 + atom->ntypes)
     error->all(FLERR,"Incorrect args for pair coefficients");
 
   // insure I,J args are * *
 
   if (strcmp(args[0],"*") != 0 || strcmp(args[1],"*") != 0)
     error->all(FLERR,"Incorrect args for pair coefficients");
 
   // read ffield file
 
   Read_Force_Field(args[2], &(system->reax_param), control);
- 
+
   // read args that map atom types to elements in potential file
   // map[i] = which element the Ith atom type is, -1 if NULL
 
   int itmp;
   int nreax_types = system->reax_param.num_atom_types;
   for (int i = 3; i < nargs; i++) {
     if (strcmp(args[i],"NULL") == 0) {
       map[i-2] = -1;
       continue;
     }
 
     itmp = atoi(args[i]) - 1;
     map[i-2] = itmp;
 
     // error check
 
     if (itmp < 0 || itmp >= nreax_types)
       error->all(FLERR,"Non-existent ReaxFF type");
 
   }
 
   int n = atom->ntypes;
 
   int count = 0;
   for (int i = 1; i <= n; i++)
     for (int j = i; j <= n; j++) {
       setflag[i][j] = 1;
       count++;
     }
-    
+
   if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::init_style( )
 {
   if (!atom->q_flag) error->all(FLERR,"Pair reax/c requires atom attribute q");
 
   // firstwarn = 1;
 
   int iqeq;
   for (iqeq = 0; iqeq < modify->nfix; iqeq++)
     if (strcmp(modify->fix[iqeq]->style,"qeq/reax") == 0) break;
-  if (iqeq == modify->nfix && qeqflag == 1) 
+  if (iqeq == modify->nfix && qeqflag == 1)
     error->all(FLERR,"Pair reax/c requires use of fix qeq/reax");
 
   system->n = atom->nlocal; // my atoms
   system->N = atom->nlocal + atom->nghost; // mine + ghosts
   system->bigN = static_cast<int> (atom->natoms);  // all atoms in the system
   system->wsize = comm->nprocs;
 
   system->big_box.V = 0;
-  system->big_box.box_norms[0] = 0; 
-  system->big_box.box_norms[1] = 0; 
+  system->big_box.box_norms[0] = 0;
+  system->big_box.box_norms[1] = 0;
   system->big_box.box_norms[2] = 0;
 
   if (atom->tag_enable == 0)
     error->all(FLERR,"Pair style reax/c requires atom IDs");
   if (force->newton_pair == 0)
     error->all(FLERR,"Pair style reax/c requires newton pair on");
 
   // need a half neighbor list w/ Newton off and ghost neighbors
   // built whenever re-neighboring occurs
 
   int irequest = neighbor->request(this);
   neighbor->requests[irequest]->newton = 2;
   neighbor->requests[irequest]->ghost = 1;
 
   cutmax = MAX3(control->nonb_cut, control->hbond_cut, 2*control->bond_cut);
 
   for( int i = 0; i < LIST_N; ++i )
     lists[i].allocated = 0;
 
   if (fix_reax == NULL) {
     char **fixarg = new char*[3];
     fixarg[0] = (char *) "REAXC";
     fixarg[1] = (char *) "all";
     fixarg[2] = (char *) "REAXC";
     modify->add_fix(3,fixarg);
     delete [] fixarg;
     fix_reax = (FixReaxC *) modify->fix[modify->nfix-1];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::setup( )
 {
   int oldN;
 
   system->n = atom->nlocal; // my atoms
   system->N = atom->nlocal + atom->nghost; // mine + ghosts
   oldN = system->N;
   system->bigN = static_cast<int> (atom->natoms);  // all atoms in the system
 
   if (setup_flag == 0) {
 
     setup_flag = 1;
-    
+
     int *num_bonds = fix_reax->num_bonds;
     int *num_hbonds = fix_reax->num_hbonds;
 
     control->vlist_cut = neighbor->cutneighmax;
 
     // determine the local and total capacity
 
     system->local_cap = MAX( (int)(system->n * SAFE_ZONE), MIN_CAP );
     system->total_cap = MAX( (int)(system->N * SAFE_ZONE), MIN_CAP );
 
     // initialize my data structures
 
     PreAllocate_Space( system, control, workspace, world );
     write_reax_atoms();
-    
+
     int num_nbrs = estimate_reax_lists();
-    if(!Make_List(system->total_cap, num_nbrs, TYP_FAR_NEIGHBOR, 
-		  lists+FAR_NBRS, world))
+    if(!Make_List(system->total_cap, num_nbrs, TYP_FAR_NEIGHBOR,
+                  lists+FAR_NBRS, world))
       error->all(FLERR,"Pair reax/c problem in far neighbor list");
-  
+
     write_reax_lists();
-    Initialize( system, control, data, workspace, &lists, out_control, 
-		mpi_data, world );
+    Initialize( system, control, data, workspace, &lists, out_control,
+                mpi_data, world );
     for( int k = 0; k < system->N; ++k ) {
       num_bonds[k] = system->my_atoms[k].num_bonds;
       num_hbonds[k] = system->my_atoms[k].num_hbonds;
     }
 
   } else {
 
     // fill in reax datastructures
 
     write_reax_atoms();
 
     // reset the bond list info for new atoms
 
     for(int k = oldN; k < system->N; ++k)
       Set_End_Index( k, Start_Index( k, lists+BONDS ), lists+BONDS );
-    
+
     // check if I need to shrink/extend my data-structs
 
     ReAllocate( system, control, data, workspace, &lists, mpi_data );
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 double PairReaxC::init_one(int i, int j)
 {
   cutghost[i][j] = cutghost[j][i] = cutmax;
   return cutmax;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::compute(int eflag, int vflag)
 {
   double evdwl,ecoul;
   double t_start, t_end;
 
   // communicate num_bonds once every reneighboring
   // 2 num arrays stored by fix, grab ptr to them
 
   if (neighbor->ago == 0) comm->forward_comm_fix(fix_reax);
   int *num_bonds = fix_reax->num_bonds;
   int *num_hbonds = fix_reax->num_hbonds;
 
   evdwl = ecoul = 0.0;
   if (eflag || vflag) ev_setup(eflag,vflag);
   else ev_unset();
 
 /*  if ((eflag_atom || vflag_atom) && firstwarn) {
     firstwarn = 0;
-    if (comm->me == 0) 
+    if (comm->me == 0)
       error->warning(FLERR,"Pair reax/c cannot yet compute "
-		     "per-atom energy or stress");
+                     "per-atom energy or stress");
   } */
 
   if (vflag_global) control->virial = 1;
   else control->virial = 0;
 
   system->n = atom->nlocal; // my atoms
   system->N = atom->nlocal + atom->nghost; // mine + ghosts
   system->bigN = static_cast<int> (atom->natoms);  // all atoms in the system
 
   system->big_box.V = 0;
-  system->big_box.box_norms[0] = 0; 
-  system->big_box.box_norms[1] = 0; 
+  system->big_box.box_norms[0] = 0;
+  system->big_box.box_norms[1] = 0;
   system->big_box.box_norms[2] = 0;
   if( comm->me == 0 ) t_start = MPI_Wtime();
 
   // setup data structures
 
   setup();
-  
+
   Reset( system, control, data, workspace, &lists, world );
   workspace->realloc.num_far = write_reax_lists();
   // timing for filling in the reax lists
   if( comm->me == 0 ) {
     t_end = MPI_Wtime();
     data->timing.nbrs = t_end - t_start;
   }
 
   // forces
 
   Compute_Forces(system,control,data,workspace,&lists,out_control,mpi_data);
   read_reax_forces();
 
   for(int k = 0; k < system->N; ++k) {
     num_bonds[k] = system->my_atoms[k].num_bonds;
     num_hbonds[k] = system->my_atoms[k].num_hbonds;
   }
 
   // energies and pressure
 
   if (eflag_global) {
     evdwl += data->my_en.e_bond;
     evdwl += data->my_en.e_ov;
     evdwl += data->my_en.e_un;
     evdwl += data->my_en.e_lp;
     evdwl += data->my_en.e_ang;
     evdwl += data->my_en.e_pen;
     evdwl += data->my_en.e_coa;
     evdwl += data->my_en.e_hb;
     evdwl += data->my_en.e_tor;
     evdwl += data->my_en.e_con;
     evdwl += data->my_en.e_vdW;
 
     ecoul += data->my_en.e_ele;
     ecoul += data->my_en.e_pol;
 
     // eng_vdwl += evdwl;
     // eng_coul += ecoul;
 
     // Store the different parts of the energy
     // in a list for output by compute pair command
 
-    pvector[0] = data->my_en.e_bond;   
+    pvector[0] = data->my_en.e_bond;
     pvector[1] = data->my_en.e_ov + data->my_en.e_un;
     pvector[2] = data->my_en.e_lp;
     pvector[3] = 0.0;
     pvector[4] = data->my_en.e_ang;
     pvector[5] = data->my_en.e_pen;
     pvector[6] = data->my_en.e_coa;
     pvector[7] = data->my_en.e_hb;
     pvector[8] = data->my_en.e_tor;
     pvector[9] = data->my_en.e_con;
     pvector[10] = data->my_en.e_vdW;
     pvector[11] = data->my_en.e_ele;
     pvector[12] = 0.0;
     pvector[13] = data->my_en.e_pol;
   }
 
   if (vflag_fdotr) virial_fdotr_compute();
 
 // #if defined(LOG_PERFORMANCE)
 //   if( comm->me == 0 && fix_qeq != NULL ) {
 //     data->timing.s_matvecs += fix_qeq->matvecs;
 //     data->timing.qEq += fix_qeq->qeq_time;
 //   }
 // #endif
 
 // Set internal timestep counter to that of LAMMPS
 
   data->step = update->ntimestep;
 
   Output_Results( system, control, data, &lists, out_control, mpi_data );
 
-  if(fixbond_flag) 
-	  fixbond( system, control, data, &lists, out_control, mpi_data );
+  if(fixbond_flag)
+          fixbond( system, control, data, &lists, out_control, mpi_data );
 
-  if(fixspecies_flag) 
-	  fixspecies( system, control, data, &lists, out_control, mpi_data );
+  if(fixspecies_flag)
+          fixspecies( system, control, data, &lists, out_control, mpi_data );
 
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::write_reax_atoms()
 {
   int *num_bonds = fix_reax->num_bonds;
   int *num_hbonds = fix_reax->num_hbonds;
-  
+
   for( int i = 0; i < system->N; ++i ){
     system->my_atoms[i].orig_id = atom->tag[i];
     system->my_atoms[i].type = map[atom->type[i]];
     system->my_atoms[i].x[0] = atom->x[i][0];
     system->my_atoms[i].x[1] = atom->x[i][1];
     system->my_atoms[i].x[2] = atom->x[i][2];
     system->my_atoms[i].q = atom->q[i];
     system->my_atoms[i].num_bonds = num_bonds[i];
     system->my_atoms[i].num_hbonds = num_hbonds[i];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void PairReaxC::get_distance( rvec xj, rvec xi, double *d_sqr, rvec *dvec )
 {
   (*dvec)[0] = xj[0] - xi[0];
   (*dvec)[1] = xj[1] - xi[1];
   (*dvec)[2] = xj[2] - xi[2];
   *d_sqr = SQR((*dvec)[0]) + SQR((*dvec)[1]) + SQR((*dvec)[2]);
 }
 
 /* ---------------------------------------------------------------------- */
 
-void PairReaxC::set_far_nbr( far_neighbor_data *fdest, 
-			      int j, double d, rvec dvec )
+void PairReaxC::set_far_nbr( far_neighbor_data *fdest,
+                              int j, double d, rvec dvec )
 {
   fdest->nbr = j;
   fdest->d = d;
   rvec_Copy( fdest->dvec, dvec );
   ivec_MakeZero( fdest->rel_box );
 }
 
 /* ---------------------------------------------------------------------- */
 
 int PairReaxC::estimate_reax_lists()
 {
   int itr_i, itr_j, itr_g, i, j, g;
   int nlocal, nghost, num_nbrs, num_marked;
   int *ilist, *jlist, *numneigh, **firstneigh, *marked;
   double d_sqr, g_d_sqr;
   rvec dvec, g_dvec;
   double *dist, **x;
   reax_list *far_nbrs;
   far_neighbor_data *far_list;
 
   x = atom->x;
   nlocal = atom->nlocal;
   nghost = atom->nghost;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   far_nbrs = lists + FAR_NBRS;
   far_list = far_nbrs->select.far_nbr_list;
 
   num_nbrs = 0;
   num_marked = 0;
   marked = (int*) calloc( system->N, sizeof(int) );
   dist = (double*) calloc( system->N, sizeof(double) );
 
   int inum = list->inum;
   int gnum = list->gnum;
   int numall = inum + gnum;
 
   for( itr_i = 0; itr_i < inum+gnum; ++itr_i ){
     i = ilist[itr_i];
     marked[i] = 1;
     ++num_marked;
     jlist = firstneigh[i];
 
     for( itr_j = 0; itr_j < numneigh[i]; ++itr_j ){
       j = jlist[itr_j];
       j &= NEIGHMASK;
       get_distance( x[j], x[i], &d_sqr, &dvec );
-      
+
       if( d_sqr <= SQR(control->nonb_cut) )
-	++num_nbrs;
+        ++num_nbrs;
     }
   }
 
   free( marked );
   free( dist );
 
   return static_cast<int> (MAX( num_nbrs*SAFE_ZONE, MIN_CAP*MIN_NBRS ));
 }
 
 /* ---------------------------------------------------------------------- */
 
 int PairReaxC::write_reax_lists()
 {
   int itr_i, itr_j, itr_g, i, j, g, flag;
   int nlocal, nghost, num_nbrs;
   int *ilist, *jlist, *numneigh, **firstneigh, *marked, *tag;
   double d_sqr, g_d, g_d_sqr;
   rvec dvec, g_dvec;
   double *dist, **x, SMALL = 0.0001;
   reax_list *far_nbrs;
   far_neighbor_data *far_list;
 
   x = atom->x;
   tag = atom->tag;
   nlocal = atom->nlocal;
   nghost = atom->nghost;
   ilist = list->ilist;
   numneigh = list->numneigh;
   firstneigh = list->firstneigh;
 
   far_nbrs = lists + FAR_NBRS;
   far_list = far_nbrs->select.far_nbr_list;
 
-  num_nbrs = 0;  
+  num_nbrs = 0;
   marked = (int*) calloc( system->N, sizeof(int) );
   dist = (double*) calloc( system->N, sizeof(double) );
 
   int inum = list->inum;
   int gnum = list->gnum;
   int numall = inum + gnum;
 
   for( itr_i = 0; itr_i < inum+gnum; ++itr_i ){
     i = ilist[itr_i];
     marked[i] = 1;
     jlist = firstneigh[i];
     Set_Start_Index( i, num_nbrs, far_nbrs );
 
     for( itr_j = 0; itr_j < numneigh[i]; ++itr_j ){
       j = jlist[itr_j];
       j &= NEIGHMASK;
       get_distance( x[j], x[i], &d_sqr, &dvec );
 
       if( d_sqr <= (control->nonb_cut*control->nonb_cut) ){
         dist[j] = sqrt( d_sqr );
-	set_far_nbr( &far_list[num_nbrs], j, dist[j], dvec );
-	++num_nbrs;
+        set_far_nbr( &far_list[num_nbrs], j, dist[j], dvec );
+        ++num_nbrs;
       }
     }
     Set_End_Index( i, num_nbrs, far_nbrs );
   }
 
   free( marked );
   free( dist );
-  
+
   return num_nbrs;
 }
-  
+
 /* ---------------------------------------------------------------------- */
-  
+
 void PairReaxC::read_reax_forces()
 {
   for( int i = 0; i < system->N; ++i ) {
     system->my_atoms[i].f[0] = workspace->f[i][0];
     system->my_atoms[i].f[1] = workspace->f[i][1];
     system->my_atoms[i].f[2] = workspace->f[i][2];
 
     atom->f[i][0] = -workspace->f[i][0];
     atom->f[i][1] = -workspace->f[i][1];
     atom->f[i][2] = -workspace->f[i][2];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void *PairReaxC::extract(const char *str, int &dim)
 {
   dim = 1;
   if (strcmp(str,"chi") == 0 && chi) {
     for (int i = 1; i <= atom->ntypes; i++)
       if (map[i] >= 0) chi[i] = system->reax_param.sbp[map[i]].chi;
       else chi[i] = 0.0;
     return (void *) chi;
   }
   if (strcmp(str,"eta") == 0 && eta) {
     for (int i = 1; i <= atom->ntypes; i++)
       if (map[i] >= 0) eta[i] = system->reax_param.sbp[map[i]].eta;
       else eta[i] = 0.0;
     return (void *) eta;
   }
   if (strcmp(str,"gamma") == 0 && gamma) {
     for (int i = 1; i <= atom->ntypes; i++)
       if (map[i] >= 0) gamma[i] = system->reax_param.sbp[map[i]].gamma;
       else gamma[i] = 0.0;
     return (void *) gamma;
   }
   return NULL;
 }
 
 /* ---------------------------------------------------------------------- */
diff --git a/src/USER-REAXC/reaxc_nonbonded.cpp b/src/USER-REAXC/reaxc_nonbonded.cpp
index 691900554..b24495488 100644
--- a/src/USER-REAXC/reaxc_nonbonded.cpp
+++ b/src/USER-REAXC/reaxc_nonbonded.cpp
@@ -1,521 +1,521 @@
 /*----------------------------------------------------------------------
   PuReMD - Purdue ReaxFF Molecular Dynamics Program
 
   Copyright (2010) Purdue University
   Hasan Metin Aktulga, hmaktulga@lbl.gov
   Joseph Fogarty, jcfogart@mail.usf.edu
   Sagar Pandit, pandit@usf.edu
   Ananth Y Grama, ayg@cs.purdue.edu
 
   Please cite the related publication:
   H. M. Aktulga, J. C. Fogarty, S. A. Pandit, A. Y. Grama,
   "Parallel Reactive Molecular Dynamics: Numerical Methods and
   Algorithmic Techniques", Parallel Computing, in press.
 
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the GNU General Public License for more details:
   <http://www.gnu.org/licenses/>.
   ----------------------------------------------------------------------*/
 
 #include "pair_reax_c.h"
 #include "reaxc_types.h"
 #if defined(PURE_REAX)
 #include "nonbonded.h"
 #include "bond_orders.h"
 #include "list.h"
 #include "vector.h"
 #elif defined(LAMMPS_REAX)
 #include "reaxc_nonbonded.h"
 #include "reaxc_bond_orders.h"
 #include "reaxc_list.h"
 #include "reaxc_vector.h"
 #endif
 
 void vdW_Coulomb_Energy( reax_system *system, control_params *control,
                          simulation_data *data, storage *workspace,
                          reax_list **lists, output_controls *out_control )
 {
   int i, j, pj, natoms;
   int start_i, end_i, orig_i, orig_j, flag;
   real p_vdW1, p_vdW1i;
   real powr_vdW1, powgi_vdW1;
   real tmp, r_ij, fn13, exp1, exp2;
   real Tap, dTap, dfn13, CEvd, CEclmb, de_core;
   real dr3gamij_1, dr3gamij_3;
   real e_ele, e_vdW, e_core, SMALL = 0.0001;
   real e_lg, de_lg, r_ij5, r_ij6, re6;
   rvec temp, ext_press;
   two_body_parameters *twbp;
   far_neighbor_data *nbr_pj;
   reax_list *far_nbrs;
   // rtensor temp_rtensor, total_rtensor;
 
   // Tallying variables:
   real pe_vdw, f_tmp, delij[3];
 
   natoms = system->n;
   far_nbrs = (*lists) + FAR_NBRS;
   p_vdW1 = system->reax_param.gp.l[28];
   p_vdW1i = 1.0 / p_vdW1;
   e_core = 0;
   e_vdW = 0;
   e_lg = de_lg = 0.0;
 
   for( i = 0; i < natoms; ++i ) {
     start_i = Start_Index(i, far_nbrs);
     end_i   = End_Index(i, far_nbrs);
     orig_i  = system->my_atoms[i].orig_id;
     //fprintf( stderr, "i:%d, start_i: %d, end_i: %d\n", i, start_i, end_i );
 
     for( pj = start_i; pj < end_i; ++pj ) {
       nbr_pj = &(far_nbrs->select.far_nbr_list[pj]);
       j = nbr_pj->nbr;
       orig_j  = system->my_atoms[j].orig_id;
 
 #if defined(PURE_REAX)
       if( nbr_pj->d <= control->nonb_cut && (j < natoms || orig_i < orig_j) ) {
 #elif defined(LAMMPS_REAX)
       flag = 0;
       if(nbr_pj->d <= control->nonb_cut) {
         if (j < natoms) flag = 1;
         else if (orig_i < orig_j) flag = 1;
         else if (orig_i == orig_j) {
           if (nbr_pj->dvec[2] > SMALL) flag = 1;
           else if (fabs(nbr_pj->dvec[2]) < SMALL) {
             if (nbr_pj->dvec[1] > SMALL) flag = 1;
             else if (fabs(nbr_pj->dvec[1]) < SMALL && nbr_pj->dvec[0] > SMALL)
               flag = 1;
           }
         }
       }
 
       if (flag) {
 #endif
 
       r_ij = nbr_pj->d;
       twbp = &(system->reax_param.tbp[ system->my_atoms[i].type ]
                                        [ system->my_atoms[j].type ]);
 
       /* Calculate Taper and its derivative */
       // Tap = nbr_pj->Tap;   -- precomputed during compte_H
       Tap = workspace->Tap[7] * r_ij + workspace->Tap[6];
       Tap = Tap * r_ij + workspace->Tap[5];
       Tap = Tap * r_ij + workspace->Tap[4];
       Tap = Tap * r_ij + workspace->Tap[3];
       Tap = Tap * r_ij + workspace->Tap[2];
       Tap = Tap * r_ij + workspace->Tap[1];
       Tap = Tap * r_ij + workspace->Tap[0];
 
       dTap = 7*workspace->Tap[7] * r_ij + 6*workspace->Tap[6];
       dTap = dTap * r_ij + 5*workspace->Tap[5];
       dTap = dTap * r_ij + 4*workspace->Tap[4];
       dTap = dTap * r_ij + 3*workspace->Tap[3];
       dTap = dTap * r_ij + 2*workspace->Tap[2];
       dTap += workspace->Tap[1]/r_ij;
 
       /*vdWaals Calculations*/
       if(system->reax_param.gp.vdw_type==1 || system->reax_param.gp.vdw_type==3)
         { // shielding
           powr_vdW1 = pow(r_ij, p_vdW1);
           powgi_vdW1 = pow( 1.0 / twbp->gamma_w, p_vdW1);
 
           fn13 = pow( powr_vdW1 + powgi_vdW1, p_vdW1i );
           exp1 = exp( twbp->alpha * (1.0 - fn13 / twbp->r_vdW) );
           exp2 = exp( 0.5 * twbp->alpha * (1.0 - fn13 / twbp->r_vdW) );
 
           e_vdW = twbp->D * (exp1 - 2.0 * exp2);
           data->my_en.e_vdW += Tap * e_vdW;
 
           dfn13 = pow( powr_vdW1 + powgi_vdW1, p_vdW1i - 1.0) *
             pow(r_ij, p_vdW1 - 2.0);
 
           CEvd = dTap * e_vdW -
             Tap * twbp->D * (twbp->alpha / twbp->r_vdW) * (exp1 - exp2) * dfn13;
         }
       else{ // no shielding
         exp1 = exp( twbp->alpha * (1.0 - r_ij / twbp->r_vdW) );
         exp2 = exp( 0.5 * twbp->alpha * (1.0 - r_ij / twbp->r_vdW) );
 
         e_vdW = twbp->D * (exp1 - 2.0 * exp2);
         data->my_en.e_vdW += Tap * e_vdW;
 
         CEvd = dTap * e_vdW -
           Tap * twbp->D * (twbp->alpha / twbp->r_vdW) * (exp1 - exp2) / r_ij;
       }
 
       if(system->reax_param.gp.vdw_type==2 || system->reax_param.gp.vdw_type==3)
         { // innner wall
           e_core = twbp->ecore * exp(twbp->acore * (1.0-(r_ij/twbp->rcore)));
           data->my_en.e_vdW += Tap * e_core;
 
           de_core = -(twbp->acore/twbp->rcore) * e_core;
           CEvd += dTap * e_core + Tap * de_core / r_ij;
 
           //  lg correction, only if lgvdw is yes
           if (control->lgflag) {
             r_ij5 = pow( r_ij, 5.0 );
             r_ij6 = pow( r_ij, 6.0 );
             re6 = pow( twbp->lgre, 6.0 );
             e_lg = -(twbp->lgcij/( r_ij6 + re6 ));
             data->my_en.e_vdW += Tap * e_lg;
 
             de_lg = -6.0 * e_lg *  r_ij5 / ( r_ij6 + re6 ) ;
             CEvd += dTap * e_lg + Tap * de_lg / r_ij;
           }
 
         }
 
       /*Coulomb Calculations*/
       dr3gamij_1 = ( r_ij * r_ij * r_ij + twbp->gamma );
       dr3gamij_3 = pow( dr3gamij_1 , 0.33333333333333 );
 
       tmp = Tap / dr3gamij_3;
       data->my_en.e_ele += e_ele =
         C_ele * system->my_atoms[i].q * system->my_atoms[j].q * tmp;
 
       CEclmb = C_ele * system->my_atoms[i].q * system->my_atoms[j].q *
         ( dTap -  Tap * r_ij / dr3gamij_1 ) / dr3gamij_3;
 
       /* tally into per-atom energy */
       if( system->pair_ptr->evflag || system->pair_ptr->vflag_atom) {
         pe_vdw = Tap * (e_vdW + e_core + e_lg);
         rvec_ScaledSum( delij, 1., system->my_atoms[i].x,
                               -1., system->my_atoms[j].x );
         f_tmp = -(CEvd + CEclmb);
         system->pair_ptr->ev_tally(i,j,natoms,1,pe_vdw,e_ele,
                         f_tmp,delij[0],delij[1],delij[2]);
       }
 
       /* fprintf(stderr, "%5d %5d %10.6f %10.6f\n",
         MIN( system->my_atoms[i].orig_id, system->my_atoms[j].orig_id ),
         MAX( system->my_atoms[i].orig_id, system->my_atoms[j].orig_id ),
         CEvd, CEclmb );                 */
 
       if( control->virial == 0 ) {
         rvec_ScaledAdd( workspace->f[i], -(CEvd + CEclmb), nbr_pj->dvec );
         rvec_ScaledAdd( workspace->f[j], +(CEvd + CEclmb), nbr_pj->dvec );
       }
       else { /* NPT, iNPT or sNPT */
         /* for pressure coupling, terms not related to bond order
            derivatives are added directly into pressure vector/tensor */
         rvec_Scale( temp, CEvd + CEclmb, nbr_pj->dvec );
 
         rvec_ScaledAdd( workspace->f[i], -1., temp );
         rvec_Add( workspace->f[j], temp );
 
         rvec_iMultiply( ext_press, nbr_pj->rel_box, temp );
         rvec_Add( data->my_ext_press, ext_press );
 
         /* fprintf( stderr, "nonbonded(%d,%d): rel_box (%f %f %f)
           force(%f %f %f) ext_press (%12.6f %12.6f %12.6f)\n",
           i, j, nbr_pj->rel_box[0], nbr_pj->rel_box[1], nbr_pj->rel_box[2],
           temp[0], temp[1], temp[2],
           data->ext_press[0], data->ext_press[1], data->ext_press[2] );          */
       }
 
 #ifdef TEST_ENERGY
       // fprintf( out_control->evdw,
       // "%12.9f%12.9f%12.9f%12.9f%12.9f%12.9f%12.9f%12.9f\n",
       // workspace->Tap[7],workspace->Tap[6],workspace->Tap[5],
       // workspace->Tap[4],workspace->Tap[3],workspace->Tap[2],
       // workspace->Tap[1], Tap );
       //fprintf( out_control->evdw, "%6d%6d%24.15e%24.15e%24.15e\n",
       fprintf( out_control->evdw, "%6d%6d%12.4f%12.4f%12.4f\n",
                system->my_atoms[i].orig_id, system->my_atoms[j].orig_id,
                r_ij, e_vdW, data->my_en.e_vdW );
       //fprintf(out_control->ecou,"%6d%6d%24.15e%24.15e%24.15e%24.15e%24.15e\n",
       fprintf( out_control->ecou, "%6d%6d%12.4f%12.4f%12.4f%12.4f%12.4f\n",
                system->my_atoms[i].orig_id, system->my_atoms[j].orig_id,
                r_ij, system->my_atoms[i].q, system->my_atoms[j].q,
                e_ele, data->my_en.e_ele );
 #endif
 #ifdef TEST_FORCES
       rvec_ScaledAdd( workspace->f_vdw[i], -CEvd, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_vdw[j], +CEvd, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_ele[i], -CEclmb, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_ele[j], +CEclmb, nbr_pj->dvec );
 #endif
       }
     }
   }
 
 #if defined(DEBUG)
   fprintf( stderr, "nonbonded: ext_press (%12.6f %12.6f %12.6f)\n",
            data->ext_press[0], data->ext_press[1], data->ext_press[2] );
   MPI_Barrier( MPI_COMM_WORLD );
 #endif
 
   Compute_Polarization_Energy( system, data );
 }
 
 
 
 void Tabulated_vdW_Coulomb_Energy( reax_system *system,control_params *control,
                                    simulation_data *data, storage *workspace,
                                    reax_list **lists,
                                    output_controls *out_control )
 {
   int i, j, pj, r, natoms;
   int type_i, type_j, tmin, tmax;
   int start_i, end_i, orig_i, orig_j, flag;
   real r_ij, base, dif;
   real e_vdW, e_ele;
   real CEvd, CEclmb, SMALL = 0.0001;
   real f_tmp, delij[3];
 
   rvec temp, ext_press;
   far_neighbor_data *nbr_pj;
   reax_list *far_nbrs;
   LR_lookup_table *t;
 
   natoms = system->n;
   far_nbrs = (*lists) + FAR_NBRS;
 
   e_ele = e_vdW = 0;
 
   for( i = 0; i < natoms; ++i ) {
     type_i  = system->my_atoms[i].type;
     start_i = Start_Index(i,far_nbrs);
     end_i   = End_Index(i,far_nbrs);
     orig_i  = system->my_atoms[i].orig_id;
 
     for( pj = start_i; pj < end_i; ++pj ) {
       nbr_pj = &(far_nbrs->select.far_nbr_list[pj]);
       j = nbr_pj->nbr;
       orig_j  = system->my_atoms[j].orig_id;
 
 #if defined(PURE_REAX)
       if( nbr_pj->d <= control->nonb_cut && (j < natoms || orig_i < orig_j) ) {
 #elif defined(LAMMPS_REAX)
       flag = 0;
       if(nbr_pj->d <= control->nonb_cut) {
         if (j < natoms) flag = 1;
         else if (orig_i < orig_j) flag = 1;
         else if (orig_i == orig_j) {
           if (nbr_pj->dvec[2] > SMALL) flag = 1;
           else if (fabs(nbr_pj->dvec[2]) < SMALL) {
             if (nbr_pj->dvec[1] > SMALL) flag = 1;
             else if (fabs(nbr_pj->dvec[1]) < SMALL && nbr_pj->dvec[0] > SMALL)
               flag = 1;
           }
         }
       }
 
       if (flag) {
 #endif
       j = nbr_pj->nbr;
       type_j = system->my_atoms[j].type;
 
       r_ij   = nbr_pj->d;
       tmin  = MIN( type_i, type_j );
       tmax  = MAX( type_i, type_j );
       t = &( LR[tmin][tmax] );
       //t = &( LR[type_i][type_j] );
 
       /* Cubic Spline Interpolation */
       r = (int)(r_ij * t->inv_dx);
       if( r == 0 )  ++r;
       base = (real)(r+1) * t->dx;
       dif = r_ij - base;
       //fprintf(stderr, "r: %f, i: %d, base: %f, dif: %f\n", r, i, base, dif);
 
       e_vdW = ((t->vdW[r].d*dif + t->vdW[r].c)*dif + t->vdW[r].b)*dif +
-	t->vdW[r].a;
+        t->vdW[r].a;
 
       e_ele = ((t->ele[r].d*dif + t->ele[r].c)*dif + t->ele[r].b)*dif +
-	t->ele[r].a;
+        t->ele[r].a;
       e_ele *= system->my_atoms[i].q * system->my_atoms[j].q;
-      
+
       data->my_en.e_vdW += e_vdW;
       data->my_en.e_ele += e_ele;
 
       CEvd = ((t->CEvd[r].d*dif + t->CEvd[r].c)*dif + t->CEvd[r].b)*dif +
         t->CEvd[r].a;
 
       CEclmb = ((t->CEclmb[r].d*dif+t->CEclmb[r].c)*dif+t->CEclmb[r].b)*dif +
         t->CEclmb[r].a;
       CEclmb *= system->my_atoms[i].q * system->my_atoms[j].q;
 
 
       /* tally into per-atom energy */
       if( system->pair_ptr->evflag || system->pair_ptr->vflag_atom) {
         rvec_ScaledSum( delij, 1., system->my_atoms[i].x,
                               -1., system->my_atoms[j].x );
         f_tmp = -(CEvd + CEclmb);
         system->pair_ptr->ev_tally(i,j,natoms,1,e_vdW,e_ele,
                         f_tmp,delij[0],delij[1],delij[2]);
       }
 
       if( control->virial == 0 ) {
         rvec_ScaledAdd( workspace->f[i], -(CEvd + CEclmb), nbr_pj->dvec );
         rvec_ScaledAdd( workspace->f[j], +(CEvd + CEclmb), nbr_pj->dvec );
       }
       else { // NPT, iNPT or sNPT
         /* for pressure coupling, terms not related to bond order derivatives
            are added directly into pressure vector/tensor */
         rvec_Scale( temp, CEvd + CEclmb, nbr_pj->dvec );
 
         rvec_ScaledAdd( workspace->f[i], -1., temp );
         rvec_Add( workspace->f[j], temp );
 
         rvec_iMultiply( ext_press, nbr_pj->rel_box, temp );
         rvec_Add( data->my_ext_press, ext_press );
       }
 
 #ifdef TEST_ENERGY
       //fprintf( out_control->evdw, "%6d%6d%24.15e%24.15e%24.15e\n",
       fprintf( out_control->evdw, "%6d%6d%12.4f%12.4f%12.4f\n",
                system->my_atoms[i].orig_id, system->my_atoms[j].orig_id,
                r_ij, e_vdW, data->my_en.e_vdW );
       //fprintf(out_control->ecou,"%6d%6d%24.15e%24.15e%24.15e%24.15e%24.15e\n",
       fprintf( out_control->ecou, "%6d%6d%12.4f%12.4f%12.4f%12.4f%12.4f\n",
                system->my_atoms[i].orig_id, system->my_atoms[j].orig_id,
                r_ij, system->my_atoms[i].q, system->my_atoms[j].q,
                e_ele, data->my_en.e_ele );
 #endif
 #ifdef TEST_FORCES
       rvec_ScaledAdd( workspace->f_vdw[i], -CEvd, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_vdw[j], +CEvd, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_ele[i], -CEclmb, nbr_pj->dvec );
       rvec_ScaledAdd( workspace->f_ele[j], +CEclmb, nbr_pj->dvec );
 #endif
       }
     }
   }
 
   Compute_Polarization_Energy( system, data );
 }
 
 
 
 void Compute_Polarization_Energy( reax_system *system, simulation_data *data )
 {
   int  i, type_i;
   real q, en_tmp;
 
   data->my_en.e_pol = 0.0;
   for( i = 0; i < system->n; i++ ) {
     q = system->my_atoms[i].q;
     type_i = system->my_atoms[i].type;
 
     en_tmp = KCALpMOL_to_EV * (system->reax_param.sbp[type_i].chi * q +
                 (system->reax_param.sbp[type_i].eta / 2.) * SQR(q));
     data->my_en.e_pol += en_tmp;
 
     /* tally into per-atom energy */
     if( system->pair_ptr->evflag)
       system->pair_ptr->ev_tally(i,i,system->n,1,0.0,en_tmp,0.0,0.0,0.0,0.0);
   }
 }
 
 void LR_vdW_Coulomb( reax_system *system, storage *workspace,
         control_params *control, int i, int j, real r_ij, LR_data *lr )
 {
   real p_vdW1 = system->reax_param.gp.l[28];
   real p_vdW1i = 1.0 / p_vdW1;
   real powr_vdW1, powgi_vdW1;
   real tmp, fn13, exp1, exp2;
   real Tap, dTap, dfn13;
   real dr3gamij_1, dr3gamij_3;
   real e_core, de_core;
   real e_lg, de_lg, r_ij5, r_ij6, re6;
   two_body_parameters *twbp;
 
   twbp = &(system->reax_param.tbp[i][j]);
   e_core = 0;
   de_core = 0;
   e_lg = de_lg = 0.0;
 
   /* calculate taper and its derivative */
   Tap = workspace->Tap[7] * r_ij + workspace->Tap[6];
   Tap = Tap * r_ij + workspace->Tap[5];
   Tap = Tap * r_ij + workspace->Tap[4];
   Tap = Tap * r_ij + workspace->Tap[3];
   Tap = Tap * r_ij + workspace->Tap[2];
   Tap = Tap * r_ij + workspace->Tap[1];
   Tap = Tap * r_ij + workspace->Tap[0];
 
   dTap = 7*workspace->Tap[7] * r_ij + 6*workspace->Tap[6];
   dTap = dTap * r_ij + 5*workspace->Tap[5];
   dTap = dTap * r_ij + 4*workspace->Tap[4];
   dTap = dTap * r_ij + 3*workspace->Tap[3];
   dTap = dTap * r_ij + 2*workspace->Tap[2];
   dTap += workspace->Tap[1]/r_ij;
 
   /*vdWaals Calculations*/
   if(system->reax_param.gp.vdw_type==1 || system->reax_param.gp.vdw_type==3)
     { // shielding
       powr_vdW1 = pow(r_ij, p_vdW1);
       powgi_vdW1 = pow( 1.0 / twbp->gamma_w, p_vdW1);
 
       fn13 = pow( powr_vdW1 + powgi_vdW1, p_vdW1i );
       exp1 = exp( twbp->alpha * (1.0 - fn13 / twbp->r_vdW) );
       exp2 = exp( 0.5 * twbp->alpha * (1.0 - fn13 / twbp->r_vdW) );
 
       lr->e_vdW = Tap * twbp->D * (exp1 - 2.0 * exp2);
 
       dfn13 = pow( powr_vdW1 + powgi_vdW1, p_vdW1i-1.0) * pow(r_ij, p_vdW1-2.0);
 
       lr->CEvd = dTap * twbp->D * (exp1 - 2.0 * exp2) -
         Tap * twbp->D * (twbp->alpha / twbp->r_vdW) * (exp1 - exp2) * dfn13;
     }
   else{ // no shielding
     exp1 = exp( twbp->alpha * (1.0 - r_ij / twbp->r_vdW) );
     exp2 = exp( 0.5 * twbp->alpha * (1.0 - r_ij / twbp->r_vdW) );
 
     lr->e_vdW = Tap * twbp->D * (exp1 - 2.0 * exp2);
     lr->CEvd = dTap * twbp->D * (exp1 - 2.0 * exp2) -
       Tap * twbp->D * (twbp->alpha / twbp->r_vdW) * (exp1 - exp2) / r_ij;
   }
 
   if(system->reax_param.gp.vdw_type==2 || system->reax_param.gp.vdw_type==3)
     { // innner wall
       e_core = twbp->ecore * exp(twbp->acore * (1.0-(r_ij/twbp->rcore)));
       lr->e_vdW += Tap * e_core;
 
       de_core = -(twbp->acore/twbp->rcore) * e_core;
       lr->CEvd += dTap * e_core + Tap * de_core / r_ij;
 
       //  lg correction, only if lgvdw is yes
       if (control->lgflag) {
         r_ij5 = pow( r_ij, 5.0 );
         r_ij6 = pow( r_ij, 6.0 );
         re6 = pow( twbp->lgre, 6.0 );
         e_lg = -(twbp->lgcij/( r_ij6 + re6 ));
         lr->e_vdW += Tap * e_lg;
 
         de_lg = -6.0 * e_lg *  r_ij5 / ( r_ij6 + re6 ) ;
         lr->CEvd += dTap * e_lg + Tap * de_lg/r_ij;
       }
 
     }
 
 
   /* Coulomb calculations */
   dr3gamij_1 = ( r_ij * r_ij * r_ij + twbp->gamma );
   dr3gamij_3 = pow( dr3gamij_1 , 0.33333333333333 );
 
   tmp = Tap / dr3gamij_3;
   lr->H = EV_to_KCALpMOL * tmp;
   lr->e_ele = C_ele * tmp;
   // fprintf( stderr,
   //    "i:%d(%d), j:%d(%d), gamma:%f, Tap:%f, dr3gamij_3:%f, qi: %f, qj: %f\n",
   //    i, system->my_atoms[i].type, j, system->my_atoms[j].type,
   //    twbp->gamma, Tap, dr3gamij_3,
   //    system->my_atoms[i].q, system->my_atoms[j].q );
 
   lr->CEclmb = C_ele * ( dTap -  Tap * r_ij / dr3gamij_1 ) / dr3gamij_3;
   // fprintf( stdout, "%d %d\t%g\t%g  %g\t%g  %g\t%g  %g\n",
   //    i+1, j+1, r_ij, e_vdW, CEvd * r_ij,
   //    system->my_atoms[i].q, system->my_atoms[j].q, e_ele, CEclmb * r_ij );
 
   // fprintf(stderr,"LR_Lookup: %3d %3d %5.3f-%8.5f %8.5f %8.5f %8.5f %8.5f\n",
   //   i, j, r_ij, lr->H, lr->e_vdW, lr->CEvd, lr->e_ele, lr->CEclmb ); */
 }
diff --git a/src/USER-SPH/atom_vec_meso.cpp b/src/USER-SPH/atom_vec_meso.cpp
index 6ca52f0f8..73cf49619 100644
--- a/src/USER-SPH/atom_vec_meso.cpp
+++ b/src/USER-SPH/atom_vec_meso.cpp
@@ -1,870 +1,870 @@
 /* ----------------------------------------------------------------------
  LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
  http://lammps.sandia.gov, Sandia National Laboratories
  Steve Plimpton, sjplimp@sandia.gov
 
  Copyright (2003) Sandia Corporation.  Under the terms of Contract
  DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
  certain rights in this software.  This software is distributed under
  the GNU General Public License.
 
  See the README file in the top-level LAMMPS directory.
  ------------------------------------------------------------------------- */
 
 #include "stdlib.h"
 #include "atom_vec_meso.h"
 #include "atom.h"
 #include "comm.h"
 #include "domain.h"
 #include "modify.h"
 #include "fix.h"
 #include "memory.h"
 #include "error.h"
 
 using namespace LAMMPS_NS;
 
 #define DELTA 10000
 
 /* ---------------------------------------------------------------------- */
 
 AtomVecMeso::AtomVecMeso(LAMMPS *lmp, int narg, char **arg) :
   AtomVec(lmp, narg, arg) {
   molecular = 0;
   mass_type = 1;
-  
+
   comm_x_only = 0; // we communicate not only x forward but also vest ...
   comm_f_only = 0; // we also communicate de and drho in reverse direction
   size_forward = 8; // 3 + rho + e + vest[3], that means we may only communicate 5 in hybrid
   size_reverse = 5; // 3 + drho + de
   size_border = 12; // 6 + rho + e + vest[3] + cv
   size_velocity = 3;
   size_data_atom = 8;
   size_data_vel = 4;
   xcol_data = 6;
-  
+
   atom->e_flag = 1;
   atom->rho_flag = 1;
   atom->cv_flag = 1;
   atom->vest_flag = 1;
 }
 
 /* ----------------------------------------------------------------------
    grow atom arrays
    n = 0 grows arrays by DELTA
    n > 0 allocates arrays to size n
    ------------------------------------------------------------------------- */
 
 void AtomVecMeso::grow(int n) {
   if (n == 0)
     nmax += DELTA;
   else
     nmax = n;
   atom->nmax = nmax;
   if (nmax < 0 || nmax > MAXSMALLINT)
     error->one(FLERR,"Per-processor system is too big");
-  
+
   tag = memory->grow(atom->tag, nmax, "atom:tag");
   type = memory->grow(atom->type, nmax, "atom:type");
   mask = memory->grow(atom->mask, nmax, "atom:mask");
   image = memory->grow(atom->image, nmax, "atom:image");
   x = memory->grow(atom->x, nmax, 3, "atom:x");
   v = memory->grow(atom->v, nmax, 3, "atom:v");
   f = memory->grow(atom->f, nmax*comm->nthreads, 3, "atom:f");
-  
+
   rho = memory->grow(atom->rho, nmax, "atom:rho");
   drho = memory->grow(atom->drho, nmax*comm->nthreads, "atom:drho");
   e = memory->grow(atom->e, nmax, "atom:e");
   de = memory->grow(atom->de, nmax*comm->nthreads, "atom:de");
   vest = memory->grow(atom->vest, nmax, 3, "atom:vest");
   cv = memory->grow(atom->cv, nmax, "atom:cv");
-  
+
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax);
 }
 
 /* ----------------------------------------------------------------------
    reset local array ptrs
    ------------------------------------------------------------------------- */
 
 void AtomVecMeso::grow_reset() {
   tag = atom->tag;
   type = atom->type;
   mask = atom->mask;
   image = atom->image;
   x = atom->x;
   v = atom->v;
   f = atom->f;
   rho = atom->rho;
   drho = atom->drho;
   e = atom->e;
   de = atom->de;
   vest = atom->vest;
   cv = atom->cv;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::copy(int i, int j, int delflag) {
   //printf("in AtomVecMeso::copy\n");
   tag[j] = tag[i];
   type[j] = type[i];
   mask[j] = mask[i];
   image[j] = image[i];
   x[j][0] = x[i][0];
   x[j][1] = x[i][1];
   x[j][2] = x[i][2];
   v[j][0] = v[i][0];
   v[j][1] = v[i][1];
   v[j][2] = v[i][2];
-  
+
   rho[j] = rho[i];
   drho[j] = drho[i];
   e[j] = e[i];
   de[j] = de[i];
   cv[j] = cv[i];
   vest[j][0] = vest[i][0];
   vest[j][1] = vest[i][1];
   vest[j][2] = vest[i][2];
-  
+
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       modify->fix[atom->extra_grow[iextra]]->copy_arrays(i, j);
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_comm_hybrid(int n, int *list, double *buf) {
   //printf("in AtomVecMeso::pack_comm_hybrid\n");
   int i, j, m;
-  
+
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = rho[j];
     buf[m++] = e[j];
     buf[m++] = vest[j][0];
     buf[m++] = vest[j][1];
     buf[m++] = vest[j][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::unpack_comm_hybrid(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_comm_hybrid\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     rho[i] = buf[m++];
     e[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_border_hybrid(int n, int *list, double *buf) {
   //printf("in AtomVecMeso::pack_border_hybrid\n");
   int i, j, m;
-  
+
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     buf[m++] = rho[j];
     buf[m++] = e[j];
     buf[m++] = vest[j][0];
     buf[m++] = vest[j][1];
     buf[m++] = vest[j][2];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::unpack_border_hybrid(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_border_hybrid\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     rho[i] = buf[m++];
     e[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_reverse_hybrid(int n, int first, double *buf) {
   //printf("in AtomVecMeso::pack_reverse_hybrid\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = drho[i];
     buf[m++] = de[i];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::unpack_reverse_hybrid(int n, int *list, double *buf) {
   //printf("in AtomVecMeso::unpack_reverse_hybrid\n");
   int i, j, m;
-  
+
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     drho[j] += buf[m++];
     de[j] += buf[m++];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_comm(int n, int *list, double *buf, int pbc_flag,
                            int *pbc) {
   //printf("in AtomVecMeso::pack_comm\n");
   int i, j, m;
   double dx, dy, dz;
-  
+
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0] * domain->xprd;
       dy = pbc[1] * domain->yprd;
       dz = pbc[2] * domain->zprd;
     } else {
       dx = pbc[0] * domain->xprd + pbc[5] * domain->xy + pbc[4] * domain->xz;
       dy = pbc[1] * domain->yprd + pbc[3] * domain->yz;
       dz = pbc[2] * domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_comm_vel(int n, int *list, double *buf, int pbc_flag,
                                int *pbc) {
   //printf("in AtomVecMeso::pack_comm_vel\n");
   int i, j, m;
   double dx, dy, dz;
-  
+
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0] * domain->xprd;
       dy = pbc[1] * domain->yprd;
       dz = pbc[2] * domain->zprd;
     } else {
       dx = pbc[0] * domain->xprd + pbc[5] * domain->xy + pbc[4] * domain->xz;
       dy = pbc[1] * domain->yprd + pbc[3] * domain->yz;
       dz = pbc[2] * domain->zprd;
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::unpack_comm(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_comm\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     rho[i] = buf[m++];
     e[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::unpack_comm_vel(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_comm_vel\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
     rho[i] = buf[m++];
     e[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_reverse(int n, int first, double *buf) {
   //printf("in AtomVecMeso::pack_reverse\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     buf[m++] = f[i][0];
     buf[m++] = f[i][1];
     buf[m++] = f[i][2];
     buf[m++] = drho[i];
     buf[m++] = de[i];
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::unpack_reverse(int n, int *list, double *buf) {
   //printf("in AtomVecMeso::unpack_reverse\n");
   int i, j, m;
-  
+
   m = 0;
   for (i = 0; i < n; i++) {
     j = list[i];
     f[j][0] += buf[m++];
     f[j][1] += buf[m++];
     f[j][2] += buf[m++];
     drho[j] += buf[m++];
     de[j] += buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_border(int n, int *list, double *buf, int pbc_flag,
                              int *pbc) {
   //printf("in AtomVecMeso::pack_border\n");
   int i, j, m;
   double dx, dy, dz;
-  
+
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = cv[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0] * domain->xprd;
       dy = pbc[1] * domain->yprd;
       dz = pbc[2] * domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = cv[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_border_vel(int n, int *list, double *buf, int pbc_flag,
                                  int *pbc) {
   //printf("in AtomVecMeso::pack_border_vel\n");
   int i, j, m;
   double dx, dy, dz;
-  
+
   m = 0;
   if (pbc_flag == 0) {
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0];
       buf[m++] = x[j][1];
       buf[m++] = x[j][2];
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = cv[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   } else {
     if (domain->triclinic == 0) {
       dx = pbc[0] * domain->xprd;
       dy = pbc[1] * domain->yprd;
       dz = pbc[2] * domain->zprd;
     } else {
       dx = pbc[0];
       dy = pbc[1];
       dz = pbc[2];
     }
     for (i = 0; i < n; i++) {
       j = list[i];
       buf[m++] = x[j][0] + dx;
       buf[m++] = x[j][1] + dy;
       buf[m++] = x[j][2] + dz;
       buf[m++] = tag[j];
       buf[m++] = type[j];
       buf[m++] = mask[j];
       buf[m++] = v[j][0];
       buf[m++] = v[j][1];
       buf[m++] = v[j][2];
       buf[m++] = rho[j];
       buf[m++] = e[j];
       buf[m++] = cv[j];
       buf[m++] = vest[j][0];
       buf[m++] = vest[j][1];
       buf[m++] = vest[j][2];
     }
   }
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::unpack_border(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_border\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax)
       grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     rho[i] = buf[m++];
     e[i] = buf[m++];
     cv[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
 }
 
 /* ---------------------------------------------------------------------- */
 
 void AtomVecMeso::unpack_border_vel(int n, int first, double *buf) {
   //printf("in AtomVecMeso::unpack_border_vel\n");
   int i, m, last;
-  
+
   m = 0;
   last = first + n;
   for (i = first; i < last; i++) {
     if (i == nmax)
       grow(0);
     x[i][0] = buf[m++];
     x[i][1] = buf[m++];
     x[i][2] = buf[m++];
     tag[i] = static_cast<int> (buf[m++]);
     type[i] = static_cast<int> (buf[m++]);
     mask[i] = static_cast<int> (buf[m++]);
     v[i][0] = buf[m++];
     v[i][1] = buf[m++];
     v[i][2] = buf[m++];
     rho[i] = buf[m++];
     e[i] = buf[m++];
     cv[i] = buf[m++];
     vest[i][0] = buf[m++];
     vest[i][1] = buf[m++];
     vest[i][2] = buf[m++];
   }
 }
 
 /* ----------------------------------------------------------------------
    pack data for atom I for sending to another proc
    xyz must be 1st 3 values, so comm::exchange() can test on them
    ------------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_exchange(int i, double *buf) {
   //printf("in AtomVecMeso::pack_exchange\n");
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = rho[i];
   buf[m++] = e[i];
   buf[m++] = cv[i];
   buf[m++] = vest[i][0];
   buf[m++] = vest[i][1];
   buf[m++] = vest[i][2];
-  
+
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i, &buf[m]);
-  
+
   buf[0] = m;
   return m;
 }
 
 /* ---------------------------------------------------------------------- */
 
 int AtomVecMeso::unpack_exchange(double *buf) {
   //printf("in AtomVecMeso::unpack_exchange\n");
   int nlocal = atom->nlocal;
   if (nlocal == nmax)
     grow(0);
-  
+
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   rho[nlocal] = buf[m++];
   e[nlocal] = buf[m++];
   cv[nlocal] = buf[m++];
   vest[nlocal][0] = buf[m++];
   vest[nlocal][1] = buf[m++];
   vest[nlocal][2] = buf[m++];
-  
+
   if (atom->nextra_grow)
     for (int iextra = 0; iextra < atom->nextra_grow; iextra++)
       m += modify->fix[atom->extra_grow[iextra]]-> unpack_exchange(nlocal,
                                                                    &buf[m]);
-  
+
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    size of restart data for all atoms owned by this proc
    include extra data stored by fixes
    ------------------------------------------------------------------------- */
 
 int AtomVecMeso::size_restart() {
   int i;
-  
+
   int nlocal = atom->nlocal;
   int n = 17 * nlocal; // 11 + rho + e + cv + vest[3]
-  
+
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       for (i = 0; i < nlocal; i++)
         n += modify->fix[atom->extra_restart[iextra]]->size_restart(i);
-  
+
   return n;
 }
 
 /* ----------------------------------------------------------------------
    pack atom I's data for restart file including extra quantities
    xyz must be 1st 3 values, so that read_restart can test on them
    molecular types may be negative, but write as positive
    ------------------------------------------------------------------------- */
 
 int AtomVecMeso::pack_restart(int i, double *buf) {
   int m = 1;
   buf[m++] = x[i][0];
   buf[m++] = x[i][1];
   buf[m++] = x[i][2];
   buf[m++] = tag[i];
   buf[m++] = type[i];
   buf[m++] = mask[i];
   *((tagint *) &buf[m++]) = image[i];
   buf[m++] = v[i][0];
   buf[m++] = v[i][1];
   buf[m++] = v[i][2];
   buf[m++] = rho[i];
   buf[m++] = e[i];
   buf[m++] = cv[i];
   buf[m++] = vest[i][0];
   buf[m++] = vest[i][1];
   buf[m++] = vest[i][2];
-  
+
   if (atom->nextra_restart)
     for (int iextra = 0; iextra < atom->nextra_restart; iextra++)
       m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i, &buf[m]);
-  
+
   buf[0] = m;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    unpack data for one atom from restart file including extra quantities
    ------------------------------------------------------------------------- */
 
 int AtomVecMeso::unpack_restart(double *buf) {
   int nlocal = atom->nlocal;
   if (nlocal == nmax) {
     grow(0);
     if (atom->nextra_store)
       memory->grow(atom->extra, nmax, atom->nextra_store, "atom:extra");
   }
-  
+
   int m = 1;
   x[nlocal][0] = buf[m++];
   x[nlocal][1] = buf[m++];
   x[nlocal][2] = buf[m++];
   tag[nlocal] = static_cast<int> (buf[m++]);
   type[nlocal] = static_cast<int> (buf[m++]);
   mask[nlocal] = static_cast<int> (buf[m++]);
   image[nlocal] = *((tagint *) &buf[m++]);
   v[nlocal][0] = buf[m++];
   v[nlocal][1] = buf[m++];
   v[nlocal][2] = buf[m++];
   rho[nlocal] = buf[m++];
   e[nlocal] = buf[m++];
   cv[nlocal] = buf[m++];
   vest[nlocal][0] = buf[m++];
   vest[nlocal][1] = buf[m++];
   vest[nlocal][2] = buf[m++];
-  
+
   double **extra = atom->extra;
   if (atom->nextra_store) {
     int size = static_cast<int> (buf[0]) - m;
     for (int i = 0; i < size; i++)
       extra[nlocal][i] = buf[m++];
   }
-  
+
   atom->nlocal++;
   return m;
 }
 
 /* ----------------------------------------------------------------------
    create one atom of itype at coord
    set other values to defaults
    ------------------------------------------------------------------------- */
 
 void AtomVecMeso::create_atom(int itype, double *coord) {
   int nlocal = atom->nlocal;
   if (nlocal == nmax)
     grow(0);
-  
+
   tag[nlocal] = 0;
   type[nlocal] = itype;
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
   mask[nlocal] = 1;
-  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | 
+  image[nlocal] = ((tagint) IMGMAX << IMG2BITS) |
     ((tagint) IMGMAX << IMGBITS) | IMGMAX;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
   rho[nlocal] = 0.0;
   e[nlocal] = 0.0;
   cv[nlocal] = 1.0;
   vest[nlocal][0] = 0.0;
   vest[nlocal][1] = 0.0;
   vest[nlocal][2] = 0.0;
   de[nlocal] = 0.0;
   drho[nlocal] = 0.0;
-  
+
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack one line from Atoms section of data file
    initialize other atom quantities
    ------------------------------------------------------------------------- */
 
 void AtomVecMeso::data_atom(double *coord, tagint imagetmp, char **values) {
   int nlocal = atom->nlocal;
   if (nlocal == nmax)
     grow(0);
-  
+
   tag[nlocal] = atoi(values[0]);
   if (tag[nlocal] <= 0)
     error->one(FLERR,"Invalid atom ID in Atoms section of data file");
-  
+
   type[nlocal] = atoi(values[1]);
   if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes)
     error->one(FLERR,"Invalid atom type in Atoms section of data file");
-  
+
   rho[nlocal] = atof(values[2]);
   e[nlocal] = atof(values[3]);
   cv[nlocal] = atof(values[4]);
-  
+
   x[nlocal][0] = coord[0];
   x[nlocal][1] = coord[1];
   x[nlocal][2] = coord[2];
-  
+
   //printf("rho=%f, e=%f, cv=%f, x=%f\n", rho[nlocal], e[nlocal], cv[nlocal], x[nlocal][0]);
-  
+
   image[nlocal] = imagetmp;
-  
+
   mask[nlocal] = 1;
   v[nlocal][0] = 0.0;
   v[nlocal][1] = 0.0;
   v[nlocal][2] = 0.0;
-  
+
   vest[nlocal][0] = 0.0;
   vest[nlocal][1] = 0.0;
   vest[nlocal][2] = 0.0;
-  
+
   de[nlocal] = 0.0;
   drho[nlocal] = 0.0;
-  
+
   atom->nlocal++;
 }
 
 /* ----------------------------------------------------------------------
    unpack hybrid quantities from one line in Atoms section of data file
    initialize other atom quantities for this sub-style
    ------------------------------------------------------------------------- */
 
 int AtomVecMeso::data_atom_hybrid(int nlocal, char **values) {
-  
+
   rho[nlocal] = atof(values[0]);
   e[nlocal] = atof(values[1]);
   cv[nlocal] = atof(values[2]);
-  
+
   return 3;
 }
 
 /* ----------------------------------------------------------------------
    return # of bytes of allocated memory
    ------------------------------------------------------------------------- */
 
 bigint AtomVecMeso::memory_usage() {
   bigint bytes = 0;
-  
+
   if (atom->memcheck("tag"))
     bytes += memory->usage(tag, nmax);
   if (atom->memcheck("type"))
     bytes += memory->usage(type, nmax);
   if (atom->memcheck("mask"))
     bytes += memory->usage(mask, nmax);
   if (atom->memcheck("image"))
     bytes += memory->usage(image, nmax);
   if (atom->memcheck("x"))
     bytes += memory->usage(x, nmax, 3);
   if (atom->memcheck("v"))
     bytes += memory->usage(v, nmax, 3);
   if (atom->memcheck("f"))
     bytes += memory->usage(f, nmax*comm->nthreads, 3);
   if (atom->memcheck("rho"))
     bytes += memory->usage(rho, nmax);
   if (atom->memcheck("drho"))
     bytes += memory->usage(drho, nmax*comm->nthreads);
   if (atom->memcheck("e"))
     bytes += memory->usage(e, nmax);
   if (atom->memcheck("de"))
     bytes += memory->usage(de, nmax*comm->nthreads);
   if (atom->memcheck("cv"))
     bytes += memory->usage(cv, nmax);
   if (atom->memcheck("vest"))
     bytes += memory->usage(vest, nmax);
-  
+
   return bytes;
 }