File size: 2,012 Bytes
8c24393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)