binding_affinity / dude.py
jglaser's picture
add dude processing scripts
8c24393
raw
history blame
2.01 kB
from mpi4py import MPI
from mpi4py.futures import MPICommExecutor
from Bio.PDB import PDBParser, PPBuilder
import warnings
import gzip
import tempfile
import os
from rdkit import Chem
import pandas as pd
def open_ligands(fn):
with tempfile.NamedTemporaryFile(mode='w+b',delete=False) as f:
with gzip.open(fn,'rb') as g:
f.write(g.read())
name = f.name
suppl = Chem.SDMolSupplier(name)
os.unlink(name)
return suppl
def get_ligands(path):
try:
parser = PDBParser()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
structure = parser.get_structure('protein',path+'/receptor.pdb')
ppb = PPBuilder()
seq = []
for pp in ppb.build_peptides(structure):
seq.append(str(pp.get_sequence()))
seq = ''.join(seq)
name = os.path.basename(path)
decoys = open_ligands(path+'/decoys_final.sdf.gz')
actives = open_ligands(path+'/actives_final.sdf.gz')
actives_smiles = []
for m in actives:
try:
actives_smiles.append(Chem.MolToSmiles(m))
except:
pass
decoys_smiles = []
for m in decoys:
try:
decoys_smiles.append(Chem.MolToSmiles(m))
except:
pass
all_smiles = actives_smiles + decoys_smiles
all_active = [True]*len(actives_smiles) + [False]*len(decoys_smiles)
names = [name]*len(all_active)
seqs = [seq]*len(all_active)
df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles, 'active': all_active})
df.to_parquet(path+'/ligands.parquet')
except Exception as e:
print(e)
pass
if __name__ == '__main__':
import glob
filenames = glob.glob('DUDE/all/*')
comm = MPI.COMM_WORLD
with MPICommExecutor(comm, root=0) as executor:
if executor is not None:
executor.map(get_ligands, filenames)