Skip to content

Implement Parameter Loading and Provide Default Dataset #3

@TKanX

Description

@TKanX

Description:

Completes the functionality of the params module by implementing the logic to load Parameters from external TOML files and providing a default, built-in parameter set. This will make the library immediately usable for common elements without requiring users to create their own parameter files. The implementation will handle file I/O, TOML deserialization, and provide a user-friendly API for both custom and default parameter loading. This work builds directly upon the data structures defined in Issue #1.

Tasks:

  • Phase 1: Create the Default Parameter File

    • Create a new directory data/.
    • Inside data/, create a new file named rappé_goddard_1991.toml.
    • Populate the TOML file:
      • Add a file-level comment explaining the source of the parameters (Rappé & Goddard, J. Phys. Chem. 1991, 95, 3358-3363) and the units.
      • Transcribe the elemental data from Table I of the paper for a core set of elements (e.g., H, C, N, O, F, Si, P, S, Cl) into the TOML file.
      • Use both atomic numbers (e.g., "6") and symbols (e.g., "C") as keys in different entries to test our custom deserializer.
  • Phase 2: Implement Parameter Loading Logic

    • In src/params/mod.rs:
      • Add toml and serde with the derive feature as dependencies in Cargo.toml.
      • Implement the Parameters::load_from_str(toml_str: &str) method. It should use toml::from_str and correctly map the toml::de::Error to our CheqError::DeserializationError.
      • Implement the Parameters::load_from_file(path: &Path) method. It should read the file to a string and then call load_from_str. It must correctly handle I/O errors and map them to CheqError::IoError, including the file path for context.
    • Unit Tests:
      • Create a tests submodule in src/params/mod.rs.
      • Write a test for load_from_str using a string literal to verify correct parsing.
      • Write a test that creates a temporary TOML file (using tempfile crate or similar), writes some data to it, and then verifies that load_from_file can read it successfully.
      • Write tests for failure cases: malformed TOML, non-existent file path, and invalid element keys (e.g., "Xx").
  • Phase 3: Implement Default Parameter Loading

    • In src/lib.rs:
      • Create a new public function pub fn load_default_parameters() -> Result<Parameters, CheqError>.
      • Inside this function, use the include_str! macro to embed the contents of data/rappé_goddard_1991.toml into the compiled library at compile time.
      • Pass this string to Parameters::load_from_str to parse and return the default Parameters instance.
    • Unit Test:
      • In the tests module of src/lib.rs, add a test for load_default_parameters.
      • The test should call the function, assert that it returns Ok, and verify that the loaded parameters contain expected elements (e.g., assert that params.elements.get(&6).is_some() for Carbon).

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions