def test_reader2(self): sdf_reader = SDFReader("input/CID_22898828.sdf") mol = sdf_reader.next() self.assertEqual(mol.title, "22898828") self.assertEqual(mol.size, 14) self.assertEqual(len(mol.graph.edges), 13) self.assert_(frozenset([4,6]) in mol.graph.edges) self.assertEqual(len(mol.graph.independent_vertices), 1) self.assertAlmostEqual(mol.coordinates[0,0]/angstrom, 6.8671) self.assertAlmostEqual(mol.coordinates[9,1]/angstrom, 0.2500) self.assertAlmostEqual(mol.coordinates[13,0]/angstrom, 12.6002) self.assert_((mol.formal_charges[:12]==-1).all()) self.assert_((mol.formal_charges[12:]==0).all())
def test_reader2(self): sdf_reader = SDFReader("input/CID_22898828.sdf") mol = sdf_reader.next() self.assertEqual(mol.title, "22898828") self.assertEqual(mol.size, 14) self.assertEqual(len(mol.graph.pairs), 13) self.assert_(frozenset([4, 6]) in mol.graph.pairs) self.assertEqual(len(mol.graph.independent_nodes), 1) self.assertAlmostEqual(mol.coordinates[0, 0] / angstrom, 6.8671) self.assertAlmostEqual(mol.coordinates[9, 1] / angstrom, 0.2500) self.assertAlmostEqual(mol.coordinates[13, 0] / angstrom, 12.6002) self.assert_((mol.formal_charges[:12] == -1).all()) self.assert_((mol.formal_charges[12:] == 0).all())
def test_fingerprint_collisions(self): # These are collisions with older versions, found by scanning the # pubchem database. cases = [('SID_55127927.sdf', 'SID_56274343.sdf'), ('SID_55488598.sdf', 'SID_54258192.sdf'), ('SID_41893280.sdf', 'SID_41893278.sdf'), ('SID_40363570.sdf', 'SID_40363571.sdf'), ('SID_31646548.sdf', 'SID_31646545.sdf')] for fn0, fn1 in cases: g0 = SDFReader(os.path.join("input", fn0)).next().graph g1 = SDFReader(os.path.join("input", fn1)).next().graph self.assertNotEqual(str(g0.fingerprint.data), str(g1.fingerprint.data))
def test_reader(self): sdf_reader = SDFReader("input/example.sdf") mol = sdf_reader.next() self.assertEqual(mol.title, "24978498") self.assertEqual(mol.size, 16) self.assertEqual(len(mol.graph.edges), 15) self.assert_(frozenset([1,14]) in mol.graph.edges) self.assertAlmostEqual(mol.coordinates[0,0]/angstrom, 2.8660) self.assertAlmostEqual(mol.coordinates[4,1]/angstrom, -1.9400) self.assertAlmostEqual(mol.coordinates[15,1]/angstrom, -2.5600) mol = sdf_reader.next() self.assertEqual(mol.title, "24978481") self.assertEqual(mol.size, 21) self.assertEqual(len(mol.graph.edges), 19) self.assert_(frozenset([3,9]) in mol.graph.edges) self.assertEqual(len(mol.graph.independent_vertices), 2) self.assertAlmostEqual(mol.coordinates[0,0]/angstrom, 2.2690) self.assertAlmostEqual(mol.coordinates[9,1]/angstrom, 2.5790) self.assertAlmostEqual(mol.coordinates[20,0]/angstrom, 1.7130) try: sdf_reader.next() self.fail("Expecting a StopIteration.") except StopIteration: pass
def iter_molecules(self, allow_multi=False): xyz_fns = [ "water.xyz", "cyclopentane.xyz", "ethene.xyz", "funny.xyz", "tea.xyz", "tpa.xyz", "thf_single.xyz", "precursor.xyz", "butane.xyz", "octane.xyz", ] for xyz_fn in xyz_fns: molecule = self.load_molecule(xyz_fn) if allow_multi or len(molecule.graph.independent_nodes) == 1: molecule.title = xyz_fn[:-4] yield molecule sdf_fns = [ "example.sdf", "CID_22898828.sdf", "SID_55127927.sdf", "SID_56274343.sdf", "SID_40363570.sdf", "SID_40363571.sdf", "SID_31646548.sdf", "SID_31646545.sdf", "SID_41893278.sdf", "SID_41893280.sdf", "SID_54258192.sdf", "SID_55488598.sdf", ] for sdf_fn in sdf_fns: for i, molecule in enumerate( SDFReader(os.path.join("input", sdf_fn))): if allow_multi or len(molecule.graph.independent_nodes) == 1: molecule.title = "%s_%i" % (sdf_fn[:-4], i) yield molecule
def test_reader(self): sdf_reader = SDFReader("input/example.sdf") mol = sdf_reader.next() self.assertEqual(mol.title, "24978498") self.assertEqual(mol.size, 16) self.assertEqual(len(mol.graph.pairs), 15) self.assert_(frozenset([1, 14]) in mol.graph.pairs) self.assertAlmostEqual(mol.coordinates[0, 0] / angstrom, 2.8660) self.assertAlmostEqual(mol.coordinates[4, 1] / angstrom, -1.9400) self.assertAlmostEqual(mol.coordinates[15, 1] / angstrom, -2.5600) mol = sdf_reader.next() self.assertEqual(mol.title, "24978481") self.assertEqual(mol.size, 21) self.assertEqual(len(mol.graph.pairs), 19) self.assert_(frozenset([3, 9]) in mol.graph.pairs) self.assertEqual(len(mol.graph.independent_nodes), 2) self.assertAlmostEqual(mol.coordinates[0, 0] / angstrom, 2.2690) self.assertAlmostEqual(mol.coordinates[9, 1] / angstrom, 2.5790) self.assertAlmostEqual(mol.coordinates[20, 0] / angstrom, 1.7130) try: sdf_reader.next() self.fail("Expecting a StopIteration.") except StopIteration: pass