From 2ca86cbad05e39e5f1ba9a3b50b2f75b3cbc9161 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Wed, 4 Nov 2026 11:56:46 +0000 Subject: [PATCH] Backport fixes from PR #517. [ci skip] --- corelib/src/libs/SireMM/anglerestraints.cpp | 4 +- corelib/src/libs/SireMM/bondrestraints.cpp | 21 ++-- corelib/src/libs/SireMM/boreschrestraints.cpp | 4 +- .../src/libs/SireMM/dihedralrestraints.cpp | 7 +- .../src/libs/SireMM/inversebondrestraints.cpp | 35 +++--- .../libs/SireMM/morsepotentialrestraints.cpp | 115 +++++++++--------- .../src/libs/SireMM/positionalrestraints.cpp | 15 ++- tests/convert/test_openmm_restraints.py | 15 +++ .../test_centroid_restraint_overlap.py | 24 ++++ tests/restraints/test_restraints_add.py | 20 +++ .../SireOpenMM/sire_to_openmm_system.cpp | 40 ++++-- 11 files changed, 185 insertions(+), 115 deletions(-) create mode 100644 tests/restraints/test_centroid_restraint_overlap.py create mode 100644 tests/restraints/test_restraints_add.py diff --git a/corelib/src/libs/SireMM/anglerestraints.cpp b/corelib/src/libs/SireMM/anglerestraints.cpp index 70f22b904..2cc36a260 100644 --- a/corelib/src/libs/SireMM/anglerestraints.cpp +++ b/corelib/src/libs/SireMM/anglerestraints.cpp @@ -468,7 +468,7 @@ AngleRestraints AngleRestraints::operator+(const AngleRestraint &restraint) cons { AngleRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -483,7 +483,7 @@ AngleRestraints AngleRestraints::operator+(const AngleRestraints &restraints) co { AngleRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/bondrestraints.cpp b/corelib/src/libs/SireMM/bondrestraints.cpp index b87aba1f1..961213afe 100644 --- a/corelib/src/libs/SireMM/bondrestraints.cpp +++ b/corelib/src/libs/SireMM/bondrestraints.cpp @@ -163,14 +163,14 @@ BondRestraint::BondRestraint(const QList &atoms0, throw SireError::invalid_arg(QObject::tr( "You cannot have an overlap in atoms between the two groups. Atom " "%1 appears in both!") - .arg(sorted.at(0)), + .arg(atom), CODELOC); atms1.append(atom); } - - atms1.squeeze(); } + + atms1.squeeze(); } /** Copy constructor */ @@ -375,8 +375,7 @@ QDataStream &operator>>(QDataStream &ds, BondRestraints &bndrests) { SharedDataStream sds(ds); - sds >> bndrests.r >> bndrests.use_pbc - >> static_cast(bndrests); + sds >> bndrests.r >> bndrests.use_pbc >> static_cast(bndrests); } else throw version_error(v, "1,2", r_bndrests, CODELOC); @@ -505,10 +504,10 @@ QString BondRestraints::toString() const } return QObject::tr("BondRestraints( name=%1, size=%2, use_pbc=$3\n%4\n)") - .arg(this->name()) - .arg(n) - .arg(this->use_pbc ? "true" : "false") - .arg(parts.join("\n")); + .arg(this->name()) + .arg(n) + .arg(this->use_pbc ? "true" : "false") + .arg(parts.join("\n")); } /** Return whether or not this is empty */ @@ -674,7 +673,7 @@ BondRestraints BondRestraints::operator+(const BondRestraint &restraint) const { BondRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -689,7 +688,7 @@ BondRestraints BondRestraints::operator+(const BondRestraints &restraints) const { BondRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/boreschrestraints.cpp b/corelib/src/libs/SireMM/boreschrestraints.cpp index 4c500d337..5672a7dd1 100644 --- a/corelib/src/libs/SireMM/boreschrestraints.cpp +++ b/corelib/src/libs/SireMM/boreschrestraints.cpp @@ -599,7 +599,7 @@ BoreschRestraints BoreschRestraints::operator+(const BoreschRestraint &restraint { BoreschRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -614,7 +614,7 @@ BoreschRestraints BoreschRestraints::operator+(const BoreschRestraints &restrain { BoreschRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/dihedralrestraints.cpp b/corelib/src/libs/SireMM/dihedralrestraints.cpp index 8ef7b254b..61a733739 100644 --- a/corelib/src/libs/SireMM/dihedralrestraints.cpp +++ b/corelib/src/libs/SireMM/dihedralrestraints.cpp @@ -251,8 +251,7 @@ QDataStream &operator>>(QDataStream &ds, DihedralRestraints &dihrests) { SharedDataStream sds(ds); - sds >> dihrests.r >> dihrests.use_pbc - >> static_cast(dihrests); + sds >> dihrests.r >> dihrests.use_pbc >> static_cast(dihrests); } else throw version_error(v, "1,2", r_dihrests, CODELOC); @@ -468,7 +467,7 @@ DihedralRestraints DihedralRestraints::operator+(const DihedralRestraint &restra { DihedralRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -483,7 +482,7 @@ DihedralRestraints DihedralRestraints::operator+(const DihedralRestraints &restr { DihedralRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/inversebondrestraints.cpp b/corelib/src/libs/SireMM/inversebondrestraints.cpp index c110c0a70..b1ea91e02 100644 --- a/corelib/src/libs/SireMM/inversebondrestraints.cpp +++ b/corelib/src/libs/SireMM/inversebondrestraints.cpp @@ -91,8 +91,8 @@ InverseBondRestraint::InverseBondRestraint() * using the specified force constant and flat-bottom well-width */ InverseBondRestraint::InverseBondRestraint(qint64 atom0, qint64 atom1, - const SireUnits::Dimension::HarmonicBondConstant &k, - const SireUnits::Dimension::Length &r0) + const SireUnits::Dimension::HarmonicBondConstant &k, + const SireUnits::Dimension::Length &r0) : ConcreteProperty(), _k(k), _r0(r0) { @@ -115,9 +115,9 @@ InverseBondRestraint::InverseBondRestraint(qint64 atom0, qint64 atom1, * and flat-bottom well width */ InverseBondRestraint::InverseBondRestraint(const QList &atoms0, - const QList &atoms1, - const SireUnits::Dimension::HarmonicBondConstant &k, - const SireUnits::Dimension::Length &r0) + const QList &atoms1, + const SireUnits::Dimension::HarmonicBondConstant &k, + const SireUnits::Dimension::Length &r0) : ConcreteProperty(), _k(k), _r0(r0) { @@ -163,14 +163,14 @@ InverseBondRestraint::InverseBondRestraint(const QList &atoms0, throw SireError::invalid_arg(QObject::tr( "You cannot have an overlap in atoms between the two groups. Atom " "%1 appears in both!") - .arg(sorted.at(0)), + .arg(atom), CODELOC); atms1.append(atom); } - - atms1.squeeze(); } + + atms1.squeeze(); } /** Copy constructor */ @@ -375,8 +375,7 @@ QDataStream &operator>>(QDataStream &ds, InverseBondRestraints &bndrests) { SharedDataStream sds(ds); - sds >> bndrests.r >> bndrests.use_pbc - >> static_cast(bndrests); + sds >> bndrests.r >> bndrests.use_pbc >> static_cast(bndrests); } else throw version_error(v, "1", r_bndrests, CODELOC); @@ -413,7 +412,7 @@ InverseBondRestraints::InverseBondRestraints(const QList & } InverseBondRestraints::InverseBondRestraints(const QString &name, - const InverseBondRestraint &restraint) + const InverseBondRestraint &restraint) : ConcreteProperty(name) { if (not restraint.isNull()) @@ -421,7 +420,7 @@ InverseBondRestraints::InverseBondRestraints(const QString &name, } InverseBondRestraints::InverseBondRestraints(const QString &name, - const QList &restraints) + const QList &restraints) : ConcreteProperty(name) { for (const auto &restraint : restraints) @@ -505,10 +504,10 @@ QString InverseBondRestraints::toString() const } return QObject::tr("InverseBondRestraints( name=%1, size=%2, use_pbc=%3\n%4\n)") - .arg(this->name()) - .arg(n) - .arg(this->use_pbc ? "true" : "false") - .arg(parts.join("\n")); + .arg(this->name()) + .arg(n) + .arg(this->use_pbc ? "true" : "false") + .arg(parts.join("\n")); } /** Return whether or not this is empty */ @@ -674,7 +673,7 @@ InverseBondRestraints InverseBondRestraints::operator+(const InverseBondRestrain { InverseBondRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -689,7 +688,7 @@ InverseBondRestraints InverseBondRestraints::operator+(const InverseBondRestrain { InverseBondRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/morsepotentialrestraints.cpp b/corelib/src/libs/SireMM/morsepotentialrestraints.cpp index 666f7426c..e2b6bef3d 100644 --- a/corelib/src/libs/SireMM/morsepotentialrestraints.cpp +++ b/corelib/src/libs/SireMM/morsepotentialrestraints.cpp @@ -91,9 +91,9 @@ MorsePotentialRestraint::MorsePotentialRestraint() * using the specified force constant and well depth (dissociation energy) */ MorsePotentialRestraint::MorsePotentialRestraint(qint64 atom0, qint64 atom1, - const SireUnits::Dimension::HarmonicBondConstant &k, - const SireUnits::Dimension::Length &r0, - const SireUnits::Dimension::MolarEnergy &de) + const SireUnits::Dimension::HarmonicBondConstant &k, + const SireUnits::Dimension::Length &r0, + const SireUnits::Dimension::MolarEnergy &de) : ConcreteProperty(), _k(k), _r0(r0), _de(de) { @@ -116,63 +116,63 @@ MorsePotentialRestraint::MorsePotentialRestraint(qint64 atom0, qint64 atom1, * and dissociation energy */ MorsePotentialRestraint::MorsePotentialRestraint(const QList &atoms0, - const QList &atoms1, - const SireUnits::Dimension::HarmonicBondConstant &k, - const SireUnits::Dimension::Length &r0, - const SireUnits::Dimension::MolarEnergy &de) -: ConcreteProperty(), -_k(k), _r0(r0), _de(de) + const QList &atoms1, + const SireUnits::Dimension::HarmonicBondConstant &k, + const SireUnits::Dimension::Length &r0, + const SireUnits::Dimension::MolarEnergy &de) + : ConcreteProperty(), + _k(k), _r0(r0), _de(de) { -if (atoms0.isEmpty() or atoms1.isEmpty()) -return; + if (atoms0.isEmpty() or atoms1.isEmpty()) + return; -// remove duplicates -atms0.reserve(atoms0.count()); + // remove duplicates + atms0.reserve(atoms0.count()); -auto sorted = atoms0; -std::sort(sorted.begin(), sorted.end()); + auto sorted = atoms0; + std::sort(sorted.begin(), sorted.end()); -atms0.append(sorted.at(0)); + atms0.append(sorted.at(0)); -for (const auto &atom : sorted) -{ -if (atom != atms0.last()) -atms0.append(atom); -} + for (const auto &atom : sorted) + { + if (atom != atms0.last()) + atms0.append(atom); + } -atms0.squeeze(); + atms0.squeeze(); -// now the same for atoms1 -atms1.reserve(atoms1.count()); + // now the same for atoms1 + atms1.reserve(atoms1.count()); -sorted = atoms1; -std::sort(sorted.begin(), sorted.end()); + sorted = atoms1; + std::sort(sorted.begin(), sorted.end()); -if (atms0.indexOf(sorted.at(0)) != -1) -throw SireError::invalid_arg(QObject::tr( - "You cannot have an overlap in atoms between the two groups. Atom " - "%1 appears in both!") - .arg(sorted.at(0)), - CODELOC); + if (atms0.indexOf(sorted.at(0)) != -1) + throw SireError::invalid_arg(QObject::tr( + "You cannot have an overlap in atoms between the two groups. Atom " + "%1 appears in both!") + .arg(sorted.at(0)), + CODELOC); -atms1.append(sorted.at(0)); + atms1.append(sorted.at(0)); -for (const auto &atom : sorted) -{ -if (atom != atms1.last()) -{ -if (atms0.indexOf(atom) != -1) -throw SireError::invalid_arg(QObject::tr( - "You cannot have an overlap in atoms between the two groups. Atom " - "%1 appears in both!") - .arg(sorted.at(0)), - CODELOC); - -atms1.append(atom); -} + for (const auto &atom : sorted) + { + if (atom != atms1.last()) + { + if (atms0.indexOf(atom) != -1) + throw SireError::invalid_arg(QObject::tr( + "You cannot have an overlap in atoms between the two groups. Atom " + "%1 appears in both!") + .arg(atom), + CODELOC); + + atms1.append(atom); + } + } -atms1.squeeze(); -} + atms1.squeeze(); } /** Copy constructor */ @@ -387,8 +387,7 @@ QDataStream &operator>>(QDataStream &ds, MorsePotentialRestraints &morser_morsep { SharedDataStream sds(ds); - sds >> morser_morsepotentialrests.r >> morser_morsepotentialrests.use_pbc - >> static_cast(morser_morsepotentialrests); + sds >> morser_morsepotentialrests.r >> morser_morsepotentialrests.use_pbc >> static_cast(morser_morsepotentialrests); } else throw version_error(v, "1,2", r_morsepotentialrests, CODELOC); @@ -425,7 +424,7 @@ MorsePotentialRestraints::MorsePotentialRestraints(const QList(name) { if (not restraint.isNull()) @@ -433,7 +432,7 @@ MorsePotentialRestraints::MorsePotentialRestraints(const QString &name, } MorsePotentialRestraints::MorsePotentialRestraints(const QString &name, - const QList &restraints) + const QList &restraints) : ConcreteProperty(name) { for (const auto &restraint : restraints) @@ -517,10 +516,10 @@ QString MorsePotentialRestraints::toString() const } return QObject::tr("MorsePotentialRestraints( name=%1, size=%2, use_pbc=%3\n%4\n)") - .arg(this->name()) - .arg(n) - .arg(this->use_pbc ? "use_pbc=True" : "use_pbc=False") - .arg(parts.join("\n")); + .arg(this->name()) + .arg(n) + .arg(this->use_pbc ? "use_pbc=True" : "use_pbc=False") + .arg(parts.join("\n")); } /** Return whether or not this is empty */ @@ -686,7 +685,7 @@ MorsePotentialRestraints MorsePotentialRestraints::operator+(const MorsePotentia { MorsePotentialRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -701,7 +700,7 @@ MorsePotentialRestraints MorsePotentialRestraints::operator+(const MorsePotentia { MorsePotentialRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/corelib/src/libs/SireMM/positionalrestraints.cpp b/corelib/src/libs/SireMM/positionalrestraints.cpp index cd3ac6902..5dfd5a335 100644 --- a/corelib/src/libs/SireMM/positionalrestraints.cpp +++ b/corelib/src/libs/SireMM/positionalrestraints.cpp @@ -314,8 +314,7 @@ QDataStream &operator>>(QDataStream &ds, PositionalRestraints &posrests) { SharedDataStream sds(ds); - sds >> posrests.r >> posrests.use_pbc - >> static_cast(posrests); + sds >> posrests.r >> posrests.use_pbc >> static_cast(posrests); } else throw version_error(v, "1,2", r_posrests, CODELOC); @@ -444,10 +443,10 @@ QString PositionalRestraints::toString() const } return QObject::tr("PositionalRestraints( name=%1, size=%2, use_pbc=%3\n%4\n)") - .arg(this->name()) - .arg(n) - .arg(this->use_pbc ? "true" : "false") - .arg(parts.join("\n")); + .arg(this->name()) + .arg(n) + .arg(this->use_pbc ? "true" : "false") + .arg(parts.join("\n")); } /** Return whether or not this is empty */ @@ -613,7 +612,7 @@ PositionalRestraints PositionalRestraints::operator+(const PositionalRestraint & { PositionalRestraints ret(*this); ret += restraint; - return *this; + return ret; } /** Add restraints onto the list */ @@ -628,7 +627,7 @@ PositionalRestraints PositionalRestraints::operator+(const PositionalRestraints { PositionalRestraints ret(*this); ret += restraints; - return *this; + return ret; } /** Set whether or not periodic boundary conditions are to be used */ diff --git a/tests/convert/test_openmm_restraints.py b/tests/convert/test_openmm_restraints.py index fe808b55d..befb019a3 100644 --- a/tests/convert/test_openmm_restraints.py +++ b/tests/convert/test_openmm_restraints.py @@ -84,6 +84,21 @@ def test_openmm_distance_restraints(ala_mols, openmm_platform): assert (new_coords[0] - new_coords[1]).length().value() == pytest.approx(5.0, 1e-2) +@pytest.mark.skipif( + "openmm" not in sr.convert.supported_formats(), + reason="openmm support is not available", +) +def test_openmm_restraint_atom_out_of_range(ala_mols, openmm_platform): + mols = ala_mols + + restraints = sr.restraints.distance( + mols, atoms0=mols[0][0], atoms1=mols[-1][0], r0="5A" + ) + + with pytest.raises(Exception, match="out of range"): + mols[0:2].dynamics(restraints=restraints, platform=openmm_platform) + + @pytest.mark.skipif( "openmm" not in sr.convert.supported_formats(), reason="openmm support is not available", diff --git a/tests/restraints/test_centroid_restraint_overlap.py b/tests/restraints/test_centroid_restraint_overlap.py new file mode 100644 index 000000000..563a44d26 --- /dev/null +++ b/tests/restraints/test_centroid_restraint_overlap.py @@ -0,0 +1,24 @@ +import pytest +import sire as sr + + +@pytest.mark.parametrize( + "build", + [ + lambda a0, a1: sr.mm.BondRestraint( + a0, a1, sr.u("1 kcal mol-1 A-2"), sr.u("1 A") + ), + lambda a0, a1: sr.mm.InverseBondRestraint( + a0, a1, sr.u("1 kcal mol-1 A-2"), sr.u("1 A") + ), + lambda a0, a1: sr.mm.MorsePotentialRestraint( + a0, a1, sr.u("1 kcal mol-1 A-2"), sr.u("1 A"), sr.u("1 kcal mol-1") + ), + ], +) +def test_centroid_restraint_overlap_names_atom(build): + restraint = build([1, 2], [3, 4]) + assert restraint.is_centroid_restraint() + + with pytest.raises(Exception, match="Atom 7 appears in both"): + build([5, 7], [3, 7]) diff --git a/tests/restraints/test_restraints_add.py b/tests/restraints/test_restraints_add.py new file mode 100644 index 000000000..9d845be9f --- /dev/null +++ b/tests/restraints/test_restraints_add.py @@ -0,0 +1,20 @@ +import pytest +import sire as sr + + +@pytest.mark.parametrize( + "build", + [ + lambda m: sr.restraints.distance(m, atoms0=m[0][0], atoms1=m[0][1]), + lambda m: sr.restraints.inverse_distance(m, atoms0=m[0][0], atoms1=m[0][1]), + lambda m: sr.restraints.positional(m, atoms=m[0][0]), + lambda m: sr.restraints.angle(m, atoms=m[0][0:3]), + lambda m: sr.restraints.dihedral(m, atoms=m[0][0:4]), + ], +) +def test_restraints_add(ala_mols, build): + restraints = build(ala_mols) + + assert len(restraints) == 1 + assert len(restraints + restraints) == 2 + assert len(restraints + restraints[0]) == 2 diff --git a/wrapper/Convert/SireOpenMM/sire_to_openmm_system.cpp b/wrapper/Convert/SireOpenMM/sire_to_openmm_system.cpp index e625d7fd0..0ef55c83f 100644 --- a/wrapper/Convert/SireOpenMM/sire_to_openmm_system.cpp +++ b/wrapper/Convert/SireOpenMM/sire_to_openmm_system.cpp @@ -66,6 +66,22 @@ using SireSystem::ForceFieldInfo; using namespace SireOpenMM; +/** Return the OpenMM particle index of the restrained atom at 'atom_idx', + * raising an exception if it is outside the system. + */ +int _to_real_atom(qint64 atom_idx, const QVector &real_atoms) +{ + if (atom_idx < 0 or atom_idx >= real_atoms.count()) + throw SireError::invalid_index(QObject::tr( + "Restraint atom index %1 is out of range for a system " + "with %2 atoms.") + .arg(atom_idx) + .arg(real_atoms.count()), + CODELOC); + + return real_atoms[atom_idx]; +} + /** Add all of the Boresch restraints from 'restraints' to the * passed systen, which is being acted on by the passed LambdaLever. * The number of real (non-anchor) atoms in the OpenMM::System is 'natoms' @@ -252,8 +268,8 @@ void _add_boresch_restraints(const SireMM::BoreschRestraints &restraints, for (int i = 0; i < 3; ++i) { - particles[i] = real_atoms[restraint.receptorAtoms()[i]]; - particles[i + 3] = real_atoms[restraint.ligandAtoms()[i]]; + particles[i] = _to_real_atom(restraint.receptorAtoms()[i], real_atoms); + particles[i + 3] = _to_real_atom(restraint.ligandAtoms()[i], real_atoms); if (particles[i] < 0 or particles[i] >= natoms or particles[i + 3] < 0 or particles[i + 3] >= natoms) @@ -345,8 +361,8 @@ void _add_bond_restraints(const SireMM::BondRestraints &restraints, for (const auto &restraint : atom_restraints) { - int atom0_index = real_atoms[restraint.atom0()]; - int atom1_index = real_atoms[restraint.atom1()]; + int atom0_index = _to_real_atom(restraint.atom0(), real_atoms); + int atom1_index = _to_real_atom(restraint.atom1(), real_atoms); if (atom0_index < 0 or atom0_index >= natoms) throw SireError::invalid_index(QObject::tr( @@ -415,8 +431,8 @@ void _add_inverse_bond_restraints(const SireMM::InverseBondRestraints &restraint for (const auto &restraint : atom_restraints) { - int atom0_index = real_atoms[restraint.atom0()]; - int atom1_index = real_atoms[restraint.atom1()]; + int atom0_index = _to_real_atom(restraint.atom0(), real_atoms); + int atom1_index = _to_real_atom(restraint.atom1(), real_atoms); if (atom0_index < 0 or atom0_index >= natoms) throw SireError::invalid_index(QObject::tr( @@ -492,8 +508,8 @@ void _add_morse_potential_restraints(const SireMM::MorsePotentialRestraints &res for (const auto &restraint : atom_restraints) { - int atom0_index = real_atoms[restraint.atom0()]; - int atom1_index = real_atoms[restraint.atom1()]; + int atom0_index = _to_real_atom(restraint.atom0(), real_atoms); + int atom1_index = _to_real_atom(restraint.atom1(), real_atoms); if (atom0_index < 0 or atom0_index >= natoms) throw SireError::invalid_index(QObject::tr( @@ -591,7 +607,7 @@ void _add_positional_restraints(const SireMM::PositionalRestraints &restraints, // we need to add all of the positions as anchor particles for (const auto &restraint : atom_restraints) { - int atom_index = real_atoms[restraint.atom()]; + int atom_index = _to_real_atom(restraint.atom(), real_atoms); if (atom_index < 0 or atom_index >= natoms) throw SireError::invalid_index(QObject::tr( @@ -728,7 +744,7 @@ void _add_rmsd_restraints(const SireMM::RMSDRestraints &restraints, for (int i = 0; i < n_particles; ++i) { - particles[i] = real_atoms[restraint.atoms()[i]]; + particles[i] = _to_real_atom(restraint.atoms()[i], real_atoms); } // Extract reference positions and convert to correct units @@ -817,7 +833,7 @@ void _add_angle_restraints(const SireMM::AngleRestraints &restraints, for (int i = 0; i < 3; ++i) { - particles[i] = real_atoms[restraint.atoms()[i]]; + particles[i] = _to_real_atom(restraint.atoms()[i], real_atoms); } std::vector parameters; @@ -882,7 +898,7 @@ void _add_dihedral_restraints(const SireMM::DihedralRestraints &restraints, for (int i = 0; i < 4; ++i) { - particles[i] = real_atoms[restraint.atoms()[i]]; + particles[i] = _to_real_atom(restraint.atoms()[i], real_atoms); } std::vector parameters;