
On Dec 19, 2008, at 7:14 AM, Dr. Jean-Didier Maréchal wrote:
Dear all,
Based on early queries, I am now using xform coord for most of my scripts. However, now I have a problem because I have mixture between xforms and coord.
For example, I want to place a helium at the center of mass of the molecular and having previously calculated it using xform coordinates... The center of mass is therefore located at another part of the space.
How could I transform on set of coords to the other?
Hi JD, When a new Model is open/created in Chimera, by default it is given the same transformation matrix as the lowest currently-open model. This is based on the presumption that frequently model coordinate systems are related and that therefore it is useful to show them in the relative positions that their raw coordinates imply. This presumption is hosing you: you want your new model to start with an identity matrix as its transformation matrix, since you are basing your model on the transformed coordinates of the existing model(s). So, you need to set your model's transform to be the identity. The first thing you should do is change your code a little so that your placing_points function returns the atom it placed (which is easy since the placeHelium function returns the new helium atom). So the last line of placing_points becomes: return BuildStructure.placeHelium('com', model='scratch', position=center) Then the last line of your script changes from: placing_points(center) to: a = placing_points(center) a.molecule.openState.xform = chimera.Xform.identity() I don't know if your center of mass of calculation will always be restricted to a single model (in your example it is), but if so then you can get away with using coord() instead of xformCoord() and I think your script will work without further changes in that case. --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
Here is the script
from chimera import selection from chimera import Point, Vector, Xform import BuildStructure
def com(sub): for i in range(len(sub.atoms)): sumi=0 center = Vector(0, 0, 0) for a in sub.atoms: sumi += a.element.mass center += a.element.mass * Vector(*a.xformCoord().data()) center_point=Point(center[0]/sumi,center[1]/sumi,center[2]/ sumi) return center_point
def placing_points(center): #pt=Point(center[0]/sum,center[1]/sum,center[2]/sum) #print pt BuildStructure.placeHelium('com', model='scratch', position=center)
ligand = selection.currentResidues()[0] center=com(ligand) placing_points(center)
_______________________________________________ Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-dev