コード例 #1
0
    def test_canonical(self):
        mol1 = helium.Molecule()
        mol2 = helium.Molecule()
        self.assertTrue(SMILES.read('C=O', mol1))
        self.assertTrue(SMILES.read('O=C', mol2))

        self.assertEqual(SMILES.writeCanonical(mol1),
                         SMILES.writeCanonical(mol2))
        self.assertEqual(SMILES.write(mol1, [0, 1]),
                         SMILES.write(mol2, [1, 0]))
        self.assertEqual('CO',
                         SMILES.write(mol1, [0, 1], helium.Smiles.Flags.None))
        self.assertEqual('CO',
                         SMILES.write(mol2, [1, 0], helium.Smiles.Flags.None))
コード例 #2
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_copy_ctor(self):
        mol1 = helium.Molecule()

        SMILES.read('CC', mol1)

        mol2 = helium.Molecule(mol1)

        self.assertEqual(2, mol1.numAtoms())
        self.assertEqual(2, mol2.numAtoms())

        mol2.clear()

        self.assertEqual(2, mol1.numAtoms())
        self.assertEqual(0, mol2.numAtoms())
コード例 #3
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_molecule_editing(self):
        mol = helium.Molecule()

        atom1 = mol.addAtom()
        atom2 = mol.addAtom()
        atom3 = mol.addAtom()
        atom4 = mol.addAtom()

        bond1 = mol.addBond(atom1, atom2)
        bond2 = mol.addBond(atom2, atom3)
        bond3 = mol.addBond(atom3, atom4)

        self.assertEqual(4, mol.numAtoms())
        self.assertEqual(3, mol.numBonds())

        mol.removeBond(bond3)

        self.assertEqual(4, mol.numAtoms())
        self.assertEqual(2, mol.numBonds())

        mol.removeAtom(atom1)

        self.assertEqual(3, mol.numAtoms())
        self.assertEqual(1, mol.numBonds())

        mol.clear()

        self.assertEqual(0, mol.numAtoms())
        self.assertEqual(0, mol.numBonds())
コード例 #4
0
    def test_floyd_warshall(self):
        mol = helium.Molecule()

        a1 = mol.addAtom()
        a2 = mol.addAtom()
        a3 = mol.addAtom()
        a4 = mol.addAtom()
        a5 = mol.addAtom()
        a6 = mol.addAtom()
        a7 = mol.addAtom()

        mol.addBond(a1, a2)
        mol.addBond(a2, a3)
        mol.addBond(a3, a4)
        mol.addBond(a4, a5)
        mol.addBond(a5, a6)
        mol.addBond(a6, a7)
        mol.addBond(a7, a1)
        mol.addBond(a2, a6)

        D = helium.floyd_warshall(mol)
        self.assertTrue(isinstance(D, helium.DistanceMatrix))
        self.assertEqual(7, D.dim())
        self.assertEqual(0, D(0, 0))
        self.assertEqual(1, D(0, 1))
        self.assertEqual(2, D(0, 2))
        self.assertEqual(3, D(0, 3))
        self.assertEqual(4, D(0, 4))
        self.assertEqual(2, D(0, 5))
        self.assertEqual(3, D(0, 6))
コード例 #5
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_bond(self):
        mol = helium.Molecule()
        SMILES.read('CC(C)=O', mol)

        atom1 = mol.atom(0)
        atom2 = mol.atom(1)
        atom3 = mol.atom(2)
        atom4 = mol.atom(3)

        bond1 = mol.bond(0)
        bond2 = mol.bond(1)
        bond3 = mol.bond(2)

        self.assertEqual(0, bond1.index())
        self.assertEqual(1, bond2.index())
        self.assertEqual(2, bond3.index())

        self.assertEqual(1, bond1.order())
        self.assertEqual(1, bond2.order())
        self.assertEqual(2, bond3.order())

        self.assertEqual(atom1, bond1.source())
        self.assertEqual(atom2, bond2.source())
        self.assertEqual(atom2, bond3.source())

        self.assertEqual(atom2, bond1.target())
        self.assertEqual(atom3, bond2.target())
        self.assertEqual(atom4, bond3.target())

        self.assertEqual(atom1, bond1.other(atom2))
        self.assertEqual(atom2, bond2.other(atom3))
        self.assertEqual(atom2, bond3.other(atom4))
