Lazy Loading#
Lazy loading is a fundamental design principle in MolSysMT that defers reading heavy array data from disk or memory until it is explicitly requested by a calculation or query.
The Big Data Challenge#
Molecular system files and multi-frame structure datasets generated by simulation packages can occupy tens or hundreds of gigabytes. Traditional structural biology packages frequently attempt to parse and load entire coordinate arrays into RAM upon opening a file, leading to memory saturation, sluggish startup times, or out-of-memory crashes when working on workstations or laptops.
Metadata-First Initialization#
When opening a system file or initializing a supported native handler (such as file:h5msm), MolSysMT performs metadata-first initialization:
Topological Indexing: Atom names, residue groups, chains, and entity hierarchies are parsed and cached.
Structural Footprint: Total structure count, timestep intervals, and array dimensions
(n_structures, n_atoms, 3)are registered.Deferred Coordinates: Heavy 3D coordinate arrays remain on disk in optimized binary formats until required.
Streaming and On-Demand Fetching#
Because heavy arrays are accessed on demand, operations that only inspect topological metadata (such as counting atoms, filtering selections, or querying sequence identities) execute instantaneously with near-zero memory footprint.
Currently, native lazy loading and on-demand streaming are implemented for the file:h5msm format and native file handlers via streaming iterators (molsysmt.H5MSMFileHandler, molsysmt.TopologyIterator, and molsysmt.StructuresIterator).