NATAL Core Documentation
Numba-Accelerated Toolkit for Analysis of Lifecycles
NATAL Core is a high-performance forward-time population genetics simulation engine with configurable species lifecycles. It supports age-structured and discrete-generation populations, sperm storage, genetic presets, hook-based interventions, and Numba-accelerated simulation kernels. NATAL Core is especially suited for modeling gene drive systems in insect populations, but its flexible architecture also makes it applicable to a wide range of population genetics scenarios.
NATAL Core is part of the NATAL project. The full project also includes NATAL Inferencer, a toolkit for inferring population genetics model parameters based on NATAL Core.
Key Features
- πͺ² Forward-time simulation with flexible population lifecycles (age-structured and discrete-generation populations)
- 𧬠Definable genetic structures including chromosomes, loci, and alleles
- π Numba-accelerated computation core with excellent performance
- π§© Built-in gene drive presets, especially homing drive and toxin-antidote drive
- πͺ Hook system for inserting custom intervention logic during simulation
- π Observation and filtering tools for downstream analysis
- πΊοΈ Multi-deme (subpopulation) spatial simulation support
Installation
1. Create a Virtual Environment
It is strongly recommended to use a virtual environment to manage dependencies.
Please choose one of the following commands. Python 3.12 is recommended, but any Python version >= 3.9 should work.
uv venv --python 3.12 .venv # uv (recommended)
python -m venv .venv # venv (please ensure Python >= 3.9)
conda create -n natal-env python=3.12 # conda
On Windows, you can run py -3.12 -m venv .venv to specify Python 3.12 as the interpreter for the virtual environment.
2. Activate the Virtual Environment
Linux / macOS:
Windows:
3. Install NATAL Core
A Minimal Example
import natal as nt
from natal.ui import launch
# 1. Define the species' genetic architecture
sp = nt.Species.from_dict(
name="TestSpecies",
structure={
"chr1": {"loc1": ["WT", "Dr", "R2", "R1"]}
},
gamete_labels=["default", "cas9_deposited"]
)
# 2. Define a drive using built-in presets
drive = nt.HomingDrive(
name="TestHoming",
drive_allele="Dr",
cas9_allele="Dr",
target_allele="WT",
resistance_allele="R2",
functional_resistance_allele="R1",
drive_conversion_rate=0.95,
late_germline_resistance_formation_rate=0.9,
functional_resistance_ratio=0.001,
embryo_resistance_formation_rate=0.0,
viability_scaling=1.0,
fecundity_scaling={"female": 0.0},
fecundity_mode="recessive",
cas9_deposition_glab="cas9_deposited"
)
# 3. Define a release event using hooks
@nt.hook(event="first", priority=0)
def release_drive_carriers():
return [
nt.Op.add(genotypes="WT|Dr", ages=1, sex="male", delta=500, when="tick == 10")
]
# 4. Build a random-mating population
pop = (nt.DiscreteGenerationPopulation
.setup(
species=sp,
name="TestPop",
stochastic=True
)
.initial_state(
individual_count={
"male": {"WT|WT": 50000}, "female": {"WT|WT": 50000}
}
)
.reproduction(
eggs_per_female=100
)
.competition(
low_density_growth_rate=6.0,
carrying_capacity=100000,
juvenile_growth_mode="concave"
)
.presets(drive).hooks(release_drive_carriers).build())
# 5. Launch the interactive WebUI and run the simulation
launch(pop)
For more ready-to-run examples, see the demos directory in the GitHub repository.
Documentation Index
It is recommended to start with Part 1 to get up to speed, then use Part 2 as a project-driven reference, and selectively read Parts 3 and 4 as needed.
Part 1: Quick Start
This section introduces the basic concepts and usage of NATAL Core, helping you get started quickly.
Part 2: Practical Components
This section introduces the main components of NATAL Core, which are the primary features used in daily work.
- Genetic Structures and Entities
- Population Initialization
- Random-Mating Population
- Genetic Presets Usage Guide
- Hook System
- Pattern Matching and Extensible Configuration
- Extracting Population Simulation Data
Part 3: Advanced Guide
This section introduces advanced features of NATAL Core, including spatial simulation and more custom configuration.
Part 4: Internal Implementation
This section introduces the underlying implementation mechanisms of NATAL Core that are not directly user-facing, helping you understand how NATAL Core works internally.
- IndexRegistry Indexing Mechanism
- PopulationState and PopulationConfig
- Simulation Kernels in Depth
- Numba Optimization Guide
- Observation History Recording Implementation
API Documentation
Links
- GitHub Repository: https://github.com/jyzhu-pointless/natal-core
- PyPI Package: https://pypi.org/project/natal-core/
License
This project is licensed under the MIT License.