예제 #1
0
static gmx_bool parse_int(char **string, int *nr)
{
    char    *orig, c;
    gmx_bool bRet;

    orig = *string;
    bRet = parse_int_char(string, nr, &c);
    if (bRet && c != ' ')
    {
        *string = orig;
        bRet    = FALSE;
    }

    return bRet;
}
예제 #2
0
static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
                            t_blocka *block, char ***gn,
                            atom_id *nr, atom_id *index, char *gname)
{
    static char   **names, *ostring;
    static gmx_bool bFirst = TRUE;
    int             j, n_names, sel_nr1;
    atom_id         i, nr1, *index1;
    char            c;
    gmx_bool        bRet, bCompl;

    if (bFirst)
    {
        bFirst = FALSE;
        snew(names, MAXNAMES);
        for (i = 0; i < MAXNAMES; i++)
        {
            snew(names[i], NAME_LEN+1);
        }
    }

    bRet    = FALSE;
    sel_nr1 = NOTSET;

    while (*string[0] == ' ')
    {
        (*string)++;
    }

    if ((*string)[0] == '!')
    {
        bCompl = TRUE;
        (*string)++;
        while (*string[0] == ' ')
        {
            (*string)++;
        }
    }
    else
    {
        bCompl = FALSE;
    }

    ostring = *string;

    if (parse_int(string, &sel_nr1) ||
        parse_string(string, &sel_nr1, block->nr, *gn))
    {
        if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
        {
            copy_group(sel_nr1, block, nr, index);
            strcpy(gname, (*gn)[sel_nr1]);
            printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
            bRet = TRUE;
        }
        else
        {
            printf("Group %d does not exist\n", sel_nr1);
        }
    }
    else if ((*string)[0] == 'a')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring))
        {
            if (parse_int(string, &sel_nr1))
            {
                bRet = select_atomnumbers(string, atoms, sel_nr1, nr, index, gname);
            }
            else if (parse_names(string, &n_names, names))
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, FALSE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if ((*string)[0] == 't')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring) &&
            parse_names(string, &n_names, names))
        {
            if (atoms->atomtype == NULL)
            {
                printf("Need a run input file to select atom types\n");
            }
            else
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, TRUE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if (strncmp(*string, "res", 3) == 0)
    {
        (*string) += 3;
        if (check_have_atoms(atoms, ostring) &&
            parse_int(string, &sel_nr1) &&
            (sel_nr1 >= 0) && (sel_nr1 < block->nr) )
        {
            bRet = atoms_from_residuenumbers(atoms,
                                             sel_nr1, block, nr, index, (*gn)[sel_nr1]);
            sprintf(gname, "atom_%s", (*gn)[sel_nr1]);
        }
    }
    else if (strncmp(*string, "ri", 2) == 0)
    {
        (*string) += 2;
        if (check_have_atoms(atoms, ostring) &&
            parse_int_char(string, &sel_nr1, &c))
        {
            bRet = select_residueindices(string, atoms, sel_nr1, c, nr, index, gname);
        }
    }
    else if ((*string)[0] == 'r')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring))
        {
            if (parse_int_char(string, &sel_nr1, &c))
            {
                bRet = select_residuenumbers(string, atoms, sel_nr1, c, nr, index, gname);
            }
            else if (parse_names(string, &n_names, names))
            {
                bRet = select_residuenames(atoms, n_names, names, nr, index);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if (strncmp(*string, "chain", 5) == 0)
    {
        (*string) += 5;
        if (check_have_atoms(atoms, ostring) &&
            parse_names(string, &n_names, names))
        {
            bRet = select_chainnames(atoms, n_names, names, nr, index);
            sprintf(gname, "ch%s", names[0]);
            for (i = 1; i < n_names; i++)
            {
                strcat(gname, names[i]);
            }
        }
    }
    if (bRet && bCompl)
    {
        snew(index1, natoms-*nr);
        nr1 = 0;
        for (i = 0; i < natoms; i++)
        {
            j = 0;
            while ((j < *nr) && (index[j] != i))
            {
                j++;
            }
            if (j == *nr)
            {
                if (nr1 >= natoms-*nr)
                {
                    printf("There are double atoms in your index group\n");
                    break;
                }
                index1[nr1] = i;
                nr1++;
            }
        }
        *nr = nr1;
        for (i = 0; i < nr1; i++)
        {
            index[i] = index1[i];
        }
        sfree(index1);

        for (i = strlen(gname)+1; i > 0; i--)
        {
            gname[i] = gname[i-1];
        }
        gname[0] = '!';
        printf("Complemented group: %d atoms\n", *nr);
    }

    return bRet;
}
예제 #3
0
static int select_residueindices(char **string, t_atoms *atoms,
                                 atom_id n1, char c,
                                 atom_id *nr, atom_id *index, char *gname)
{
    /*this should be similar to select_residuenumbers except select by index (sequential numbering in file)*/
    /*resind+1 for 1-indexing*/
    char       buf[STRLEN];
    int        i, j, up;
    t_resinfo *ri;

    *nr = 0;
    while ((*string)[0] == ' ')
    {
        (*string)++;
    }
    if ((*string)[0] == '-')
    {
        /* Residue number range selection */
        if (c != ' ')
        {
            printf("Error: residue insertion codes can not be used with residue range selection\n");
            return 0;
        }
        (*string)++;
        parse_int(string, &up);

        for (i = 0; i < atoms->nr; i++)
        {
            ri = &atoms->resinfo[atoms->atom[i].resind];
            for (j = n1; (j <= up); j++)
            {
                if (atoms->atom[i].resind+1 == j && (c == ' ' || ri->ic == c))
                {
                    index[*nr] = i;
                    (*nr)++;
                }
            }
        }
        printf("Found %d atom%s with resind.+1 in range %d-%d\n",
               *nr, (*nr == 1) ? "" : "s", n1, up);
        if (n1 == up)
        {
            sprintf(buf, "r_%d", n1);
        }
        else
        {
            sprintf(buf, "r_%d-%d", n1, up);
        }
        strcpy(gname, buf);
    }
    else
    {
        /* Individual residue number/insertion code selection */
        j = n1;
        sprintf(gname, "r");
        do
        {
            for (i = 0; i < atoms->nr; i++)
            {
                ri = &atoms->resinfo[atoms->atom[i].resind];
                if (atoms->atom[i].resind+1 == j && ri->ic == c)
                {
                    index[*nr] = i;
                    (*nr)++;
                }
            }
            sprintf(buf, "_%d", j);
            strcat(gname, buf);
        }
        while (parse_int_char(string, &j, &c));
    }

    return *nr;
}
예제 #4
0
static int select_residuenumbers(char **string, const t_atoms *atoms,
                                 int n1, char c,
                                 int *nr, int *index, char *gname)
{
    char       buf[STRLEN];
    int        i, j, up;
    t_resinfo *ri;

    *nr = 0;
    while ((*string)[0] == ' ')
    {
        (*string)++;
    }
    if ((*string)[0] == '-')
    {
        /* Residue number range selection */
        if (c != ' ')
        {
            printf("Error: residue insertion codes can not be used with residue range selection\n");
            return 0;
        }
        (*string)++;
        parse_int(string, &up);

        for (i = 0; i < atoms->nr; i++)
        {
            ri = &atoms->resinfo[atoms->atom[i].resind];
            for (j = n1; (j <= up); j++)
            {
                if (ri->nr == j && (c == ' ' || ri->ic == c))
                {
                    index[*nr] = i;
                    (*nr)++;
                }
            }
        }
        printf("Found %d atom%s with res.nr. in range %d-%d\n",
               *nr, (*nr == 1) ? "" : "s", n1, up);
        if (n1 == up)
        {
            sprintf(buf, "r_%d", n1);
        }
        else
        {
            sprintf(buf, "r_%d-%d", n1, up);
        }
        std::strcpy(gname, buf);
    }
    else
    {
        /* Individual residue number/insertion code selection */
        j = n1;
        sprintf(gname, "r");
        do
        {
            for (i = 0; i < atoms->nr; i++)
            {
                ri = &atoms->resinfo[atoms->atom[i].resind];
                if (ri->nr == j && ri->ic == c)
                {
                    index[*nr] = i;
                    (*nr)++;
                }
            }
            sprintf(buf, "_%d", j);
            std::strcat(gname, buf);
        }
        while (parse_int_char(string, &j, &c));
    }

    return *nr;
}