def generate_lone_pair_multiple_bond_resonance_structures(mol): """ Generate all of the resonance structures formed by lone electron pair - multiple bond shifts in 3-atom systems. Examples: aniline (Nc1ccccc1), azide, [:NH2]C=[::O] <=> [NH2+]=C[:::O-] (where ':' denotes a lone pair, '.' denotes a radical, '-' not in [] denotes a single bond, '-'/'+' denote charge) """ 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 = [] for atom in mol.vertices: if atom.lone_pairs >= 1: paths = pathfinder.find_lone_pair_multiple_bond_paths(atom) for atom1, atom2, atom3, bond12, bond23 in paths: # Adjust to (potentially) new resonance structure atom1.decrement_lone_pairs() atom3.increment_lone_pairs() bond12.increment_order() bond23.decrement_order() atom1.update_charge() atom3.update_charge() # Make a copy of structure structure = mol.copy(deep=True) # Restore current structure atom1.increment_lone_pairs() atom3.decrement_lone_pairs() bond12.decrement_order() bond23.increment_order() atom1.update_charge() atom3.update_charge() 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
def test_h2nnoo(self): smiles = "N[N+]([O-])=O" mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[0]) self.assertTrue(paths)
def test_sn2(self): smiles = "OS(O)=[N+]=[N-]" mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[2]) self.assertTrue(paths)
def test_hn3(self): smiles = "[NH-][N+]#N" mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[0]) self.assertTrue(paths)
def test_n2ob(self): smiles = "N#[N+][O-]" mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[2]) self.assertTrue(paths)
def test_n2oa(self): smiles = "[N-]=[N+]=O" mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[0]) self.assertTrue(paths)
def test_nh2cho(self): smiles = 'NC=O' mol = Molecule().from_smiles(smiles) paths = find_lone_pair_multiple_bond_paths(mol.atoms[0]) self.assertTrue(paths)