From 46df93303e430ca219c9f7ab27f4de5dc11fea8b Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Thu, 16 Sep 2021 10:45:17 +0000 Subject: [PATCH] Eliminate GMX_MIMIC symbol from source code --- src/config.h.cmakein | 3 - src/gromacs/mdrun/mimic.cpp | 2 +- src/gromacs/mimic/CMakeLists.txt | 14 +++- src/gromacs/mimic/communicator.cpp | 82 +++++---------------- src/gromacs/mimic/communicator.h | 12 +-- src/gromacs/mimic/communicator_stub.cpp | 97 +++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 76 deletions(-) create mode 100644 src/gromacs/mimic/communicator_stub.cpp diff --git a/src/config.h.cmakein b/src/config.h.cmakein index 298d9f40b6..b082d5e702 100644 --- a/src/config.h.cmakein +++ b/src/config.h.cmakein @@ -401,9 +401,6 @@ /* Build using clang analyzer */ #cmakedefine01 GMX_CLANG_ANALYZER -/* Use MiMiC QM/MM interface */ -#cmakedefine01 GMX_MIMIC - /* Use Interactive Molecular Dynamics */ #cmakedefine01 GMX_IMD diff --git a/src/gromacs/mdrun/mimic.cpp b/src/gromacs/mdrun/mimic.cpp index 29b74e0d8b..995336e157 100644 --- a/src/gromacs/mdrun/mimic.cpp +++ b/src/gromacs/mdrun/mimic.cpp @@ -452,7 +452,7 @@ void gmx::LegacySimulator::do_mimic() if (MASTER(cr)) { - MimicCommunicator::getCoords(&state_global->x, state_global->natoms); + MimicCommunicator::getCoords(state_global->x, state_global->natoms); } if (ir->efep != FreeEnergyPerturbationType::No) diff --git a/src/gromacs/mimic/CMakeLists.txt b/src/gromacs/mimic/CMakeLists.txt index 84040bd4c7..d4832ab1c5 100644 --- a/src/gromacs/mimic/CMakeLists.txt +++ b/src/gromacs/mimic/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2018,2019,2020, by the GROMACS development team, led by +# Copyright (c) 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. @@ -34,7 +34,17 @@ # Set up the module library add_library(mimic INTERFACE) -file(GLOB MIMIC_SOURCES *.cpp) +if (GMX_MIMIC) + file(GLOB MIMIC_SOURCES + communicator.cpp + utilities.cpp + ) +else() + file(GLOB MIMIC_SOURCES + communicator_stub.cpp + utilities.cpp + ) +endif() set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${MIMIC_SOURCES} PARENT_SCOPE) # Source files have the following dependencies on library infrastructure. diff --git a/src/gromacs/mimic/communicator.cpp b/src/gromacs/mimic/communicator.cpp index 177dc8813b..9b3f8a9fc1 100644 --- a/src/gromacs/mimic/communicator.cpp +++ b/src/gromacs/mimic/communicator.cpp @@ -41,71 +41,23 @@ #include #include "gromacs/math/units.h" -#include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/arrayref.h" -#if GMX_MIMIC -# include -# include -#endif +// Include headers from MiMiC library +#include +#include -// When not built in a configuration with QMMM support, much of this -// code is unreachable by design. Tell clang not to warn about it. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmissing-noreturn" - -#if !GMX_MIMIC -//! \brief Definitions to stub the ones defined in DataTypes.h -constexpr int TYPE_INT = 0, TYPE_DOUBLE = 0; - -/*! \brief Stub communication library function to call in case if - * GROMACS is compiled without MiMiC. Calling causes GROMACS to exit! - */ -static void MCL_init_client(const char*) // NOLINT(readability-named-parameter) +namespace gmx { - GMX_RELEASE_ASSERT( - GMX_MIMIC, - "GROMACS is compiled without MiMiC support! Please, recompile with -DGMX_MIMIC=ON"); -} -/*! \brief Stub communication library function to call in case if - * GROMACS is compiled without MiMiC. Calling causes GROMACS to exit! - */ -static void MCL_send(void*, int, int, int) // NOLINT(readability-named-parameter) -{ - GMX_RELEASE_ASSERT( - GMX_MIMIC, - "GROMACS is compiled without MiMiC support! Please, recompile with -DGMX_MIMIC=ON"); -} - -/*! \brief Stub communication library function to call in case if - * GROMACS is compiled without MiMiC. Calling causes GROMACS to exit! - */ -static void MCL_receive(void*, int, int, int) // NOLINT(readability-named-parameter) -{ - GMX_RELEASE_ASSERT( - GMX_MIMIC, - "GROMACS is compiled without MiMiC support! Please, recompile with -DGMX_MIMIC=ON"); -} - -/*! \brief Stub communication library function to call in case if - * GROMACS is compiled without MiMiC. Calling causes GROMACS to exit! - */ -static void MCL_destroy() -{ - GMX_RELEASE_ASSERT( - GMX_MIMIC, - "GROMACS is compiled without MiMiC support! Please, recompile with -DGMX_MIMIC=ON"); -} -#endif - -void gmx::MimicCommunicator::init() +void MimicCommunicator::init() { char path[GMX_PATH_MAX]; gmx_getcwd(path, GMX_PATH_MAX); MCL_init_client(path); } -void gmx::MimicCommunicator::sendInitData(gmx_mtop_t* mtop, PaddedHostVector coords) +void MimicCommunicator::sendInitData(gmx_mtop_t* mtop, ArrayRef coords) { MCL_send(&mtop->natoms, 1, TYPE_INT, 0); MCL_send(&mtop->atomtypes.nr, 1, TYPE_INT, 0); @@ -141,7 +93,7 @@ void gmx::MimicCommunicator::sendInitData(gmx_mtop_t* mtop, PaddedHostVector(mtop->ffparams.iparams[contype].constr.dA) - / gmx::c_bohr2Nm); + / c_bohr2Nm); } for (int ncon = 0; ncon < nsettle; ++ncon) @@ -243,32 +195,32 @@ void gmx::MimicCommunicator::sendInitData(gmx_mtop_t* mtop, PaddedHostVectornatoms, TYPE_DOUBLE, 0); } -int64_t gmx::MimicCommunicator::getStepNumber() +int64_t MimicCommunicator::getStepNumber() { int steps; MCL_receive(&steps, 1, TYPE_INT, 0); return steps; } -void gmx::MimicCommunicator::getCoords(PaddedHostVector* x, const int natoms) +void MimicCommunicator::getCoords(ArrayRef x, const int natoms) { std::vector coords(natoms * 3); MCL_receive(&*coords.begin(), 3 * natoms, TYPE_DOUBLE, 0); for (int j = 0; j < natoms; ++j) { - (*x)[j][0] = static_cast(coords[j * 3] * gmx::c_bohr2Nm); - (*x)[j][1] = static_cast(coords[j * 3 + 1] * gmx::c_bohr2Nm); - (*x)[j][2] = static_cast(coords[j * 3 + 2] * gmx::c_bohr2Nm); + x[j][0] = static_cast(coords[j * 3] * gmx::c_bohr2Nm); + x[j][1] = static_cast(coords[j * 3 + 1] * gmx::c_bohr2Nm); + x[j][2] = static_cast(coords[j * 3 + 2] * gmx::c_bohr2Nm); } } -void gmx::MimicCommunicator::sendEnergies(real energy) +void MimicCommunicator::sendEnergies(real energy) { double convertedEnergy = energy / (gmx::c_hartree2Kj * gmx::c_avogadro); MCL_send(&convertedEnergy, 1, TYPE_DOUBLE, 0); } -void gmx::MimicCommunicator::sendForces(gmx::ArrayRef forces, int natoms) +void MimicCommunicator::sendForces(ArrayRef forces, int natoms) { std::vector convertedForce; for (int j = 0; j < natoms; ++j) @@ -280,9 +232,9 @@ void gmx::MimicCommunicator::sendForces(gmx::ArrayRef forces, int nat MCL_send(&*convertedForce.begin(), convertedForce.size(), TYPE_DOUBLE, 0); } -void gmx::MimicCommunicator::finalize() +void MimicCommunicator::finalize() { MCL_destroy(); } -#pragma GCC diagnostic pop +} // namespace gmx diff --git a/src/gromacs/mimic/communicator.h b/src/gromacs/mimic/communicator.h index 6d2b9c2761..ea7f18b93f 100644 --- a/src/gromacs/mimic/communicator.h +++ b/src/gromacs/mimic/communicator.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 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. @@ -36,14 +36,16 @@ #ifndef GMX_MIMIC_COMMUNICATOR_H #define GMX_MIMIC_COMMUNICATOR_H -#include "gromacs/gpu_utils/hostallocator.h" -#include "gromacs/math/paddedvector.h" #include "gromacs/mdlib/constr.h" #include "gromacs/topology/topology.h" #include "gromacs/utility/futil.h" namespace gmx { + +template +class ArrayRef; + /** * \inlibraryapi * \internal \brief @@ -73,7 +75,7 @@ public: * @param mtop global topology data * @param coords coordinates of all atoms */ - static void sendInitData(gmx_mtop_t* mtop, PaddedHostVector coords); + static void sendInitData(gmx_mtop_t* mtop, ArrayRef coords); /*! \brief * Gets the number of MD steps to perform from MiMiC @@ -88,7 +90,7 @@ public: * @param x array of coordinates to fill * @param natoms number of atoms in the system */ - static void getCoords(PaddedHostVector* x, int natoms); + static void getCoords(ArrayRef x, int natoms); /*! \brief * Send the potential energy value to MiMiC diff --git a/src/gromacs/mimic/communicator_stub.cpp b/src/gromacs/mimic/communicator_stub.cpp new file mode 100644 index 0000000000..c4179425ba --- /dev/null +++ b/src/gromacs/mimic/communicator_stub.cpp @@ -0,0 +1,97 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 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. + * + * 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 + * http://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 http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ +#include "gmxpre.h" + +#include "communicator.h" + +#include "gromacs/math/units.h" +#include "gromacs/utility/arrayref.h" +#include "gromacs/utility/exceptions.h" + +namespace gmx +{ + +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmissing-noreturn" +#endif + +void MimicCommunicator::init() +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +void MimicCommunicator::sendInitData(gmx_mtop_t* /*mtop*/, ArrayRef /*coords*/) +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +int64_t MimicCommunicator::getStepNumber() +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +void MimicCommunicator::getCoords(ArrayRef /*x*/, const int /*natoms*/) +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +void MimicCommunicator::sendEnergies(real /*energy*/) +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +void MimicCommunicator::sendForces(ArrayRef /*forces*/, int /*natoms*/) +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +void MimicCommunicator::finalize() +{ + GMX_THROW(InternalError( + "GROMACS is compiled without MiMiC support! Please, reconfigure with -DGMX_MIMIC=ON")); +} + +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + +} // namespace gmx -- 2.22.0