aiqcamp commited on
Commit
e31033d
·
verified ·
1 Parent(s): effd5d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -213
app.py CHANGED
@@ -439,51 +439,7 @@ def toggle_secondary_structure(choice):
439
  elif choice == "explicit":
440
  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)
441
 
442
- def generate_hero(name, strength, flexibility, speed, defense, size, abilities):
443
- try:
444
- # protein_diffusion_model 호출하여 마지막 결과 얻기
445
- generator = protein_diffusion_model(
446
- sequence=None,
447
- seq_len=size,
448
- helix_bias=flexibility,
449
- strand_bias=strength,
450
- loop_bias=speed,
451
- secondary_structure=None,
452
- aa_bias=None,
453
- aa_bias_potential=None,
454
- num_steps="25",
455
- noise="normal",
456
- hydrophobic_target_score=str(-defense),
457
- hydrophobic_potential="2",
458
- contigs=None,
459
- pssm=None,
460
- seq_mask=None,
461
- str_mask=None,
462
- rewrite_pdb=None
463
- )
464
-
465
- # 마지막 결과만 가져오기
466
- final_result = None
467
- for result in generator:
468
- final_result = result
469
-
470
- if final_result is None:
471
- raise Exception("생성 결과가 없습니다")
472
-
473
- # 능력치 계산
474
- stats = calculate_hero_stats(flexibility, strength, speed, defense)
475
-
476
- # 결과 반환 (3D 구조 제외)
477
- return (
478
- create_radar_chart(stats), # 능력치 차트
479
- generate_hero_description(name, stats, abilities) # 히어로 설명
480
- )
481
- except Exception as e:
482
- print(f"Error in generate_hero: {str(e)}")
483
- return (
484
- None,
485
- f"에러: {str(e)}"
486
- )
487
 
488
  def create_radar_chart(stats):
489
  # 레이더 차트 생성 로직
