from mpi4py import MPI from mpi4py.futures import MPICommExecutor from openbabel import pybel from Bio import SeqIO import os def parse_complex(fn): try: name = os.path.basename(fn) seq = str(next(SeqIO.parse(fn+'/'+name+'_protein.pdb', "pdb-seqres")).seq) mol = next(pybel.readfile('sdf',fn+'/'+name+'_ligand.sdf')) smi = mol.write('can').split('\t')[0] return name, seq, smi except: return None if __name__ == '__main__': import glob filenames = glob.glob('pdbbind/data/v2020-other-PL/*') filenames.extend(glob.glob('pdbbind/data/refined-set/*')) comm = MPI.COMM_WORLD with MPICommExecutor(comm, root=0) as executor: if executor is not None: result = executor.map(parse_complex, filenames) result = list(result) names = [r[0] for r in result if r is not None] seqs = [r[1] for r in result if r is not None] all_smiles = [r[2] for r in result if r is not None] import pandas as pd df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles}) df.to_parquet('data/pdbbind_complex.parquet')