make_grid.py 3.35 KB
Newer Older
1
2
3
4
5
6
7
"""
Create a protein/ligand grid. Can compile to JavaScript using Transcrypt.
"""

from gridder.util import load_receptor, load_ligand, mol_to_points, get_connection_point
from gridder.grid_util import get_raw_batch
from gridder.fake_rdkit import Point
jdurrant's avatar
jdurrant committed
8
9

# __pragma__ ('skip')
Jacob Durrant's avatar
Jacob Durrant committed
10
import json
11

jdurrant's avatar
jdurrant committed
12
13
# __pragma__ ('noskip')

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""?
from gridder.example_data import receptor_pdb, ligand_sdf
?"""

# Data Format
#
# Receptor data:
# - rec_lookup:     [id][start][end]
# - rec_coords:     [x][y][z]
# - rec_types:      [num][is_hacc][is_hdon][is_aro][pcharge]
#
# Fragment data:
# - frag_lookup:    [id][fstart][fend][pstart][pend]
# - frag_coords:    [x][y][z]
# - frag_types:     [num]
# - frag_smiles:    [smiles]
# - frag_mass:      [mass]
# - frag_dist:      [dist]

jdurrant's avatar
jdurrant committed
33
34
35
36
37
"""?
def get_test_data():
    return receptor_pdb, ligand_sdf
?"""

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

def make_grid(receptor: str, ligand: str, grid_center: list) -> None:
    """Makes a grid from the receptor or ligand.

    :param receptor:    The receptor. A file name if running from the command
                        line, or the PDB-formated contents if running in the
                        browser.
    :type receptor:     str
    :param ligand:      The ligand. A file name if running from the command
                        line, or the SDF-formated contents if running in the
                        browser.
    :type ligand:       str
    :param grid_center: The center of the grid. In the browser, it will be
                        identified using 3Dmol.js.
    :type grid_center: List
    """

    # load ligand and receptor

    rec = load_receptor(receptor)
jdurrant's avatar
jdurrant committed
58
59

    # If SDF
60
61
    lig, frags = load_ligand(ligand)  # List of tuples, (parent, frag)

jdurrant's avatar
jdurrant committed
62
63
64
65
    # If PDB
    # l = load_receptor(ligand)
    # lig, frags = None, [(l, None)]  # to get pdb to work

66
    # compute shared receptor coords and layers
Jacob Durrant's avatar
Jacob Durrant committed
67
    rec_coords, rec_layers = mol_to_points(rec, None, note_sulfur=True)
68
69

    # Only keep the first fragment. A JDD addition.
jdurrant's avatar
jdurrant committed
70
71
    # frags = frags[:1]
    frags = [frags[0]]
72
73
74
75

    for parent, frag in frags:

        # compute parent coords and layers
Jacob Durrant's avatar
Jacob Durrant committed
76
        parent_coords, parent_layers = mol_to_points(parent, None, note_sulfur=False)
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

        # find connection point
        # __pragma__ ('skip')
        try:
            conn = get_connection_point(frag)
        except:
            # If runing under python with fake_rdkit
            conn = Point(grid_center)
        # __pragma__ ('noskip')

        """?
        conn = Point(grid_center)
        ?"""

        # generate batch
        grid = get_raw_batch(
Jacob Durrant's avatar
Jacob Durrant committed
93
94
95
96
97
98
            rec_coords,
            rec_layers,
            parent_coords,
            parent_layers,
            conn,
            1,
jdurrant's avatar
jdurrant committed
99
100
            24,  # width=
            0.75,  # res=
101
102
        )

jdurrant's avatar
jdurrant committed
103
        # __pragma__ ('skip')
Jacob Durrant's avatar
Jacob Durrant committed
104
        print(json.dumps(grid))
jdurrant's avatar
jdurrant committed
105
106
107
108
109
110
        # __pragma__ ('noskip')

        """?
        # print(str(grid))
        return grid
        ?"""
111
112
113
114


if __name__ == "__main__":
    # __pragma__ ('skip')
jdurrant's avatar
jdurrant committed
115
116
117
118
119
120
121
122
123
    print(
        make_grid(
            # "./1b6l/1b6l_protein.pdb",
            "11gs/11gs_protein.pdb",
            # "./1b6l/1b6l_ligand.sdf",
            "11gs/11gs_ligand.minus-grid0-frag.sdf",
            # [0.512000, 3.311000, 12.006000],
            [14.62, 9.944, 24.471],
        )
124
125
126
127
    )
    # __pragma__ ('noskip')

    """?
jdurrant's avatar
jdurrant committed
128
129
130
131
132
    # make_grid(
    #     receptor_pdb,
    #     ligand_sdf,
    #     [14.62, 9.944, 24.471],
    # )
133
    ?"""