From 8492c4149e073c85583b3ba9d21863f905bfd6eb Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Tue, 23 Apr 2013 20:35:26 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@9787
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/pair.h             |  1 +
 src/pair_coul_wolf.cpp |  5 ++++-
 src/pair_lj_cut.cpp    | 11 ++++++++++
 src/pair_lj_cut.h      |  1 +
 src/read_data.cpp      | 46 ++++++++++++++++++++++++++++++++++++++++--
 src/read_data.h        |  1 +
 src/write_data.cpp     | 28 ++++++++++++++++++++++---
 src/write_data.h       |  1 +
 8 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/src/pair.h b/src/pair.h
index 40f78934e4..8eb6854c09 100644
--- a/src/pair.h
+++ b/src/pair.h
@@ -153,6 +153,7 @@ class Pair : protected Pointers {
   virtual void write_restart_settings(FILE *) {}
   virtual void read_restart_settings(FILE *) {}
   virtual void write_data(FILE *) {}
+  virtual void write_data_all(FILE *) {}
 
   virtual int pack_comm(int, int *, double *, int, int *) {return 0;}
   virtual void unpack_comm(int, int, double *) {}
diff --git a/src/pair_coul_wolf.cpp b/src/pair_coul_wolf.cpp
index af9751fa11..8cf821c2d7 100644
--- a/src/pair_coul_wolf.cpp
+++ b/src/pair_coul_wolf.cpp
@@ -34,7 +34,10 @@ using namespace MathConst;
 
 /* ---------------------------------------------------------------------- */
 
-PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp) {}
+PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp)
+{
+  writedata = 0;
+}
 
 /* ---------------------------------------------------------------------- */
 
diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp
index 15e7e7b855..becf294526 100644
--- a/src/pair_lj_cut.cpp
+++ b/src/pair_lj_cut.cpp
@@ -690,6 +690,17 @@ void PairLJCut::write_data(FILE *fp)
     fprintf(fp,"%d %g %g\n",i,epsilon[i][i],sigma[i][i]);
 }
 
