aiqcamp commited on
Commit
dadf5f2
ยท
verified ยท
1 Parent(s): 4b85b50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -76
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os,sys
 
2
 
3
  # install environment goods
4
  #os.system("pip -q install dgl -f https://data.dgl.ai/wheels/cu113/repo.html")
@@ -54,13 +55,11 @@ args['strand_bias'] = 0.0
54
  args['loop_bias'] = 0.0
55
  args['helix_bias'] = 0.0
56
 
57
-
58
-
59
  def protein_diffusion_model(sequence, seq_len, helix_bias, strand_bias, loop_bias,
60
  secondary_structure, aa_bias, aa_bias_potential,
61
- #target_charge, target_ph, charge_potential,
62
  num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
63
  contigs, pssm, seq_mask, str_mask, rewrite_pdb):
 
64
 
65
  dssp_checkpoint = './SEQDIFF_230205_dssp_hotspots_25mask_EQtasks_mod30.pt'
66
  og_checkpoint = './SEQDIFF_221219_equalTASKS_nostrSELFCOND_mod30.pt'
@@ -222,7 +221,9 @@ def protein_diffusion_model(sequence, seq_len, helix_bias, strand_bias, loop_bia
222
  yield output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
223
 
224
  output_seq, output_pdb, plddt = S.get_outputs()
225
- yield output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
 
 
226
 
227
  def get_plddt_plot(plddt_data, max_t):
228
  x = [i+1 for i in range(len(plddt_data))]
@@ -394,7 +395,19 @@ def get_pssm(fasta_msa, input_pssm):
394
  return fig, outdir
395
 
396
 
397
- #toggle options
 
 
 
 
 
 
 
 
 
 
 
 
398
  def toggle_seq_input(choice):
399
  if choice == "protein length":
400
  return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
@@ -407,16 +420,116 @@ def toggle_secondary_structure(choice):
407
  elif choice == "explicit":
408
  return gr.update(visible=False, value=None),gr.update(visible=False, value=None),gr.update(visible=False, value=None),gr.update(visible=True, value=None)
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
 
411
- # Define the Gradio interface
412
- with gr.Blocks(theme='ParityError/Interstellar') as demo:
 
 
413
 
414
-
 
 
 
 
 
 
 
 
415
 
416
- #with gr.Row().style(equal_height=False):
 
417
  with gr.Row():
418
  with gr.Column():
 
 
419
  with gr.Tabs():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  with gr.TabItem("Inputs"):
421
  gr.Markdown("""## INPUTS""")
422
  gr.Markdown("""#### Start Sequence
@@ -453,15 +566,6 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
453
  with gr.Row():
454
  aa_bias = gr.Textbox(label="aa bias", lines=1, placeholder='specify one letter AA and fraction to bias, for example W0.1 or M0.1,K0.1' )
455
  aa_bias_potential = gr.Textbox(label="aa bias scale", lines=1, placeholder='AA Bias potential scale (recomended range 1.0-5.0)')
456
-
457
- '''
458
- with gr.Accordion(label='Charge Bias',open=False):
459
- gr.Markdown("""Bias for a specified net charge at a particular pH using the boxes below""")
460
- with gr.Row():
461
- target_charge = gr.Textbox(label="net charge", lines=1, placeholder='net charge to target')
462
- target_ph = gr.Textbox(label="pH", lines=1, placeholder='pH at which net charge is desired')
463
- charge_potential = gr.Textbox(label="charge potential scale", lines=1, placeholder='charge potential scale (recomended range 1.0-5.0)')
464
- '''
465
 
466
  with gr.Accordion(label='Hydrophobic Bias',open=False):
467
  gr.Markdown("""Bias for or against hydrophobic composition, to get more soluble proteins, bias away with a negative target score (ex. -5)""")
@@ -473,10 +577,9 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
473
  gr.Markdown("""Increasing T to more steps can be helpful for harder design challenges, sampling from different distributions can change the sequence and structural composition""")
474
  with gr.Row():
475
  num_steps = gr.Textbox(label="T", lines=1, placeholder='number of diffusion steps (25 or less will speed things up)')
476
- noise = gr.Dropdown(['normal','gmm2 [-1,1]','gmm3 [-1,0,1]'], label='noise type', value='normal')
477
-
478
- with gr.TabItem("Motif Selection"):
479
 
 
480
  gr.Markdown("""### Motif Selection Preview""")
481
  gr.Markdown('Contigs explained: to grab residues (seq and str) on a pdb chain you will provide the chain letter followed by a range of residues as indexed in the pdb file for example (A3-10) is the syntax to select residues 3-10 on chain A (the chain always needs to be specified). To add diffused residues to either side of this motif you can specify a range or discrete value without a chain letter infront. To add 15 residues before the motif and 20-30 residues (randomly sampled) after use the following syntax: 15,A3-10,20-30 commas are used to separate regions selected from the pdb and designed (diffused) resiudes which will be added. ')
482
  pdb_id_code = gr.Textbox(label="PDB ID", lines=1, placeholder='INPUT PDB ID TO FETCH (ex. 1DPX)', visible=True)
@@ -499,11 +602,21 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
499
  pssm_view = gr.Plot(label='PSSM Viewer')
500
  pssm_gen_btn = gr.Button("Generate PSSM")
501
 
502
-
503
- btn = gr.Button("GENERATE")
504
-
505
- #with gr.Row():
506
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
  gr.Markdown("""## OUTPUTS""")
508
  gr.Markdown("""#### Confidence score for generated structure at each timestep""")
509
  plddt_plot = gr.Plot(label='plddt at step t')
@@ -513,53 +626,17 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
513
  output_pdb = gr.File(label="PDB file")
514
  gr.Markdown("""#### Structure viewer""")
515
  output_viewer = gr.HTML()
516
- '''
517
- gr.Markdown("""### Don't know where to get started? Click on an example below to try it out!""")
518
- gr.Examples(
519
- [["","125",0.0,0.0,0.2,"","","","20","normal",'','','',None,'','',None],
520
- ["","100",0.0,0.0,0.0,"","W0.2","2","20","normal",'','','',None,'','',None],
521
- # ["","100",0.0,0.0,0.0,
522
- # "XXHHHHHHHHHXXXXXXXHHHHHHHHHXXXXXXXHHHHHHHHXXXXSSSSSSSSSSSXXXXXXXXSSSSSSSSSSSSXXXXXXXSSSSSSSSSXXXXXXX",
523
- # "","","25","normal",'','','',None,'','',None],
524
- # ["XXXXXXXXXXXXXXXXXXXXXXXXXIPDXXXXXXXXXXXXXXXXXXXXXXPEPSEQXXXXXXXXXXXXXXXXXXXXXXXXXXIPDXXXXXXXXXXXXXXXXXXX",
525
- # "",0.0,0.0,0.0,"","","","25","normal",'','','',None,'','',None],
526
- # ["","",0.0,0.0,0.0,"","","","25","normal",'','',
527
- # '9,D10-11,8,D20-20,4,D25-35,65,D101-101,2,D104-105,8,D114-116,15,D132-138,6,D145-145,2,D148-148,12,D161-161,3',
528
- # './tmp/PSSM_lysozyme.csv',
529
- # 'D25-25,D27-31,D33-35,D132-137',
530
- # 'D26-26','./tmp/150l.pdb']
531
- ],
532
- inputs=[sequence,
533
- seq_len,
534
- helix_bias,
535
- strand_bias,
536
- loop_bias,
537
- secondary_structure,
538
- aa_bias,
539
- aa_bias_potential,
540
- #target_charge,
541
- #target_ph,
542
- #charge_potential,
543
- num_steps,
544
- noise,
545
- hydrophobic_target_score,
546
- hydrophobic_potential,
547
- contigs,
548
- pssm,
549
- seq_mask,
550
- str_mask,
551
- rewrite_pdb],
552
- outputs=[output_seq,
553
- output_pdb,
554
- output_viewer,
555
- plddt_plot],
556
- fn=protein_diffusion_model,
557
- )
558
- '''
559
- preview_btn.click(get_motif_preview,[pdb_id_code, contigs],[preview_viewer, rewrite_pdb])
560
 
 
 
561
  pssm_gen_btn.click(get_pssm,[fasta_msa,input_pssm],[pssm_view, pssm])
 
 
 
 
 
562
 
 
563
  btn.click(protein_diffusion_model,
564
  [sequence,
565
  seq_len,
@@ -569,9 +646,6 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
569
  secondary_structure,
570
  aa_bias,
571
  aa_bias_potential,
572
- #target_charge,
573
- #target_ph,
574
- #charge_potential,
575
  num_steps,
576
  noise,
577
  hydrophobic_target_score,
@@ -587,7 +661,4 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
587
  plddt_plot])
588
 
589
  demo.queue()
590
- demo.launch(debug=True)
591
-
592
-
593
-
 
1
  import os,sys
2
+ import plotly.graph_objects as go
3
 
4
  # install environment goods
5
  #os.system("pip -q install dgl -f https://data.dgl.ai/wheels/cu113/repo.html")
 
55
  args['loop_bias'] = 0.0
56
  args['helix_bias'] = 0.0
57
 
 
 
58
  def protein_diffusion_model(sequence, seq_len, helix_bias, strand_bias, loop_bias,
59
  secondary_structure, aa_bias, aa_bias_potential,
 
60
  num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
61
  contigs, pssm, seq_mask, str_mask, rewrite_pdb):
62
+
63
 
64
  dssp_checkpoint = './SEQDIFF_230205_dssp_hotspots_25mask_EQtasks_mod30.pt'
65
  og_checkpoint = './SEQDIFF_221219_equalTASKS_nostrSELFCOND_mod30.pt'
 
221
  yield output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
222
 
223
  output_seq, output_pdb, plddt = S.get_outputs()
224
+
225
+ return output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
226
+
227
 
228
  def get_plddt_plot(plddt_data, max_t):
229
  x = [i+1 for i in range(len(plddt_data))]
 
395
  return fig, outdir
396
 
397
 
398
+
399
+
400
+ # ํžˆ์–ด๋กœ ๋Šฅ๋ ฅ์น˜ ๊ณ„์‚ฐ ํ•จ์ˆ˜ ์ถ”๊ฐ€
401
+ def calculate_hero_stats(helix_bias, strand_bias, loop_bias, hydrophobic_score):
402
+ stats = {
403
+ 'strength': strand_bias * 20, # ๋ฒ ํƒ€์‹œํŠธ ๊ตฌ์กฐ ๊ธฐ๋ฐ˜
404
+ 'flexibility': helix_bias * 20, # ์•ŒํŒŒํ—ฌ๋ฆญ์Šค ๊ตฌ์กฐ ๊ธฐ๋ฐ˜
405
+ 'speed': loop_bias * 5, # ๋ฃจํ”„ ๊ตฌ์กฐ ๊ธฐ๋ฐ˜
406
+ 'defense': abs(hydrophobic_score) if hydrophobic_score else 0
407
+ }
408
+ return stats
409
+
410
+ ##toggle options
411
  def toggle_seq_input(choice):
412
  if choice == "protein length":
413
  return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
 
420
  elif choice == "explicit":
421
  return gr.update(visible=False, value=None),gr.update(visible=False, value=None),gr.update(visible=False, value=None),gr.update(visible=True, value=None)
422
 
423
+ def generate_hero(name, strength, flexibility, speed, defense, size, abilities):
424
+ try:
425
+ # protein_diffusion_model ํ˜ธ์ถœ
426
+ results = protein_diffusion_model(
427
+ sequence=None,
428
+ seq_len=size,
429
+ helix_bias=flexibility,
430
+ strand_bias=strength,
431
+ loop_bias=speed,
432
+ secondary_structure=None,
433
+ aa_bias=None,
434
+ aa_bias_potential=None,
435
+ num_steps="25",
436
+ noise="normal",
437
+ hydrophobic_target_score=str(-defense),
438
+ hydrophobic_potential="2",
439
+ contigs=None,
440
+ pssm=None,
441
+ seq_mask=None,
442
+ str_mask=None,
443
+ rewrite_pdb=None
444
+ )
445
+
446
+ # ๋Šฅ๋ ฅ์น˜ ๊ณ„์‚ฐ
447
+ stats = calculate_hero_stats(flexibility, strength, speed, defense)
448
+
449
+ # ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
450
+ return (
451
+ results[2], # 3D ๊ตฌ์กฐ
452
+ create_radar_chart(stats), # ๋Šฅ๋ ฅ์น˜ ์ฐจํŠธ
453
+ generate_hero_description(name, stats, abilities) # ํžˆ์–ด๋กœ ์„ค๋ช…
454
+ )
455
+ except Exception as e:
456
+ return (
457
+ gr.HTML("์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค"),
458
+ None,
459
+ f"์—๋Ÿฌ: {str(e)}"
460
+ )
461
+
462
+ def create_radar_chart(stats):
463
+ # ๋ ˆ์ด๋” ์ฐจํŠธ ์ƒ์„ฑ ๋กœ์ง
464
+ categories = list(stats.keys())
465
+ values = list(stats.values())
466
+
467
+ fig = go.Figure(data=go.Scatterpolar(
468
+ r=values,
469
+ theta=categories,
470
+ fill='toself'
471
+ ))
472
+
473
+ fig.update_layout(
474
+ polar=dict(
475
+ radialaxis=dict(
476
+ visible=True,
477
+ range=[0, 1]
478
+ )),
479
+ showlegend=False
480
+ )
481
+
482
+ return fig
483
 
484
+ def generate_hero_description(name, stats, abilities):
485
+ # ํžˆ์–ด๋กœ ์„ค๋ช… ์ƒ์„ฑ ๋กœ์ง
486
+ description = f"""
487
+ ํžˆ์–ด๋กœ ์ด๋ฆ„: {name}
488
 
489
+ ์ฃผ์š” ๋Šฅ๋ ฅ:
490
+ - ๊ทผ๋ ฅ: {'โ˜…' * int(stats['strength'] * 5)}
491
+ - ์œ ์—ฐ์„ฑ: {'โ˜…' * int(stats['flexibility'] * 5)}
492
+ - ์Šคํ”ผ๋“œ: {'โ˜…' * int(stats['speed'] * 5)}
493
+ - ๋ฐฉ์–ด๋ ฅ: {'โ˜…' * int(stats['defense'] * 5)}
494
+
495
+ ํŠน์ˆ˜ ๋Šฅ๋ ฅ: {', '.join(abilities)}
496
+ """
497
+ return description
498
 
499
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ˆ˜์ •
500
+ with gr.Blocks(theme='ParityError/Interstellar') as demo:
501
  with gr.Row():
502
  with gr.Column():
503
+ gr.Markdown("# ๐Ÿฆธโ€โ™‚๏ธ ์Šˆํผํžˆ์–ด๋กœ ๋‹จ๋ฐฑ์งˆ ๋งŒ๋“ค๊ธฐ")
504
+
505
  with gr.Tabs():
506
+ with gr.TabItem("ํžˆ์–ด๋กœ ๋””์ž์ธ"):
507
+ # ํžˆ์–ด๋กœ ๊ธฐ๋ณธ ์ •๋ณด
508
+ hero_name = gr.Textbox(label="ํžˆ์–ด๋กœ ์ด๋ฆ„", placeholder="๋‹น์‹ ์˜ ํžˆ์–ด๋กœ ์ด๋ฆ„์„ ์ง€์–ด์ฃผ์„ธ์š”!")
509
+
510
+ # ๋Šฅ๋ ฅ์น˜ ์„ค์ •
511
+ gr.Markdown("### ๐Ÿ’ช ํžˆ์–ด๋กœ ๋Šฅ๋ ฅ์น˜ ์„ค์ •")
512
+ with gr.Row():
513
+ strength = gr.Slider(minimum=0.0, maximum=0.05, label="๐Ÿ’ช ์ดˆ๊ฐ•๋ ฅ(๊ทผ๋ ฅ)", value=0.02)
514
+ flexibility = gr.Slider(minimum=0.0, maximum=0.05, label="๐Ÿคธโ€โ™‚๏ธ ์œ ์—ฐ์„ฑ", value=0.02)
515
+
516
+ with gr.Row():
517
+ speed = gr.Slider(minimum=0.0, maximum=0.20, label="โšก ์Šคํ”ผ๋“œ", value=0.1)
518
+ defense = gr.Slider(minimum=-10, maximum=10, label="๐Ÿ›ก๏ธ ๋ฐฉ์–ด๋ ฅ", value=0)
519
+
520
+ # ํžˆ์–ด๋กœ ํฌ๊ธฐ ์„ค์ •
521
+ hero_size = gr.Slider(minimum=50, maximum=200, label="ํžˆ์–ด๋กœ ํฌ๊ธฐ", value=100)
522
+
523
+ # ํŠน์ˆ˜ ๋Šฅ๋ ฅ ์„ค์ •
524
+ with gr.Accordion("๐ŸŒŸ ํŠน์ˆ˜ ๋Šฅ๋ ฅ", open=False):
525
+ special_ability = gr.CheckboxGroup(
526
+ choices=["์ž๊ฐ€ ํšŒ๋ณต", "์›๊ฑฐ๋ฆฌ ๊ณต๊ฒฉ", "๋ฐฉ์–ด๋ง‰ ์ƒ์„ฑ"],
527
+ label="ํŠน์ˆ˜ ๋Šฅ๋ ฅ ์„ ํƒ"
528
+ )
529
+
530
+ # ์ƒ์„ฑ ๋ฒ„ํŠผ
531
+ create_btn = gr.Button("ํžˆ์–ด๋กœ ์ƒ์„ฑ!", variant="primary")
532
+
533
  with gr.TabItem("Inputs"):
534
  gr.Markdown("""## INPUTS""")
535
  gr.Markdown("""#### Start Sequence
 
566
  with gr.Row():
567
  aa_bias = gr.Textbox(label="aa bias", lines=1, placeholder='specify one letter AA and fraction to bias, for example W0.1 or M0.1,K0.1' )
568
  aa_bias_potential = gr.Textbox(label="aa bias scale", lines=1, placeholder='AA Bias potential scale (recomended range 1.0-5.0)')
 
 
 
 
 
 
 
 
 
569
 
570
  with gr.Accordion(label='Hydrophobic Bias',open=False):
571
  gr.Markdown("""Bias for or against hydrophobic composition, to get more soluble proteins, bias away with a negative target score (ex. -5)""")
 
577
  gr.Markdown("""Increasing T to more steps can be helpful for harder design challenges, sampling from different distributions can change the sequence and structural composition""")
578
  with gr.Row():
579
  num_steps = gr.Textbox(label="T", lines=1, placeholder='number of diffusion steps (25 or less will speed things up)')
580
+ noise = gr.Dropdown(['normal','gmm2 [-1,1]','gmm3 [-1,0,1]'], label='noise type', value='normal')
 
 
581
 
582
+ with gr.TabItem("Motif Selection"):
583
  gr.Markdown("""### Motif Selection Preview""")
584
  gr.Markdown('Contigs explained: to grab residues (seq and str) on a pdb chain you will provide the chain letter followed by a range of residues as indexed in the pdb file for example (A3-10) is the syntax to select residues 3-10 on chain A (the chain always needs to be specified). To add diffused residues to either side of this motif you can specify a range or discrete value without a chain letter infront. To add 15 residues before the motif and 20-30 residues (randomly sampled) after use the following syntax: 15,A3-10,20-30 commas are used to separate regions selected from the pdb and designed (diffused) resiudes which will be added. ')
585
  pdb_id_code = gr.Textbox(label="PDB ID", lines=1, placeholder='INPUT PDB ID TO FETCH (ex. 1DPX)', visible=True)
 
602
  pssm_view = gr.Plot(label='PSSM Viewer')
603
  pssm_gen_btn = gr.Button("Generate PSSM")
604
 
 
 
 
 
605
  with gr.Column():
606
+ gr.Markdown("## ๐Ÿฆธโ€โ™‚๏ธ ํžˆ์–ด๋กœ ํ”„๋กœํ•„")
607
+
608
+ # ํžˆ์–ด๋กœ ์‹œ๊ฐํ™”
609
+ hero_structure = gr.HTML(label="ํžˆ์–ด๋กœ ๊ตฌ์กฐ")
610
+
611
+ # ๋Šฅ๋ ฅ์น˜ ๋ ˆ์ด๋” ์ฐจํŠธ
612
+ hero_stats = gr.Plot(label="๋Šฅ๋ ฅ์น˜ ๋ถ„์„")
613
+
614
+ # ํžˆ์–ด๋กœ ์„ค๋ช…
615
+ hero_description = gr.Textbox(label="ํžˆ์–ด๋กœ ํŠน์„ฑ", lines=3)
616
+
617
+ # ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ
618
+ download_btn = gr.Button("ํžˆ์–ด๋กœ ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ")
619
+
620
  gr.Markdown("""## OUTPUTS""")
621
  gr.Markdown("""#### Confidence score for generated structure at each timestep""")
622
  plddt_plot = gr.Plot(label='plddt at step t')
 
626
  output_pdb = gr.File(label="PDB file")
627
  gr.Markdown("""#### Structure viewer""")
628
  output_viewer = gr.HTML()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
630
+ # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
631
+ preview_btn.click(get_motif_preview,[pdb_id_code, contigs],[preview_viewer, rewrite_pdb])
632
  pssm_gen_btn.click(get_pssm,[fasta_msa,input_pssm],[pssm_view, pssm])
633
+ create_btn.click(
634
+ generate_hero,
635
+ inputs=[hero_name, strength, flexibility, speed, defense, hero_size, special_ability],
636
+ outputs=[hero_structure, hero_stats, hero_description]
637
+ )
638
 
639
+ btn = gr.Button("GENERATE")
640
  btn.click(protein_diffusion_model,
641
  [sequence,
642
  seq_len,
 
646
  secondary_structure,
647
  aa_bias,
648
  aa_bias_potential,
 
 
 
649
  num_steps,
650
  noise,
651
  hydrophobic_target_score,
 
661
  plddt_plot])
662
 
663
  demo.queue()
664
+ demo.launch(debug=True)