Skip to content

Commit

Permalink
Fixed a bug where the lambdalever cache incorrectly used the cached c…
Browse files Browse the repository at this point in the history
…onstraint lengths

instead of the cached bond lengths
  • Loading branch information
chryswoods committed Feb 26, 2024
1 parent 50fd5ee commit 50cc723
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 20 additions & 5 deletions wrapper/Convert/SireOpenMM/lambdalever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ MolLambdaCache &MolLambdaCache::operator=(const MolLambdaCache &other)
const QVector<double> &MolLambdaCache::morph(const LambdaSchedule &schedule,
const QString &force,
const QString &key,
const QString &subkey,
const QVector<double> &initial,
const QVector<double> &final) const
{
auto nonconst_this = const_cast<MolLambdaCache *>(this);

QString force_key = force + "::" + key;
QString cache_key = key;

if (not subkey.isEmpty())
cache_key += ("::" + subkey);

QString force_key = force + "::" + cache_key;

QReadLocker lkr(&(nonconst_this->lock));

Expand Down Expand Up @@ -108,16 +114,16 @@ const QVector<double> &MolLambdaCache::morph(const LambdaSchedule &schedule,
{
// all forces use the same equation for this lever
// Look for the common equation
it = cache.constFind(key);
it = cache.constFind(cache_key);

if (it == cache.constEnd())
{
// we're the first - create the values and cache them
nonconst_this->cache.insert(key,
nonconst_this->cache.insert(cache_key,
schedule.morph("*", key,
initial, final, lam_val));

it = cache.constFind(key);
it = cache.constFind(cache_key);
}

// save this equation for this force for this lever
Expand All @@ -127,6 +133,15 @@ const QVector<double> &MolLambdaCache::morph(const LambdaSchedule &schedule,
return cache.constFind(force_key).value();
}

const QVector<double> &MolLambdaCache::morph(const LambdaSchedule &schedule,
const QString &force,
const QString &key,
const QVector<double> &initial,
const QVector<double> &final) const
{
return this->morph(schedule, force, key, QString(), initial, final);
}

//////
////// Implementation of LeverCache
//////
Expand Down Expand Up @@ -783,7 +798,7 @@ double LambdaLever::setLambda(OpenMM::Context &context,
{
const auto morphed_constraint_length = cache.morph(
schedule,
"bond", "bond_length",
"bond", "bond_length", "constraint",
r0_0, r0_1);

for (int j = 0; j < idxs.count(); ++j)
Expand Down
6 changes: 6 additions & 0 deletions wrapper/Convert/SireOpenMM/lambdalever.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ namespace SireOpenMM
const QVector<double> &initial,
const QVector<double> &final) const;

const QVector<double> &morph(const SireCAS::LambdaSchedule &schedule,
const QString &force, const QString &key,
const QString &subkey,
const QVector<double> &initial,
const QVector<double> &final) const;

private:
QHash<QString, QVector<double>> cache;
QReadWriteLock lock;
Expand Down

0 comments on commit 50cc723

Please sign in to comment.