Skip to content

Commit 2c5fb9c

Browse files
author
Charlles Abreu
authored
Forces cleared at start and after updating parameters in context (#14)
1 parent c9500fb commit 2c5fb9c

File tree

8 files changed

+22
-13
lines changed

8 files changed

+22
-13
lines changed

openmmcppforces/include/CompositeRMSDForce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* A plugin for distributing platform-agnostic OpenMM Forces *
99
* *
1010
* Copyright (c) 2024 Charlles Abreu *
11-
* https://github.com/RedesignScience/openmm-cpp-forces *
11+
* https://github.com/RedesignScience/openmm-cpp-forces *
1212
* -------------------------------------------------------------------------- */
1313

1414
#include "internal/windowsExportOpenMMCPPForces.h"

openmmcppforces/include/internal/CompositeRMSDForceImpl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* A plugin for distributing platform-agnostic OpenMM Forces *
99
* *
1010
* Copyright (c) 2024 Charlles Abreu *
11-
* https://github.com/RedesignScience/openmm-cpp-forces *
11+
* https://github.com/RedesignScience/openmm-cpp-forces *
1212
* -------------------------------------------------------------------------- */
1313

1414
#include "CompositeRMSDForce.h"
@@ -28,7 +28,8 @@ namespace OpenMMCPPForces {
2828

2929
class CompositeRMSDForceImpl : public CustomCPPForceImpl {
3030
public:
31-
CompositeRMSDForceImpl(const CompositeRMSDForce& owner) : CustomCPPForceImpl(owner), owner(owner) {}
31+
CompositeRMSDForceImpl(const CompositeRMSDForce& owner) :
32+
CustomCPPForceImpl(owner), owner(owner), resetForces(true) {}
3233
void initialize(ContextImpl& context);
3334
double computeForce(ContextImpl& context, const vector<Vec3>& positions, vector<Vec3>& forces);
3435
const CompositeRMSDForce& getOwner() const {
@@ -40,7 +41,8 @@ class CompositeRMSDForceImpl : public CustomCPPForceImpl {
4041
const CompositeRMSDForce& owner;
4142
vector<vector<int>> groups;
4243
vector<Vec3> referencePos;
43-
double sumRefPosSquared;
44+
double sumRefPosSq;
45+
bool resetForces;
4446
};
4547

4648
} // namespace OpenMMCPPForces

openmmcppforces/src/CompositeRMSDForce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* A plugin for distributing platform-agnostic OpenMM Forces *
66
* *
77
* Copyright (c) 2024 Charlles Abreu *
8-
* https://github.com/RedesignScience/openmm-cpp-forces *
8+
* https://github.com/RedesignScience/openmm-cpp-forces *
99
* -------------------------------------------------------------------------- */
1010

1111
#include "CompositeRMSDForce.h"

openmmcppforces/src/CompositeRMSDForceImpl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* A plugin for distributing platform-agnostic OpenMM Forces *
66
* *
77
* Copyright (c) 2024 Charlles Abreu *
8-
* https://github.com/RedesignScience/openmm-cpp-forces *
8+
* https://github.com/RedesignScience/openmm-cpp-forces *
99
* -------------------------------------------------------------------------- */
1010

1111
#include "internal/CompositeRMSDForceImpl.h"
@@ -70,9 +70,11 @@ void CompositeRMSDForceImpl::updateParameters(int systemSize) {
7070
referencePos.push_back(positions[i] - center);
7171
}
7272

73-
sumRefPosSquared = 0.0;
73+
sumRefPosSq = 0.0;
7474
for (auto& p : referencePos)
75-
sumRefPosSquared += p.dot(p);
75+
sumRefPosSq += p.dot(p);
76+
77+
resetForces = true;
7678
}
7779

7880
void CompositeRMSDForceImpl::initialize(ContextImpl& context) {
@@ -138,7 +140,7 @@ double CompositeRMSDForceImpl::computeForce(ContextImpl& context, const vector<V
138140

139141
// Compute the RMSD.
140142

141-
double sum = sumRefPosSquared;
143+
double sum = sumRefPosSq;
142144
for (auto& p : centeredPos)
143145
sum += p.dot(p);
144146

@@ -166,6 +168,11 @@ double CompositeRMSDForceImpl::computeForce(ContextImpl& context, const vector<V
166168

167169
// Rotate the reference positions and compute the forces.
168170

171+
if (resetForces) {
172+
fill(forces.begin(), forces.end(), Vec3(0, 0, 0));
173+
resetForces = false;
174+
}
175+
169176
index = 0;
170177
for (auto& group : groups) {
171178
double scale = 1.0 / (rmsd*group.size());

serialization/include/CompositeRMSDForceProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* A plugin for distributing platform-agnostic OpenMM Forces *
99
* *
1010
* Copyright (c) 2024 Charlles Abreu *
11-
* https://github.com/RedesignScience/openmm-cpp-forces *
11+
* https://github.com/RedesignScience/openmm-cpp-forces *
1212
* -------------------------------------------------------------------------- */
1313

1414
#include "internal/windowsExportOpenMMCPPForces.h"

serialization/src/OpenMMCPPForcesSerializationProxyRegistration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* A plugin for distributing platform-agnostic OpenMM Forces *
66
* *
77
* Copyright (c) 2024 Charlles Abreu *
8-
* https://github.com/RedesignScience/openmm-cpp-forces *
8+
* https://github.com/RedesignScience/openmm-cpp-forces *
99
* -------------------------------------------------------------------------- */
1010

1111
#ifdef WIN32

serialization/tests/TestSerializeCompositeRMSDForce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* A plugin for distributing platform-agnostic OpenMM Forces *
66
* *
77
* Copyright (c) 2024 Charlles Abreu *
8-
* https://github.com/RedesignScience/openmm-cpp-forces *
8+
* https://github.com/RedesignScience/openmm-cpp-forces *
99
* -------------------------------------------------------------------------- */
1010

1111
#include "CompositeRMSDForce.h"

tests/TestCompositeRMSDForce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* A plugin for distributing platform-agnostic OpenMM Forces *
66
* *
77
* Copyright (c) 2024 Charlles Abreu *
8-
* https://github.com/RedesignScience/openmm-cpp-forces *
8+
* https://github.com/RedesignScience/openmm-cpp-forces *
99
* -------------------------------------------------------------------------- */
1010

1111
#include "CompositeRMSDForce.h"

0 commit comments

Comments
 (0)