From be6f9095461de16c09a14805c28512a1025af127 Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Wed, 10 Mar 2021 10:39:18 +0100 Subject: [PATCH] Change vector references to Arrayref in AWH Preparation for further refactoring. --- src/gromacs/applied_forces/awh/bias.cpp | 8 +- src/gromacs/applied_forces/awh/bias.h | 6 +- src/gromacs/applied_forces/awh/biasgrid.cpp | 8 +- src/gromacs/applied_forces/awh/biasgrid.h | 8 +- src/gromacs/applied_forces/awh/biasparams.cpp | 32 ++-- src/gromacs/applied_forces/awh/biasparams.h | 20 ++- .../applied_forces/awh/biassharing.cpp | 8 +- src/gromacs/applied_forces/awh/biassharing.h | 10 +- src/gromacs/applied_forces/awh/biasstate.cpp | 154 +++++++++--------- src/gromacs/applied_forces/awh/biasstate.h | 114 ++++++------- src/gromacs/applied_forces/awh/coordstate.cpp | 8 +- src/gromacs/applied_forces/awh/coordstate.h | 6 +- .../applied_forces/awh/histogramsize.cpp | 14 +- .../applied_forces/awh/histogramsize.h | 14 +- 14 files changed, 207 insertions(+), 203 deletions(-) diff --git a/src/gromacs/applied_forces/awh/bias.cpp b/src/gromacs/applied_forces/awh/bias.cpp index 4021fc08d0..4d1ae3ce84 100644 --- a/src/gromacs/applied_forces/awh/bias.cpp +++ b/src/gromacs/applied_forces/awh/bias.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -253,7 +253,7 @@ gmx::ArrayRef Bias::calcForceAndUpdateBias(const awh_dvec * \param[in] pointState The state of the points in a bias. * \returns the total sample count. */ -static int64_t countSamples(const std::vector& pointState) +static int64_t countSamples(ArrayRef pointState) { double numSamples = 0; for (const PointState& point : pointState) @@ -362,14 +362,14 @@ void Bias::updateHistory(AwhBiasHistory* biasHistory) const Bias::Bias(int biasIndexInCollection, const AwhParams& awhParams, const AwhBiasParams& awhBiasParams, - const std::vector& dimParamsInit, + ArrayRef dimParamsInit, double beta, double mdTimeStep, int numSharingSimulations, const std::string& biasInitFilename, ThisRankWillDoIO thisRankWillDoIO, BiasParams::DisableUpdateSkips disableUpdateSkips) : - dimParams_(dimParamsInit), + dimParams_(dimParamsInit.begin(), dimParamsInit.end()), grid_(dimParamsInit, awhBiasParams.dimParams), params_(awhParams, awhBiasParams, diff --git a/src/gromacs/applied_forces/awh/bias.h b/src/gromacs/applied_forces/awh/bias.h index 5fd4ad5c82..f3386facf3 100644 --- a/src/gromacs/applied_forces/awh/bias.h +++ b/src/gromacs/applied_forces/awh/bias.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -166,7 +166,7 @@ public: Bias(int biasIndexInCollection, const AwhParams& awhParams, const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, + ArrayRef dimParams, double beta, double mdTimeStep, int numSharingSimulations, @@ -279,7 +279,7 @@ public: /*! \brief Returns the dimension parameters. */ - inline const std::vector& dimParams() const { return dimParams_; } + inline ArrayRef dimParams() const { return dimParams_; } //! Returns the bias parameters inline const BiasParams& params() const { return params_; } diff --git a/src/gromacs/applied_forces/awh/biasgrid.cpp b/src/gromacs/applied_forces/awh/biasgrid.cpp index af639fbf6f..1f4ce66d5f 100644 --- a/src/gromacs/applied_forces/awh/biasgrid.cpp +++ b/src/gromacs/applied_forces/awh/biasgrid.cpp @@ -309,7 +309,7 @@ namespace * \param[in] indexMulti Multidimensional grid point index to convert to a linear one. * \returns the linear index. */ -int multiDimGridIndexToLinear(const std::vector& axis, const awh_ivec indexMulti) +int multiDimGridIndexToLinear(ArrayRef axis, const awh_ivec indexMulti) { awh_ivec numPointsDim = { 0 }; @@ -557,7 +557,7 @@ static int pointDistanceAlongAxis(const GridAxis& axis, double x, double x0) * \param[in] axis The grid axes. * \returns true if the value is in the grid. */ -static bool valueIsInGrid(const awh_dvec value, const std::vector& axis) +static bool valueIsInGrid(const awh_dvec value, ArrayRef axis) { /* For each dimension get the one-dimensional index and check if it is in range. */ for (size_t d = 0; d < axis.size(); d++) @@ -634,7 +634,7 @@ int GridAxis::nearestIndex(double value) const * \param[in] axis The grid axes. * \returns the point index nearest to the value. */ -static int getNearestIndexInGrid(const awh_dvec value, const std::vector& axis) +static int getNearestIndexInGrid(const awh_dvec value, ArrayRef axis) { awh_ivec indexMulti; @@ -811,7 +811,7 @@ GridAxis::GridAxis(double origin, double end, double period, int numPoints, bool } } -BiasGrid::BiasGrid(const std::vector& dimParams, const AwhDimParams* awhDimParams) +BiasGrid::BiasGrid(ArrayRef dimParams, const AwhDimParams* awhDimParams) { /* Define the discretization along each dimension */ awh_dvec period; diff --git a/src/gromacs/applied_forces/awh/biasgrid.h b/src/gromacs/applied_forces/awh/biasgrid.h index 8ca2c263a5..0a4bbc3034 100644 --- a/src/gromacs/applied_forces/awh/biasgrid.h +++ b/src/gromacs/applied_forces/awh/biasgrid.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -58,6 +58,8 @@ #include #include +#include "gromacs/utility/arrayref.h" + #include "dimparams.h" /* This is needed for awh_dvec */ namespace gmx @@ -197,7 +199,7 @@ public: * coordinate living on the grid (determines the grid spacing). * \param[in] awhDimParams Dimension params from inputrec. */ - BiasGrid(const std::vector& dimParams, const AwhDimParams* awhDimParams); + BiasGrid(ArrayRef dimParams, const AwhDimParams* awhDimParams); /*! \brief Returns the number of points in the grid. * @@ -221,7 +223,7 @@ public: * * \returns a constant reference to the grid axes. */ - const std::vector& axis() const { return axis_; } + ArrayRef axis() const { return axis_; } /*! \brief Returns a grid axis. * diff --git a/src/gromacs/applied_forces/awh/biasparams.cpp b/src/gromacs/applied_forces/awh/biasparams.cpp index 1e66ba164b..9524c7047b 100644 --- a/src/gromacs/applied_forces/awh/biasparams.cpp +++ b/src/gromacs/applied_forces/awh/biasparams.cpp @@ -115,9 +115,9 @@ int64_t calcTargetUpdateInterval(const AwhParams& awhParams, const AwhBiasParams * \param[in] gridAxis The BiasGrid axes. * \returns the check interval in steps. */ -int64_t calcCheckCoveringInterval(const AwhParams& awhParams, - const std::vector& dimParams, - const std::vector& gridAxis) +int64_t calcCheckCoveringInterval(const AwhParams& awhParams, + ArrayRef dimParams, + ArrayRef gridAxis) { /* Each sample will have a width of sigma. To cover the axis a minimum number of samples of width sigma is required. */ @@ -174,10 +174,10 @@ int64_t calcCheckCoveringInterval(const AwhParams& awhParams, * \param[in] samplingTimestep Sampling frequency of probability weights. * \returns estimate of initial histogram size. */ -double getInitialHistogramSizeEstimate(const AwhBiasParams& awhBiasParams, - const std::vector& gridAxis, - double beta, - double samplingTimestep) +double getInitialHistogramSizeEstimate(const AwhBiasParams& awhBiasParams, + ArrayRef gridAxis, + double beta, + double samplingTimestep) { /* Get diffusion factor */ double maxCrossingTime = 0.; @@ -221,15 +221,15 @@ int getNumSharedUpdate(const AwhBiasParams& awhBiasParams, int numSharingSimulat } // namespace -BiasParams::BiasParams(const AwhParams& awhParams, - const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - double beta, - double mdTimeStep, - DisableUpdateSkips disableUpdateSkips, - int numSharingSimulations, - const std::vector& gridAxis, - int biasIndex) : +BiasParams::BiasParams(const AwhParams& awhParams, + const AwhBiasParams& awhBiasParams, + ArrayRef dimParams, + double beta, + double mdTimeStep, + DisableUpdateSkips disableUpdateSkips, + int numSharingSimulations, + ArrayRef gridAxis, + int biasIndex) : invBeta(beta > 0 ? 1 / beta : 0), numStepsSampleCoord_(awhParams.nstSampleCoord), numSamplesUpdateFreeEnergy_(awhParams.numSamplesUpdateFreeEnergy), diff --git a/src/gromacs/applied_forces/awh/biasparams.h b/src/gromacs/applied_forces/awh/biasparams.h index 9fed42fa07..b416d98556 100644 --- a/src/gromacs/applied_forces/awh/biasparams.h +++ b/src/gromacs/applied_forces/awh/biasparams.h @@ -60,6 +60,8 @@ namespace gmx { +template +class ArrayRef; struct AwhBiasParams; struct AwhParams; struct DimParams; @@ -189,15 +191,15 @@ public: * \param[in] disableUpdateSkips If to disable update skips, useful for testing. * \param[in] biasIndex Index of the bias. */ - BiasParams(const AwhParams& awhParams, - const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - double beta, - double mdTimeStep, - DisableUpdateSkips disableUpdateSkips, - int numSharingSimulations, - const std::vector& gridAxis, - int biasIndex); + BiasParams(const AwhParams& awhParams, + const AwhBiasParams& awhBiasParams, + ArrayRef dimParams, + double beta, + double mdTimeStep, + DisableUpdateSkips disableUpdateSkips, + int numSharingSimulations, + ArrayRef gridAxis, + int biasIndex); /* Data members */ const double invBeta; /**< 1/beta = kT in kJ/mol */ diff --git a/src/gromacs/applied_forces/awh/biassharing.cpp b/src/gromacs/applied_forces/awh/biassharing.cpp index b377931fa0..73bc4a6e8d 100644 --- a/src/gromacs/applied_forces/awh/biassharing.cpp +++ b/src/gromacs/applied_forces/awh/biassharing.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -79,9 +79,9 @@ bool haveBiasSharingWithinSimulation(const AwhParams& awhParams) return haveSharing; } -void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams& awhParams, - const std::vector& pointSize, - const gmx_multisim_t* multiSimComm) +void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams& awhParams, + ArrayRef pointSize, + const gmx_multisim_t* multiSimComm) { const int numSim = multiSimComm->numSimulations_; diff --git a/src/gromacs/applied_forces/awh/biassharing.h b/src/gromacs/applied_forces/awh/biassharing.h index 751fe2f9a5..0b79170937 100644 --- a/src/gromacs/applied_forces/awh/biassharing.h +++ b/src/gromacs/applied_forces/awh/biassharing.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2017,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -56,6 +56,8 @@ struct gmx_multisim_t; namespace gmx { +template +class ArrayRef; struct AwhParams; /*! \brief Returns if any bias is sharing within a simulation. @@ -75,9 +77,9 @@ bool haveBiasSharingWithinSimulation(const AwhParams& awhParams); * \param[in] pointSize Vector of grid-point sizes for each bias. * \param[in] multiSimComm Struct for multi-simulation communication. */ -void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams& awhParams, - const std::vector& pointSize, - const gmx_multisim_t* multiSimComm); +void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams& awhParams, + ArrayRef pointSize, + const gmx_multisim_t* multiSimComm); } // namespace gmx diff --git a/src/gromacs/applied_forces/awh/biasstate.cpp b/src/gromacs/applied_forces/awh/biasstate.cpp index 783cfab1f8..d7c35b2351 100644 --- a/src/gromacs/applied_forces/awh/biasstate.cpp +++ b/src/gromacs/applied_forces/awh/biasstate.cpp @@ -220,14 +220,14 @@ double freeEnergyMinimumValue(gmx::ArrayRef pointState) * \param[in] gridpointIndex The index of the current grid point. * \returns the log of the biased probability weight. */ -double biasedLogWeightFromPoint(const std::vector& dimParams, - const std::vector& points, - const BiasGrid& grid, - int pointIndex, - double pointBias, - const awh_dvec value, - gmx::ArrayRef neighborLambdaEnergies, - int gridpointIndex) +double biasedLogWeightFromPoint(ArrayRef dimParams, + ArrayRef points, + const BiasGrid& grid, + int pointIndex, + double pointBias, + const awh_dvec value, + ArrayRef neighborLambdaEnergies, + int gridpointIndex) { double logWeight = detail::c_largeNegativeExponent; @@ -275,9 +275,9 @@ double biasedLogWeightFromPoint(const std::vector& dimParams, * \returns The calculated marginal distribution in a 1D array with * as many elements as there are points along the axis of interest. */ -std::vector calculateFELambdaMarginalDistribution(const BiasGrid& grid, - gmx::ArrayRef neighbors, - gmx::ArrayRef probWeightNeighbor) +std::vector calculateFELambdaMarginalDistribution(const BiasGrid& grid, + ArrayRef neighbors, + ArrayRef probWeightNeighbor) { const std::optional lambdaAxisIndex = grid.lambdaAxisIndex(); GMX_RELEASE_ASSERT(lambdaAxisIndex, @@ -297,9 +297,9 @@ std::vector calculateFELambdaMarginalDistribution(const BiasGrid& } // namespace -void BiasState::calcConvolvedPmf(const std::vector& dimParams, - const BiasGrid& grid, - std::vector* convolvedPmf) const +void BiasState::calcConvolvedPmf(ArrayRef dimParams, + const BiasGrid& grid, + std::vector* convolvedPmf) const { size_t numPoints = grid.numPoints(); @@ -348,7 +348,7 @@ namespace * \param[in,out] pointState The state of all points. * \param[in] params The bias parameters. */ -void updateTargetDistribution(gmx::ArrayRef pointState, const BiasParams& params) +void updateTargetDistribution(ArrayRef pointState, const BiasParams& params) { double freeEnergyCutoff = 0; if (params.eTarget == AwhTargetType::Cutoff) @@ -475,11 +475,11 @@ int BiasState::warnForHistogramAnomalies(const BiasGrid& grid, int biasIndex, do return numWarnings; } -double BiasState::calcUmbrellaForceAndPotential(const std::vector& dimParams, - const BiasGrid& grid, - int point, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef force) const +double BiasState::calcUmbrellaForceAndPotential(ArrayRef dimParams, + const BiasGrid& grid, + int point, + ArrayRef neighborLambdaDhdl, + ArrayRef force) const { double potential = 0; for (size_t d = 0; d < dimParams.size(); d++) @@ -508,12 +508,12 @@ double BiasState::calcUmbrellaForceAndPotential(const std::vector& di return potential; } -void BiasState::calcConvolvedForce(const std::vector& dimParams, - const BiasGrid& grid, - gmx::ArrayRef probWeightNeighbor, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef forceWorkBuffer, - gmx::ArrayRef force) const +void BiasState::calcConvolvedForce(ArrayRef dimParams, + const BiasGrid& grid, + ArrayRef probWeightNeighbor, + ArrayRef neighborLambdaDhdl, + ArrayRef forceWorkBuffer, + ArrayRef force) const { for (size_t d = 0; d < dimParams.size(); d++) { @@ -539,15 +539,15 @@ void BiasState::calcConvolvedForce(const std::vector& dimParams, } } -double BiasState::moveUmbrella(const std::vector& dimParams, - const BiasGrid& grid, - gmx::ArrayRef probWeightNeighbor, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef biasForce, - int64_t step, - int64_t seed, - int indexSeed, - bool onlySampleUmbrellaGridpoint) +double BiasState::moveUmbrella(ArrayRef dimParams, + const BiasGrid& grid, + ArrayRef probWeightNeighbor, + ArrayRef neighborLambdaDhdl, + ArrayRef biasForce, + int64_t step, + int64_t seed, + int indexSeed, + bool onlySampleUmbrellaGridpoint) { /* Generate and set a new coordinate reference value */ coordState_.sampleUmbrellaGridpoint( @@ -737,11 +737,11 @@ void mergeSharedUpdateLists(std::vector* updateList, * last update. \param[in] endUpdatelist The end of the rectangular that has been sampled since * last update. \param[in,out] updateList Local update list to set (assumed >= npoints long). */ -void makeLocalUpdateList(const BiasGrid& grid, - const std::vector& points, - const awh_ivec originUpdatelist, - const awh_ivec endUpdatelist, - std::vector* updateList) +void makeLocalUpdateList(const BiasGrid& grid, + ArrayRef points, + const awh_ivec originUpdatelist, + const awh_ivec endUpdatelist, + std::vector* updateList) { awh_ivec origin; awh_ivec numPoints; @@ -961,11 +961,11 @@ void labelCoveredPoints(const std::vector& visited, } // namespace -bool BiasState::isSamplingRegionCovered(const BiasParams& params, - const std::vector& dimParams, - const BiasGrid& grid, - const t_commrec* commRecord, - const gmx_multisim_t* multiSimComm) const +bool BiasState::isSamplingRegionCovered(const BiasParams& params, + ArrayRef dimParams, + const BiasGrid& grid, + const t_commrec* commRecord, + const gmx_multisim_t* multiSimComm) const { /* Allocate and initialize arrays: one for checking visits along each dimension, one for keeping track of which points to check and one for the covered points. @@ -1106,15 +1106,15 @@ static void normalizeFreeEnergyAndPmfSum(std::vector* pointState) } } -void BiasState::updateFreeEnergyAndAddSamplesToHistogram(const std::vector& dimParams, - const BiasGrid& grid, - const BiasParams& params, - const t_commrec* commRecord, - const gmx_multisim_t* multiSimComm, - double t, - int64_t step, - FILE* fplog, - std::vector* updateList) +void BiasState::updateFreeEnergyAndAddSamplesToHistogram(ArrayRef dimParams, + const BiasGrid& grid, + const BiasParams& params, + const t_commrec* commRecord, + const gmx_multisim_t* multiSimComm, + double t, + int64_t step, + FILE* fplog, + std::vector* updateList) { /* Note hat updateList is only used in this scope and is always * re-initialized. We do not use a local vector, because that would @@ -1252,9 +1252,9 @@ void BiasState::updateFreeEnergyAndAddSamplesToHistogram(const std::vector& dimParams, - const BiasGrid& grid, - gmx::ArrayRef neighborLambdaEnergies, +double BiasState::updateProbabilityWeightsAndConvolvedBias(ArrayRef dimParams, + const BiasGrid& grid, + ArrayRef neighborLambdaEnergies, std::vector>* weight) const { /* Only neighbors of the current coordinate value will have a non-negligible chance of getting sampled */ @@ -1340,9 +1340,9 @@ double BiasState::updateProbabilityWeightsAndConvolvedBias(const std::vector& dimParams, - const BiasGrid& grid, - const awh_dvec& coordValue) const +double BiasState::calcConvolvedBias(ArrayRef dimParams, + const BiasGrid& grid, + const awh_dvec& coordValue) const { int point = grid.nearestIndex(coordValue); const GridPoint& gridPoint = grid.point(point); @@ -1566,7 +1566,7 @@ void BiasState::broadcast(const t_commrec* commRecord) gmx_bcast(sizeof(histogramSize_), &histogramSize_, commRecord->mpi_comm_mygroup); } -void BiasState::setFreeEnergyToConvolvedPmf(const std::vector& dimParams, const BiasGrid& grid) +void BiasState::setFreeEnergyToConvolvedPmf(ArrayRef dimParams, const BiasGrid& grid) { std::vector convolvedPmf; @@ -1626,12 +1626,12 @@ static int countTrailingZeroRows(const double* const* data, int numRows, int num * \param[in] biasIndex The index of the bias. * \param[in,out] pointState The state of the points in this bias. */ -static void readUserPmfAndTargetDistribution(const std::vector& dimParams, - const BiasGrid& grid, - const std::string& filename, - int numBias, - int biasIndex, - std::vector* pointState) +static void readUserPmfAndTargetDistribution(ArrayRef dimParams, + const BiasGrid& grid, + const std::string& filename, + int numBias, + int biasIndex, + std::vector* pointState) { /* Read the PMF and target distribution. From the PMF, the convolved PMF, or the reference value free energy, can be calculated @@ -1821,12 +1821,12 @@ void BiasState::normalizePmf(int numSharingSims) } } -void BiasState::initGridPointState(const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - const BiasGrid& grid, - const BiasParams& params, - const std::string& filename, - int numBias) +void BiasState::initGridPointState(const AwhBiasParams& awhBiasParams, + ArrayRef dimParams, + const BiasGrid& grid, + const BiasParams& params, + const std::string& filename, + int numBias) { /* Modify PMF, free energy and the constant target distribution factor * to user input values if there is data given. @@ -1869,10 +1869,10 @@ void BiasState::initGridPointState(const AwhBiasParams& awhBiasParams, normalizePmf(params.numSharedUpdate); } -BiasState::BiasState(const AwhBiasParams& awhBiasParams, - double histogramSizeInitial, - const std::vector& dimParams, - const BiasGrid& grid) : +BiasState::BiasState(const AwhBiasParams& awhBiasParams, + double histogramSizeInitial, + ArrayRef dimParams, + const BiasGrid& grid) : coordState_(awhBiasParams, dimParams, grid), points_(grid.numPoints()), weightSumCovering_(grid.numPoints()), diff --git a/src/gromacs/applied_forces/awh/biasstate.h b/src/gromacs/applied_forces/awh/biasstate.h index 622f96f12c..97a632ffbd 100644 --- a/src/gromacs/applied_forces/awh/biasstate.h +++ b/src/gromacs/applied_forces/awh/biasstate.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -107,10 +107,10 @@ public: * \param[in] dimParams The dimension parameters. * \param[in] grid The bias grid. */ - BiasState(const AwhBiasParams& awhBiasParams, - double histogramSizeInitial, - const std::vector& dimParams, - const BiasGrid& grid); + BiasState(const AwhBiasParams& awhBiasParams, + double histogramSizeInitial, + ArrayRef dimParams, + const BiasGrid& grid); /*! \brief * Restore the bias state from history. @@ -157,9 +157,9 @@ private: * \param[in] grid The grid. * \param[in,out] convolvedPmf Array returned will be of the same length as the AWH grid to store the convolved PMF in. */ - void calcConvolvedPmf(const std::vector& dimParams, - const BiasGrid& grid, - std::vector* convolvedPmf) const; + void calcConvolvedPmf(ArrayRef dimParams, + const BiasGrid& grid, + std::vector* convolvedPmf) const; /*! \brief * Convolves the PMF and sets the initial free energy to its convolution. @@ -167,7 +167,7 @@ private: * \param[in] dimParams The bias dimensions parameters * \param[in] grid The bias grid. */ - void setFreeEnergyToConvolvedPmf(const std::vector& dimParams, const BiasGrid& grid); + void setFreeEnergyToConvolvedPmf(ArrayRef dimParams, const BiasGrid& grid); /*! \brief * Normalize the PMF histogram. @@ -187,12 +187,12 @@ public: * \param[in] filename Name of file to read PMF and target from. * \param[in] numBias The number of biases. */ - void initGridPointState(const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - const BiasGrid& grid, - const BiasParams& params, - const std::string& filename, - int numBias); + void initGridPointState(const AwhBiasParams& awhBiasParams, + ArrayRef dimParams, + const BiasGrid& grid, + const BiasParams& params, + const std::string& filename, + int numBias); /*! \brief * Performs statistical checks on the collected histograms and warns if issues are detected. @@ -224,11 +224,11 @@ public: * \param[in,out] force Force vector to set. * Returns the umbrella potential. */ - double calcUmbrellaForceAndPotential(const std::vector& dimParams, - const BiasGrid& grid, - int point, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef force) const; + double calcUmbrellaForceAndPotential(ArrayRef dimParams, + const BiasGrid& grid, + int point, + ArrayRef neighborLambdaDhdl, + ArrayRef force) const; /*! \brief * Calculates and sets the convolved force acting on the coordinate. @@ -248,12 +248,12 @@ public: * \param[in] forceWorkBuffer Force work buffer, values only used internally. * \param[in,out] force Bias force vector to set. */ - void calcConvolvedForce(const std::vector& dimParams, - const BiasGrid& grid, - gmx::ArrayRef probWeightNeighbor, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef forceWorkBuffer, - gmx::ArrayRef force) const; + void calcConvolvedForce(ArrayRef dimParams, + const BiasGrid& grid, + ArrayRef probWeightNeighbor, + ArrayRef neighborLambdaDhdl, + ArrayRef forceWorkBuffer, + ArrayRef force) const; /*! \brief * Move the center point of the umbrella potential. @@ -281,15 +281,15 @@ public: * force and potential. * \returns the new potential value. */ - double moveUmbrella(const std::vector& dimParams, - const BiasGrid& grid, - gmx::ArrayRef probWeightNeighbor, - ArrayRef neighborLambdaDhdl, - gmx::ArrayRef biasForce, - int64_t step, - int64_t seed, - int indexSeed, - bool onlySampleUmbrellaGridpoint); + double moveUmbrella(ArrayRef dimParams, + const BiasGrid& grid, + ArrayRef probWeightNeighbor, + ArrayRef neighborLambdaDhdl, + ArrayRef biasForce, + int64_t step, + int64_t seed, + int indexSeed, + bool onlySampleUmbrellaGridpoint); private: /*! \brief @@ -361,11 +361,11 @@ private: * \param[in] multiSimComm Struct for multi-simulation communication. * \returns true if covered. */ - bool isSamplingRegionCovered(const BiasParams& params, - const std::vector& dimParams, - const BiasGrid& grid, - const t_commrec* commRecord, - const gmx_multisim_t* multiSimComm) const; + bool isSamplingRegionCovered(const BiasParams& params, + ArrayRef dimParams, + const BiasGrid& grid, + const t_commrec* commRecord, + const gmx_multisim_t* multiSimComm) const; /*! \brief * Return the new reference weight histogram size for the current update. @@ -416,15 +416,15 @@ public: * \param[in,out] fplog Log file. * \param[in,out] updateList Work space to store a temporary list. */ - void updateFreeEnergyAndAddSamplesToHistogram(const std::vector& dimParams, - const BiasGrid& grid, - const BiasParams& params, - const t_commrec* commRecord, - const gmx_multisim_t* ms, - double t, - int64_t step, - FILE* fplog, - std::vector* updateList); + void updateFreeEnergyAndAddSamplesToHistogram(ArrayRef dimParams, + const BiasGrid& grid, + const BiasParams& params, + const t_commrec* commRecord, + const gmx_multisim_t* ms, + double t, + int64_t step, + FILE* fplog, + std::vector* updateList); /*! \brief * Update the probability weights and the convolved bias. @@ -449,8 +449,8 @@ public: * \returns the convolved bias. */ - double updateProbabilityWeightsAndConvolvedBias(const std::vector& dimParams, - const BiasGrid& grid, + double updateProbabilityWeightsAndConvolvedBias(ArrayRef dimParams, + const BiasGrid& grid, ArrayRef neighborLambdaEnergies, std::vector>* weight) const; @@ -464,7 +464,7 @@ public: * \param[in] grid The grid. * \param[in] probWeightNeighbor Probability weights of the neighbors. */ - void sampleProbabilityWeights(const BiasGrid& grid, gmx::ArrayRef probWeightNeighbor); + void sampleProbabilityWeights(const BiasGrid& grid, ArrayRef probWeightNeighbor); /*! \brief * Sample the reaction coordinate and PMF for future updates or analysis. @@ -479,7 +479,7 @@ public: */ void sampleCoordAndPmf(const std::vector& dimParams, const BiasGrid& grid, - gmx::ArrayRef probWeightNeighbor, + ArrayRef probWeightNeighbor, double convolvedBias); /*! \brief * Calculates the convolved bias for a given coordinate value. @@ -496,9 +496,9 @@ public: * \param[in] coordValue Coordinate value. * \returns the convolved bias >= -GMX_FLOAT_MAX. */ - double calcConvolvedBias(const std::vector& dimParams, - const BiasGrid& grid, - const awh_dvec& coordValue) const; + double calcConvolvedBias(ArrayRef dimParams, + const BiasGrid& grid, + const awh_dvec& coordValue) const; /*! \brief * Fills the given array with PMF values. @@ -509,7 +509,7 @@ public: * * \param[out] pmf Array(ref) to be filled with the PMF values, should have the same size as the bias grid. */ - void getPmf(gmx::ArrayRef /*pmf*/) const; + void getPmf(ArrayRef /*pmf*/) const; /*! \brief Returns the current coordinate state. */ diff --git a/src/gromacs/applied_forces/awh/coordstate.cpp b/src/gromacs/applied_forces/awh/coordstate.cpp index bfa7022b10..544a940bb4 100644 --- a/src/gromacs/applied_forces/awh/coordstate.cpp +++ b/src/gromacs/applied_forces/awh/coordstate.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -63,9 +63,9 @@ namespace gmx { -CoordState::CoordState(const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - const BiasGrid& grid) +CoordState::CoordState(const AwhBiasParams& awhBiasParams, + ArrayRef dimParams, + const BiasGrid& grid) { for (size_t d = 0; d < dimParams.size(); d++) { diff --git a/src/gromacs/applied_forces/awh/coordstate.h b/src/gromacs/applied_forces/awh/coordstate.h index f38ce86de9..05995f826c 100644 --- a/src/gromacs/applied_forces/awh/coordstate.h +++ b/src/gromacs/applied_forces/awh/coordstate.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -77,9 +77,7 @@ public: * \param[in] dimParams The dimension Parameters. * \param[in] grid The grid. */ - CoordState(const AwhBiasParams& awhBiasParams, - const std::vector& dimParams, - const BiasGrid& grid); + CoordState(const AwhBiasParams& awhBiasParams, ArrayRef dimParams, const BiasGrid& grid); /*! \brief * Sample a new umbrella reference point given the current coordinate value. diff --git a/src/gromacs/applied_forces/awh/histogramsize.cpp b/src/gromacs/applied_forces/awh/histogramsize.cpp index f16deed99a..059d8cc6de 100644 --- a/src/gromacs/applied_forces/awh/histogramsize.cpp +++ b/src/gromacs/applied_forces/awh/histogramsize.cpp @@ -150,7 +150,7 @@ namespace * \param[in] pointStates The state of the bias points. * \returns true if the histogram is equilibrated. */ -bool histogramIsEquilibrated(const std::vector& pointStates) +bool histogramIsEquilibrated(ArrayRef pointStates) { /* Get the total weight of the total weight histogram; needed for normalization. */ double totalWeight = 0; @@ -207,12 +207,12 @@ bool histogramIsEquilibrated(const std::vector& pointStates) } // namespace -double HistogramSize::newHistogramSize(const BiasParams& params, - double t, - bool covered, - const std::vector& pointStates, - ArrayRef weightsumCovering, - FILE* fplog) +double HistogramSize::newHistogramSize(const BiasParams& params, + double t, + bool covered, + ArrayRef pointStates, + ArrayRef weightsumCovering, + FILE* fplog) { double newHistogramSize; if (inInitialStage_) diff --git a/src/gromacs/applied_forces/awh/histogramsize.h b/src/gromacs/applied_forces/awh/histogramsize.h index 7d9313549c..9c60adedfe 100644 --- a/src/gromacs/applied_forces/awh/histogramsize.h +++ b/src/gromacs/applied_forces/awh/histogramsize.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -122,12 +122,12 @@ public: * \param[in,out] fplog Log file. * \returns the new histogram size. */ - double newHistogramSize(const BiasParams& params, - double t, - bool covered, - const std::vector& pointStates, - ArrayRef weightsumCovering, - FILE* fplog); + double newHistogramSize(const BiasParams& params, + double t, + bool covered, + ArrayRef pointStates, + ArrayRef weightsumCovering, + FILE* fplog); /*! \brief Restores the histogram size from history. * -- 2.22.0