2

I need to perform a very fast computation of inertia tensors in Python.

The problem is as follows:

Let xyz be a Numpy Array of shape: (samples, atoms, 3) that describes the 3 cartesian coordinates of each atoms in each samples.

The atoms in each sample must be splited into a set of molecules. I need the inertia tensor of each molecule in every sample.

Each molecule contains n atoms and they are ordered in such way that they are grouped together. That is:

   numpy.array( numpy.split(xyz, atoms/n, axis=1).shape )

returns an array of shape: (number of molecules, samples, atoms per molecule, 3), where the first index runs over the molecules.

Notes:

  • It is very similar to the problem solved here, but they compute the inertia tensor of the whole system while I need the inertia tensors of its parts (inertia tensor of each molecule in the system).
  • It would be preferable to obtain an array of inertia tensors.
  • I think that numpy.einsum would be a good alternative (but I find it hard to implement)
  • I can get an array of atomic masses fast and without problems.
  • If it helps, samples is of size 100 to 500 approx., and atoms up to about 20 000 (but the operation runs in many chunks that made a total of about 1E5 samples).
Linus Juhlin
  • 1,175
  • 10
  • 31
user1420303
  • 153
  • 1
  • 9
  • So your problem is vectorizing an easy to write algorithm using loops to gain performance? I would simply use a JIT compiler like numpy here. For example https://stackoverflow.com/a/45403017/4045774 or https://stackoverflow.com/a/45329782/4045774 – max9111 Aug 31 '17 at 21:50

0 Answers0