On Jul 28, 2010, at 5:30 PM, Jozef Lewandowski wrote:
Hi everybody,
Lately, I have been using "measure inertia" command a lot. For my
purposes I needed to visualize the inertia axes as arrows instead of the
default ellipsoid. I used the vectors from the reply log to write BILD
files defining the arrows for the inertia axes.
Is there an easy way to script just that? Or differently, is there an
easy way to visualize as arrows inertia axes for peptide planes in a
protein?
Hi Jozef,
Let's say that the atoms you want to base the axes on are selected then:
from chimera.selection import currentAtoms, numpyArrayFromAtoms
coords = numpyArrayFromAtoms(currentAtoms())
would give you a numpy array of the atoms coordinates. Then:
from numpy.linalg import svd
centroid = coords.mean(0)
centered = coords - centroid
ignore, vals, vecs = svd(centered)
would give you the eigenvalues, eigenvectors, and centroid of the selection. BTW, the above was gleaned from nosing around StructMeasure/__init__.py. Similarly, by nosing around the new Metal Geometry tool (specifically MetalGeom/gui.py, available only in the daily build), we find some code for constructing BILD arrows on the fly:
bildString = ".color orange\n"
for val, vec in zip(vals, vecs):
bildString += ".arrow %g %g %g %g %g %g .1 .2 .9\n" % (
centroid[0], centroid[1], centroid[2],
centroid[0] + val[0] * vec[0],
centroid[1] + val[1] * vec[1],
centroid[2] + val[2] * vec[2])
from StringIO import StringIO
bild = StringIO(bildString)
mol = currentAtoms()[0].molecule
from chimera import openModels
openModels.open(bild, type="Bild", identifyAs="inertial axes", sameAs=mol)
Putting all the above in a .py file and opening it in Chimera will show the inertial axes on the display and list them as a model in the Model Panel.
--Eric
Eric Pettersen