Commit d6cfefc0 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5122 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 4f64b5c7
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ if (test $1 = 1) then
  cp angle_charmm.cpp ..
  cp angle_cosine.cpp ..
  cp angle_cosine_delta.cpp ..
  cp angle_cosine_periodic.cpp ..
  cp angle_cosine_squared.cpp ..
  cp angle_harmonic.cpp ..
  cp angle_hybrid.cpp ..
@@ -32,12 +33,16 @@ if (test $1 = 1) then
  cp improper_cvff.cpp ..
  cp improper_harmonic.cpp ..
  cp improper_hybrid.cpp ..
  cp improper_umbrella.cpp ..
  cp pair_hbond_dreiding_lj.cpp ..
  cp pair_hbond_dreiding_morse.cpp ..
  cp pair_lj_charmm_coul_charmm.cpp ..
  cp pair_lj_charmm_coul_charmm_implicit.cpp ..

  cp angle_charmm.h ..
  cp angle_cosine.h ..
  cp angle_cosine_delta.h ..
  cp angle_cosine_periodic.h ..
  cp angle_cosine_squared.h ..
  cp angle_harmonic.h ..
  cp angle_hybrid.h ..
@@ -65,6 +70,9 @@ if (test $1 = 1) then
  cp improper_cvff.h ..
  cp improper_harmonic.h ..
  cp improper_hybrid.h ..
  cp improper_umbrella.h ..
  cp pair_hbond_dreiding_lj.h ..
  cp pair_hbond_dreiding_morse.h ..
  cp pair_lj_charmm_coul_charmm.h ..
  cp pair_lj_charmm_coul_charmm_implicit.h ..

@@ -73,6 +81,7 @@ elif (test $1 = 0) then
  rm ../angle_charmm.cpp
  rm ../angle_cosine.cpp
  rm ../angle_cosine_delta.cpp
  rm ../angle_cosine_periodic.cpp
  rm ../angle_cosine_squared.cpp
  rm ../angle_harmonic.cpp
  rm ../angle_hybrid.cpp
@@ -100,12 +109,16 @@ elif (test $1 = 0) then
  rm ../improper_cvff.cpp
  rm ../improper_harmonic.cpp
  rm ../improper_hybrid.cpp
  rm ../improper_umbrella.cpp
  rm ../pair_hbond_dreiding_lj.cpp
  rm ../pair_hbond_dreiding_morse.cpp
  rm ../pair_lj_charmm_coul_charmm.cpp
  rm ../pair_lj_charmm_coul_charmm_implicit.cpp

  rm ../angle_charmm.h
  rm ../angle_cosine.h
  rm ../angle_cosine_delta.h
  rm ../angle_cosine_periodic.h
  rm ../angle_cosine_squared.h
  rm ../angle_harmonic.h
  rm ../angle_hybrid.h
@@ -133,6 +146,9 @@ elif (test $1 = 0) then
  rm ../improper_cvff.h
  rm ../improper_harmonic.h
  rm ../improper_hybrid.h
  rm ../improper_umbrella.h
  rm ../pair_hbond_dreiding_lj.h
  rm ../pair_hbond_dreiding_morse.h
  rm ../pair_lj_charmm_coul_charmm.h
  rm ../pair_lj_charmm_coul_charmm_implicit.h

+290 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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: Tod A Pascal (Caltech)
------------------------------------------------------------------------- */

#include "math.h"
#include "stdlib.h"
#include "angle_cosine_periodic.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;

#define SMALL 0.001

/* ---------------------------------------------------------------------- */

AngleCosinePeriodic::AngleCosinePeriodic(LAMMPS *lmp) : Angle(lmp) {}

/* ---------------------------------------------------------------------- */

AngleCosinePeriodic::~AngleCosinePeriodic()
{
  if (allocated) {
    memory->sfree(setflag);
    memory->sfree(k);
    memory->sfree(b);
    memory->sfree(multiplicity);
  }
}

/* ---------------------------------------------------------------------- */

