def set_atom_feat(a: Atom, key: str, val: int): if key == 'atomic_num': a.SetAtomicNum(val) elif key == 'formal_charge': a.SetFormalCharge(val) elif key == 'chiral_tag': a_chiral = rdchem.ChiralType.values[val] a.SetChiralTag(a_chiral) elif key == 'num_explicit_hs': a.SetNumExplicitHs(val) elif key == 'is_aromatic': a.SetIsAromatic(bool(val)) return a
def downgrade_ring(self, atom: Chem.Atom): ## very crappy way of doing this log.debug(f'downgrading whole ring!') atom.SetIsAromatic(False) ringinfo = self._get_ring_info(mode='atom') get_atomrings = lambda ai: [ring for ring in ringinfo if ai in ring] atomrings = get_atomrings(atom.GetIdx()) for atomring in atomrings: rnieghs = self._get_ring_neighbors(atomring) for n1, n2 in rnieghs: self.mol.GetAtomWithIdx(n1).SetIsAromatic(False) self.mol.GetAtomWithIdx(n2).SetIsAromatic(False) self.mol.GetBondBetweenAtoms(n1, n2).SetBondType( Chem.BondType.SINGLE) for atomring in atomrings: rnieghs = self._get_ring_neighbors(atomring) for n1, n2 in rnieghs: if self._get_valence_difference(self.mol.GetAtomWithIdx(n1)) <= -2 and \ self._get_valence_difference(self.mol.GetAtomWithIdx(n2)) <= -2: self.mol.GetBondBetweenAtoms(n1, n2).SetBondType( Chem.BondType.DOUBLE)