How chython/chytorch works
Project type and purpose
• This is a Python machine-learning library (no UI) for modeling molecules and reactions in a “torch” way. It provides:
• Neural modules (e.g., MoleculeEncoder, ReactionEncoder, LoRA layers, Voting classifiers).
• Data utilities (datasets, collate functions, LMDB mapping, SMILES parsing).
• A light “models zoo” interface.
• There is no “frontend” or web layer—this is a pure library for researchers and developers.
File structure
• Top-level:
• build.py, pyproject.toml: build and packaging scripts.
• chytorch/: the core library.
• examples/: usage examples.
• .github/workflows: CI for packaging/tests.
• Under chytorch/:
• nn/: all neural-network components grouped further by purpose (transformer, lora, molecule, reaction, voting, losses, slicer).
• utils/: data-handling layers (datasets, collate, LMDB, SMILES, molecule unpacking, reaction encoding).
• zoo/: model-zoo interface (small README).
• No external services or microservices—pure library.
README for additional insights
• Core encoder: Graphormer-style MoleculeEncoder built on torch.nn.TransformerEncoder.
• Data pipeline: MoleculeDataset, SMILESDataset, collate functions.
• Voting interfaces for ensembling.
• Dependencies implicitly include PyTorch, chython (for MoleculeContainer), RDKit (optional), LMDB.
a. Main components:
1. Data Ingestion Layer (chytorch.utils.data):
• SMILESDataset
• MoleculeDataset
• LMDBMapper
• collate functions
2. Neural Network Layer (chytorch.nn):
• MoleculeEncoder (Graphormer)
• ReactionEncoder
• LoRA adapters (linear, embedding)
• Slicer
• VotingClassifier / Regressor
• Loss functions
3. External Dependencies:
• PyTorch
• chython (MoleculeContainer, ReactionContainer)
• RDKit (for molecule handling, optional)
• LMDB (for storage)
4. Packaging & CI:
• build.py / pyproject.toml
• GitHub workflows
b. Relationships & interactions:
• User code or examples → instantiate SMILESDataset/MoleculeDataset → DataLoader
• DataLoader + collate → Batch tensor input → MoleculeEncoder/ReactionEncoder → tensor outputs
• Outputs → optional Voting modules for ensemble predictions
• Losses computed → optimizer/backprop via PyTorch
• Model parameters saved/loaded via standard torch API
• Packaging layer wraps library for pip install; CI ensures tests/builds succeed
c. Architectural patterns / design principles:
• Modular layering: data layer separated from network layer
• Pluggable adapters (LoRA), plug-and-play encoder stacks
• Dataset and collate functions follow torch.utils.data interfaces
• Ensemble (Voting) pattern for predictions
• Build & test automation via GitHub Actions
d. Key technologies & frameworks:
• Python 3
• PyTorch (core ML)
• Cython (unpacking modules .pyx)
• LMDB (data storage)
• RDKit (chemistry toolkit)
• chython (molecule representation)
Detailed architectural elements
• Package boundaries: utils vs. nn vs. zoo
• Subcomponents: transformer.attention → Graphormer, lora modules, molecule encoders
• Data containers (MoleculeContainer) entry point
• Collate functions bridging raw containers to tensor batches
• Voting heads as parallel branches after core encoder