Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature bonds #121

Merged
merged 10 commits into from
Oct 30, 2023
10 changes: 8 additions & 2 deletions corelib/src/libs/SireIO/amberrst7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,15 @@ SireMaths::Vector AmberRst7::boxDimensions() const
}

/** Return the parsed box angles */
SireMaths::Vector AmberRst7::boxAngles() const
QVector<SireUnits::Dimension::Angle> AmberRst7::boxAngles() const
{
return box_angs;
QVector<SireUnits::Dimension::Angle> angs(3);

angs[0] = box_angs.x() * SireUnits::degree;
angs[1] = box_angs.y() * SireUnits::degree;
angs[2] = box_angs.z() * SireUnits::degree;

return angs;
}

/** Return this parser constructed from the passed filename */
Expand Down
4 changes: 3 additions & 1 deletion corelib/src/libs/SireIO/amberrst7.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "SireMaths/vector.h"

#include "SireUnits/dimensions.h"

SIRE_BEGIN_HEADER

namespace SireIO
Expand Down Expand Up @@ -112,7 +114,7 @@ namespace SireIO
QVector<SireMaths::Vector> velocities() const;

SireMaths::Vector boxDimensions() const;
SireMaths::Vector boxAngles() const;
QVector<SireUnits::Dimension::Angle> boxAngles() const;

protected:
void addToSystem(SireSystem::System &system, const PropertyMap &map) const;
Expand Down
41 changes: 41 additions & 0 deletions corelib/src/libs/SireMol/mover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "dihedralid.h"
#include "improperid.h"

#include "atomvelocities.h"

#include "tostring.h"

#include "SireMaths/align.h"
Expand Down Expand Up @@ -697,6 +699,25 @@ void MoverBase::translate(MoleculeData &moldata, const AtomSelection &selected_a
}
}

/** Rotate the velocities (in 'vels') of the specified selected
atoms using the rotation matrix 'rotmat'.
This function assumes that coords and selected_atoms are compatible */
void rotate_velocities(AtomVelocities &vels, const AtomSelection &selected_atoms,
const Matrix &rotmat)
{
if (selected_atoms.selectedNone())
return;

auto velocities = vels.toVector(selected_atoms);

for (auto &velocity : velocities)
{
velocity = Velocity3D(rotmat * velocity.value());
}

vels.copyFrom(velocities, selected_atoms);
}