void AngleCosinePeriodic::compute(int eflag, int vflag)
{
  int i,i1,i2,i3,n,m,type,b_factor;
  double delx1,dely1,delz1,delx2,dely2,delz2;
  double eangle,f1[3],f3[3];
  double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22;
  double tn,tn_1,tn_2,un,un_1,un_2;

  eangle = 0.0;
  if (eflag || vflag) ev_setup(eflag,vflag);
  else evflag = 0;

  double **x = atom->x;
  double **f = atom->f;
  int **anglelist = neighbor->anglelist;
  int nanglelist = neighbor->nanglelist;
  int nlocal = atom->nlocal;
  int newton_bond = force->newton_bond;

  for (n = 0; n < nanglelist; n++) {
    i1 = anglelist[n][0];
    i2 = anglelist[n][1];
    i3 = anglelist[n][2];
    type = anglelist[n][3];

    // 1st bond

    delx1 = x[i1][0] - x[i2][0];
    dely1 = x[i1][1] - x[i2][1];
    delz1 = x[i1][2] - x[i2][2];
    domain->minimum_image(delx1,dely1,delz1);

    rsq1 = delx1*delx1 + dely1*dely1 + delz1*delz1;
    r1 = sqrt(rsq1);

    // 2nd bond

    delx2 = x[i3][0] - x[i2][0];
    dely2 = x[i3][1] - x[i2][1];
    delz2 = x[i3][2] - x[i2][2];
    domain->minimum_image(delx2,dely2,delz2);

    rsq2 = delx2*delx2 + dely2*dely2 + delz2*delz2;
    r2 = sqrt(rsq2);

    // c = cosine of angle

    c = delx1*delx2 + dely1*dely2 + delz1*delz2;
    c /= r1*r2;
    if (c > 1.0) c = 1.0;
    if (c < -1.0) c = -1.0;

    m = multiplicity[type];
    b_factor = b[type];

    // cos(n*x) = Tn(cos(x))
    // Tn(x) = Chebyshev polynomials of the first kind: T_0 = 1, T_1 = x, ...
    // recurrence relationship:
    // Tn(x) = 2*x*T[n-1](x) - T[n-2](x) where T[-1](x) = 0
    // also, dTn(x)/dx = n*U[n-1](x)
    // where Un(x) = 2*x*U[n-1](x) - U[n-2](x) and U[-1](x) = 0
    // finally need to handle special case for n = 1

    tn = 1.0;
    tn_1 = 1.0;
    tn_2 = 0.0;
    un = 1.0; 
    un_1 = 2.0;
    un_2 = 0.0;

    s = sqrt(1.0 - c*c);
    if (s < SMALL) s = SMALL;
    s = 1.0/s;

    // force & energy

    tn_2 = c;
    for (i = 1; i <= m; i++) {
      tn = 2*c*tn_1 - tn_2;
      tn_2 = tn_1;
      tn_1 = tn;
    }

    for (i = 2; i <= m; i++) {
      un = 2*c*un_1 - un_2;
      un_2 = un_1;
      un_1 = un;
    }
    tn = b_factor*pow((-1),m)*tn;
    un = b_factor*pow((-1),m)*m*un;

    if (eflag) eangle = 2*k[type]*(1.0 - tn);

    a = -k[type]*un;
    a11 = a*c / rsq1;
    a12 = -a / (r1*r2);
    a22 = a*c / rsq2;
        
    f1[0] = a11*delx1 + a12*delx2;
    f1[1] = a11*dely1 + a12*dely2;
    f1[2] = a11*delz1 + a12*delz2;
    f3[0] = a22*delx2 + a12*delx1;
    f3[1] = a22*dely2 + a12*dely1;
    f3[2] = a22*delz2 + a12*delz1;

    // apply force to each of 3 atoms

    if (newton_bond || i1 < nlocal) {
      f[i1][0] += f1[0];
      f[i1][1] += f1[1];
      f[i1][2] += f1[2];
    }

    if (newton_bond || i2 < nlocal) {
      f[i2][0] -= f1[0] + f3[0];
      f[i2][1] -= f1[1] + f3[1];
      f[i2][2] -= f1[2] + f3[2];
    }

    if (newton_bond || i3 < nlocal) {
      f[i3][0] += f3[0];
      f[i3][1] += f3[1];
      f[i3][2] += f3[2];
    }

    if (evflag) ev_tally(i1,i2,i3,nlocal,newton_bond,eangle,f1,f3,
			 delx1,dely1,delz1,delx2,dely2,delz2);
  }
}

