|
from mpi4py import MPI |
|
from mpi4py.futures import MPICommExecutor |
|
|
|
from Bio.PDB import PDBParser, PDBIO, Select, PPBuilder |
|
import warnings |
|
|
|
import tempfile |
|
import os |
|
import sys |
|
from rdkit import Chem |
|
|
|
import pandas as pd |
|
|
|
def is_het(residue): |
|
res = residue.id[0] |
|
return res != " " and res != "W" |
|
|
|
|
|
class ResidueSelect(Select): |
|
def __init__(self, het): |
|
self.het = het |
|
|
|
def accept_residue(self, residue): |
|
""" Recognition of heteroatoms - Remove water molecules """ |
|
return (self.het and is_het(residue) or not self.het and not is_het(residue)) |
|
|
|
def get_complex(fn): |
|
try: |
|
parser = PDBParser() |
|
io = PDBIO() |
|
structure = parser.get_structure('complex',fn) |
|
io.set_structure(structure) |
|
|
|
with tempfile.NamedTemporaryFile(mode='w',delete=False) as f: |
|
name_receptor = f.name |
|
|
|
with tempfile.NamedTemporaryFile(mode='w',delete=False) as f: |
|
name_ligand = f.name |
|
|
|
io.save(name_receptor,ResidueSelect(het=False)) |
|
io.save(name_ligand,ResidueSelect(het=True)) |
|
|
|
parser = PDBParser() |
|
receptor = parser.get_structure('protein',name_receptor) |
|
ppb = PPBuilder() |
|
seq = [] |
|
for pp in ppb.build_peptides(structure): |
|
seq.append(str(pp.get_sequence())) |
|
seq = ''.join(seq) |
|
|
|
mol = Chem.MolFromPDBFile(name_ligand) |
|
smiles = Chem.MolToSmiles(mol) |
|
|
|
os.unlink(name_ligand) |
|
os.unlink(name_receptor) |
|
|
|
return seq, smiles |
|
|
|
except Exception as e: |
|
print(e) |
|
pass |
|
|
|
|
|
if __name__ == '__main__': |
|
import glob |
|
|
|
filenames = glob.glob(sys.argv[2]) |
|
comm = MPI.COMM_WORLD |
|
with MPICommExecutor(comm, root=0) as executor: |
|
if executor is not None: |
|
result = executor.map(get_complex, filenames) |
|
|
|
names = [] |
|
all_seq = [] |
|
all_smiles = [] |
|
for n,r in zip(filenames,result): |
|
try: |
|
all_seq.append(r[0]) |
|
all_smiles.append(r[1]) |
|
names.append(os.path.basename(n)) |
|
except: |
|
pass |
|
df = pd.DataFrame({'name': names, 'seq': all_seq, 'smiles': all_smiles}) |
|
df.to_parquet(sys.argv[1]) |
|
|
|
|