chembfn-webui 0.5.0__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/PKG-INFO +9 -2
  2. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/README.md +7 -0
  3. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/bin/app.py +53 -17
  4. chembfn_webui-1.0.0/chembfn_webui/cache/results.csv +1 -0
  5. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/lib/version.py +1 -1
  6. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/PKG-INFO +9 -2
  7. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/requires.txt +1 -1
  8. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/setup.py +1 -1
  9. chembfn_webui-0.5.0/chembfn_webui/cache/results.csv +0 -1
  10. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/LICENSE +0 -0
  11. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/__init__.py +0 -0
  12. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/cache/cache_file_here.txt +0 -0
  13. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/lib/utilities.py +0 -0
  14. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/model/base_model/place_base_model_here.txt +0 -0
  15. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/model/lora/place_lora_folder_here.txt +0 -0
  16. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt +0 -0
  17. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui/model/vocab/place_vocabulary_file_here.txt +0 -0
  18. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/SOURCES.txt +0 -0
  19. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/dependency_links.txt +0 -0
  20. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/entry_points.txt +0 -0
  21. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/chembfn_webui.egg-info/top_level.txt +0 -0
  22. {chembfn_webui-0.5.0 → chembfn_webui-1.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chembfn_webui
3
- Version: 0.5.0
3
+ Version: 1.0.0
4
4
  Summary: WebUI for ChemBFN
5
5
  Home-page: https://github.com/Augus1999/ChemBFN-WebUI
6
6
  Author: Nianze A. Tao
@@ -20,7 +20,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: bayesianflow_for_chem>=1.3.0
23
+ Requires-Dist: bayesianflow_for_chem>=2.2.2
24
24
  Requires-Dist: mol2chemfigPy3>=1.5.11
25
25
  Requires-Dist: gradio>=5.32.1
26
26
  Requires-Dist: torch>=2.7.0
@@ -111,6 +111,13 @@ $ set CHEMBFN_WEBUI_MODEL_DIR={YOUR/MODEL/DIR}
111
111
  $ chembfn
112
112
  ```
113
113
 
114
+ V. use an external directory to hold the model files (Notebook, Google Colab)
115
+ ```python
116
+ import os
117
+ os.environ["CHEMBFN_WEBUI_MODEL_DIR"] = "{YOUR/MODEL/DIR}"
118
+ !chembfn --public
119
+ ```
120
+
114
121
  ### 4. Write the prompt
115
122
 
116
123
  * Leave prompt blank for unconditional generation.
@@ -76,6 +76,13 @@ $ set CHEMBFN_WEBUI_MODEL_DIR={YOUR/MODEL/DIR}
76
76
  $ chembfn
77
77
  ```
78
78
 
79
+ V. use an external directory to hold the model files (Notebook, Google Colab)
80
+ ```python
81
+ import os
82
+ os.environ["CHEMBFN_WEBUI_MODEL_DIR"] = "{YOUR/MODEL/DIR}"
83
+ !chembfn --public
84
+ ```
85
+
79
86
  ### 4. Write the prompt
80
87
 
81
88
  * Leave prompt blank for unconditional generation.
@@ -10,7 +10,7 @@ from functools import partial
10
10
  from typing import Tuple, List, Dict, Union
11
11
 
12
12
  sys.path.append(str(Path(__file__).parent.parent))
13
- from rdkit.Chem import Draw, MolFromSmiles
13
+ from rdkit.Chem import Draw, MolFromSmiles # type: ignore
14
14
  from mol2chemfigPy3 import mol2chemfig
15
15
  import gradio as gr
16
16
  import torch
@@ -18,13 +18,19 @@ from selfies import decoder
18
18
  from bayesianflow_for_chem import ChemBFN, MLP, EnsembleChemBFN
19
19
  from bayesianflow_for_chem.data import (
20
20
  VOCAB_KEYS,
21
- AA_VOCAB_KEYS,
21
+ FASTA_VOCAB_KEYS,
22
22
  load_vocab,
23
23
  smiles2vec,
24
- aa2vec,
24
+ fasta2vec,
25
25
  split_selfies,
26
26
  )
27
- from bayesianflow_for_chem.tool import sample, inpaint, adjust_lora_, quantise_model_
27
+ from bayesianflow_for_chem.tool import (
28
+ sample,
29
+ inpaint,
30
+ optimise,
31
+ adjust_lora_,
32
+ quantise_model_,
33
+ )
28
34
  from lib.utilities import (
29
35
  find_model,
30
36
  find_vocab,
@@ -176,11 +182,12 @@ def run(
176
182
  temperature: float,
177
183
  prompt: str,
178
184
  scaffold: str,
185
+ template: str,
179
186
  sar_control: str,
180
187
  exclude_token: str,
181
188
  quantise: str,
182
189
  jited: str,
183
- ) -> Tuple[Union[List, None], List[str], str, str, str]:
190
+ ) -> Tuple[Union[List, None], List[str], str, gr.TextArea, str]:
184
191
  """
185
192
  Run generation or inpainting.
186
193
 
@@ -195,6 +202,7 @@ def run(
195
202
  :param temperature: sampling temperature while ODE-solver used
196
203
  :param prompt: prompt string
197
204
  :param scaffold: molecular scaffold
205
+ :param template: molecular template
198
206
  :param sar_control: semi-autoregressive behaviour flags
199
207
  :param exclude_token: unwanted tokens
200
208
  :param quantise: `"on"` or `"off"`
@@ -210,6 +218,7 @@ def run(
210
218
  :type temperature: float
211
219
  :type prompt: str
212
220
  :type scaffold: str
221
+ :type template: str
213
222
  :type sar_control: str
214
223
  :type exclude_token: str
215
224
  :type quantise: str
@@ -237,8 +246,8 @@ def run(
237
246
  img_fn = lambda x: [Draw.MolToImage(MolFromSmiles(i), (500, 500)) for i in x]
238
247
  chemfig_fn = lambda x: [mol2chemfig(i, "-r", inline=True) for i in x]
239
248
  if token_name == "FASTA":
240
- vocab_keys = AA_VOCAB_KEYS
241
- tokeniser = aa2vec
249
+ vocab_keys = FASTA_VOCAB_KEYS
250
+ tokeniser = fasta2vec
242
251
  trans_fn = lambda x: x
243
252
  img_fn = lambda _: None # senseless to provide dumb 2D images
244
253
  chemfig_fn = lambda _: [""] # senseless to provide very long Chemfig code
@@ -346,11 +355,14 @@ def run(
346
355
  if not allowed_tokens:
347
356
  allowed_tokens = "all"
348
357
  scaffold = scaffold.strip()
349
- if not scaffold:
350
- mols = sample(
358
+ template = template.strip()
359
+ if scaffold:
360
+ x = [1] + tokeniser(scaffold)
361
+ x = x + [0 for _ in range(lmax - len(x))]
362
+ x = torch.tensor([x], dtype=torch.long).repeat(batch_size, 1)
363
+ mols = inpaint(
351
364
  bfn,
352
- batch_size,
353
- lmax,
365
+ x,
354
366
  step,
355
367
  y,
356
368
  guidance_strength,
@@ -361,11 +373,13 @@ def run(
361
373
  mols = trans_fn(mols)
362
374
  imgs = img_fn(mols)
363
375
  chemfigs = chemfig_fn(mols)
364
- else:
365
- x = [1] + tokeniser(scaffold)
376
+ if template:
377
+ _message.append(f"Molecular template {template} ignored.")
378
+ elif template:
379
+ x = [1] + tokeniser(scaffold) + [2]
366
380
  x = x + [0 for _ in range(lmax - len(x))]
367
381
  x = torch.tensor([x], dtype=torch.long).repeat(batch_size, 1)
368
- mols = inpaint(
382
+ mols = optimise(
369
383
  bfn,
370
384
  x,
371
385
  step,
@@ -378,6 +392,21 @@ def run(
378
392
  mols = trans_fn(mols)
379
393
  imgs = img_fn(mols)
380
394
  chemfigs = chemfig_fn(mols)
395
+ else:
396
+ mols = sample(
397
+ bfn,
398
+ batch_size,
399
+ lmax,
400
+ step,
401
+ y,
402
+ guidance_strength,
403
+ vocab_keys=vocab_keys,
404
+ method=_method,
405
+ allowed_tokens=allowed_tokens,
406
+ )
407
+ mols = trans_fn(mols)
408
+ imgs = img_fn(mols)
409
+ chemfigs = chemfig_fn(mols)
381
410
  n_mol = len(mols)
382
411
  with open(cache_dir / "results.csv", "w", encoding="utf-8", newline="") as rf:
383
412
  rf.write("\n".join(mols))
@@ -388,7 +417,7 @@ def run(
388
417
  imgs,
389
418
  mols,
390
419
  "\n\n".join(chemfigs),
391
- "\n".join(_message),
420
+ gr.TextArea("\n".join(_message), label="message", lines=len(_message)),
392
421
  str(cache_dir / "results.csv"),
393
422
  )
394
423
 
@@ -437,8 +466,9 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
437
466
  label="prompt", lines=12, html_attributes=HTML_STYLE
438
467
  )
439
468
  scaffold = gr.Textbox(label="scaffold", html_attributes=HTML_STYLE)
469
+ template = gr.Textbox(label="template", html_attributes=HTML_STYLE)
440
470
  gr.Markdown("")
441
- message = gr.TextArea(label="message")
471
+ message = gr.TextArea(label="message", lines=2)
442
472
  with gr.Tab(label="result viewer"):
443
473
  with gr.Tab(label="result"):
444
474
  btn_download = gr.File(label="download", visible=False)
@@ -527,6 +557,7 @@ with gr.Blocks(title="ChemBFN WebUI") as app:
527
557
  temperature,
528
558
  prompt,
529
559
  scaffold,
560
+ template,
530
561
  sar_control,
531
562
  exclude_token,
532
563
  quantise,
@@ -578,7 +609,12 @@ def main() -> None:
578
609
  :return:
579
610
  :rtype: None
580
611
  """
581
- parser = argparse.ArgumentParser()
612
+ parser = argparse.ArgumentParser(
613
+ description="A web-based visualisation tool for ChemBFN method.",
614
+ epilog=f"ChemBFN WebUI {__version__}, developed in Hiroshima University by chemists for chemists. "
615
+ "Visit https://augus1999.github.io/bayesian-flow-network-for-chemistry/ for more details.",
616
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
617
+ )
582
618
  parser.add_argument(
583
619
  "--public", default=False, help="open to public", action="store_true"
584
620
  )
@@ -0,0 +1 @@
1
+ CN1CCOCC1c1cccc(C(=O)Nc2ccnn2C(C)C)c1
@@ -4,5 +4,5 @@
4
4
  Version info.
5
5
  """
6
6
 
7
- __version__ = "0.5.0"
7
+ __version__ = "1.0.0"
8
8
  __author__ = "Nianze A. TAO"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chembfn_webui
3
- Version: 0.5.0
3
+ Version: 1.0.0
4
4
  Summary: WebUI for ChemBFN
5
5
  Home-page: https://github.com/Augus1999/ChemBFN-WebUI
6
6
  Author: Nianze A. Tao
@@ -20,7 +20,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: bayesianflow_for_chem>=1.3.0
23
+ Requires-Dist: bayesianflow_for_chem>=2.2.2
24
24
  Requires-Dist: mol2chemfigPy3>=1.5.11
25
25
  Requires-Dist: gradio>=5.32.1
26
26
  Requires-Dist: torch>=2.7.0
@@ -111,6 +111,13 @@ $ set CHEMBFN_WEBUI_MODEL_DIR={YOUR/MODEL/DIR}
111
111
  $ chembfn
112
112
  ```
113
113
 
114
+ V. use an external directory to hold the model files (Notebook, Google Colab)
115
+ ```python
116
+ import os
117
+ os.environ["CHEMBFN_WEBUI_MODEL_DIR"] = "{YOUR/MODEL/DIR}"
118
+ !chembfn --public
119
+ ```
120
+
114
121
  ### 4. Write the prompt
115
122
 
116
123
  * Leave prompt blank for unconditional generation.
@@ -1,4 +1,4 @@
1
- bayesianflow_for_chem>=1.3.0
1
+ bayesianflow_for_chem>=2.2.2
2
2
  mol2chemfigPy3>=1.5.11
3
3
  gradio>=5.32.1
4
4
  torch>=2.7.0
@@ -55,7 +55,7 @@ setup(
55
55
  packages=find_packages(),
56
56
  python_requires=">=3.11",
57
57
  install_requires=[
58
- "bayesianflow_for_chem>=1.3.0",
58
+ "bayesianflow_for_chem>=2.2.2",
59
59
  "mol2chemfigPy3>=1.5.11",
60
60
  "gradio>=5.32.1",
61
61
  "torch>=2.7.0",
@@ -1 +0,0 @@
1
- CCOCC(=O)N1CCC[C@@H](C2CC2)CC1
File without changes
File without changes