Metadata-Version: 2.4
Name: dcat-ap-plus-compound
Version: 0.1.0
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
License-File: LICENSE
Summary: Compounds in DCAT-AP-PLUS and Chem-DCAT-AP, from identity to substructure and similarity search, computed rather than inferred by a reasoner and answered with verdicts.
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: Bug Tracker, https://github.com//dcat-ap-plus-compound/issues
Project-URL: Changelog, https://github.com//dcat-ap-plus-compound/blob/main/CHANGELOG.md
Project-URL: documentation, https://dcat-ap-plus-compound.readthedocs.io
Project-URL: repository, https://github.com//dcat-ap-plus-compound

# dcat-ap-plus-compound

Compounds in DCAT-AP-PLUS and Chem-DCAT-AP, from identity to substructure and similarity search, computed rather than
inferred by a reasoner and answered with verdicts.

Status: first slice built. The Rust core reads SMILES, kekulizes aromatic systems, assigns implicit hydrogens, and
computes the exact properties of specification part 08 and the invariants of ladders. Every value agrees with RDKit on
the reference cases. Identity keys (InChI, InChIKey), substructure search and similarity are specified and not yet
built. The specification, the blueprint for this package and its adapters, is in
[docs/specification](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-compound/src/branch/main/docs/specification/README.md).

## Installation

From PyPI, for Python 3.13. The wheels for Linux, macOS and Windows carry the Rust core.

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

Installing from the source distribution, or from the repository, compiles the Rust core and needs a Rust toolchain.

## 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. Each language keeps its own build
tool, and they 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 the artefact runtime runs: `properties`, `closed-ladder`, `linear-ladder` | cargo |
| `crates/compound-wasm/` | Rust | the core for browsers, through the same protocol | wasm-pack |
| `packages/compound/` | TypeScript | `@dcat-ap-plus/compound`: typed calls of the tools for web interfaces | npm |
| `crates/compound-py/` | Rust | the extension module `dcat_ap_plus_compound._core`, built by maturin into every wheel | maturin |
| `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: 01 the Rust core against RDKit; 02 RepoRT's stated structures checked and written as Chem-DCAT-AP chemical entities in a SciDatS file | 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 | |

## Usage

The command answers the tool protocol of the artefact runtime: one request on standard input, one answer per record.
A record it cannot answer is refused, with a reason in the shared grammar (`<label>: <blocker>; needs <remedy>`).

```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,...}}]}
```

Conventions reach the command as a `conventions.json` that the program names in the tool's `files`, so their digest
enters the stage key. Without one the defaults hold: `parse:strict@1` refuses a SMILES with surrounding whitespace,
and `parse:trim-whitespace@1` reads it.

From Python, with the core compiled into the package:

```python
from dcat_ap_plus_compound import rust

rust.ask("properties", smiles="c1ccsc1")  # {'formula': 'C4H4S', ...}
rust.ask("properties", smiles=" CCO")  # Refusal(label='unparsable', ...)
rust.ask("properties", conventions={"parse:trim-whitespace@1": {}}, smiles=" CCO")
```

## Data

Notebook 02 reads an extract of RepoRT (Kretschmer et al., *Nature Methods* 21, 153–155, 2024) in
[docs/notebooks/data/report](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-compound/src/branch/main/docs/notebooks/data/report/README.md). The extract is licensed CC BY-SA 4.0, as RepoRT
is; the rest of the repository is under the MIT licence.

## Development

Requires [uv](https://docs.astral.sh/uv/), the Rust toolchain pinned in `rust-toolchain.toml` (installed by rustup on
first use), [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/). The project follows the
[copier-python](https://gitlab.com/opensourcelab/software-dev/copier-python) template; see
[CONTRIBUTING.md](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-compound/src/branch/main/CONTRIBUTING.md).

## Authors and acknowledgment

Kundai Farai Sachikonye, University of Greifswald. Developed within NFDI4Cat, the National Research Data Infrastructure
for Catalysis-Related Sciences.

## Licence

MIT. See [LICENSE](https://git.uni-greifswald.de/sachikonyk/dcat-ap-plus-compound/src/branch/main/LICENSE). The RepoRT extract in `docs/notebooks/data/report` is CC BY-SA 4.0.

