Skip to content

Commit

Permalink
Import fixes and changes from GROMACS repo
Browse files Browse the repository at this point in the history
Limited to the gromacs/applied_forces directory, not the library
  • Loading branch information
jhenin committed Sep 17, 2024
1 parent 2688f12 commit e1220bd
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
if(NOT GMX_USE_COLVARS STREQUAL "INTERNAL")
gmx_add_libgromacs_sources(
colvarsMDModule_stub.cpp
colvarsoptions.cpp
)
else()
gmx_add_libgromacs_sources(
Expand All @@ -46,8 +47,8 @@ else()
colvarsforceprovider.cpp
colvarproxygromacs.cpp
)
endif()

if (BUILD_TESTING)
add_subdirectory(tests)
endif()
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@

#include "colvarproxygromacs.h"

#include <cstddef>

#include <sstream>
#include <vector>

#include "gromacs/math/vectypes.h"
#include "gromacs/random/seed.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/path.h"

#include "colvarproxy_gromacs_version.h"

enum class PbcType : int;


namespace gmx
{
Expand Down Expand Up @@ -180,7 +188,7 @@ int ColvarProxyGromacs::backup_file(char const* filename)
}
else
{
// General backup provedure
// General backup procedure
make_backup(filename);
}
return COLVARS_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@
#ifndef GMX_APPLIED_FORCES_COLVARPROXYGROMACS_H
#define GMX_APPLIED_FORCES_COLVARPROXYGROMACS_H

#include <map>
#include <string>

// NOLINTBEGIN
// Disabling clang-tidy checks on Colvars library code that is not called directly by GROMACS,
// or is not even used at all (e.g. code used by NAMD or VMD interfaces)
#include "external/colvars/colvarproxy.h"

#include "gromacs/utility/real.h"
// NOLINTEND

#include "gromacs/pbcutil/pbc.h"
Expand All @@ -54,6 +59,8 @@
#include "gromacs/topology/atoms.h"
#include "gromacs/utility/logger.h"

enum class PbcType : int;


namespace gmx
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,32 @@

#include "colvarsMDModule.h"

#include <functional>
#include <memory>
#include <string>

#include "gromacs/domdec/localatomsetmanager.h"
#include "gromacs/fileio/checkpoint.h"
#include "gromacs/mdrunutility/mdmodulesnotifiers.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/iforceprovider.h"
#include "gromacs/mdtypes/imdmodule.h"
#include "gromacs/utility/keyvaluetreebuilder.h"

#include "colvarsforceprovider.h"
#include "colvarsoptions.h"
#include "colvarssimulationsparameters.h"

enum class PbcType : int;
struct gmx_mtop_t;


