Hi Fabien,

On Thu, May 19, 2011 at 5:09 AM, Archambault Fabien
<fabien.archamba...@nanotimes.fr> wrote:
> I believe hte function I have to use is Avogadro.Navigate.rotate
> Its help is:
>  rotate( (GLWidget)arg1, (object)arg2, (float)arg3, (float)arg4,
> (float)arg5) -> None :
>  Rotate about center by deltaX, deltaY, and deltaZ in the x, y and z
> axes A generalization of the rotate() and tilt() methods.

That method will rotate the camera, not the molecule. To rotate the
molecule itself, you will need to manually set each atom's position
using the Molecule.pos() and Molecule.setPos() functions (I think that
is the correct python syntax?).

There is a tutorial extension that shows how to rotate selected atoms
around an arbitrary vector -- it is in C++, but should offer some help
as to how a rotation can be performed. The source code can be found in
libavogadro/examples/thirdPartyExtensions/04-RotateSelection/rotateselectionextension.cpp
of the avogadro master branch.

The function that actually performs the rotation is here:

https://github.com/cryos/avogadro/blob/master/libavogadro/examples/thirdPartyExtensions/04-RotateSelection/rotateselectionextension.cpp#L107

The key bits are:

Eigen::AngleAxis<double> rot (angle * DEG_TO_RAD, axis.normalized());

This essentially constructs a rotation matrix 'rot' using the
Eigen::AngleAxis transform from an angle and axis vector.

Then it's a matter of iterating through the atoms and applying the rotation:

    for (int i = 0; i < selected.size(); i++) {
      atom = qobject_cast<Atom*>(selected.at(i));
      // you'll probably want 'atom = mymolecule.atoms().at(i)' in your app
      // instead of the above line
      coord = *atom->pos(); // extract coordinate
      coord -= offset; // Optional: offset the rotation axis
      coord = rot * coord; // Apply rotation
      coord += offset; // reset offset
      atom->setPos(coord); // Set new coordinate
    }

Hope this helps,

Dave

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-discuss

Reply via email to