/** Rotate the selected atoms in the molecule whose data
is in 'moldata' using the rotation matrix 'rotmat'
around the point 'point', using 'coord_property'
Expand Down Expand Up @@ -737,6 +758,26 @@ void MoverBase::rotate(MoleculeData &moldata, const AtomSelection &selected_atom
moldata.setProperty(center_property.source(), VectorProperty(SireMaths::rotate(center, rotmat, point)));
}
}

// should we rotate the velocities too?
bool rotate_velocities = false;

if (map.specified("rotate_velocities"))
{
rotate_velocities = map["rotate_velocities"].value().asABoolean();
}

PropertyName vel_property = map["velocity"];

if (rotate_velocities and moldata.hasProperty(vel_property))
{
auto velocities = moldata.property(vel_property).asA<AtomVelocities>();

::rotate_velocities(velocities, selected_atoms, rotmat);

if (vel_property.hasSource())
moldata.setProperty(vel_property.source(), velocities);
}
}

/** Transform the selected atoms in the molecule whose data
Expand Down
8 changes: 8 additions & 0 deletions corelib/src/libs/SireSystem/forcefieldinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ void ForceFieldInfo::setCutoffType(QString cutoff_type)
void ForceFieldInfo::setCutoffType(QString s_cutoff_type,
const PropertyMap &map)
{
if (s_cutoff_type == "auto")
{
if (this->space().isPeriodic())
s_cutoff_type = "PME";
else
s_cutoff_type = "RF";
}

auto cutoff_type = string_to_cutoff_type(s_cutoff_type);

if (cutoff_type == NO_CUTOFF)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/blogposts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enables :mod:`sire` to perform GPU-accelerated molecular dynamics simulations.
GPU-accelerated free energies
-----------------------------

* `GPU-accelerated free energies <https://www.openbiosim.org/sire-diaries-gpu-accelerated-free-energies/>`__
* `GPU-accelerated free energies <https://www.openbiosim.org/sire-diaries-gpu-free-energy/>`__

In this fourth post, written around the 2023.4 release,
we show how the OpenMM integration has been extended to
Expand Down
37 changes: 35 additions & 2 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
`2023.5.0 <https://github.com/openbiosim/sire/compare/2023.4.0...2023.5.0>`__ - December 2023
---------------------------------------------------------------------------------------------

* Added a new :mod:`sire.options` module that contains new
:cls:`sire.options.Option` objects to represent configurable options.
These include documentation, and make it easier to validate and expose
possible values of configurable options. The API docs for
:cls:`~sire.options.Option` shows how to create your own Option type.
The unit test in ``tests/options/test_options.py`` show how to use
the options. This is integrated into the sire/OpenMM layer.

* Have :cls:`~sire.io.parser.RST7` return a list of angles from the
``box_angles()`` function, rather than a :cls:`~sire.maths.Vector`.
This prevents the confusing behaviour where the angles are wrongly
shown in units of angstroms... This fixes issues #106.

* Added a new :func:`sire.maths.rotate` function, and added the option
(default True) to rotate velocities as well as coordinates when usign
a cursor to rotate molecule views. This fixes issue #103.

* Extended the ``.atom(s)``, ``.residue(s)``, ``.bond(s)`` and all other
indexing functions so that you can pass in an existing view or views as
the key. This lets you look up views in a container by other views, e.g.
``mols.bond(mols.atoms()[0], mols.atoms()[1])`` would return the bond
between the first two atoms in the container ``mols``. Also added
a ``error_on_missing`` flag to the ``atoms``, ``residues``, ``bonds`` etc
functions, so that you get a ``KeyError`` exception if there is no match,
and ``error_on_missing`` is ``True``. For example,
``mols.atoms("element C", error_on_missing=True)`` would raise an exception
if there are no carbon atoms in this container. This is default ``False``
to keep existing behaviour, but we would recommend setting this to ``True``
and would like to change the default in the future.

* Please add an item to this changelog when you create your PR

`2023.4.1 <https://github.com/openbiosim/sire/compare/2023.4.0...2023.4.1>`__ - October 2023
---------------------------------------------------------------------------------------------

* Fixed regression introduced in 2023.4.0 that meant that removed the constraints
from water molecules that had no internal bonds. These waters would blow up
as there was nothing holding them together. The need for these constraints is
Expand All @@ -35,8 +70,6 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
* Fixed an issue where the vacuum dynamics and minimisation simulations still
had a spurious periodic box added when ``.commit()`` was called.

* Please add an item to this changelog when you create your PR

`2023.4.0 <https://github.com/openbiosim/sire/compare/2023.3.0...2023.4.0>`__ - October 2023
--------------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion recipes/sire/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package:
name: {{ name }}
version: {{ environ.get('GIT_DESCRIBE_TAG', 'PR') }}
version: {{ environ.get('GIT_DESCRIBE_TAG', 'PR').replace('-','') }}

source:
git_url: SIRE_REMOTE
Expand Down
1 change: 1 addition & 0 deletions src/sire/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ add_subdirectory (mm)
add_subdirectory (mol)
add_subdirectory (morph)
add_subdirectory (move)
add_subdirectory (options)
add_subdirectory (restraints)
add_subdirectory (search)
add_subdirectory (stream)
Expand Down
1 change: 1 addition & 0 deletions src/sire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ def _convert(id):
mol = _lazy_import.lazy_module("sire.mol")
morph = _lazy_import.lazy_module("sire.morph")
move = _lazy_import.lazy_module("sire.move")
options = _lazy_import.lazy_module("sire.options")
qt = _lazy_import.lazy_module("sire.qt")
restraints = _lazy_import.lazy_module("sire.restraints")
search = _lazy_import.lazy_module("sire.search")
Expand Down
19 changes: 19 additions & 0 deletions src/sire/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ def __propertymap_set(obj, key, value):
PropertyMap.__orig__set = PropertyMap.set
PropertyMap.set = __propertymap_set

def __propertymap_get_string(obj, key: str):
"""
Return the string value associated with the passed 'key'

This returns 'key' if there is no value associated
"""
key = str(key)
if obj.specified(key):
val = obj[key]

if val.has_value():
return val.value().as_string()
else:
return val.source()
else:
return key

PropertyMap.get_string = __propertymap_get_string


def create_map(values, extras=None):
"""Construct a PropertyMap from the
Expand Down
64 changes: 58 additions & 6 deletions src/sire/maths/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"kabasch_fit",
"Matrix",
"pi",
"rotate",
"RanGenerator",
"Sphere",
"Torsion",
Expand Down Expand Up @@ -47,6 +48,58 @@
align = _Maths.align


def rotate(
point, angle=None, axis=None, matrix=None, quaternion=None, center=None
):
"""
Rotate the passed point by the passed angle and axis, or the
passed matrix, or the passed quaternion, optionally centering
the rotation about the passed center.

point: sire.maths.Vector
The vector to be rotated

angle: (float or angle)
The angle to rotate by - this is interpreted as
degrees if you pass in a float. Otherwise use
sire.units.degrees or sire.units.radians to specify
the angle unit. This is superseded by the
matrix and quaternion arguments.

axis: sire.maths.Vector (or anything that can convert to a Vector)
The vector about which to rotate. If this is not
specified, and no other rotation specification is
used, then the rotation is about the z axis.
This is superseded by the matrix and
quaternion arguments.

quaternion: sire.maths.Quaternion
The Quaternion description of the rotation. Note that,
if you pass this, then the angle, axis and matrix
arguments will be ignored.

matrix: sire.maths.Matrix
The 3x3 rotation matrix that describes the rotation.
Note that, if you pass this, then the angle and axis
arguments will be ignored. This is superseded by
the quaternion argument.

center: sire.maths.Vector
The center of rotation. Defaults to (0,0,0) if not set.

Returns: sire.maths.Vector
The rotated vector
"""
q = create_quaternion(
angle=angle, axis=axis, matrix=matrix, quaternion=quaternion
)

if center is None:
center = Vector(0, 0, 0)

return _Maths.rotate(point, q.to_matrix(), center)


def create_quaternion(angle=None, axis=None, matrix=None, quaternion=None):
"""Create a quaternion from the passed angle and axis
of the passed rotation matrix. If a rotation
Expand Down Expand Up @@ -103,15 +156,14 @@ def create_quaternion(angle=None, axis=None, matrix=None, quaternion=None):

from ..units import degrees

try:
angle = float(angle) * degrees
except TypeError:
pass

try:
valid_angle = angle.has_same_units(degrees)
except Exception:
valid_angle = False
try:
angle = float(angle) * degrees
valid_angle = True
except Exception:
valid_angle = False

if not valid_angle:
raise TypeError(
Expand Down
Loading
Loading