def atom_to_feat(self, atm: Chem.Atom, owning_mol: Chem.Mol, idx): # nb the func GetOwningMol could not be used for mol as would return different object each time this_atms_idx = atm.GetIdx() assert idx == this_atms_idx feat = torch.zeros(len(self), dtype=torch.float32) # One hot encoding of element try: feat[self.atms_to_idx[atm.GetSymbol()]] = 1. except KeyError as ex: warnings.warn(f"Ignoring the symbol {atm.GetSymbol()}") idx_up_to = self.number_atom_options # Atomic Number feat[idx_up_to] = float(atm.GetAtomicNum()) idx_up_to += 1 # Acceptor/donor acceptor_ids, donor_ids = self.get_acceptor_and_donor_ids(owning_mol) # Acceptor feat[idx_up_to] = float(this_atms_idx in acceptor_ids) idx_up_to += 1 # Donor feat[idx_up_to] = float(this_atms_idx in donor_ids) idx_up_to += 1 # Hybridization hyb_idx = self.hybridization(atm.GetHybridization()) if hyb_idx is not None: feat[idx_up_to + hyb_idx] = 1. idx_up_to += self.number_hyb_options # Aromatic feat[idx_up_to] = float(atm.GetIsAromatic()) idx_up_to += 1 # Number of Hydrogens feat[idx_up_to] = float(atm.GetNumImplicitHs()) idx_up_to += 1 return feat
def atom_to_string(atom: Chem.Atom) -> str: return '{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}'.format( atom.GetChiralTag(), atom.GetDegree(), atom.GetExplicitValence(), atom.GetFormalCharge(), atom.GetHybridization(), atom.GetIsAromatic(), atom.GetMass(), atom.GetNumExplicitHs(), atom.GetNumImplicitHs(), atom.GetNumRadicalElectrons(), atom.GetTotalDegree(), atom.GetTotalNumHs(), atom.GetTotalValence(), atom.IsInRing() )