/* ---------------------------------------------------------------------- */

void AngleCosinePeriodic::allocate()
{
  allocated = 1;
  int n = atom->nangletypes;

  k = (double *) memory->smalloc((n+1)*sizeof(double),"angle:k");
  multiplicity = (int *) memory->smalloc((n+1)*sizeof(int),
					 "angle:multiplicity");
  b = (int *) memory->smalloc((n+1)*sizeof(int),"angle:b");

  setflag = (int *) memory->smalloc((n+1)*sizeof(int),"angle:setflag");
  for (int i = 1; i <= n; i++) setflag[i] = 0;
}

/* ----------------------------------------------------------------------
   set coeffs for one or more types
------------------------------------------------------------------------- */

void AngleCosinePeriodic::coeff(int which, int narg, char **arg)
{
  if (which > 0) return;
  if (narg != 4) error->all("Incorrect args for angle coefficients");
  if (!allocated) allocate();

  int ilo,ihi;
  force->bounds(arg[0],atom->nangletypes,ilo,ihi);

  double c_one = atof(arg[1]);
  int b_one = atoi(arg[2]);
  int n_one = atoi(arg[3]);
  if (n_one <= 0) error->all("Incorrect args for angle coefficients");

  int count = 0;
  for (int i = ilo; i <= ihi; i++) {
    k[i] = c_one/(n_one*n_one);
    b[i] = b_one;
    multiplicity[i] = n_one;
    setflag[i] = 1;
    count++;
  }

  if (count == 0) error->all("Incorrect args for angle coefficients");
}

/* ---------------------------------------------------------------------- */

double AngleCosinePeriodic::equilibrium_angle(int i)
{
  return PI;
}

/* ----------------------------------------------------------------------
   proc 0 writes out coeffs to restart file 
------------------------------------------------------------------------- */

void AngleCosinePeriodic::write_restart(FILE *fp)
{
  fwrite(&k[1],sizeof(double),atom->nangletypes,fp);
  fwrite(&b[1],sizeof(int),atom->nangletypes,fp);
  fwrite(&multiplicity[1],sizeof(int),atom->nangletypes,fp);
}

/* ----------------------------------------------------------------------
   proc 0 reads coeffs from restart file, bcasts them 
------------------------------------------------------------------------- */

void AngleCosinePeriodic::read_restart(FILE *fp)
{
  allocate();

  if (comm->me == 0) {
    fread(&k[1],sizeof(double),atom->nangletypes,fp);
    fread(&b[1],sizeof(int),atom->nangletypes,fp);
    fread(&multiplicity[1],sizeof(int),atom->nangletypes,fp);
  }

  MPI_Bcast(&k[1],atom->nangletypes,MPI_DOUBLE,0,world);
  MPI_Bcast(&b[1],atom->nangletypes,MPI_INT,0,world);
  MPI_Bcast(&multiplicity[1],atom->nangletypes,MPI_INT,0,world);
  for (int i = 1; i <= atom->nangletypes; i++) setflag[i] = 1;
}

/* ---------------------------------------------------------------------- */

double AngleCosinePeriodic::single(int type, int i1, int i2, int i3)
{
  double **x = atom->x;

  double delx1 = x[i1][0] - x[i2][0];
  double dely1 = x[i1][1] - x[i2][1];
  double delz1 = x[i1][2] - x[i2][2];
  domain->minimum_image(delx1,dely1,delz1);
  double r1 = sqrt(delx1*delx1 + dely1*dely1 + delz1*delz1);
  
  double delx2 = x[i3][0] - x[i2][0];
  double dely2 = x[i3][1] - x[i2][1];
  double delz2 = x[i3][2] - x[i2][2];
  domain->minimum_image(delx2,dely2,delz2);
  double r2 = sqrt(delx2*delx2 + dely2*dely2 + delz2*delz2);

  double c = delx1*delx2 + dely1*dely2 + delz1*delz2;
  c /= r1*r2;
  if (c > 1.0) c = 1.0;
  if (c < -1.0) c = -1.0;

  c = cos(acos(c)*multiplicity[type]);
  return k[type]*(1.0-b[type]*pow(-1,multiplicity[type])*c);
}
+49 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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.
------------------------------------------------------------------------- */

