def test_batch_construction(self): mol_batch = NPMol.create_from_batch(batch_atoms=atoms, batch_distances=distances) for i in range(len(distances)): npt.assert_allclose(mol_batch[i].distances, distances[i]) npt.assert_allclose(mol_batch[i].distance_matrix, distance_matrix[i]) npt.assert_equal(mol_batch[i].atoms, atom_types[i]) self.assertTrue(isinstance(mol_batch[i].smiles, str))
def test_empty(self): atoms_empty = np.zeros([batch_size, num_atoms, num_atom_types]) atoms_empty[:, :, -1] = 1 mol_batch = NPMol.create_from_batch(batch_atoms=atoms_empty, batch_distances=distances) for mol in mol_batch: npt.assert_equal(mol.distance_matrix, np.zeros([0, 0])) npt.assert_equal(mol.coordinates, np.zeros([0, 3])) npt.assert_equal(mol.smiles, '') npt.assert_equal(mol.atoms, [])
def test_atom_features(self): data_dir = os.path.join(os.path.dirname(__file__), 'sample_data') trainer = VAETrainer(data_dir, 10, 10) sdf_path = os.path.join(os.path.dirname(__file__), 'sample_mol.sdf') mol_supplier = Chem.SDMolSupplier( sdf_path, removeHs=True) # import molecules from sdf file rdkit_mol = mol_supplier[0] featurizer = DistanceFeaturizer(9, implicit_hydrogen=True) feat_mol = featurizer.featurize(rdkit_mol) coordinates = np.copy(feat_mol.coordinates) coordinates *= -1 # invert coordinates[:, 0] *= -1 # mirror mol = NPMol(atoms=feat_mol.atom_features, coordinates=feat_mol.coordinates) rec_mol = NPMol(atoms=feat_mol.atom_features, coordinates=coordinates) mse, mae = trainer._compute_position_accuracy(mol, rec_mol) np.testing.assert_allclose([mse, mae], [0, 0], atol=1e-5)
def test_padding_removal(self): p_coordinates = np.concatenate((coordinates[0], [[0, 0, 0]])) p_distance_matrix = np.pad(distance_matrix[0], ((0, 1), (0, 1)), mode='constant') p_distances = p_distance_matrix[np.triu_indices(4, 1)] p_atoms = np.concatenate((atoms[0], [[0, 0, 0, 0, 1]])) mol = NPMol(atoms=p_atoms, coordinates=p_coordinates, distance_matrix=p_distance_matrix, distances=p_distances) npt.assert_allclose(mol.distances, distances[0]) npt.assert_allclose(mol.distance_matrix, distance_matrix[0]) npt.assert_allclose(mol.coordinates, coordinates[0]) npt.assert_equal(mol.atoms, atom_types[0])
def test_atom_types(self): mol = NPMol(atoms=atoms[0], coordinates=coordinates[0]) npt.assert_equal(mol.atoms, atom_types[0])
def test_coordinates_provided(self): mol = NPMol(atoms=atoms[0], coordinates=coordinates[0]) npt.assert_allclose(mol.distances, distances[0]) npt.assert_allclose(mol.distance_matrix, distance_matrix[0]) self.assertTrue(isinstance(mol.smiles, str))
def test_distance_matrix_provided(self): mol = NPMol(atoms=atoms[0], distance_matrix=distance_matrix[0]) npt.assert_allclose(mol.distances, distances[0]) self.assertTrue(isinstance(mol.smiles, str)) npt.assert_equal(mol.coordinates.shape, coordinates[0].shape)
def test_none_provided(self): with self.assertRaises(ValueError): _ = NPMol(atoms=atoms)