You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Description:
Completes the functionality of the
paramsmodule by implementing the logic to loadParametersfrom 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
data/.data/, create a new file namedrappé_goddard_1991.toml."6") and symbols (e.g.,"C") as keys in different entries to test our custom deserializer.Phase 2: Implement Parameter Loading Logic
src/params/mod.rs:tomlandserdewith thederivefeature as dependencies inCargo.toml.Parameters::load_from_str(toml_str: &str)method. It should usetoml::from_strand correctly map thetoml::de::Errorto ourCheqError::DeserializationError.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.testssubmodule insrc/params/mod.rs.load_from_strusing a string literal to verify correct parsing.tempfilecrate or similar), writes some data to it, and then verifies thatload_from_filecan read it successfully.Phase 3: Implement Default Parameter Loading
src/lib.rs:pub fn load_default_parameters() -> Result<Parameters, CheqError>.include_str!macro to embed the contents ofdata/rappé_goddard_1991.tomlinto the compiled library at compile time.Parameters::load_from_strto parse and return the defaultParametersinstance.testsmodule ofsrc/lib.rs, add a test forload_default_parameters.Ok, and verify that the loaded parameters contain expected elements (e.g., assert thatparams.elements.get(&6).is_some()for Carbon).