#ifdef ANGLE_CLASS

AngleStyle(cosine/periodic, AngleCosinePeriodic)

#else

#ifndef LMP_ANGLE_PERIODIC_H
#define LMP_ANGLE_PERIODIC_H

#include "stdio.h"
#include "angle.h"

namespace LAMMPS_NS {

class AngleCosinePeriodic : public Angle {
 public:
  AngleCosinePeriodic(class LAMMPS *);
  ~AngleCosinePeriodic();
  void compute(int, int);
  void coeff(int, int, char **);
  double equilibrium_angle(int);
  void write_restart(FILE *);
  void read_restart(FILE *);
  double single(int, int, int, int);

 private:
  double *k; 
  int *multiplicity,*b;

  void allocate();
};

}

#endif
#endif
+309 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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: Tod A Pascal (Caltech)
------------------------------------------------------------------------- */

#include "mpi.h"
#include "math.h"
#include "stdlib.h"
#include "improper_umbrella.h"
#include "atom.h"
#include "comm.h"
#include "neighbor.h"
#include "domain.h"
#include "force.h"
#include "update.h"
#include "memory.h"
#include "error.h"

using namespace LAMMPS_NS;

#define TOLERANCE 0.05
#define SMALL     0.001

/* ---------------------------------------------------------------------- */

ImproperUmbrella::ImproperUmbrella(LAMMPS *lmp) : Improper(lmp) {}

/* ---------------------------------------------------------------------- */

ImproperUmbrella::~ImproperUmbrella()
{
  if (allocated) {
    memory->sfree(setflag);
    memory->sfree(kw);
    memory->sfree(w0);
    memory->sfree(C);
  }
}

/* ---------------------------------------------------------------------- */

