Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

feat(core): Implement Modular I/O Framework with BGF Support and Refactor Core Data Models#6

Merged
TKanX merged 34 commits intomainfrom
feature/5-implement-modular-io-framework-and-bgf-file-support
Jul 2, 2025
Merged

feat(core): Implement Modular I/O Framework with BGF Support and Refactor Core Data Models#6
TKanX merged 34 commits intomainfrom
feature/5-implement-modular-io-framework-and-bgf-file-support

Conversation

@TKanX
Copy link
Member

@TKanX TKanX commented Jul 2, 2025

Summary:

Implemented a modular I/O framework within scream-core to handle the reading and writing of molecular file formats, with BGF (.bgf) being the first supported format. This work introduces a generic MolecularFile trait for future expansion. A significant refactoring of the core data models was performed, including a redesigned Atom struct that uses bitflags for state and a more organized MolecularSystemBuilder. Error handling has also been improved by introducing custom error types with thiserror.

Changes:

  • Implemented Modular I/O Framework:

    • Created a new core::io module to house file format handlers.
    • Introduced a generic MolecularFile trait with methods for reading from and writing to readers/writers and file paths, ensuring a consistent API for all supported formats.
  • Added BGF File Support:

    • Implemented BgfFile as the first concrete implementation of the MolecularFile trait.
    • Reading: Parses ATOM, HETATM, and CONECT records from a BGF file, correctly identifying chain types (Protein, Water, Ligand) and building a MolecularSystem via the builder.
    • Writing: Capable of writing a MolecularSystem back into a valid BGF file format, including atom records and connectivity information.
    • Added a comprehensive test suite for BGF reading and writing logic.
  • Core Data Model Refactoring:

    • Redesigned Atom Struct:
      • The Element enum has been removed.
      • The Atom struct now contains more descriptive topological fields (res_name, res_id, chain_id) and SCREAM-specific parameters (flags, delta, vdw_radius, etc.).
    • Introduced AtomFlags:
      • Added an AtomFlags struct using the bitflags crate to efficiently manage boolean atom properties like IS_FIXED_ROLE and IS_VISIBLE_INTERACTION.
    • Enhanced MolecularSystemBuilder:
      • Moved the builder to its own module (core::models::builder) for better code organization.
      • Updated the builder to construct the new, more detailed Atom and MolecularSystem structures.
  • Dependency and Error Handling Improvements:

    • Added bitflags and thiserror as new dependencies to scream-core.
    • Implemented a custom BgfError enum using thiserror for clearer and more ergonomic error handling during file parsing.
    • Updated other error types (e.g., ParseChainTypeError) to use thiserror.

TKanX added 30 commits June 28, 2025 16:32
@TKanX TKanX requested a review from Copilot July 2, 2025 19:50
@TKanX TKanX self-assigned this Jul 2, 2025
@TKanX TKanX added the enhancement ✨ New feature or request label Jul 2, 2025
@TKanX TKanX linked an issue Jul 2, 2025 that may be closed by this pull request
14 tasks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a modular I/O framework with BGF file support in scream-core and refactors the core data models for better organization and extensibility.

  • Introduce MolecularFile trait and BgfFile reader/writer with custom BgfError and metadata.
  • Refactor Atom, use bitflags for AtomFlags, decouple MolecularSystemBuilder into its own module, and improve error types using thiserror.
  • Update MolecularSystem API by removing internal maps and adding mutable accessors.

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/core/models/topology.rs Added thiserror derive to ParseBondOrderError.
src/core/models/system.rs Removed lookup maps, use iterators for get_atom_by_serial and get_chain_by_id, added *_mut methods.
src/core/models/builder.rs New module for MolecularSystemBuilder, updated add_atom signature.
src/core/io/traits.rs New MolecularFile trait for unified file I/O.
src/core/io/bgf.rs Implemented BGF parsing/writing, error handling, and tests.
Cargo.toml Added bitflags and thiserror dependencies.
Comments suppressed due to low confidence (1)

crates/scream-core/src/core/io/bgf.rs:138

  • Footer lines are emitted before bond connectivity (CONECT) records, which may not match the expected BGF file structure; consider moving this block to after the connectivity loop.
        for line in &metadata.footer_lines {

@TKanX TKanX merged commit 9a9fa2e into main Jul 2, 2025
2 checks passed
@TKanX TKanX deleted the feature/5-implement-modular-io-framework-and-bgf-file-support branch July 2, 2025 21:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement ✨ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Modular I/O Framework and BGF File Support

2 participants