コード例 #6
0
 def test_path_fingerprint(self):
     mol = helium.Molecule()
     fp = helium.path_fingerprint(mol)
     fp = helium.path_fingerprint(mol, 7)
     fp = helium.path_fingerprint(mol, 7, 16)
     fp = helium.path_fingerprint(mol, 7, 16, 1021)
     self.assertEqual(16, fp.numWords)
コード例 #7
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_atom(self):
        mol = helium.Molecule()
        SMILES.read('CC(C)N', mol)

        atom1 = mol.atom(0)
        atom2 = mol.atom(1)
        atom3 = mol.atom(2)
        atom4 = mol.atom(3)

        self.assertEqual(0, atom1.index())
        self.assertEqual(1, atom2.index())
        self.assertEqual(2, atom3.index())
        self.assertEqual(3, atom4.index())

        self.assertEqual(6, atom1.element())
        self.assertEqual(6, atom2.element())
        self.assertEqual(6, atom3.element())
        self.assertEqual(7, atom4.element())

        self.assertEqual(1, atom1.degree())
        self.assertEqual(3, atom2.degree())
        self.assertEqual(1, atom3.degree())
        self.assertEqual(1, atom4.degree())

        indices = []
        for nbr in atom2.nbrs():
            indices.append(nbr.index())
        self.assertListEqual([0, 2, 3], indices)

        indices = []
        for bond in atom2.bonds():
            indices.append(bond.index())
        self.assertListEqual([0, 1, 2], indices)
コード例 #8
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_bfs_4(self):
        mol = helium.Molecule()
        SMILES.read('C1CCC(CC)CC1', mol)

        visitor = helium.BFSDebugVisitor()
        helium.breadth_first_search(mol, mol.atom(5), visitor)
        self.compare_file('bfs4.log', visitor.output)
コード例 #9
0
ファイル: dfs.py プロジェクト: dualword/Helium
    def test_dfs_4(self):
        mol = helium.Molecule()
        SMILES.read('C1CCCCC1CC.CC', mol)

        visitor = helium.DFSDebugVisitor()
        helium.depth_first_search(mol, visitor)
        self.compare_file('dfs4.log', visitor.output)
コード例 #10
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_custom_visitor(self):
        mol = helium.Molecule()
        SMILES.read('C1CCC(CC)CC1', mol)

        visitor = BFSTestVisitor()
        helium.breadth_first_search(mol, visitor)
        self.compare_file('bfs1.log', visitor.output)
コード例 #11
0
ファイル: dfs.py プロジェクト: dualword/Helium
    def test_dfs_10(self):
        mol = helium.Molecule()
        SMILES.read('C(C)N', mol)

        visitor = helium.DFSDebugVisitor()
        helium.ordered_depth_first_search(mol, [0, 2, 1], visitor)
        self.compare_file('dfs10.log', visitor.output)
コード例 #12
0
ファイル: dfs.py プロジェクト: dualword/Helium
    def test_dfs_3(self):
        mol = helium.Molecule()
        SMILES.read('C1CCC(CC)CC1', mol)

        visitor = helium.DFSDebugVisitor()
        helium.exhaustive_depth_first_search(mol, mol.atom(0), visitor)
        self.compare_file('dfs3.log', visitor.output)
コード例 #13
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_atom_order_visitor(self):
        mol = helium.Molecule()
        SMILES.read('CCC', mol)

        visitor = helium.BFSAtomOrderVisitor()
        helium.breadth_first_search(mol, visitor)
        self.assertListEqual([0, 1, 2], visitor.atoms)
コード例 #14
0
    def test_ringset(self):
        mol = helium.Molecule()
        SMILES.read('CCC1CC1', mol)
        rings = helium.relevant_cycles(mol)
        self.assertTrue(isinstance(rings, helium.RingSet))

        self.assertEqual(1, rings.size())
        self.assertEqual(1, len(rings))

        self.assertEqual(1, len(rings.rings()))
        self.assertTrue(isinstance(rings.ring(0), helium.Ring))

        self.assertFalse(rings.isAtomInRing(mol.atom(0)))
        self.assertTrue(rings.isAtomInRing(mol.atom(2)))

        self.assertFalse(rings.isBondInRing(mol.bond(0)))
        self.assertTrue(rings.isBondInRing(mol.bond(2)))

        self.assertFalse(rings.isAtomInRingSize(mol.atom(2), 4))
        self.assertTrue(rings.isAtomInRingSize(mol.atom(2), 3))

        self.assertFalse(rings.isBondInRingSize(mol.bond(2), 4))
        self.assertTrue(rings.isBondInRingSize(mol.bond(2), 3))

        self.assertEqual(2, rings.numRingNbrs(mol.atom(2)))
        self.assertEqual(1, rings.numRings(mol.atom(2)))
