Anonymous commited on
Commit ·
7d5db9e
1
Parent(s): bbd1f80
Simplify demo and add paper link
Browse files
README.md
CHANGED
|
@@ -17,6 +17,8 @@ Interactive per-atom tokenization using the trained VQAtom checkpoint.
|
|
| 17 |
|
| 18 |
[VQ-Atom: Semantic Discretization of Local Atomic Environments for Molecular Representation Learning](https://arxiv.org/abs/2605.16823)
|
| 19 |
|
| 20 |
-
##
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
[VQ-Atom: Semantic Discretization of Local Atomic Environments for Molecular Representation Learning](https://arxiv.org/abs/2605.16823)
|
| 19 |
|
| 20 |
+
## How it works
|
| 21 |
|
| 22 |
+
1. A three-hop graph neural network aggregates each atom's local molecular environment.
|
| 23 |
+
2. The continuous representation is mapped to an element-partitioned vector-quantization codebook.
|
| 24 |
+
3. The selected codebook entry is returned as a global, discrete VQAtom ID.
|
app.py
CHANGED
|
@@ -50,19 +50,37 @@ def encode_molecule(smiles):
|
|
| 50 |
|
| 51 |
|
| 52 |
CSS = """
|
| 53 |
-
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600;700&
|
| 54 |
-
:root{--ink:#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"""
|
| 56 |
|
| 57 |
with gr.Blocks(css=CSS, title="VQAtom Demo", fill_width=True) as demo:
|
| 58 |
-
gr.HTML('''<header class="
|
| 59 |
-
<section class="hero"><
|
| 60 |
-
<section class="demo-
|
| 61 |
with gr.Row(elem_classes="input-card"):
|
| 62 |
-
smiles = gr.Textbox(value="CC(=O)NC1=CC=CC=C1", label="SMILES
|
| 63 |
-
button = gr.Button("
|
| 64 |
output = gr.HTML(elem_classes="output-html")
|
| 65 |
-
gr.HTML('''</section><section class="method"><
|
| 66 |
button.click(encode_molecule, smiles, output)
|
| 67 |
smiles.submit(encode_molecule, smiles, output)
|
| 68 |
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
CSS = """
|
| 53 |
+
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');
|
| 54 |
+
:root{--ink:#17231d;--paper:#f7f6f1;--line:#d9ddd7;--green:#bfff3f;--muted:#66716b}
|
| 55 |
+
.gradio-container{max-width:none!important;margin:0!important;background:var(--paper)!important;color:var(--ink)!important;font-family:'DM Sans',sans-serif!important}
|
| 56 |
+
.contain{max-width:none!important;padding:0!important}footer{display:none!important}.main{padding:0!important}
|
| 57 |
+
.shell{max-width:1040px;margin:auto;padding:0 24px}.topbar{height:64px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line)}
|
| 58 |
+
.brand{font-size:20px;font-weight:700}.brand i{font-style:normal;background:var(--ink);color:var(--green);border-radius:50%;font-size:10px;padding:9px 6px;margin-right:8px}
|
| 59 |
+
.paper-link{color:var(--ink)!important;text-decoration:none;border:1px solid var(--line);border-radius:7px;padding:8px 12px;font-size:13px;font-weight:600}
|
| 60 |
+
.hero{padding:58px 0 34px;max-width:760px}.hero h1{font-size:clamp(42px,6vw,66px);line-height:1.02;letter-spacing:-2.5px;margin:0 0 18px}.hero p{font-size:17px;line-height:1.65;color:var(--muted);max-width:690px;margin:0}
|
| 61 |
+
.demo-card{background:white;border:1px solid var(--line);border-radius:12px;padding:24px;box-shadow:0 8px 24px rgba(24,35,29,.05)}
|
| 62 |
+
.demo-card h2{font-size:19px;margin:0 0 5px}.demo-card>p{color:var(--muted);font-size:13px;margin:0 0 18px}
|
| 63 |
+
.input-card{padding:0!important;margin:0!important;gap:12px!important}.input-card label span{font-size:11px!important;letter-spacing:.8px}.input-card textarea{font-family:monospace!important;background:#fbfcfa!important;border-color:var(--line)!important}
|
| 64 |
+
.encode-btn{background:var(--ink)!important;color:white!important;border:0!important;font-weight:700!important;min-width:180px!important}
|
| 65 |
+
.output-html{background:transparent!important;border:0!important;padding:0!important;margin:16px 0 0!important}
|
| 66 |
+
.result-shell{border:1px solid var(--line);border-radius:9px;overflow:hidden;background:white}.result-head{display:flex;justify-content:space-between;padding:14px 16px;border-bottom:1px solid var(--line)}
|
| 67 |
+
.result-head span,.sequence>span{font-size:9px;letter-spacing:1.4px;color:var(--muted)}.result-head small{font:10px monospace;color:var(--muted)}
|
| 68 |
+
.mol-svg{padding:12px;background:white;text-align:center}.mol-svg svg{max-width:760px;width:100%;height:auto}.sequence{border-top:1px solid var(--line);padding:16px}
|
| 69 |
+
.sequence>div{display:flex;gap:7px;flex-wrap:wrap;margin-top:10px}.atom-token{display:grid;grid-template-columns:auto auto;gap:2px 7px;align-items:center;border:1px solid var(--line);background:#f7f9f6;padding:7px 9px;border-radius:6px}
|
| 70 |
+
.atom-token span{font-size:8px;color:#7d8983}.atom-token b{font-size:12px}.atom-token code{grid-column:1/3;color:#356600;font-size:10px}
|
| 71 |
+
.method{padding:54px 0 70px}.method h2{font-size:27px;margin:0 0 22px}.steps{display:grid;grid-template-columns:repeat(3,1fr);gap:14px}.steps article{border:1px solid var(--line);border-radius:10px;padding:18px;background:#fbfcfa}.steps b{color:#679400;font-size:10px}.steps h3{font-size:16px;margin:9px 0 6px}.steps p{font-size:12px;line-height:1.6;color:var(--muted);margin:0}.citation{font-size:13px;color:var(--muted);margin-top:22px}.citation a{color:var(--ink);font-weight:700}
|
| 72 |
+
@media(max-width:700px){.shell{padding:0 16px}.hero{padding:40px 0 26px}.hero h1{font-size:42px}.hero p{font-size:15px}.demo-card{padding:17px}.steps{grid-template-columns:1fr}.input-card{display:block!important}.encode-btn{margin-top:10px!important;width:100%!important}.result-head{display:block}.result-head small{display:block;margin-top:6px;overflow-wrap:anywhere}}
|
| 73 |
"""
|
| 74 |
|
| 75 |
with gr.Blocks(css=CSS, title="VQAtom Demo", fill_width=True) as demo:
|
| 76 |
+
gr.HTML('''<div class="shell"><header class="topbar"><div class="brand"><i>VQ</i>Atom</div><a class="paper-link" href="https://arxiv.org/abs/2605.16823" target="_blank">Read the paper ↗</a></header>
|
| 77 |
+
<section class="hero"><h1>Turn molecular environments into discrete tokens.</h1><p>Enter a SMILES string to assign a learned, context-dependent VQAtom ID to each heavy atom.</p></section>
|
| 78 |
+
<section class="demo-card"><h2>Try VQAtom</h2><p>The example below is acetanilide. Replace it with any valid SMILES string.</p>''')
|
| 79 |
with gr.Row(elem_classes="input-card"):
|
| 80 |
+
smiles = gr.Textbox(value="CC(=O)NC1=CC=CC=C1", label="SMILES", lines=1, scale=5)
|
| 81 |
+
button = gr.Button("Generate IDs", elem_classes="encode-btn", scale=1)
|
| 82 |
output = gr.HTML(elem_classes="output-html")
|
| 83 |
+
gr.HTML('''</section><section class="method"><h2>How the IDs are created</h2><div class="steps"><article><b>01 · GRAPH CONTEXT</b><h3>Aggregate</h3><p>A GNN collects each atom’s local molecular environment over three hops.</p></article><article><b>02 · VECTOR QUANTIZATION</b><h3>Quantize</h3><p>The resulting representation is assigned to the nearest entry in an element-partitioned codebook.</p></article><article><b>03 · DISCRETE TOKEN</b><h3>Identify</h3><p>The selected codebook entry becomes a reusable global VQAtom ID for that atom.</p></article></div><p class="citation">Method and evaluation: <a href="https://arxiv.org/abs/2605.16823" target="_blank">VQ-Atom: Semantic Discretization of Local Atomic Environments for Molecular Representation Learning ↗</a></p></section></div>''')
|
| 84 |
button.click(encode_molecule, smiles, output)
|
| 85 |
smiles.submit(encode_molecule, smiles, output)
|
| 86 |
|