Ejemplo n.º 1
0
def _convert_4_atom_3_bond_path(start):
    """
    Searches for 4-atom-3-bond [X=X-X=X+] paths starting from the parameter atom.
    If a path is found, the starting atom receives an unpaired electron while
    the bonds in the delocalization path are "inverted". A unit of charge on the
    end atom is neutralized and a lone pair is added.
    """
    path = pathfinder.find_butadiene_end_with_charge(start)

    if path is not None:
        start.radical_electrons += 1
        end = path[-1]
        end.charge += 1 if end.charge < 0 else -1
        end.lone_pairs += 1

        # filter bonds from path and convert bond orders:
        bonds = path[1::2]  # odd
        for bond in bonds[::2]:  # even
            assert isinstance(bond, Bond)
            bond.decrement_order()
        for bond in bonds[1::2]:  # odd bonds
            assert isinstance(bond, Bond)
            bond.increment_order()

        return True

    return False
Ejemplo n.º 2
0
def convert_4_atom_3_bond_path(start):
    """
    Searches for 4-atom-3-bond [X=X-X=X+] paths starting from the parameter atom.
    If a path is found, the starting atom receives an unpaired electron while
    the bonds in the delocalization path are "inverted". A unit of charge on the 
    end atom is neutralized and a lone pair is added.
    """
    path = pathfinder.find_butadiene_end_with_charge(start)

    if path is not None:    
        start.radicalElectrons += 1
        end = path[-1]
        end.charge += 1 if end.charge < 0 else -1
        end.lonePairs += 1

        # filter bonds from path and convert bond orders:
        bonds = path[1::2]#odd
        for bond in bonds[::2]:# even
            assert isinstance(bond, Bond)
            bond.decrementOrder()
        for bond in bonds[1::2]:# odd bonds
            assert isinstance(bond, Bond)
            bond.incrementOrder()  

        return True

    return False
Ejemplo n.º 3
0
 def test_c8h14o4(self):
     inchi = "InChI=1S/C8H14O4S/c1-3-6-13(2,11)7-8(9)4-5-12-10/h3,6H,1,4-5,7H2,2H3,(H-,10,11)"
     mol = Molecule().from_inchi(inchi)
     start = mol.atoms[0]
     path = find_butadiene_end_with_charge(start)
     idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]
     expected_idx_path = [1, 3, 6, 13]
     self.assertEqual(idx_path, expected_idx_path)
Ejemplo n.º 4
0
    def test_c6h6o6(self):
        inchi = "InChI=1S/C6H6O6/c7-6(2-5-12-9)10-3-1-4-11-8/h1,7H,4-5H2"
        mol = Molecule().from_inchi(inchi)
        start = mol.atoms[2]
        path = find_butadiene_end_with_charge(start)
        idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]

        expected_idx_path = [3, 10]
        self.assertEquals(idx_path, expected_idx_path)
Ejemplo n.º 5
0
    def test_c6h6o4(self):
        inchi = "InChI=1S/C6H6O4/c1-2-4-9-6(7)3-5-10-8/h2-3H,1,5H2"
        mol = Molecule().from_inchi(inchi)
        start = mol.atoms[0]
        path = find_butadiene_end_with_charge(start)
        idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]

        expected_idx_path = [1, 2, 4, 9]
        self.assertEquals(idx_path, expected_idx_path)
Ejemplo n.º 6
0
    def test_co(self):
        adjlist = """
1 C u0 p1 c-1 {2,T}
2 O u0 p1 c+1 {1,T}
        """

        mol = Molecule().from_adjacency_list(adjlist)
        start = mol.atoms[0]
        path = find_butadiene_end_with_charge(start)
        idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]

        expected_idx_path = [1, 2]
        self.assertEquals(idx_path, expected_idx_path)
Ejemplo n.º 7
0
    def test_c2h2o3(self):
        adjlist = """
1 C u0 p0 c0 {5,D} {6,S} {7,S}
2 C u0 p0 c0 {3,D} {4,S} {5,S}
3 O u0 p2 c0 {2,D}
4 O u0 p3 c-1 {2,S}
5 O u0 p1 c+1 {1,D} {2,S}
6 H u0 p0 c0 {1,S}
7 H u0 p0 c0 {1,S}
        """

        mol = Molecule().from_adjacency_list(adjlist)
        start = mol.atoms[0]
        path = find_butadiene_end_with_charge(start)
        idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]

        expected_idx_path = [1, 5]
        self.assertEquals(idx_path, expected_idx_path)
Ejemplo n.º 8
0
    def test_c4h6o(self):
        adjlist = """
1  C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2  C u0 p1 c-1 {1,S} {3,S} {9,S}
3  C u0 p0 c0 {2,S} {4,S} {10,S} {11,S}
4  C u0 p0 c0 {3,S} {5,T}
5  O u0 p1 c+1 {4,T}
6  H u0 p0 c0 {1,S}
7  H u0 p0 c0 {1,S}
8  H u0 p0 c0 {1,S}
9  H u0 p0 c0 {2,S}
10 H u0 p0 c0 {3,S}
11 H u0 p0 c0 {3,S}
        """

        mol = Molecule().from_adjacency_list(adjlist)
        start = mol.atoms[3]
        path = find_butadiene_end_with_charge(start)
        idx_path = [mol.atoms.index(atom) + 1 for atom in path[0::2]]

        expected_idx_path = [4, 5]
        self.assertEquals(idx_path, expected_idx_path)