Spaces:
Sleeping
Sleeping
File size: 4,465 Bytes
8c639ec 22e3abd 8c639ec 22e3abd 8c639ec 22e3abd 8c639ec |
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 |
from pymol import cmd
import os
import json
import time
import threading
try:
from gradio_client import Client
except ImportError:
print("gradio_client not installed, trying install:")
import pip
pip.main(['install', 'gradio_client'])
from gradio_client import Client
if os.environ.get("GRADIO_LOCAL") != None:
public_link = "http://127.0.0.1:7860"
else:
public_link = "ProteinDesignLab/protpardelle"
def thread_protpardelle(input_pdb,
resample_idxs,
modeltype,
mode,
minlen=50,
maxlen= 60,
steplen = 2,
per_len = 2):
client = Client(public_link)
job = client.submit(
input_pdb, # str in 'PDB Content' Textbox component
modeltype, # str in 'Choose a Mode' Radio component
f'"{resample_idxs}"', # str in 'Resampled Idxs' Textbox component
mode, # str (Option from: ['backbone', 'allatom'])
minlen, # int | float (numeric value between 2 and 200) minlen
maxlen, # int | float (numeric value between 3 and 200) in 'maxlen' Slider component
steplen, # int | float (numeric value between 1 and 50) in 'steplen' Slider component
per_len, # int | float (numeric value between 1 and 200) in 'perlen' Slider component
api_name="/protpardelle"
)
#start time
start = time.time()
while (job.done() == False):
status = job.status()
elapsed = time.time()-start
# format as hh:mm:ss
elapsed = time.strftime("%H:%M:%S", time.gmtime(elapsed))
print(f"\r protpardelle running since {elapsed}", end="")
time.sleep(1)
results = job.result()
# load each result into pymol
results = json.loads(results)
for (name,pdb_content) in results:
print(name)
cmd.read_pdbstr(pdb_content, os.path.basename(name))
def query_protpardelle(
name_of_input: str,
selection_resample_idxs: str="",
per_len: int = 2,
mode: str="allatom",
):
"""
AUTHOR
Simon Duerr
https://twitter.com/simonduerr
DESCRIPTION
Run Protpardelle
USAGE
protpardelle name_of_input, selection_resampled_idx, modeltype, mode, per_len
PARAMETERS
name_of_input = string: name of input object
selection_resampled_idx = string: selection of resampled protein residues
per_len = int: per_len (default: 2)
mode = string: mode (default: 'allatom')
"""
if name_of_input != "":
input_pdb = cmd.get_pdbstr(name_of_input)
all_aa = cmd.index(name_of_input+" and name CA")
idx = cmd.index(selection_resample_idxs+" and name CA")
#map to zero indexed values
aa_mapping = {aa[1]:i for i,aa in enumerate(all_aa)}
idx = ",".join([str(aa_mapping[aa[1]]) for aa in idx])
print("resampling", idx , "(zero indexed) from", name_of_input)
t = threading.Thread(target=thread_protpardelle,
args=(input_pdb, idx, "conditional",mode ),
kwargs={'per_len':per_len},
daemon=True)
t.start()
def query_protpardelle_uncond(
minlen: int = 50,
maxlen: int = 60,
steplen: int = 2,
per_len: int = 2,
mode: str="allatom",
):
"""
AUTHOR
Simon Duerr
https://twitter.com/simonduerr
DESCRIPTION
Run Protpardelle
USAGE
protpardelle_uncond minlen, maxlen, steplen, per_len,mode
PARAMETERS
minlen = int: minlen
maxlen = int: maxlen
steplen = int: steplen
per_len = int: per_len
mode = string: mode (default: 'allatom')
"""
modeltype = "unconditional"
idx = None
input_pdb = None
t = threading.Thread(target=thread_protpardelle,
args=(input_pdb, idx, modeltype, mode),
kwargs={'minlen':minlen, 'maxlen':maxlen, 'steplen':steplen,'per_len':per_len},
daemon=True)
t.start()
def setprotpardellelink(link:str):
"""
AUTHOR
Simon Duerr
https://twitter.com/simonduerr
DESCRIPTION
Set a public link to use a locally hosted version of this space
USAGE
protpardelle_setlink link_or_username/spacename
"""
global public_link
try:
client = Client(link)
except:
print("could not connect to:", public_link)
public_link = link
cmd.extend("protpardelle_setlink", setprotpardellelink)
cmd.extend("protpardelle", query_protpardelle)
cmd.extend("protpardelle_uncond", query_protpardelle_uncond)
|