Ejemplo n.º 1
0
/*!
 * \param[in,out] d       Trajectory analysis data structure.
 * \param[in]     type    Type of covered fractions to calculate.
 * \returns       0 on success, a non-zero error code on error.
 *
 * By default, covered fractions are not calculated.
 * If this function is called, the covered fraction calculation is
 * initialize to calculate the fractions of type \p type for each selection.
 * The function must be called after gmx_ana_init_selections() has been
 * called.
 *
 * For more fine-grained control of the calculation, you can use
 * gmx_ana_selection_init_coverfrac(): if you initialize some selections
 * this function to something else than CFRAC_NONE before calling
 * gmx_ana_init_coverfrac(), these settings are not overwritten.
 *
 * You only need to call this function if your program needs to have
 * information about the covered fractions, e.g., for normalization.
 *
 * \see gmx_ana_selection_init_coverfrac()
 */
int
gmx_ana_init_coverfrac(gmx_ana_traj_t *d, e_coverfrac_t type)
{
    int                 g;

    if (type == CFRAC_NONE)
    {
        return 0;
    }

    for (g = 0; g < d->ngrps; ++g)
    {
        if (d->sel[g]->cfractype == CFRAC_NONE)
        {
            gmx_ana_selection_init_coverfrac(d->sel[g], type);
        }
    }
    return 0;
}
Ejemplo n.º 2
0
/*!
 * \param[in,out] sc    Selection collection to append to.
 * \param         sel   Selection to append to \p sc (can be NULL, in which
 *   case nothing is done).
 * \param         last  Last selection in \p sc, or NULL if not present or not
 *   known.
 * \returns       The last selection in \p sc after the append.
 *
 * Appends \p sel after the last root element in \p sc, and returns either
 * \p sel (if it was non-NULL) or the last element in \p sc (if \p sel was
 * NULL).
 */
t_selelem *
_gmx_sel_append_selection(gmx_ana_selcollection_t *sc, t_selelem *sel,
                          t_selelem *last)
{
    if (last)
    {
        last->next = sel;
    }
    else
    {
        if (sc->root)
        {
            last = sc->root;
            while (last->next)
            {
                last = last->next;
            }
            last->next = sel;
        }
        else
        {
            sc->root = sel;
        }
    }
    if (sel)
    {
        last = sel;
        /* Add the new selection to the collection if it is not a variable. */
        if (sel->child->type != SEL_SUBEXPR)
        {
            int        i;

            sc->nr++;
            srenew(sc->sel, sc->nr);
            i = sc->nr - 1;
            snew(sc->sel[i], 1);

            if (sel->child->type == SEL_CONST)
            {
                gmx_ana_pos_copy(&sc->sel[i]->p, sel->child->v.u.p, TRUE);
                sc->sel[i]->bDynamic = FALSE;
            }
            else
            {
                t_selelem *child;

                child = sel->child;
                child->flags     &= ~SEL_ALLOCVAL;
                _gmx_selvalue_setstore(&child->v, &sc->sel[i]->p);
                /* We should also skip any modifiers to determine the dynamic
                 * status. */
                while (child->type == SEL_MODIFIER)
                {
                    child = child->child;
                }
                /* For variable references, we should skip the
                 * SEL_SUBEXPRREF and SEL_SUBEXPR elements. */
                if (child->type == SEL_SUBEXPRREF)
                {
                    child = child->child->child;
                }
                sc->sel[i]->bDynamic = (child->child->flags & SEL_DYNAMIC);
            }
            /* The group will be set after compilation */
            sc->sel[i]->g        = NULL;
            sc->sel[i]->selelem  = sel;
            gmx_ana_selection_init_coverfrac(sc->sel[i], CFRAC_NONE);
        }
    }
    return last;
}