How prasanna163/nciforge works
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: nci_torch/pipeline.py Torch NCI · knf_vector.py KNF vector · knf_core/pipeline.py Pipeline · xtb.py xTB
Components 21
CLI & orchestration
User entrypoints, command dispatch, and execution coordination
- CLI · Main command parser and pipeline dispatcher
knf_core/main.py - Pipeline · Batch execution, resume, and run coordination
knf_core/pipeline.py - Bootstrap · Initial setup and environment preparation
knf_core/first_run.py - Config · Runtime configuration and automatic environment detection
knf_core/autoconfig.py
Input prep
Format handling, geometry normalization, and xTB bridge
- Convert · Input file handling and structure conversion
knf_core/converter.py - Geometry · Geometry normalization and molecule preparation
knf_core/geometry.py - Wrapper · Isolates external command execution
knf_core/wrapper.py - xTB · xTB preprocessing, optimization, and topology outputs
knf_core/xtb.py - Utils · Shared repository-wide utilities
knf_core/utils.py
NCI engines
Backend-specific non-covalent interaction computation paths
- Multiwfn · Multiwfn-backed NCI workflow
knf_core/multiwfn.py - Torch NCI · Torch-based NCI subsystem entry
knf_core/nci_torch/pipeline.py - Engine · Core Torch NCI computation engine
knf_core/nci_torch/engine.py - Grid · NCI grid generation and sampling
knf_core/nci_torch/grid.py - Molden · Molden input handling for Torch NCI
knf_core/nci_torch/molden.py
Descriptors
Scientific post-processing into KNF, SNCI, and SCDI outputs
- KNF vector · Canonical KNF feature vector extraction
knf_core/knf_vector.py - SNCI · SNCI scalar metric computation
knf_core/snci.py - SCDI · SCDI scalar metric computation
knf_core/scdi.py
Identity & export
KUID classification, indexing, and artifact generation
Connections 22
- 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