Exemplo n.º 1
0
atom_id search_atom(char *type,int start,int natoms,t_atom at[],char **anm[],
		    char *bondtype,bool bDontQuit)
{
  int     i,resnr=-1;
  bool    bPrevious,bNext;

  bPrevious = (strchr(type,'-') != NULL);
  bNext     = (strchr(type,'+') != NULL);

  if (!bPrevious) {
    resnr = at[start].resnr;
    if (bNext) {
      /* The next residue */
      type++;
      while ((start<natoms) && (at[start].resnr == resnr))
	start++;
      if (start < natoms)
	resnr = at[start].resnr;
    }
    
    for(i=start; (i<natoms) && (bNext || (at[i].resnr == resnr)); i++) {
      if (strcasecmp(type,*(anm[i]))==0)
	return (atom_id) i;
    }
    if (!(bNext && at[start].resnr==at[natoms-1].resnr))
      atom_not_found(FARGS,type,at[start].resnr+1,bondtype,bDontQuit);
  }
  else {
    /* The previous residue */
    type++;
    if (start > 0)
      resnr = at[start-1].resnr;
    for(i=start-1; (i>=0) /*&& (at[i].resnr == resnr)*/; i--)
      if (strcasecmp(type,*(anm[i]))==0)
	return (atom_id) i;
    if (start > 0)
      atom_not_found(FARGS,type,at[start].resnr+1,bondtype,bDontQuit);
  }
  return NO_ATID;
}
Exemplo n.º 2
0
int search_atom(const char *type, int start,
                t_atoms *atoms,
                const char *bondtype, bool bAllowMissing)
{
    int             i, resind = -1;
    bool            bPrevious, bNext;
    int             natoms = atoms->nr;
    t_atom         *at     = atoms->atom;
    char ** const * anm    = atoms->atomname;

    bPrevious = (strchr(type, '-') != nullptr);
    bNext     = (strchr(type, '+') != nullptr);

    if (!bPrevious)
    {
        resind = at[start].resind;
        if (bNext)
        {
            /* The next residue */
            type++;
            while ((start < natoms) && (at[start].resind == resind))
            {
                start++;
            }
            if (start < natoms)
            {
                resind = at[start].resind;
            }
        }

        for (i = start; (i < natoms) && (bNext || (at[i].resind == resind)); i++)
        {
            if (anm[i] && gmx_strcasecmp(type, *(anm[i])) == 0)
            {
                return i;
            }
        }
        if (!(bNext && at[start].resind == at[natoms-1].resind))
        {
            atom_not_found(FARGS, type, at[start].resind, *atoms->resinfo[resind].name, bondtype, bAllowMissing);
        }
    }
    else
    {
        /* The previous residue */
        type++;
        if (start > 0)
        {
            resind = at[start-1].resind;
        }
        for (i = start-1; (i >= 0) /*&& (at[i].resind == resind)*/; i--)
        {
            if (gmx_strcasecmp(type, *(anm[i])) == 0)
            {
                return i;
            }
        }
        if (start > 0)
        {
            atom_not_found(FARGS, type, at[start].resind, *atoms->resinfo[resind].name, bondtype, bAllowMissing);
        }
    }
    return -1;
}