-
Notifications
You must be signed in to change notification settings - Fork 1
/
esmfold.py
96 lines (71 loc) · 3.56 KB
/
esmfold.py
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
import streamlit as st
from stmol import showmol
import py3Dmol
import requests
import biotite.structure.io as bsio
st.set_page_config(
page_title="ESMFold Protein Structure Predictor",
page_icon="🧬",
layout="wide",
)
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
# Homebutton
if st.sidebar.button('Home'):
st.markdown('<meta http-equiv="refresh" content="0;URL=https://cloud.wijerathne.com">', unsafe_allow_html=True)
#st.set_page_config(layout = 'wide')
st.sidebar.title(':rainbow[ESMFold] - :orange[Protein Predictor]')
st.sidebar.subheader(':gray[Evolutionary-scale prediction of atomic-level protein structure with a language model]')
# stmol
def render_mol(pdb):
pdbview = py3Dmol.view()
pdbview.addModel(pdb,'pdb')
pdbview.setStyle({'cartoon':{'color':'spectrum'}})
pdbview.setBackgroundColor('white')#('0xeeeeee')
pdbview.zoomTo()
pdbview.zoom(1.3, 800)
pdbview.spin(True)
showmol(pdbview, height = 500,width=800)
# Protein sequence input
DEFAULT_SEQ = "MGSSHHHHHHSQDLMVTSTYIPMSQRRSWADVKPIMQDDGPNPVVPIMYSEEYKDAMDYFRAIAAKEEKSERALELTEIIVRMNPAHYTVWQYRFSLLTSLNKSLEDELRLMNEFAVQNLKSYQVWHHRLLLLDRISPQDPVSEIEYIHGSLLPDPKNYHTWAYLHWLYSHFSTLGRISEAQWGSELDWCNEMLRVDGRNNSAWGWRWYLRVSRPGAETSSRSLQDELIYILKSIHLIPHNVSAWNYLRGFLKHFSLPLVPILPAILPYTASKLNPDIETVEAFGFPMPSDPLPEDTPLPVPLALEYLADSFIEQNRVDDAAKVFEKLSSEYDQMRAGYWEFRRRECAE "
txt = st.sidebar.text_area(':orange[Input sequence]', DEFAULT_SEQ, height=275)
# ESMfold
def update(sequence=txt):
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post('https://api.esmatlas.com/foldSequence/v1/pdb/', headers=headers, data=sequence, verify=False) # Added verify=False
name = sequence[:3] + sequence[-3:]
pdb_string = response.content.decode('utf-8')
with open('predicted.pdb', 'w') as f:
f.write(pdb_string)
struct = bsio.load_structure('predicted.pdb', extra_fields=["b_factor"])
b_value = round(struct.b_factor.mean(), 5)
# Display protein structure
st.subheader(':orange[Predicted Protein Structure]')
st.write('Click and Hold to rotate & Use :orange[Ctrl + Scroll] to Zoom in and out.')
render_mol(pdb_string)
# plDDT value is stored in the B-factor field
st.subheader(f'Per-residue confidence score (pLDDT): {b_value}')
st.subheader('' ,divider='rainbow')
percentage_value = round(b_value * 100, 2)
st.info(f'plDDT: {percentage_value}%')
st.write('plDDT is a per-residue estimate of the confidence in prediction on a scale from 0-100. Values greater than 90 indicating high confidence, and values below 50 indicating low confidence.')
st.download_button(
label="Download PDB File",
data=pdb_string,
file_name='predicted-protein-PDB.pdb',
mime='text/plain',
)
# Homebutton
if st.button('Back to Home'):
st.markdown('<meta http-equiv="refresh" content="0;URL=https://cloud.wijerathne.com">', unsafe_allow_html=True)
predict = st.sidebar.button('Predict', on_click=update)
if not predict:
st.warning('⬅️ 🧬 Enter the protein sequence data from the menu!')
st.sidebar.write('[*ESMFold*](https://esmatlas.com/about) is an end-to-end single sequence protein structure predictor based on the ESM-2 language model. The model and this app is based on Meta AI ESMfold. For more information, please follow the [metaAi](https://ai.meta.com/blog/protein-folding-esmfold-metagenomics/).')