tmpchem / computational_chemistry

Files used in TMP Chem videos on computational chemistry
209 stars 91 forks source link

Sorting convention for principal axis #5

Closed darismendi closed 5 years ago

darismendi commented 5 years ago

Hi tmpchem

I'm wondering what is the sorting convention you are using to align molecules with respect to the principal axis (ascending or descending)?. I'm trying to compute the gyration tensor of a macromolecule knowing beforehand its relationship to the inertia tensor (see appendix of dx.doi.org/10.1021/jp2065612). In my case, all atoms have the same mass, and I would expect to get the same coordinates for both, the gyration tensor aligned molecule and inertia tensor aligned molecule.

https://github.com/tmpchem/computational_chemistry/blob/329559f5c875d1ab75d5be827534eb8729dffc8e/scripts/geometry_analysis/geometry_analysis.py#L368-L387

Many thanks in advance for your time

tmpchem commented 5 years ago

The convention here is fairly simple: Sort the axes such that the moment of inertia eigenvalues are descending in the order X, Y, Z (i.e. the Z-axis should be the easiest to rotate around, with the least moment of inertia). You can see this on line 378, as the preceding for loops set up a pairwise comparison insertion sort, with a swap operation only occurring when the lower-indexed axis (in the order X, Y, Z) has a lower diagonal element than the following element in the pair. In the case of ties the original order will be retained, though there is no threshold for floating point equivalence here, so any small numerical error will result in tie-breaking.

There are many possible conventions for axis sorting / alignment based on relative moment of inertia eigenvalues and point group symmetries, but this program is designed to be a simple introductory example that can be generally followed by those without much programming experience, so the design choices here are motivated primarily by code simplicity.

I've had other projects in the past that required enumerating the flow chart of every possibility, and that gets pretty involved. Definitely not worth it in this instance.