| from mpi4py import MPI | |
| from mpi4py.futures import MPICommExecutor | |
| from openbabel import pybel | |
| from Bio.PDB import * | |
| parser = PDBParser() | |
| import os | |
| molecular_weight_cutoff = 2500 | |
| def parse_ligand(fn): | |
| print(fn) | |
| try: | |
| struct = parser.get_structure('lig',fn) | |
| if len(list(struct.get_atoms())) > molecular_weight_cutoff: | |
| raise ValueError | |
| mol = next(pybel.readfile('pdb',fn)) | |
| if mol.molwt > molecular_weight_cutoff: | |
| raise ValueError | |
| smi = mol.write('can').split('\t')[0] | |
| return smi | |
| except: | |
| return None | |
| if __name__ == '__main__': | |
| import glob | |
| comm = MPI.COMM_WORLD | |
| with MPICommExecutor(comm, root=0) as executor: | |
| if executor is not None: | |
| import pandas as pd | |
| df = pd.read_table('biolip/data/BioLiP_2013-03-6_nr.txt',sep='\t',header=None,usecols=[0,4,5,6,13,14,15,16,19]) | |
| df = df.rename(columns={0:'pdb',4:'chain',5:'l_id',6:'l_chain', | |
| 13: 'affinity_lit',14: 'affinity_moad',15: 'affinity_pdbbind-cn',16:'affinity_bindingdb', | |
| 19: 'seq'}) | |
| base = 'biolip/data/ligand_nr/' | |
| df['ligand_fn'] = base + df['pdb']+'_'+df['chain']+'_'+df['l_id'].astype(str)+'_'+df['l_chain'].astype(str)+'.pdb' | |
| smiles = list(executor.map(parse_ligand, df['ligand_fn'])) | |
| df['smiles'] = smiles | |
| df.to_parquet('data/biolip_complex.parquet') | |