namespace gmx
{
class IMDOutputProvider;
class IMdpOptionProvider;
class KeyValueTreeObject;
class MDLogger;

namespace
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
#include "gromacs/fileio/checkpoint.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/imdmodule.h"
#include "gromacs/mdtypes/imdpoptionprovider.h"
#include "gromacs/utility/keyvaluetreebuilder.h"

#include "colvarsMDModule.h"
#include "colvarsoptions.h"


namespace gmx
Expand All @@ -62,7 +64,7 @@ namespace
/*! \internal
* \brief Colvars module
*
* Stub Implementation
* Stub Implementation in case Colvars library is not compiled
*/
class ColvarsMDModule final : public IMDModule
{
Expand All @@ -71,15 +73,39 @@ class ColvarsMDModule final : public IMDModule
explicit ColvarsMDModule() = default;


void subscribeToPreProcessingNotifications(MDModulesNotifiers* /*notifier*/) override {}
void subscribeToPreProcessingNotifications(MDModulesNotifiers* /*notifier*/) override
{
// Proper exit when Colvars is activated from the mdp but has not been compiled along with GROMACS.
// In this case, Colvars config file cannot be parsed & verified and the tpr created could be flawed.
if (colvarsOptionsStub_.isActive())
{
GMX_THROW(InternalError(
"Colvars module is activated but GROMACS has not been compiled with Colvars, "
"Colvars simulation is not possible.\n"
"Please, reconfigure GROMACS with -DGMX_USE_COLVARS=internal.\n"));
}
}

void subscribeToSimulationSetupNotifications(MDModulesNotifiers* /*notifier*/) override {}

IMdpOptionProvider* mdpOptionProvider() override { return nullptr; }
IMdpOptionProvider* mdpOptionProvider() override { return &colvarsOptionsStub_; }

IMDOutputProvider* outputProvider() override { return nullptr; }

void initForceProviders(ForceProviders* /*forceProviders*/) override {}
void initForceProviders(ForceProviders* /*forceProviders*/) override
{
// Proper exit when Colvars is activated from the tpr but has not been compiled along with GROMACS.
if (colvarsOptionsStub_.isActive())
{
GMX_THROW(InternalError(
"Colvars module is activated but GROMACS has not been compiled with Colvars, "
"Colvars simulation is not possible.\n"
"Please, reconfigure GROMACS with -DGMX_USE_COLVARS=internal.\n"));
}
}

private:
ColvarsOptions colvarsOptionsStub_;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,40 @@

#include "colvarsforceprovider.h"

#include <cstddef>
#include <cstdint>

#include <array>
#include <string>

#include "external/colvars/colvars_memstream.h"

#include "gromacs/applied_forces/colvars/colvarproxygromacs.h"
#include "gromacs/compat/pointers.h"
#include "gromacs/domdec/localatomsetmanager.h"
#include "gromacs/fileio/checkpoint.h"
#include "gromacs/gmxlib/network.h"
#include "gromacs/math/vec.h"
#include "gromacs/mdlib/broadcaststructs.h"
#include "gromacs/mdlib/groupcoord.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/enerdata.h"
#include "gromacs/mdtypes/forceoutput.h"
#include "gromacs/pbcutil/pbc.h"
#include "gromacs/topology/ifunc.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/keyvaluetreebuilder.h"
#include "gromacs/utility/smalloc.h"

enum class PbcType : int;


namespace gmx
{
class MDLogger;

/********************************************************************
* ColvarsForceProviderState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,33 @@
#define GMX_APPLIED_FORCES_COLVARSFORCEPROVIDER_H


#include <cstdint>

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "gromacs/domdec/localatomset.h"
#include "gromacs/math/vectypes.h"
#include "gromacs/mdrunutility/mdmodulesnotifiers.h"
#include "gromacs/mdtypes/iforceprovider.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/utility/real.h"

#include "colvarproxygromacs.h"

enum class PbcType : int;
struct t_commrec;


namespace gmx
{
class KeyValueTreeObject;
class KeyValueTreeObjectBuilder;
class LocalAtomSetManager;
class MDLogger;
struct MDModulesWriteCheckpointData;


/*! \internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,43 @@
/*! \internal \file
* \brief
* Implements options for Colvars.
* Keep a minimal ColvarsOptions implementation in the case Colvars is not activated
* to ensure compatbility (with gmx tools for example).
*/
#include "gmxpre.h"

#include "colvarsoptions.h"

#include "config.h"

#include <cstddef>

#include <filesystem>
#include <fstream>
#include <optional>

#include "gromacs/math/arrayrefwithpadding.h"
#include "gromacs/math/vec.h"
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/ioptionscontainerwithsections.h"
#include "gromacs/options/optionsection.h"
#include "gromacs/topology/mtop_util.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/keyvaluetreebuilder.h"
#include "gromacs/utility/keyvaluetreetransform.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/textreader.h"

#include "colvarspreprocessor.h"
#if GMX_HAVE_COLVARS
# include "colvarspreprocessor.h"
#endif

enum class PbcType : int;
struct gmx_mtop_t;


namespace gmx
Expand Down Expand Up @@ -127,11 +145,23 @@ void ColvarsOptions::initMdpOptions(IOptionsContainerWithSections* options)
}


bool ColvarsOptions::isActive() const
{
return active_;
}


#if GMX_HAVE_COLVARS


void ColvarsOptions::writeInternalParametersToKvt(KeyValueTreeObjectBuilder treeBuilder)
{

// Copy the content of the colvars input file into a string for latter save in KVT
colvarsConfigString_ = TextReader::readFileToString(colvarsFileName_);
if (!colvarsFileName_.empty())
{
colvarsConfigString_ = TextReader::readFileToString(colvarsFileName_);
}

// Write colvars input file as a string
treeBuilder.addValue<std::string>(c_colvarsModuleName + "-" + c_configStringTag_, colvarsConfigString_);
Expand Down Expand Up @@ -270,8 +300,7 @@ void ColvarsOptions::processEdrFilename(const EdrOutputFilename& filename)
// Provided name should not be empty
GMX_RELEASE_ASSERT(!filename.edrOutputFilename_.empty(), "Empty name for the *.edr output file");

outputPrefix_ =
stripExtension(std::filesystem::path(filename.edrOutputFilename_).filename()).u8string();
outputPrefix_ = stripExtension(std::filesystem::path(filename.edrOutputFilename_)).string();
}


Expand All @@ -287,11 +316,6 @@ void ColvarsOptions::processTemperature(const EnsembleTemperature& temp)
}
}

bool ColvarsOptions::isActive() const
{
return active_;
}

const std::string& ColvarsOptions::colvarsFileName() const
{
return colvarsFileName_;
Expand Down Expand Up @@ -344,4 +368,6 @@ void ColvarsOptions::setParameters(const std::string& colvarsfile,
}


#endif // GMX_HAVE_COLVARS

} // namespace gmx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@
#include "gromacs/mdrunutility/mdmodulesnotifiers.h"
#include "gromacs/mdtypes/imdpoptionprovider.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/logger.h"
#include "gromacs/utility/real.h"

enum class PbcType : int;
struct gmx_mtop_t;


namespace gmx
{
Expand All @@ -61,6 +65,9 @@ class KeyValueTreeObject;
class KeyValueTreeBuilder;
struct CoordinatesAndBoxPreprocessed;
struct MdRunInputFilename;
class IKeyValueTreeTransformRules;
class IOptionsContainerWithSections;
class KeyValueTreeObjectBuilder;


//! Tag with name of the Colvars MDModule
Expand Down Expand Up @@ -185,8 +192,8 @@ class ColvarsOptions final : public IMdpOptionProvider

//! \}

//! Colvars config filename, default colvars.dat
std::string colvarsFileName_ = "colvars.dat";
//! Colvars config filename
std::string colvarsFileName_;


//! Colvars seed for Langevin integrator
Expand Down
Loading

0 comments on commit e1220bd

Please sign in to comment.