Ejemplo n.º 1
0
void
AnalysisDataDisplacementModule::setMSDHistogram(AnalysisDataBinAverageModule *histm)
{
    GMX_RELEASE_ASSERT(!_impl->histm, "Can only set MSD histogram once");
    _impl->histm = histm;
    histm->setIgnoreMissing(true);
    addModule(histm);
}
Ejemplo n.º 2
0
AnalysisDataHandle
TrajectoryAnalysisModuleData::dataHandle(const AnalysisData &data)
{
    Impl::HandleContainer::const_iterator i = impl_->handles_.find(&data);
    GMX_RELEASE_ASSERT(i != impl_->handles_.end(),
                       "Data handle requested on unknown dataset");
    return i->second;
}
Ejemplo n.º 3
0
void TopologyManager::initUniformMolecules(int moleculeSize)
{
    GMX_RELEASE_ASSERT(mtop_ != nullptr, "Topology not initialized");
    GMX_RELEASE_ASSERT(mtop_->molblock.size() == 1, "initUniformMolecules only implemented for a single molblock");
    gmx_molblock_t &molblock = mtop_->molblock[0];
    t_atoms        &atoms    = mtop_->moltype[molblock.type].atoms;
    GMX_RELEASE_ASSERT(atoms.nr % moleculeSize == 0,
                       "The number of atoms should be a multiple of moleculeSize");
    molblock.nmol  = atoms.nr/moleculeSize;
    atoms.nr       = moleculeSize;
    const int nres = atoms.atom[atoms.nr].resind;
    GMX_RELEASE_ASSERT(atoms.atom[atoms.nr-1].resind != nres,
                       "The residues should break at molecule boundaries");
    atoms.nres                 = nres;
    mtop_->haveMoleculeIndices = true;
    gmx_mtop_finalize(mtop_.get());
}
Ejemplo n.º 4
0
void
AnalysisDataDisplacementModule::setMSDHistogram(
        AnalysisDataBinAverageModulePointer histm)
{
    GMX_RELEASE_ASSERT(_impl->histm == NULL, "Can only set MSD histogram once");
    _impl->histm = histm.get();
    addModule(histm);
}
Ejemplo n.º 5
0
void OptionsAssigner::finishSection()
{
    // Should only be called if we are in a subsection.
    GMX_RELEASE_ASSERT(impl_->inSection(), "startSection() not called");
    Impl::Section *section = impl_->sectionStack_.back();
    section->finish();
    impl_->sectionStack_.pop_back();
}
Ejemplo n.º 6
0
void
AbstractAnalysisArrayData::setColumnCount(int ncols)
{
    GMX_RELEASE_ASSERT(!isAllocated(),
                       "Cannot change column count after data has been allocated");
    AbstractAnalysisData::setColumnCount(0, ncols);
    pointSetInfo_ = AnalysisDataPointSetInfo(0, ncols, 0, 0);
}
Ejemplo n.º 7
0
/*! \brief Replace duplicated spaces with a single one in string
 *
 * Only the first character will be kept for multiple adjacent characters that
 * are both identical and where the first one returns true for isspace().
 *
 * \param str String that will be modified.
 */
