# prasanna163/nciforge architecture

> Architecture diagram of the GitHub repository prasanna163/nciforge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prasanna163/nciforge
- Repository: https://github.com/prasanna163/nciforge

## Overview

1. **What this repo is**
   NCIForge is a Python CLI pipeline for turning molecular structure files into non-covalent interaction descriptors and identifiers. The core output is a KNF feature vector (`f1..f9`), plus SNCI/SCDI metrics and two identifier layers: `KUID` and `KUID-Intensive`.

2. **Primary runtime boundary**
   The package is mostly an orchestration layer. It delegates heavy chemistry work to external tools in `PATH`:
   - `xtb` for molecular preprocessing/optimization/topology
   - `obabel` for structure conversion
   - `Multiwfn` only for the legacy/alternate NCI backend
   - optional `torch` for the accelerated NCI backend

3. **Entry points and CLI shape**
   The main user-facing entry point is the `nciforge` CLI, with a compatibility alias `knf`. The entry module in `knf_core/main.py` drives command parsing and dispatch into the pipeline. The repo supports single-file execution, batch directories, multiprocessing, GPU mode, universal KUID recomputation, and atlas bundle generation.

4. **High-level processing flow**
   The architecture is a staged pipeline:
   molecular input → format/geometry normalization → xTB preprocessing → NCI grid evaluation → KNF/SNCI/SCDI post-processing → KUID/KUID-Intensive classification → export of per-molecule and batch artifacts.

5. **Input normalization and geometry layer**
   `converter.py`, `geometry.py`, `utils.py`, and `wrapper.py` form the front end for file handling and structure normalization. These modules likely absorb heterogeneous input formats, prepare molecule metadata, and isolate shell-command integration from the rest of the code.

6. **xTB integration**
   `xtb.py` is the bridge to xTB and appears to own the molecule-level preprocessing result files such as optimized structures and topology outputs. The benchmark folders show artifacts like `xtbtopo.mol` and `.xtboptok`, which indicates xTB is a required early stage before descriptor extraction.

7. **NCI computation backends**
   There are two distinct NCI execution paths:
   - `knf_core/multiwfn.py` for the Multiwfn-backed workflow
   - `knf_core/nci_torch/` for the Torch backend
   The Torch package is a separate subsystem with its own engine, grid generation, Molden handling, pipeline, export, and types. This suggests the repo cleanly separates the NCI numerical engine from the KNF/KUID business logic.

8. **Descriptor and metric post-processing**
   The descriptor layer lives in `knf_vector.py`, `scdi.py`, and `snci.py`. This is where raw NCI outputs are transformed into the canonical KNF feature vector and the related scalar metrics. These are the scientific outputs that downstream indexing and bundle generation consume.

9. **KUID classification and indexing**
   `kuid.py`, `kuid_index.py`, and `kuid_intensive.py` implement the identifier system. The repo distinguishes instance-level identity from topology-family identity, then builds supporting lookup structures such as prefix indexes, reverse indexes, bridge mappings, and family statistics. This is a separate subsystem from raw descriptor computation.

10. **Batch aggregation and reproducibility**
    `pipeline.py` and `first_run.py` appear to manage batch execution, incremental resume, calibration, and first-run setup. The README’s “incremental resume” and “universal KUID” behavior indicate that batch outputs are not just dumped files; they are reused as cached computation inputs for later normalization and recomputation.

11. **Exported artifacts and data products**
    Outputs are centered around JSON and CSV, with a few PNG and NPZ artifacts for analysis/benchmarking. Single runs emit molecule-level `knf.json` and calibration files; batch runs emit unified tables and several indexing files; atlas mode produces a compact `submission_bundle` with a manifest and canonical CSV. The repository also includes result directories under `nci_compare/` and `test-4/`, which are reference/benchmark artifacts rather than runtime code.

12. **Operational packaging**
    The repo is packaged as a Python project with Docker support. `Dockerfile`, `docker-compose.yml`, `README.DOCKER.md`, and `scripts/docker-entrypoint.sh` show that the system can be run in containerized environments, which matters because the runtime depends on external binaries and optionally GPU-enabled PyTorch.