void ImproperUmbrella::compute(int eflag, int vflag)
{
  int i1,i2,i3,i4,n,type;
  double eimproper,f1[3],f2[3],f3[3],f4[3];
  double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z;
  double domega,c,a,s,projhfg,dhax,dhay,dhaz,dahx,dahy,dahz,cotphi;
  double ax,ay,az,ra2,rh2,ra,rh,rar,rhr,arx,ary,arz,hrx,hry,hrz;

  eimproper = 0.0;
  if (eflag || vflag) ev_setup(eflag,vflag);
  else evflag = 0;

  double **x = atom->x;
  double **f = atom->f;
  int **improperlist = neighbor->improperlist;
  int nimproperlist = neighbor->nimproperlist;
  int nlocal = atom->nlocal;
  int newton_bond = force->newton_bond;

  for (n = 0; n < nimproperlist; n++) {
    i1 = improperlist[n][0];
    i2 = improperlist[n][1];
    i3 = improperlist[n][2];
    i4 = improperlist[n][3];
    type = improperlist[n][4];

    // 1st bond

    vb1x = x[i2][0] - x[i1][0];
    vb1y = x[i2][1] - x[i1][1];
    vb1z = x[i2][2] - x[i1][2];
    domain->minimum_image(vb1x,vb1y,vb1z);

    // 2nd bond

    vb2x = x[i3][0] - x[i1][0];
    vb2y = x[i3][1] - x[i1][1];
    vb2z = x[i3][2] - x[i1][2];
    domain->minimum_image(vb2x,vb2y,vb2z);

    // 3rd bond

    vb3x = x[i4][0] - x[i1][0];
    vb3y = x[i4][1] - x[i1][1];
    vb3z = x[i4][2] - x[i1][2];
    domain->minimum_image(vb3x,vb3y,vb3z);

    // c0 calculation
    // A = vb1 X vb2 is perpendicular to IJK plane

    ax = vb1y*vb2z-vb1z*vb2y;
    ay = vb1z*vb2x-vb1x*vb2z;
    az = vb1x*vb2y-vb1y*vb2x;
    ra2 = ax*ax+ay*ay+az*az;
    rh2 = vb3x*vb3x+vb3y*vb3y+vb3z*vb3z;
    ra = sqrt(ra2);
    rh = sqrt(rh2);
    if (ra < SMALL) ra = SMALL;
    if (rh < SMALL) rh = SMALL;

    rar = 1/ra;
    rhr = 1/rh;
    arx = ax*rar;
    ary = ay*rar;
    arz = az*rar;
    hrx = vb3x*rhr;
    hry = vb3y*rhr;
    hrz = vb3z*rhr;

    c = arx*hrx+ary*hry+arz*hrz;

    // error check

    if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) {
      int me;
      MPI_Comm_rank(world,&me);
      if (screen) {
	fprintf(screen,"Improper problem: %d %d %d %d %d %d\n",
		me,update->ntimestep,
		atom->tag[i1],atom->tag[i2],atom->tag[i3],atom->tag[i4]);
	fprintf(screen,"  1st atom: %d %g %g %g\n",
		me,x[i1][0],x[i1][1],x[i1][2]);
	fprintf(screen,"  2nd atom: %d %g %g %g\n",
		me,x[i2][0],x[i2][1],x[i2][2]);
	fprintf(screen,"  3rd atom: %d %g %g %g\n",
		me,x[i3][0],x[i3][1],x[i3][2]);
	fprintf(screen,"  4th atom: %d %g %g %g\n",
		me,x[i4][0],x[i4][1],x[i4][2]);
      }
    }
    
    if (c > 1.0) s = 1.0;
    if (c < -1.0) s = -1.0;

    s = sqrt(1.0 - c*c);
    if (s < SMALL) s = SMALL;
    cotphi = c/s;

    projhfg = (vb3x*vb1x+vb3y*vb1y+vb3z*vb1z) / 
      sqrt(vb1x*vb1x+vb1y*vb1y+vb1z*vb1z); 
    projhfg += (vb3x*vb2x+vb3y*vb2y+vb3z*vb2z) / 
      sqrt(vb2x*vb2x+vb2y*vb2y+vb2z*vb2z);
    if (projhfg > 0.0) {
      s *= -1.0;
      cotphi *= -1.0;
    }
	
    //  force and energy
    // if w0 = 0: E = k * (1 - cos w)
    // if w0 != 0: E = 0.5 * C (cos w - cos w0)^2, C = k/(sin(w0)^2

    if (w0[type] == 0.0) {
      if (eflag) eimproper = kw[type] * (1.0-s);
      a = -kw[type];
    } else {
      domega = s - cos(w0[type]);
      a = 0.5 * C[type] * domega;
      if (eflag) eimproper = a * domega;
      a *= 2.0;
    }

    // dhax = diffrence between H and A in X direction, etc

    a = a*cotphi;
    dhax = hrx-c*arx;
    dhay = hry-c*ary;
    dhaz = hrz-c*arz;

    dahx = arx-c*hrx;
    dahy = ary-c*hry;
    dahz = arz-c*hrz;

    f2[0] = (dhay*vb1z - dhaz*vb1y)*rar;
    f2[1] = (dhaz*vb1x - dhax*vb1z)*rar;
    f2[2] = (dhax*vb1y - dhay*vb1x)*rar;

    f3[0] = (-dhay*vb2z + dhaz*vb2y)*rar;
    f3[1] = (-dhaz*vb2x + dhax*vb2z)*rar;
    f3[2] = (-dhax*vb2y + dhay*vb2x)*rar;

    f4[0] = dahx*rhr;
    f4[1] = dahy*rhr;
    f4[2] = dahz*rhr;

    f1[0] = -(f2[0] + f3[0] + f4[0]);
    f1[1] = -(f2[1] + f3[1] + f4[1]);
    f1[2] = -(f2[2] + f3[2] + f4[2]);

    // apply force to each of 4 atoms

    if (newton_bond || i1 < nlocal) {
      f[i1][0] += f1[0]*a;
      f[i1][1] += f1[1]*a;
      f[i1][2] += f1[2]*a;
    }

    if (newton_bond || i2 < nlocal) {
      f[i2][0] += f3[0]*a;
      f[i2][1] += f3[1]*a;
      f[i2][2] += f3[2]*a;
    }

    if (newton_bond || i3 < nlocal) {
      f[i3][0] += f2[0]*a;
      f[i3][1] += f2[1]*a;
      f[i3][2] += f2[2]*a;
    }

    if (newton_bond || i4 < nlocal) {
      f[i4][0] += f4[0]*a;
      f[i4][1] += f4[1]*a;
      f[i4][2] += f4[2]*a;
    }

    if (evflag)
      ev_tally(i1,i2,i3,i4,nlocal,newton_bond,eimproper,f1,f3,f4,
	       vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z);
  }
}

