Exemplo n.º 1
0
def generate_allyl_delocalization_resonance_structures(mol):
    """
    Generate all of the resonance structures formed by one allyl radical shift.

    Biradicals on a single atom are not supported.
    """
    cython.declare(structures=list, paths=list, index=cython.int, structure=Molecule)
    cython.declare(atom=Atom, atom1=Atom, atom2=Atom, atom3=Atom, bond12=Bond, bond23=Bond)
    cython.declare(v1=Vertex, v2=Vertex)

    structures = []
    if mol.is_radical():  # Iterate over radicals in structure
        for atom in mol.vertices:
            paths = pathfinder.find_allyl_delocalization_paths(atom)
            for atom1, atom2, atom3, bond12, bond23 in paths:
                # Adjust to (potentially) new resonance structure
                atom1.decrement_radical()
                atom3.increment_radical()
                bond12.increment_order()
                bond23.decrement_order()
                # Make a copy of structure
                structure = mol.copy(deep=True)
                # Restore current structure
                atom1.increment_radical()
                atom3.decrement_radical()
                bond12.decrement_order()
                bond23.increment_order()
                try:
                    structure.update_atomtypes(log_species=False)
                except AtomTypeError:
                    pass  # Don't append resonance structure if it creates an undefined atomtype
                else:
                    structures.append(structure)
    return structures
Exemplo n.º 2
0
 def test_nitrogenated_birad(self):
     smiles = '[CH]=C[N]'
     mol = Molecule().from_smiles(smiles)
     paths = find_allyl_delocalization_paths(mol.atoms[3])
     self.assertTrue(paths)
Exemplo n.º 3
0
 def test_allyl_radical(self):
     smiles = "[CH2]C=C"
     mol = Molecule().from_smiles(smiles)
     paths = find_allyl_delocalization_paths(mol.atoms[0])
     self.assertTrue(paths)