def get_smarts(pdb_file): """ Use RDKit to get the smarts string of the molecule. :param pdb_file: The molecule input file :return: The smarts string """ mol = MolFromPDBFile(pdb_file, removeHs=False) return MolToSmarts(mol)
def get_smiles(pdb_file): """ Use RDKit to load in the pdb file of the molecule and get the smiles code. :param pdb_file: The molecule input file :return: The smiles string """ mol = MolFromPDBFile(pdb_file, removeHs=False) return MolToSmiles(mol, isomericSmiles=True, allHsExplicit=True)
def get_mol(pdb_file): """ Use RDKit to generate a mol file. :param pdb_file: The molecule input file :return: The name of the mol file made """ mol = MolFromPDBFile(pdb_file, removeHs=False) mol_name = f'{pdb_file[:-4]}.mol' MolToMolFile(mol, mol_name) return mol_name
def read_file(filename): molecule = [] file_type = filename.split('.')[-1] if file_type == 'pdb': mol = MolFromPDBFile(filename, removeHs=False) elif file_type == 'mol2': mol = MolFromMol2File(filename, removeHs=False) else: mol = None print(mol) return molecule
def _make_atom_graph(self, pdb_code=None, pdb_path=None, node_featurizer=None, edge_featurizer=None, graph_type='bigraph'): """ Create atom-level graph from PDB structure :param graph_type: :param pdb_code: :param pdb_path: :param node_featurizer: :param edge_featurizer: :return: """ if node_featurizer is None: node_featurizer = CanonicalAtomFeaturizer() if edge_featurizer is None: edge_featurizer = CanonicalBondFeaturizer() # Read in protein as mol # if pdb_path: if pdb_code: pdb_path = self.pdb_dir + pdb_code + '.pdb' if not os.path.isfile(pdb_path): self._download_pdb(pdb_code) assert os.path.isfile(pdb_path) mol = MolFromPDBFile(pdb_path) # DGL mol to graph if graph_type == 'bigraph': g = mol_to_bigraph(mol, node_featurizer=node_featurizer, edge_featurizer=edge_featurizer) elif graph_type == 'complete': g = mol_to_complete_graph( mol, node_featurizer=node_featurizer, ) elif graph_type == 'k_nn': raise NotImplementedError print(g) return g
def rdkit_descriptors(pdb_file): """ Use RDKit Descriptors to extract properties and store in Descriptors dictionary. :param pdb_file: The molecule input file :return: Descriptors dictionary """ mol = MolFromPDBFile(pdb_file, removeHs=False) # Use RDKit Descriptors to extract properties and store in Descriptors dictionary descriptors = { 'Heavy atoms': Descriptors.HeavyAtomCount(mol), 'H-bond donors': Descriptors.NumHDonors(mol), 'H-bond acceptors': Descriptors.NumHAcceptors(mol), 'Molecular weight': Descriptors.MolWt(mol), 'LogP': Descriptors.MolLogP(mol) } return descriptors
def read_file(self, filename): # This handles splitting the paths filename = Path(filename) # Try and read the file if filename.suffix == '.pdb': mol = MolFromPDBFile(filename.name, removeHs=False) try: rdPartialCharges.ComputeGasteigerCharges(mol) except RuntimeError: print('RDKit could not assign the partial charges') elif filename.suffix == '.mol2': mol = MolFromMol2File(filename.name, removeHs=False) elif filename.suffix == '.mol': mol = MolFromMolFile(filename.name, removeHs=False) else: mol = None return mol
def mm_optimise(pdb_file, ff='MMF'): """ Perform rough preliminary optimisation to speed up later optimisations. :param pdb_file: The name of the input pdb file :param ff: The Force field to be used either MMF or UFF :return: The name of the optimised pdb file that is made """ force_fields = { 'MMF': MMFFOptimizeMolecule, 'UFF': UFFOptimizeMolecule } mol = MolFromPDBFile(pdb_file, removeHs=False) mol_name = pdb_file[:-4] force_fields[ff](mol) AllChem.MolToPDBFile(mol, f'{mol_name}_rdkit_optimised.pdb') return f'{mol_name}_rdkit_optimised.pdb'
def pdb2rdmol(pdb): return MolFromPDBFile(pdb, False, False)