コード例 #15
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_bond_order_visitor(self):
        mol = helium.Molecule()
        SMILES.read('CCC', mol)

        visitor = helium.BFSBondOrderVisitor()
        helium.breadth_first_search(mol, visitor)
        self.assertListEqual([0, 1], visitor.bonds)
コード例 #16
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_atom_editing(self):
        mol = helium.Molecule()
        atom = mol.addAtom()

        self.assertEqual(0, atom.index())

        atom.setElement(6)
        self.assertEqual(6, atom.element())
        atom.setElement(7)
        self.assertEqual(7, atom.element())

        atom.setAromatic(True)
        self.assertTrue(atom.isAromatic())
        atom.setAromatic(False)
        self.assertFalse(atom.isAromatic())

        atom.setMass(12)
        self.assertEqual(12, atom.mass())
        atom.setMass(13)
        self.assertEqual(13, atom.mass())

        atom.setHydrogens(4)
        self.assertEqual(4, atom.hydrogens())
        atom.setHydrogens(3)
        self.assertEqual(3, atom.hydrogens())

        atom.setCharge(1)
        self.assertEqual(1, atom.charge())
        atom.setCharge(-1)
        self.assertEqual(-1, atom.charge())
コード例 #17
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_closure_recorder_visitor(self):
        mol = helium.Molecule()
        SMILES.read('C1CCCCC1', mol)

        visitor = helium.BFSClosureRecorderVisitor()
        helium.breadth_first_search(mol, visitor)
        self.assertListEqual([3], visitor.back_bonds)
コード例 #18
0
    def test_cycle_membership(self):
        mol = helium.Molecule()
        SMILES.read('CC1CC1C', mol)

        atoms, bonds = helium.cycle_membership(mol)

        self.assertListEqual([False, True, True, True, False], atoms)
        self.assertListEqual([False, True, True, True, False], bonds)
コード例 #19
0
ファイル: bfs.py プロジェクト: dualword/Helium
    def test_bfs_5(self):
        mol = helium.Molecule()
        SMILES.read('C1CCC(CC)CC1', mol)

        atomMask = [True] * mol.numAtoms()
        atomMask[0] = False

        visitor = helium.BFSDebugVisitor()
        helium.breadth_first_search_mask(mol, mol.atom(5), visitor, atomMask)
        self.compare_file('bfs5.log', visitor.output)
コード例 #20
0
    def test_relevant_cycles(self):
        mol = helium.Molecule()
        SMILES.read('c1ccccc1-c1ccccc1', mol)

        rings = helium.relevant_cycles(mol)
        self.assertEqual(2, len(rings))

        atoms, bonds = helium.cycle_membership(mol)
        rings = helium.relevant_cycles(mol, 1, atoms, bonds)
        self.assertEqual(2, len(rings))
コード例 #21
0
ファイル: molecule.py プロジェクト: dualword/Helium
    def test_substructure_ctor(self):
        mol = helium.Molecule()
        SMILES.read('Oc1cc(CC)ccc1N', mol)

        atoms = [True] * mol.numAtoms()
        atoms[0] = False
        atoms[4] = False
        atoms[5] = False
        atoms[9] = False

        bonds = [True] * mol.numBonds()
        bonds[0] = False
        bonds[3] = False
        bonds[4] = False
        bonds[9] = False

        sub = helium.Molecule(mol, atoms, bonds)

        self.assertEqual('c1ccccc1', SMILES.write(sub))
