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)
def test_no_neighbors_transform_matrix_is_translate(self): from e3fp.fingerprint.fprinter import stereo_indicators_from_shell from e3fp.fingerprint.structs import Shell shell = Shell(0) center_coord = np.random.uniform(3) stereo_indicators_from_shell(shell, [], {0: center_coord}) np.testing.assert_almost_equal(shell.transform_matrix[:3, 3], -center_coord)
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)
def test_empty_tuples_returns_empty(self): from e3fp.fingerprint.fprinter import stereo_indicators_from_shell from e3fp.fingerprint.structs import Shell shell = Shell(0, {}) atom_coords_dict = {0: np.random.uniform(size=3)} atom_tuples = [] stereo_ind = stereo_indicators_from_shell(shell, atom_tuples, atom_coords_dict) self.assertEqual(len(stereo_ind), 0)
def test_no_unique_y_two_evenly_spaced_correct(self): from e3fp.fingerprint.fprinter import stereo_indicators_from_shell from e3fp.fingerprint.structs import Shell shell = Shell(0, {1, 2}) atom_coords_dict = {0: [0, 0, 0], 1: [0, 1, 0], 2: [0, 0, 1]} atom_tuples = [(1, 1, Shell(1)), (1, 1, Shell(2))] stereo_ind = stereo_indicators_from_shell(shell, atom_tuples, atom_coords_dict) # mean should be between 1 and 2, so z cannot be picked, so all 0. expect_stereo_ind = [1, 2] self.assertEqual(stereo_ind, expect_stereo_ind)
def test_no_unique_y_along_poles_correct(self): from e3fp.fingerprint.fprinter import stereo_indicators_from_shell from e3fp.fingerprint.structs import Shell shell = Shell(0, {1, 2, 3}) atom_coords_dict = {0: [0, 0, 0], 1: [0, 1, 0], 2: [0, -5, 0], 3: [0, -10, 0]} atom_tuples = [(1, 1, Shell(1)), (1, 1, Shell(2)), (1, 1, Shell(3))] stereo_ind = stereo_indicators_from_shell(shell, atom_tuples, atom_coords_dict) # mean should be along atom 2/3, so z not be picked, but all at poles. expect_stereo_ind = [-1, 1, 1] self.assertEqual(stereo_ind, expect_stereo_ind)