From: Shyam S. <sa...@ca...> - 2020-09-13 00:27:13
|
Hello -- I am trying to transform an object to align it's major axis with the x-axis at z = 0 in the camera coordinate space. Sample pdb file (just a simple scale bar) is attached. My thought process is as follows: 1. Convert <1, 0, 0> in camera space to model space (vector A) 2. Find vector that corresponds to object's major axis (vector B) 3. Find transformation matrix C that rotates to vector B to vector A 4. Use transform_selection with C Unfortunately, my attempts are without success (see below), perhaps due to my lack of understanding of the pymol coordinate spaces. I see saw two potentially relevant threads here, but I wasn't able to pull things together successfully: https://www.mail-archive.com/pym...@li.../msg14278.html https://sourceforge.net/p/pymol/mailman/message/10098601/ If you have any thoughts here, please let me know! Thanks, Shyam M_to_model = np.array(cmd.get_view()[:9]).reshape(3,3) def to_model(X): return np.matmul(X, M_to_model) # 1. xaxis in model coordinates xaxis_mod = to_model([10, 0, 0]) # 2. major axis of scale in model coordinates scale_orient = cmd.get_extent("scale_25") scale_orient = np.diff(scale_orient, axis=0)[0] print(xaxis_mod, scale_orient) # 3. matrix to rotate scale to axis # From scipy.spatial.transform.rotation # https://github.com/scipy/scipy/blob/01d8bfb6f239df4ce70c799b9b485b53733c9911/scipy/spatial/transform/rotation.py#L1854-L1982 rot, _ = align_vectors([scale_orient], [xaxis_mod]) # 4. transform scale def reformat_3x3(rot): \ return [*rot[0], 0, \ *rot[1], 0, \ *rot[2], 0, \ 0, 0, 0, 1] cmd.transform_selection("scale_25", reformat_3x3(rot), homogenous=1) |