示例#1
0
def superpower_postrefine(idx, CB_OP_C_P, old_Amat):
    Amat = old_Amat
    from LS49.work_pre_experiment.post5_ang_misset import get_item
    from LS49.ML_push.exploratory_missetting import metric
    R = get_item(idx)
    print("get ersatz_postrefined with index", idx)
    C = crystal_orientation.crystal_orientation(
        Amat, crystal_orientation.basis_type.direct)
    C.show(legend="ground truth, P1")
    C2 = C.change_basis(CB_OP_C_P.inverse())
    C2.show(legend="ground truth, C2")
    direct_A = R["integrated_crystal_model"].get_A_inverse_as_sqr(
    )  # from dials model, integration step
    permute = sqr((0, 0, 1, 0, 1, 0, -1, 0, 0))
    sim_compatible = direct_A * permute  # permute columns when post multiplying
    P = crystal_orientation.crystal_orientation(
        sim_compatible, crystal_orientation.basis_type.direct)
    P.show(legend="dials_integrated, C2")
    PR = P.change_basis(CB_OP_C_P)
    PR.show(legend="dials_integrated, primitive setting")
    PRC2 = PR.change_basis(CB_OP_C_P.inverse())  # dials integrated, C2
    cb_op_align = PR.best_similarity_transformation(C, 200, 1)
    align_PR = PR.change_basis(sqr(cb_op_align))
    align_PR.show(legend="dials_integrated, P1, aligned")
    print("alignment matrix", cb_op_align)
    metric_val = metric(align_PR, C)
    print("Key %d aligned angular offset is %12.9f deg." % (idx, metric_val))
    print("Key %d alignC2 angular offset is %12.9f deg." %
          (idx, metric(align_PR.change_basis(CB_OP_C_P.inverse()), C2)))
    minimum = 1000.  # metric_val
    ixm = 0
    iym = 0
    best_Ori_C2 = None
    for ix in range(-10, 11, 2):
        xrotated_Ori = PRC2.rotate_thru((0, 0, 1), ix * 0.01 * math.pi / 180.)
        for iy in range(-10, 11, 2):
            yrotated_Ori = xrotated_Ori.rotate_thru((0, 1, 0),
                                                    iy * 0.01 * math.pi / 180.)
            new_aligned_Ori = yrotated_Ori.change_basis(
                CB_OP_C_P).change_basis(sqr(cb_op_align)).change_basis(
                    CB_OP_C_P.inverse())
            grid_metric_val = metric(new_aligned_Ori, C2)
            if grid_metric_val < minimum:
                ixm = ix
                iym = iy
                best_Ori_C2 = new_aligned_Ori
            #print("ix %4d"%ix,"iy %4d"%iy,"grid search angular offset is %12.9f deg."%(grid_metric_val))
            minimum = min(minimum, grid_metric_val)

    print("Key %d minimC2 angular offset is %12.9f deg." % (idx, minimum),
          "with ix=%d iy=%d" % (ixm, iym))
    best_Ori = best_Ori_C2.change_basis(CB_OP_C_P)
    print(
        "Key %d minimum angular offset is %12.9f deg." %
        (idx, metric(best_Ori, C)), "with ix=%d iy=%d" % (ixm, iym))
    best_Ori.show(legend="superpower, aligned")
    return dict(superpower_postrefine=best_Ori.direct_matrix(),
                dials_refine=align_PR.direct_matrix(),
                coarse_ground_truth=C.direct_matrix())
示例#2
0
  def get_current_angular_offsets(self,rotxyz): # pass in the x,y,z rotations in units of 0.01 degree
    from LS49.ML_push.exploratory_missetting import metric

    updated_mat = self.dials_integrated_P1_aligned.rotate_thru((1.0,0.0,0.0), rotxyz[0] * math.pi* 0.01/180.
                                                 ).rotate_thru((0.0,1.0,0.0), rotxyz[1] * math.pi* 0.01/180.
                                                 ).rotate_thru((0.0,0.0,1.0), rotxyz[2] * math.pi* 0.01/180.)

    metric_P1 = metric(updated_mat,self.ground_truth_P1)
    metric_C2 = metric(updated_mat.change_basis(self.CB_OP_C_P.inverse()) ,self.ground_truth_C2)

    return metric_P1,metric_C2
