Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
8d872824
Commit
8d872824
authored
7 years ago
by
Studer Gabriel
Browse files
Options
Downloads
Patches
Plain Diff
Make sure position, velocity etc. information is preserved when reinitializeing openmm context
parent
9de283d4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/mol/mm/doc/simulation.rst
+21
-1
21 additions, 1 deletion
modules/mol/mm/doc/simulation.rst
modules/mol/mm/src/simulation.cc
+19
-5
19 additions, 5 deletions
modules/mol/mm/src/simulation.cc
modules/mol/mm/src/simulation.hh
+2
-0
2 additions, 0 deletions
modules/mol/mm/src/simulation.hh
with
42 additions
and
6 deletions
modules/mol/mm/doc/simulation.rst
+
21
−
1
View file @
8d872824
...
...
@@ -201,6 +201,10 @@ mapped back to the attached structure at any time.
.. method:: AddPositionConstraint(index)
Fixes the position of the particle with index given in the argument.
This requires to reinitialize the internal openmm Context
(this is expensive!). Positions, velocities, forces, energies etc.
are properly preserved but e.g. states of random number generators etc.
might be lost.
:param index: Particle to be fixed
:type index: :class:`int`
...
...
@@ -211,6 +215,10 @@ mapped back to the attached structure at any time.
.. method:: AddPositionConstraints(indices)
Fixes the position of the atoms with the indices given in in the argument.
This requires to reinitialize the internal openmm Context
(this is expensive!). Positions, velocities, forces, energies etc.
are properly preserved but e.g. states of random number generators etc.
might be lost.
:param indices: Particles to be fixed
:type indices: :class:`list`
...
...
@@ -221,6 +229,10 @@ mapped back to the attached structure at any time.
.. method:: ResetPositionConstraints()
Removes all position constraints.
This requires to reinitialize the internal openmm Context
(this is expensive!). Positions, velocities, forces, energies etc.
are properly preserved but e.g. states of random number generators etc.
might be lost.
.. method:: ResetHarmonicBond(index, bond_length, force_constant)
...
...
@@ -347,7 +359,11 @@ mapped back to the attached structure at any time.
.. method:: ResetDistanceConstraint(index, constraint_length)
Update of the distance constraint parameters in the simulation **and**
in the attached :class:`Topology`
in the attached :class:`Topology`.
This requires to reinitialize the internal openmm Context
(this is expensive!). Positions, velocities, forces, energies etc.
are properly preserved but e.g. states of random number generators etc.
might be lost.
:param index: Distance constraint to be reset
:param constraint_length: New constraint length in nm
...
...
@@ -445,6 +461,10 @@ mapped back to the attached structure at any time.
Update of the mass in the simulation **and**
in the attached :class:`Topology`
This requires to reinitialize the internal openmm Context
(this is expensive!). Positions, velocities, forces, energies etc.
are properly preserved but e.g. states of random number generators etc.
might be lost.
:param index: Mass to be reset
:param mass: New mass
...
...
This diff is collapsed.
Click to expand it.
modules/mol/mm/src/simulation.cc
+
19
−
5
View file @
8d872824
...
...
@@ -694,7 +694,7 @@ void Simulation::ResetDistanceConstraint(uint index, Real constraint_length){
int
particle1
,
particle2
;
system_
->
getConstraintParameters
(
index
,
particle1
,
particle2
,
dummy
);
system_
->
setConstraintParameters
(
index
,
particle1
,
particle2
,
constraint_length
);
context_
->
r
einitialize
();
this
->
R
einitialize
Context
();
top_
->
SetDistanceConstraintParameters
(
index
,
constraint_length
);
}
...
...
@@ -703,7 +703,7 @@ void Simulation::AddPositionConstraint(uint index){
throw
ost
::
Error
(
"Provided index exceeds number of atoms!"
);
}
system_
->
setParticleMass
(
index
,
0.0
);
context_
->
r
einitialize
();
this
->
R
einitialize
Context
();
top_
->
AddPositionConstraint
(
index
);
}
...
...
@@ -717,7 +717,7 @@ void Simulation::AddPositionConstraints(const std::vector<uint>& index){
system_
->
setParticleMass
(
*
i
,
0.0
);
top_
->
AddPositionConstraint
(
*
i
);
}
context_
->
r
einitialize
();
this
->
R
einitialize
Context
();
}
void
Simulation
::
ResetPositionConstraints
(){
...
...
@@ -726,7 +726,7 @@ void Simulation::ResetPositionConstraints(){
system_
->
setParticleMass
(
i
,
original_masses
[
i
]);
}
top_
->
ResetPositionConstraints
();
context_
->
r
einitialize
();
this
->
R
einitialize
Context
();
}
void
Simulation
::
ResetHarmonicPositionRestraint
(
uint
index
,
const
geom
::
Vec3
&
ref_position
,
Real
k
,
...
...
@@ -872,7 +872,7 @@ void Simulation::ResetMass(uint index, Real mass){
throw
ost
::
Error
(
"Provided index exceeds number of atoms!"
);
}
system_
->
setParticleMass
(
index
,
mass
);
context_
->
r
einitialize
();
this
->
R
einitialize
Context
();
top_
->
SetMass
(
index
,
mass
);
}
...
...
@@ -896,5 +896,19 @@ void Simulation::SetPeriodicBoxExtents(geom::Vec3& vec){
context_
->
setPeriodicBoxVectors
(
ucell_a
,
ucell_b
,
ucell_c
);
}
void
Simulation
::
ReinitializeContext
()
{
// reinitializing requires to reset all those things!
// Be aware, state of random number generators etc might not be
// preserved!
OpenMM
::
State
state
=
context_
->
getState
(
OpenMM
::
State
::
Positions
|
OpenMM
::
State
::
Velocities
|
OpenMM
::
State
::
Forces
|
OpenMM
::
State
::
Energy
|
OpenMM
::
State
::
Parameters
|
OpenMM
::
State
::
ParameterDerivatives
);
context_
->
reinitialize
();
context_
->
setState
(
state
);
}
}}}
This diff is collapsed.
Click to expand it.
modules/mol/mm/src/simulation.hh
+
2
−
0
View file @
8d872824
...
...
@@ -147,6 +147,8 @@ private:
int
TimeToNextNotification
();
void
ReinitializeContext
();
// loads plugins from directory for OpenMM BUT only once per unique path!
static
void
EnsurePluginsLoaded
(
const
String
&
plugin_path
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment