diff --git a/corelib/src/libs/SireVol/triclinicbox.cpp b/corelib/src/libs/SireVol/triclinicbox.cpp index 413b5f2fc..9f6ddad85 100644 --- a/corelib/src/libs/SireVol/triclinicbox.cpp +++ b/corelib/src/libs/SireVol/triclinicbox.cpp @@ -565,6 +565,21 @@ Matrix TriclinicBox::boxMatrix() const return this->cellMatrix(); } +SireUnits::Dimension::Length TriclinicBox::maximumCutoff() const +{ + // If the box is reduced, then use half the minimum diagonal element. + if (this->isReduced()) + { + QList diagonals = {this->v0.x(), this->v1.y(), this->v2.z()}; + return SireUnits::Dimension::Length(*std::min_element(diagonals.begin(), diagonals.end())/2.0); + } + // Otherwise, use half the norm of the smallest box vector. + else + { + return SireUnits::Dimension::Length(this->dist_max); + } +} + /** Return the volume of the central box of this space. */ SireUnits::Dimension::Volume TriclinicBox::volume() const { diff --git a/corelib/src/libs/SireVol/triclinicbox.h b/corelib/src/libs/SireVol/triclinicbox.h index a39028f52..bc3706ada 100644 --- a/corelib/src/libs/SireVol/triclinicbox.h +++ b/corelib/src/libs/SireVol/triclinicbox.h @@ -153,6 +153,9 @@ namespace SireVol QString toString() const; + /** Get the maximum cutoff distance for the triclinic box. */ + SireUnits::Dimension::Length maximumCutoff() const; + /** Get the volume of the triclinic box. */ SireUnits::Dimension::Volume volume() const; diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 5e528c5d1..ca25501ce 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -17,6 +17,9 @@ organisation on `GitHub `__. * Please add an item to this changelog when you create your PR * Correctly set the ``element1`` property in ``sire.morph.create_from_pertfile``. +* Added mising :meth:`~sire.vol.TriclinicBox.maximum_cutoff` method so that + the cutoff is set correctly when creating a :obj:`~sire.system.ForceFieldInfo` + object. `2024.1.0 `__ - April 2024 ------------------------------------------------------------------------------------------ diff --git a/tests/vol/test_triclinic.py b/tests/vol/test_triclinic.py index 52691eb64..c9e929ea5 100644 --- a/tests/vol/test_triclinic.py +++ b/tests/vol/test_triclinic.py @@ -141,3 +141,34 @@ def test_stream(): # Make sure the boxes are the same. assert recovered_box == box + + +def test_max_cutoff(ala_mols): + """ + Test that the maximum cutoff is set correctly. + """ + + # Create a local copy of the molecules. + mols = ala_mols.clone() + + # Create a cubic triclinic space. + + # Set the vectors. + v0 = sr.maths.Vector(50, 0, 0) + v1 = sr.maths.Vector(0, 50, 0) + v2 = sr.maths.Vector(0, 0, 50) + + # Create the space. + space = sr.vol.TriclinicBox(v0, v1, v2) + + # Check the maximum cutoff. + assert space.maximum_cutoff() == 25 * sr.units.angstroms + + # Now set the space property on the molecules. + mols.set_property("space", space) + + # Create a ForceFieldInfo object. + ffinfo = sr.system.ForceFieldInfo(mols) + + # Check the cutoff. This is the maximum cutoff minus 1 angstrom. + assert ffinfo.cutoff() == 24 * sr.units.angstroms