Skip to content

Commit d9ad34b

Browse files
Merge branch 'v2.10'
2 parents 6152e6f + 25fec32 commit d9ad34b

File tree

12 files changed

+1406
-20
lines changed

12 files changed

+1406
-20
lines changed

patches/gromacs-2025.0.config

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
function plumed_preliminary_test(){
4+
# check if the README contains the word GROMACS and if gromacs has been already configured
5+
grep -q GROMACS README 1>/dev/null 2>/dev/null
6+
}
7+
8+
function plumed_patch_info(){
9+
cat << EOF
10+
A basic PLUMED interface is already present in GROMACS
11+
12+
This patch previes extra features to be implemented in the official PLUMED integration in the next GROMACS version
13+
14+
Patching must be done in the gromacs root directory _before_ the cmake command is invoked.
15+
16+
The GROMACS integration has some improvements with the compatibility wiht the multi-threading implementation
17+
but it is still preferable to configure gromacs as
18+
19+
cmake -DGMX_THREAD_MPI=OFF and add -DGMX_MPI=ON if you want to use MPI.
20+
21+
To enable PLUMED in a gromacs simulation one should use
22+
mdrun with an extra -plumed flag. The flag can be used to
23+
specify the name of the PLUMED input file, e.g.:
24+
25+
gmx mdrun -plumed plumed.dat
26+
27+
For more information on gromacs you should visit http://www.gromacs.org
28+
29+
EOF
30+
}
31+
32+
plumed_before_patch(){
33+
plumed_patch_info
34+
}
35+
36+
PLUMED_PATCH_NO_INCLUDE=true
37+
38+
#this will be added later
39+
#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"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# This file is part of the GROMACS molecular simulation package.
3+
#
4+
# Copyright 2024- The GROMACS Authors
5+
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
6+
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
7+
#
8+
# GROMACS is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU Lesser General Public License
10+
# as published by the Free Software Foundation; either version 2.1
11+
# of the License, or (at your option) any later version.
12+
#
13+
# GROMACS is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# Lesser General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU Lesser General Public
19+
# License along with GROMACS; if not, see
20+
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
21+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22+
#
23+
# If you want to redistribute modifications to GROMACS, please
24+
# consider that scientific software is very special. Version
25+
# control is crucial - bugs must be traceable. We will be happy to
26+
# consider code for inclusion in the official distribution, but
27+
# derived work must not be called official GROMACS. Details are found
28+
# in the README & COPYING files - if they are missing, get the
29+
# official version at https://www.gromacs.org.
30+
#
31+
# To help us fund GROMACS development, we humbly ask that you cite
32+
# the research papers on the package. Check out https://www.gromacs.org.
33+
34+
35+
36+
37+
38+
39+
40+
# Builds the interface to plumed and add the linkage to libPlumed
41+
42+
gmx_option_multichoice(GMX_USE_PLUMED
43+
"Build the PLUMED wrapper with GROMACS"
44+
ON
45+
ON)
46+
mark_as_advanced(GMX_USE_PLUMED)
47+
48+
function(gmx_manage_plumed)
49+
# Create a link target, leave it empty if the plumed option is not active
50+
add_library(plumedgmx INTERFACE)
51+
set (GMX_PLUMED_ACTIVE OFF CACHE INTERNAL "Cache entry for PLUMED activation")
52+
if(WIN32)
53+
if(GMX_USE_PLUMED STREQUAL "ON")
54+
message(FATAL_ERROR "PLUMED is not supported on Windows. Reconfigure with -DGMX_USE_PLUMED=OFF.")
55+
endif()
56+
elseif(NOT GMX_USE_PLUMED STREQUAL "OFF")
57+
include(CMakePushCheckState)
58+
cmake_push_check_state(RESET)
59+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
60+
include(CheckFunctionExists)
61+
check_function_exists(dlopen HAVE_DLOPEN)
62+
cmake_pop_check_state()
63+
if(HAVE_DLOPEN)
64+
# Plumed.h compiled in c++ mode creates a fully inlined interface
65+
# So we just need to activate the directory in applied_forces
66+
set(PLUMED_DIR "${CMAKE_SOURCE_DIR}/src/external/plumed")
67+
target_link_libraries( plumedgmx INTERFACE ${CMAKE_DL_LIBS} )
68+
# The plumedgmx already exists, now we set it up:
69+
target_include_directories(plumedgmx SYSTEM INTERFACE $<BUILD_INTERFACE:${PLUMED_DIR}>)
70+
set (GMX_PLUMED_ACTIVE ON CACHE INTERNAL "Cache entry for PLUMED activation")
71+
else()
72+
if(GMX_USE_PLUMED STREQUAL "ON")
73+
message(FATAL_ERROR "PLUMED needs dlopen or anything equivalent. Reconfigure with -DGMX_USE_PLUMED=OFF.")
74+
else() # "AUTO"
75+
message(STATUS "PLUMED needs dlopen or anything equivalent. Disabling support.")
76+
endif()
77+
78+
endif()
79+
80+
endif()
81+
82+
endfunction()
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# This file is part of the GROMACS molecular simulation package.
3+
#
4+
# Copyright 2024- The GROMACS Authors
5+
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
6+
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
7+
#
8+
# GROMACS is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU Lesser General Public License
10+
# as published by the Free Software Foundation; either version 2.1
11+
# of the License, or (at your option) any later version.
12+
#
13+
# GROMACS is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# Lesser General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU Lesser General Public
19+
# License along with GROMACS; if not, see
20+
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
21+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22+
#
23+
# If you want to redistribute modifications to GROMACS, please
24+
# consider that scientific software is very special. Version
25+
# control is crucial - bugs must be traceable. We will be happy to
26+
# consider code for inclusion in the official distribution, but
27+
# derived work must not be called official GROMACS. Details are found
28+
# in the README & COPYING files - if they are missing, get the
29+
# official version at https://www.gromacs.org.
30+
#
31+
# To help us fund GROMACS development, we humbly ask that you cite
32+
# the research papers on the package. Check out https://www.gromacs.org.
33+
34+
35+
36+
37+
38+
39+
40+
# Builds the interface to plumed and add the linkage to libPlumed
41+
42+
gmx_option_multichoice(GMX_USE_PLUMED
43+
"Build the PLUMED wrapper with GROMACS"
44+
AUTO
45+
AUTO ON OFF)
46+
mark_as_advanced(GMX_USE_PLUMED)
47+
48+
function(gmx_manage_plumed)
49+
# Create a link target, leave it empty if the plumed option is not active
50+
add_library(plumedgmx INTERFACE)
51+
set (GMX_PLUMED_ACTIVE OFF CACHE INTERNAL "Cache entry for PLUMED activation")
52+
if(WIN32)
53+
if(GMX_USE_PLUMED STREQUAL "ON")
54+
message(FATAL_ERROR "PLUMED is not supported on Windows. Reconfigure with -DGMX_USE_PLUMED=OFF.")
55+
endif()
56+
elseif(NOT GMX_USE_PLUMED STREQUAL "OFF")
57+
include(CMakePushCheckState)
58+
cmake_push_check_state(RESET)
59+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
60+
include(CheckFunctionExists)
61+
check_function_exists(dlopen HAVE_DLOPEN)
62+
cmake_pop_check_state()
63+
if(HAVE_DLOPEN)
64+
# Plumed.h compiled in c++ mode creates a fully inlined interface
65+
# So we just need to activate the directory in applied_forces
66+
set(PLUMED_DIR "${CMAKE_SOURCE_DIR}/src/external/plumed")
67+
target_link_libraries( plumedgmx INTERFACE ${CMAKE_DL_LIBS} )
68+
# The plumedgmx already exists, now we set it up:
69+
target_include_directories(plumedgmx SYSTEM INTERFACE $<BUILD_INTERFACE:${PLUMED_DIR}>)
70+
set (GMX_PLUMED_ACTIVE ON CACHE INTERNAL "Cache entry for PLUMED activation")
71+
else()
72+
if(GMX_USE_PLUMED STREQUAL "ON")
73+
message(FATAL_ERROR "PLUMED needs dlopen or anything equivalent. Reconfigure with -DGMX_USE_PLUMED=OFF.")
74+
else() # "AUTO"
75+
message(STATUS "PLUMED needs dlopen or anything equivalent. Disabling support.")
76+
endif()
77+
78+
endif()
79+
80+
endif()
81+
82+
endfunction()
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* This file is part of the GROMACS molecular simulation package.
3+
*
4+
* Copyright 2024- The GROMACS Authors
5+
* and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
6+
* Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
7+
*
8+
* GROMACS is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public License
10+
* as published by the Free Software Foundation; either version 2.1
11+
* of the License, or (at your option) any later version.
12+
*
13+
* GROMACS is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with GROMACS; if not, see
20+
* https://www.gnu.org/licenses, or write to the Free Software Foundation,
21+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22+
*
23+
* If you want to redistribute modifications to GROMACS, please
24+
* consider that scientific software is very special. Version
25+
* control is crucial - bugs must be traceable. We will be happy to
26+
* consider code for inclusion in the official distribution, but
27+
* derived work must not be called official GROMACS. Details are found
28+
* in the README & COPYING files - if they are missing, get the
29+
* official version at https://www.gromacs.org.
30+
*
31+
* To help us fund GROMACS development, we humbly ask that you cite
32+
* the research papers on the package. Check out https://www.gromacs.org.
33+
*/
34+
/*! \internal \file
35+
* \brief
36+
* Implements Plumed MDModule class
37+
*
38+
* \author Daniele Rapetti <drapetti@sissa.it>
39+
* \ingroup module_applied_forces
40+
*/
41+
#include "gmxpre.h"
42+
43+
#include "plumedMDModule.h"
44+
45+
#include <memory>
46+
#include <string>
47+
48+
#include "gromacs/domdec/localatomsetmanager.h"
49+
#include "gromacs/fileio/checkpoint.h"
50+
#include "gromacs/mdrunutility/mdmodulesnotifiers.h"
51+
#include "gromacs/mdtypes/commrec.h"
52+
#include "gromacs/mdtypes/imdmodule.h"
53+
#include "gromacs/utility/keyvaluetreebuilder.h"
54+
55+
#include "plumedOptions.h"
56+
#include "plumedforceprovider.h"
57+
58+
class gmx_multisim_t;
59+
60+
namespace gmx
61+
{
62+
63+
namespace
64+
{
65+
66+
/*! \internal
67+
* \brief Plumed module
68+
*
69+
* Class that implements the plumed MDModule
70+
*/
71+
class PlumedMDModule final : public IMDModule
72+
{
73+
public:
74+
//! \brief Construct the plumed module.
75+
explicit PlumedMDModule() = default;
76+
// Now callbacks for several kinds of MdModuleNotification are created
77+
// and subscribed, and will be dispatched correctly at run time
78+
// based on the type of the parameter required by the lambda.
79+
80+
/*! \brief Requests to be notified during pre-processing.
81+
*
82+
* Plumed does not act during the preprocessing phase of a simulation, so the input are ignored
83+
*/
84+
void subscribeToPreProcessingNotifications(MDModulesNotifiers* /*notifier*/) override {}
85+
86+
/*! \brief Subscribe to MDModules notifications for information needed just before the simulation.
87+
*/
88+
void subscribeToSimulationSetupNotifications(MDModulesNotifiers* notifier) override
89+
{
90+
// 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)
91+
92+
// Access the plumed filename this is used to activate the plumed module
93+
notifier->simulationSetupNotifier_.subscribe(
94+
[this](const PlumedInputFilename& plumedFilename)
95+
{ this->options_.setPlumedFile(plumedFilename.plumedFilename_); });
96+
// Retrieve the Multisim options
97+
notifier->simulationSetupNotifier_.subscribe(
98+
[this](const gmx_multisim_t* ms)
99+
{ this->options_.setMultisim(ms); });
100+
// Access the temperature if it is constant during the simulation
101+
notifier->simulationSetupNotifier_.subscribe(
102+
[this](const EnsembleTemperature& ensembleT)
103+
{ this->options_.setEnsembleTemperature(ensembleT); });
104+
// Access of the topology
105+
notifier->simulationSetupNotifier_.subscribe([this](const gmx_mtop_t& mtop)
106+
{ this->options_.setTopology(mtop); });
107+
// Retrieve the Communication Record during simulations setup
108+
notifier->simulationSetupNotifier_.subscribe([this](const t_commrec& cr)
109+
{ this->options_.setComm(cr); });
110+
// setting the simulation time step
111+
notifier->simulationSetupNotifier_.subscribe(
112+
[this](const SimulationTimeStep& simulationTimeStep)
113+
{ this->options_.setSimulationTimeStep(simulationTimeStep.delta_t); });
114+
// Retrieve the starting behavior
115+
notifier->simulationSetupNotifier_.subscribe(
116+
[this](const StartingBehavior& startingBehavior)
117+
{ this->options_.setStartingBehavior(startingBehavior); });
118+
// writing checkpoint data
119+
notifier->checkpointingNotifier_.subscribe(
120+
[this](MDModulesWriteCheckpointData /*checkpointData*/)
121+
{
122+
if (options_.active())
123+
{
124+
plumedForceProvider_->writeCheckpointData();
125+
}
126+
});
127+
}
128+
129+
//! From IMDModule
130+
IMdpOptionProvider* mdpOptionProvider() override { return nullptr; }
131+
//! From IMDModule
132+
IMDOutputProvider* outputProvider() override
133+
{ // Plumed provide its own output
134+
return nullptr;
135+
}
136+
//! From IMDModule - Adds this module to the force providers if active
137+
void initForceProviders(ForceProviders* forceProviders) override
138+
{
139+
if (options_.active())
140+
{
141+
plumedForceProvider_ = std::make_unique<PlumedForceProvider>(options_.options());
142+
forceProviders->addForceProvider(plumedForceProvider_.get(), "Plumed");
143+
}
144+
}
145+
146+
147+
private:
148+
//! Parameters that become available at simulation setup time.
149+
PlumedOptionProvider options_{};
150+
//! Object that evaluates the forces
151+
std::unique_ptr<PlumedForceProvider> plumedForceProvider_{};
152+
};
153+
154+
} // namespace
155+
156+
std::unique_ptr<IMDModule> PlumedModuleInfo::create()
157+
{
158+
return std::make_unique<PlumedMDModule>();
159+
}
160+
} // namespace gmx

0 commit comments

Comments
 (0)