-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 namedrappé_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.
- Create a new directory
-
Phase 2: Implement Parameter Loading Logic
- In
src/params/mod.rs:- Add
tomlandserdewith thederivefeature as dependencies inCargo.toml. - Implement the
Parameters::load_from_str(toml_str: &str)method. It should usetoml::from_strand correctly map thetoml::de::Errorto ourCheqError::DeserializationError. - Implement the
Parameters::load_from_file(path: &Path)method. It should read the file to a string and then callload_from_str. It must correctly handle I/O errors and map them toCheqError::IoError, including the file path for context.
- Add
- Unit Tests:
- Create a
testssubmodule insrc/params/mod.rs. - Write a test for
load_from_strusing a string literal to verify correct parsing. - Write a test that creates a temporary TOML file (using
tempfilecrate or similar), writes some data to it, and then verifies thatload_from_filecan read it successfully. - Write tests for failure cases: malformed TOML, non-existent file path, and invalid element keys (e.g., "Xx").
- Create a
- In
-
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 ofdata/rappé_goddard_1991.tomlinto the compiled library at compile time. - Pass this string to
Parameters::load_from_strto parse and return the defaultParametersinstance.
- Create a new public function
- Unit Test:
- In the
testsmodule ofsrc/lib.rs, add a test forload_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 thatparams.elements.get(&6).is_some()for Carbon).
- In the
- In
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancement ✨New feature or requestNew feature or request
Type
Projects
Status
Done