File size: 4,139 Bytes
580db5b b0cb70d 9f2073b 289b045 b0cb70d 9f2073b b0cb70d 9f2073b efd57a2 3363489 9f2073b 1742c86 1714685 9f2073b b0cb70d 5a255ae 12fcf9e 9f2073b 1f3c26c efd57a2 1f3c26c 580db5b 9f2073b c9bfe79 fb540ae e90417a 9f2073b c8cad2c 9f2073b 289b045 9f2073b a10eab8 9f2073b 64f9281 9f2073b 6839858 9f2073b 6839858 61ecdb3 6839858 289b045 |
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 |
import gradio as gr
from igfold import IgFoldRunner
import os
import random
def read_mol(molpath):
with open(molpath, "r") as fp:
lines = fp.readlines()
mol = ""
for l in lines:
mol += l
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>
<script type="text/javascript" >
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
document.getElementById("dwn-btn").addEventListener("click", function(){
var filename = "result.pdb";
download(filename, "test";
}, false);
</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.getModel(0).setStyle({}, {cartoon:{color:"spectrum"}});
viewer.addSurface($3Dmol.SurfaceType.VDW, {opacity: 0.7, color: "lightblue"});
viewer.zoomTo();
viewer.render();
viewer.zoom(0.8, 2000);
})
</script>
</body></html>"""
)
return dw_script + 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>
<p><input type="button" id="dwn-btn" value="Download dinamically generated text file"/></p>
"""
def validate(seq):
alphabet = set('ACDEFGHIKLMNPQRSTVWY')
leftover = set(seq.upper()) - alphabet
return not leftover
def pred_seq(h_seq, l_seq):
h_seq = h_seq.upper()
l_seq = l_seq.upper()
h_is_valid = validate(h_seq)
l_is_valid = validate(l_seq)
if h_is_valid and l_is_valid:
sequences = {
"H": h_seq,
"L": l_seq
}
f_name = ''.join([random.choice("ACDEFGHIKLMNPQRSTVWY") for _ in range(15)])
pred_pdb = f"{f_name}.pdb"
igfold = IgFoldRunner()
igfold.fold(
pred_pdb,
sequences=sequences,
do_refine=False,
do_renum=False,
)
html = molecule(pred_pdb)
else:
html = "<p>ERROR! Not valid sequence</p>"
return (html)
inputs = [gr.Textbox(lines=5, label="Heavy chain"),
gr.Textbox(lines=5, label="Light chain")
]
iface = gr.Interface(fn=pred_seq,
inputs=inputs,
outputs=gr.HTML(),
title="Antibody structure prediction")
iface.launch(share = True) |