def test_quaternion_0():
    q = uniform_quaternion(random_state=2)
    eq(np.sum(q**2), np.float64(1.0))
    eq(q.shape, (4, ))

    q2 = uniform_quaternion(size=2)
    eq(np.sum(q2**2, axis=1), np.ones(2))
    eq(q2.shape, (2, 4))

    q2 = uniform_quaternion(size=(6, 6))
    eq(np.sum(q2**2, axis=2), np.ones((6, 6)))
    eq(q2.shape, (6, 6, 4))
Exemple #2
0
def test_quaternion_0():
    q = uniform_quaternion(random_state=2)
    eq(np.sum(q**2), np.float64(1.0))
    eq(q.shape, (4,))

    q2 = uniform_quaternion(size=2)
    eq(np.sum(q2**2, axis=1), np.ones(2))
    eq(q2.shape, (2,4))

    q2 = uniform_quaternion(size=(6,6))
    eq(np.sum(q2**2, axis=2), np.ones((6,6)))
    eq(q2.shape, (6,6,4))
Exemple #3
0
def test_quaternion_1():
    q = uniform_quaternion(random_state=2)
    rot = rotation_matrix_from_quaternion(q)
    
    eq(rot.shape, (3,3))
    eq(np.linalg.det(rot), np.double(1.0))
    eq(np.linalg.inv(rot), rot.T)
Exemple #4
0
def test_lprmsd_3(get_fn):
    # resolve rotation and permutation togetehr
    t1 = md.load(get_fn('alanine-dipeptide-explicit.pdb'))[0]
    t2 = md.load(get_fn('alanine-dipeptide-explicit.pdb'))[0]

    h2o_o_indices = [a.index for a in t1.topology.atoms if a.residue.name == 'HOH' and a.element.symbol == 'O'][0:20]
    h2o_h_indices = [a.index for a in t1.topology.atoms if a.residue.name == 'HOH' and a.element.symbol == 'H'][0:20]
    backbone_indices = [a.index for a in t1.topology.atoms if a.element.symbol in ['C', 'N']][:5]

    # scramble two groups of indices
    t2.xyz[:, random.permutation(h2o_o_indices)] = t2.xyz[:, h2o_o_indices]
    t2.xyz[:, random.permutation(h2o_h_indices)] = t2.xyz[:, h2o_h_indices]

    # offset the backbone indices slightly
    t2.xyz[:, backbone_indices] += 0.001 * random.randn(len(backbone_indices), 3)

    # rotate everything
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    t2.xyz[0].dot(rot)

    print('raw distinguishable indices', backbone_indices)
    atom_indices = np.concatenate((h2o_o_indices, backbone_indices))
    value = md.lprmsd(t2, t1, atom_indices=atom_indices, permute_groups=[h2o_o_indices])
    t1.xyz[:, h2o_o_indices] += random.randn(len(h2o_o_indices), 3)

    print('final value', value)
    assert value[0] < 1e-2
def test_quaternion_1():
    q = uniform_quaternion(random_state=2)
    rot = rotation_matrix_from_quaternion(q)

    eq(rot.shape, (3, 3))
    eq(np.linalg.det(rot), np.double(1.0))
    eq(np.linalg.inv(rot), rot.T)
Exemple #6
0
def test_lprmsd_1():
    # resolve a random rotation with no permutation
    ref = random.randn(1, 50, 3).astype(np.float32)
    mapping = np.arange(50)
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    new = ref[:, mapping].dot(rot)

    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None), permute_groups=[[]])
    assert value[0] < 1e-2
Exemple #7
0
def test_lprmsd_2():
    # resolve a random rotation with some permutation
    ref = random.randn(1, 50, 3).astype(np.float32)
    # first half of the atoms can permute, last 10 are fixed permutation
    mapping = np.concatenate((random.permutation(10), 10 + np.arange(40)))
    rot = rotation_matrix_from_quaternion(uniform_quaternion())
    new = ref[:, mapping].dot(rot)
    
    value = lprmsd(Trajectory(xyz=new, topology=None), Trajectory(xyz=ref, topology=None), permute_groups=[np.arange(10)])
    assert value[0] < 1e-2
Exemple #8
0
def test_quaternion_2():
    q = uniform_quaternion(size=2)
    rot = rotation_matrix_from_quaternion(q)
    
    eq(rot.shape, (2, 3, 3))

    # check 1st rotation matrix
    eq(np.linalg.det(rot[0]), np.double(1.0))
    eq(np.linalg.inv(rot[0]), rot[0].T)
    # check 2nd rotation matrix
    eq(np.linalg.det(rot[1]), np.double(1.0))
    eq(np.linalg.inv(rot[1]), rot[1].T)
def test_quaternion_2():
    q = uniform_quaternion(size=2)
    rot = rotation_matrix_from_quaternion(q)

    eq(rot.shape, (2, 3, 3))

    # check 1st rotation matrix
    eq(np.linalg.det(rot[0]), np.double(1.0))
    eq(np.linalg.inv(rot[0]), rot[0].T)
    # check 2nd rotation matrix
    eq(np.linalg.det(rot[1]), np.double(1.0))
    eq(np.linalg.inv(rot[1]), rot[1].T)