예제 #1
0
    def test_stereo_sets_correct_transform_matrix(self):
        from e3fp.fingerprint.fprinter import stereo_indicators_from_shell
        from e3fp.fingerprint.array_ops import project_to_plane, \
                                               make_transform_matrix, \
                                               transform_array
        from e3fp.fingerprint.structs import Shell

        shell = Shell(0, {1, 2})
        atom_coords = np.asarray([[0,  0,   0.],
                                  [0,  2.,  0.],  # -> y
                                  [0,  0,   3.]],  # -> z
                                 dtype=np.float)
        atom_tuples = [(1, 1, Shell(1)),  # -> y
                       (5, 5, Shell(2))]  # -> z
        for i in range(20):
            rand_trans = np.random.uniform(size=3)*100
            rand_y = np.random.uniform(size=3)*10
            rand_v = np.random.uniform(size=3)*20
            rand_z = project_to_plane(rand_v, rand_y)*30
            rand_transform_mat = make_transform_matrix(np.zeros(3), rand_y,
                                                       rand_z)
            trans_mat = np.identity(4, dtype=np.float)
            trans_mat[:3, 3] = rand_trans
            rand_transform_mat = np.dot(trans_mat, rand_transform_mat)

            new_coords = transform_array(rand_transform_mat, atom_coords)
            reverse_trans_mat = np.linalg.inv(rand_transform_mat)

            np.testing.assert_almost_equal(
                atom_coords, transform_array(reverse_trans_mat, new_coords))

            atom_coords_dict = dict(list(zip(list(range(3)), new_coords)))
            stereo_indicators_from_shell(shell, atom_tuples, atom_coords_dict)
            np.testing.assert_almost_equal(shell.transform_matrix,
                                           reverse_trans_mat)
예제 #2
0
    def test_stereo_indicators_for_frame(self):
        from e3fp.fingerprint.fprinter import stereo_indicators_from_shell
        from e3fp.fingerprint.array_ops import project_to_plane,\
                                               make_transform_matrix,\
                                               transform_array
        from e3fp.fingerprint.structs import Shell

        shell = Shell(0, {1, 2, 3})
        atom_coords = np.asarray([[0,  0,   0.],
                                  [1, -0.5, 0.],
                                  [0,  2.,  0.],  # -> y
                                  [0,  0,   3.]],  # -> z
                                 dtype=np.float)
        atom_tuples = [(1, 1, Shell(2)),  # -> y
                       (2, 1, Shell(1)),
                       (5, 5, Shell(3))]  # -> z
        for i in range(20):
            rand_trans = np.random.uniform(size=3)*100
            rand_y = np.random.uniform(size=3)*10
            rand_v = np.random.uniform(size=3)*20
            rand_z = project_to_plane(rand_v, rand_y)*30
            rand_transform_mat = make_transform_matrix(np.zeros(3), rand_y,
                                                       rand_z)
            new_coords = transform_array(rand_transform_mat, atom_coords)
            np.testing.assert_almost_equal(
                atom_coords, transform_array(
                    np.linalg.inv(rand_transform_mat), new_coords))
            new_coords += rand_trans

            atom_coords_dict = dict(list(zip(list(range(4)), new_coords)))
            stereo_ind = stereo_indicators_from_shell(shell, atom_tuples,
                                                      atom_coords_dict)
            # 2 is chosen for y, 3 for z
            expect_stereo_ind = [1, -5, 2]
            self.assertEqual(stereo_ind, expect_stereo_ind)