Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions corelib/src/libs/SireCAS/lambdaschedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,20 @@ void LambdaSchedule::addDecoupleStage(const QString &name, bool perturbed_is_dec
this->setEquation(name, "ghost/ghost", "*", this->initial());
this->setEquation(name, "ghost-14", "*", this->initial());

// kappa is fixed to 1.0
this->setEquation(name, "ghost/ghost", "kappa", 1.0);
this->setEquation(name, "ghost-14", "kappa", 1.0);
// stop subtracting the hard Coulomb as the charges in the
// NonbondedForce go to zero, so the intramolecular terms are kept
this->setEquation(name, "ghost/ghost", "kappa", 1.0 - this->lam());
this->setEquation(name, "ghost-14", "kappa", 1.0 - this->lam());
}
else
{
this->setEquation(name, "ghost/ghost", "*", this->final());
this->setEquation(name, "ghost-14", "*", this->final());

// kappa is fixed to 1.0
this->setEquation(name, "ghost/ghost", "kappa", 1.0);
this->setEquation(name, "ghost-14", "kappa", 1.0);
// stop subtracting the hard Coulomb as the charges in the
// NonbondedForce go to zero, so the intramolecular terms are kept
this->setEquation(name, "ghost/ghost", "kappa", this->lam());
this->setEquation(name, "ghost-14", "kappa", this->lam());
}
}

Expand Down
44 changes: 44 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
* Fixed the bond, inverse bond and Morse potential centroid restraint constructors naming
the wrong atom when the two groups overlap, and reallocating the second group on every atom.

* Stop constraining unperturbed heavy-atom bonds at the alchemical junction, reverting
the SOMD1-matching change in 2026.1.0. It destabilised perturbable molecules with large
ghost regions, such as partially mapped macrocycles.

* Fixed a segmentation fault when the OpenMM minimiser raised an exception, since the GIL
wasn't restored before the exception reached Python. A system whose starting energy is
infinite or NaN now raises an error saying so, rather than an unrelated error about the
number of positions.

* Never constrain a bond that is broken or formed by a perturbation, since its atoms are
unbonded at one end state. It was constrained if either atom was light at either end
state, which blew up some ring-breaking simulations.

* Calculate interactions between ghost atoms in the same molecule without a cutoff. They
were truncated at the cutoff, which made the energy discontinuous for molecules larger
than the cutoff when a schedule set ``kappa`` below 1, e.g. to decouple a ligand while
keeping its intramolecular interactions. Energies for other schedules change slightly,
since these interactions are no longer truncated.

* When the OpenMM minimiser fails, it now leaves the context at the last accepted positions,
or the starting positions if those have a lower energy, rather than at a rejected line
search trial point, which could make dynamics blow up immediately. It raises a timeout
error when it times out, and repeated line search failures no longer retry until the
timeout.

* ``PerturbableOpenMMMolecule.get_lever_values()`` no longer reports levers whose values
only change by floating point round-off, e.g. bonded terms that are the same in both
end states.

* Scale ``kappa`` with λ again in ``LambdaSchedule.standard_decouple()``, reverting the
change in 2025.1.0, so that the decoupled molecule keeps its intramolecular electrostatic
interactions. With ``kappa`` fixed they were turned off, so a single-leg decoupling
calculation, e.g. of a hydration free energy, missed the vacuum contribution.

* Fixed the Coulomb interaction of the pair whose bond is broken or formed by a
ring-breaking perturbation, and of the pairs across that bond, when using reaction
field. They were calculated without the reaction field terms, so the end state where
the bond doesn't exist was wrong.

* Scale the Lennard-Jones interaction of the pair whose bond is broken or formed by a
ring-breaking perturbation by ``1 - alpha`` for the Zacharias and Taylor soft-core
forms, as for Beutler. Previously the bonded pair still had a softened Lennard-Jones
interaction in the end state where the bond exists.

