Esempio n. 1
0
/* Read in the next atom info into the given storage areas; this assumes
   that file has already been moved to the beginning of the atom records.
   Returns the serial number of the atom. If there is an error, returns -1.*/
static int get_psf_atom(FILE *f, char *name, char *atype, char *resname,
   char *segname, int *resid, float *q, float *m, int charmmext) {
  char inbuf[PSF_RECORD_LENGTH+2];
  int num;

  if (inbuf != fgets(inbuf, PSF_RECORD_LENGTH+1, f)) {
    return(-1); /* failed to read in an atom */
  }

  if (strlen(inbuf) < 50) {
    fprintf(stderr, "Line too short in psf file: \n%s\n", inbuf);
    return -1;
  }

  num = atoi(inbuf); /* atom index */

  if (charmmext == 1) {
    /* CHARMM PSF format is (if CMAP,CHEQ are also included):
     *  '(I10,1X,A8,1X,A8,1X,A8,1X,A8,1X,I4,1X,2G14.6,I8,2G14.6)'
     */
    strnwscpy(segname, inbuf+11, 7);
    strnwscpy(resname, inbuf+29, 7);
    strnwscpy(name, inbuf+38, 7);
    strnwscpy(atype, inbuf+47, 4);
    
    *resid = atoi(inbuf+20);
    *q = (float) atof(inbuf+52);
    *m = (float) atof(inbuf+68);
  } else {
    strnwscpy(segname, inbuf+9, 4);
    strnwscpy(resname, inbuf+19, 4);
    strnwscpy(name, inbuf+24, 4);
    strnwscpy(atype, inbuf+29, 4);

    *resid = atoi(inbuf+13);
    *q = (float) atof(inbuf+34);
    *m = (float) atof(inbuf+50);
  }

#if 0
  /* if this is a Charmm31 PSF file, there may be two extra */
  /* columns containing polarizable force field data.       */
  if (psf->charmmcheq) {
    /* do something to read in these columns here */
  }
#endif

  return num;
}
Esempio n. 2
0
/* Read in the next atom info into the given storage areas; this assumes
   that file has already been moved to the beginning of the atom records.
   Returns the serial number of the atom. If there is an error, returns -1.*/
