Exemplo n.º 1
0
void print_bondeds(FILE *out, int natoms, directive d,
                   int ftype, int fsubtype, t_params plist[])
{
    t_symtab       stab;
    gpp_atomtype_t atype;
    t_param       *param;
    t_atom        *a;
    int            i;

    atype = init_atomtype();
    snew(a, 1);
    snew(param, 1);
    open_symtab(&stab);
    for (i = 0; (i < natoms); i++)
    {
        char buf[12];
        sprintf(buf, "%4d", (i+1));
        add_atomtype(atype, &stab, a, buf, param, 0, 0, 0, 0, 0, 0, 0);
    }
    print_bt(out, d, atype, ftype, fsubtype, plist, TRUE);

    done_symtab(&stab);
    sfree(a);
    sfree(param);
    done_atomtype(atype);
}
Exemplo n.º 2
0
gpp_atomtype_t read_atype(const char *ffdir, t_symtab *tab)
{
    int            nfile, f;
    char         **file;
    FILE          *in;
    char           buf[STRLEN], name[STRLEN];
    double         m;
    int            nratt = 0;
    gpp_atomtype_t at;
    t_atom        *a;
    t_param       *nb;

    nfile = fflib_search_file_end(ffdir, ".atp", TRUE, &file);
    at    = init_atomtype();
    snew(a, 1);
    snew(nb, 1);

    for (f = 0; f < nfile; f++)
    {
        in = fflib_open(file[f]);
        while (!feof(in))
        {
            /* Skip blank or comment-only lines */
            do
            {
                if (fgets2(buf, STRLEN, in) != NULL)
                {
                    strip_comment(buf);
                    trim(buf);
                }
            }
            while (!feof(in) && strlen(buf) == 0);

            if (sscanf(buf, "%s%lf", name, &m) == 2)
            {
                a->m = m;
                add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0, 0.0, 0.0 );
                fprintf(stderr, "\rAtomtype %d", ++nratt);
                fflush(stderr);
            }
            else
            {
                fprintf(stderr, "\nInvalid format: %s\n", buf);
            }
        }
        gmx_ffclose(in);
        sfree(file[f]);
    }
    fprintf(stderr, "\n");
    sfree(file);

    return at;
}
Exemplo n.º 3
0
int nm2type(int nnm, t_nm2type nm2t[], t_symtab *tab, t_atoms *atoms,
            gpp_atomtype_t atype, int *nbonds, t_params *bonds)
{
    int      cur = 0;
#define prev (1-cur)
    int      i, j, k, m, n, nresolved, nb, maxbond, ai, aj, best, im, nqual[2][ematchNR];
    int     *bbb, *n_mask, *m_mask, **match, **quality;
    char    *aname_i, *aname_m, *aname_n, *type;
    double   qq, mm;
    t_param *param;

    snew(param, 1);
    maxbond = 0;
    for (i = 0; (i < atoms->nr); i++)
    {
        maxbond = max(maxbond, nbonds[i]);
    }
    if (debug)
    {
        fprintf(debug, "Max number of bonds per atom is %d\n", maxbond);
    }
    snew(bbb, maxbond);
    snew(n_mask, maxbond);
    snew(m_mask, maxbond);
    snew(match, maxbond);
    for (i = 0; (i < maxbond); i++)
    {
        snew(match[i], maxbond);
    }

    nresolved = 0;
    for (i = 0; (i < atoms->nr); i++)
    {
        aname_i = *atoms->atomname[i];
        nb      = 0;
        for (j = 0; (j < bonds->nr); j++)
        {
            ai = bonds->param[j].AI;
            aj = bonds->param[j].AJ;
            if (ai == i)
            {
                bbb[nb++] = aj;
            }
            else if (aj == i)
            {
                bbb[nb++] = ai;
            }
        }
        if (nb != nbonds[i])
        {
            gmx_fatal(FARGS, "Counting number of bonds nb = %d, nbonds[%d] = %d",
                      nb, i, nbonds[i]);
        }
        if (debug)
        {
            fprintf(debug, "%4s has bonds to", aname_i);
            for (j = 0; (j < nb); j++)
            {
                fprintf(debug, " %4s", *atoms->atomname[bbb[j]]);
            }
            fprintf(debug, "\n");
        }
        best = -1;
        for (k = 0; (k < ematchNR); k++)
        {
            nqual[prev][k] = 0;
        }

        /* First check for names */
        for (k = 0; (k < nnm); k++)
        {
            if (nm2t[k].nbonds == nb)
            {
                im = match_str(*atoms->atomname[i], nm2t[k].elem);
                if (im > ematchWild)
                {
                    for (j = 0; (j < ematchNR); j++)
                    {
                        nqual[cur][j] = 0;
                    }

                    /* Fill a matrix with matching quality */
                    for (m = 0; (m < nb); m++)
                    {
                        aname_m = *atoms->atomname[bbb[m]];
                        for (n = 0; (n < nb); n++)
                        {
                            aname_n     = nm2t[k].bond[n];
                            match[m][n] = match_str(aname_m, aname_n);
                        }
                    }
                    /* Now pick the best matches */
                    for (m = 0; (m < nb); m++)
                    {
                        n_mask[m] = 0;
                        m_mask[m] = 0;
                    }
                    for (j = ematchNR-1; (j > 0); j--)
                    {
                        for (m = 0; (m < nb); m++)
                        {
                            for (n = 0; (n < nb); n++)
                            {
                                if ((n_mask[n] == 0) &&
                                    (m_mask[m] == 0) &&
                                    (match[m][n] == j))
                                {
                                    n_mask[n] = 1;
                                    m_mask[m] = 1;
                                    nqual[cur][j]++;
                                }
                            }
                        }
                    }
                    if ((nqual[cur][ematchExact]+
                         nqual[cur][ematchElem]+
                         nqual[cur][ematchWild]) == nb)
                    {
                        if ((nqual[cur][ematchExact] > nqual[prev][ematchExact]) ||

                            ((nqual[cur][ematchExact] == nqual[prev][ematchExact]) &&
                             (nqual[cur][ematchElem] > nqual[prev][ematchElem])) ||

                            ((nqual[cur][ematchExact] == nqual[prev][ematchExact]) &&
                             (nqual[cur][ematchElem] == nqual[prev][ematchElem]) &&
                             (nqual[cur][ematchWild] > nqual[prev][ematchWild])))
                        {
                            best = k;
                            cur  = prev;
                        }
                    }
                }
            }
        }
        if (best != -1)
        {
            int  atomnr = 0;
            real alpha  = 0;

            qq   = nm2t[best].q;
            mm   = nm2t[best].m;
            type = nm2t[best].type;

            if ((k = get_atomtype_type(type, atype)) == NOTSET)
            {
                atoms->atom[i].qB = alpha;
                atoms->atom[i].m  = atoms->atom[i].mB = mm;
                k                 = add_atomtype(atype, tab, &(atoms->atom[i]), type, param,
                                                 atoms->atom[i].type, 0, 0, 0, atomnr, 0, 0);
            }
            atoms->atom[i].type  = k;
            atoms->atom[i].typeB = k;
            atoms->atom[i].q     = qq;
            atoms->atom[i].qB    = qq;
            atoms->atom[i].m     = mm;
            atoms->atom[i].mB    = mm;
            nresolved++;
        }
        else
        {
            fprintf(stderr, "Can not find forcefield for atom %s-%d with %d bonds\n",
                    *atoms->atomname[i], i+1, nb);
        }
    }
    sfree(bbb);
    sfree(n_mask);
    sfree(m_mask);
    sfree(param);

    return nresolved;
}