Skip to content

V2.10 patches/gromacs2025 #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions patches/gromacs-2025.0.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


function plumed_preliminary_test(){
# check if the README contains the word GROMACS and if gromacs has been already configured
grep -q GROMACS README 1>/dev/null 2>/dev/null
}

function plumed_patch_info(){
cat << EOF
A basic PLUMED interface is already present in GROMACS

This patch previes extra features to be implemented in the official PLUMED integration in the next GROMACS version

Patching must be done in the gromacs root directory _before_ the cmake command is invoked.

The GROMACS integration has some improvements with the compatibility wiht the multi-threading implementation
but it is still preferable to configure gromacs as

cmake -DGMX_THREAD_MPI=OFF and add -DGMX_MPI=ON if you want to use MPI.

To enable PLUMED in a gromacs simulation one should use
mdrun with an extra -plumed flag. The flag can be used to
specify the name of the PLUMED input file, e.g.:

gmx mdrun -plumed plumed.dat

For more information on gromacs you should visit http://www.gromacs.org

EOF
}

plumed_before_patch(){
plumed_patch_info
}

PLUMED_PATCH_NO_INCLUDE=true

#this will be added later
#PLUMED_PATCH_EXTRA_FILES="src/external/plumed/PlumedInclude.h src/external/plumed/PlumedKernel.cpp src/gromacs/applied_forces/plumed/PlumedOutside.cpp src/gromacs/applied_forces/plumed/PlumedOutside.h"
82 changes: 82 additions & 0 deletions patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright 2024- The GROMACS Authors
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
#
# GROMACS is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# GROMACS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at https://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out https://www.gromacs.org.







# Builds the interface to plumed and add the linkage to libPlumed

gmx_option_multichoice(GMX_USE_PLUMED
"Build the PLUMED wrapper with GROMACS"
ON
ON)
mark_as_advanced(GMX_USE_PLUMED)

function(gmx_manage_plumed)
# Create a link target, leave it empty if the plumed option is not active
add_library(plumedgmx INTERFACE)
set (GMX_PLUMED_ACTIVE OFF CACHE INTERNAL "Cache entry for PLUMED activation")
if(WIN32)
if(GMX_USE_PLUMED STREQUAL "ON")
message(FATAL_ERROR "PLUMED is not supported on Windows. Reconfigure with -DGMX_USE_PLUMED=OFF.")
endif()
elseif(NOT GMX_USE_PLUMED STREQUAL "OFF")
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
include(CheckFunctionExists)
check_function_exists(dlopen HAVE_DLOPEN)
cmake_pop_check_state()
if(HAVE_DLOPEN)
# Plumed.h compiled in c++ mode creates a fully inlined interface
# So we just need to activate the directory in applied_forces
set(PLUMED_DIR "${CMAKE_SOURCE_DIR}/src/external/plumed")
target_link_libraries( plumedgmx INTERFACE ${CMAKE_DL_LIBS} )
# The plumedgmx already exists, now we set it up:
target_include_directories(plumedgmx SYSTEM INTERFACE $<BUILD_INTERFACE:${PLUMED_DIR}>)
set (GMX_PLUMED_ACTIVE ON CACHE INTERNAL "Cache entry for PLUMED activation")
else()
if(GMX_USE_PLUMED STREQUAL "ON")
message(FATAL_ERROR "PLUMED needs dlopen or anything equivalent. Reconfigure with -DGMX_USE_PLUMED=OFF.")
else() # "AUTO"
message(STATUS "PLUMED needs dlopen or anything equivalent. Disabling support.")
endif()

endif()

endif()

endfunction()
82 changes: 82 additions & 0 deletions patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake.preplumed
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright 2024- The GROMACS Authors
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
#
# GROMACS is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# GROMACS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at https://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out https://www.gromacs.org.







# Builds the interface to plumed and add the linkage to libPlumed

gmx_option_multichoice(GMX_USE_PLUMED
"Build the PLUMED wrapper with GROMACS"
AUTO
AUTO ON OFF)
mark_as_advanced(GMX_USE_PLUMED)

function(gmx_manage_plumed)
# Create a link target, leave it empty if the plumed option is not active
add_library(plumedgmx INTERFACE)
set (GMX_PLUMED_ACTIVE OFF CACHE INTERNAL "Cache entry for PLUMED activation")
if(WIN32)
if(GMX_USE_PLUMED STREQUAL "ON")
message(FATAL_ERROR "PLUMED is not supported on Windows. Reconfigure with -DGMX_USE_PLUMED=OFF.")
endif()
elseif(NOT GMX_USE_PLUMED STREQUAL "OFF")
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
include(CheckFunctionExists)
check_function_exists(dlopen HAVE_DLOPEN)
cmake_pop_check_state()
if(HAVE_DLOPEN)
# Plumed.h compiled in c++ mode creates a fully inlined interface
# So we just need to activate the directory in applied_forces
set(PLUMED_DIR "${CMAKE_SOURCE_DIR}/src/external/plumed")
target_link_libraries( plumedgmx INTERFACE ${CMAKE_DL_LIBS} )
# The plumedgmx already exists, now we set it up:
target_include_directories(plumedgmx SYSTEM INTERFACE $<BUILD_INTERFACE:${PLUMED_DIR}>)
set (GMX_PLUMED_ACTIVE ON CACHE INTERNAL "Cache entry for PLUMED activation")
else()
if(GMX_USE_PLUMED STREQUAL "ON")
message(FATAL_ERROR "PLUMED needs dlopen or anything equivalent. Reconfigure with -DGMX_USE_PLUMED=OFF.")
else() # "AUTO"
message(STATUS "PLUMED needs dlopen or anything equivalent. Disabling support.")
endif()

