colbyford commited on
Commit
7f5c48e
1 Parent(s): 02970c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -53
app.py CHANGED
@@ -15,26 +15,30 @@ from colabfold.plot import plot_msa_v2
15
  def a3m_file(file):
16
  return "tmp.a3m"
17
 
18
- def make_uncond_seq(seq_len, model_type):
19
- if model_type == "EvoDiff-Seq-OADM 38M":
20
- checkpoint = OA_DM_38M()
21
- model, collater, tokenizer, scheme = checkpoint
22
- tokeinzed_sample, generated_sequence = generate_oaardm(model, tokenizer, seq_len, batch_size=1, device='cpu')
23
-
24
- if model_type == "EvoDiff-D3PM-Uniform 38M":
25
- checkpoint = D3PM_UNIFORM_38M(return_all=True)
26
- model, collater, tokenizer, scheme, timestep, Q_bar, Q = checkpoint
27
- tokeinzed_sample, generated_sequence = generate_d3pm(model, tokenizer, Q, Q_bar, timestep, seq_len, batch_size=1, device='cpu')
28
 
29
- return generated_sequence
30
 
31
- def make_cond_seq(seq_len, msa_file, model_type):
32
- if model_type == "EvoDiff-MSA":
33
- checkpoint = MSA_OA_DM_MAXSUB()
34
- model, collater, tokenizer, scheme = checkpoint
35
- tokeinzed_sample, generated_sequence = generate_query_oadm_msa_simple(msa_file.name, model, tokenizer, n_sequences=64, seq_length=seq_len, device='cpu', selection_type='random')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- return generated_sequence
38
 
39
  def display_pdb(path_to_pdb):
40
  '''
@@ -65,40 +69,32 @@ def display_pdb(path_to_pdb):
65
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
66
  '''
67
 
68
- def predict_protein(sequence):
69
- model_type = "alphafold2_ptm"
70
- download_alphafold_params(model_type, Path("."))
71
- results = run(
72
- queries=queries,
73
- result_dir=result_dir,
74
- use_templates=use_templates,
75
- custom_template_path=custom_template_path,
76
- num_relax=0,
77
- msa_mode=msa_mode,
78
- model_type=model_type,
79
- num_models=1,
80
- num_recycles=1,
81
- recycle_early_stop_tolerance=recycle_early_stop_tolerance,
82
- num_seeds=num_seeds,
83
- use_dropout=use_dropout,
84
- model_order=[1],
85
- is_complex=False,
86
- data_dir=Path("."),
87
- keep_existing_results=False,
88
- rank_by="auto",
89
- pair_mode=pair_mode,
90
- pairing_strategy=pairing_strategy,
91
- stop_at_score=float(100),
92
- prediction_callback=prediction_callback,
93
- dpi=dpi,
94
- zip_results=False,
95
- save_all=save_all,
96
- max_msa=max_msa,
97
- use_cluster_profile=use_cluster_profile,
98
- input_features_callback=input_features_callback,
99
- save_recycles=save_recycles,
100
- user_agent="colabfold/google-colab-main",
101
- )
102
 
103
  usg_app = gr.Interface(
104
  fn=make_uncond_seq,
@@ -106,7 +102,10 @@ usg_app = gr.Interface(
106
  gr.Slider(10, 100, label = "Sequence Length"),
107
  gr.Dropdown(["EvoDiff-Seq-OADM 38M", "EvoDiff-D3PM-Uniform 38M"], type="value", label = "Model")
108
  ],
109
- outputs="text",
 
 
 
110
  title = "Unconditional sequence generation",
111
  description="Generate a sequence with `EvoDiff-Seq-OADM 38M` (smaller/faster) or `EvoDiff-D3PM-Uniform 38M` (larger/slower) models."
112
  )
@@ -118,7 +117,10 @@ csg_app = gr.Interface(
118
  gr.File(file_types=["a3m"], label = "MSA File"),
119
  gr.Dropdown(["EvoDiff-MSA"], type="value", label = "Model")
120
  ],
121
- outputs="text",
 
 
 
122
  # examples=[["https://github.com/microsoft/evodiff/raw/main/examples/example_files/bfd_uniclust_hits.a3m"]],
123
  title = "Conditional sequence generation",
