File size: 6,563 Bytes
1b9fa1d
 
3e2256f
1b9fa1d
fb9e841
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b9fa1d
 
43bf868
 
fb9e841
 
 
 
 
033bacd
 
 
fb9e841
 
033bacd
 
 
 
 
fb9e841
 
 
 
5e2e978
fb9e841
5e2e978
fb9e841
 
 
31efa71
fb9e841
 
 
 
 
 
 
 
 
 
 
5e2e978
fb9e841
5e2e978
fb9e841
 
 
31efa71
fb9e841
 
 
488fbc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb9e841
 
 
 
 
 
 
 
 
033bacd
 
 
fb9e841
 
 
 
5e2e978
fb9e841
5e2e978
fb9e841
 
 
31efa71
fb9e841
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import gradio as gr
import cg2all
import os


def read_mol(molpath):
    with open(molpath, "r") as fp:
        lines = fp.readlines()
    mol = ""
    for l in lines:
        mol += l
    #
    mol = mol.replace("OT1", "O  ")
    mol = mol.replace("OT2", "OXT")
    return mol


def molecule(input_pdb):
    mol = read_mol(input_pdb)
    x = (
        """<!DOCTYPE html>
        <html>
        <head>    
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <style>
    body{
        font-family:sans-serif
    }
    .mol-container {
    width: 100%;
    height: 600px;
    position: relative;
    }
    .mol-container select{
        background-image:None;
    }
    </style>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
    </head>
    <body>  

    <div id="container" class="mol-container"></div>
  
            <script>
               let pdb = `"""
        + mol
        + """`  
      
             $(document).ready(function () {
                let element = $("#container");
                let config = { backgroundColor: "white" };
                let viewer = $3Dmol.createViewer(element, config);
                viewer.addModel(pdb, "pdb");
                viewer.setStyle({}, {cartoon: { color:"spectrum"}});
                viewer.addStyle({"and":[{resn:["GLY","PRO"], invert:true}, {atom:["N","C","O"], invert:true}]}, {stick: {radius:0.2, colorscheme:"WhiteCarbon"}});
                viewer.addStyle({"and":[{resn:"GLY"}, {atom:"CA"}]}, {stick: {radius:0.2, colorscheme:"WhiteCarbon"}});
                viewer.addStyle({"and":[{resn:"PRO"}, {atom:["C","O"], invert:true}]}, {stick: {radius:0.2, colorscheme:"WhiteCarbon"}});
                viewer.zoomTo();
                viewer.render();
                viewer.zoom(0.8, 2000);
              })
        </script>
        </body></html>"""
    )

    return f"""<iframe style="width: 100%; height: 600px" name="result" allow="midi; geolocation; microphone; camera; 
    display-capture; encrypted-media;" sandbox="allow-modals allow-forms 
    allow-scripts allow-same-origin allow-popups 
    allow-top-navigation-by-user-activation allow-downloads" allowfullscreen="" 
    allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""


def runner(in_pdb, model_type):
    out_fn = in_pdb.name[:-4] + "-all.pdb"
    ckpt_fn = f"model/{model_type}.ckpt"
    cg2all.convert_cg2all(in_pdb.name, out_fn, model_type=model_type, ckpt_fn=ckpt_fn)
    view = molecule(out_fn)
    return out_fn, view


with gr.Blocks() as app:
    gr.Markdown(
        "# cg2all: conversion of coarse-grained protein structure model to all-atom structure"
    )
    with gr.Row():
        with gr.Column():
            input_pdb = gr.File(
                file_count="single",
                label="Input CG structure",
                file_types=[".pdb", ".PDB", ".txt", ".TXT"],
            )
            model_type = gr.Radio(
                [
                    "CalphaBasedModel",
                    "ResidueBasedModel",
                    "SidechainModel",
                    "CalphaCMModel",
                    "CalphaSCModel",
                    "BackboneModel",
                    "MainchainModel",
                    "Martini",
                    "Martini3",
                    "PRIMO",
                ],
                label="Input CG model type",
            )
            #
            button = gr.Button("Run")
            #
            gr.Examples(
                [
                    ["inputs/1ab1_A.calpha.pdb", "CalphaBasedModel"],
                    ["inputs/1ab1_A.residue.pdb", "ResidueBasedModel"],
                    ["inputs/1ab1_A.sc.pdb", "SidechainModel"],
                    ["inputs/1ab1_A.cacm.pdb", "CalphaCMModel"],
                    ["inputs/1ab1_A.casc.pdb", "CalphaSCModel"],
                    ["inputs/1ab1_A.bb.pdb", "BackboneModel"],
                    ["inputs/1ab1_A.mc.pdb", "MainchainModel"],
                    ["inputs/1ab1_A.martini.pdb", "Martini"],
                    ["inputs/1ab1_A.martini3.pdb", "Martini3"],
                    ["inputs/1ab1_A.primo.pdb", "PRIMO"],
                ],
                [input_pdb, model_type],
                label="Monomeric coarse-grained structure",
            )
            gr.Examples(
                [
                    ["inputs/Q9EP54.sample.pdb", "CalphaBasedModel"],
                ],
                [input_pdb, model_type],
                label="ML(idpGAN)-generated IDP structure",
            )
            gr.Examples(
                [
                    ["inputs/3iyg.pdb", "CalphaBasedModel"],
                ],
                [input_pdb, model_type],
                label="Multimeric medium-resolution cryo-EM structure",
            )
            gr.Examples(
                [
                    ["inputs/LAF1rgg.sample.pdb", "CalphaBasedModel"],
                ],
                [input_pdb, model_type],
                label="Snapshot of COCOMO simulation of LLPS",
            )

        with gr.Column():
            output_pdb = gr.File(file_count="single", label="Output structure")
            viewer = gr.HTML()

        button.click(fn=runner, inputs=[input_pdb, model_type], outputs=[output_pdb, viewer])
    #
    gr.Markdown("---")
    gr.Markdown(
        "### GitHub repository: [https://github.com/huhlim/cg2all](https://github.com/huhlim/cg2all)"
    )
    gr.Markdown("### Local installation: `pip install git+http://github.com/huhlim/cg2all`")
    gr.Markdown("### Supported coarse-grained models")
    gr.Markdown("- CalphaBasedModel: CA-trace")
    gr.Markdown("- ResidueBasedModel: Residue center-of-mass")
    gr.Markdown("- SidechainModel: Sidechain center-of-mass")
    gr.Markdown("- CalphaCMModel: CA-trace + Residue center-of-mass")
    gr.Markdown("- CalphaSCModel: CA-trace + Sidechain center-of-mass")
    gr.Markdown("- BackboneModel: Backbone N, CA, and C atoms")
    gr.Markdown("- MainchainModel: Backbone N, CA, C, and O atoms")
    gr.Markdown("- Martini: [Martini model](http://cgmartini.nl)")
    gr.Markdown("- Martini3: [Martini3 model](http://www.cgmartini.nl/index.php/martini-3-0)")
    gr.Markdown("- PRIMO: [PRIMO model](https://dx.doi.org/10.1002/prot.22645)")

    gr.Markdown("### Cite: TODO")

app.launch()