Skip to content

Commit

Permalink
Merge pull request #190 from OpenBioSim/fix_189
Browse files Browse the repository at this point in the history
Fix issue #189
  • Loading branch information
chryswoods authored Apr 23, 2024
2 parents 4ddb6e4 + 3894035 commit cb69318
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions corelib/src/libs/SireVol/triclinicbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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
{
Expand Down
3 changes: 3 additions & 0 deletions corelib/src/libs/SireVol/triclinicbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.

* 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 <https://github.com/openbiosim/sire/compare/2023.5.2...2024.1.0>`__ - April 2024
------------------------------------------------------------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions tests/vol/test_triclinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb69318

Please sign in to comment.