Skip to content

Commit c9500fb

Browse files
author
Charlles Abreu
authored
Adds method for copy and deepcopy to work with CompositeRMSDForce (#13)
* Improved docstring * Fixed comments * Bug fix * Added __copy__ magic method
1 parent 54a74c0 commit c9500fb

File tree

9 files changed

+27
-17
lines changed

9 files changed

+27
-17
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: 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 "CompositeRMSDForce.h"

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: 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 "internal/CompositeRMSDForceImpl.h"

python/openmmcppforces/openmmcppforces.i

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Add units to function outputs.
3434
*/
3535

3636
%pythonappend OpenMMCPPForces::CompositeRMSDForce::getReferencePositions() const %{
37-
val= unit.nanometers
37+
val *= unit.nanometers
3838
%}
3939

4040
/*
@@ -56,20 +56,21 @@ namespace OpenMMCPPForces {
5656
This is a force whose energy equals the root mean squared deviation (RMSD) between the
5757
current coordinates of multiple particle groups and reference structures defined for
5858
each group. The composite RMSD is computed after aligning every particle group to its
59-
reference while keeping the relative orientations of all groups fixed. Therefore, it is
60-
not a mere composition of independent RMSD calculations done in the usual way.
59+
reference while keeping the relative orientations of all groups fixed. In other words,
60+
every group can translate independently in search for the best alignment, but all
61+
groups must rotate in unison.
6162

6263
Consider `m` particle groups, with each group :math:`{\bf g}_j` containing
6364
:math:`n_j` particles. The centroid of each group is given by
6465

6566
.. math::
6667

67-
{\bf c}_j = \frac{1}{n_j} \sum_{k \in {\bf g}_j} {\bf r}_k
68+
{\bf c}_j = \frac{1}{n_j} \sum_{i \in {\bf g}_j} {\bf r}_i
6869

69-
where :math:`{\bf r}_k` is the position of particle :math:`k` and the sum is over
70+
where :math:`{\bf r}_i` is the position of particle :math:`k` and the sum is over
7071
all particles in the group. Analogously, :math:`{\bf c}_j^{\rm ref}` is the
7172
centroid of the reference structure for group :math:`j`, whose each particle
72-
:math:`k` is located at :math:`{\bf r}_k^{\rm ref}`.
73+
:math:`k` is located at :math:`{\bf r}_i^{\rm ref}`.
7374

7475
The composite RMSD is then defined as
7576

@@ -78,9 +79,9 @@ The composite RMSD is then defined as
7879
d_{\rm crms}({\bf r}) = \sqrt{
7980
\frac{1}{n} \min_{
8081
\bf q \in \mathbb{R}^4 \atop \|{\bf q}\| = 1
81-
} \sum_{j=1}^m \sum_{k \in {\bf g}_j} \left\|
82-
{\bf A}({\bf q})\left({\bf r}_k - {\bf c}_j\right) -
83-
{\bf r}_k^{\rm ref} + {\bf c}_j^{\rm ref}
82+
} \sum_{j=1}^m \sum_{i \in {\bf g}_j} \left\|
83+
{\bf A}({\bf q})\left({\bf r}_i - {\bf c}_j\right) -
84+
{\bf r}_i^{\rm ref} + {\bf c}_j^{\rm ref}
8485
\right\|^2
8586
}
8687

@@ -217,14 +218,23 @@ public:
217218
%}
218219
bool usesPeriodicBoundaryConditions();
219220
221+
220222
%extend {
223+
%feature("docstring") %{Cast a :OpenMM:`Force` to a :class:`CompositeRMSDForce`.%}
221224
static OpenMMCPPForces::CompositeRMSDForce& cast(OpenMM::Force& force) {
222225
return dynamic_cast<OpenMMCPPForces::CompositeRMSDForce&>(force);
223226
}
224227
228+
%feature("docstring") %{Check if a :OpenMM:`Force` is a :class:`CompositeRMSDForce`.%}
225229
static bool isinstance(OpenMM::Force& force) {
226230
return (dynamic_cast<OpenMMCPPForces::CompositeRMSDForce*>(&force) != NULL);
227231
}
232+
233+
%feature("docstring") %{Clone a :class:`CompositeRMSDForce` object.%}
234+
%newobject __copy__;
235+
OpenMMCPPForces::CompositeRMSDForce* __copy__() {
236+
return OpenMM::XmlSerializer::clone<OpenMMCPPForces::CompositeRMSDForce>(*self);
237+
}
228238
}
229239
};
230240

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)