def _parse_atom(self, atom: Chem.Atom) -> None: if atom.GetSymbol() == '*': neighbor = atom.GetNeighbors()[0] n_name = self._get_pdb_atomname(neighbor) self.CONNECT.append([n_name, len(self.CONNECT) + 1, 'CONNECT']) else: d = self._get_atom_descriptors(atom) self.ATOM.append(d)
def atom_type_CO(atom: Chem.Atom) -> List[bool]: """Returns a one-hot list of length 2 for whether `atom` is a carbon or oxygen atom. """ anum = atom.GetSymbol() atom_feats = [ anum == 'C', anum == 'O', ] return atom_feats
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 is_sp2(atom: Chem.Atom) -> bool: N_neigh = len(atom.GetBonds()) symbol = atom.GetSymbol() if symbol == 'H': return False elif symbol == 'N' and N_neigh < 3: return True elif symbol == 'C' and N_neigh < 4: return True elif symbol == 'O' and N_neigh < 2: return True else: return False
def get_atom_type(self, atom: Chem.Atom) -> int: """ Get the atom type (represented as the index in self.atom_types) of the given atom `atom` Args: atom (Chem.Atom): The input atom Returns: int: The atom type as int """ atom_symbol = atom.GetSymbol() atom_charge = atom.GetFormalCharge() atom_hs = atom.GetNumExplicitHs() return self.atom_types.index((atom_symbol, atom_charge, atom_hs))
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 _parse_atom(self, atom: Chem.Atom) -> None: if atom.GetSymbol() == '*': neighbor = atom.GetNeighbors()[0] n_name = self._get_PDBInfo_atomname(neighbor) if self.is_aminoacid() and neighbor.GetSymbol() == 'N': # atom_name, index, connect_type, connect_name self.CONNECT.append([n_name, 1, 'LOWER_CONNECT', 'LOWER']) elif self.is_aminoacid() and neighbor.GetSymbol() == 'C': # atom_name, index, connect_type, connect_name self.CONNECT.append([n_name, 2, 'UPPER_CONNECT', 'UPPER']) elif self.is_aminoacid(): i = max(3, len(self.CONNECT) + 1) self.CONNECT.append([n_name, i, 'CONNECT']) else: self.CONNECT.append([n_name, len(self.CONNECT) + 1, 'CONNECT']) else: d = self._get_atom_descriptors(atom) self.ATOM.append(d)
def _parse_atom(self, atom: Chem.Atom) -> None: self.log.debug( f'Parsing {atom.GetSymbol()} at position {atom.GetIdx()}') if atom.GetSymbol() == '*': neighbor = atom.GetNeighbors()[0] n_name = self._get_PDBInfo_atomname(neighbor) if self.is_aminoacid() and neighbor.GetSymbol() == 'N': # atom_name, index, connect_type, connect_name self.CONNECT.append([n_name, 1, 'LOWER_CONNECT', 'LOWER']) elif self.is_aminoacid() and neighbor.GetSymbol() == 'C': # atom_name, index, connect_type, connect_name self.CONNECT.append([n_name, 2, 'UPPER_CONNECT', 'UPPER']) elif self.is_aminoacid(): i = max(3, len(self.CONNECT) + 1) self.CONNECT.append([n_name, i, 'CONNECT']) else: self.CONNECT.append([n_name, len(self.CONNECT) + 1, 'CONNECT']) else: d = self._get_atom_descriptors( atom) # dict of 'name', 'rtype': 'mtype', 'partial' self.ATOM.append(d) formal = atom.GetFormalCharge() if formal != 0: self.CHARGE.append([d['name'], formal])
def has_hybridization(self, atom: Atom): symbol = atom.GetSymbol() return symbol in self.ATOMS_WITH_HYBRIDIZATION
def _copy_atom(atom: Chem.Atom) -> Chem.Atom: new_atom = Chem.Atom(atom.GetSymbol()) new_atom.SetFormalCharge(atom.GetFormalCharge()) new_atom.SetNumRadicalElectrons(atom.GetNumRadicalElectrons()) return new_atom
def is_hydrogen(self, atom: Atom): return atom.GetSymbol() == "H"
def symbol(atom: Atom) -> str: """Atomic symbol (string). """ return atom.GetSymbol()