Commit 0eeb2407 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

whitespace cleanup, fix bug in looking for empty strings, improve read...

whitespace cleanup, fix bug in looking for empty strings, improve read performance and handling of comments
parent c88acc96
Loading
Loading
Loading
Loading
+217 −200
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@

/* ----------------------------------------------------------------------
   Implementation of the CHARMM CMAP; adds an extra energy term for the
   peptide backbone dihedrals.  The tools/ch2lmp.pl conversion script, which
   generates an extra section in the LAMMPS data file, is needed in order to
   generate the info used by this fix style.
   peptide backbone dihedrals.  The tools/ch2lmp/charmm2lammps.pl
   conversion script, which generates an extra section in the LAMMPS data
   file, is needed in order to generate the info used by this fix style.

   Contributing authors:
   Xiaohu Hu, CMB/ORNL (hux2@ornl.gov)
@@ -27,11 +27,11 @@
   - MacKerell et al., J. Comput. Chem. 25(2004):1400-1415.
 -------------------------------------------------------------------------*/

#include "mpi.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include <mpi.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "fix_cmap.h"
#include "atom.h"
#include "atom_vec.h"
@@ -622,16 +622,19 @@ double FixCMAP::compute_scalar()

void FixCMAP::read_grid_map(char *cmapfile)
{
  char line[MAXLINE];
  char *chunk;
  char linebuf[MAXLINE];
  char *chunk,*line;
  int i1, i2, i3, i4, i5, i6, j1, j2, j3, j4, j5, j6, counter;

  FILE *fp = fopen(cmapfile,"r");
  FILE *fp = NULL;
  if (comm->me == 0) {
    fp = force->open_potential(cmapfile);
    if (fp == NULL) {
      char str[128];
      sprintf(str,"Cannot open fix cmap file %s",cmapfile);
      error->one(FLERR,str);
    }
  }

  for (int ix1 = 0; ix1 < 6; ix1++)
    for (int ix2 = 0; ix2 < CMAPDIM; ix2++)
@@ -642,8 +645,24 @@ void FixCMAP::read_grid_map(char *cmapfile)
  i1 = i2 = i3 = i4 = i5 = i6 = 0;
  j1 = j2 = j3 = j4 = j5 = j6 = 0;

  while (fgets(line,MAXLINE,fp) != NULL) {
    if (line == "" || line[0] == '#') { ;; }
  int done = 0;

  while (!done) {
    // only read on rank 0 and broadcast to all other ranks
    if (comm->me == 0)
      done = (fgets(linebuf,MAXLINE,fp) == NULL);

    MPI_Bcast(&done,1,MPI_INT,0,world);
    if (done) continue;

    MPI_Bcast(linebuf,MAXLINE,MPI_CHAR,0,world);

    // remove leading whitespace
    line = linebuf;
    while (line && (*line == ' ' || *line == '\t' || *line == '\r')) ++line;

    // skip if empty line or comment
    if (!line || *line =='\n' || *line == '\0' || *line == '#') continue;

    // read in the cmap grid point values
    // NOTE: The order to read the 6 grid maps is HARD-CODED, thus errors
@@ -657,7 +676,6 @@ void FixCMAP::read_grid_map(char *cmapfile)
    // 5. Glycine map
    // 6. Glycine before proline map

    else {
    chunk = strtok(line, " \r\n");
    while (chunk != NULL) {

@@ -747,9 +765,8 @@ void FixCMAP::read_grid_map(char *cmapfile)
      else break;
    }
  }
  }

  fclose(fp);
  if (comm->me == 0) fclose(fp);
}

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