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
adb3cda7
Commit
adb3cda7
authored
Jan 05, 2017
by
peastman
Browse files
Added more error checking to constraints
parent
a51caf73
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
openmmapi/src/ContextImpl.cpp
openmmapi/src/ContextImpl.cpp
+17
-3
No files found.
openmmapi/src/ContextImpl.cpp
View file @
adb3cda7
...
...
@@ -56,12 +56,13 @@ const static char CHECKPOINT_MAGIC_BYTES[] = "OpenMM Binary Checkpoint\n";
ContextImpl
::
ContextImpl
(
Context
&
owner
,
const
System
&
system
,
Integrator
&
integrator
,
Platform
*
platform
,
const
map
<
string
,
string
>&
properties
)
:
owner
(
owner
),
system
(
system
),
integrator
(
integrator
),
hasInitializedForces
(
false
),
hasSetPositions
(
false
),
integratorIsDeleted
(
false
),
lastForceGroups
(
-
1
),
platform
(
platform
),
platformData
(
NULL
)
{
if
(
system
.
getNumParticles
()
==
0
)
int
numParticles
=
system
.
getNumParticles
();
if
(
numParticles
==
0
)
throw
OpenMMException
(
"Cannot create a Context for a System with no particles"
);
// Check for errors in virtual sites and massless particles.
for
(
int
i
=
0
;
i
<
system
.
getN
umParticles
()
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n
umParticles
;
i
++
)
{
if
(
system
.
isVirtualSite
(
i
))
{
if
(
system
.
getParticleMass
(
i
)
!=
0.0
)
throw
OpenMMException
(
"Virtual site has nonzero mass"
);
...
...
@@ -71,14 +72,23 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
throw
OpenMMException
(
"A virtual site cannot depend on another virtual site"
);
}
}
set
<
pair
<
int
,
int
>
>
constraintAtoms
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
i
++
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
particle1
==
particle2
)
throw
OpenMMException
(
"A constraint cannot connect a particle to itself"
);
if
(
particle1
<
0
||
particle2
<
0
||
particle1
>=
numParticles
||
particle2
>=
numParticles
)
throw
OpenMMException
(
"Illegal particle index in constraint"
);
double
mass1
=
system
.
getParticleMass
(
particle1
);
double
mass2
=
system
.
getParticleMass
(
particle2
);
if
((
mass1
==
0.0
&&
mass2
!=
0.0
)
||
(
mass2
==
0.0
&&
mass1
!=
0.0
))
throw
OpenMMException
(
"A constraint cannot involve a massless particle"
);
pair
<
int
,
int
>
atoms
=
make_pair
(
min
(
particle1
,
particle2
),
max
(
particle1
,
particle2
));
if
(
constraintAtoms
.
find
(
atoms
)
!=
constraintAtoms
.
end
())
throw
OpenMMException
(
"The System has two constraints between the same atoms. This will produce a singular constraint matrix."
);
constraintAtoms
.
insert
(
atoms
);
}
// Validate the list of properties.
...
...
@@ -170,7 +180,7 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
for
(
size_t
i
=
0
;
i
<
forceImpls
.
size
();
++
i
)
forceImpls
[
i
]
->
initialize
(
*
this
);
integrator
.
initialize
(
*
this
);
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
setVelocities
(
*
this
,
vector
<
Vec3
>
(
system
.
getN
umParticles
()
));
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
setVelocities
(
*
this
,
vector
<
Vec3
>
(
n
umParticles
));
}
ContextImpl
::~
ContextImpl
()
{
...
...
@@ -259,10 +269,14 @@ void ContextImpl::setPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3
}
void
ContextImpl
::
applyConstraints
(
double
tol
)
{
if
(
!
hasSetPositions
)
throw
OpenMMException
(
"Particle positions have not been set"
);
applyConstraintsKernel
.
getAs
<
ApplyConstraintsKernel
>
().
apply
(
*
this
,
tol
);
}
void
ContextImpl
::
applyVelocityConstraints
(
double
tol
)
{
if
(
!
hasSetPositions
)
throw
OpenMMException
(
"Particle positions have not been set"
);
applyConstraintsKernel
.
getAs
<
ApplyConstraintsKernel
>
().
applyToVelocities
(
*
this
,
tol
);
}
...
...
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