A Bond-Level Sequence Framework for Molecular Representation Learning with Structural Constraints.
3 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 3 matches · 1 of them tie a paragraph to a whole file without given lines: a weak match, whose lines are not tinted
- [1] § 3. Materials and Methods › 3.2. Materials › 3.2.2. Implementation Details ↔ utils/config.py, the whole file · a weak match · score 0.57 · masking ratios, hyperparameters, schedules, triplet, seeds, layer · block
oscr:b:HRHXYXWDA9CDX-V· Report a mismatch - [2] § 3. Materials and Methods › 3.1. Methodology › 3.1.1. Preliminary ↔ datasets/dataset.py, lines 32 to 75 · score 0.56 · formal charges, atomic, aromaticity, conjugation, ring, vector · block
oscr:b:KEFMRQSXARXKP-8· Report a mismatch - [3] § 3. Materials and Methods › 3.1. Methodology › 3.1.1. Preliminary ↔ scripts/preprocess.py, lines 46 to 62 · score 0.56 · formal charges, atomic, aromaticity, conjugation, ring, vector · block
oscr:b:GZFHMFV9N5J20-H· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 152 lines · 4.3 KB · no license · 1 match
- # utils/config.py
- import os
- import json
- import time
- import torch
- class Config:
- seed = 202
- device = "cuda" if torch.cuda.is_available() else "cpu"
- num_workers = 0
- pin_memory = False
- # -----------------------
- # 1) Data
- # -----------------------
- train_csv = "data/pretrain/10K.csv"
- smiles_col = "SMILES"
- vocab_path = "data/splits/vocab_directed.json"
- target_cache_path = "data/pretrain/cache/data_directed.pt"
- max_seq_len = 64
- mask_ratio_1 = 0.15
- mask_ratio_2 = 0.30
- # -----------------------
- # 2) Model (Backbone)
- # -----------------------
- embed_dim = 256#512 #256
- num_heads = 32#64#32
- hidden_dim = 1024
- num_layers = 4
- dropout = 0.1
- global_attr_dim = 4
- adj_ratio = 0.85
- # -----------------------
- # 3) Optim / Schedule
- # -----------------------
- epochs = 20
- batch_size = 256
- lr = 1e-5
- weight_decay = 0.01
- grad_clip_norm = 5.0
- best_ema_beta = 0.9
- # -----------------------
- # 4) Pretrain Loss Hyperparams
- # -----------------------
- contrastive_temperature = 0.1
- triplet_margin = 1e-6
- triplet_loss_weight = 0.1
- # -----------------------
- # 5) Output
- # -----------------------
- out_root = "out/pretrain"
- run_name = "" # 为空则自动时间戳
- save_every_epochs = 1
- resume = True
- log_every_steps = 50
- # -----------------------
- # 6) Finetune (Classification)
- # -----------------------
- ft_dataset_name = "tox21"
- ft_data_root = "data/finetune"
- ft_epochs = 50
- ft_batch_size = 32
- ft_lr = 2e-5
- ft_encoder_lr_ratio = 0.05
- ft_weight_decay = 0.01
- ft_dropout = 0.2
- ft_freeze_epochs = 5
- unfreeze_last_n = -1
- ft_patience = 10
- ft_pos_weight_mode = "sqrt"
- pretrain_ckpt = "out/pretrain/best.pt"
- ft_vocab_path_un = "data/splits/vocab_undirected.json"
- ft_vocab_path_di = "data/splits/vocab_directed.json"
- mask_strategy = "structured" # random 或 structured
- use_consistency = True
- use_triplet = True
- lambda_cl = 1.0
- lambda_tri = 1.0
- # ============= 🆕 新增/修改的方法 =============
- @classmethod
- def override_from_json(cls, json_path: str) -> None:
- """从 JSON 文件加载参数并覆盖当前配置"""
- if not json_path or not os.path.exists(json_path):
- print(f"[Config] Warning: Config file not found: {json_path}")
- return
- print(f"[Config] Loading params from {json_path} ...")
- with open(json_path, "r", encoding="utf-8") as f:
- params = json.load(f)
- cls.override(params)
- @classmethod
- def override(cls, params: dict) -> None:
- """使用字典批量覆盖配置"""
- for k, v in params.items():
- if hasattr(cls, k):
- # 类型安全检查(可选):防止把 float 覆盖成 str
- original_val = getattr(cls, k)
- if isinstance(original_val, float) and isinstance(v, int):
- v = float(v)
- setattr(cls, k, v)
- # 只有在值真的改变时才打印,避免刷屏
- if str(original_val) != str(v):
- print(f" -> Override: {k} = {v}")
- else:
- print(f" -> [Ignore] Unknown key: {k}")
- @classmethod
- def get_run_name(cls) -> str:
- return cls.run_name or time.strftime("%m.%d_%H-%M-%S", time.localtime())
- @classmethod
- def get_run_dir(cls) -> str:
- return os.path.join(cls.out_root, cls.get_run_name())
- @classmethod
- def ensure_dirs(cls) -> str:
- run_dir = cls.get_run_dir()
- os.makedirs(run_dir, exist_ok=True)
- os.makedirs(os.path.join(run_dir, "ckpt"), exist_ok=True)
- return run_dir
- @classmethod
- def dump(cls, run_dir: str) -> None:
- """保存最终配置,方便复现"""
- cfg = {}
- for k, v in vars(cls).items():
- if k.startswith("_"): continue
- if callable(v) or isinstance(v, (classmethod, staticmethod)): continue
- try:
- json.dumps(v)
- cfg[k] = v
- except TypeError:
- cfg[k] = str(v)
- with open(os.path.join(run_dir, "config.json"), "w", encoding="utf-8") as f:
- json.dump(cfg, f, ensure_ascii=False, indent=2)
config.py at commit 5b5028e, no license · at the source
Overview
- National Engineering Research Center of Industrial Crystallization Technology, School of Chemical Engineering and Technology, Tianjin University, Tianjin 300072, China; (H.F.); (H.Q.); (X.H.); (D.Z.)
- Engineering Research Center of Green Refining Process, Ministry of Education, Tianjin University, Tianjin 300072, China
Abstract
Molecular property prediction is a fundamental task in drug discovery and materials design. While graph neural networks (GNNs) and SMILES-based Transformers have made significant strides, the former are often limited by local message-passing bottlenecks such as over-squashing, while the latter frequently lack explicit topological constraints and suffer from severe vocabulary imbalance. In this work, we revisit the granularity of molecular modeling and propose a representation learning framework built upon bond-level sequences. Our framework models molecules as sequences of directed bond tokens and introduces a structure-aware hybrid attention mechanism. By imposing hard topological constraints on a subset of attention heads to reinforce local connectivity while preserving global receptive fields in the remaining heads, the design is intended to separate short-range chemical bonding from long-range contextual dependencies. For pre-training, we implemented a multi-scale consistency learning paradigm, which utilizes an atom-centric group masking strategy to induce a hierarchical loss of local structural information and employs contrastive and triplet losses to ensure identity consistency across varying scales of structural degradation. Furthermore, by incorporating macro-scale physicochemical descriptors (e.g., LogP, TPSA) as global anchors, we examined how the inclusion of global attribute bias can provide weak physicochemical priors during pre-training, while its effect during downstream fine-tuning remains task-dependent. Experimental results demonstrate that our lightweight model, with approximately 3.5 million parameters, exhibits a dataset-dependent performance profile across MoleculeNet benchmarks and shows promising behavior on selected topology-sensitive tasks, particularly MUV. Ablation studies further analyze the contribution of bond-level connectivity, the stage-dependent dynamics of global attribute bias, structured masking, and pre-training configurations. Ultimately, this work provides an alternative representation design for molecular modeling, offering a parameter-efficient option for future molecular learning systems alongside traditional SMILES-based and graph-based formulations.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.
Haoran-Fan/bondformer
5b5028ee4f3b0df07ee10bc5bb9cd174b59f8366, 11 March 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
21 files
- datasets/
build_vocab.py , Python, 111 lines - datasets/
dataset.py , Python, 413 lines, 1 match - datasets/
tokenizer.py , Python, 109 lines - models/
__init__.py , Python, 10 lines - models/
bert.py , Python, 42 lines - models/
embedding.py , Python, 10 lines - models/
heads.py , Python, 77 lines - models/
transformer.py , Python, 162 lines - scripts/
finetune_cls.py , Python, 336 lines - scripts/
master_preprocess.py , Python, 75 lines - scripts/
preprocess.py , Python, 161 lines, 1 match - scripts/
pretrain.py , Python, 345 lines - tools/
build_adj_cache.py , Python, 83 lines - tools/
prepare_ogb_split.py , Python, 130 lines - trainer/
finetune_cls_trainer.py , Python, 187 lines - trainer/
finetune_reg_trainer.py , Python, 184 lines - trainer/
losses.py , Python, 55 lines - trainer/
metrics.py , Python, 43 lines - trainer/
pretrain_trainer.py , Python, 326 lines - utils/
config.py , Python, 152 lines, 1 match - readme.md, Text, 93 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 20 scripts, each with its path and the digest of its content;
- 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data Availability Statement
The source code, environment specifications, and a self-contained demonstration dataset supporting the findings of this study are publicly available in the official repository to ensure reproducibility and open access: [https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 7 authors, 5 keywords, 1 funder, 8 references.
Cite
This paper
Fan, H., Qi, H., Huang, X., Zhu, D., Wang, N., Wang, T., & Hao, H. (2026). A Bond-Level Sequence Framework for Molecular Representation Learning with Structural Constraints. Molecules (Basel, Switzerland), 31(11), 1972. https://
BibTeX
@article{fan2026bond,
author = {Fan, Haoran and Qi, Haoqiang and Huang, Xin and Zhu, Dongyang and Wang, Na and Wang, Ting and Hao, Hongxun},
title = {{A Bond-Level Sequence Framework for Molecular Representation Learning with Structural Constraints}},
journal = {Molecules (Basel, Switzerland)},
year = {2026},
month = jun,
volume = {31},
number = {11},
pages = {1972},
publisher = {Multidisciplinary Digital Publishing Institute (MDPI)},
issn = {1420-3049},
doi = {10.3390/
url = {https://
pmid = {42280272},
pmcid = {PMC13257498}
}
RIS
TY - JOUR
AU - Fan, Haoran
AU - Qi, Haoqiang
AU - Huang, Xin
AU - Zhu, Dongyang
AU - Wang, Na
AU - Wang, Ting
AU - Hao, Hongxun
TI - A Bond-Level Sequence Framework for Molecular Representation Learning with Structural Constraints
T2 - Molecules (Basel, Switzerland)
J2 - Molecules
PY - 2026
DA - 2026/
VL - 31
IS - 11
SP - 1972
SN - 1420-3049
PB - Multidisciplinary Digital Publishing Institute (MDPI)
DO - 10.3390/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.3390/
"type": "article-journal",
"title": "A Bond-Level Sequence Framework for Molecular Representation Learning with Structural Constraints",
"container-title": "Molecules (Basel, Switzerland)",
"author": [
{
"family": "Fan",
"given": "Haoran"
},
{
"family": "Qi",
"given": "Haoqiang"
},
{
"family": "Huang",
"given": "Xin"
},
{
"family": "Zhu",
"given": "Dongyang"
},
{
"family": "Wang",
"given": "Na"
},
{
"family": "Wang",
"given": "Ting"
},
{
"family": "Hao",
"given": "Hongxun"
}
],
"container-title-short":
"volume": "31",
"issue": "11",
"page": "1972",
"DOI": "10.3390/
"PMID": "42280272",
"PMCID": "PMC13257498",
"ISSN": "1420-3049",
"publisher": "Multidisciplinary Digital Publishing Institute (MDPI)",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
5
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1021/jacsau.5c00289 [code]
- HiCLR: Knowledge-Induced Hierarchical Contrastive Learning with Retrosynthesis Prediction Yields a Reaction Foundation Model.Journal: JACS AuIn common: RDKit, PyTorch, scikit-learn, 2 other tools, 3 references
- [2] doi:10.1002/advs.202513556 [code]
- Learned Conformational Space and Pharmacophore Into Molecular Foundational Model.Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)In common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [3] doi:10.1038/s41540-024-00401-0 [code]
- A deep position-encoding model for predicting olfactory perception from molecular structures and electrostatics.Journal: NPJ systems biology and applicationsIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [4] doi:10.34133/csbj.0036 [code]
- HYG-mol: An Interpretable Multimodal Hypergraph Framework for Molecular Property Prediction.Journal: Computational and structural biotechnology journalIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [5] doi:10.1038/s41467-025-66685-w [code]
- Molecular Motif Learning as a pretraining objective for molecular property prediction.Journal: Nature communicationsIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [6] doi:10.1186/s13321-024-00933-x [code]
- Group graph: a molecular graph representation with enhanced performance, efficiency and interpretability.Journal: Journal of cheminformaticsIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [7] doi:10.1038/s41467-023-38192-3 [code]
- Chemistry-intuitive explanation of graph neural networks for molecular property prediction with substructure masking.Journal: Nature communicationsIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 2 references
- [8] doi:10.1186/s13321-025-01007-2 [code]
- Prediction of blood-brain barrier and Caco-2 permeability through the Enalos Cloud Platform: combining contrastive learning and atom-attention message passing neural networks.Journal: Journal of cheminformaticsIn common: RDKit, PyTorch, scikit-learn, 2 other tools, 2 references
- [9] doi:10.1021/acs.jcim.5c01888 [code]
- CANDID-CNS: AI Unlocks Stereochemistry and Beyond Rule of 5 to Predict CNS Penetration of Small Molecules.Journal: Journal of chemical information and modelingIn common: RDKit, PyTorch, scikit-learn, 2 other tools, 2 references
- [10] doi:10.1021/acs.jcim.5c00724 [code]
- Graph Convolutional Neural Network-Enabled Frontier Molecular Orbital Prediction: A Case Study with Neurotransmitters and Antidepressants.Journal: Journal of chemical information and modelingIn common: RDKit, PyTorch, scikit-learn, 2 other tools, cellular / molecular, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 20 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:6bd73ce6c34fbbee…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.3390/molecules31111972)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.3390/molecules31111972.svg
:target: https://openscicode.org/badge/doi/10.3390/molecules31111972
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.3390/molecules31111972"><img src="https://openscicode.org/badge/doi/10.3390/molecules31111972.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
