From c22df207d938a4506bf443b94c3bb61a09251f42 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Wed, 11 Sep 2024 17:02:57 +0100 Subject: [PATCH 01/13] drivenMD initial set up --- src/module/module.cpp | 1 + src/module/types.h | 1 + src/modules/drivenMD/CMakeLists.txt | 1 + src/modules/drivenMD/drivenMD.cpp | 34 +++++++++ src/modules/drivenMD/drivenMD.h | 71 +++++++++++++++++ src/modules/drivenMD/functions.cpp | 9 +++ src/modules/drivenMD/process.cpp | 113 ++++++++++++++++++++++++++++ src/modules/registry.cpp | 2 + 8 files changed, 232 insertions(+) create mode 100644 src/modules/drivenMD/CMakeLists.txt create mode 100644 src/modules/drivenMD/drivenMD.cpp create mode 100644 src/modules/drivenMD/drivenMD.h create mode 100644 src/modules/drivenMD/functions.cpp create mode 100644 src/modules/drivenMD/process.cpp diff --git a/src/module/module.cpp b/src/module/module.cpp index d4953db1cd..387cda17b2 100644 --- a/src/module/module.cpp +++ b/src/module/module.cpp @@ -26,6 +26,7 @@ EnumOptions moduleTypes_("ModuleType", {{ModuleTypes::A {ModuleTypes::Compare, "Compare"}, {ModuleTypes::DAngle, "DAngle"}, {ModuleTypes::DataTest, "DataTest"}, + {ModuleTypes::DrivenMD, "DrivenMD"}, {ModuleTypes::Energy, "Energy"}, {ModuleTypes::EPSR, "EPSR"}, {ModuleTypes::EPSRManager, "EPSRManager"}, diff --git a/src/module/types.h b/src/module/types.h index 2ce1d453b6..8c1a4c9c0f 100644 --- a/src/module/types.h +++ b/src/module/types.h @@ -20,6 +20,7 @@ enum ModuleType Compare, DAngle, DataTest, + DrivenMD, Energy, EPSR, EPSRManager, diff --git a/src/modules/drivenMD/CMakeLists.txt b/src/modules/drivenMD/CMakeLists.txt new file mode 100644 index 0000000000..ad792d62d1 --- /dev/null +++ b/src/modules/drivenMD/CMakeLists.txt @@ -0,0 +1 @@ +dissolve_add_module(drivenMD.h drivenMD) diff --git a/src/modules/drivenMD/drivenMD.cpp b/src/modules/drivenMD/drivenMD.cpp new file mode 100644 index 0000000000..90d59cd9fc --- /dev/null +++ b/src/modules/drivenMD/drivenMD.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#include "modules/drivenMD/drivenMD.h" +#include "keywords/bool.h" +#include "keywords/double.h" +#include "keywords/moduleVector.h" +#include "keywords/optionalDouble.h" +#include "keywords/optionalInt.h" +#include "keywords/rangeVector.h" +#include "keywords/stdString.h" +#include "keywords/weightedModuleVector.h" + +DrivenMDModule::DrivenMDModule() : Module(ModuleTypes::DrivenMD) +{ + keywords_.addTarget("Target", "Add specified Module (and it's Reference data) as a refinement target", + targets_, + std::vector{ModuleTypes::NeutronSQ, ModuleTypes::XRaySQ}); + keywords_.addTarget( + "TargetWeight", "Set relative weighting for specific module targets as they enter into the scattering matrix", + targetWeights_, std::vector{ModuleTypes::NeutronSQ, ModuleTypes::XRaySQ}); + + keywords_.setOrganisation("Options", "Control"); + keywords_.add("ModifyPotential", + "Frequency at which to apply generated perturbations to interatomic potentials", + modifyPotential_, 0, std::nullopt, 1, "Off"); + keywords_.setOrganisation( + "Advanced", "Additional R-Factors", + "Specify additional Q-ranges over which to calculate R-factors in addition to that over the whole Q-range."); + keywords_.add("RFactorRanges", "Ranges over which to calculate RFactors", ranges_); +} + +// Set whether to apply this module's generated potentials to the global pair potentials +void DrivenMDModule::setApplyPotentials(bool b) { applyPotentials_ = b; } diff --git a/src/modules/drivenMD/drivenMD.h b/src/modules/drivenMD/drivenMD.h new file mode 100644 index 0000000000..00bf1468f4 --- /dev/null +++ b/src/modules/drivenMD/drivenMD.h @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#pragma once + +#include "base/enumOptions.h" +#include "classes/scatteringMatrix.h" +#include "math/data1D.h" +#include "math/range.h" +#include "module/groups.h" +#include "module/module.h" +#include "templates/array3D.h" +#include + +// Forward Declarations +class AtomType; +class PartialSet; + +// SAXSDrivenMD Module +class DrivenMDModule : public Module +{ + public: + DrivenMDModule(); + ~DrivenMDModule() override = default; + + /* + * Definition + */ + public: + private: + // Vector storing atom pairs and associated potentials + std::vector, std::shared_ptr, Data1D>> empiricalPotentials_; + // Frequency at which to apply generated perturbations to interatomic potentials + std::optional modifyPotential_{1}; + // Whether to apply this module's generated potentials to the global pair potentials + bool applyPotentials_{true}; + // Target Modules containing data to refine against + std::vector targets_; + // Weightings for targets (if not 1.0) + std::vector> targetWeights_; + // Ranges to calculate rFactor over + std::vector ranges_; + // Scattering matrix + ScatteringMatrix scatteringMatrix_; + + public: + // Return list of target Modules / data for refinement + const std::vector &targets() const; + // Return current scattering matrix + const ScatteringMatrix &scatteringMatrix() const; + // Set whether to apply this module's generated potentials to the global pair potentials + void setApplyPotentials(bool b); + + /* + * Functions + */ + private: + // Target Configuration (determined from target modules) + Configuration *targetConfiguration_{nullptr}; + + /* + * Processing + */ + private: + // Run main processing + Module::ExecutionResult process(ModuleContext &moduleContext) override; + + public: + // Run set-up stage + bool setUp(ModuleContext &moduleContext, Flags actionSignals) override; +}; diff --git a/src/modules/drivenMD/functions.cpp b/src/modules/drivenMD/functions.cpp new file mode 100644 index 0000000000..0f8def6250 --- /dev/null +++ b/src/modules/drivenMD/functions.cpp @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#include "main/dissolve.h" +#include "math/gaussFit.h" +#include "math/poissonFit.h" +#include "module/context.h" +#include "modules/drivenMD/drivenMD.h" +#include "templates/algorithms.h" diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp new file mode 100644 index 0000000000..b1e993bdec --- /dev/null +++ b/src/modules/drivenMD/process.cpp @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#include "base/sysFunc.h" +#include "classes/neutronWeights.h" +#include "classes/partialSet.h" +#include "classes/scatteringMatrix.h" +#include "classes/xRayWeights.h" +#include "io/export/data1D.h" +#include "keywords/module.h" +#include "main/dissolve.h" +#include "math/error.h" +#include "math/filters.h" +#include "math/ft.h" +#include "math/gaussFit.h" +#include "math/poissonFit.h" +#include "module/context.h" +#include "module/group.h" +#include "modules/drivenMD/drivenMD.h" +#include "modules/energy/energy.h" +#include "modules/gr/gr.h" +#include "modules/neutronSQ/neutronSQ.h" +#include "modules/sq/sq.h" +#include "templates/algorithms.h" +#include "templates/array3D.h" +#include + +// Run set-up stage +bool DrivenMDModule::setUp(ModuleContext &moduleContext, Flags actionSignals) +{ + // Default to applying generated potentials - an associated EPSRManager may turn this off in its own setup stage + applyPotentials_ = true; + + // Check for exactly one Configuration referenced through target modules + targetConfiguration_ = nullptr; + std::optional rho; + for (auto *module : targets_) + { + // Retrieve source SQ module, and then the related RDF module + auto optSQModule = module->keywords().get>("SourceSQs"); + const SQModule *sqModule = nullptr; + if (optSQModule) + sqModule = optSQModule.value(); + if (!sqModule) + return Messenger::error( + "[SETUP {}] Target '{}' doesn't source any S(Q) data, so it can't be used as a target for the EPSR module.", + name_, module->name()); + + auto *grModule = sqModule->sourceGR(); + if (!grModule) + return Messenger::error( + "[SETUP {}] Target '{}'s S(Q) module doesn't reference a GRModule, it can't be used as a target " + "for the EPSR module.", + name_, module->name()); + // Check for number of targets, or different target if there's only 1 + auto rdfConfigs = grModule->keywords().getVectorConfiguration("Configurations"); + if (rdfConfigs.size() != 1) + return Messenger::error( + "[SETUP {}] GR module '{}' targets multiple configurations, which is not permitted when using " + "its data in the EPSR module.", + name_, grModule->name()); + + if ((targetConfiguration_ != nullptr) && (targetConfiguration_ != rdfConfigs.front())) + return Messenger::error("[SETUP {}] GR module '{}' targets a configuration which is different from another target " + "module, and which is not permitted when using its data in the EPSR module.", + name_, grModule->name()); + + else + targetConfiguration_ = rdfConfigs.front(); + + rho = targetConfiguration_->atomicDensity(); + } + + // Realise storage for generated S(Q), and initialise a scattering matrix, but only if we have a valid configuration + if (targetConfiguration_) + { + auto &estimatedSQ = moduleContext.dissolve().processingModuleData().realise>( + "EstimatedSQ", name_, GenericItem::InRestartFileFlag); + scatteringMatrix_.initialise(targetConfiguration_->atomTypes(), estimatedSQ); + } + + return true; +} + +// Run main processing +Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) +{ + std::string testDataName; + + /* + * Do we have targets to refine against? + */ + if (targets_.empty()) + { + Messenger::error("At least one Module target containing suitable data must be provided.\n"); + return ExecutionResult::Failed; + } + + if (!targetConfiguration_) + { + Messenger::error("No target configuration is set.\n"); + return ExecutionResult::Failed; + } + + if (!targetConfiguration_->atomicDensity()) + { + Messenger::error("No density available for target configuration '{}'\n", targetConfiguration_->name()); + return ExecutionResult::Failed; + } + auto rho = *targetConfiguration_->atomicDensity(); + + return ExecutionResult::Success; +} diff --git a/src/modules/registry.cpp b/src/modules/registry.cpp index 4739903a38..46d2d51858 100644 --- a/src/modules/registry.cpp +++ b/src/modules/registry.cpp @@ -11,6 +11,7 @@ #include "modules/bragg/bragg.h" #include "modules/compare/compare.h" #include "modules/dAngle/dAngle.h" +#include "modules/drivenMD/drivenMD.h" #include "modules/energy/energy.h" #include "modules/epsr/epsr.h" #include "modules/epsrManager/epsrManager.h" @@ -53,6 +54,7 @@ ModuleRegistry::ModuleRegistry() registerProducer(ModuleTypes::Bragg, "Calculate Bragg intensities", "Correlation Functions"); registerProducer(ModuleTypes::Compare, "Compare data sets and calculate errors", "Checks & Tests"); registerProducer(ModuleTypes::DAngle, "Calculate distance/angle maps", "Analysis"); + registerProducer(ModuleTypes::DrivenMD, "SAXS/SAND driven molecular dynamics test", "Forcefield"); registerProducer(ModuleTypes::Energy, "Calculate the total energy of a Configuration", "Forcefield"); registerProducer(ModuleTypes::EPSR, "Refine interatomic potentials in a manner consistent with EPSR", "Forcefield"); From ecec7342a54719c77d0a377b7db6fc691be50505 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 19 Sep 2024 09:55:38 +0100 Subject: [PATCH 02/13] added drivenMD functionality --- src/modules/drivenMD/drivenMD.cpp | 26 +---- src/modules/drivenMD/drivenMD.h | 25 +---- src/modules/drivenMD/functions.cpp | 19 +++- src/modules/drivenMD/process.cpp | 170 ++++++++++++++--------------- src/modules/registry.cpp | 2 +- 5 files changed, 109 insertions(+), 133 deletions(-) diff --git a/src/modules/drivenMD/drivenMD.cpp b/src/modules/drivenMD/drivenMD.cpp index 90d59cd9fc..015122eac4 100644 --- a/src/modules/drivenMD/drivenMD.cpp +++ b/src/modules/drivenMD/drivenMD.cpp @@ -2,33 +2,17 @@ // Copyright (c) 2024 Team Dissolve and contributors #include "modules/drivenMD/drivenMD.h" -#include "keywords/bool.h" -#include "keywords/double.h" +#include "keywords/configuration.h" +#include "keywords/fileAndFormat.h" #include "keywords/moduleVector.h" -#include "keywords/optionalDouble.h" -#include "keywords/optionalInt.h" -#include "keywords/rangeVector.h" -#include "keywords/stdString.h" +#include "keywords/speciesSiteVector.h" #include "keywords/weightedModuleVector.h" DrivenMDModule::DrivenMDModule() : Module(ModuleTypes::DrivenMD) { + keywords_.addTarget("Configuration", "Set target configuration for the module", targetConfiguration_) + ->setEditSignals({KeywordBase::ClearModuleData, KeywordBase::RecreateRenderables}); keywords_.addTarget("Target", "Add specified Module (and it's Reference data) as a refinement target", targets_, std::vector{ModuleTypes::NeutronSQ, ModuleTypes::XRaySQ}); - keywords_.addTarget( - "TargetWeight", "Set relative weighting for specific module targets as they enter into the scattering matrix", - targetWeights_, std::vector{ModuleTypes::NeutronSQ, ModuleTypes::XRaySQ}); - - keywords_.setOrganisation("Options", "Control"); - keywords_.add("ModifyPotential", - "Frequency at which to apply generated perturbations to interatomic potentials", - modifyPotential_, 0, std::nullopt, 1, "Off"); - keywords_.setOrganisation( - "Advanced", "Additional R-Factors", - "Specify additional Q-ranges over which to calculate R-factors in addition to that over the whole Q-range."); - keywords_.add("RFactorRanges", "Ranges over which to calculate RFactors", ranges_); } - -// Set whether to apply this module's generated potentials to the global pair potentials -void DrivenMDModule::setApplyPotentials(bool b) { applyPotentials_ = b; } diff --git a/src/modules/drivenMD/drivenMD.h b/src/modules/drivenMD/drivenMD.h index 00bf1468f4..d0079b6aaa 100644 --- a/src/modules/drivenMD/drivenMD.h +++ b/src/modules/drivenMD/drivenMD.h @@ -12,11 +12,7 @@ #include "templates/array3D.h" #include -// Forward Declarations -class AtomType; -class PartialSet; - -// SAXSDrivenMD Module +// DrivenMD Module class DrivenMDModule : public Module { public: @@ -30,24 +26,12 @@ class DrivenMDModule : public Module private: // Vector storing atom pairs and associated potentials std::vector, std::shared_ptr, Data1D>> empiricalPotentials_; - // Frequency at which to apply generated perturbations to interatomic potentials - std::optional modifyPotential_{1}; - // Whether to apply this module's generated potentials to the global pair potentials - bool applyPotentials_{true}; // Target Modules containing data to refine against std::vector targets_; - // Weightings for targets (if not 1.0) - std::vector> targetWeights_; - // Ranges to calculate rFactor over - std::vector ranges_; - // Scattering matrix - ScatteringMatrix scatteringMatrix_; public: // Return list of target Modules / data for refinement const std::vector &targets() const; - // Return current scattering matrix - const ScatteringMatrix &scatteringMatrix() const; // Set whether to apply this module's generated potentials to the global pair potentials void setApplyPotentials(bool b); @@ -57,15 +41,12 @@ class DrivenMDModule : public Module private: // Target Configuration (determined from target modules) Configuration *targetConfiguration_{nullptr}; - + // Calculate partial g(r) in serial with simple double-loop + PartialSet calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet); /* * Processing */ private: // Run main processing Module::ExecutionResult process(ModuleContext &moduleContext) override; - - public: - // Run set-up stage - bool setUp(ModuleContext &moduleContext, Flags actionSignals) override; }; diff --git a/src/modules/drivenMD/functions.cpp b/src/modules/drivenMD/functions.cpp index 0f8def6250..ea03ee975e 100644 --- a/src/modules/drivenMD/functions.cpp +++ b/src/modules/drivenMD/functions.cpp @@ -2,8 +2,23 @@ // Copyright (c) 2024 Team Dissolve and contributors #include "main/dissolve.h" -#include "math/gaussFit.h" -#include "math/poissonFit.h" #include "module/context.h" #include "modules/drivenMD/drivenMD.h" #include "templates/algorithms.h" + +// Calculate partial g(r) in serial with simple double-loop +PartialSet DrivenMDModule::calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet) +{ + // Calculate radial distribution functions with a simple double loop, in serial then return the partial set!!!!!!! + const auto *box = cfg->box(); + + dissolve::for_each_pair( + ParallelPolicies::seq, cfg->atoms().begin(), cfg->atoms().end(), + [box, &partialSet](auto i, auto &ii, auto j, auto &jj) + { + if (&ii != &jj) + partialSet.fullHistogram(ii.localTypeIndex(), jj.localTypeIndex()).bin(box->minimumDistance(ii.r(), jj.r())); + }); + + return partialSet; +} \ No newline at end of file diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index b1e993bdec..a2a696e680 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -2,112 +2,108 @@ // Copyright (c) 2024 Team Dissolve and contributors #include "base/sysFunc.h" -#include "classes/neutronWeights.h" -#include "classes/partialSet.h" -#include "classes/scatteringMatrix.h" -#include "classes/xRayWeights.h" -#include "io/export/data1D.h" #include "keywords/module.h" #include "main/dissolve.h" -#include "math/error.h" -#include "math/filters.h" #include "math/ft.h" -#include "math/gaussFit.h" -#include "math/poissonFit.h" #include "module/context.h" #include "module/group.h" #include "modules/drivenMD/drivenMD.h" -#include "modules/energy/energy.h" #include "modules/gr/gr.h" -#include "modules/neutronSQ/neutronSQ.h" -#include "modules/sq/sq.h" -#include "templates/algorithms.h" -#include "templates/array3D.h" #include -// Run set-up stage -bool DrivenMDModule::setUp(ModuleContext &moduleContext, Flags actionSignals) -{ - // Default to applying generated potentials - an associated EPSRManager may turn this off in its own setup stage - applyPotentials_ = true; - - // Check for exactly one Configuration referenced through target modules - targetConfiguration_ = nullptr; - std::optional rho; - for (auto *module : targets_) - { - // Retrieve source SQ module, and then the related RDF module - auto optSQModule = module->keywords().get>("SourceSQs"); - const SQModule *sqModule = nullptr; - if (optSQModule) - sqModule = optSQModule.value(); - if (!sqModule) - return Messenger::error( - "[SETUP {}] Target '{}' doesn't source any S(Q) data, so it can't be used as a target for the EPSR module.", - name_, module->name()); - - auto *grModule = sqModule->sourceGR(); - if (!grModule) - return Messenger::error( - "[SETUP {}] Target '{}'s S(Q) module doesn't reference a GRModule, it can't be used as a target " - "for the EPSR module.", - name_, module->name()); - // Check for number of targets, or different target if there's only 1 - auto rdfConfigs = grModule->keywords().getVectorConfiguration("Configurations"); - if (rdfConfigs.size() != 1) - return Messenger::error( - "[SETUP {}] GR module '{}' targets multiple configurations, which is not permitted when using " - "its data in the EPSR module.", - name_, grModule->name()); - - if ((targetConfiguration_ != nullptr) && (targetConfiguration_ != rdfConfigs.front())) - return Messenger::error("[SETUP {}] GR module '{}' targets a configuration which is different from another target " - "module, and which is not permitted when using its data in the EPSR module.", - name_, grModule->name()); - - else - targetConfiguration_ = rdfConfigs.front(); - - rho = targetConfiguration_->atomicDensity(); - } - - // Realise storage for generated S(Q), and initialise a scattering matrix, but only if we have a valid configuration - if (targetConfiguration_) - { - auto &estimatedSQ = moduleContext.dissolve().processingModuleData().realise>( - "EstimatedSQ", name_, GenericItem::InRestartFileFlag); - scatteringMatrix_.initialise(targetConfiguration_->atomTypes(), estimatedSQ); - } - - return true; -} - // Run main processing Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) { - std::string testDataName; + auto &processingData = moduleContext.dissolve().processingModuleData(); /* - * Do we have targets to refine against? + * 1) Loop over a site + * 2) Move in the x, y and z direction + * 3) Calculate gr at each step + * 4) FT gr-1 to F(Q) and weight by scattering length + * 5) Take the negative gradient of the difference between the gr and the F(Q) which corresponds to the derived force + * that we then apply to MD simulation */ - if (targets_.empty()) - { - Messenger::error("At least one Module target containing suitable data must be provided.\n"); - return ExecutionResult::Failed; - } - if (!targetConfiguration_) - { - Messenger::error("No target configuration is set.\n"); - return ExecutionResult::Failed; - } + std::vector forces; + PartialSet totalGR; + PartialSet referenceData; + + // Does a PartialSet already exist for this Configuration? + auto originalGRObject = processingData.realiseIf( + fmt::format("{}//OriginalGR", targetConfiguration_->niceName()), name_, GenericItem::InRestartFileFlag); + auto &originalgr = originalGRObject.first; + double delta{0.1}; + auto atoms = targetConfiguration_->atoms(); + forces.resize(atoms.size()); - if (!targetConfiguration_->atomicDensity()) + for (auto &i : atoms) { - Messenger::error("No density available for target configuration '{}'\n", targetConfiguration_->name()); - return ExecutionResult::Failed; + for (auto n = 0; n < 3; ++n) + { + double newPosition{}; + switch (n) + { + // Move x + case 1: + // Get position, change via delta then set + newPosition = i.x() - delta; + i.set(newPosition, i.y(), i.z()); + // Calculate GR + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + // FT to structure factor + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // Store Error here + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.x() + (2 * delta); + i.set(newPosition, i.y(), i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // Store Error here + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + // Reset position + newPosition = i.x() - delta; + i.set(newPosition, i.y(), i.z()); + break; + // Move y + case 2: + newPosition = i.y() - delta; + i.set(i.x(), newPosition, i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.y() + (2 * delta); + i.set(i.x(), newPosition, i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.y() - delta; + i.set(i.x(), newPosition, i.z()); + break; + // Move z + case 3: + newPosition = i.z() - delta; + i.set(i.x(), i.y(), newPosition); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.z() + (2 * delta); + i.set(i.x(), i.y(), newPosition); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.z() - delta; + i.set(i.x(), i.y(), newPosition); + break; + } + } } - auto rho = *targetConfiguration_->atomicDensity(); return ExecutionResult::Success; } diff --git a/src/modules/registry.cpp b/src/modules/registry.cpp index 46d2d51858..9916cc74a5 100644 --- a/src/modules/registry.cpp +++ b/src/modules/registry.cpp @@ -54,7 +54,7 @@ ModuleRegistry::ModuleRegistry() registerProducer(ModuleTypes::Bragg, "Calculate Bragg intensities", "Correlation Functions"); registerProducer(ModuleTypes::Compare, "Compare data sets and calculate errors", "Checks & Tests"); registerProducer(ModuleTypes::DAngle, "Calculate distance/angle maps", "Analysis"); - registerProducer(ModuleTypes::DrivenMD, "SAXS/SAND driven molecular dynamics test", "Forcefield"); + registerProducer(ModuleTypes::DrivenMD, "SAXS/SANS driven molecular dynamics test", "Forcefield"); registerProducer(ModuleTypes::Energy, "Calculate the total energy of a Configuration", "Forcefield"); registerProducer(ModuleTypes::EPSR, "Refine interatomic potentials in a manner consistent with EPSR", "Forcefield"); From 8ac8e88575fa1660ca9b4c578c82fb2cbd8d12ac Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Fri, 20 Sep 2024 14:39:19 +0100 Subject: [PATCH 03/13] added gui file in --- src/modules/drivenMD/gui/CMakeLists.txt | 1 + src/modules/drivenMD/gui/drivenMDFuncs.cpp | 15 ++++++ src/modules/drivenMD/gui/epsrManagerWidget.h | 34 ++++++++++++++ src/modules/drivenMD/gui/epsrManagerWidget.ui | 47 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/modules/drivenMD/gui/CMakeLists.txt create mode 100644 src/modules/drivenMD/gui/drivenMDFuncs.cpp create mode 100644 src/modules/drivenMD/gui/epsrManagerWidget.h create mode 100644 src/modules/drivenMD/gui/epsrManagerWidget.ui diff --git a/src/modules/drivenMD/gui/CMakeLists.txt b/src/modules/drivenMD/gui/CMakeLists.txt new file mode 100644 index 0000000000..96a541db4b --- /dev/null +++ b/src/modules/drivenMD/gui/CMakeLists.txt @@ -0,0 +1 @@ +dissolve_add_module_gui(drivenMD) diff --git a/src/modules/drivenMD/gui/drivenMDFuncs.cpp b/src/modules/drivenMD/gui/drivenMDFuncs.cpp new file mode 100644 index 0000000000..43af1ccf17 --- /dev/null +++ b/src/modules/drivenMD/gui/drivenMDFuncs.cpp @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#include "main/dissolve.h" +#include "modules/drivenMD/drivenMD.h" +#include "modules/drivenMD/gui/epsrManagerWidget.h" + +DrivenMDModuleWidget::DrivenMDModuleWidget(QWidget *parent, DrivenMDModule *module, Dissolve &dissolve) + : ModuleWidget(parent, dissolve), module_(module) +{ + // Set up user interface + ui_.setupUi(this); + + refreshing_ = false; +} diff --git a/src/modules/drivenMD/gui/epsrManagerWidget.h b/src/modules/drivenMD/gui/epsrManagerWidget.h new file mode 100644 index 0000000000..44d03e2c73 --- /dev/null +++ b/src/modules/drivenMD/gui/epsrManagerWidget.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#pragma once + +#include "modules/drivenMD/gui/ui_drivenMDWidget.h" +#include "modules/widget.h" + +// Forward Declarations +class DrivenMDModule; +class Dissolve; +class Module; + +// Module Widget +class DrivenMDModuleWidget : public ModuleWidget +{ + // All Qt declarations derived from QObject must include this macro + Q_OBJECT + + public: + DrivenMDModuleWidget(QWidget *parent, DrivenMDModule *module, Dissolve &dissolve); + ~DrivenMDModuleWidget() override = default; + + private: + // Associated Module + DrivenMDModule *module_; + + /* + * UI + */ + private: + // Main form declaration + Ui::DrivenMDModuleWidget ui_; +}; diff --git a/src/modules/drivenMD/gui/epsrManagerWidget.ui b/src/modules/drivenMD/gui/epsrManagerWidget.ui new file mode 100644 index 0000000000..159430921f --- /dev/null +++ b/src/modules/drivenMD/gui/epsrManagerWidget.ui @@ -0,0 +1,47 @@ + + + DrivenMDModuleWidget + + + + 0 + 0 + 473 + 395 + + + + + 0 + 0 + + + + + 8 + + + + AnalyseModule Controls + + + + 4 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + From ce48ab5476da6a82ed7da7cef9360e6f229ebbab Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Sat, 21 Sep 2024 11:50:09 +0100 Subject: [PATCH 04/13] updated gui files --- src/modules/drivenMD/gui/drivenMDFuncs.cpp | 2 +- .../drivenMD/gui/{epsrManagerWidget.h => drivenMDWidget.h} | 0 .../drivenMD/gui/{epsrManagerWidget.ui => drivenMDWidget.ui} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename src/modules/drivenMD/gui/{epsrManagerWidget.h => drivenMDWidget.h} (100%) rename src/modules/drivenMD/gui/{epsrManagerWidget.ui => drivenMDWidget.ui} (100%) diff --git a/src/modules/drivenMD/gui/drivenMDFuncs.cpp b/src/modules/drivenMD/gui/drivenMDFuncs.cpp index 43af1ccf17..bd5e8c8c12 100644 --- a/src/modules/drivenMD/gui/drivenMDFuncs.cpp +++ b/src/modules/drivenMD/gui/drivenMDFuncs.cpp @@ -3,7 +3,7 @@ #include "main/dissolve.h" #include "modules/drivenMD/drivenMD.h" -#include "modules/drivenMD/gui/epsrManagerWidget.h" +#include "modules/drivenMD/gui/drivenMDWidget.h" DrivenMDModuleWidget::DrivenMDModuleWidget(QWidget *parent, DrivenMDModule *module, Dissolve &dissolve) : ModuleWidget(parent, dissolve), module_(module) diff --git a/src/modules/drivenMD/gui/epsrManagerWidget.h b/src/modules/drivenMD/gui/drivenMDWidget.h similarity index 100% rename from src/modules/drivenMD/gui/epsrManagerWidget.h rename to src/modules/drivenMD/gui/drivenMDWidget.h diff --git a/src/modules/drivenMD/gui/epsrManagerWidget.ui b/src/modules/drivenMD/gui/drivenMDWidget.ui similarity index 100% rename from src/modules/drivenMD/gui/epsrManagerWidget.ui rename to src/modules/drivenMD/gui/drivenMDWidget.ui From 93619840515442d85c946212f18ec5d953a2d87c Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Mon, 18 Nov 2024 10:36:22 +0000 Subject: [PATCH 05/13] initial test of gradient calculation --- src/modules/drivenMD/process.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index a2a696e680..b472d2d17c 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -28,6 +28,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) std::vector forces; PartialSet totalGR; PartialSet referenceData; + std::vector storedSQ; // Does a PartialSet already exist for this Configuration? auto originalGRObject = processingData.realiseIf( @@ -54,18 +55,19 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) // FT to structure factor Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // Store Error here - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + storedSQ[0] = (totalGR); newPosition = i.x() + (2 * delta); i.set(newPosition, i.y(), i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // Store Error here - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + storedSQ[1] = (totalGR); // Reset position newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); + // Calculate difference and gradient + storedSQ[1].total() -= storedSQ[0].total(); + storedSQ[1].total() /= ((i.x() + delta) - (i.x() - delta)); break; // Move y case 2: From d82d163090296f0b4c0e6f030f5baf9dac4b1dbe Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 21 Nov 2024 09:44:46 +0000 Subject: [PATCH 06/13] reference data initial --- src/modules/drivenMD/process.cpp | 139 ++++++++++++++++--------------- 1 file changed, 74 insertions(+), 65 deletions(-) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index b472d2d17c..680cfd2f36 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -27,8 +27,6 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) std::vector forces; PartialSet totalGR; - PartialSet referenceData; - std::vector storedSQ; // Does a PartialSet already exist for this Configuration? auto originalGRObject = processingData.realiseIf( @@ -38,74 +36,85 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) auto atoms = targetConfiguration_->atoms(); forces.resize(atoms.size()); - for (auto &i : atoms) + for (auto *module : targets_) { - for (auto n = 0; n < 3; ++n) + // Retrieve the ReferenceData + if (!processingData.contains("ReferenceData", module->name())) { - double newPosition{}; - switch (n) + Messenger::error("Reference data not found for target '{}'.\n", module->name()); + return ExecutionResult::Failed; + } + const auto &originalReferenceData = processingData.value("ReferenceData", module->name()); + + for (auto &i : atoms) + { + for (auto n = 0; n < 3; ++n) { - // Move x - case 1: - // Get position, change via delta then set - newPosition = i.x() - delta; - i.set(newPosition, i.y(), i.z()); - // Calculate GR - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - // FT to structure factor - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - storedSQ[0] = (totalGR); - newPosition = i.x() + (2 * delta); - i.set(newPosition, i.y(), i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - storedSQ[1] = (totalGR); - // Reset position - newPosition = i.x() - delta; - i.set(newPosition, i.y(), i.z()); - // Calculate difference and gradient - storedSQ[1].total() -= storedSQ[0].total(); - storedSQ[1].total() /= ((i.x() + delta) - (i.x() - delta)); - break; - // Move y - case 2: - newPosition = i.y() - delta; - i.set(i.x(), newPosition, i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); - newPosition = i.y() + (2 * delta); - i.set(i.x(), newPosition, i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); - newPosition = i.y() - delta; - i.set(i.x(), newPosition, i.z()); - break; - // Move z - case 3: - newPosition = i.z() - delta; - i.set(i.x(), i.y(), newPosition); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); - newPosition = i.z() + (2 * delta); - i.set(i.x(), i.y(), newPosition); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, - WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); - newPosition = i.z() - delta; - i.set(i.x(), i.y(), newPosition); - break; + double newPosition{}; + switch (n) + { + // Move x + case 1: + // Get position, change via delta then set + newPosition = i.x() - delta; + i.set(newPosition, i.y(), i.z()); + // Calculate GR + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + // FT to structure factor + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + totalGR.total() -= originalReferenceData; + newPosition = i.x() + (2 * delta); + i.set(newPosition, i.y(), i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + + totalGR.total() -= originalReferenceData; + // Reset position + newPosition = i.x() - delta; + i.set(newPosition, i.y(), i.z()); + // Calculate difference and gradient + storedSQ[1].total() -= storedSQ[0].total(); + storedSQ[1].total() /= ((i.x() + delta) - (i.x() - delta)); + break; + // Move y + case 2: + newPosition = i.y() - delta; + i.set(i.x(), newPosition, i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.y() + (2 * delta); + i.set(i.x(), newPosition, i.z()); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.y() - delta; + i.set(i.x(), newPosition, i.z()); + break; + // Move z + case 3: + newPosition = i.z() - delta; + i.set(i.x(), i.y(), newPosition); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.z() + (2 * delta); + i.set(i.x(), i.y(), newPosition); + totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + WindowFunction::Form::Lorch0); + // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + newPosition = i.z() - delta; + i.set(i.x(), i.y(), newPosition); + break; + } } } } - return ExecutionResult::Success; } From 8a638163d8a872dc47a7a15726bd6ba0df5dbc8c Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 21 Nov 2024 14:14:08 +0000 Subject: [PATCH 07/13] added in calc of errors --- src/modules/drivenMD/process.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index 680cfd2f36..48c3dd96ad 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -4,6 +4,7 @@ #include "base/sysFunc.h" #include "keywords/module.h" #include "main/dissolve.h" +#include "math/error.h" #include "math/ft.h" #include "module/context.h" #include "module/group.h" @@ -25,7 +26,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) * that we then apply to MD simulation */ - std::vector forces; + std::vector> forces; PartialSet totalGR; // Does a PartialSet already exist for this Configuration? @@ -34,7 +35,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) auto &originalgr = originalGRObject.first; double delta{0.1}; auto atoms = targetConfiguration_->atoms(); - forces.resize(atoms.size()); + forces.reserve(atoms.size()); for (auto *module : targets_) { @@ -48,6 +49,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) for (auto &i : atoms) { + auto &f = forces.emplace_back(i.r()); for (auto n = 0; n < 3; ++n) { double newPosition{}; @@ -63,35 +65,34 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) // FT to structure factor Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - totalGR.total() -= originalReferenceData; + // Store the error in a vector + f.x = Error::rmse(totalGR.total(), originalReferenceData).error; + // Set new position (needs 2x to get +x from original) newPosition = i.x() + (2 * delta); i.set(newPosition, i.y(), i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - - totalGR.total() -= originalReferenceData; + // Calculate new error + f.x -= Error::rmse(totalGR.total(), originalReferenceData).error; // Reset position newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); - // Calculate difference and gradient - storedSQ[1].total() -= storedSQ[0].total(); - storedSQ[1].total() /= ((i.x() + delta) - (i.x() - delta)); break; - // Move y + // Move y and repeat case 2: newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + f.y = Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.y() + (2 * delta); i.set(i.x(), newPosition, i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + f.y -= Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); break; @@ -102,13 +103,13 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + f.z = Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.z() + (2 * delta); i.set(i.x(), i.y(), newPosition); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - // forces.emplace_back(referenceData.total().values() - totalGR.total().values()); + f.z -= Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.z() - delta; i.set(i.x(), i.y(), newPosition); break; From e6b13686364a505dc99b470dd7f60e0547a620ae Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Fri, 22 Nov 2024 10:09:07 +0000 Subject: [PATCH 08/13] translate coordinates --- src/modules/drivenMD/process.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index 48c3dd96ad..acb8d0ee1c 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -115,7 +115,10 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) break; } } + i.translateCoordinates(f); + targetConfiguration_->updateAtomLocation(&i); } + targetConfiguration_->updateObjectRelationships(); } return ExecutionResult::Success; } From 10b22db5662e430164b9013ef3f9ce400ee56d51 Mon Sep 17 00:00:00 2001 From: Tristan Youngs Date: Fri, 22 Nov 2024 12:04:28 +0000 Subject: [PATCH 09/13] Investigations. --- src/modules/drivenMD/functions.cpp | 8 +++++- src/modules/drivenMD/process.cpp | 41 +++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/modules/drivenMD/functions.cpp b/src/modules/drivenMD/functions.cpp index ea03ee975e..dd39e56b00 100644 --- a/src/modules/drivenMD/functions.cpp +++ b/src/modules/drivenMD/functions.cpp @@ -20,5 +20,11 @@ PartialSet DrivenMDModule::calculateGRTestSerial(Configuration *cfg, PartialSet partialSet.fullHistogram(ii.localTypeIndex(), jj.localTypeIndex()).bin(box->minimumDistance(ii.r(), jj.r())); }); + // Transform histogram data into radial distribution functions + partialSet.formPartials(box->volume()); + + // Sum total functions + partialSet.formTotals(true); + return partialSet; -} \ No newline at end of file +} diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index acb8d0ee1c..18233bb6e3 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -33,6 +33,15 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) auto originalGRObject = processingData.realiseIf( fmt::format("{}//OriginalGR", targetConfiguration_->niceName()), name_, GenericItem::InRestartFileFlag); auto &originalgr = originalGRObject.first; + auto rdfRange = targetConfiguration_->box()->inscribedSphereRadius(); + auto binWidth = 0.025; + rdfRange = int(rdfRange / binWidth) * binWidth; + if (originalGRObject.second == GenericItem::ItemStatus::Created) + originalgr.setUp(targetConfiguration_->atomTypes(), rdfRange, binWidth); + + originalgr.setUpHistograms(rdfRange, binWidth); + originalgr.reset(); + double delta{0.1}; auto atoms = targetConfiguration_->atoms(); forces.reserve(atoms.size()); @@ -49,65 +58,68 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) for (auto &i : atoms) { - auto &f = forces.emplace_back(i.r()); + auto &f = forces.emplace_back(Vec3(0.0,0.0,0.0)); + fmt::print("Atom {}\n", i.globalIndex()); for (auto n = 0; n < 3; ++n) { double newPosition{}; switch (n) { // Move x - case 1: + case 0: // Get position, change via delta then set newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); // Calculate GR - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + calculateGRTestSerial(targetConfiguration_, originalgr); // FT to structure factor - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); // Store the error in a vector f.x = Error::rmse(totalGR.total(), originalReferenceData).error; + fmt::print("X+ = {}\n", Error::rmse(totalGR.total(), originalReferenceData).error); // Set new position (needs 2x to get +x from original) newPosition = i.x() + (2 * delta); i.set(newPosition, i.y(), i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); // Calculate new error f.x -= Error::rmse(totalGR.total(), originalReferenceData).error; + fmt::print("X+ = {}\n", Error::rmse(totalGR.total(), originalReferenceData).error); // Reset position newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); break; // Move y and repeat - case 2: + case 1: newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); f.y = Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.y() + (2 * delta); i.set(i.x(), newPosition, i.z()); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); f.y -= Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); break; // Move z - case 3: + case 2: newPosition = i.z() - delta; i.set(i.x(), i.y(), newPosition); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); f.z = Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.z() + (2 * delta); i.set(i.x(), i.y(), newPosition); totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); - Fourier::sineFT(totalGR.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, + Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); f.z -= Error::rmse(totalGR.total(), originalReferenceData).error; newPosition = i.z() - delta; @@ -115,10 +127,15 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) break; } } + i.translateCoordinates(f); + f.print(); targetConfiguration_->updateAtomLocation(&i); + } - targetConfiguration_->updateObjectRelationships(); } + + targetConfiguration_->updateObjectRelationships(); + return ExecutionResult::Success; } From eb56a81bff1449cab892f1b7ca999d57537f54e0 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Fri, 22 Nov 2024 15:24:51 +0000 Subject: [PATCH 10/13] fix calc of originalgr and debugging added in --- src/modules/drivenMD/drivenMD.h | 2 +- src/modules/drivenMD/functions.cpp | 4 +-- src/modules/drivenMD/process.cpp | 53 ++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/modules/drivenMD/drivenMD.h b/src/modules/drivenMD/drivenMD.h index d0079b6aaa..c9fc9f1b6f 100644 --- a/src/modules/drivenMD/drivenMD.h +++ b/src/modules/drivenMD/drivenMD.h @@ -42,7 +42,7 @@ class DrivenMDModule : public Module // Target Configuration (determined from target modules) Configuration *targetConfiguration_{nullptr}; // Calculate partial g(r) in serial with simple double-loop - PartialSet calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet); + void calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet); /* * Processing */ diff --git a/src/modules/drivenMD/functions.cpp b/src/modules/drivenMD/functions.cpp index dd39e56b00..a75a4c1c39 100644 --- a/src/modules/drivenMD/functions.cpp +++ b/src/modules/drivenMD/functions.cpp @@ -7,7 +7,7 @@ #include "templates/algorithms.h" // Calculate partial g(r) in serial with simple double-loop -PartialSet DrivenMDModule::calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet) +void DrivenMDModule::calculateGRTestSerial(Configuration *cfg, PartialSet &partialSet) { // Calculate radial distribution functions with a simple double loop, in serial then return the partial set!!!!!!! const auto *box = cfg->box(); @@ -25,6 +25,4 @@ PartialSet DrivenMDModule::calculateGRTestSerial(Configuration *cfg, PartialSet // Sum total functions partialSet.formTotals(true); - - return partialSet; } diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index 18233bb6e3..9dcee04e24 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -27,7 +27,6 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) */ std::vector> forces; - PartialSet totalGR; // Does a PartialSet already exist for this Configuration? auto originalGRObject = processingData.realiseIf( @@ -42,7 +41,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) originalgr.setUpHistograms(rdfRange, binWidth); originalgr.reset(); - double delta{0.1}; + double delta{2}; auto atoms = targetConfiguration_->atoms(); forces.reserve(atoms.size()); @@ -58,7 +57,8 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) for (auto &i : atoms) { - auto &f = forces.emplace_back(Vec3(0.0,0.0,0.0)); + fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); + auto &f = forces.emplace_back(Vec3(0.0, 0.0, 0.0)); fmt::print("Atom {}\n", i.globalIndex()); for (auto n = 0; n < 3; ++n) { @@ -68,70 +68,87 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) // Move x case 0: // Get position, change via delta then set + fmt::print("X coord = {}\n", i.x()); newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); + fmt::print("X coord = {}\n", i.x()); // Calculate GR calculateGRTestSerial(targetConfiguration_, originalgr); // FT to structure factor Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); // Store the error in a vector - f.x = Error::rmse(totalGR.total(), originalReferenceData).error; - fmt::print("X+ = {}\n", Error::rmse(totalGR.total(), originalReferenceData).error); + f.x = Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("X+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); // Set new position (needs 2x to get +x from original) newPosition = i.x() + (2 * delta); i.set(newPosition, i.y(), i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + fmt::print("X coord = {}\n", i.x()); + calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); // Calculate new error - f.x -= Error::rmse(totalGR.total(), originalReferenceData).error; - fmt::print("X+ = {}\n", Error::rmse(totalGR.total(), originalReferenceData).error); + f.x -= Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("X+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); // Reset position newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); + fmt::print("X coord = {}\n", i.x()); break; // Move y and repeat case 1: + fmt::print("Y coord = {}\n", i.y()); newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + fmt::print("Y coord = {}\n", i.y()); + calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - f.y = Error::rmse(totalGR.total(), originalReferenceData).error; + f.y = Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("Y+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); newPosition = i.y() + (2 * delta); i.set(i.x(), newPosition, i.z()); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + fmt::print("Y coord = {}\n", i.y()); + calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - f.y -= Error::rmse(totalGR.total(), originalReferenceData).error; + f.y -= Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("Y+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); + fmt::print("Y coord = {}\n", i.y()); break; // Move z case 2: + fmt::print("Z coord = {}\n", i.z()); newPosition = i.z() - delta; i.set(i.x(), i.y(), newPosition); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + fmt::print("Z coord = {}\n", i.z()); + calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - f.z = Error::rmse(totalGR.total(), originalReferenceData).error; + f.z = Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("Z+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); newPosition = i.z() + (2 * delta); i.set(i.x(), i.y(), newPosition); - totalGR = calculateGRTestSerial(targetConfiguration_, originalgr); + fmt::print("Z coord = {}\n", i.z()); + calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); - f.z -= Error::rmse(totalGR.total(), originalReferenceData).error; + f.z -= Error::rmse(originalgr.total(), originalReferenceData).error; + fmt::print("Z+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); newPosition = i.z() - delta; i.set(i.x(), i.y(), newPosition); + fmt::print("Z coord = {}\n", i.z()); break; } } - + fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); i.translateCoordinates(f); f.print(); targetConfiguration_->updateAtomLocation(&i); - + printf("We've moved\n"); + fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); } } From aec7a9b7a2ad88142c084d087062934947578cb4 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Mon, 25 Nov 2024 13:52:25 +0000 Subject: [PATCH 11/13] added in reset and moved translate --- src/modules/drivenMD/process.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index 9dcee04e24..ed4c6c4e73 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -72,6 +72,8 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.x() - delta; i.set(newPosition, i.y(), i.z()); fmt::print("X coord = {}\n", i.x()); + // Reset GR + originalgr.reset(); // Calculate GR calculateGRTestSerial(targetConfiguration_, originalgr); // FT to structure factor @@ -84,6 +86,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.x() + (2 * delta); i.set(newPosition, i.y(), i.z()); fmt::print("X coord = {}\n", i.x()); + originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); @@ -101,6 +104,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.y() - delta; i.set(i.x(), newPosition, i.z()); fmt::print("Y coord = {}\n", i.y()); + originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); @@ -109,6 +113,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.y() + (2 * delta); i.set(i.x(), newPosition, i.z()); fmt::print("Y coord = {}\n", i.y()); + originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); @@ -124,6 +129,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.z() - delta; i.set(i.x(), i.y(), newPosition); fmt::print("Z coord = {}\n", i.z()); + originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); @@ -132,6 +138,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) newPosition = i.z() + (2 * delta); i.set(i.x(), i.y(), newPosition); fmt::print("Z coord = {}\n", i.z()); + originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); Fourier::sineFT(originalgr.total(), 1.0 / (2.0 * PI * PI * 1.39), 0.05, 0.05, 30.0, WindowFunction::Form::Lorch0); @@ -143,15 +150,19 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) break; } } - fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); - i.translateCoordinates(f); - f.print(); - targetConfiguration_->updateAtomLocation(&i); - printf("We've moved\n"); - fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); } } + for (auto &&[i, f] : zip(atoms, forces)) + { + fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); + i.translateCoordinates(f); + f.print(); + targetConfiguration_->updateAtomLocation(&i); + printf("We've moved\n"); + fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); + } + targetConfiguration_->updateObjectRelationships(); return ExecutionResult::Success; From 8ae828eee5cfeb95235b34e1d09b0dad7d6644f4 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 5 Dec 2024 13:41:07 +0000 Subject: [PATCH 12/13] change to translateCoordinates() --- src/modules/drivenMD/process.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index ed4c6c4e73..ca0970f390 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -62,15 +62,13 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) fmt::print("Atom {}\n", i.globalIndex()); for (auto n = 0; n < 3; ++n) { - double newPosition{}; switch (n) { // Move x case 0: // Get position, change via delta then set fmt::print("X coord = {}\n", i.x()); - newPosition = i.x() - delta; - i.set(newPosition, i.y(), i.z()); + i.translateCoordinates(-delta, 0, 0); fmt::print("X coord = {}\n", i.x()); // Reset GR originalgr.reset(); @@ -83,8 +81,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) f.x = Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("X+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); // Set new position (needs 2x to get +x from original) - newPosition = i.x() + (2 * delta); - i.set(newPosition, i.y(), i.z()); + i.translateCoordinates(2 * delta, 0, 0); fmt::print("X coord = {}\n", i.x()); originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); @@ -94,15 +91,13 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) f.x -= Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("X+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); // Reset position - newPosition = i.x() - delta; - i.set(newPosition, i.y(), i.z()); + i.translateCoordinates(-delta, 0, 0); fmt::print("X coord = {}\n", i.x()); break; // Move y and repeat case 1: fmt::print("Y coord = {}\n", i.y()); - newPosition = i.y() - delta; - i.set(i.x(), newPosition, i.z()); + i.translateCoordinates(0, -delta, 0); fmt::print("Y coord = {}\n", i.y()); originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); @@ -110,8 +105,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) WindowFunction::Form::Lorch0); f.y = Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("Y+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); - newPosition = i.y() + (2 * delta); - i.set(i.x(), newPosition, i.z()); + i.translateCoordinates(0, 2 * delta, 0); fmt::print("Y coord = {}\n", i.y()); originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); @@ -119,15 +113,13 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) WindowFunction::Form::Lorch0); f.y -= Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("Y+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); - newPosition = i.y() - delta; - i.set(i.x(), newPosition, i.z()); + i.translateCoordinates(0, -delta, 0); fmt::print("Y coord = {}\n", i.y()); break; // Move z case 2: fmt::print("Z coord = {}\n", i.z()); - newPosition = i.z() - delta; - i.set(i.x(), i.y(), newPosition); + i.translateCoordinates(0, 0, -delta); fmt::print("Z coord = {}\n", i.z()); originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); @@ -135,8 +127,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) WindowFunction::Form::Lorch0); f.z = Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("Z+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); - newPosition = i.z() + (2 * delta); - i.set(i.x(), i.y(), newPosition); + i.translateCoordinates(0, 0, 2 * delta); fmt::print("Z coord = {}\n", i.z()); originalgr.reset(); calculateGRTestSerial(targetConfiguration_, originalgr); @@ -144,8 +135,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) WindowFunction::Form::Lorch0); f.z -= Error::rmse(originalgr.total(), originalReferenceData).error; fmt::print("Z+ = {}\n", Error::rmse(originalgr.total(), originalReferenceData).error); - newPosition = i.z() - delta; - i.set(i.x(), i.y(), newPosition); + i.translateCoordinates(0, 0, -delta); fmt::print("Z coord = {}\n", i.z()); break; } @@ -158,7 +148,6 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); i.translateCoordinates(f); f.print(); - targetConfiguration_->updateAtomLocation(&i); printf("We've moved\n"); fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); } From 4a7b38a146c6793565e62fa38c1f37258b1ddd38 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 12 Dec 2024 16:06:10 +0000 Subject: [PATCH 13/13] added incrementContentsVersion --- src/modules/drivenMD/process.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/drivenMD/process.cpp b/src/modules/drivenMD/process.cpp index ca0970f390..b0e27817ef 100644 --- a/src/modules/drivenMD/process.cpp +++ b/src/modules/drivenMD/process.cpp @@ -152,6 +152,7 @@ Module::ExecutionResult DrivenMDModule::process(ModuleContext &moduleContext) fmt::print("X coord = {}, Y coord = {}, Z coord = {}\n", i.x(), i.y(), i.z()); } + targetConfiguration_->incrementContentsVersion(); targetConfiguration_->updateObjectRelationships(); return ExecutionResult::Success;