def atom_features(atom: Chem.Atom): return np.array( encoding_onehot_unk(atom.GetSymbol(), [ 'C', 'N', 'O', 'S', 'F', 'Si', 'P', 'Cl', 'Br', 'Mg', 'Na', 'Ca', 'Fe', 'As', 'Al', 'I', 'B', 'V', 'K', 'Tl', 'Yb', 'Sb', 'Sn', 'Ag', 'Pd', 'Co', 'Se', 'Ti', 'Zn', 'H', 'Li', 'Ge', 'Cu', 'Au', 'Ni', 'Cd', 'In', 'Mn', 'Zr', 'Cr', 'Pt', 'Hg', 'Pb', 'Unknown' ]) + encoding_onehot(atom.GetDegree(), [0, 1, 2, 3, 4, 5]) + encoding_onehot_unk(atom.GetTotalNumHs(), [0, 1, 2, 3, 4]) + encoding_onehot_unk(atom.GetImplicitValence(), [0, 1, 2, 3, 4, 5]) + [atom.GetIsAromatic()])
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() )
def _AtomHallKierDeltas(atom: Chem.Atom, skipHs: bool = False) -> List[float]: """Calculate Kier & Hall atomic valence delta-values for molecular connectivity. From Kier L. and Hall L., J. Pharm. Sci. (1983), 72(10),1170-1173. """ global periodicTable res = [] n = atom.GetAtomicNum() if n > 1: nV = periodicTable.GetNOuterElecs(n) nHs = atom.GetTotalNumHs() if n < 10: res.append(float(nV - nHs)) else: res.append(float(nV - nHs) / float(n - nV - 1)) elif not skipHs: res.append(0.0) return res
def atom_feature(atom: Atom) -> Tuple[torch.Tensor, int]: ''' Extract atom feature vector. Returns: (feature_vec, feature_dim) Features: # item # dim atomic number 25 exp-valence 7 imp-valence 4 hybridization 7 Hs 5 degree 6 formal charge 6 in ring 1 aromatic 1 mass / 100 1 (sum) 63 ''' index = torch.tensor([ ATOM_MAP[atom.GetAtomicNum()], atom.GetExplicitValence(), atom.GetImplicitValence(), HYBRID_MAP[atom.GetHybridization()], atom.GetTotalNumHs(), atom.GetDegree(), atom.GetFormalCharge() + 2, # -2 ~ 3 int(atom.IsInRing()), int(atom.GetIsAromatic()) ]) + OFFSET vec = torch.zeros(ATOM_FDIM) vec[index] = 1.0 vec[-1] = atom.GetMass() / 100 return vec, ATOM_FDIM
def hydrogens(atom: Atom) -> int: """Total number of hydrogen atoms (int). """ return atom.GetTotalNumHs()