Metadata-Version: 2.4
Name: dcat-ap-plus-compound
Version: 0.1.1
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
License-File: LICENSE
Summary: Chemistry layer of the DCAT-AP-PLUS extensions: exact molecular properties of Chem-DCAT-AP chemical entities, computed from SMILES by a Rust core checked against RDKit.
Keywords: cheminformatics,SMILES,molecular formula,monoisotopic mass,molar mass,DCAT-AP-PLUS,Chem-DCAT-AP,RDF,FAIR,research data management,NFDI4Cat,catalysis
Author-email: Kundai Farai Sachikonye <kundai.sachikonye@uni-greifswald.de>
Maintainer: Kundai Farai Sachikonye
License: MIT
Requires-Python: ==3.13.*
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: NFDI4Cat, https://nfdi4cat.org

# dcat-ap-plus-compound

[![PyPI](https://img.shields.io/pypi/v/dcat-ap-plus-compound)](https://pypi.org/project/dcat-ap-plus-compound/)
[![Python](https://img.shields.io/pypi/pyversions/dcat-ap-plus-compound)](https://pypi.org/project/dcat-ap-plus-compound/)
[![Licence](https://img.shields.io/pypi/l/dcat-ap-plus-compound)](https://pypi.org/project/dcat-ap-plus-compound/)

The chemistry layer of the DCAT-AP-PLUS extensions: exact molecular properties of Chem-DCAT-AP chemical entities,
computed from SMILES by a Rust core that is checked against RDKit.

Status: pre-alpha. The first slice is built; the rest is specified.

## Overview

DCAT-AP-PLUS is the Data Catalog Vocabulary application profile extended by NFDI4Chem and NFDI4Cat. A catalogue in it
and its chemistry extension, Chem-DCAT-AP, names the chemical entities a dataset is about, usually by a stated
structure, formula or name. This package completes those
entities by computation: what follows from a stated structure and published constants alone is derived, never inferred
by a reasoner, and every answer is a verdict with its basis. An input that cannot be answered is refused with a reason
in a shared grammar (`<label>: <blocker>; needs <remedy>`), never silently dropped.

Notebook 20 of [dcat-ap-plus-chromatography](https://pypi.org/project/dcat-ap-plus-chromatography/) uses it for the
analytes its runs measure.

## What it computes

| Tool | From | Gives |
|---|---|---|
| `properties` | a Simplified Molecular Input Line Entry System (SMILES) string | Hill formula with its charge, element counts, formal charge, heavy-atom count, ring count (smallest set of smallest rings), component count, monoisotopic mass, molar mass with its interval |
| `closed-ladder`, `linear-ladder` | a profile of rung values | the invariants of the ladder: circulation, circulation per rung, uniformity |

The Rust core reads SMILES, kekulizes aromatic systems and assigns implicit hydrogens itself. Every value agrees with
RDKit on the reference cases, which the Rust, Python and TypeScript tests all reproduce.

Specified and not yet built: identity keys (InChI, InChIKey), protonation at a medium, substructure search, similarity
and model estimates.

## Installation

Python 3.13. Wheels for Linux, macOS and Windows carry the compiled Rust core; the package has no other dependency.

```console
pip install dcat-ap-plus-compound
```

Installing from the source distribution compiles the Rust core and needs a [Rust toolchain](https://rustup.rs).

## Usage

```python
from dcat_ap_plus_compound import rust

rust.ask("properties", smiles="CC(=O)[O-]")
# {'formula': 'C2H3O2-', 'formal_charge': -1, 'monoisotopic_mass': 59.0138..., 'molar_mass': 59.044, ...}

rust.ask("properties", smiles=" CCO")
# Refusal(label='unparsable', blocker='SMILES at position 0: leading whitespace',
#         needs='a `parse` convention that trims it, such as parse:trim-whitespace@1')

rust.ask("properties", conventions={"parse:trim-whitespace@1": {}}, smiles=" CCO")
# {'formula': 'C2H6O', ...}: read under the named convention
```

Many records in one call, each answered or refused on its own:

```python
answers = rust.tool("properties", [{"record": key, "inputs": {"smiles": s}} for key, s in structures.items()])
```

The same core builds as a command for the artefact runtime, one JSON request on standard input and one answer per
record:

```console
$ cargo build --release -p compound-tool
$ echo '{"records": [{"record": "r1", "inputs": {"smiles": "CC(=O)[O-]"}}]}' | target/release/compound tool properties
{"answers":[{"record":"r1","values":{"formula":"C2H3O2-","monoisotopic_mass":59.01385291591,...}}]}
```

## Results on public data

The 445 analytes of RepoRT datasets 0187–0196 are computed from their stated SMILES in 0.15 s. Against the formula
RepoRT states, 420 agree, 21 are the neutral parent of a charged structure, and 4 differ, one of them a wrong structure
in RepoRT. The entities are then written as Chem-DCAT-AP `ChemicalEntity` records in a SciDatS file (notebook 02).

## Documentation

The source repository holds the specification (17 parts, the blueprint for the package and its adapters), the
notebooks (the Rust core against RDKit; RepoRT's stated structures checked) and the changelog.

## Data

Notebook 02 reads an extract of RepoRT (Kretschmer et al., *Nature Methods* 21, 153–155, 2024) in
`docs/notebooks/data/report`, licensed Creative Commons Attribution-ShareAlike 4.0 (CC BY-SA 4.0)
as RepoRT is.

## Layout

The heavy computing runs in Rust. Python is the prototype, built on RDKit, the reference the Rust code is tested
against, and the language of the notebooks. TypeScript carries the web interface. The three share one version.

| Path | Language | What | Tool |
|---|---|---|---|
| `crates/compound-core/` | Rust | SMILES reading, kekulization, implicit hydrogens, exact properties, ladders; the tool protocol as JSON in and out; no I/O | cargo |
| `crates/compound-tool/` | Rust | the `compound tool <name>` command | cargo |
| `crates/compound-wasm/` | Rust | the core for browsers, through the same protocol | wasm-pack |
| `crates/compound-py/` | Rust | the extension module `dcat_ap_plus_compound._core`, built by maturin into every wheel | maturin |
| `packages/compound/` | TypeScript | `@dcat-ap-plus/compound`: typed calls of the tools for web interfaces | npm |
| `src/dcat_ap_plus_compound/`, `tests/` | Python 3.13 | `rust.py` asks the extension module; the tests compare it with RDKit | uv |
| `docs/notebooks/` | Python | demonstrations | uv |
| `scripts/` | Python | `generate_elements.py` writes the element table from RDKit; `generate_core_fixtures.py` writes the reference values | uv |
| `tests/fixtures/core/` | JSON | values RDKit computed, which the Rust, Python and TypeScript tests must reproduce | |

## Development

Requires [uv](https://docs.astral.sh/uv/), the Rust toolchain pinned in `rust-toolchain.toml`,
[wasm-pack](https://rustwasm.github.io/wasm-pack/) and Node 20 or later.

```console
# Python
uv sync   # compiles the extension module from crates/compound-py with maturin
uv run ruff check .
uv run ruff format --check .
uv run zuban check
uv run pytest
uv run --group notebooks python docs/notebooks/build.py
uv run --group docs sphinx-build -W -b html docs docs/_build

# Rust
cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace

# WebAssembly and TypeScript (the build runs wasm-pack first)
npm ci
npm run build
npm run typecheck
npm test
```

After an RDKit upgrade, regenerate the element table and the fixtures with
`uv run --group notebooks python scripts/generate_elements.py` and `scripts/generate_core_fixtures.py`; a test fails
while the fixtures are out of date. Commit messages follow
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/); see
`CONTRIBUTING.md`.

## Citation

Sachikonye, K. F. (2026). *dcat-ap-plus-compound* (version 0.1.1) [Software]. https://pypi.org/project/dcat-ap-plus-compound/

## Acknowledgement

Kundai Farai Sachikonye, University of Greifswald. Developed within
[NFDI4Cat](https://nfdi4cat.org), the National Research Data Infrastructure for Catalysis-Related Sciences, funded by
the German Research Foundation (DFG), project number 441926934.

## Licence

MIT. The RepoRT extract in `docs/notebooks/data/report` is CC BY-SA 4.0.

