Example #1
0
int get_espresso_coordnum(const char *infile)
{
    FILE    *fp;
    char     word[STRLEN];
    int      natoms, level, r;
    gmx_bool bFoundParticles;

    natoms = 0;

    fp = gmx_fio_fopen(infile, "r");

    bFoundParticles = FALSE;
    level           = 0;
    while ((r = get_espresso_word(fp, word)) && !bFoundParticles)
    {
        if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles)
        {
            bFoundParticles = TRUE;
            level          += check_open_parenthesis(fp, r, infile, "particles");
            while (level > 0 && (r = get_espresso_word(fp, word)))
            {
                if (r == 2)
                {
                    level++;
                    if (level == 2)
                    {
                        natoms++;
                    }
                }
                else if (r == 3)
                {
                    level--;
                }
            }
        }
        else if (r == 2)
        {
            level++;
        }
        else if (r == 3)
        {
            level--;
        }
    }
    if (!bFoundParticles)
    {
        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
                infile);
    }

    gmx_fio_fclose(fp);

    return natoms;
}
Example #2
0
static int check_close_parenthesis(FILE *fp, int r,
                                   const char *infile, const char *keyword)
{
    int  level_inc;
    char word[STRLEN];

    level_inc = 0;
    if (r == 3)
    {
        level_inc--;
    }
    else
    {
        r = get_espresso_word(fp, word);
        if (r == 3)
        {
            level_inc--;
        }
        else
        {
            gmx_fatal(FARGS, "Expected '}' after section '%s' in file '%s'",
                      keyword, infile);
        }
    }

    return level_inc;
}
Example #3
0
static int check_open_parenthesis(FILE *fp,int r,
				  const char *infile,const char *keyword)
{
  int level_inc;
  char word[STRLEN];

  level_inc = 0;
  if (r == 2) {
    level_inc++;
  } else {
    r = get_espresso_word(fp,word);
    if (r == 2)
      level_inc++;
    else
      gmx_fatal(FARGS,"Expected '{' after '%s' in file '%s'",
		keyword,infile);
  }

  return level_inc;
}
Example #4
0
void gmx_espresso_read_conf(const char *infile,
                            t_topology *top, rvec x[], rvec *v, matrix box)
{
    t_atoms  *atoms = &top->atoms;
    FILE     *fp;
    char      word[STRLEN], buf[STRLEN];
    int       level, r, nprop, p, i, m, molnr;
    int       prop[32];
    double    d;
    gmx_bool  bFoundParticles, bFoundProp, bFoundVariable, bMol;

    // TODO: The code does not understand titles it writes...
    top->name = put_symtab(&top->symtab, "");

    clear_mat(box);

    fp = gmx_fio_fopen(infile, "r");

    bFoundParticles = FALSE;
    bFoundVariable  = FALSE;
    bMol            = FALSE;
    level           = 0;
    while ((r = get_espresso_word(fp, word)))
    {
        if (level == 1 && std::strcmp(word, "particles") == 0 && !bFoundParticles)
        {
            bFoundParticles = TRUE;
            level          += check_open_parenthesis(fp, r, infile, "particles");
            nprop           = 0;
            while (level == 2 && (r = get_espresso_word(fp, word)))
            {
                bFoundProp = FALSE;
                for (p = 0; p < espNR; p++)
                {
                    if (strcmp(word, esp_prop[p]) == 0)
                    {
                        bFoundProp    = TRUE;
                        prop[nprop++] = p;
                        /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
                    }
                }
                if (!bFoundProp && word[0] != '}')
                {
                    gmx_fatal(FARGS, "Can not read Espresso files with particle property '%s'", word);
                }
                if (bFoundProp && p == espMOLECULE)
                {
                    bMol = TRUE;
                }
                if (r == 3)
                {
                    level--;
                }
            }

            i = 0;
            while (level > 0 && (r = get_espresso_word(fp, word)))
            {
                if (r == 2)
                {
                    level++;
                }
                else if (r == 3)
                {
                    level--;
                }
                if (level == 2)
                {
                    for (p = 0; p < nprop; p++)
                    {
                        switch (prop[p])
                        {
                            case espID:
                                r = get_espresso_word(fp, word);
                                /* Not used */
                                break;
                            case espPOS:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    sscanf(word, "%lf", &d);
                                    x[i][m] = d;
                                }
                                break;
                            case espTYPE:
                                r                   = get_espresso_word(fp, word);
                                atoms->atom[i].type = std::strtol(word, NULL, 10);
                                break;
                            case espQ:
                                r = get_espresso_word(fp, word);
                                sscanf(word, "%lf", &d);
                                atoms->atom[i].q = d;
                                break;
                            case espV:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    sscanf(word, "%lf", &d);
                                    v[i][m] = d;
                                }
                                break;
                            case espF:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    /* not used */
                                }
                                break;
                            case espMOLECULE:
                                r     = get_espresso_word(fp, word);
                                molnr = std::strtol(word, NULL, 10);
                                if (i == 0 ||
                                    atoms->resinfo[atoms->atom[i-1].resind].nr != molnr)
                                {
                                    atoms->atom[i].resind =
                                        (i == 0 ? 0 : atoms->atom[i-1].resind+1);
                                    atoms->resinfo[atoms->atom[i].resind].nr       = molnr;
                                    atoms->resinfo[atoms->atom[i].resind].ic       = ' ';
                                    atoms->resinfo[atoms->atom[i].resind].chainid  = ' ';
                                    atoms->resinfo[atoms->atom[i].resind].chainnum = molnr; /* Not sure if this is right? */
                                }
                                else
                                {
                                    atoms->atom[i].resind = atoms->atom[i-1].resind;
                                }
                                break;
                        }
                    }
                    /* Generate an atom name from the particle type */
                    sprintf(buf, "T%u", atoms->atom[i].type);
                    atoms->atomname[i] = put_symtab(&top->symtab, buf);
                    if (bMol)
                    {
                        if (i == 0 || atoms->atom[i].resind != atoms->atom[i-1].resind)
                        {
                            atoms->resinfo[atoms->atom[i].resind].name =
                                put_symtab(&top->symtab, "MOL");
                        }
                    }
                    else
                    {
                        /* Residue number is the atom number */
                        atoms->atom[i].resind = i;
                        /* Generate an residue name from the particle type */
                        if (atoms->atom[i].type < 26)
                        {
                            sprintf(buf, "T%c", 'A'+atoms->atom[i].type);
                        }
                        else
                        {
                            sprintf(buf, "T%c%c",
                                    'A'+atoms->atom[i].type/26, 'A'+atoms->atom[i].type%26);
                        }
                        t_atoms_set_resinfo(atoms, i, &top->symtab, buf, i, ' ', 0, ' ');
                    }

                    if (r == 3)
                    {
                        level--;
                    }
                    i++;
                }
            }
            atoms->nres = atoms->nr;

            if (i != atoms->nr)
            {
                gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr);
            }
        }
        else if (level == 1 && std::strcmp(word, "variable") == 0 && !bFoundVariable)
        {
            bFoundVariable = TRUE;
            level         += check_open_parenthesis(fp, r, infile, "variable");
            while (level == 2 && (r = get_espresso_word(fp, word)))
            {
                if (level == 2 && std::strcmp(word, "box_l") == 0)
                {
                    for (m = 0; m < 3; m++)
                    {
                        r = get_espresso_word(fp, word);
                        sscanf(word, "%lf", &d);
                        box[m][m] = d;
                    }
                    level += check_close_parenthesis(fp, r, infile, "box_l");
                }
            }
        }
        else if (r == 2)
        {
            level++;
        }
        else if (r == 3)
        {
            level--;
        }
    }

    if (!bFoundParticles)
    {
        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
                infile);
    }

    gmx_fio_fclose(fp);
}
Example #5
0
static void read_espresso_conf(char *infile,
			       t_atoms *atoms,rvec x[],rvec *v,matrix box)
{
  static t_symtab *symtab=NULL;
  FILE *fp;
  char word[STRLEN],buf[STRLEN];
  int  natoms,level,npar,r,nprop,p,i,m;
  int  prop[32];
  double d;
  bool bFoundParticles,bFoundProp,bFoundVariable,bMol;

  if (!symtab) {
    snew(symtab,1);
    open_symtab(symtab);
  }

  clear_mat(box);
  
  fp = gmx_fio_fopen(infile,"r");
  
  bFoundParticles = FALSE;
  bFoundVariable = FALSE;
  bMol = FALSE;
  level = 0;
  while ((r=get_espresso_word(fp,word))) {
    if (level==1 && strcmp(word,"particles")==0 && !bFoundParticles) {
      bFoundParticles = TRUE;
      level += check_open_parenthesis(fp,r,infile,"particles");
      nprop = 0;
      while (level == 2 && (r=get_espresso_word(fp,word))) {
	bFoundProp = FALSE;
	for(p=0; p<espNR; p++) {
	  if (strcmp(word,esp_prop[p]) == 0) {
	    bFoundProp = TRUE;
	    prop[nprop++] = p;
	    /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
	  }
	}
	if (!bFoundProp && word[0] != '}') {
	  gmx_fatal(FARGS,"Can not read Espresso files with particle property '%s'",word);
	}
	if (bFoundProp && p == espMOLECULE)
	  bMol = TRUE;
	if (r == 3)
	  level--;
      }
      
      i = 0;
      while (level > 0 && (r=get_espresso_word(fp,word))) {
	if (r == 2) {
	  level++;
	} else if (r == 3) {
	  level--;
	}
	if (level == 2) {
	  for(p=0; p<nprop; p++) {
	    switch (prop[p]) {
	    case espID:
	      r = get_espresso_word(fp,word);
	      /* Not used */
	      break;
	    case espPOS:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		sscanf(word,"%lf",&d);
		x[i][m] = d;
	      }
	      break;
	    case espTYPE:
	      r = get_espresso_word(fp,word);
	      atoms->atom[i].type = atoi(word);
	      break;
	    case espQ:
	      r = get_espresso_word(fp,word);
	      sscanf(word,"%lf",&d);
	      atoms->atom[i].q = d;
	      break;
	    case espV:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		sscanf(word,"%lf",&d);
		v[i][m] = d;
	      }
	      break;
	    case espF:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		/* not used */
	      }
	      break;
	    case espMOLECULE:
	      r = get_espresso_word(fp,word);
	      atoms->atom[i].resnr = atoi(word);
	      break;
	    }
	  }
	  /* Generate an atom name from the particle type */
	  sprintf(buf,"T%d",atoms->atom[i].type);
	  atoms->atomname[i] = put_symtab(symtab,buf);
	  if (bMol) {
	    if (i == 0 || atoms->atom[i].resnr != atoms->atom[i-1].resnr) {
	      atoms->resname[atoms->atom[i].resnr] = put_symtab(symtab,"MOL");
	    }
	  } else {
	    /* Residue number is the atom number */
	    atoms->atom[i].resnr = i;
	    /* Generate an residue name from the particle type */
	    if (atoms->atom[i].type < 26) {
	      sprintf(buf,"T%c",'A'+atoms->atom[i].type);
	    } else {
	      sprintf(buf,"T%c%c",
		      'A'+atoms->atom[i].type/26,'A'+atoms->atom[i].type%26);
	    }
	    atoms->resname[atoms->atom[i].resnr] = put_symtab(symtab,buf);
	  }	  

	  if (r == 3)
	    level--;
	  i++;
	}
      }
      atoms->nres = atoms->nr;

      if (i != atoms->nr) {
	gmx_fatal(FARGS,"Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms",i,atoms->nr);
      }
    } else if (level==1 && strcmp(word,"variable")==0 && !bFoundVariable) {
      bFoundVariable = TRUE;
      level += check_open_parenthesis(fp,r,infile,"variable");
      while (level==2 && (r=get_espresso_word(fp,word))) {
	if (level==2 && strcmp(word,"box_l") == 0) {
	  for(m=0; m<3; m++) {
	    r = get_espresso_word(fp,word);
	    sscanf(word,"%lf",&d);
	    box[m][m] = d;
	  }
	  level += check_close_parenthesis(fp,r,infile,"box_l");
	}
      }
    } else if (r == 2) {
      level++;
    } else if (r == 3) {
      level--;
    }
  }
  
  if (!bFoundParticles) {
    fprintf(stderr,"Did not find a particles section in Espresso file '%s'\n",
	    infile);
  }
  
  gmx_fio_fclose(fp);
}