attentionbydesign / tymera

Custom Scripts
GNU General Public License v3.0
0 stars 0 forks source link

Accelerator for lineup_models() #15

Open attentionbydesign opened 1 week ago

attentionbydesign commented 1 week ago

Should be an easy fix, already got an empty toggle_lineup function or something similar in custom accelerators that can help edited

attentionbydesign commented 6 days ago

Not easy, because still need a way to toggle back.

  1. Prior to even moving the models into lineup view, gotta save their current state. This means something like remembering

    • location of centroid
    • orientation of major axis
  2. When reverting back, you get the current centroid and axis, and calculate the transformation that got it there. In theory applying the inverse of that should revert the position and orientation.

So far, this seems to work fine with translations. However, rotations might be complicated by how the COFR is defined. If using the major axes as defined by the atoms of the structure, imagine if an arrow shaped model pointing up (ie positive y) positioned far from the origin is turned 90 degrees about the z-axis so that it is now pointing to the right (positive x) with cofr as center of the model (i.e. chimera defines as center of the bounding sphere of displayed and active atoms of a model, not necessarily the centroid). So you try and revert its orientation by rotating -90 about an axis perpendicular to the initial arrow and current arrow direction. In this case, that should potentially work, but model is far from the origin, so its centroid pt will get translated up and to the left as it is rotated -90 (more like revolved around) about the global Z axis.

In theory, shouldn't it be fine as long as you translate it after rotating?

For some reason, it simply is not working...

Some things to try for rotation:

attentionbydesign commented 5 days ago

localXform is problematic in that any transformations are based on the local coordinate system, in which the axes might not be defined the same (e.g., rotating about X in local could be Y or Z in global).

Issue with using bestLine from StructMeasure was that the sign/polarity of a given axis can randomly flip with certain orientations. i.e., even slightly rotating (<20 degrees) might randomly flip the sign, which means the direction of rotation would be flipped randomly.

Went back to the idea of calculating the transformation matrix between two different sets of atom coordinates using numpy. Converted this back to a chimera Xform object, then broke it down to substituent rotation and translation operations, then combined them back into the one function revertSpatialConfig(mol, saved_coords).

Further Tasks:

This should probably not have any issues with sequence/order, as they will each be based on the global coordinate system which doesn't shift or rotate. The camera merely zooms in or out, but moving all models is the proxy for panning; not sure if the camera actually can pan.

attentionbydesign commented 4 days ago

Saving coordinates to a dictionary worked! See second to last commit for today.

Some issues / potential improvements:

In the case of moving a subset of models back relative to all models, regardless of the global: you can first revert that subset, then apply the inverse of whatever transformation would have reverted the other models.

Example: By default , models #1-5 are pointing their local y axes in the positive Z direction of global, as with most volumes. This position is saved into init_p. You rotate by 90 about X to align the Y axes. Then you move model #3 away from the rest in the +X direction. Then you rotate it about Z to look at its different sides.

To reset without ending up all the way back at initial_p, you only initially revert #3 back to its position in inital_p, but then you get the transformation that would have reverted #1-2,4-5 and apply its inverse to #3.

Why do we have reason to believe that a single xf would be shared by those four different models? Because they were not activated. But what if you activate #4 only and move it around after moving #3? And then you only want to revert #3? Then perhaps make a conditonal that checks to see if any of the unselected models (ie not trying to revert) have a different transformation from the rest; if so, pick the most common! Ultimately, if almost all the models were moved around, then perhaps we need to specify which model you want to revert the selected model relative to; e.g., if #3 is a ligand bound to #5, and #4 is another ligand, you move both #3 and #4 but want to revert back #3 only --> gotta specify you want to revert with respect to #5, then it should revert #3 back to inital_p first, then take the inverse of whatever would have reverted #5 and apply it to #3. Regardless of where you move either model, their relative positions are encoded in initial_p.

Arithmetic Analogy: Within initial_p, say #3 was at position A, and #5 was at position B. You move them to C and D respectively, where C-D does not equal A-B. You move #3 C +(A-C) = A. Then, move it fr@om A: A+(D-B)=E. Subtract D from both sides: E-D = A-B. So regardless of what C and D are, you can always get #3 to position E which is the same distance from D as A was from B.