avogadrolibs icon indicating copy to clipboard operation
avogadrolibs copied to clipboard

Centroid is not created at correct position

Open matterhorn103 opened this issue 11 months ago • 3 comments

Avogadro version: (please complete the following information from the About box):

  • Avogadrolibs: 1.99.0
  • Qt: 5.15.2

Desktop version: (please complete the following information):

  • OS: openSUSE Tumbleweed
  • Version: 20240318 AppImage (Nightly but maybe a week old)

Describe the bug Build > Add Centroid doesn't put the centroid in the correct place but instead a very large x value (y and z seem correct).

To Reproduce Steps to reproduce the behavior:

The coordinates in the coordinate editor after adding a centroid for a cyclopentane ring:

C -4.113527 0.316425 0.000000 C -5.183343 2.094432 0.000013 H -0.574506 3.569662 0.899734 H -4.383103 -0.239449 0.873632 H -4.362473 -0.196962 -0.905185 C -3.405321 4.083372 0.000070 H -5.798374 2.152369 -0.873647 H -5.820881 2.154459 0.857242 C -1.039678 3.224507 0.000076 H -3.556076 4.682475 -0.873571 H -3.549994 4.658202 0.890878 C -0.904067 0.723253 0.000092 H -0.543563 3.592610 -0.873577 H -0.429724 0.327520 0.873759 H -0.334561 0.248164 -0.771176 Xx 381.170813 2.088398 0.000050

Presumably the same coordinates, minus the centroid, should reproduce the same centroid.

matterhorn103 avatar Mar 21 '24 15:03 matterhorn103

Hi, @matterhorn103 I attempted to replicate the issue involving the centroid but was unsuccessful. Everything seems to be functioning properly on my end. I created a molecule of ethane (C2H6) and navigated to the build menu, where I added a centroid. Afterward, I logged the positions of the atoms and centroid, and they appeared to be accurate. Is there another method you suggest for reproducing the bug? My apologies if I am misunderstanding your request.

Atom 1: (-9.47656, 1.24692, 0)
Atom 2: (3.19798, 1.32027, -3.49332e-05)
Atom 3: (-9.83792, 2.0566, -0.598943)
Atom 4: (-9.82787, 0.320286, -0.403532)
Atom 5: (-9.83387, 1.35767, 1.00248)
Atom 6: (3.55529, 1.20951, -1.00251)
Atom 7: (3.54929, 2.2469, 0.403497)
Atom 8: (3.55934, 0.510585, 0.598908)
Centroid: (-3.13929, 1.28359, -1.74666e-05)


Here's the screenshot: Screenshot from 2024-04-07 16-45-50

perminder-17 avatar Apr 07 '24 11:04 perminder-17

With your coordinates for ethane the centroid is also generated incorrectly for me. It is produced at: Xx 416.923210 1.283593 -0.000017

Weirdly when I try to reproduce my original bug I still get an incorrect centroid, but not at the same coordinates as before. Now it reproducibly appears at: Xx 221.100054 2.092736 -0.000702.

This is a different PC but still OpenSUSE Tumbleweed and the AppImage of Avogadro. It is interesting that the numbers produced should be different for the same input coordinates.

What version of Avogadro are you using?

matterhorn103 avatar Apr 08 '24 12:04 matterhorn103

I'm having trouble understanding why the centroid isn't correctly positioned along the x-axis in your case. There also seems to be a slight variance in the centroid position for the y and z axes on the cyclopentane ring. After reviewing the codebase and examining the calculations, everything appears to be in order. I even logged the values for the centroid and atom coordinates, and they seem accurate.

Here's the screenshot for cyclopentane ring:-

Screenshot from 2024-04-09 04-20-43

I think it might not actually be a bug in the code, but rather a system-specific issue. Different PCs may behave differently when calculating the centroid. I'm using version 1.99.0 of Avogadro and have tested both the Appimage download and the source download, with consistent and correct results. May @ghutchis have some insights regarding the bug you are facing.

perminder-17 avatar Apr 08 '24 22:04 perminder-17