/* ---------------------------------------------------------------------- */

void ImproperUmbrella::allocate()
{
  allocated = 1;
  int n = atom->nimpropertypes;

  kw = (double *) memory->smalloc((n+1)*sizeof(double),"improper:kw");
  w0 = (double *) memory->smalloc((n+1)*sizeof(double),"improper:w0");
  C = (double *) memory->smalloc((n+1)*sizeof(double),"improper:C");

  setflag = (int *) memory->smalloc((n+1)*sizeof(int),"improper:setflag");
  for (int i = 1; i <= n; i++) setflag[i] = 0;
}

/* ----------------------------------------------------------------------
   set coeffs for one type
------------------------------------------------------------------------- */

void ImproperUmbrella::coeff(int which, int narg, char **arg)
{
  if (which > 0) return;
  if (narg != 3) error->all("Incorrect args for improper coefficients");
  if (!allocated) allocate();

  int ilo,ihi;
  force->bounds(arg[0],atom->nimpropertypes,ilo,ihi);

  double k_one = atof(arg[1]);
  double w_one = atof(arg[2]);

  // convert w0 from degrees to radians

  int count = 0;
  for (int i = ilo; i <= ihi; i++) {
    kw[i] = k_one;
    w0[i] = w_one/180.0 * PI;
    if (w_one == 0) C[i] = 1.0;
    else C[i] = kw[i]/(pow(sin(w0[i]),2));
    setflag[i] = 1;
    count++;
  }

  if (count == 0) error->all("Incorrect args for improper coefficients");
}

/* ----------------------------------------------------------------------
   proc 0 writes out coeffs to restart file 
------------------------------------------------------------------------- */

void ImproperUmbrella::write_restart(FILE *fp)
{
  fwrite(&kw[1],sizeof(double),atom->nimpropertypes,fp);
  fwrite(&w0[1],sizeof(double),atom->nimpropertypes,fp);
  fwrite(&C[1],sizeof(double),atom->nimpropertypes,fp);
}

/* ----------------------------------------------------------------------
   proc 0 reads coeffs from restart file, bcasts them 
------------------------------------------------------------------------- */

void ImproperUmbrella::read_restart(FILE *fp)
{
  allocate();

  if (comm->me == 0) {
    fread(&kw[1],sizeof(double),atom->nimpropertypes,fp);
    fread(&w0[1],sizeof(double),atom->nimpropertypes,fp);
    fread(&C[1],sizeof(double),atom->nimpropertypes,fp);
  }
  MPI_Bcast(&kw[1],atom->nimpropertypes,MPI_DOUBLE,0,world);
  MPI_Bcast(&w0[1],atom->nimpropertypes,MPI_DOUBLE,0,world);
  MPI_Bcast(&C[1],atom->nimpropertypes,MPI_DOUBLE,0,world);

  for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1;
}
+46 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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.
------------------------------------------------------------------------- */

#ifdef IMPROPER_CLASS

ImproperStyle(umbrella,ImproperUmbrella)

#else

#ifndef LMP_IMPROPER_UMBRELLA_H
#define LMP_IMPROPER_UMBRELLA_H

#include "stdio.h"
#include "improper.h"

namespace LAMMPS_NS {

class ImproperUmbrella : public Improper {
 public:
  ImproperUmbrella(class LAMMPS *);
  ~ImproperUmbrella();
  void compute(int, int);
  void coeff(int, int, char **);
  void write_restart(FILE *);
  void read_restart(FILE *);

 private:
  double *kw, *w0, *C;

  void allocate();
};

}

#endif
#endif
Loading