Metadata-Version: 2.4
Name: blincs
Version: 0.1.0
Summary: Breadth-first Line Notation for Chemical Structures
Author: Wim Dehaen
License: MIT License
        
        Copyright (c) 2025 dehaenw
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/dehaenw/blincs
Project-URL: Repository, https://github.com/dehaenw/blincs
Keywords: chemistry,line-notation,smiles,molecular-representation,rdkit
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Chemistry
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rdkit>=2022.03
Dynamic: license-file

# BLINCS

**Breadth-first Line Notation for Chemical Structures.**

BLINCS is a compact line notation for molecules that encodes molecular
structure as a breadth-first traversal of the spanning tree, recording ring
closures as paired digits (similar to SMILES) but with a deterministic BFS
ordering. It depends only on RDKit and the Python standard library.

A presentation from RDKit UGM 2025 is available [here](https://github.com/rdkit/UGM_2025/blob/main/presentations/Thu/Afternoon/lightning/04_wim-dehaen.pdf).

## Installation

```bash
pip install blincs
```

Or from source:

```bash
git clone https://github.com/dehaenw/blincs.git
cd blincs
pip install .
```

## Usage

Convert an RDKit mol to BLINCS:

```python
from rdkit import Chem
from blincs import blincs

mol = Chem.MolFromSmiles("c1ccccc1")
bli = blincs.mol_to_blincs(mol)
# → 'cccccc%1%1'
```

Convert BLINCS back to an RDKit mol:

```python
mol = blincs.blincs_to_mol("C1CCCC1")
# → RDKit RWMol for pentane
```

Use `canonical=True` for stereo-aware canonical encoding (recommended):

```python
bli = blincs.mol_to_blincs(mol, canonical=True)
```

More examples in [`examples.ipynb`](examples.ipynb).

## Roundtrip accuracy

Benchmarked on **ChEMBL 34** (2,310,851 molecules) — full InChI comparison:

| Category | Count | % |
|---|---|---|
| Full match (identical InChI) | 2,310,815 | **99.998%** |
| Parse failures (RDKit cannot parse input) | 4 | 0.0002% |
| Decode failures (exotic polycyclic cages) | 7 | 0.0003% |
| Stereo mismatches | 25 | 0.001% |

The 25 remaining stereo mismatches are concentrated in highly symmetric
cage systems (bispyridinium cages, adamantane/norbornane bridges, and
symmetric halocyclohexanes) where CIP-based parity assignment is ambiguous.

On the 2,000-molecule stereo-containing subset ([`data/chembl_2k.smi`](data/chembl_2k.smi)),
roundtrip accuracy is **100%** (all stereochemistry preserved).

## Testing

```bash
pip install pytest
pytest tests/
```

## License

MIT — see [`LICENSE`](LICENSE).