124
  description="Evolutionary guided sequence generation with the `EvoDiff-MSA` model."
 
15
  def a3m_file(file):
16
  return "tmp.a3m"
17
 
 
 
 
 
 
 
 
 
 
 
18
 
 
19
 
20
+ def predict_protein(sequence):
21
+ download_alphafold_params("alphafold2_ptm", Path("."))
22
+ results = run(
23
+ queries=[('evodiff_protein',sequence, None)],
24
+ result_dir='evodiff_protein',
25
+ use_templates=False,
26
+ num_relax=0,
27
+ msa_mode="mmseqs2_uniref_env",
28
+ model_type="alphafold2_ptm",
29
+ num_models=1,
30
+ num_recycles=1,
31
+ model_order=[1],
32
+ is_complex=False,
33
+ data_dir=Path("."),
34
+ keep_existing_results=False,
35
+ rank_by="auto",
36
+ stop_at_score=float(100),
37
+ zip_results=False,
38
+ user_agent="colabfold/google-colab-main",
39
+ )
40
 
41
+ return f"evodiff_protein/evodiff_protein_unrelaxed_rank_001_alphafold2_ptm_model_1_seed_000.pdb"
42
 
43
  def display_pdb(path_to_pdb):
44
  '''
 
69
  allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
70
  '''
71
 
72
+ def make_uncond_seq(seq_len, model_type):
73
+ if model_type == "EvoDiff-Seq-OADM 38M":
74
+ checkpoint = OA_DM_38M()
75
+ model, collater, tokenizer, scheme = checkpoint
76
+ tokeinzed_sample, generated_sequence = generate_oaardm(model, tokenizer, seq_len, batch_size=1, device='cpu')
77
+
78
+ if model_type == "EvoDiff-D3PM-Uniform 38M":
79
+ checkpoint = D3PM_UNIFORM_38M(return_all=True)
80
+ model, collater, tokenizer, scheme, timestep, Q_bar, Q = checkpoint
81
+ tokeinzed_sample, generated_sequence = generate_d3pm(model, tokenizer, Q, Q_bar, timestep, seq_len, batch_size=1, device='cpu')
82
+
83
+ path_to_pdb = predict_protein(generated_sequence)
84
+ molhtml = display_pdb(path_to_pdb)
85
+
86
+ return generated_sequence, molhtml
87
+
88
+ def make_cond_seq(seq_len, msa_file, model_type):
89
+ if model_type == "EvoDiff-MSA":
90
+ checkpoint = MSA_OA_DM_MAXSUB()
91
+ model, collater, tokenizer, scheme = checkpoint
92
+ tokeinzed_sample, generated_sequence = generate_query_oadm_msa_simple(msa_file.name, model, tokenizer, n_sequences=64, seq_length=seq_len, device='cpu', selection_type='random')
93
+
94
+ path_to_pdb = predict_protein(generated_sequence)
95
+ molhtml = display_pdb(path_to_pdb)
96
+
97
+ return generated_sequence, molhtml
 
 
 
 
 
 
 
 
98
 
99
  usg_app = gr.Interface(
100
  fn=make_uncond_seq,
 
102
  gr.Slider(10, 100, label = "Sequence Length"),
103
  gr.Dropdown(["EvoDiff-Seq-OADM 38M", "EvoDiff-D3PM-Uniform 38M"], type="value", label = "Model")
104
  ],
105
+ outputs=[
106
+ "text",
107
+ gr.HTML()
108
+ ],
109
  title = "Unconditional sequence generation",
110
  description="Generate a sequence with `EvoDiff-Seq-OADM 38M` (smaller/faster) or `EvoDiff-D3PM-Uniform 38M` (larger/slower) models."
111
  )
 
117
  gr.File(file_types=["a3m"], label = "MSA File"),
118
  gr.Dropdown(["EvoDiff-MSA"], type="value", label = "Model")
119
  ],
120
+ outputs=[
121
+ "text",
122
+ gr.HTML()
123
+ ],
124
  # examples=[["https://github.com/microsoft/evodiff/raw/main/examples/example_files/bfd_uniclust_hits.a3m"]],
125
  title = "Conditional sequence generation",
126
  description="Evolutionary guided sequence generation with the `EvoDiff-MSA` model."