def test_acrolein(self): mol = Molecule().from_smiles("C=CC=O") # Acrolein start, end = mol.atoms[0], mol.atoms[3] path = find_butadiene(start, end) self.assertIsNotNone(path) start, end = mol.atoms[0], mol.atoms[4] # wrong end path = find_butadiene(start, end) self.assertIsNone(path) start, end = mol.atoms[-1], mol.atoms[3] # wrong start path = find_butadiene(start, end) self.assertIsNone(path)
def _fix_butadiene_path(start, end): """ Searches for a 1,3-butadiene path between the start and end atom. Adds an unpaired electron to start and end atom, and "inverts" the bonds in between them. """ path = pathfinder.find_butadiene(start, end) if path is not None: start.radical_electrons += 1 end.radical_electrons += 1 # filter bonds from path and convert bond orders: bonds = path[1::2] # odd elements for bond in bonds[::2]: # even bonds 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
def fix_butadiene_path(start, end): """ Searches for a 1,3-butadiene path between the start and end atom. Adds an unpaired electron to start and end atom, and "inverts" the bonds in between them. """ path = pathfinder.find_butadiene(start, end) if path is not None: start.radicalElectrons += 1 end.radicalElectrons += 1 # filter bonds from path and convert bond orders: bonds = path[1::2]#odd elements for bond in bonds[::2]:# even bonds assert isinstance(bond, Bond) bond.decrementOrder() for bond in bonds[1::2]:# odd bonds assert isinstance(bond, Bond) bond.incrementOrder() return True return False
def test_13cyclohexadiene(self): adjlist = """ 1 C u0 p0 c0 {2,D} {6,S} {7,S} 2 C u0 p0 c0 {1,D} {3,S} {8,S} 3 C u0 p0 c0 {2,S} {4,D} {9,S} 4 C u0 p0 c0 {3,D} {5,S} {10,S} 5 C u0 p0 c0 {4,S} {6,S} {11,S} {12,S} 6 C u0 p0 c0 {1,S} {5,S} {13,S} {14,S} 7 H u0 p0 c0 {1,S} 8 H u0 p0 c0 {2,S} 9 H u0 p0 c0 {3,S} 10 H u0 p0 c0 {4,S} 11 H u0 p0 c0 {5,S} 12 H u0 p0 c0 {5,S} 13 H u0 p0 c0 {6,S} 14 H u0 p0 c0 {6,S} """ mol = Molecule().from_adjacency_list(adjlist) # 1,3-cyclohexadiene start, end = mol.atoms[0], mol.atoms[3] path = find_butadiene(start, end) self.assertIsNotNone(path)
def test_135hexatriene(self): mol = Molecule().from_smiles("C=CC=CC=C") # 1,3,5-hexatriene start, end = mol.atoms[0], mol.atoms[5] path = find_butadiene(start, end) self.assertIsNotNone(path)
def test_c4h4(self): mol = Molecule().from_smiles("C=C=C=C") # C4H4 start, end = mol.atoms[0], mol.atoms[3] path = find_butadiene(start, end) self.assertIsNotNone(path)
def test_benzene(self): mol = Molecule().from_smiles("C1=CC=CC=C1") # benzene start, end = mol.atoms[0], mol.atoms[5] path = find_butadiene(start, end) self.assertIsNotNone(path)