コード例 #22
0
ファイル: dfs.py プロジェクト: dualword/Helium
    def test_dfs_5(self):
        mol = helium.Molecule()
        SMILES.read('C1CCCCC1CC.CC', mol)

        atomMask = [True] * mol.numAtoms()
        atomMask[6] = False
        atomMask[7] = False

        visitor = helium.DFSDebugVisitor()
        helium.depth_first_search_mask(mol, visitor, atomMask)
        self.compare_file('dfs5.log', visitor.output)
コード例 #23
0
    def test_extended_connectivities(self):
        mol = helium.Molecule()
        SMILES.read('CCC', mol)

        ec = helium.extended_connectivities(mol, helium.DefaultAtomInvariant())
        self.assertTrue(isinstance(ec, list))
        self.assertEqual(3, len(ec))

        ec = helium.extended_connectivities(mol, TestAtomInvariant())
        self.assertTrue(isinstance(ec, list))
        self.assertEqual(3, len(ec))
コード例 #24
0
    def test_find_no_mapping_miss(self):
        smarts = helium.Smarts()
        smarts.init('N')

        mol = helium.Molecule()
        SMILES.read('CCC', mol)

        mapping = helium.NoMapping()
        rings = helium.RingSet(mol)

        self.assertFalse(smarts.findMapping(mol, rings, mapping))
        self.assertFalse(mapping.match)
コード例 #25
0
    def test_apply(self):
        smirks = helium.Smirks()
        self.assertTrue(smirks.init('[C:1]>>[N:1]'))
        mol = helium.Molecule()

        SMILES.read('C', mol)
        self.assertTrue(smirks.apply(mol, helium.RingSet(mol)))
        self.assertEqual('N', SMILES.write(mol))

        SMILES.read('O', mol)
        self.assertFalse(smirks.apply(mol, helium.RingSet(mol)))
        self.assertEqual('O', SMILES.write(mol))
コード例 #26
0
    def test_find_count_mapping(self):
        smarts = helium.Smarts()
        smarts.init('C')

        mol = helium.Molecule()
        SMILES.read('CCC', mol)

        mapping = helium.CountMapping()
        rings = helium.RingSet(mol)

        self.assertTrue(smarts.findMapping(mol, rings, mapping))
        self.assertEqual(3, mapping.count)
コード例 #27
0
    def test_memory_mapped_molecule_file(self):
        f = helium.MemoryMappedMoleculeFile()
        self.assertFalse(f.load('foo'))

        f.load(self.datadir + '/1K.hel')
        self.assertEqual(1000, f.numMolecules())

        mol = helium.Molecule()
        self.assertTrue(f.readMolecule(0, mol))
        self.assertEqual(8, mol.numAtoms())

        f = helium.MemoryMappedMoleculeFile(self.datadir + '/1K.hel')
        self.assertEqual(1000, f.numMolecules())
コード例 #28
0
    def test_find_single_mapping(self):
        smarts = helium.Smarts()
        smarts.init('c1ccccc1')

        mol = helium.Molecule()
        SMILES.read('c1ccccc1-c2ccccc2', mol)

        mapping = helium.SingleMapping()
        rings = helium.RingSet(mol)


        self.assertTrue(smarts.findMapping(mol, rings, mapping))
        self.assertEqual(6, len(mapping.map))
コード例 #29
0
    def test_default_bond_invariant(self):
        mol = helium.Molecule()
        SMILES.read('CN=O:C', mol)

        invariant = helium.DefaultBondInvariant()
        self.assertEqual(1, invariant(mol, mol.bond(0)))

        invariant = helium.DefaultBondInvariant(
            helium.DefaultBondInvariant.Invariants.Order)
        self.assertEqual(2, invariant(mol, mol.bond(1)))

        invariant = helium.DefaultBondInvariant(
            helium.DefaultBondInvariant.Invariants.Aromatic)
        self.assertEqual(100, invariant(mol, mol.bond(2)))
コード例 #30
0
    def test_enumerate_paths(self):
        mol = helium.Molecule()
        SMILES.read('CC(C)C', mol)

        callback = TestSubgraphCallback()

        helium.enumerate_subgraphs(mol, callback, 7)
        self.assertTrue(isinstance(callback.subgraphs, list))
        self.assertEqual(11, len(callback.subgraphs))

        callback.subgraphs = []
        helium.enumerate_subgraphs(mol, callback, 3)
        self.assertTrue(isinstance(callback.subgraphs, list))
        self.assertEqual(10, len(callback.subgraphs))