Metadata-Version: 2.4
Name: topoppi-affinity
Version: 3.0.0
Summary: Affinity modelling using interface descriptors produced by the TopoPPI workflow
License-Expression: MIT
Project-URL: Documentation, https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/README.md
Project-URL: Repository, https://github.com/GeraltZeroZhong/TopoPPI
Project-URL: Issues, https://github.com/GeraltZeroZhong/TopoPPI/issues
Requires-Python: <3.11,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: topoppi[representation]<3.1,>=3.0.0
Requires-Dist: scikit-learn<1.8,>=1.6
Requires-Dist: pandas>=2.0
Requires-Dist: joblib<1.6,>=1.5
Requires-Dist: openpyxl>=3.1
Provides-Extra: models
Requires-Dist: torch>=2.2; extra == "models"
Requires-Dist: torch-geometric>=2.5; extra == "models"
Requires-Dist: esm==3.2.1.post1; extra == "models"
Requires-Dist: transformers<4.48.2,>=4.38; extra == "models"
Requires-Dist: numpy<2,>=1.26; (sys_platform == "darwin" and platform_machine == "x86_64") and extra == "models"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: POT>=0.9; extra == "dev"
Requires-Dist: catboost>=1.2; extra == "dev"
Dynamic: license-file

# TopoPPI Affinity

TopoPPI Affinity adds affinity modelling and linked interface review to [TopoPPI](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/README.md). It extracts native interface descriptors and includes CPU models for binding affinity (pKd) and mutation effects (ΔΔG). Users can fit regression models to supplied data or load custom models, then review saved predictions alongside the corresponding residues and contacts.

## Installation

Install TopoPPI Affinity from PyPI with Python 3.10.

```sh
python -m pip install topoppi-affinity
```

For development, install Core, the plugin and its test dependencies from the repository root.

```sh
python -m pip install -e . -e './plugins/affinity[dev]'
```

The optional `models` extra supplies neural representation dependencies. Install it when using a model that requires them. Tk is required for the optional GUI. OptCuts is required for atlas generation. Native geometry and prediction run independently of atlas generation.

## Platform capability

Installation registers `affinity.predict`, `topoppi affinity ...`, and the
optional GUI integration through `topoppi.plugins`. Model dependencies load when
needed for prediction. New analyses can share a Core geometry object:

```python
import topoppi

geometry = topoppi.compute_geometry(
    topoppi.get_interface(topoppi.load_structure("complex.pdb"), "A", "B")
)
result = topoppi.run("affinity.predict", geometry, task="absolute", output="results")
```

The capability reuses selected atoms and native surfaces without reopening the
input. `workflow.analyze` and the standalone CLI also accept structure paths.
Namespaced defaults use `ExecutionContext.plugin_config["affinity"]`; explicit
arguments take precedence.

The Core GUI lists **Binding affinity** and **Mutation effects** in the shared
**Binding analysis** navigation, alongside Hotspot ranking when that plugin is
installed. The prediction panel has two scientific tasks: whole-complex pKd and
mutation ΔΔG. Keep **Prepared task model** to use the bundled physical model.
Advanced known/unseen ensembles retain their separately documented training
scope; **Local model file** selects a compatible custom estimator.

Selecting a local model reads its target and declared scope. A later task or
scope mismatch is reported before computation. Variant drafts remain available
when switching tasks; absolute-affinity prediction uses the unmodified complex.
Selected interface residues can be sent to the mutation editor as separate
single-substitution variants or one variant containing multiple substitutions.
Adding variants appends rows, retains existing edits and resolves duplicate row
identifiers. An existing
draft for another structure or partner grouping must be switched explicitly.

Task UI and resource setup live in `topoppi_affinity.integration` and
`topoppi_affinity.installer`. The old `topoppi-install-affinity` command is a
deprecated forwarding adapter and requires the plugin to be installed first.

## Synthetic quick start

This example converts a dissociation constant to pKd and back:

```python
from topoppi_affinity.thermodynamics import kd_to_pkd, pkd_to_kd

assert float(kd_to_pkd(1e-8)) == 8.0
assert float(pkd_to_kd(8.0)) == 1e-8
```

The `examples/tiny_complex.pdb` fixture contains independently constructed toy coordinates. Its variant CSV exercises alternative substitutions, a variant containing multiple substitutions and an absent residue. Use it to check input handling and row-error reporting.

## Structure example and prediction

The installed example contains the documented [PDB 1BVK structure](https://www.rcsb.org/structure/1BVK) and example variants. It illustrates the antibody–lysozyme interface. Export it with:

```sh
topoppi-affinity example --output affinity-demo
```

Analyze it with the bundled affinity model:

```sh
topoppi-affinity analyze --structure affinity-demo/1bvk.pdb \
  --chains-a A,B --chains-b C --task absolute \
  --output affinity-demo/results
topoppi-affinity inspect affinity-demo/results
topoppi-affinity gui affinity-demo/results
```

The plugin contains one default model per task, including fitted preprocessing
and feature definitions. For mutation effects, use `--task mutation` and provide
`--mutations` or `--variants`. Default prediction runs on CPU without model
downloads. See [models](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/models.md) and the [workflow](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/workflow.md).

## Inputs and outputs

Supply PDB or mmCIF structures and complete partner chain groups. Mutation input uses `variant_id,mutations` CSV records or structured residue fields. Affinity targets are pKd or mutation ΔΔG in kcal/mol; positive ΔΔG means weaker binding. Temperature is in kelvin and the dissociation constant Kd is in molar units.

Saved analyses contain a JSON report, prediction tables, the native interface and any requested layout results. Prediction rows retain their identifiers, status and error messages. The report records model scope and separate prediction/layout status. Models determine their feature requirements and applicability; review their training metadata before interpreting predictions.

Run `topoppi-affinity --help` for CLI commands. See the [workflow guide](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/workflow.md), [model interfaces](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/models.md), [evaluation primitives](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/evaluation.md), [feature tools](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/tools/README.md) and [test instructions](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/tests/README.md).

## Contributing

Use independently constructed fixtures for unit tests, preserve target units and row identities, and add coverage for changed public behavior. Run the affinity test suite together with affected core tests. Public interfaces are listed in the [API guide](https://github.com/GeraltZeroZhong/TopoPPI/blob/HEAD/plugins/affinity/docs/api.md).
