Spaces:
Runtime error
Runtime error
Simon Duerr commited on
Commit ·
de38e57
1
Parent(s): fceeb17
add sasa and plddt selection
Browse filesFiles changed (3)
- README.md+1-1
- app.py+63-28
- requirements.txt+2-2
3 unmodified lines456789103 unmodified linescolorFrom: redcolorTo: pinksdk: gradiosdk_version: 3.0.11app_file: app.pypinned: falselicense: mit3 unmodified lines456789103 unmodified linescolorFrom: redcolorTo: pinksdk: gradiosdk_version: 3.1app_file: app.pypinned: falselicense: mit
1234567891011121314151617181920212223242526272829303132332 unmodified lines363738394041424344454647484950515253545556575859262 unmodified lines322323324325326327328329330331791 unmodified lines112311241125112611271128112915 unmodified lines114511461147114811491150import json, time, os, sys, globimport gradio as grsys.path.append("/home/user/app/ProteinMPNN/vanilla_proteinmpnn")sys.path.append("/home/duerr/phd/08_Code/ProteinMPNN/ProteinMPNN/vanilla_proteinmpnn")import matplotlib.pyplot as pltimport shutilimport warningsimport numpy as npimport torchfrom torch import optimfrom torch.utils.data import DataLoaderfrom torch.utils.data.dataset import random_split, Subsetimport copyimport torch.nn as nnimport torch.nn.functional as Fimport randomimport osimport os.pathimport plotly.express as pximport urllibimport jax.numpy as jnpimport tensorflow as tffrom moleculekit.molecule import Moleculeif "/home/user/app/af_backprop" not in sys.path:sys.path.append("/home/user/app/af_backprop")2 unmodified linesif "/home/duerr/phd/08_Code/ProteinMPNN/af_backprop" not in sys.path:sys.path.append("/home/duerr/phd/08_Code/ProteinMPNN/af_backprop")from utils import *# import librariesimport colabfold as cffrom alphafold.common import proteinfrom alphafold.data import pipelinefrom alphafold.model import data, configfrom alphafold.model import model as afmodelfrom alphafold.common import residue_constantsimport plotly.graph_objects as goimport rayimport reimport numpy as npimport jaxtf.config.set_visible_devices([], "GPU")262 unmodified linesmol.write("cleaned.pdb")return "cleaned.pdb", dfdef make_fixed_positions_dict(atomsel, residue_index_df):# we use the uploaded file for the selectionmol = Molecule('original.pdb')# use index for selection as resids will changeselected_residues = mol.get("index",atomsel)# clean up791 unmodified lines- <code>resid 94 96 119</code> Residues 94, 94 and 119- <code>within 5 of resname ZN</code> All residues with any atom <5 Å of zinc ion- <code>chain A and within 5 of chain B </code> All residues of chain A that are part of the interface with chain B- <code>protein and within 5 of nucleic </code> All residues that bind to DNA (if present in structure)""")atomsel = gr.Textbox(placeholder="Specify atom selection ", label="Fixed positions")btn = gr.Button("Run")15 unmodified lines["Redesign of Homomer to Heteromer", "3HTN", "A,B", "C", False, 2, 0.1, ""],["Redesign of MID1 scaffold keeping binding site fixed", "3V1C", "A,B", "", False, 2, 0.1, "within 5 of resname ZN"],["Redesign of DNA binding protein", "3JRD", "A,B", "", False, 2, 0.1, "within 8 of nucleic"],],)1234567891011121314151617181920212223242526272829302 unmodified lines33343536373839404142434445464748495051525354262 unmodified lines317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359791 unmodified lines115111521153115411551156115711581159116011611162116315 unmodified lines1179118011811182118311841185import json, time, os, sys, globimport urllibimport shutilimport warningsimport copyimport randomimport reimport os.pathimport torchimport rayimport jaximport gradio as grimport pandas as pdimport numpy as npimport plotly.express as pximport jax.numpy as jnpimport tensorflow as tfimport matplotlib.pyplot as pltimport colabfold as cfimport plotly.graph_objects as goimport torch.nn as nnimport torch.nn.functional as Fif "/home/user/app/af_backprop" not in sys.path:sys.path.append("/home/user/app/af_backprop")2 unmodified linesif "/home/duerr/phd/08_Code/ProteinMPNN/af_backprop" not in sys.path:sys.path.append("/home/duerr/phd/08_Code/ProteinMPNN/af_backprop")from torch import optimfrom torch.utils.data import DataLoaderfrom torch.utils.data.dataset import random_split, Subsetfrom moleculekit.molecule import Moleculefrom alphafold.common import proteinfrom alphafold.data import pipelinefrom alphafold.model import data, configfrom alphafold.model import model as afmodelfrom alphafold.common import residue_constantsfrom utils import *sys.path.append("/home/user/app/ProteinMPNN/vanilla_proteinmpnn")sys.path.append("/home/duerr/phd/08_Code/ProteinMPNN/ProteinMPNN/vanilla_proteinmpnn")tf.config.set_visible_devices([], "GPU")262 unmodified linesmol.write("cleaned.pdb")return "cleaned.pdb", dfdef assign_sasa(mol):from moleculekit.projections.metricsasa import MetricSasametr = MetricSasa(mode="residue", filtersel="protein")sasaR = metr.project(mol)[0]is_prot = mol.atomselect("protein")resids=pd.DataFrame.from_dict({"resid":mol.resid, "is_prot":is_prot})new_masses=[]i_without_non_prot = 0for i, g in resids.groupby((resids['resid'].shift() != resids['resid']).cumsum()):if g["is_prot"].unique()[0]==True:g["sasa"]=sasaR[i_without_non_prot]i_without_non_prot+=1else:g["sasa"]=0new_masses.extend(list(g.sasa))return np.array(new_masses)def process_atomsel(atomsel):"""everything lowercase and replace some keywords not relevant for protein design"""atomsel=re.sub('sasa', 'mass',atomsel, flags=re.I)atomsel=re.sub('plddt', 'beta',atomsel, flags=re.I)return atomseldef make_fixed_positions_dict(atomsel, residue_index_df):# we use the uploaded file for the selectionmol = Molecule('original.pdb')# use index for selection as resids will change# set sasa to 0 for all non protein atoms (all non protein atoms are deleted later)mol.masses = assign_sasa(mol)print(mol.masses.shape)print(assign_sasa(mol).shape)atomsel = process_atomsel("chain B or (chain A and Sasa < 30)")selected_residues = mol.get("index",atomsel)# clean up791 unmodified lines- <code>resid 94 96 119</code> Residues 94, 94 and 119- <code>within 5 of resname ZN</code> All residues with any atom <5 Å of zinc ion- <code>chain A and within 5 of chain B </code> All residues of chain A that are part of the interface with chain B- <code>protein and within 5 of nucleic </code> All residues that bind to DNA (if present in structure)- <code>not (chain A and within 5 of chain B) </code> only modify residues that are in the interface with the fixed chain, not further away- <code>chain A or (chain B and sasa < 20) </code> Keep chain A and all core residues fixeds- <code>pLDDT >70 </code> Redesign all residues with low pLDDTNote that <code>sasa</code> and <code>pLDDT</code> selectors modify default VMD behavior. SASA is calculated using moleculekit and written to the mass attribute. Selections based on mass do not work.pLDDT is an alias for beta, it only works correctly with structures that contain the appropriate values in the beta column of the PDB file. """)atomsel = gr.Textbox(placeholder="Specify atom selection ", label="Fixed positions")btn = gr.Button("Run")15 unmodified lines["Redesign of Homomer to Heteromer", "3HTN", "A,B", "C", False, 2, 0.1, ""],["Redesign of MID1 scaffold keeping binding site fixed", "3V1C", "A,B", "", False, 2, 0.1, "within 5 of resname ZN"],["Redesign of DNA binding protein", "3JRD", "A,B", "", False, 2, 0.1, "within 8 of nucleic"],["Surface Redesign of miniprotein", "7JZM", "A,B", "", False, 2, 0.1, "chain B or (chain A and sasa < 20)"],],)
17 unmodified lines18192021222317 unmodified linesGPUtilraytqdmgradio==3.0.11protobuf<4-f https://storage.googleapis.com/jax-releases/jax_releases.html17 unmodified lines18192021222317 unmodified linesGPUtilraytqdmgradio==3.1protobuf<4-f https://storage.googleapis.com/jax-releases/jax_releases.html
README.md+1-1
app.py+63-28
requirements.txt+2-2