chembfn-webui 0.5.0__py3-none-any.whl → 1.0.0__py3-none-any.whl
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.
- chembfn_webui/bin/app.py +53 -17
- chembfn_webui/cache/results.csv +1 -1
- chembfn_webui/lib/version.py +1 -1
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/METADATA +9 -2
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/RECORD +9 -9
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/WHEEL +0 -0
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/entry_points.txt +0 -0
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {chembfn_webui-0.5.0.dist-info → chembfn_webui-1.0.0.dist-info}/top_level.txt +0 -0
chembfn_webui/bin/app.py
CHANGED
|
@@ -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
|
-
|
|
21
|
+
FASTA_VOCAB_KEYS,
|
|
22
22
|
load_vocab,
|
|
23
23
|
smiles2vec,
|
|
24
|
-
|
|
24
|
+
fasta2vec,
|
|
25
25
|
split_selfies,
|
|
26
26
|
)
|
|
27
|
-
from bayesianflow_for_chem.tool import
|
|
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,
|
|
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 =
|
|
241
|
-
tokeniser =
|
|
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
|
-
|
|
350
|
-
|
|
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
|
-
|
|
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
|
-
|
|
365
|
-
|
|
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 =
|
|
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
|
)
|
chembfn_webui/cache/results.csv
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
CN1CCOCC1c1cccc(C(=O)Nc2ccnn2C(C)C)c1
|
chembfn_webui/lib/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chembfn_webui
|
|
3
|
-
Version: 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>=
|
|
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,16 +1,16 @@
|
|
|
1
1
|
chembfn_webui/__init__.py,sha256=AXUdd_PrlfVO56losFUP7A8XrqCDPylwRbTpe_WG3Uc,87
|
|
2
|
-
chembfn_webui/bin/app.py,sha256=
|
|
2
|
+
chembfn_webui/bin/app.py,sha256=fqIP5O5aojwZmw2-eHBcuFm4YuQBIEuwOMTvDzW7jcA,21632
|
|
3
3
|
chembfn_webui/cache/cache_file_here.txt,sha256=hi60T_q6Cf5WPtXuwe4CqjiWpaUqrczsmGMhKIUL--M,28
|
|
4
|
-
chembfn_webui/cache/results.csv,sha256=
|
|
4
|
+
chembfn_webui/cache/results.csv,sha256=xdSOWM1GGGJEFS1Y4sfCjA-9-66AECEo6El59_yW1hw,37
|
|
5
5
|
chembfn_webui/lib/utilities.py,sha256=ALPw-Evjd9DdsU_RQA6Zp2Gc6XnRR7Y_5fZrqG9azWo,7460
|
|
6
|
-
chembfn_webui/lib/version.py,sha256=
|
|
6
|
+
chembfn_webui/lib/version.py,sha256=Mbvn1j2C-hWCKICax3XLfU-P0Q3j0oPQ4GQXoDFJ3fs,138
|
|
7
7
|
chembfn_webui/model/base_model/place_base_model_here.txt,sha256=oa8_ILaAlWpTXICVDi-Y46_OahV7wB6Che6gbiEIh-c,39
|
|
8
8
|
chembfn_webui/model/lora/place_lora_folder_here.txt,sha256=YYOo0Cj278DyRcgVrCLa1f2Q-cqgNeMnelaLiA3Fuic,69
|
|
9
9
|
chembfn_webui/model/standalone_model/place_standalone_model_folder_here.txt,sha256=Dp42UscfI0Zp3SnvRv5vOfWiJZnxdY7rG3jo0kf86VM,80
|
|
10
10
|
chembfn_webui/model/vocab/place_vocabulary_file_here.txt,sha256=fLOINvZP2022oE7RsmfDjgyaw2yMi7glmdu_cTwmo88,28
|
|
11
|
-
chembfn_webui-0.
|
|
12
|
-
chembfn_webui-0.
|
|
13
|
-
chembfn_webui-0.
|
|
14
|
-
chembfn_webui-0.
|
|
15
|
-
chembfn_webui-0.
|
|
16
|
-
chembfn_webui-0.
|
|
11
|
+
chembfn_webui-1.0.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
12
|
+
chembfn_webui-1.0.0.dist-info/METADATA,sha256=iRpNEXoJZRG42fMjyHwsmcUJ5jV0MrGgWUMkZrqUb3s,5897
|
|
13
|
+
chembfn_webui-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
chembfn_webui-1.0.0.dist-info/entry_points.txt,sha256=fp8WTPybvwpeYKrUhTi456wwZbmCMJXN1TeFGpR1SlY,55
|
|
15
|
+
chembfn_webui-1.0.0.dist-info/top_level.txt,sha256=VdWt3Z7jhbB0pQO_mkRawnU5s75SBT9BV8fGaAIJTDI,14
|
|
16
|
+
chembfn_webui-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|