Anonymous commited on
Commit
7d5db9e
·
1 Parent(s): bbd1f80

Simplify demo and add paper link

Browse files
Files changed (2) hide show
  1. README.md +4 -2
  2. app.py +26 -8
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
- ## Interactive Demo
21
 
22
- Enter a SMILES string to generate context-dependent VQ-Atom token IDs for individual atoms.
 
 
 
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&family=Libre+Caslon+Display&display=swap');
54
- :root{--ink:#18211d;--cream:#f3f0e7;--lime:#d8ff52;--muted:#68716c}.gradio-container{max-width:none!important;margin:0!important;background:var(--cream)!important;color:var(--ink)!important;font-family:'DM Sans',sans-serif!important}.contain{max-width:none!important;padding:0!important}footer{display:none!important}.main{padding:0!important}.page-nav{height:76px;padding:0 6vw;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #ccd0c8}.brand{font-size:22px;font-weight:700}.brand i{font-style:normal;background:var(--ink);color:var(--lime);border-radius:50%;font-size:11px;padding:10px 7px;margin-right:8px}.page-nav nav{display:flex;gap:30px;font-size:12px}.hero{padding:85px 8vw 75px}.eyebrow{font-size:10px;letter-spacing:2px;font-weight:700}.eyebrow i{display:inline-block;width:8px;height:8px;background:var(--lime);border-radius:50%;box-shadow:0 0 0 5px #d8ff5240;margin-right:12px}.hero h1{font:400 clamp(62px,9vw,124px)/.84 'Libre Caslon Display',Georgia,serif;letter-spacing:-5px;margin:32px 0}.hero h1 em{color:var(--muted)}.hero p{max-width:510px;margin-left:45%;color:var(--muted);line-height:1.7}.demo-wrap{background:var(--ink);padding:80px 7vw 100px}.demo-title{display:grid;grid-template-columns:1fr 2fr 1.2fr;gap:30px;color:#f6f3e9;margin-bottom:42px}.demo-title span{color:var(--lime);font-size:10px;letter-spacing:2px}.demo-title h2{font:400 44px/1.05 'Libre Caslon Display',Georgia,serif;margin:0}.demo-title p{color:#aeb6b1;line-height:1.6;margin:0}.input-card{background:#202b26!important;border:1px solid #53605a!important;border-radius:8px 8px 0 0!important;padding:22px!important;margin:0!important}.input-card label span{color:#aeb6b1!important;font-size:10px!important;letter-spacing:1.5px}.input-card textarea{background:#111915!important;color:white!important;border-color:#53605a!important;font-family:monospace!important}.encode-btn{background:var(--lime)!important;color:var(--ink)!important;border:0!important;font-weight:700!important;min-width:190px!important}.output-html{background:transparent!important;border:0!important;padding:0!important;margin:0!important}.result-shell{border:1px solid #53605a;border-top:0;color:#f6f3e9;background:#202b26}.result-head{display:flex;justify-content:space-between;padding:18px 22px;border-bottom:1px solid #53605a}.result-head span,.sequence>span{font-size:9px;letter-spacing:1.5px;color:#aeb6b1}.result-head small{font:10px monospace;color:#8d9993}.mol-svg{padding:20px;background:#f7f4ec;text-align:center}.mol-svg svg{max-width:760px;width:100%;height:auto}.sequence{border-top:1px solid #53605a;padding:20px 22px}.sequence>div{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}.atom-token{display:grid;grid-template-columns:auto auto;gap:3px 8px;align-items:center;border:1px solid #53605a;background:#26332d;padding:8px 10px}.atom-token span{font-size:8px;color:#7d8983}.atom-token b{font-size:12px}.atom-token code{grid-column:1/3;color:var(--lime);font-size:10px}.method{padding:100px 7vw}.method h2{font:400 48px 'Libre Caslon Display',serif}.steps{display:grid;grid-template-columns:repeat(3,1fr);gap:25px}.steps article{border-top:1px solid #ccd0c8;padding-top:22px}.steps b{color:#8c958f;font-size:10px}.steps p{font-size:12px;line-height:1.6;color:var(--muted)}@media(max-width:760px){.page-nav nav{display:none}.hero{padding:60px 24px}.hero h1{font-size:58px;letter-spacing:-3px}.hero p{margin-left:0}.demo-wrap{padding:60px 20px}.demo-title,.steps{grid-template-columns:1fr}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  """
56
 
57
  with gr.Blocks(css=CSS, title="VQAtom Demo", fill_width=True) as demo:
58
- gr.HTML('''<header class="page-nav"><div class="brand"><i>VQ</i>Atom</div><nav><span>Demo</span><span>Method</span><span>About</span></nav></header>
59
- <section class="hero"><div class="eyebrow"><i></i>DISCRETE MOLECULAR REPRESENTATION</div><h1>Molecules,<br><em>reimagined</em> as language.</h1><p>VQAtom turns each atom’s structural neighborhood into a discrete token — a new vocabulary for molecular AI.</p></section>
60
- <section class="demo-wrap"><div class="demo-title"><span>01 / LIVE MODEL</span><h2>See the hidden vocabulary<br>inside a molecule.</h2><p>Enter a SMILES string. The trained VQAtom encoder assigns one contextual token to every heavy atom.</p></div>''')
61
  with gr.Row(elem_classes="input-card"):
62
- smiles = gr.Textbox(value="CC(=O)NC1=CC=CC=C1", label="SMILES INPUT", lines=1, scale=5)
63
- button = gr.Button("Encode molecule →", elem_classes="encode-btn", scale=1)
64
  output = gr.HTML(elem_classes="output-html")
65
- gr.HTML('''</section><section class="method"><span>02 / THE IDEA</span><h2>Not just atoms. Atoms <em>in context.</em></h2><div class="steps"><article><b>01</b><h3>Aggregate</h3><p>A three-hop graph encoder gathers each atom’s structural neighborhood.</p></article><article><b>02</b><h3>Quantize</h3><p>Element-partitioned codebooks map continuous representations to stable clusters.</p></article><article><b>03</b><h3>Tokenize</h3><p>Every heavy atom receives a global VQAtom ID for downstream language models.</p></article></div></section>''')
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