static void
removeExtraSpaces(std::string *str)
{
    GMX_RELEASE_ASSERT(str != nullptr, "A pointer to an actual string must be provided");
    std::string::iterator newEnd =
        std::unique( str->begin(), str->end(), [ = ](char a, char b){ return isspace(a) != 0 && (a == b); } );
    str->erase(newEnd, str->end());
}
void
AnalysisDataModuleManager::applyModule(AbstractAnalysisData        *data,
                                       AnalysisDataModuleInterface *module)
{
    impl_->checkModuleProperties(*module);
    GMX_RELEASE_ASSERT(impl_->state_ == Impl::eFinished,
                       "Data module can only be applied to ready data");
    impl_->presentData(data, module);
}
Ejemplo n.º 9
0
void
gmx_omp_nthreads_set(int mod, int nthreads)
{
    /* Catch an attempt to set the number of threads on an invalid
     * OpenMP module. */
    GMX_RELEASE_ASSERT(mod >= 0 && mod < emntNR, "Trying to set nthreads on invalid OpenMP module");

    modth.nth[mod] = nthreads;
}
Ejemplo n.º 10
0
void AbstractOptionStorage::finish()
{
    GMX_RELEASE_ASSERT(!bInSet_, "finishSet() not called");
    processAll();
    if (isRequired() && !(isSet() || hasFlag(efOption_ExplicitDefaultValue)))
    {
        GMX_THROW(InvalidInputError("Option is required, but not set"));
    }
}
Ejemplo n.º 11
0
void
_gmx_sel_mempool_reserve(gmx_sel_mempool_t *mp, size_t size)
{
    GMX_RELEASE_ASSERT(mp->nblocks == 0,
                       "Cannot reserve memory pool when there is something allocated");
    GMX_RELEASE_ASSERT(!mp->buffer, "Cannot reserve memory pool twice");
    if (size == 0)
    {
        size = mp->maxsize;
    }
    mp->buffer = (char *)malloc(size);
    if (!mp->buffer)
    {
        throw std::bad_alloc();
    }
    mp->freesize = size;
    mp->freeptr  = mp->buffer;
}
Ejemplo n.º 12
0
void dd_collect_state(gmx_domdec_t *dd,
                      const t_state *state_local, t_state *state)
{
    int nh = state_local->nhchainlength;

    if (DDMASTER(dd))
    {
        GMX_RELEASE_ASSERT(state->nhchainlength == nh, "The global and local Nose-Hoover chain lengths should match");

        for (int i = 0; i < efptNR; i++)
        {
            state->lambda[i] = state_local->lambda[i];
        }
        state->fep_state = state_local->fep_state;
        state->veta      = state_local->veta;
        state->vol0      = state_local->vol0;
        copy_mat(state_local->box, state->box);
        copy_mat(state_local->boxv, state->boxv);
        copy_mat(state_local->svir_prev, state->svir_prev);
        copy_mat(state_local->fvir_prev, state->fvir_prev);
        copy_mat(state_local->pres_prev, state->pres_prev);

        for (int i = 0; i < state_local->ngtc; i++)
        {
            for (int j = 0; j < nh; j++)
            {
                state->nosehoover_xi[i*nh+j]        = state_local->nosehoover_xi[i*nh+j];
                state->nosehoover_vxi[i*nh+j]       = state_local->nosehoover_vxi[i*nh+j];
            }
            state->therm_integral[i] = state_local->therm_integral[i];
        }
        for (int i = 0; i < state_local->nnhpres; i++)
        {
            for (int j = 0; j < nh; j++)
            {
                state->nhpres_xi[i*nh+j]        = state_local->nhpres_xi[i*nh+j];
                state->nhpres_vxi[i*nh+j]       = state_local->nhpres_vxi[i*nh+j];
            }
        }
        state->baros_integral = state_local->baros_integral;
    }
    if (state_local->flags & (1 << estX))
    {
        gmx::ArrayRef<gmx::RVec> globalXRef = state ? makeArrayRef(state->x) : gmx::EmptyArrayRef();
        dd_collect_vec(dd, state_local, makeConstArrayRef(state_local->x), globalXRef);
    }
    if (state_local->flags & (1 << estV))
    {
        gmx::ArrayRef<gmx::RVec> globalVRef = state ? makeArrayRef(state->v) : gmx::EmptyArrayRef();
        dd_collect_vec(dd, state_local, makeConstArrayRef(state_local->v), globalVRef);
    }
    if (state_local->flags & (1 << estCGP))
    {
        gmx::ArrayRef<gmx::RVec> globalCgpRef = state ? makeArrayRef(state->cg_p) : gmx::EmptyArrayRef();
        dd_collect_vec(dd, state_local, makeConstArrayRef(state_local->cg_p), globalCgpRef);
    }
}
Ejemplo n.º 13
0
void TopologyManager::requestFrame()
{
    GMX_RELEASE_ASSERT(mtop_ == nullptr,
                       "Frame must be requested before initializing topology");
    if (frame_ == nullptr)
    {
        snew(frame_, 1);
    }
}
Ejemplo n.º 14
0
void OptionsAssigner::appendValue(const std::string &value)
{
    AbstractOptionStorage *option = _impl->_currentOption;
    GMX_RELEASE_ASSERT(option != NULL, "startOption() not called");
    // Does not count correctly, but the actual count is not really used.
    // TODO: Rename the variable to better reflect the usage.
    ++_impl->_currentValueCount;
    option->appendValue(value);
}
Ejemplo n.º 15
0
/*! \internal
 * This method is not const because the dataStarted() methods of the attached
 * modules can request storage of the data.
 */
