colbyford commited on
Commit
620584c
1 Parent(s): 6a5443d

Reduce need for scaffold functions

Browse files
Files changed (1) hide show
  1. app.py +13 -43
app.py CHANGED
@@ -20,12 +20,12 @@ theme = gr.themes.Monochrome(
20
  def get_model(model_name, token):
21
  login(token=token)
22
 
23
- # if torch.cuda.is_available():
24
- # model = ESM3.from_pretrained(model_name, device=torch.device("cuda"))
25
- # else:
26
- # model = ESM3.from_pretrained(model_name, device=torch.device("cpu"))
27
 
28
- model = ESM3.from_pretrained(model_name, device=torch.device("cpu"))
29
  return model
30
 
31
  ## Function to render 3D structure using py3Dmol
@@ -48,46 +48,14 @@ def get_pdb(pdb_id, chain_id):
48
  return pdb
49
 
50
 
51
- # def select_motif(pdb, motif_start, motif_end):
52
- # motif_inds = np.arange(motif_start, motif_end)
53
- # motif_sequence = pdb[motif_inds].sequence
54
- # motif_atom37_positions = pdb[motif_inds].atom37_positions
55
- # return [motif_sequence, motif_atom37_positions]
56
-
57
- # def setup_prompt(prompt_length, motif_sequence, motif_atom37_positions, insert_size):
58
- # prompt_length = 200
59
-
60
- # sequence_prompt = ["_"]*prompt_length
61
- # sequence_prompt[insert_size:insert_size+len(motif_sequence)] = list(motif_sequence)
62
- # sequence_prompt = "".join(sequence_prompt)
63
-
64
- # structure_prompt = torch.full((prompt_length, 37, 3), np.nan)
65
- # structure_prompt[insert_size:insert_size+len(motif_atom37_positions)] = torch.tensor(motif_atom37_positions)
66
-
67
- # protein_prompt = ESMProtein(sequence=sequence_prompt, coordinates=structure_prompt)
68
-
69
- # return [sequence_prompt, structure_prompt, protein_prompt]
70
-
71
-
72
- # def generate_scaffold_sequence(model_name, token, sequence_prompt, protein_prompt):
73
- # sequence_generation_config = GenerationConfig(track="sequence",
74
- # num_steps=sequence_prompt.count("_") // 2,
75
- # temperature=0.5)
76
- # model = get_model(model_name, token)
77
- # sequence_generation = model.generate(protein_prompt, sequence_generation_config)
78
- # return sequence_generation
79
-
80
-
81
  def scaffold(model_name, token, pdb_id, chain_id, motif_start, motif_end, prompt_length, insert_size):
82
  pdb = get_pdb(pdb_id, chain_id)
83
- # motif_sequence, motif_atom37_positions = select_motif(pdb, motif_start, motif_end)
84
 
 
85
  motif_inds = np.arange(motif_start, motif_end)
86
  motif_sequence = pdb[motif_inds].sequence
87
  motif_atom37_positions = pdb[motif_inds].atom37_positions
88
 
89
- # sequence_prompt, structure_prompt, protein_prompt = setup_prompt(prompt_length, motif_sequence, motif_atom37_positions, insert_size)
90
-
91
  ## Create sequence prompt
92
  sequence_prompt = ["_"]*prompt_length
93
  sequence_prompt[insert_size:insert_size+len(motif_sequence)] = list(motif_sequence)
@@ -97,10 +65,8 @@ def scaffold(model_name, token, pdb_id, chain_id, motif_start, motif_end, prompt
97
  structure_prompt = torch.full((prompt_length, 37, 3), np.nan)
98
  structure_prompt[insert_size:insert_size+len(motif_atom37_positions)] = torch.tensor(motif_atom37_positions)
99
 
100
- ## Create protein prompt
101
  protein_prompt = ESMProtein(sequence=sequence_prompt, coordinates=structure_prompt)
102
-
103
- # sequence_generation = generate_scaffold_sequence(model_name, token, sequence_prompt, protein_prompt)
104
  sequence_generation_config = GenerationConfig(track="sequence",
105
  num_steps=sequence_prompt.count("_") // 2,
106
  temperature=0.5)
@@ -261,8 +227,12 @@ with gr.Blocks(theme=theme) as esm_app:
261
  gr.Markdown(
262
  """
263
  # ESM3: A frontier language model for biology.
264
- - Created By: [EvolutionaryScale](https://www.evolutionaryscale.ai/blog/esm3-release)
265
- - Spaces App By: [Tuple, The Cloud Genomics Company](https://tuple.xyz) [[Colby T. Ford](https://colbyford.com)]
 
 
 
 
266
  """
267
  )
268
  with gr.Row():
 
20
  def get_model(model_name, token):
21
  login(token=token)
22
 
23
+ if torch.cuda.is_available():
24
+ model = ESM3.from_pretrained(model_name, device=torch.device("cuda"))
25
+ else:
26
+ model = ESM3.from_pretrained(model_name, device=torch.device("cpu"))
27
 
28
+ # model = ESM3.from_pretrained(model_name, device=torch.device("cpu"))
29
  return model
30
 
31
  ## Function to render 3D structure using py3Dmol
 
48
  return pdb
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  def scaffold(model_name, token, pdb_id, chain_id, motif_start, motif_end, prompt_length, insert_size):
52
  pdb = get_pdb(pdb_id, chain_id)
 
53
 
54
+ ## Get motif sequence and atom37 positions
55
  motif_inds = np.arange(motif_start, motif_end)
56
  motif_sequence = pdb[motif_inds].sequence
57
  motif_atom37_positions = pdb[motif_inds].atom37_positions
58
 
 
 
59
  ## Create sequence prompt
60
  sequence_prompt = ["_"]*prompt_length
61
  sequence_prompt[insert_size:insert_size+len(motif_sequence)] = list(motif_sequence)
 
65
  structure_prompt = torch.full((prompt_length, 37, 3), np.nan)
66
  structure_prompt[insert_size:insert_size+len(motif_atom37_positions)] = torch.tensor(motif_atom37_positions)
67
 
68
+ ## Create protein prompt and sequence generation config
69
  protein_prompt = ESMProtein(sequence=sequence_prompt, coordinates=structure_prompt)
 
 
70
  sequence_generation_config = GenerationConfig(track="sequence",
71
  num_steps=sequence_prompt.count("_") // 2,
72
  temperature=0.5)
 
227
  gr.Markdown(
228
  """
229
  # ESM3: A frontier language model for biology.
230
+ Model Created By: [EvolutionaryScale](https://www.evolutionaryscale.ai)
231
+ - Press Release: https://www.evolutionaryscale.ai/blog/esm3-release
232
+ - GitHub: https://github.com/evolutionaryscale/esm
233
+ - HuggingFace Model: https://huggingface.co/EvolutionaryScale/esm3-sm-open-v1
234
+
235
+ Spaces App By: [Tuple, The Cloud Genomics Company](https://tuple.xyz) [[Colby T. Ford](https://colbyford.com)]
236
  """
237
  )
238
  with gr.Row():