def test_transform_depth3(self): # This is to test loop backs in the breadth-first search a = Shell(depth=3) a.fit(ALL_DATA) expected_results = numpy.array([ [[0, 0, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0]], [[0, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[2, 2, 0, 0], [1, 1, 1, 1], [2, 2, 0, 0], [2, 1, 1, 0], [4, 1, 0, 0], [3, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 1, 0, 0], [2, 1, 2, 1], [3, 0, 0, 1], [3, 1, 1, 0], [3, 0, 0, 2], [3, 0, 0, 1], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0], [2, 3, 0, 0], [1, 0, 0, 0], [0, 2, 0, 1], [0, 2, 0, 1], [0, 2, 0, 1], [4, 0, 1, 0], [4, 0, 0, 1], [3, 0, 1, 1], [5, 0, 0, 0], [4, 0, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 2, 0, 0], [2, 1, 2, 1], [4, 0, 0, 0], [2, 2, 1, 0], [3, 0, 0, 0], [2, 1, 1, 0], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0], [1, 1, 0, 0], [1, 1, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]] ]) self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
def test_fit_use_coordination(self): a = Shell(depth=1, use_coordination=True) a.fit(ALL_DATA) self.assertEqual( a._elements, set([ 'H0', 'H1', 'O2', 'C4', 'N1', 'C3', 'C2', 'N2', 'N3', 'C1', 'O1', 'O0' ]))
def test_add_unknown(self): a = Shell(add_unknown=True) a.fit([METHANE]) temp = [] for mol in BASE_SHELL: inner = [] for atom in mol: inner.append(atom[:2] + [atom[2] + atom[3]]) temp.append(inner) expected = numpy.array(temp) self.assertTrue((a.transform(ALL_DATA) == expected).all())
def test_transform_use_coordination(self): a = Shell(depth=1, use_coordination=True) a.fit([MID]) expected_results = numpy.array([[[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0]]]) self.assertTrue((a.transform([MID]) == expected_results).all())
def test_transform_use_coordination(self): a = Shell(depth=1, use_coordination=True) a.fit([MID]) expected_results = numpy.array([ [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0]] ]) self.assertTrue((a.transform([MID]) == expected_results).all())
def test_transform_depth2(self): a = Shell(depth=2) a.fit(ALL_DATA) expected_results = numpy.array([[[0, 4, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]], [[1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]], [[1, 0, 1, 1], [2, 1, 0, 0], [2, 1, 0, 0], [2, 1, 0, 0], [2, 0, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [1, 0, 1, 1], [3, 0, 0, 0], [2, 1, 0, 0], [2, 0, 0, 1], [2, 0, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 0, 1], [2, 0, 0, 0], [0, 3, 0, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0, 1], [3, 0, 0, 0], [3, 0, 0, 0], [2, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0], [1, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 1, 0], [1, 0, 2, 0], [3, 0, 0, 0], [2, 1, 0, 0], [3, 0, 0, 0], [1, 1, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 2, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0], [2, 0, 0, 0], [1, 1, 0, 0], [1, 0, 0, 0]]]) self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
def test_transform_depth2(self): a = Shell(depth=2) a.fit(ALL_DATA) expected_results = numpy.array([ [[0, 4, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]], [[1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]], [[1, 0, 1, 1], [2, 1, 0, 0], [2, 1, 0, 0], [2, 1, 0, 0], [2, 0, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [1, 0, 1, 1], [3, 0, 0, 0], [2, 1, 0, 0], [2, 0, 0, 1], [2, 0, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 0, 1], [2, 0, 0, 0], [0, 3, 0, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0, 1], [3, 0, 0, 0], [3, 0, 0, 0], [2, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0], [1, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 1, 0], [1, 0, 2, 0], [3, 0, 0, 0], [2, 1, 0, 0], [3, 0, 0, 0], [1, 1, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 2, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0], [2, 0, 0, 0], [1, 1, 0, 0], [1, 0, 0, 0]] ]) self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
def test_small_to_large_transform(self): a = Shell() a.fit([METHANE]) expected = numpy.array([numpy.array(x)[:, :2].tolist() for x in BASE_SHELL]) self.assertTrue((a.transform(ALL_DATA) == expected).all())
def test_transform(self): a = Shell() a.fit(ALL_DATA) self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
def test_fit(self): a = Shell(depth=1) a.fit(ALL_DATA) self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
def test_get_labels_unknown(self): a = Shell(add_unknown=True) a.fit(ALL_DATA) expected = ('C', 'H', 'N', 'O', UNKNOWN) self.assertEqual(a.get_labels(), expected)
def test_get_labels(self): a = Shell() a.fit(ALL_DATA) expected = ('C', 'H', 'N', 'O') self.assertEqual(a.get_labels(), expected)
def test_large_to_small_transform(self): a = Shell() a.fit([BIG]) self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
def test_small_to_large_transform(self): a = Shell() a.fit([METHANE]) expected = numpy.array( [numpy.array(x)[:, :2].tolist() for x in BASE_SHELL]) self.assertTrue((a.transform(ALL_DATA) == expected).all())
def test_fit_use_coordination(self): a = Shell(depth=1, use_coordination=True) a.fit(ALL_DATA) self.assertEqual(a._elements, ('C1', 'C2', 'C3', 'C4', 'H0', 'H1', 'N1', 'N2', 'N3', 'O0', 'O1', 'O2'))
def test_get_labels_unknown(self): a = Shell(add_unknown=True) a.fit(ALL_DATA) expected = ('C', 'H', 'N', 'O', 'UNKNOWN') self.assertEqual(a.get_labels(), expected)