@@ -522,173 +478,64 @@ def generate_hero_description(name, stats, abilities):
522
  """
523
  return description
524
 
525
- # Gradio 인터페이스 수정
526
- with gr.Blocks(theme='ParityError/Interstellar') as demo:
527
- with gr.Row():
528
- with gr.Column():
529
- gr.Markdown("# 🦸‍♂️ 슈퍼히어로 단백질 만들기")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
 
531
- with gr.Tabs():
532
- with gr.TabItem("히어로 디자인"):
533
- # 히어로 기본 정보
534
- hero_name = gr.Textbox(label="히어로 이름", placeholder="당신의 히어로 이름을 지어주세요!")
535
-
536
- # 능력치 설정
537
- gr.Markdown("### 💪 히어로 능력치 설정")
538
- with gr.Row():
539
- strength = gr.Slider(minimum=0.0, maximum=0.05, label="💪 초강력(근력)", value=0.02)
540
- flexibility = gr.Slider(minimum=0.0, maximum=0.05, label="🤸‍♂️ 유연성", value=0.02)
541
-
542
- with gr.Row():
543
- speed = gr.Slider(minimum=0.0, maximum=0.20, label="⚡ 스피드", value=0.1)
544
- defense = gr.Slider(minimum=-10, maximum=10, label="🛡️ 방어력", value=0)
545
-
546
- # 히어로 크기 설정
547
- hero_size = gr.Slider(minimum=50, maximum=200, label="히어로 크기", value=100)
548
-
549
- # 특수 능력 설정
550
- with gr.Accordion("🌟 특수 능력", open=False):
551
- special_ability = gr.CheckboxGroup(
552
- choices=["자가 회복", "원거리 공격", "방어막 생성"],
553
- label="���수 능력 선택"
554
- )
555
-
556
- # 생성 버튼
557
- create_btn = gr.Button("히어로 생성!", variant="primary")
558
-
559
- with gr.TabItem("Inputs"):
560
- gr.Markdown("""## INPUTS""")
561
- gr.Markdown("""#### Start Sequence
562
- Specify the protein length for complete unconditional generation, or scaffold a motif (or your name) using the custom sequence input""")
563
- seq_opt = gr.Radio(["protein length","custom sequence"], label="How would you like to specify the starting sequence?", value='protein length')
564
-
565
- sequence = gr.Textbox(label="custom sequence", lines=1, placeholder='AMINO ACIDS: A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y\n MASK TOKEN: X', visible=False)
566
- seq_len = gr.Slider(minimum=5.0, maximum=250.0, label="protein length", value=100, visible=True)
567
-
568
- seq_opt.change(fn=toggle_seq_input,
569
- inputs=[seq_opt],
570
- outputs=[seq_len, sequence],
571
- queue=False)
572
-
573
- gr.Markdown("""### Optional Parameters""")
574
- with gr.Accordion(label='Secondary Structure',open=True):
575
- gr.Markdown("""Try changing the sliders or inputing explicit secondary structure conditioning for each residue""")
576
- sec_str_opt = gr.Radio(["sliders","explicit"], label="How would you like to specify secondary structure?", value='sliders')
577
-
578
- secondary_structure = gr.Textbox(label="secondary structure", lines=1, placeholder='HELIX = H STRAND = S LOOP = L MASK = X(must be the same length as input sequence)', visible=False)
579
-
580
- with gr.Column():
581
- helix_bias = gr.Slider(minimum=0.0, maximum=0.05, label="helix bias", visible=True)
582
- strand_bias = gr.Slider(minimum=0.0, maximum=0.05, label="strand bias", visible=True)
583
- loop_bias = gr.Slider(minimum=0.0, maximum=0.20, label="loop bias", visible=True)
584
-
585
- sec_str_opt.change(fn=toggle_secondary_structure,
586
- inputs=[sec_str_opt],
587
- outputs=[helix_bias,strand_bias,loop_bias,secondary_structure],
588
- queue=False)
589
-
590
- with gr.Accordion(label='Amino Acid Compositional Bias',open=False):
591
- gr.Markdown("""Bias sequence composition for particular amino acids by specifying the one letter code followed by the fraction to bias. This can be input as a list for example: W0.2,E0.1""")
592
- with gr.Row():
593
- 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' )
594
- aa_bias_potential = gr.Textbox(label="aa bias scale", lines=1, placeholder='AA Bias potential scale (recomended range 1.0-5.0)')
595
-
596
- with gr.Accordion(label='Hydrophobic Bias',open=False):
597
- gr.Markdown("""Bias for or against hydrophobic composition, to get more soluble proteins, bias away with a negative target score (ex. -5)""")
598
- with gr.Row():
599
- hydrophobic_target_score = gr.Textbox(label="hydrophobic score", lines=1, placeholder='hydrophobic score to target (negative score is good for solublility)')
600
- hydrophobic_potential = gr.Textbox(label="hydrophobic potential scale", lines=1, placeholder='hydrophobic potential scale (recomended range 1.0-2.0)')
601
-
602
- with gr.Accordion(label='Diffusion Params',open=False):
603
- 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""")
604
- with gr.Row():
605
- num_steps = gr.Textbox(label="T", lines=1, placeholder='number of diffusion steps (25 or less will speed things up)')
606
- noise = gr.Dropdown(['normal','gmm2 [-1,1]','gmm3 [-1,0,1]'], label='noise type', value='normal')
607
-
608
- with gr.TabItem("Motif Selection"):
609
- gr.Markdown("""### Motif Selection Preview""")
610
- 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. ')
611
- pdb_id_code = gr.Textbox(label="PDB ID", lines=1, placeholder='INPUT PDB ID TO FETCH (ex. 1DPX)', visible=True)
612
- contigs = gr.Textbox(label="contigs", lines=1, placeholder='specify contigs to grab particular residues from pdb ()', visible=True)
613
- gr.Markdown('Using the same contig syntax, seq or str of input motif residues can be masked, allowing the model to hold strucutre fixed and design sequence or vice-versa')
614
- with gr.Row():
615
- seq_mask = gr.Textbox(label='seq mask',lines=1,placeholder='input residues to mask sequence')
616
- str_mask = gr.Textbox(label='str mask',lines=1,placeholder='input residues to mask structure')
617
- preview_viewer = gr.HTML()
618
- rewrite_pdb = gr.File(label='PDB file')
619
- preview_btn = gr.Button("Preview Motif")
620
-
621
- with gr.TabItem("MSA to PSSM"):
622
- gr.Markdown("""### MSA to PSSM Generation""")
623
- gr.Markdown('input either an MSA or PSSM to guide the model toward generating samples within your family of interest')
624
- with gr.Row():
625
- fasta_msa = gr.File(label='MSA')
626
- input_pssm = gr.File(label='PSSM (.csv)')
627
- pssm = gr.File(label='Generated PSSM')
628
- pssm_view = gr.Plot(label='PSSM Viewer')
629
- pssm_gen_btn = gr.Button("Generate PSSM")
630
-
631
- with gr.Column():
632
- gr.Markdown("## 🦸‍♂️ 히어로 프로필")
633
-
634
- # 히어로 시각화 부분 제거 (hero_structure 삭제)
635
-
636
- # 능력치 레이더 차트
637
- hero_stats = gr.Plot(label="능력치 분석")
638
-
639
- # 히어로 설명
640
- hero_description = gr.Textbox(label="히어로 특성", lines=3)
641
-
642
- # 다운로드 버튼
643
- download_btn = gr.Button("히어로 데이터 다운로드")
644
-
645
- gr.Markdown("""## OUTPUTS""")
646
- gr.Markdown("""#### Confidence score for generated structure at each timestep""")
647
- plddt_plot = gr.Plot(label='plddt at step t')
648
- gr.Markdown("""#### Output protein sequnece""")
649
- output_seq = gr.Textbox(label="sequence")
650
- gr.Markdown("""#### Download PDB file""")
651
- output_pdb = gr.File(label="PDB file")
652
- gr.Markdown("""#### Structure viewer""")
653
- output_viewer = gr.HTML()
654
-
655
-
656
-
657
- # 이벤트 연결
658
- preview_btn.click(get_motif_preview,[pdb_id_code, contigs],[preview_viewer, rewrite_pdb])
659
- pssm_gen_btn.click(get_pssm,[fasta_msa,input_pssm],[pssm_view, pssm])
660
-
661
-
662
- create_btn.click(
663
- generate_hero,
664
- inputs=[hero_name, strength, flexibility, speed, defense, hero_size, special_ability],
665
- outputs=[hero_stats, hero_description] # hero_structure 제거
666
- )
667
 
