Skip to main content

Knot Recognition

Abstract

This project provides a scientific pipeline for knot recognition from images. It combines a ResNet-based CNN classifier with a structured, heuristic Gauss/PD extractor operating on skeletonized drawings. The repository is organized to support reproducible experiments, clear documentation, and future extensions.

Installation

pip install knot-recognition

Quickstart

knot --image /path/to/image.png --checkpoint ./checkpoints/best.pth --mapping mapping_example.csv

Optional symmetry-invariant feature extraction:

knot --image /path/to/image.png --checkpoint ./checkpoints/best.pth --mapping mapping_example.csv --features

Force a device:

knot --image /path/to/image.png --checkpoint ./checkpoints/best.pth --device cpu
knot-moves --image /path/to/image.png --overlay results/figures/moves_overlay.png

Diagram reducer + classifier (solver):

knot-solve --image /path/to/image.png --checkpoint ./checkpoints/best.pth --mapping mapping_example.csv

Training:

python -m knot_recognition.train --data-dir /path/to/data --outdir ./checkpoints --epochs 20 --batch 32 --lr 1e-3

Training on a specific device:

python -m knot_recognition.train --data-dir /path/to/data --device cuda

Protein Knot Pipeline (Stages 1–4)

Stage 1: Extract Cα backbones (KnotProt chains):

PYTHONPATH=./src python scripts/extract_knotprot_stage1.py \
  --pdb-dir data/knotprot/pdb \
  --out data/knotprot/backbones.npz \
  --manifest data/knotprot/backbones.csv

Stage 2: Projection + crossing detection

  • sample_viewpoints, project_polyline, detect_crossings

Stage 3: Gauss code from crossings

  • gauss_code_from_crossings

Stage 4: Hybrid ML classifier (projection image + Gauss embedding):

PYTHONPATH=./src python scripts/build_knotprot_hybrid_dataset.py \
  --viewpoints 32 --limit 20 --offset 0 --stride 3 --max-points 300 \
  --out data/knotprot/hybrid_dataset_part1.npz \
  --manifest data/knotprot/hybrid_manifest_part1.csv

PYTHONPATH=./src python scripts/merge_hybrid_parts.py \
  --out data/knotprot/hybrid_dataset.npz

python scripts/train_hybrid_classifier.py \
  --data data/knotprot/hybrid_dataset.npz \
  --out checkpoints/hybrid_classifier.pth \
  --epochs 2 --batch 64 --lr 1e-3

Project Structure

  • src/knot_recognition/: Core Python package (models, dataset, preprocessing, inference, Gauss/PD extraction).
  • docs/: Methods and reproducibility notes.
  • notebooks/: Exploratory analysis and ablations.
  • scripts/: Experiment drivers and automation helpers.
  • data/: Reserved for datasets and processed artifacts.
  • results/: Reserved for experiment outputs and figures.
  • raw_knot/: Legacy dataset location (kept for compatibility).
  • outputs/: Legacy outputs location (kept for compatibility).
  • tests/: Synthetic tests for Gauss/PD extraction.

Data Format

Folder-structured dataset:

data_root/
  3_1/
  4_1/

Each subfolder is a class label and contains images.

Methods (Summary)

get_resnet(num_classes=1000, pretrained=True, model_name="resnet18", freeze_backbone=False)

  • Skeleton graph -> spur pruning -> junction clustering -> graph simplification
  • Edge pairing at crossings -> curve traversal -> PD construction
  • Entry point: extract_gauss_code(skel, img_gray=None, cfg=None, return_debug=False)

Mapping CSV Schema

mapping_example.csv:

label,pd_code,gauss_code
3_1,"PD[ [1,2],[3,4] ]","1 -2 3"

Reproducibility

  • Documented environment and workflow notes are in docs/reproducibility.md.
  • Scientific documentation is in docs/scientific.md.
  • Use a clean virtual environment and pinned versions for formal experiments.

Tests

pytest -q

Citation

See CITATION.cff for citation metadata.

Usage

See USAGE.md for end-to-end examples.

Known Limitations

  • Chirality detection is heuristic and depends on how flips affect CNN confidence.
  • Gauss/PD extractor assumes clean, high-contrast drawings.
  • Over/under (sign) inference is not reliable from skeletons alone.

Metadata

Release files for knot-recognition 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for knot-recognition 0.1.0
File Size Uploaded Provenance Actions
knot_recognition-0.1.0.tar.gz 27.6 kB Without provenance Details for knot_recognition-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for knot-recognition 0.1.0
File Interpreter ABI Platform Actions
knot_recognition-0.1.0-py3-none-any.whl Python 3 none any Details for knot_recognition-0.1.0-py3-none-any.whl

Total release size: 54.8 kB

Release files / knot_recognition-0.1.0.tar.gz

Download URL knot_recognition-0.1.0.tar.gz
Size 27.6 kB
Tags Source
SHA-256 checksum
How to use checksums
abd96b1de45ab94eef49fb2ce5681f5fe5c1d8bf53aa4bbf55315d167356f9b5
BLAKE2b-256 checksum
How to use checksums
39450276dc3e79974834c46983f6a24baf88d558d1b3f3982e2d23a54caac9ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / knot_recognition-0.1.0-py3-none-any.whl

Download URL knot_recognition-0.1.0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17ee9014a0758d1d51cff5698b6e10b291cfd7b91d111ac870d308e30d707f7a
BLAKE2b-256 checksum
How to use checksums
d5dadfc2e48eaf6ae1004c1100687d543d7018ee5625c15fd69722794e98ad67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for knot-recognition 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page