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 Defines the state for the modular simulator
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_modularsimulator
44 #include "gromacs/utility/enumerationhelpers.h"
45 #include "statepropagatordata.h"
47 #include "gromacs/commandline/filenm.h"
48 #include "gromacs/domdec/collect.h"
49 #include "gromacs/domdec/domdec.h"
50 #include "gromacs/fileio/confio.h"
51 #include "gromacs/math/vec.h"
52 #include "gromacs/mdlib/gmx_omp_nthreads.h"
53 #include "gromacs/mdlib/mdatoms.h"
54 #include "gromacs/mdlib/mdoutf.h"
55 #include "gromacs/mdlib/stat.h"
56 #include "gromacs/mdlib/update.h"
57 #include "gromacs/mdtypes/checkpointdata.h"
58 #include "gromacs/mdtypes/commrec.h"
59 #include "gromacs/mdtypes/forcebuffers.h"
60 #include "gromacs/mdtypes/forcerec.h"
61 #include "gromacs/mdtypes/inputrec.h"
62 #include "gromacs/mdtypes/mdatom.h"
63 #include "gromacs/mdtypes/mdrunoptions.h"
64 #include "gromacs/mdtypes/state.h"
65 #include "gromacs/pbcutil/pbc.h"
66 #include "gromacs/topology/atoms.h"
67 #include "gromacs/topology/topology.h"
68 #include "gromacs/trajectory/trajectoryframe.h"
70 #include "freeenergyperturbationdata.h"
71 #include "modularsimulator.h"
72 #include "simulatoralgorithm.h"
77 * \brief Helper object to scale velocities according to reference temperature change
79 class StatePropagatorData::ReferenceTemperatureHelper
83 ReferenceTemperatureHelper(const t_inputrec* inputrec,
84 StatePropagatorData* statePropagatorData,
85 const t_mdatoms* mdatoms) :
86 numTemperatureGroups_(inputrec->opts.ngtc),
87 referenceTemperature_(inputrec->opts.ref_t, inputrec->opts.ref_t + inputrec->opts.ngtc),
88 velocityScalingFactors_(numTemperatureGroups_),
89 statePropagatorData_(statePropagatorData),
94 /*! \brief Update the reference temperature
96 * Changing the reference temperature requires scaling the velocities, which
99 * \param temperatures New reference temperatures
100 * \param algorithm The algorithm which initiated the temperature update
102 void updateReferenceTemperature(ArrayRef<const real> temperatures,
103 ReferenceTemperatureChangeAlgorithm gmx_unused algorithm)
105 // Currently, we don't know about any temperature change algorithms, so we assert this never gets called
106 GMX_ASSERT(false, "StatePropagatorData: Unknown ReferenceTemperatureChangeAlgorithm.");
107 for (int temperatureGroup = 0; temperatureGroup < numTemperatureGroups_; ++temperatureGroup)
109 velocityScalingFactors_[temperatureGroup] =
110 std::sqrt(temperatures[temperatureGroup] / referenceTemperature_[temperatureGroup]);
113 auto velocities = statePropagatorData_->velocitiesView().unpaddedArrayRef();
114 int nth = gmx_omp_nthreads_get(ModuleMultiThread::Update);
115 #pragma omp parallel for num_threads(nth) schedule(static) default(none) \
116 shared(nth, velocityScalingFactors_, velocities)
117 for (int threadIndex = 0; threadIndex < nth; threadIndex++)
121 getThreadAtomRange(nth, threadIndex, statePropagatorData_->localNAtoms_, &startAtom, &endAtom);
122 for (int atomIdx = startAtom; atomIdx < endAtom; ++atomIdx)
124 const int temperatureGroup = (mdatoms_->cTC != nullptr) ? mdatoms_->cTC[atomIdx] : 0;
125 velocities[atomIdx] *= velocityScalingFactors_[temperatureGroup];
128 std::copy(temperatures.begin(), temperatures.end(), referenceTemperature_.begin());
132 //! The number of temperature groups
133 const int numTemperatureGroups_;
134 //! Coupling temperature per group
135 std::vector<real> referenceTemperature_;
136 //! Working array used at every temperature update
137 std::vector<real> velocityScalingFactors_;
139 //! Pointer to StatePropagatorData to scale velocities
140 StatePropagatorData* statePropagatorData_;
141 //! Atom parameters for this domain (temperature group information)
142 const t_mdatoms* mdatoms_;
145 StatePropagatorData::StatePropagatorData(int numAtoms,
148 t_state* globalState,
150 bool canMoleculesBeDistributedOverPBC,
151 bool writeFinalConfiguration,
152 const std::string& finalConfigurationFilename,
153 const t_inputrec* inputrec,
154 const t_mdatoms* mdatoms,
155 const gmx_mtop_t& globalTop) :
156 totalNumAtoms_(numAtoms),
159 previousBox_{ { 0 } },
161 element_(std::make_unique<Element>(this,
167 inputrec->nstxout_compressed,
168 canMoleculesBeDistributedOverPBC,
169 writeFinalConfiguration,
170 finalConfigurationFilename,
173 referenceTemperatureHelper_(std::make_unique<ReferenceTemperatureHelper>(inputrec, this, mdatoms)),
174 vvResetVelocities_(false),
175 isRegularSimulationEnd_(false),
177 globalState_(globalState)
179 bool stateHasVelocities;
180 // Local state only becomes valid now.
181 if (DOMAINDECOMP(cr))
183 auto localState = std::make_unique<t_state>();
184 dd_init_local_state(*cr->dd, globalState, localState.get());
185 stateHasVelocities = ((localState->flags & enumValueToBitMask(StateEntry::V)) != 0);
186 setLocalState(std::move(localState));
190 state_change_natoms(globalState, globalState->natoms);
191 f_.resize(globalState->natoms);
192 localNAtoms_ = globalState->natoms;
195 copy_mat(globalState->box, box_);
196 stateHasVelocities = ((globalState->flags & enumValueToBitMask(StateEntry::V)) != 0);
197 previousX_.resizeWithPadding(localNAtoms_);
198 ddpCount_ = globalState->ddp_count;
203 changePinningPolicy(&x_, gmx::PinningPolicy::PinnedIfSupported);
206 if (DOMAINDECOMP(cr) && MASTER(cr))
208 xGlobal_.resizeWithPadding(totalNumAtoms_);
209 previousXGlobal_.resizeWithPadding(totalNumAtoms_);
210 vGlobal_.resizeWithPadding(totalNumAtoms_);
211 fGlobal_.resizeWithPadding(totalNumAtoms_);
214 if (!inputrec->bContinuation)
216 if (stateHasVelocities)
218 auto v = velocitiesView().paddedArrayRef();
219 // Set the velocities of vsites, shells and frozen atoms to zero
220 for (int i = 0; i < mdatoms->homenr; i++)
222 if (mdatoms->ptype[i] == ParticleType::Shell)
226 else if (mdatoms->cFREEZE)
228 for (int m = 0; m < DIM; m++)
230 if (inputrec->opts.nFreeze[mdatoms->cFREEZE[i]][m])
238 if (inputrec->eI == IntegrationAlgorithm::VV)
240 vvResetVelocities_ = true;
245 StatePropagatorData::~StatePropagatorData() = default;
247 StatePropagatorData::Element* StatePropagatorData::element()
249 return element_.get();
252 void StatePropagatorData::setup()
256 element_->elementSetup();
260 ArrayRefWithPadding<RVec> StatePropagatorData::positionsView()
262 return x_.arrayRefWithPadding();
265 ArrayRefWithPadding<const RVec> StatePropagatorData::constPositionsView() const
267 return x_.constArrayRefWithPadding();
270 ArrayRefWithPadding<RVec> StatePropagatorData::previousPositionsView()
272 return previousX_.arrayRefWithPadding();
275 ArrayRefWithPadding<const RVec> StatePropagatorData::constPreviousPositionsView() const
277 return previousX_.constArrayRefWithPadding();
280 ArrayRefWithPadding<RVec> StatePropagatorData::velocitiesView()
282 return v_.arrayRefWithPadding();
285 ArrayRefWithPadding<const RVec> StatePropagatorData::constVelocitiesView() const
287 return v_.constArrayRefWithPadding();
290 ForceBuffersView& StatePropagatorData::forcesView()
295 const ForceBuffersView& StatePropagatorData::constForcesView() const
300 rvec* StatePropagatorData::box()
305 const rvec* StatePropagatorData::constBox() const
310 rvec* StatePropagatorData::previousBox()
315 const rvec* StatePropagatorData::constPreviousBox() const
320 int StatePropagatorData::localNumAtoms() const
325 int StatePropagatorData::totalNumAtoms() const
327 return totalNumAtoms_;
330 std::unique_ptr<t_state> StatePropagatorData::localState()
332 auto state = std::make_unique<t_state>();
333 state->flags = enumValueToBitMask(StateEntry::X) | enumValueToBitMask(StateEntry::V)
334 | enumValueToBitMask(StateEntry::Box);
335 state_change_natoms(state.get(), localNAtoms_);
338 copy_mat(box_, state->box);
339 state->ddp_count = ddpCount_;
340 state->ddp_count_cg_gl = ddpCountCgGl_;
341 state->cg_gl = cgGl_;
345 void StatePropagatorData::setLocalState(std::unique_ptr<t_state> state)
347 localNAtoms_ = state->natoms;
348 x_.resizeWithPadding(localNAtoms_);
349 previousX_.resizeWithPadding(localNAtoms_);
350 v_.resizeWithPadding(localNAtoms_);
353 copy_mat(state->box, box_);
355 ddpCount_ = state->ddp_count;
356 ddpCountCgGl_ = state->ddp_count_cg_gl;
357 cgGl_ = state->cg_gl;
359 if (vvResetVelocities_)
361 /* DomDec runs twice early in the simulation, once at setup time, and once before the first
362 * step. Every time DD runs, it sets a new local state here. We are saving a backup during
363 * setup time (ok for non-DD cases), so we need to update our backup to the DD state before
364 * the first step here to avoid resetting to an earlier DD state. This is done before any
365 * propagation that needs to be reset, so it's not very safe but correct for now.
366 * TODO: Get rid of this once input is assumed to be at half steps
368 velocityBackup_ = v_;
372 t_state* StatePropagatorData::globalState()
377 ForceBuffers* StatePropagatorData::forcePointer()
382 void StatePropagatorData::copyPosition()
384 int nth = gmx_omp_nthreads_get(ModuleMultiThread::Update);
386 #pragma omp parallel for num_threads(nth) schedule(static) default(none) shared(nth)
387 for (int th = 0; th < nth; th++)
389 int start_th, end_th;
390 getThreadAtomRange(nth, th, localNAtoms_, &start_th, &end_th);
391 copyPosition(start_th, end_th);
394 /* Box is changed in update() when we do pressure coupling,
395 * but we should still use the old box for energy corrections and when
396 * writing it to the energy file, so it matches the trajectory files for
397 * the same timestep above. Make a copy in a separate array.
399 copy_mat(box_, previousBox_);
402 void StatePropagatorData::copyPosition(int start, int end)
404 for (int i = start; i < end; ++i)
406 previousX_[i] = x_[i];
410 void StatePropagatorData::updateReferenceTemperature(ArrayRef<const real> temperatures,
411 ReferenceTemperatureChangeAlgorithm algorithm)
413 referenceTemperatureHelper_->updateReferenceTemperature(temperatures, algorithm);
416 void StatePropagatorData::Element::scheduleTask(Step step,
417 Time gmx_unused time,
418 const RegisterRunFunction& registerRunFunction)
420 if (statePropagatorData_->vvResetVelocities_)
422 statePropagatorData_->vvResetVelocities_ = false;
423 registerRunFunction([this]() { statePropagatorData_->resetVelocities(); });
425 // copy x -> previousX
426 registerRunFunction([this]() { statePropagatorData_->copyPosition(); });
427 // if it's a write out step, keep a copy for writeout
428 if (step == writeOutStep_ || (step == lastStep_ && writeFinalConfiguration_))
430 registerRunFunction([this]() { saveState(); });
434 void StatePropagatorData::Element::saveState()
436 GMX_ASSERT(!localStateBackup_, "Save state called again before previous state was written.");
437 localStateBackup_ = statePropagatorData_->localState();
438 if (freeEnergyPerturbationData_)
440 localStateBackup_->fep_state = freeEnergyPerturbationData_->currentFEPState();
441 ArrayRef<const real> lambdaView = freeEnergyPerturbationData_->constLambdaView();
442 std::copy(lambdaView.begin(), lambdaView.end(), localStateBackup_->lambda.begin());
443 localStateBackup_->flags |=
444 enumValueToBitMask(StateEntry::Lambda) | enumValueToBitMask(StateEntry::FepState);
448 std::optional<SignallerCallback> StatePropagatorData::Element::registerTrajectorySignallerCallback(TrajectoryEvent event)
450 if (event == TrajectoryEvent::StateWritingStep)
452 return [this](Step step, Time /*unused*/) { this->writeOutStep_ = step; };
457 std::optional<ITrajectoryWriterCallback>
458 StatePropagatorData::Element::registerTrajectoryWriterCallback(TrajectoryEvent event)
460 if (event == TrajectoryEvent::StateWritingStep)
462 return [this](gmx_mdoutf* outf, Step step, Time time, bool writeTrajectory, bool gmx_unused writeLog) {
465 write(outf, step, time);
472 void StatePropagatorData::Element::write(gmx_mdoutf_t outf, Step currentStep, Time currentTime)
474 wallcycle_start(mdoutf_get_wcycle(outf), WallCycleCounter::Traj);
475 unsigned int mdof_flags = 0;
476 if (do_per_step(currentStep, nstxout_))
478 mdof_flags |= MDOF_X;
480 if (do_per_step(currentStep, nstvout_))
482 mdof_flags |= MDOF_V;
484 if (do_per_step(currentStep, nstfout_))
486 mdof_flags |= MDOF_F;
488 if (do_per_step(currentStep, nstxout_compressed_))
490 mdof_flags |= MDOF_X_COMPRESSED;
492 if (do_per_step(currentStep, mdoutf_get_tng_box_output_interval(outf)))
494 mdof_flags |= MDOF_BOX;
496 if (do_per_step(currentStep, mdoutf_get_tng_lambda_output_interval(outf)))
498 mdof_flags |= MDOF_LAMBDA;
500 if (do_per_step(currentStep, mdoutf_get_tng_compressed_box_output_interval(outf)))
502 mdof_flags |= MDOF_BOX_COMPRESSED;
504 if (do_per_step(currentStep, mdoutf_get_tng_compressed_lambda_output_interval(outf)))
506 mdof_flags |= MDOF_LAMBDA_COMPRESSED;
511 wallcycle_stop(mdoutf_get_wcycle(outf), WallCycleCounter::Traj);
514 GMX_ASSERT(localStateBackup_, "Trajectory writing called, but no state saved.");
516 // TODO: This is only used for CPT - needs to be filled when we turn CPT back on
517 ObservablesHistory* observablesHistory = nullptr;
519 mdoutf_write_to_trajectory_files(fplog_,
522 static_cast<int>(mdof_flags),
523 statePropagatorData_->totalNumAtoms_,
526 localStateBackup_.get(),
527 statePropagatorData_->globalState_,
529 statePropagatorData_->f_.view().force(),
530 &dummyCheckpointDataHolder_);
532 if (currentStep != lastStep_ || !isRegularSimulationEnd_)
534 localStateBackup_.reset();
536 wallcycle_stop(mdoutf_get_wcycle(outf), WallCycleCounter::Traj);
539 void StatePropagatorData::Element::elementSetup()
541 if (statePropagatorData_->vvResetVelocities_)
543 // MD-VV does the first velocity half-step only to calculate the constraint virial,
544 // then resets the velocities since the input is assumed to be positions and velocities
545 // at full time step. TODO: Change this to have input at half time steps.
546 statePropagatorData_->velocityBackup_ = statePropagatorData_->v_;
550 void StatePropagatorData::resetVelocities()
552 v_ = velocityBackup_;
558 * \brief Enum describing the contents StatePropagatorData::Element writes to modular checkpoint
560 * When changing the checkpoint content, add a new element just above Count, and adjust the
561 * checkpoint functionality.
563 enum class CheckpointVersion
565 Base, //!< First version of modular checkpointing
566 Count //!< Number of entries. Add new versions right above this!
568 constexpr auto c_currentVersion = CheckpointVersion(int(CheckpointVersion::Count) - 1);
571 template<CheckpointDataOperation operation>
572 void StatePropagatorData::doCheckpointData(CheckpointData<operation>* checkpointData)
574 checkpointVersion(checkpointData, "StatePropagatorData version", c_currentVersion);
575 checkpointData->scalar("numAtoms", &totalNumAtoms_);
577 if (operation == CheckpointDataOperation::Read)
579 xGlobal_.resizeWithPadding(totalNumAtoms_);
580 vGlobal_.resizeWithPadding(totalNumAtoms_);
583 checkpointData->arrayRef("positions", makeCheckpointArrayRef<operation>(xGlobal_));
584 checkpointData->arrayRef("velocities", makeCheckpointArrayRef<operation>(vGlobal_));
585 checkpointData->tensor("box", box_);
586 checkpointData->scalar("ddpCount", &ddpCount_);
587 checkpointData->scalar("ddpCountCgGl", &ddpCountCgGl_);
588 checkpointData->arrayRef("cgGl", makeCheckpointArrayRef<operation>(cgGl_));
591 void StatePropagatorData::Element::saveCheckpointState(std::optional<WriteCheckpointData> checkpointData,
594 if (DOMAINDECOMP(cr))
596 // Collect state from all ranks into global vectors
597 dd_collect_vec(cr->dd,
598 statePropagatorData_->ddpCount_,
599 statePropagatorData_->ddpCountCgGl_,
600 statePropagatorData_->cgGl_,
601 statePropagatorData_->x_,
602 statePropagatorData_->xGlobal_);
603 dd_collect_vec(cr->dd,
604 statePropagatorData_->ddpCount_,
605 statePropagatorData_->ddpCountCgGl_,
606 statePropagatorData_->cgGl_,
607 statePropagatorData_->v_,
608 statePropagatorData_->vGlobal_);
612 // Everything is local - copy local vectors into global ones
613 statePropagatorData_->xGlobal_.resizeWithPadding(statePropagatorData_->totalNumAtoms());
614 statePropagatorData_->vGlobal_.resizeWithPadding(statePropagatorData_->totalNumAtoms());
615 std::copy(statePropagatorData_->x_.begin(),
616 statePropagatorData_->x_.end(),
617 statePropagatorData_->xGlobal_.begin());
618 std::copy(statePropagatorData_->v_.begin(),
619 statePropagatorData_->v_.end(),
620 statePropagatorData_->vGlobal_.begin());
624 statePropagatorData_->doCheckpointData<CheckpointDataOperation::Write>(&checkpointData.value());
629 * \brief Update the legacy global state
631 * When restoring from checkpoint, data will be distributed during domain decomposition at setup stage.
632 * Domain decomposition still uses the legacy global t_state object so make sure it's up-to-date.
634 static void updateGlobalState(t_state* globalState,
635 const PaddedHostVector<RVec>& x,
636 const PaddedHostVector<RVec>& v,
640 const std::vector<int>& cgGl)
644 copy_mat(box, globalState->box);
645 globalState->ddp_count = ddpCount;
646 globalState->ddp_count_cg_gl = ddpCountCgGl;
647 globalState->cg_gl = cgGl;
650 void StatePropagatorData::Element::restoreCheckpointState(std::optional<ReadCheckpointData> checkpointData,
655 statePropagatorData_->doCheckpointData<CheckpointDataOperation::Read>(&checkpointData.value());
658 // Copy data to global state to be distributed by DD at setup stage
659 if (DOMAINDECOMP(cr) && MASTER(cr))
661 updateGlobalState(statePropagatorData_->globalState_,
662 statePropagatorData_->xGlobal_,
663 statePropagatorData_->vGlobal_,
664 statePropagatorData_->box_,
665 statePropagatorData_->ddpCount_,
666 statePropagatorData_->ddpCountCgGl_,
667 statePropagatorData_->cgGl_);
669 // Everything is local - copy global vectors to local ones
670 if (!DOMAINDECOMP(cr))
672 statePropagatorData_->x_.resizeWithPadding(statePropagatorData_->totalNumAtoms_);
673 statePropagatorData_->v_.resizeWithPadding(statePropagatorData_->totalNumAtoms_);
674 std::copy(statePropagatorData_->xGlobal_.begin(),
675 statePropagatorData_->xGlobal_.end(),
676 statePropagatorData_->x_.begin());
677 std::copy(statePropagatorData_->vGlobal_.begin(),
678 statePropagatorData_->vGlobal_.end(),
679 statePropagatorData_->v_.begin());
683 const std::string& StatePropagatorData::Element::clientID()
685 return StatePropagatorData::checkpointID();
688 void StatePropagatorData::Element::trajectoryWriterTeardown(gmx_mdoutf* gmx_unused outf)
690 // Note that part of this code is duplicated in do_md_trajectory_writing.
691 // This duplication is needed while both legacy and modular code paths are in use.
692 // TODO: Remove duplication asap, make sure to keep in sync in the meantime.
693 if (!writeFinalConfiguration_ || !isRegularSimulationEnd_)
698 GMX_ASSERT(localStateBackup_, "Final trajectory writing called, but no state saved.");
700 wallcycle_start(mdoutf_get_wcycle(outf), WallCycleCounter::Traj);
701 if (DOMAINDECOMP(cr_))
704 MASTER(cr_) ? statePropagatorData_->globalState_->x : gmx::ArrayRef<gmx::RVec>();
705 dd_collect_vec(cr_->dd,
706 localStateBackup_->ddp_count,
707 localStateBackup_->ddp_count_cg_gl,
708 localStateBackup_->cg_gl,
709 localStateBackup_->x,
712 MASTER(cr_) ? statePropagatorData_->globalState_->v : gmx::ArrayRef<gmx::RVec>();
713 dd_collect_vec(cr_->dd,
714 localStateBackup_->ddp_count,
715 localStateBackup_->ddp_count_cg_gl,
716 localStateBackup_->cg_gl,
717 localStateBackup_->v,
722 // We have the whole state locally: copy the local state pointer
723 statePropagatorData_->globalState_ = localStateBackup_.get();
728 fprintf(stderr, "\nWriting final coordinates.\n");
729 if (canMoleculesBeDistributedOverPBC_ && !systemHasPeriodicMolecules_)
731 // Make molecules whole only for confout writing
732 do_pbc_mtop(pbcType_,
733 localStateBackup_->box,
735 statePropagatorData_->globalState_->x.rvec_array());
737 write_sto_conf_mtop(finalConfigurationFilename_.c_str(),
740 statePropagatorData_->globalState_->x.rvec_array(),
741 statePropagatorData_->globalState_->v.rvec_array(),
743 localStateBackup_->box);
745 wallcycle_stop(mdoutf_get_wcycle(outf), WallCycleCounter::Traj);
748 std::optional<SignallerCallback> StatePropagatorData::Element::registerLastStepCallback()
750 return [this](Step step, Time /*time*/) {
752 isRegularSimulationEnd_ = (step == lastPlannedStep_);
756 StatePropagatorData::Element::Element(StatePropagatorData* statePropagatorData,
762 int nstxout_compressed,
763 bool canMoleculesBeDistributedOverPBC,
764 bool writeFinalConfiguration,
765 std::string finalConfigurationFilename,
766 const t_inputrec* inputrec,
767 const gmx_mtop_t& globalTop) :
768 statePropagatorData_(statePropagatorData),
772 nstxout_compressed_(nstxout_compressed),
774 freeEnergyPerturbationData_(nullptr),
775 isRegularSimulationEnd_(false),
777 canMoleculesBeDistributedOverPBC_(canMoleculesBeDistributedOverPBC),
778 systemHasPeriodicMolecules_(inputrec->bPeriodicMols),
779 pbcType_(inputrec->pbcType),
780 lastPlannedStep_(inputrec->nsteps + inputrec->init_step),
781 writeFinalConfiguration_(writeFinalConfiguration),
782 finalConfigurationFilename_(std::move(finalConfigurationFilename)),
785 top_global_(globalTop)
788 void StatePropagatorData::Element::setFreeEnergyPerturbationData(FreeEnergyPerturbationData* freeEnergyPerturbationData)
790 freeEnergyPerturbationData_ = freeEnergyPerturbationData;
793 ISimulatorElement* StatePropagatorData::Element::getElementPointerImpl(
794 LegacySimulatorData gmx_unused* legacySimulatorData,
795 ModularSimulatorAlgorithmBuilderHelper gmx_unused* builderHelper,
796 StatePropagatorData* statePropagatorData,
797 EnergyData gmx_unused* energyData,
798 FreeEnergyPerturbationData* freeEnergyPerturbationData,
799 GlobalCommunicationHelper gmx_unused* globalCommunicationHelper)
801 statePropagatorData->element()->setFreeEnergyPerturbationData(freeEnergyPerturbationData);
802 return statePropagatorData->element();
805 void StatePropagatorData::readCheckpointToTrxFrame(t_trxframe* trxFrame, ReadCheckpointData readCheckpointData)
807 StatePropagatorData statePropagatorData;
808 statePropagatorData.doCheckpointData(&readCheckpointData);
810 trxFrame->natoms = statePropagatorData.totalNumAtoms_;
812 trxFrame->x = makeRvecArray(statePropagatorData.xGlobal_, statePropagatorData.totalNumAtoms_);
814 trxFrame->v = makeRvecArray(statePropagatorData.vGlobal_, statePropagatorData.totalNumAtoms_);
815 trxFrame->bF = false;
816 trxFrame->bBox = true;
817 copy_mat(statePropagatorData.box_, trxFrame->box);
820 const std::string& StatePropagatorData::checkpointID()
822 static const std::string identifier = "StatePropagatorData";