Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
ae341831
Unverified
Commit
ae341831
authored
Jul 25, 2022
by
Peter Eastman
Committed by
GitHub
Jul 25, 2022
Browse files
CustomCVForce avoids breaking up molecules (#3711)
parent
a39fa14a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
3 deletions
+49
-3
openmmapi/include/openmm/internal/CustomCVForceImpl.h
openmmapi/include/openmm/internal/CustomCVForceImpl.h
+2
-1
openmmapi/src/CustomCVForceImpl.cpp
openmmapi/src/CustomCVForceImpl.cpp
+11
-1
tests/TestCustomCVForce.h
tests/TestCustomCVForce.h
+36
-1
No files found.
openmmapi/include/openmm/internal/CustomCVForceImpl.h
View file @
ae341831
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-20
17
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
22
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -62,6 +62,7 @@ public:
...
@@ -62,6 +62,7 @@ public:
double
calcForcesAndEnergy
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
);
double
calcForcesAndEnergy
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
);
std
::
map
<
std
::
string
,
double
>
getDefaultParameters
();
std
::
map
<
std
::
string
,
double
>
getDefaultParameters
();
std
::
vector
<
std
::
string
>
getKernelNames
();
std
::
vector
<
std
::
string
>
getKernelNames
();
std
::
vector
<
std
::
pair
<
int
,
int
>
>
getBondedParticles
()
const
;
void
getCollectiveVariableValues
(
ContextImpl
&
context
,
std
::
vector
<
double
>&
values
);
void
getCollectiveVariableValues
(
ContextImpl
&
context
,
std
::
vector
<
double
>&
values
);
Context
&
getInnerContext
();
Context
&
getInnerContext
();
void
updateParametersInContext
(
ContextImpl
&
context
);
void
updateParametersInContext
(
ContextImpl
&
context
);
...
...
openmmapi/src/CustomCVForceImpl.cpp
View file @
ae341831
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-20
17
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
22
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -91,6 +91,16 @@ vector<string> CustomCVForceImpl::getKernelNames() {
...
@@ -91,6 +91,16 @@ vector<string> CustomCVForceImpl::getKernelNames() {
return
names
;
return
names
;
}
}
vector
<
pair
<
int
,
int
>
>
CustomCVForceImpl
::
getBondedParticles
()
const
{
vector
<
pair
<
int
,
int
>
>
bonds
;
const
ContextImpl
&
innerContextImpl
=
getContextImpl
(
*
innerContext
);
for
(
auto
&
impl
:
innerContextImpl
.
getForceImpls
())
{
for
(
auto
&
bond
:
impl
->
getBondedParticles
())
bonds
.
push_back
(
bond
);
}
return
bonds
;
}
map
<
string
,
double
>
CustomCVForceImpl
::
getDefaultParameters
()
{
map
<
string
,
double
>
CustomCVForceImpl
::
getDefaultParameters
()
{
map
<
string
,
double
>
parameters
;
map
<
string
,
double
>
parameters
;
parameters
.
insert
(
innerContext
->
getParameters
().
begin
(),
innerContext
->
getParameters
().
end
());
parameters
.
insert
(
innerContext
->
getParameters
().
begin
(),
innerContext
->
getParameters
().
end
());
...
...
tests/TestCustomCVForce.h
View file @
ae341831
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2017 Stanford University and the Authors.
*
* Portions copyright (c) 2017
-2022
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -38,9 +38,11 @@
...
@@ -38,9 +38,11 @@
#include "openmm/CustomCVForce.h"
#include "openmm/CustomCVForce.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/CustomNonbondedForce.h"
#include "openmm/CustomNonbondedForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/System.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include "sfmt/SFMT.h"
#include <algorithm>
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
...
@@ -234,6 +236,38 @@ void testReordering() {
...
@@ -234,6 +236,38 @@ void testReordering() {
ASSERT_EQUAL_VEC
(
delta
*
2
/
r
,
state
.
getForces
()[
10
],
1e-5
);
ASSERT_EQUAL_VEC
(
delta
*
2
/
r
,
state
.
getForces
()[
10
],
1e-5
);
}
}
void
testMolecules
()
{
// Verify that CustomCVForce correctly propagates information about molecules
// from the forces it contains.
System
system
;
for
(
int
i
=
0
;
i
<
5
;
i
++
)
system
.
addParticle
(
1.0
);
CustomCVForce
*
cv
=
new
CustomCVForce
(
"x+y"
);
system
.
addForce
(
cv
);
HarmonicBondForce
*
bonds1
=
new
HarmonicBondForce
();
bonds1
->
addBond
(
0
,
1
,
1.0
,
1.0
);
bonds1
->
addBond
(
2
,
3
,
1.0
,
1.0
);
cv
->
addCollectiveVariable
(
"x"
,
bonds1
);
HarmonicBondForce
*
bonds2
=
new
HarmonicBondForce
();
bonds2
->
addBond
(
1
,
2
,
1.0
,
1.0
);
cv
->
addCollectiveVariable
(
"y"
,
bonds2
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
vector
<
int
>
>
molecules
=
context
.
getMolecules
();
ASSERT_EQUAL
(
2
,
molecules
.
size
());
for
(
auto
&
mol
:
molecules
)
{
if
(
mol
.
size
()
==
1
)
{
ASSERT_EQUAL
(
4
,
mol
[
0
]);
}
else
{
ASSERT_EQUAL
(
4
,
mol
.
size
());
for
(
int
i
=
0
;
i
<
4
;
i
++
)
ASSERT
(
find
(
mol
.
begin
(),
mol
.
end
(),
i
)
!=
mol
.
end
());
}
}
}
void
runPlatformTests
();
void
runPlatformTests
();
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -243,6 +277,7 @@ int main(int argc, char* argv[]) {
...
@@ -243,6 +277,7 @@ int main(int argc, char* argv[]) {
testEnergyParameterDerivatives
();
testEnergyParameterDerivatives
();
testTabulatedFunction
();
testTabulatedFunction
();
testReordering
();
testReordering
();
testMolecules
();
runPlatformTests
();
runPlatformTests
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment