Unverified Commit 64faa6c6 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #1553 from athomps/read_dump_xyz

Fixed a few problems with read_dump xyz
parents 0d15c57f 7a627170
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ void ReaderMolfile::skip()
   only called by proc 0
------------------------------------------------------------------------- */

bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
bigint ReaderMolfile::read_header(double box[3][3], int &boxinfo, int &triclinic,
                                  int fieldinfo, int nfield,
                                  int *fieldtype, char ** /* fieldlabel */,
                                  int scaleflag, int wrapflag, int &fieldflag,
@@ -204,17 +204,24 @@ bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
  nid = 0;

  // signal that we have no box info at all so far.
  triclinic = -1;

  boxinfo = 0;
  triclinic = 0;

  // 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)) {
    boxinfo = 1;
    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;
@@ -224,6 +231,7 @@ bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
      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;
@@ -243,7 +251,8 @@ bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
        (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 */
      // go from box length to boundary

      double xbnd;

      xbnd = 0.0;
@@ -275,6 +284,7 @@ bigint ReaderMolfile::read_header(double box[3][3], int &triclinic,
  }

  // if no field info requested, just return
 
 if (!fieldinfo) return natoms;

  memory->create(fieldindex,nfield,"read_dump:fieldindex");
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class ReaderMolfile : public Reader {

  virtual int read_time(bigint &);
  virtual void skip();
  virtual bigint read_header(double [3][3], int &, int, int, int *, char **,
  virtual bigint read_header(double [3][3], int &, int &, int, int, int *, char **,
                             int, int, int &, int &, int &, int &);
  virtual void read_atoms(int, int, double **);

+36 −32
Original line number Diff line number Diff line
@@ -483,30 +483,33 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip)

void ReadDump::header(int fieldinfo)
{
  int triclinic_snap;
  int boxinfo, triclinic_snap;
  int fieldflag,xflag,yflag,zflag;

  if (filereader) {
    for (int i = 0; i < nreader; i++)
      nsnapatoms[i] = readers[i]->read_header(box,triclinic_snap,fieldinfo,
      nsnapatoms[i] = readers[i]->read_header(box,boxinfo,triclinic_snap,fieldinfo,
                                              nfield,fieldtype,fieldlabel,
                                              scaleflag,wrapflag,fieldflag,
                                              xflag,yflag,zflag);
  }

  MPI_Bcast(nsnapatoms,nreader,MPI_LMP_BIGINT,0,clustercomm);
  MPI_Bcast(&boxinfo,1,MPI_INT,0,clustercomm);
  MPI_Bcast(&triclinic_snap,1,MPI_INT,0,clustercomm);
  MPI_Bcast(&box[0][0],9,MPI_DOUBLE,0,clustercomm);

  // local copy of snapshot box parameters
  // used in xfield,yfield,zfield when converting dump atom to absolute coords

  if (boxinfo) {
    xlo = box[0][0];
    xhi = box[0][1];
    ylo = box[1][0];
    yhi = box[1][1];
    zlo = box[2][0];
    zhi = box[2][1];
    
    if (triclinic_snap) {
      xy = box[0][2];
      xz = box[1][2];
@@ -525,6 +528,7 @@ void ReadDump::header(int fieldinfo)
    xprd = xhi - xlo;
    yprd = yhi - ylo;
    zprd = zhi - zlo;
  }

  // done if not checking fields

@@ -536,17 +540,17 @@ void ReadDump::header(int fieldinfo)
  MPI_Bcast(&zflag,1,MPI_INT,0,clustercomm);

  // error check on current vs new box and fields
  // triclinic_snap < 0 means no box info in file
  // boxinfo == 0 means no box info in file

  if (triclinic_snap < 0 && boxflag > 0)
  if (boxflag) {
    if (!boxinfo)
      error->all(FLERR,"No box information in dump, must use 'box no'");
  if (triclinic_snap >= 0) {
    if ((triclinic_snap && !triclinic) ||
    else if ((triclinic_snap && !triclinic) ||
             (!triclinic_snap && triclinic))
      error->one(FLERR,"Read_dump triclinic status does not match simulation");
  }

  // error check on requested fields exisiting in dump file
  // error check on requested fields existing in dump file

  if (fieldflag < 0)
    error->one(FLERR,"Read_dump field not found in dump file");
+10 −0
Original line number Diff line number Diff line
@@ -75,3 +75,13 @@ void Reader::close_file()
  else fclose(fp);
  fp = NULL;
}

/* ----------------------------------------------------------------------
   detect unused arguments
------------------------------------------------------------------------- */

void Reader::settings(int narg, char** /*args*/)
{
  if (narg > 0)
    error->all(FLERR,"Illegal read_dump command");
}
+2 −2
Original line number Diff line number Diff line
@@ -25,11 +25,11 @@ class Reader : protected Pointers {
  Reader(class LAMMPS *);
  virtual ~Reader() {}

  virtual void settings(int, char**) {};
  virtual void settings(int, char**);

  virtual int read_time(bigint &) = 0;
  virtual void skip() = 0;
  virtual bigint read_header(double [3][3], int &, int, int, int *, char **,
  virtual bigint read_header(double [3][3], int &, int &, int, int, int *, char **,
                             int, int, int &, int &, int &, int &) = 0;
  virtual void read_atoms(int, int, double **) = 0;

Loading