-
Notifications
You must be signed in to change notification settings - Fork 35
TranslateAMolecule
cschaerfe edited this page Feb 20, 2015
·
3 revisions
Rotating an entire molecule, single atom or any other AtomContainer can be done with the help of BALL's TransformationProcessor:
Specify a rotation-matrix:
#include <BALL/MATHS/angle.h>
#include <BALL/COMMON/constants.h>
#include <BALL/MATHS/vector3.h>
#include <BALL/MATHS/matrix44.h>
using namespace BALL;
...
Angle angle = Angle(Constants::PI, true);
Vector3 rotationaxis(1., 0., 0.);
Matrix4x4 mat;
mat.setRotation(angle, rotationaxis); Then create a transformation using the rotation-matrix and apply
#include <BALL/STRUCTURE/geometricTransformations.h>
// create
TransformationProcessor transformation(mat);
// apply
molecule->apply(transformation);Single atoms can be also be transformed by
atom.setPosition(mat * atom.getPosition());Note Since objects are not necessarily located in the origin, move your object under consideration into the origin, then rotate, and move back. Otherwise your object will be shifted around.
#include <BALL/STRUCTURE/geometricTransformations.h>
#include <BALL/STRUCTURE/geometricProperties.h>
...
// compute the translation vector to the origin
GeometricCenterProcessor center;
molecule->apply(center);
Vector3 toOrigin = center.getCenter().negate();
// create the translation
TranslationProcessor translation;
translation.setTranslation(toOrigin);
// translate the molecule
molecule->apply(translation);
/*
* rotate the molecule here as described above
*/
// move the molecule back to its original center
translation.setTranslation(toOrigin.negate());
molecule->apply(translation);
Information on how to determine a transformation between two proteins can be found here.