13. **Comparison and validation tooling**
    `scripts/compare_nci.py` and the `nci_compare/` tree support benchmarking and backend comparison. These assets imply the architecture is not only a production pipeline but also a validation harness for checking speed/accuracy tradeoffs across xTB, Multiwfn, and Torch-backed NCI paths.

14. **Diagramming boundary suggestion**
    For an architecture diagram, the main boxes should be:
    - CLI / orchestration
    - structure preprocessing and xTB
    - NCI backend selector (Multiwfn or Torch)
    - KNF/SNCI/SCDI feature extraction
    - KUID indexing and calibration
    - export/bundle generation
    - external tools/runtime dependencies

Main entry points: [`knf_core/nci_torch/pipeline.py`](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/pipeline.py) (Torch NCI), [`knf_core/knf_vector.py`](https://github.com/prasanna163/nciforge/blob/main/knf_core/knf_vector.py) (KNF vector), [`knf_core/pipeline.py`](https://github.com/prasanna163/nciforge/blob/main/knf_core/pipeline.py) (Pipeline), [`knf_core/xtb.py`](https://github.com/prasanna163/nciforge/blob/main/knf_core/xtb.py) (xTB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_cli["CLI & orchestration"]
  node_main["CLI<br/>entrypoint<br/>[main.py]"]
  node_pipeline["Pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_first_run["Bootstrap<br/>setup<br/>[first_run.py]"]
  node_autoconfig["Config<br/>[autoconfig.py]"]
end

subgraph group_group_pre["Input prep"]
  node_converter["Convert<br/>input normalizer<br/>[converter.py]"]
  node_geometry["Geometry<br/>structure prep<br/>[geometry.py]"]
  node_wrapper["Wrapper<br/>shell bridge<br/>[wrapper.py]"]
  node_xtb["xTB<br/>preprocessing bridge<br/>[xtb.py]"]
  node_utils["Utils<br/>shared helpers<br/>[utils.py]"]
end

subgraph group_group_nci["NCI engines"]
  node_multiwfn["Multiwfn<br/>legacy backend<br/>[multiwfn.py]"]
  node_torch_pipeline["Torch NCI<br/>accelerated backend<br/>[pipeline.py]"]
  node_torch_engine["Engine<br/>numeric kernel<br/>[engine.py]"]
  node_torch_grid["Grid<br/>[grid.py]"]
  node_torch_molden["Molden<br/>file adapter<br/>[molden.py]"]
end

subgraph group_group_desc["Descriptors"]
  node_knf_vector["KNF vector<br/>descriptor<br/>[knf_vector.py]"]
  node_snci(("SNCI<br/>metric<br/>[snci.py]"))
  node_scdi(("SCDI<br/>metric<br/>[scdi.py]"))
end

subgraph group_group_ids["Identity & export"]
  node_kuid["KUID<br/>identity<br/>[kuid.py]"]
  node_kuid_index[("Index<br/>[kuid_index.py]")]
  node_kuid_intensive["Intensive<br/>family id<br/>[kuid_intensive.py]"]
  node_nci_export["Export<br/>artifact writer<br/>[export.py]"]
end

node_main -->|"load config"| node_autoconfig
node_main -->|"dispatch"| node_pipeline
node_pipeline -->|"prepare inputs"| node_converter
node_converter -->|"normalize structure"| node_geometry
node_geometry -->|"run commands"| node_wrapper
node_wrapper -->|"call xTB"| node_xtb
node_xtb -->|"legacy NCI"| node_multiwfn
node_xtb -->|"torch NCI"| node_torch_pipeline
node_torch_pipeline -->|"compute"| node_torch_engine
node_torch_pipeline -->|"build grid"| node_torch_grid
node_torch_pipeline -->|"read molden"| node_torch_molden
node_multiwfn -->|"derive vector"| node_knf_vector
node_torch_pipeline -->|"derive vector"| node_knf_vector
node_knf_vector -->|"compute"| node_snci
node_knf_vector -->|"compute"| node_scdi
node_knf_vector -->|"classify"| node_kuid
node_kuid -->|"index"| node_kuid_index
node_kuid -->|"family map"| node_kuid_intensive
node_kuid_intensive -->|"lookup support"| node_kuid_index
node_torch_pipeline -->|"export"| node_nci_export
node_pipeline -->|"shared helpers"| node_utils
node_pipeline -->|"bootstrap"| node_first_run

click node_main "https://github.com/prasanna163/nciforge/blob/main/knf_core/main.py"
click node_pipeline "https://github.com/prasanna163/nciforge/blob/main/knf_core/pipeline.py"
click node_first_run "https://github.com/prasanna163/nciforge/blob/main/knf_core/first_run.py"
click node_autoconfig "https://github.com/prasanna163/nciforge/blob/main/knf_core/autoconfig.py"
click node_converter "https://github.com/prasanna163/nciforge/blob/main/knf_core/converter.py"
click node_geometry "https://github.com/prasanna163/nciforge/blob/main/knf_core/geometry.py"
click node_wrapper "https://github.com/prasanna163/nciforge/blob/main/knf_core/wrapper.py"
click node_xtb "https://github.com/prasanna163/nciforge/blob/main/knf_core/xtb.py"
click node_multiwfn "https://github.com/prasanna163/nciforge/blob/main/knf_core/multiwfn.py"
click node_torch_pipeline "https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/pipeline.py"
click node_torch_engine "https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/engine.py"
click node_torch_grid "https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/grid.py"
click node_torch_molden "https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/molden.py"
click node_knf_vector "https://github.com/prasanna163/nciforge/blob/main/knf_core/knf_vector.py"
click node_snci "https://github.com/prasanna163/nciforge/blob/main/knf_core/snci.py"
click node_scdi "https://github.com/prasanna163/nciforge/blob/main/knf_core/scdi.py"
click node_kuid "https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid.py"
click node_kuid_index "https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid_index.py"
click node_kuid_intensive "https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid_intensive.py"
click node_nci_export "https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/export.py"
click node_utils "https://github.com/prasanna163/nciforge/blob/main/knf_core/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_pipeline,node_first_run,node_autoconfig toneBlue
class node_converter,node_geometry,node_wrapper,node_xtb,node_utils toneAmber
class node_multiwfn,node_torch_pipeline,node_torch_engine,node_torch_grid,node_torch_molden toneMint
class node_knf_vector,node_snci,node_scdi toneRose
class node_kuid,node_kuid_index,node_kuid_intensive,node_nci_export toneIndigo
```

## Components

### CLI & orchestration

User entrypoints, command dispatch, and execution coordination

- [CLI](https://github.com/prasanna163/nciforge/blob/main/knf_core/main.py): entrypoint · Main command parser and pipeline dispatcher · `knf_core/main.py`
- [Pipeline](https://github.com/prasanna163/nciforge/blob/main/knf_core/pipeline.py): orchestrator · Batch execution, resume, and run coordination · `knf_core/pipeline.py`
- [Bootstrap](https://github.com/prasanna163/nciforge/blob/main/knf_core/first_run.py): setup · Initial setup and environment preparation · `knf_core/first_run.py`
- [Config](https://github.com/prasanna163/nciforge/blob/main/knf_core/autoconfig.py): configuration · Runtime configuration and automatic environment detection · `knf_core/autoconfig.py`

### Input prep

Format handling, geometry normalization, and xTB bridge

- [Convert](https://github.com/prasanna163/nciforge/blob/main/knf_core/converter.py): input normalizer · Input file handling and structure conversion · `knf_core/converter.py`
- [Geometry](https://github.com/prasanna163/nciforge/blob/main/knf_core/geometry.py): structure prep · Geometry normalization and molecule preparation · `knf_core/geometry.py`
- [Wrapper](https://github.com/prasanna163/nciforge/blob/main/knf_core/wrapper.py): shell bridge · Isolates external command execution · `knf_core/wrapper.py`
- [xTB](https://github.com/prasanna163/nciforge/blob/main/knf_core/xtb.py): preprocessing bridge · xTB preprocessing, optimization, and topology outputs · `knf_core/xtb.py`
- [Utils](https://github.com/prasanna163/nciforge/blob/main/knf_core/utils.py): shared helpers · Shared repository-wide utilities · `knf_core/utils.py`

### NCI engines

Backend-specific non-covalent interaction computation paths

- [Multiwfn](https://github.com/prasanna163/nciforge/blob/main/knf_core/multiwfn.py): legacy backend · Multiwfn-backed NCI workflow · `knf_core/multiwfn.py`
- [Torch NCI](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/pipeline.py): accelerated backend · Torch-based NCI subsystem entry · `knf_core/nci_torch/pipeline.py`
- [Engine](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/engine.py): numeric kernel · Core Torch NCI computation engine · `knf_core/nci_torch/engine.py`
- [Grid](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/grid.py): grid builder · NCI grid generation and sampling · `knf_core/nci_torch/grid.py`
- [Molden](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/molden.py): file adapter · Molden input handling for Torch NCI · `knf_core/nci_torch/molden.py`

### Descriptors

Scientific post-processing into KNF, SNCI, and SCDI outputs

- [KNF vector](https://github.com/prasanna163/nciforge/blob/main/knf_core/knf_vector.py): descriptor · Canonical KNF feature vector extraction · `knf_core/knf_vector.py`
- [SNCI](https://github.com/prasanna163/nciforge/blob/main/knf_core/snci.py): metric · SNCI scalar metric computation · `knf_core/snci.py`
- [SCDI](https://github.com/prasanna163/nciforge/blob/main/knf_core/scdi.py): metric · SCDI scalar metric computation · `knf_core/scdi.py`

### Identity & export

KUID classification, indexing, and artifact generation

- [KUID](https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid.py): identity · Instance-level identifier classification · `knf_core/kuid.py`
- [Index](https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid_index.py): lookup index · Prefix, reverse, and family lookup structures · `knf_core/kuid_index.py`
- [Intensive](https://github.com/prasanna163/nciforge/blob/main/knf_core/kuid_intensive.py): family id · Topology-family identifier layer · `knf_core/kuid_intensive.py`
- [Export](https://github.com/prasanna163/nciforge/blob/main/knf_core/nci_torch/export.py): artifact writer · Torch-side result export and serialization · `knf_core/nci_torch/export.py`

## Connections

- CLI → Config: load config · Initializes runtime settings and environment detection
- CLI → Pipeline: dispatch · Hands parsed commands to orchestration
- Pipeline → Convert: prepare inputs · Normalizes input files and batch sources
- Convert → Geometry: normalize structure · Produces geometry-ready molecule state
- Geometry → Wrapper: run commands · Invokes shell-backed helpers safely
- Wrapper → xTB: call xTB · Routes preprocessing to xTB integration
- xTB → Multiwfn: legacy NCI · Feeds xTB-prepared structures into the Multiwfn path
- xTB → Torch NCI: torch NCI · Feeds xTB-prepared structures into the Torch backend
- Torch NCI → Engine: compute · Runs the numeric interaction engine
- Torch NCI → Grid: build grid · Creates NCI sampling grids
- Torch NCI → Molden: read molden · Consumes Molden-formatted orbital/geometry data
- Multiwfn → KNF vector: derive vector · Transforms raw NCI output into KNF features
- Torch NCI → KNF vector: derive vector · Transforms Torch NCI output into KNF features
- KNF vector → SNCI: compute · Produces SNCI metrics from the descriptor set
- KNF vector → SCDI: compute · Produces SCDI metrics from the descriptor set
- KNF vector → KUID: classify · Maps descriptors to instance identifiers
- KUID → Index: index · Builds lookup and reverse-index structures
- KUID → Intensive: family map · Derives topology-family identity layer
- Intensive → Index: lookup support · Uses indexes and bridge mappings for family classification
- Torch NCI → Export: export · Writes Torch-side artifacts and serialized outputs
- Pipeline → Utils: shared helpers · Uses common utility functions across stages
- Pipeline → Bootstrap: bootstrap · Handles first-run initialization and setup