static int get_psf_atom(FILE *f, char *name, char *atype, char *resname,
                        char *segname, int *resid, float *q, float *m, 
                        int namdfmt, int charmmext, int charmmdrude) {
  char inbuf[PSF_RECORD_LENGTH+2];
  int num;

  if (inbuf != fgets(inbuf, PSF_RECORD_LENGTH+1, f)) {
    return(-1); /* failed to read in an atom */
  }

  if (strlen(inbuf) < 50) {
    fprintf(stderr, "Line too short in psf file: \n%s\n", inbuf);
    return -1;
  }

  num = atoi(inbuf); /* atom index */

  if (namdfmt == 1) {
    /* XXX We should add field width limits here so that      */
    /*     a PSF file with crazy wide fields cannot overwrite */
    /*     destination buffers.                               */
    int cnt;
    cnt = sscanf(inbuf, "%d %s %d %s %s %s %f %f",
                 &num, segname, resid, resname, name, atype, q, m);
    if (cnt != 8) {
      printf("psfplugin) Failed to parse atom line in NAMD PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
  } else if (charmmdrude == 1) {
    /* CHARMM PSF format is (if DRUDE and CHEQ are enabled):
     *  '(I10,1X,A8,1X,A8,1X,A8,1X,A8,1X,I4,1X,2G14.6,I8,2G14.6)'
     */
    strnwscpy(segname, inbuf+11, 7);
    strnwscpy(resname, inbuf+29, 7);
    strnwscpy(name, inbuf+38, 7);
    strnwscpy(atype, inbuf+47, 4);
    
    *resid = atoi(inbuf+20);
    *q = (float) atof(inbuf+52);
    *m = (float) atof(inbuf+68);
    // data we don't currently read:
    //   *imove = atoi(inbuf+84);
    //   *alphadp = atof(inbuf+92);
    //   *tholei = atof(inbuf+108);
  } else if (charmmext == 1) {
    /* CHARMM PSF format is (if CMAP and CHEQ are also enabled):
     *  '(I10,1X,A8,1X,A8,1X,A8,1X,A8,1X,I4,1X,2G14.6,I8,2G14.6)'
     */
    strnwscpy(segname, inbuf+11, 7);
    strnwscpy(resname, inbuf+29, 7);
    strnwscpy(name, inbuf+38, 7);
    strnwscpy(atype, inbuf+47, 4);
    
    *resid = atoi(inbuf+20);
    *q = (float) atof(inbuf+52);
    *m = (float) atof(inbuf+68);
  } else {
    /* CHARMM PSF format is 
     *  '(I8,1X,A4,1X,A4,1X,A4,1X,A4,1X,I4,1X,2G14.6,I8)'
     */
    strnwscpy(segname, inbuf+9, 4);
    strnwscpy(resname, inbuf+19, 4);
    strnwscpy(name, inbuf+24, 4);
    strnwscpy(atype, inbuf+29, 4);

    *resid = atoi(inbuf+13);
    *q = (float) atof(inbuf+34);
    *m = (float) atof(inbuf+50);
  }

#if 0
  /* if this is a Charmm31 PSF file, there may be two extra */
  /* columns containing polarizable force field data.       */
  if (psf->charmmcheq) {
    /* do something to read in these columns here */
  }
#endif

  return num;
}
Esempio n. 3
0
/* Read in the next atom info into the given storage areas; this assumes
   that file has already been moved to the beginning of the atom records.
   Returns the serial number of the atom. If there is an error, returns -1.*/
static int get_psf_atom(FILE *f, char *name, char *atype, char *resname,
                        char *segname, int *resid, char *insertion, float *q, float *m, 
                        int namdfmt, int charmmext, int charmmdrude) {
  char inbuf[PSF_RECORD_LENGTH+2];
  int num;

  if (inbuf != fgets(inbuf, PSF_RECORD_LENGTH+1, f)) {
    return(-1); /* failed to read in an atom */
  }

  if (strlen(inbuf) < 50) {
    fprintf(stderr, "Line too short in psf file: \n%s\n", inbuf);
    return -1;
  }

  num = atoi(inbuf); /* atom index */

  if (namdfmt == 1) {
    int cnt, rcnt;
    char residstr[8], trash;
    cnt = sscanf(inbuf, "%d %7s %7s %7s %7s %7s %f %f",
                 &num, segname, residstr, resname, name, atype, q, m);
    insertion[0] = ' ';  insertion[1] = '\0';
    rcnt = sscanf(residstr, "%d%c%c", resid, insertion, &trash);
    if (cnt != 8 || rcnt < 1 || rcnt > 2) {
      printf("psfplugin) Failed to parse atom line in NAMD PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
  } else if (charmmdrude == 1 || charmmext == 1) {
    int xplorshift;
    /* CHARMM PSF format is (if DRUDE or (?) CHEQ are enabled):
     *  '(I10,1X,A8,1X,A8,1X,A8,1X,A8,1X,I4,1X,2G14.6,I8,2G14.6)'
     */
    if ( inbuf[10] != ' ' ||
         inbuf[19] != ' ' ||
         inbuf[28] != ' ' ||
         inbuf[37] != ' ' ||
         inbuf[46] != ' ' ) {
      printf("psfplugin) Failed to parse atom line in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }

    strnwscpy(segname, inbuf+11, 7);
    strnwscpy(resname, inbuf+29, 7);
    strnwscpy(name, inbuf+38, 7);

    xplorshift = 0;
    strnwscpy(atype, inbuf+47, 4);
    if ( ! isdigit(atype[0]) ) {
      strnwscpy(atype, inbuf+47, 6);
      xplorshift = 2;
    }

    if ( inbuf[51+xplorshift] != ' ' ) {
      printf("psfplugin) Failed to parse atom line in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    
    insertion[0] = ' ';  insertion[1] = '\0';
    sscanf(inbuf+20, "%d%c", resid, insertion);
    *q = (float) atof(inbuf+52+xplorshift);
    *m = (float) atof(inbuf+66+xplorshift);
    // data we don't currently read:
    // if (charmmdrude == 1) {
    //   *imove = atoi(inbuf+80+xplorshift);
    //   *alphadp = atof(inbuf+88+xplorshift);
    //   *tholei = atof(inbuf+102+xplorshift);
    // }
  } else {
    /* CHARMM PSF format is 
     *  '(I8,1X,A4,1X,A4,1X,A4,1X,A4,1X,I4,1X,2G14.6,I8)'
     */
    const char *rdbuf = inbuf;
    char intbuf[16];

    intbuf[0] = '\0';
    rdbuf += strnwscpy_shift(intbuf, rdbuf, 8, 10);
    if ( rdbuf[8] != ' ' ) {
      printf("psfplugin) Failed to parse atom index in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    rdbuf += strnwscpy_shift(segname, rdbuf+9, 4, 7);
    if ( rdbuf[13] != ' ' ) {
      printf("psfplugin) Failed to parse segname in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    intbuf[0] = '\0';
    rdbuf += strnwscpy_shift(intbuf, rdbuf+14, 4, 8);
    insertion[0] = ' ';  insertion[1] = '\0';
    sscanf(intbuf, "%d%c", resid, insertion);
    if ( rdbuf[18] != ' ' ) {
      printf("psfplugin) Failed to parse resid in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    rdbuf += strnwscpy_shift(resname, rdbuf+19, 4, 7);
    if ( rdbuf[23] != ' ' ) {
      printf("psfplugin) Failed to parse resname in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    rdbuf += strnwscpy_shift(name, rdbuf+24, 4, 7);
    if ( rdbuf[28] != ' ' ) {
      printf("psfplugin) Failed to parse atom name in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    rdbuf += strnwscpy_shift(atype, rdbuf+29, 4, 7);
    if ( rdbuf[33] != ' ' ) {
      printf("psfplugin) Failed to parse atom type in PSF file:\n");
      printf("psfplugin)   '%s'\n", inbuf);
      return -1;
    }
    *q = (float) atof(rdbuf+34);
    *m = (float) atof(rdbuf+48);
  }

#if 0
  /* if this is a Charmm31 PSF file, there may be two extra */
  /* columns containing polarizable force field data.       */
  if (psf->charmmcheq) {
    /* do something to read in these columns here */
  }
#endif

  return num;
}