668
-
669
- btn = gr.Button("GENERATE")
670
- btn.click(protein_diffusion_model,
671
- [sequence,
672
- seq_len,
673
- helix_bias,
674
- strand_bias,
675
- loop_bias,
676
- secondary_structure,
677
- aa_bias,
678
- aa_bias_potential,
679
- num_steps,
680
- noise,
681
- hydrophobic_target_score,
682
- hydrophobic_potential,
683
- contigs,
684
- pssm,
685
- seq_mask,
686
- str_mask,
687
- rewrite_pdb],
688
- [output_seq,
689
- output_pdb,
690
- output_viewer,
691
- plddt_plot])
692
-
693
- demo.queue()
694
- demo.launch(debug=True)
 
439
  elif choice == "explicit":
440
  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)
441
 
442
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
  def create_radar_chart(stats):
445
  # 레이더 차트 생성 로직
 
478
  """
479
  return description
480
 
481
+ def combined_generation(name, strength, flexibility, speed, defense, size, abilities,
482
+ sequence, seq_len, helix_bias, strand_bias, loop_bias,
483
+ secondary_structure, aa_bias, aa_bias_potential,
484
+ num_steps, noise, hydrophobic_target_score, hydrophobic_potential,
485
+ contigs, pssm, seq_mask, str_mask, rewrite_pdb):
486
+ try:
487
+ # protein_diffusion_model 실행
488
+ generator = protein_diffusion_model(
489
+ sequence=None,
490
+ seq_len=size, # 히어로 크기를 seq_len으로 사용
491
+ helix_bias=flexibility, # 히어로 유연성을 helix_bias로 사용
492
+ strand_bias=strength, # 히어로 강도를 strand_bias로 사용
493
+ loop_bias=speed, # 히어로 스피드를 loop_bias로 사용
494
+ secondary_structure=None,
495
+ aa_bias=None,
496
+ aa_bias_potential=None,
497
+ num_steps="25",
498
+ noise="normal",
499
+ hydrophobic_target_score=str(-defense), # 히어로 방어력을 hydrophobic score로 사용
500
+ hydrophobic_potential="2",
501
+ contigs=None,
502
+ pssm=None,
503
+ seq_mask=None,
504
+ str_mask=None,
505
+ rewrite_pdb=None
506
+ )
507
+
508
+ # 마지막 결과 가져오기
509
+ final_result = None
510
+ for result in generator:
511
+ final_result = result
512
 
513
+ if final_result is None:
514
+ raise Exception("생성 결과가 없습니다")
515
+
516
+ output_seq, output_pdb, structure_view, plddt_plot = final_result
517
+
518
+ # 히어로 능력치 계산
519
+ stats = calculate_hero_stats(flexibility, strength, speed, defense)
520
+
521
+ # 모든 결과 반환
522
+ return (
523
+ create_radar_chart(stats), # 능력치 차트
524
+ generate_hero_description(name, stats, abilities), # 히어로 설명
525
+ output_seq, # 단백질 서열
526
+ output_pdb, # PDB 파일
527
+ structure_view, # 3D 구조
528
+ plddt_plot # 신뢰도 차트
529
+ )
530
+ except Exception as e:
531
+ print(f"Error in combined_generation: {str(e)}")
532
+ return (
533
+ None,
534
+ f"에러: {str(e)}",
535
+ None,
536
+ None,
537
+ gr.HTML("에러가 발생했습니다"),
538
+ None
539
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
 
541
+ with gr.Blocks(theme='ParityError/Interstellar') as demo: