Eigen3 migration

Dear Avogadro developers,

I want to use Avogadro in my project to visualize molecules and crystal
structures. In my project, I’m using Eigen3 library, so I decide to get
into Avogadro code and change it to support Eigen3 API.

I did step-by-step migration, like described here.
http://eigen.tuxfamily.org/dox/Eigen2SupportModes.html and came to stage
EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS, meaning that new code
should follow 100% Eigen3 API, but in old code still function
compatible with eigen2 exists (“eigen2_” prefix)

I have only one part of code, which is not working like before.
computeGeomInfo() in molecule.cpp

In Eigen3 library LeastSquares module was excluded, so I should write
the code for the fitting by myself. The investigation of the code showed
one problematic part.

void Molecule::computeGeomInfo() const
{

d->center.setZero();
… //some code not affecting d->center variable

 // compute radius and the farthest atom
 d->radius = std::numeric_limits<double>::min();
 foreach (Atom *atom, m_atomList) {
   double distanceToCenter = (*atom->pos() -

d->center).squaredNorm(); //!!! center is Zero
if(distanceToCenter > d->radius) {
d->radius = distanceToCenter;
d->farthestAtom = atom;
}
}
d->radius = sqrt(d->radius);

     ...... // Calculation of the center after

     // Calculate the center of the molecule too
     foreach (Atom *atom, m_atomList) {
       Vector3d *pos = &(*m_atomPos)[atom->id()];
       d->center += *pos;
       atomPositions[i++] = pos;
     }
     d->center /= static_cast<double>(nAtoms);

     ...

I just want to ask some questions.

  1. Are you interesting in the contribution (eigen2->eigen3).
  2. What should I do with geometry info procedure. Should I change the
    radius calculations.

Best regards,
Kirill.

On Fri, Mar 8, 2013 at 6:57 AM, Kirill Okhotnikov
kirill.okhotnikov@gmail.com wrote:

Dear Avogadro developers,

I want to use Avogadro in my project to visualize molecules and crystal
structures. In my project, I’m using Eigen3 library, so I decide to get
into Avogadro code and change it to support Eigen3 API.

I did step-by-step migration, like described here.
http://eigen.tuxfamily.org/dox/Eigen2SupportModes.html and came to stage
EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS, meaning that new code
should follow 100% Eigen3 API, but in old code still function
compatible with eigen2 exists (“eigen2_” prefix)

I have only one part of code, which is not working like before.
computeGeomInfo() in molecule.cpp

In Eigen3 library LeastSquares module was excluded, so I should write
the code for the fitting by myself. The investigation of the code showed
one problematic part.

Is there a topic branch somewhere? That code is pretty old, and could
be rewritten. I haven’t used the porting API but it would be nice to
move to Eigen 3 if it is not too difficult, the Avogadro 2 code is
using Eigen 3 too, along with most new code bases. Seeing the impact
of the change would be nice as I haven’t tried porting Avogadro.

Thanks,

Marcus

Hi,

Glad that you found the Eigen2->Eigen3 porting path useful. It’s true that
Eigen2’s linear regression functions were removed in Eigen3. To complete
this porting, you have to express these mathematical operations directly in
terms of linear solving. You can easily do least squares solving with
Eigen3 using a SVD or QR decomposition (
http://eigen.tuxfamily.org/dox/TutorialLinearAlgebra.html ). I don’t
actually remember what particular kind of linear regression the Eigen2 code
here was doing, but I remember that all what we wanted to do here was find
the plane best fitting the molecule and the function it used,
fitHyperplane, is explained there,
http://eigen.tuxfamily.org/dox-2.0/group__LeastSquares__Module.html
and you can also look at its source code in Eigen2 and easily adapt that to
Eigen3.

Benoit

2013/3/8 Kirill Okhotnikov kirill.okhotnikov@gmail.com

Dear Avogadro developers,

I want to use Avogadro in my project to visualize molecules and crystal
structures. In my project, I’m using Eigen3 library, so I decide to get
into Avogadro code and change it to support Eigen3 API.

I did step-by-step migration, like described here.
http://eigen.tuxfamily.org/dox/Eigen2SupportModes.html and came to stage
EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS, meaning that new code
should follow 100% Eigen3 API, but in old code still function
compatible with eigen2 exists (“eigen2_” prefix)

I have only one part of code, which is not working like before.
computeGeomInfo() in molecule.cpp

In Eigen3 library LeastSquares module was excluded, so I should write
the code for the fitting by myself. The investigation of the code showed
one problematic part.

void Molecule::computeGeomInfo() const
{

d->center.setZero();
… //some code not affecting d->center variable

 // compute radius and the farthest atom
 d->radius = std::numeric_limits<double>::min();
 foreach (Atom *atom, m_atomList) {
   double distanceToCenter = (*atom->pos() -

d->center).squaredNorm(); //!!! center is Zero
if(distanceToCenter > d->radius) {
d->radius = distanceToCenter;
d->farthestAtom = atom;
}
}
d->radius = sqrt(d->radius);

     ...... // Calculation of the center after

     // Calculate the center of the molecule too
     foreach (Atom *atom, m_atomList) {
       Vector3d *pos = &(*m_atomPos)[atom->id()];
       d->center += *pos;
       atomPositions[i++] = pos;
     }
     d->center /= static_cast<double>(nAtoms);

     ...

I just want to ask some questions.

  1. Are you interesting in the contribution (eigen2->eigen3).
  2. What should I do with geometry info procedure. Should I change the
    radius calculations.

Best regards,
Kirill.


Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave™: Endpoint Security, Q1 2013 and “remains a good choice” in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options