`2026.2.0 <https://github.com/openbiosim/sire/compare/2026.1.0...2026.2.0>`__ - September 2026
----------------------------------------------------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions doc/source/tutorial/part07/02_levers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ In this case, as we have a perturbable system, the Force objects used are;
interactions between ghost atoms in the system. Ghost atoms are any atoms
that are ghosts in either end state. It uses parameters that are controlled
by the ``charge``, ``sigma``, ``epsilon``, ``alpha`` and ``kappa`` levers.
Interactions between ghost atoms in the same molecule are calculated
by an
`OpenMM::CustomBondForce <http://docs.openmm.org/latest/api-c++/generated/CustomBondForce.html>`__
in the same force group, in which the electrostatic term has no cutoff,
and which is controlled by the same levers.
* ``ghost/non-ghost``: `OpenMM::CustomNonbondedForce <http://docs.openmm.org/latest/api-c++/generated/CustomNonbondedForce.html>`__.
This models all of the electrostatic (coulomb) and van der Waals (Lennard-Jones)
interactions between the ghost atoms and the non-ghost atoms in the system.
Expand Down
21 changes: 17 additions & 4 deletions doc/source/tutorial/part07/03_ghosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ Ghost atoms are then added to three custom OpenMM Forces:

1. A CustomNonbondedForce called the "ghost/ghost" force. This uses a
custom energy function to calculate the soft-core electrostatic and
LJ interactions between all ghost atoms. It also calculates the
"hard" electrostatic interaction and subtracts this from the
total (to remove the real-space contribution that was calculated
in the standard OpenMM NonBondedForce).
LJ interactions between ghost atoms in different molecules. It also
calculates the "hard" electrostatic interaction and subtracts this
from the total (to remove the real-space contribution that was
calculated in the standard OpenMM NonBondedForce).

Interactions between ghost atoms in the same molecule (other than
excluded and 1-4 pairs) use the same energy function, but are
calculated by a CustomBondForce in which the electrostatic term has
no cutoff. This is in the same force group as the ghost/ghost force,
and is controlled by the same levers. The "hard" electrostatic
interaction for these pairs is added to the NonBondedForce as an
exception. When reaction field is used, a further CustomBondForce in
the same force group as the NonBondedForce adds the difference between
the exception and a normal reaction field interaction. This means that
the end states are unchanged, while the intramolecular electrostatic
interactions are never truncated, which matters when ``kappa`` is less
than 1 for molecules that are larger than the cutoff.

2. A CustomNonbondedForce called the "ghost/non-ghost" force. This uses a
custom energy function to calculate the soft-core electrostatic and
Expand Down
Binary file modified doc/source/tutorial/part07/images/07_06_01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 71 additions & 43 deletions src/sire/morph/_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,63 @@ def evaluate_xml_force(mols, xml, force):
nrg_coul_list = []
nrg_lj_list = []

def evaluate_bonds(bond_force):
"""Evaluate the energy of each bond in a CustomBondForce."""

# Get the energy terms.
terms = list(reversed(bond_force.get("energy").split(";")[1:-1]))

# The LJ term may be cut off, e.g. "coul_nrg+step(0.9-r)*lj_nrg".
import re

match = re.search(r"step\(([^-]+)-r\)", bond_force.get("energy").split(";")[0])
lj_cutoff = float(match.group(1)) if match else None

# Get the parameters for this force.
parameters = [p.get("name") for p in bond_force.find("PerBondParameters")]

# Get all the bond parameters.
bonds = bond_force.find("Bonds").findall("Bond")

# Get the list of atoms.
atoms = mols.atoms()

# Loop over all bonds.
for bond in bonds:
# Get the atoms involved in the bond.
atom_i = atoms[int(bond.get("p1"))]
atom_j = atoms[int(bond.get("p2"))]

# Set the parameters for this bond.
for k, param in enumerate(parameters):
setattr(module, param, float(bond.get(f"param{k + 1}")))

# Get the distance between the particles.
r = measure(atom_i, atom_j).to(nanometer)