void
AbstractAnalysisData::notifyDataStart()
{
    GMX_RELEASE_ASSERT(!impl_->bDataStart_,
                       "notifyDataStart() called more than once");
    GMX_RELEASE_ASSERT(columnCount_ > 0, "Data column count is not set");
    impl_->bDataStart_ = impl_->bInData_ = true;

    Impl::ModuleList::const_iterator i;
    for (i = impl_->modules_.begin(); i != impl_->modules_.end(); ++i)
    {
        if (columnCount_ > 1 && !((*i)->flags() & AnalysisDataModuleInterface::efAllowMulticolumn))
        {
            GMX_THROW(APIError("Data module not compatible with data object properties"));
        }
        (*i)->dataStarted(this);
    }
}
Ejemplo n.º 16
0
void UpdateGroupsCog::addCogs(gmx::ArrayRef<const int>        globalAtomIndices,
                              gmx::ArrayRef<const gmx::RVec>  coordinates)
{
    const int    localAtomBegin = cogIndices_.size();
    const size_t cogBegin       = cogs_.size();

    GMX_RELEASE_ASSERT(globalAtomIndices.size() >= localAtomBegin,
                       "addCogs should only be called to add COGs to the list that is already present (which could be empty)");

    cogIndices_.reserve(globalAtomIndices.size());

    int moleculeBlock = 0;
    for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.size(); localAtom++)
    {
        const int   globalAtom = globalAtomIndices[localAtom];
        int         moleculeIndex;
        int         atomIndexInMolecule;
        mtopGetMolblockIndex(&mtop_, globalAtom,
                             &moleculeBlock, &moleculeIndex, &atomIndexInMolecule);
        const auto &indicesForBlock        = indicesPerMoleculeblock_[moleculeBlock];
        int         globalUpdateGroupIndex =
            indicesForBlock.groupStart_ +
            moleculeIndex*indicesForBlock.numGroupsPerMolecule_ +
            indicesForBlock.groupIndex_[atomIndexInMolecule];

        if (const int *cogIndexPtr = globalToLocalMap_.find(globalUpdateGroupIndex))
        {
            GMX_ASSERT(static_cast<size_t>(*cogIndexPtr) >= cogBegin,
                       "Added atoms should not be part of previously present groups");

            cogIndices_.push_back(*cogIndexPtr);

            cogs_[*cogIndexPtr] += coordinates[localAtom];
            numAtomsPerCog_[*cogIndexPtr]++;
        }
        else
        {
            const int cogIndex = cogs_.size();

            globalToLocalMap_.insert(globalUpdateGroupIndex, cogIndex);
            cogIndices_.push_back(cogIndex);
            cogs_.push_back(coordinates[localAtom]);
            numAtomsPerCog_.push_back(1);
        }
    }

    /* Divide sum of coordinates for each COG by the number of atoms */
    for (size_t i = cogBegin; i < cogs_.size(); i++)
    {
        const int numAtoms = numAtomsPerCog_[i];
        if (numAtoms > 1)
        {
            cogs_[i] /= numAtoms;
        }
    }
}
Ejemplo n.º 17
0
void
AbstractAnalysisArrayData::setRowCount(int rowCount)
{
    GMX_RELEASE_ASSERT(rowCount > 0, "Invalid number of rows");
    GMX_RELEASE_ASSERT(!isAllocated(),
                       "Cannot change row count after data has been allocated");
    GMX_RELEASE_ASSERT(bUniformX_ || xvalue_.empty()
                       || rowCount == static_cast<int>(xvalue_.size()),
                       "X axis set with setXAxisValue() does not match the row count");
    xvalue_.resize(rowCount);
    if (bUniformX_ && rowCount > rowCount_)
    {
        for (int i = rowCount_; i < rowCount; ++i)
        {
            xvalue_[i] = xvalue_[0] + i * xstep_;
        }
    }
    rowCount_ = rowCount;
}
Ejemplo n.º 18
0
void
SelectionCollection::setOutputPosType(const char *type)
{
    GMX_RELEASE_ASSERT(type != NULL, "Cannot assign NULL position type");
    // Check that the type is valid, throw if it is not.
    e_poscalc_t  dummytype;
    int          dummyflags;
    PositionCalculationCollection::typeFromEnum(type, &dummytype, &dummyflags);
    impl_->spost_ = type;
}
Ejemplo n.º 19
0
bool File::isInteractive() const
{
    GMX_RELEASE_ASSERT(impl_->fp_ != NULL,
                       "Attempted to access a file object that is not open");
#ifdef HAVE_UNISTD_H
    return isatty(fileno(impl_->fp_));
#else
    return true;
#endif
}
Ejemplo n.º 20
0
void TopologyManager::requestVelocities()
{
    GMX_RELEASE_ASSERT(frame_ != nullptr,
                       "Velocities requested before requesting a frame");
    frame_->bV = TRUE;
    if (frame_->natoms > 0)
    {
        snew(frame_->v, frame_->natoms);
    }
}
Ejemplo n.º 21
0
void TimeUnitBehavior::setTimeUnit(TimeUnit timeUnit)
{
    GMX_RELEASE_ASSERT(timeUnit >= 0 && timeUnit <= TimeUnit_s,
                       "Invalid time unit");
    timeUnit_ = timeUnit;
    if (timeUnitStore_ != NULL)
    {
        *timeUnitStore_ = timeUnit;
    }
}
Ejemplo n.º 22
0
void
SelectionCollection::setOutputPosType(const char *type)
{
    GMX_RELEASE_ASSERT(type != NULL, "Cannot assign NULL position type");
    //! Check that the type is valid.
    e_poscalc_t  dummytype;
    int          dummyflags;
    gmx_ana_poscalc_type_from_enum(type, &dummytype, &dummyflags);
    _impl->_spost = type;
}
Ejemplo n.º 23
0
void TopologyManager::requestForces()
{
    GMX_RELEASE_ASSERT(frame_ != nullptr,
                       "Forces requested before requesting a frame");
    frame_->bF = TRUE;
    if (frame_->natoms > 0)
    {
        snew(frame_->f, frame_->natoms);
    }
}
Ejemplo n.º 24
0
HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format,
                                     const HelpLinks *links)
    : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, links))))
{
    if (links != NULL)
    {
        GMX_RELEASE_ASSERT(links->impl_->format_ == format,
                           "Links must have the same output format as the context");
    }
}
Ejemplo n.º 25
0
bool
AbstractAnalysisData::requestStorage(int nframes)
{
    GMX_RELEASE_ASSERT(nframes >= -1, "Invalid number of frames requested");
    if (nframes == 0)
    {
        return true;
    }
    return requestStorageInternal(nframes);
}
Ejemplo n.º 26
0
CommandLineModuleManager::Impl::Impl(const char                *binaryName,
                                     CommandLineProgramContext *programContext)
    : programContext_(*programContext),
      binaryName_(binaryName != NULL ? binaryName : ""),
      helpModule_(NULL), singleModule_(NULL),
      bQuiet_(false)
{
    GMX_RELEASE_ASSERT(binaryName_.find('-') == std::string::npos,
                       "Help export does not currently work with binary names with dashes");
}
void MessageStringCollector::finishContext()
{
    GMX_RELEASE_ASSERT(!impl_->contexts_.empty(),
                       "finishContext() called without context");
    impl_->contexts_.pop_back();
    if (impl_->prevContext_ > impl_->contexts_.size())
    {
        impl_->prevContext_ = impl_->contexts_.size();
    }
}
Ejemplo n.º 28
0
/*!
 * \param[in,out] pos   Position data structure.
 *
 * Currently, this function can only be called after gmx_ana_pos_reserve()
 * has been called at least once with a \p n >= 0.
 */
void
gmx_ana_pos_reserve_forces(gmx_ana_pos_t *pos)
{
    GMX_RELEASE_ASSERT(pos->nalloc_x > 0,
                       "No memory reserved yet for positions");
    if (!pos->f)
    {
        snew(pos->f, pos->nalloc_x);
    }
}
void
AnalysisDataProxy::dataStarted(AbstractAnalysisData *data)
{
    GMX_RELEASE_ASSERT(data == &source_, "Source data mismatch");
    setDataSetCount(data->dataSetCount());
    for (int i = 0; i < data->dataSetCount(); ++i)
    {
        setColumnCount(i, columnSpan_);
    }
    moduleManager().notifyDataStart(this);
}
Ejemplo n.º 30
0
static void copy_state_serial(const t_state *src, t_state *dest)
{
    if (dest != src)
    {
        /* Currently the local state is always a pointer to the global
         * in serial, so we should never end up here.
         * TODO: Implement a (trivial) t_state copy once converted to C++.
         */
        GMX_RELEASE_ASSERT(false, "State copying is currently not implemented in replica exchange");
    }
}