Example #1
0
void
SelectionCollection::setTopology(t_topology *top, int natoms)
{
    GMX_RELEASE_ASSERT(natoms > 0 || top != NULL,
                       "The number of atoms must be given if there is no topology");
    // Get the number of atoms from the topology if it is not given.
    if (natoms <= 0)
    {
        natoms = top->atoms.nr;
    }
    if (impl_->bExternalGroupsSet_)
    {
        ExceptionInitializer        errors("Invalid index group references encountered");
        SelectionTreeElementPointer root = impl_->sc_.root;
        while (root)
        {
            checkExternalGroups(root, natoms, &errors);
            root = root->next;
        }
        if (errors.hasNestedExceptions())
        {
            GMX_THROW(InconsistentInputError(errors));
        }
    }
    gmx_ana_selcollection_t *sc = &impl_->sc_;
    // Do this first, as it allocates memory, while the others don't throw.
    gmx_ana_index_init_simple(&sc->gall, natoms);
    sc->pcc.setTopology(top);
    sc->top = top;
}
void
SelectionCollection::setTopology(t_topology *top, int natoms)
{
    gmx_ana_selcollection_t *sc = &_impl->_sc;
    gmx_ana_poscalc_coll_set_topology(sc->pcc, top);
    sc->top = top;

    /* Get the number of atoms from the topology if it is not given */
    if (natoms <= 0)
    {
        if (sc->top == NULL)
        {
            GMX_THROW(APIError("Selections need either the topology or the number of atoms"));
        }
        natoms = sc->top->atoms.nr;
    }

    gmx_ana_index_init_simple(&sc->gall, natoms, NULL);
}
Example #3
0
/*!
 * \param[in,out] sc        Selection collection to set the topology for.
 * \param[in]     top       Topology data.
 * \param[in]     natoms    Number of atoms. If <=0, the number of atoms in the
 *   topology is used.
 * \returns       0 on success, EINVAL if \p top is NULL and \p natoms <= 0.
 *
 * The topology is also set for the position calculation collection
 * associated with \p sc.
 *
 * \p natoms determines the largest atom index that can be selected by the
 * selection: even if the topology contains more atoms, they will not be
 * selected.
 */
int
gmx_ana_selcollection_set_topology(gmx_ana_selcollection_t *sc, t_topology *top,
                                   int natoms)
{
    gmx_ana_poscalc_coll_set_topology(sc->pcc, top);
    sc->top = top;

    /* Get the number of atoms from the topology if it is not given */
    if (natoms <= 0)
    {
        if (!sc->top)
        {
            gmx_incons("selections need either the topology or the number of atoms");
            return EINVAL;
        }
        natoms = sc->top->atoms.nr;
    }
    gmx_ana_index_init_simple(&sc->gall, natoms, NULL);
    return 0;
}