def helix_axis(sele='all', state=1):
    xform = xform_between_chains('A',
                                 'B',
                                 sele=f'({sele}) and name CA',
                                 state=state)
    axis, ang, cen = hm.axis_ang_cen_of(xform)
    return axis, cen
예제 #2
0
def show_with_axis(worms, idx=0):
    """TODO: Summary

    Args:
        worms (TYPE): Description
        idx (int, optional): Description
    """
    pose = worms.pose(idx, align=0, end=1)
    x_from = worms.positions[idx][worms.criteria.from_seg]
    x_to = worms.positions[idx][worms.criteria.to_seg]
    x = x_to @ np.linalg.inv(x_from)
    axis, ang, cen = homog.axis_ang_cen_of(x)
    np.set_printoptions(precision=20)
    print(x)
    print(axis)
    print(ang)
    print(cen)
    axis *= 100
    showme(pose, name="unit")
    util.xform_pose(x, pose)
    showme(pose, name="sym1")
    util.xform_pose(x, pose)
    showme(pose, name="sym2")
    showline(axis, cen)
    showsphere(cen)
예제 #3
0
    def score(self, segpos, *, verbosity=False, **kw):
        x_from = segpos[self.from_seg]
        x_to = segpos[self.to_seg]
        xhat = x_to @ inv(x_from)
        trans = xhat[..., :, 3]
        if self.nfold is 1:
            angle = hm.angle_of(xhat)
            carterrsq = np.sum(trans[..., :3]**2, axis=-1)
            roterrsq = angle**2
        else:
            if self.origin_seg is not None:
                tgtaxis = segpos[self.origin_seg] @ [0, 0, 1, 0]
                tgtcen = segpos[self.origin_seg] @ [0, 0, 0, 1]
                axis, angle, cen = hm.axis_ang_cen_of(xhat)
                carterrsq = hm.hnorm2(cen - tgtcen)
                roterrsq = (1 - np.abs(hm.hdot(axis, tgtaxis))) * np.pi
            else:  # much cheaper if cen not needed
                axis, angle = hm.axis_angle_of(xhat)
                carterrsq = roterrsq = 0
            carterrsq = carterrsq + hm.hdot(trans, axis)**2
            roterrsq = roterrsq + (angle - self.symangle)**2
            # if self.relweight is not None:
            #     # penalize 'relative' error
            #     distsq = np.sum(trans[..., :3]**2, axis=-1)
            #     relerrsq = carterrsq / distsq
            #     relerrsq[np.isnan(relerrsq)] = 9e9
            #     # too much of a hack??
            #     carterrsq += self.relweight * relerrsq
            if verbosity > 0:
                print('axis', axis[0])
                print('trans', trans[0])
                print('dot trans', hm.hdot(trans, axis)[0])
                print('angle', angle[0] * 180 / np.pi)

        return np.sqrt(carterrsq / self.tol**2 + roterrsq / self.rot_tol**2)
def primary_xform_commutator(units, state=1, **kw):
    print('stub 0:')
    print(units[0].stub)
    closest = None
    for j in range(1, 20):
        x = hm.hinv(units[0].stub) @ units[j].stub
        # print(f'stub {j}:')
        # print(units[j].stub)
        # print(x)
        axis, ang, cen = hm.axis_ang_cen_of(x)
        helical = hm.hdot(axis, x[:, 3])
        print(j, helical, x[2, 3])
        if abs(helical) > 0.01:
            return x
    return None
예제 #5
0
 def alignment(self, segpos, **kwargs):
     if self.origin_seg is not None:
         return inv(segpos[self.origin_seg])
     x_from = segpos[self.from_seg]
     x_to = segpos[self.to_seg]
     xhat = x_to @ inv(x_from)
     axis, ang, cen = hm.axis_ang_cen_of(xhat)
     # print('aln', axis)
     # print('aln', ang * 180 / np.pi)
     # print('aln', cen)
     # print('aln', xhat[..., :, 3])
     dotz = hm.hdot(axis, Uz)[..., None]
     tgtaxis = np.where(dotz > 0, [0, 0, 1, 0], [0, 0, -1, 0])
     align = hm.hrot((axis + tgtaxis) / 2, np.pi, cen)
     align[..., :3, 3] -= cen[..., :3]
     return align
예제 #6
0
파일: vis.py 프로젝트: natteruw/worms
def show_with_axis(worms, idx=0):
    pose = worms.pose(idx, align=0, end=1)
    x_from = worms.positions[idx][worms.criteria.from_seg]
    x_to = worms.positions[idx][worms.criteria.to_seg]
    x = x_to @ np.linalg.inv(x_from)
    axis, ang, cen = homog.axis_ang_cen_of(x)
    np.set_printoptions(precision=20)
    print(x)
    print(axis)
    print(ang)
    print(cen)
    axis *= 100
    showme(pose, name='unit')
    util.xform_pose(x, pose)
    showme(pose, name='sym1')
    util.xform_pose(x, pose)
    showme(pose, name='sym2')
    showline(axis, cen)
    showsphere(cen)