2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * \brief Declares the force element for the modular simulator
38 * This element calculates the forces, with or without shells or
39 * flexible constraints.
41 * \author Pascal Merz <pascal.merz@me.com>
42 * \ingroup module_modularsimulator
44 * This header is only used within the modular simulator module
47 #ifndef GMX_MODULARSIMULATOR_FORCEELEMENT_H
48 #define GMX_MODULARSIMULATOR_FORCEELEMENT_H
52 #include "gromacs/domdec/dlbtiming.h"
53 #include "gromacs/mdtypes/md_enums.h"
54 #include "gromacs/utility/enumerationhelpers.h"
55 #include "gromacs/utility/real.h"
57 #include "modularsimulatorinterfaces.h"
58 #include "topologyholder.h"
70 class FreeEnergyPerturbationData;
71 class GlobalCommunicationHelper;
73 class LegacySimulatorData;
75 class MdrunScheduleWorkload;
76 class ModularSimulatorAlgorithmBuilderHelper;
77 class ObservablesReducer;
78 class StatePropagatorData;
79 class VirtualSitesHandler;
82 * \ingroup module_modularsimulator
83 * \brief Force element
85 * The force element manages the call to either
86 * do_force(...) or relax_shell_flexcon(...)
88 class ForceElement final :
89 public ISimulatorElement,
90 public ITopologyHolderClient,
91 public INeighborSearchSignallerClient,
92 public IEnergySignallerClient
96 ForceElement(StatePropagatorData* statePropagatorData,
97 EnergyData* energyData,
98 FreeEnergyPerturbationData* freeEnergyPerturbationData,
103 const t_inputrec* inputrec,
104 const MDAtoms* mdAtoms,
107 gmx_wallcycle* wcycle,
108 MdrunScheduleWorkload* runScheduleWork,
109 VirtualSitesHandler* vsite,
110 ImdSession* imdSession,
113 const gmx_mtop_t& globalTopology,
114 gmx_enfrot* enforcedRotation);
116 /*! \brief Register force calculation for step / time
118 * \param step The step number
119 * \param time The time
120 * \param registerRunFunction Function allowing to register a run function
122 void scheduleTask(Step step, Time time, const RegisterRunFunction& registerRunFunction) override;
124 //! Check that we got the local topology
125 void elementSetup() override;
126 //! Print some final output
127 void elementTeardown() override;
129 /*! \brief Factory method implementation
131 * \param legacySimulatorData Pointer allowing access to simulator level data
132 * \param builderHelper ModularSimulatorAlgorithmBuilder helper object
133 * \param statePropagatorData Pointer to the \c StatePropagatorData object
134 * \param energyData Pointer to the \c EnergyData object
135 * \param freeEnergyPerturbationData Pointer to the \c FreeEnergyPerturbationData object
136 * \param globalCommunicationHelper Pointer to the \c GlobalCommunicationHelper object
137 * \param observablesReducer Pointer to the \c ObservablesReducer object
139 * \return Pointer to the element to be added. Element needs to have been stored using \c storeElement
141 static ISimulatorElement* getElementPointerImpl(LegacySimulatorData* legacySimulatorData,
142 ModularSimulatorAlgorithmBuilderHelper* builderHelper,
143 StatePropagatorData* statePropagatorData,
144 EnergyData* energyData,
145 FreeEnergyPerturbationData* freeEnergyPerturbationData,
146 GlobalCommunicationHelper* globalCommunicationHelper,
147 ObservablesReducer* observablesReducer);
150 //! ITopologyHolderClient implementation
151 void setTopology(const gmx_localtop_t* top) override;
152 //! INeighborSearchSignallerClient implementation
153 std::optional<SignallerCallback> registerNSCallback() override;
154 //! IEnergySignallerClient implementation
155 std::optional<SignallerCallback> registerEnergyCallback(EnergySignallerEvent event) override;
156 //! The actual do_force call
157 template<bool doShellFC>
158 void run(Step step, Time time, unsigned int flags);
160 //! The shell / FC helper struct
161 gmx_shellfc_t* shellfc_;
162 //! Whether shells or flexible constraints are present
163 const bool doShellFC_;
167 //! The next energy calculation step
168 Step nextEnergyCalculationStep_;
169 //! The next energy calculation step
170 Step nextVirialCalculationStep_;
171 //! The next free energy calculation step
172 Step nextFreeEnergyCalculationStep_;
174 // TODO: Clarify relationship to data objects and find a more robust alternative to raw pointers (#3583)
175 //! Pointer to the micro state
176 StatePropagatorData* statePropagatorData_;
177 //! Pointer to the energy data
178 EnergyData* energyData_;
179 //! Pointer to the free energy perturbation data
180 FreeEnergyPerturbationData* freeEnergyPerturbationData_;
182 //! The local topology - updated by Topology via Client system
183 const gmx_localtop_t* localTopology_;
185 //! Whether we're having a dynamic box
186 const bool isDynamicBox_;
187 //! Whether we're being verbose
188 const bool isVerbose_;
189 //! The number of shell relaxation steps we did
190 Step nShellRelaxationSteps_;
192 //! DD / DLB helper object
193 const DDBalanceRegionHandler ddBalanceRegionHandler_;
195 /* \brief The FEP lambda vector
197 * Used if FEP is off, since do_force
198 * requires lambda to be allocated anyway
200 gmx::EnumerationArray<FreeEnergyPerturbationType, real> lambda_;
202 // Access to ISimulator data
205 //! Handles communication.
206 const t_commrec* cr_;
207 //! Contains user input mdp options.
208 const t_inputrec* inputrec_;
209 //! Atom parameters for this domain.
210 const MDAtoms* mdAtoms_;
211 //! Manages flop accounting.
213 //! Manages wall cycle accounting.
214 gmx_wallcycle* wcycle_;
215 //! Parameters for force calculations.
217 //! Handles virtual sites.
218 VirtualSitesHandler* vsite_;
219 //! The Interactive Molecular Dynamics session.
220 ImdSession* imdSession_;
221 //! The pull work object.
223 //! Schedule of work for each MD step for this task.
224 MdrunScheduleWorkload* runScheduleWork_;
225 //! Handles constraints.
226 Constraints* constr_;
227 //! Handles enforced rotation.
228 gmx_enfrot* enforcedRotation_;
233 #endif // GMX_MODULARSIMULATOR_FORCEELEMENT_H