aiqcamp commited on
Commit
a71505c
·
verified ·
1 Parent(s): cebc63d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -35
app.py CHANGED
@@ -284,7 +284,6 @@ def display_pdb(path_to_pdb):
284
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
285
  '''
286
 
287
-
288
  def get_motif_preview(pdb_id, contigs):
289
  try:
290
  input_pdb = fetch_pdb(pdb_id=pdb_id.lower() if pdb_id else None)
@@ -292,44 +291,39 @@ def get_motif_preview(pdb_id, contigs):
292
  return gr.HTML("PDB ID를 입력해주세요"), None
293
 
294
  parse = parse_pdb(input_pdb)
295
-
296
-
297
- #output_name = './rewrite_'+input_pdb.split('/')[-1]
298
- #writepdb(output_name, torch.tensor(parse_og['xyz']),torch.tensor(parse_og['seq']))
299
- #parse = parse_pdb(output_name)
300
- output_name = input_pdb
301
 
302
- pdb = open(output_name, "r").read()
303
- view = py3Dmol.view(width=500, height=500)
304
- view.addModel(pdb, "pdb")
305
 
306
- if contigs in ['',0]:
307
- contigs = ['0']
308
- else:
309
- contigs = [contigs]
310
 
311
- print('DEBUG: ',contigs)
312
-
313
- pdb_map = get_mappings(ContigMap(parse,contigs))
314
- print('DEBUG: ',pdb_map)
315
- print('DEBUG: ',pdb_map['con_ref_idx0'])
316
- roi = [x[1]-1 for x in pdb_map['con_ref_pdb_idx']]
317
-
318
- colormap = {0:'#D3D3D3', 1:'#F74CFF'}
319
- colors = {i+1: colormap[1] if i in roi else colormap[0] for i in range(parse['xyz'].shape[0])}
320
- view.setStyle({"cartoon": {"colorscheme": {"prop": "resi", "map": colors}}})
321
- view.zoomTo()
322
- output = view._make_html().replace("'", '"')
323
- print(view._make_html())
324
- x = f"""<!DOCTYPE html><html></center> {output} </center></html>""" # do not use ' in this input
325
-
326
- return f"""<iframe height="500px" width="100%" name="result" allow="midi; geolocation; microphone; camera;
327
- display-capture; encrypted-media;" sandbox="allow-modals allow-forms
328
- allow-scripts allow-same-origin allow-popups
329
- allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
330
- allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""", output_name
331
 
332
- except Exception as e:
333
  return gr.HTML(f"오류가 발생했습니다: {str(e)}"), None
334
 
335
  def fetch_pdb(pdb_id=None):
 
284
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
285
  '''
286
 
 
287
  def get_motif_preview(pdb_id, contigs):
288
  try:
289
  input_pdb = fetch_pdb(pdb_id=pdb_id.lower() if pdb_id else None)
 
291
  return gr.HTML("PDB ID를 입력해주세요"), None
292
 
293
  parse = parse_pdb(input_pdb)
294
+ output_name = input_pdb
 
 
 
 
 
295
 
296
+ pdb = open(output_name, "r").read()
297
+ view = py3Dmol.view(width=500, height=500)
298
+ view.addModel(pdb, "pdb")
299
 
300
+ if contigs in ['',0]:
301
+ contigs = ['0']
302
+ else:
303
+ contigs = [contigs]
304
 
305
+ print('DEBUG: ',contigs)
306
+
307
+ pdb_map = get_mappings(ContigMap(parse,contigs))
308
+ print('DEBUG: ',pdb_map)
309
+ print('DEBUG: ',pdb_map['con_ref_idx0'])
310
+ roi = [x[1]-1 for x in pdb_map['con_ref_pdb_idx']]
311
+
312
+ colormap = {0:'#D3D3D3', 1:'#F74CFF'}
313
+ colors = {i+1: colormap[1] if i in roi else colormap[0] for i in range(parse['xyz'].shape[0])}
314
+ view.setStyle({"cartoon": {"colorscheme": {"prop": "resi", "map": colors}}})
315
+ view.zoomTo()
316
+ output = view._make_html().replace("'", '"')
317
+ print(view._make_html())
318
+ x = f"""<!DOCTYPE html><html></center> {output} </center></html>""" # do not use ' in this input
319
+
320
+ return f"""<iframe height="500px" width="100%" name="result" allow="midi; geolocation; microphone; camera;
321
+ display-capture; encrypted-media;" sandbox="allow-modals allow-forms
322
+ allow-scripts allow-same-origin allow-popups
323
+ allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
324
+ allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""", output_name
325
 
326
+ except Exception as e:
327
  return gr.HTML(f"오류가 발생했습니다: {str(e)}"), None
328
 
329
  def fetch_pdb(pdb_id=None):