endif()

endif()

endfunction()
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright 2024- The GROMACS Authors
* and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
* Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* GROMACS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GROMACS; if not, see
* https://www.gnu.org/licenses, or write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* If you want to redistribute modifications to GROMACS, please
* consider that scientific software is very special. Version
* control is crucial - bugs must be traceable. We will be happy to
* consider code for inclusion in the official distribution, but
* derived work must not be called official GROMACS. Details are found
* in the README & COPYING files - if they are missing, get the
* official version at https://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out https://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements Plumed MDModule class
*
* \author Daniele Rapetti <[email protected]>
* \ingroup module_applied_forces
*/
#include "gmxpre.h"

#include "plumedMDModule.h"

#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/imdmodule.h"
#include "gromacs/utility/keyvaluetreebuilder.h"

#include "plumedOptions.h"
#include "plumedforceprovider.h"

class gmx_multisim_t;

namespace gmx
{

namespace
{

/*! \internal
* \brief Plumed module
*
* Class that implements the plumed MDModule
*/
class PlumedMDModule final : public IMDModule
{
public:
//! \brief Construct the plumed module.
explicit PlumedMDModule() = default;
// Now callbacks for several kinds of MdModuleNotification are created
// and subscribed, and will be dispatched correctly at run time
// based on the type of the parameter required by the lambda.

/*! \brief Requests to be notified during pre-processing.
*
* Plumed does not act during the preprocessing phase of a simulation, so the input are ignored
*/
void subscribeToPreProcessingNotifications(MDModulesNotifiers* /*notifier*/) override {}

/*! \brief Subscribe to MDModules notifications for information needed just before the simulation.
*/
void subscribeToSimulationSetupNotifications(MDModulesNotifiers* notifier) override
{
// TODO: add a check for threadmpi (see #5104, https://gitlab.com/gromacs/gromacs/-/merge_requests/4367#note_2102475958, the manual and the force provider for the details)

// Access the plumed filename this is used to activate the plumed module
notifier->simulationSetupNotifier_.subscribe(
[this](const PlumedInputFilename& plumedFilename)
{ this->options_.setPlumedFile(plumedFilename.plumedFilename_); });
// Retrieve the Multisim options
notifier->simulationSetupNotifier_.subscribe(
[this](const gmx_multisim_t* ms)
{ this->options_.setMultisim(ms); });
// Access the temperature if it is constant during the simulation
notifier->simulationSetupNotifier_.subscribe(
[this](const EnsembleTemperature& ensembleT)
{ this->options_.setEnsembleTemperature(ensembleT); });
// Access of the topology
notifier->simulationSetupNotifier_.subscribe([this](const gmx_mtop_t& mtop)
{ this->options_.setTopology(mtop); });
// Retrieve the Communication Record during simulations setup
notifier->simulationSetupNotifier_.subscribe([this](const t_commrec& cr)
{ this->options_.setComm(cr); });
// setting the simulation time step
notifier->simulationSetupNotifier_.subscribe(
[this](const SimulationTimeStep& simulationTimeStep)
{ this->options_.setSimulationTimeStep(simulationTimeStep.delta_t); });
// Retrieve the starting behavior
notifier->simulationSetupNotifier_.subscribe(
[this](const StartingBehavior& startingBehavior)
{ this->options_.setStartingBehavior(startingBehavior); });
// writing checkpoint data
notifier->checkpointingNotifier_.subscribe(
[this](MDModulesWriteCheckpointData /*checkpointData*/)
{
if (options_.active())
{
plumedForceProvider_->writeCheckpointData();
}
});
}

//! From IMDModule
IMdpOptionProvider* mdpOptionProvider() override { return nullptr; }
//! From IMDModule
IMDOutputProvider* outputProvider() override
{ // Plumed provide its own output
return nullptr;
}
//! From IMDModule - Adds this module to the force providers if active
void initForceProviders(ForceProviders* forceProviders) override
{
if (options_.active())
{
plumedForceProvider_ = std::make_unique<PlumedForceProvider>(options_.options());
forceProviders->addForceProvider(plumedForceProvider_.get(), "Plumed");
}
}


private:
//! Parameters that become available at simulation setup time.
PlumedOptionProvider options_{};
//! Object that evaluates the forces
std::unique_ptr<PlumedForceProvider> plumedForceProvider_{};
};

} // namespace

std::unique_ptr<IMDModule> PlumedModuleInfo::create()
{
return std::make_unique<PlumedMDModule>();
}
} // namespace gmx
Loading