示例#3
0
 def get_idx_rotation_models(self, idx):
     rotation = sqr(ersatz_all_orientations()[idx])
     Amat = (rotation *
             sqr(self.sfall_main.unit_cell().orthogonalization_matrix())
             ).transpose()
     from LS49.work_pre_experiment.post5_ang_misset import get_item
     from LS49.ML_push.exploratory_missetting import metric
     R = get_item(idx)
     print("coarse ground truth with index", idx)
     C = crystal_orientation.crystal_orientation(
         Amat, crystal_orientation.basis_type.direct)
     C.show(legend="ground truth, P1")
     C2 = C.change_basis(self.CB_OP_C_P.inverse())
     C2.show(legend="ground truth, C2")
     direct_A = R["integrated_crystal_model"].get_A_inverse_as_sqr(
     )  # from dials model, integration step
     permute = sqr((0, 0, 1, 0, 1, 0, -1, 0, 0))
     sim_compatible = direct_A * permute  # permute columns when post multiplying
     P = crystal_orientation.crystal_orientation(
         sim_compatible, crystal_orientation.basis_type.direct)
     P.show(legend="dials_integrated, C2")
     PR = P.change_basis(self.CB_OP_C_P)
     PR.show(legend="dials_integrated, primitive setting")
     PRC2 = PR.change_basis(
         self.CB_OP_C_P.inverse())  # dials integrated, C2
     cb_op_align = PR.best_similarity_transformation(C, 200, 1)
     align_PR = PR.change_basis(sqr(cb_op_align))
     align_PR.show(legend="dials_integrated, P1, aligned")
     print("alignment matrix", cb_op_align)
     metric_val = metric(align_PR, C)
     print("Key %d aligned angular offset is %12.9f deg." %
           (idx, metric_val))
     print(
         "Key %d alignC2 angular offset is %12.9f deg." %
         (idx, metric(align_PR.change_basis(self.CB_OP_C_P.inverse()), C2)))
     # coarse, dials crystal orientation models = C, align_PR
     # apply Rotx:
     align_PR_dx = align_PR.rotate_thru((1.0, 0.0, 0.0),
                                        math.pi * 0.01 / 180.)
     align_PR_dy = align_PR.rotate_thru((0.0, 1.0, 0.0),
                                        math.pi * 0.01 / 180.)
     align_PR_dz = align_PR.rotate_thru((0.0, 0.0, 1.0),
                                        math.pi * 0.01 / 180.)
     self.dials_integrated_P1_aligned = align_PR
     self.ground_truth_P1 = C
     self.ground_truth_C2 = C2
     return (dict(Amat=align_PR.direct_matrix(),
                  Amat_dx=align_PR_dx.direct_matrix(),
                  Amat_dy=align_PR_dy.direct_matrix(),
                  Amat_dz=align_PR_dz.direct_matrix()))
示例#4
0
  def get_incremented_rotation_models(self,rotxyz): # pass in the x,y,z rotations in units of 0.01 degree
    from LS49.ML_push.exploratory_missetting import metric

    updated_mat = self.dials_integrated_P1_aligned.rotate_thru((1.0,0.0,0.0), rotxyz[0] * math.pi* 0.01/180.
                                                 ).rotate_thru((0.0,1.0,0.0), rotxyz[1] * math.pi* 0.01/180.
                                                 ).rotate_thru((0.0,0.0,1.0), rotxyz[2] * math.pi* 0.01/180.)

    metric_val = metric(updated_mat,self.ground_truth_P1)
    print("minimization step, aligned angular offset is %12.9f deg."%(metric_val))
    new_dx = updated_mat.rotate_thru((1.0,0.0,0.0), math.pi* 0.01/180.)
    new_dy = updated_mat.rotate_thru((0.0,1.0,0.0), math.pi* 0.01/180.)
    new_dz = updated_mat.rotate_thru((0.0,0.0,1.0), math.pi* 0.01/180.)
    return (dict(Amat=updated_mat.direct_matrix(),Amat_dx=new_dx.direct_matrix(),
            Amat_dy=new_dy.direct_matrix(), Amat_dz=new_dz.direct_matrix()))