Atom counts in NEB

Does it make sense to add a check in neb.cpp that verifies that the number
of atoms read in for the reactant image is the same as the number of atoms
in the product image? This would catch user input errors instead of
either producing garbage output or segmentation errors. The patch below
may work, which does the following: (1) count the number of lines read,
(2) broadcast that number, (3) check that it is equal to the number of
atoms. If not, exit with a universal error.

Here's the diff:
--- src/neb.cpp 2013-04-03 00:31:25.720758100 -0400
+++ ../sandbox/neb.cpp 2013-05-14 12:44:51.467440388 -0400
@@ -332,6 +332,7 @@
    int firstline = 1;
    int ncount = 0;
    int eof = 0;
+ bigint nlines_read = 0;

    while (!eof) {
      if (me_universe == 0) {
@@ -339,6 +340,7 @@
        for (nlines = 0; nlines < CHUNK; nlines++) {
          ptr = fgets(&buffer[m],MAXLINE,fp);
          if (ptr == NULL) break;
+ nlines_read++;
          m += strlen(&buffer[m]);
        }
        if (ptr == NULL) eof = 1;
@@ -386,6 +388,10 @@
      }
    }

+ MPI_Bcast(&nlines_read,1,MPI_LMP_BIGINT,0,uworld);
+ if ( nlines_read != atom->natoms )
+ error->universe_all(FLERR,
+ "Different number of atoms in NEB reactant and product images.");
    // clean up

    delete [] buffer;
/* END DIFF */

If you're curious, I managed to trip this by "creating" an atom in my
product image that was outside the simulation box (I forgot "remap yes"
on "create_atoms single").

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]...

"You can never know everything, and part of what you know is always
   wrong. A portion of wisdom lies in knowing that. A portion of courage
   lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
   surprised."