# Evaluate the energy term by term.
for term in terms:
# Replace any instances of ^ with **.
term = term.replace("^", "**")

# Split the term into the result and the expression.
result, expression = term.split("=")

# Evaluate the expression.
setattr(module, result, eval(expression))

# Give energies units.
coul_nrg = module.coul_nrg * kJ_per_mol
lj_nrg = module.lj_nrg * kJ_per_mol

if lj_cutoff is not None and r > lj_cutoff:
lj_nrg = 0.0 * kJ_per_mol

# Append the results for this bond.
pairs.append((atom_i, atom_j))
nrg_coul_list.append(coul_nrg)
nrg_lj_list.append(lj_nrg)

# CustomNonbondedForce: ghost-ghost or ghost-nonghost.
if name != "Ghost14BondForce":
# Get the parameters for this force.
Expand All @@ -137,6 +194,8 @@ def evaluate_xml_force(mols, xml, force):
.find("Set2")
]

is_same_set = set(set1) == set(set2)

# Get the exclusions.
exclusions = [
(int(e.get("p1")), int(e.get("p2")))
Expand Down Expand Up @@ -173,8 +232,9 @@ def evaluate_xml_force(mols, xml, force):
# Get the index from set2.
j = set2[y]

# Ignore self-interaction.
if i == j:
# Ignore self-interaction, and count each pair once when
# the two sets are the same.
if i == j or (is_same_set and j < i):
continue

# Check if this pair is excluded.
Expand Down Expand Up @@ -217,49 +277,17 @@ def evaluate_xml_force(mols, xml, force):
nrg_coul_list.append(coul_nrg)
nrg_lj_list.append(lj_nrg)

# Intramolecular ghost/ghost pairs are computed without a cutoff
# in a separate CustomBondForce.
if name == "GhostGhostNonbondedForce":
for bond_force in tree.find("Forces"):
if bond_force.get("name") == "GhostGhostBondForce":
evaluate_bonds(bond_force)
break

# CustomBondForce: ghost-14.
else:
# Get the parameters for this force.
parameters = [p.get("name") for p in force.find("PerBondParameters")]

# Get all the bond parameters.
bonds = force.find("Bonds").findall("Bond")

# Get the list of atoms.
atoms = mols.atoms()

# Loop over all bonds.
for bond in bonds:
# Get the atoms involved in the bond.
atom_i = atoms[int(bond.get("p1"))]
atom_j = atoms[int(bond.get("p2"))]

# Set the parameters for this bond.
for k, param in enumerate(parameters):
setattr(module, param, float(bond.get(f"param{k + 1}")))

# Get the distance between the particles.
r = measure(atom_i, atom_j).to(nanometer)

# Evaluate the energy term by term.
for term in terms:
# Replace any instances of ^ with **.
term = term.replace("^", "**")

# Split the term into the result and the expression.
result, expression = term.split("=")

# Evaluate the expression.
setattr(module, result, eval(expression))

# Give energies units.
coul_nrg = module.coul_nrg * kJ_per_mol
lj_nrg = module.lj_nrg * kJ_per_mol

# Append the results for this bond.
pairs.append((atom_i, atom_j))
nrg_coul_list.append(coul_nrg)
nrg_lj_list.append(lj_nrg)
evaluate_bonds(force)

# Return the results.
return pairs, nrg_coul_list, nrg_lj_list
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ def cyclopropyl_constraint_bug():
return sr.load_test_files("ejm_31_jmc_28.bss")


@pytest.fixture(scope="session")
def macrocycle_ghost_constraints():
return sr.load_test_files("macrocycle_ghost_constraints.bss")


@pytest.fixture(scope="session")
def ring_break_constraints():
return sr.load_test_files("ring_break_constraints.bss")


@pytest.fixture(scope="session")
def zero_lj_mols():
return sr.load_test_files("zero_lj.prm7", "zero_lj.rst7")
Expand Down
Loading
Loading