+/* ----------------------------------------------------------------------
+   proc 0 writes all pairs to data file
+------------------------------------------------------------------------- */
+
+void PairLJCut::write_data_all(FILE *fp)
+{
+  for (int i = 1; i <= atom->ntypes; i++)
+    for (int j = i; j <= atom->ntypes; j++)
+      fprintf(fp,"%d %d %g %g %g\n",i,j,epsilon[i][i],sigma[i][i],cut[i][j]);
+}
+
 /* ---------------------------------------------------------------------- */
 
 double PairLJCut::single(int i, int j, int itype, int jtype, double rsq,
diff --git a/src/pair_lj_cut.h b/src/pair_lj_cut.h
index 46a7bf560d..cccd9d1c69 100644
--- a/src/pair_lj_cut.h
+++ b/src/pair_lj_cut.h
@@ -39,6 +39,7 @@ class PairLJCut : public Pair {
   void write_restart_settings(FILE *);
   void read_restart_settings(FILE *);
   void write_data(FILE *);
+  void write_data_all(FILE *);
   double single(int, int, int, int, double, double, double, double &);
   void *extract(const char *, int &);
 
diff --git a/src/read_data.cpp b/src/read_data.cpp
index f03805cbca..56a7651e0a 100644
--- a/src/read_data.cpp
+++ b/src/read_data.cpp
@@ -47,7 +47,7 @@ using namespace LAMMPS_NS;
 #define MAXBODY 20         // max # of lines in one body, also in Atom class
 
                            // customize for new sections
-#define NSECTIONS 24       // change when add to header::section_keywords
+#define NSECTIONS 25       // change when add to header::section_keywords
 
 /* ---------------------------------------------------------------------- */
 
@@ -255,6 +255,10 @@ void ReadData::command(int narg, char **arg)
       if (force->pair == NULL)
         error->all(FLERR,"Must define pair_style before Pair Coeffs");
       paircoeffs();
+    } else if (strcmp(keyword,"PairIJ Coeffs") == 0) {
+      if (force->pair == NULL)
+        error->all(FLERR,"Must define pair_style before PairIJ Coeffs");
+      pairIJcoeffs();
     } else if (strcmp(keyword,"Bond Coeffs") == 0) {
       if (atom->avec->bonds_allow == 0)
         error->all(FLERR,"Invalid data file section: Bond Coeffs");
@@ -387,7 +391,7 @@ void ReadData::header(int flag)
   const char *section_keywords[NSECTIONS] =
     {"Atoms","Velocities","Ellipsoids","Lines","Triangles","Bodies",
      "Bonds","Angles","Dihedrals","Impropers",
-     "Masses","Pair Coeffs","Bond Coeffs","Angle Coeffs",
+     "Masses","Pair Coeffs","PairIJ Coeffs","Bond Coeffs","Angle Coeffs",
      "Dihedral Coeffs","Improper Coeffs",
      "BondBond Coeffs","BondAngle Coeffs","MiddleBondTorsion Coeffs",
      "EndBondTorsion Coeffs","AngleTorsion Coeffs",
@@ -1062,6 +1066,40 @@ void ReadData::paircoeffs()
 
 /* ---------------------------------------------------------------------- */
 
+void ReadData::pairIJcoeffs()
+{
+  int i,j,m;
+  char *buf = new char[atom->ntypes*(atom->ntypes+1)/2 * MAXLINE];
+  char *original = buf;
+
+  if (me == 0) {
+    char *eof;
+    m = 0;
+    for (i = 0; i < atom->ntypes; i++)
+      for (j = i; j < atom->ntypes; j++) {
+        eof = fgets(&buf[m],MAXLINE,fp);
+        if (eof == NULL) error->one(FLERR,"Unexpected end of data file");
+        m += strlen(&buf[m]);
+        if (buf[m-1] != '\n') strcpy(&buf[m++],"\n");
+        buf[m-1] = '\0';
+      }
+  }
+
+  MPI_Bcast(&m,1,MPI_INT,0,world);
+  MPI_Bcast(buf,m,MPI_CHAR,0,world);
+
+  for (i = 0; i < atom->ntypes; i++)
+    for (j = i; j < atom->ntypes; j++) {
+      m = strlen(buf) + 1;
+      parse_coeffs(buf,NULL,0);
+      force->pair->coeff(narg,arg);
+      buf += m;
+    }
+  delete [] original;
+}
+
+/* ---------------------------------------------------------------------- */
+
 void ReadData::bondcoeffs()
 {
   int i,m;
@@ -1305,6 +1343,10 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom,
       if (force->pair == NULL)
         error->one(FLERR,"Must define pair_style before Pair Coeffs");
       skip_lines(atom->ntypes);
+    } else if (strcmp(keyword,"PairIJ Coeffs") == 0) {
+      if (force->pair == NULL)
+        error->one(FLERR,"Must define pair_style before Pair Coeffs");
+      skip_lines(atom->ntypes*(atom->ntypes+1)/2);
     } else if (strcmp(keyword,"Bond Coeffs") == 0) {
       if (atom->avec->bonds_allow == 0)
         error->one(FLERR,"Invalid data file section: Bond Coeffs");
diff --git a/src/read_data.h b/src/read_data.h
index 4788cdacf7..b1d3bb48b1 100644
--- a/src/read_data.h
+++ b/src/read_data.h
@@ -72,6 +72,7 @@ class ReadData : protected Pointers {
 
   void mass();
   void paircoeffs();
+  void pairIJcoeffs();
   void bondcoeffs();
   void anglecoeffs(int);
   void dihedralcoeffs(int);
diff --git a/src/write_data.cpp b/src/write_data.cpp
index cfb1f7855a..0f3de354ed 100644
--- a/src/write_data.cpp
+++ b/src/write_data.cpp
@@ -37,6 +37,7 @@
 using namespace LAMMPS_NS;
 
 enum{IGNORE,WARN,ERROR};                    // same as thermo.cpp
+enum{II,IJ};
 
 /* ---------------------------------------------------------------------- */
 
@@ -54,7 +55,8 @@ void WriteData::command(int narg, char **arg)
 {
   if (domain->box_exist == 0)
     error->all(FLERR,"Write_data command before simulation box is defined");
-  if (narg != 1) error->all(FLERR,"Illegal write_data command");
+
+  if (narg < 1) error->all(FLERR,"Illegal write_data command");
 
   // if filename contains a "*", replace with current timestep
 
@@ -67,6 +69,21 @@ void WriteData::command(int narg, char **arg)
     sprintf(file,"%s" BIGINT_FORMAT "%s",arg[0],update->ntimestep,ptr+1);
   } else strcpy(file,arg[0]);
 
+  // read optional args
+
+  pairflag = II;
+
+  int iarg = 1;
+  while (iarg < narg) {
+    if (strcmp(arg[iarg],"pair") == 0) {
+      if (iarg+2 > narg) error->all(FLERR,"Illegal write_data command");
+      if (strcmp(arg[iarg+1],"ii") == 0) pairflag = II;
+      else if (strcmp(arg[iarg+1],"ij") == 0) pairflag = IJ;
+      else error->all(FLERR,"Illegal write_data command");
+      iarg += 2;
+    } else error->all(FLERR,"Illegal write_data command");
+  }
+
   // init entire system since comm->exchange is done
   // comm::init needs neighbor::init needs pair::init needs kspace::init, etc
 
@@ -224,8 +241,13 @@ void WriteData::type_arrays()
 void WriteData::force_fields()
 {
   if (force->pair && force->pair->writedata) {
-    fprintf(fp,"\nPair Coeffs\n\n");
-    force->pair->write_data(fp);
+    if (pairflag == II) {
+      fprintf(fp,"\nPair Coeffs\n\n");
+      force->pair->write_data(fp);
+    } else if (pairflag == IJ) {
+      fprintf(fp,"\nPairIJ Coeffs\n\n");
+      force->pair->write_data_all(fp);
+    }
   }
   if (atom->avec->bonds_allow && force->bond && force->bond->writedata) {
     fprintf(fp,"\nBond Coeffs\n\n");
diff --git a/src/write_data.h b/src/write_data.h
index 7b30441926..e879b00d76 100644
--- a/src/write_data.h
+++ b/src/write_data.h
@@ -33,6 +33,7 @@ class WriteData : protected Pointers {
 
  private:
   int me,nprocs;
+  int pairflag;
   FILE *fp;
   bigint nbonds_local,nbonds;
   bigint nangles_local,nangles;
-- 
GitLab