option to import component properties from chemicals database#337
option to import component properties from chemicals database#337EvenSol wants to merge 12 commits intoequinor:masterfrom
Conversation
…-database Add chemicals-based extended component database option
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to import component properties from the chemicals Python package when components are not found in the default NeqSim database. The implementation provides an optional extended database feature that leverages the chemicals library for critical properties (Tc, Pc, omega) lookup.
- Introduces a new
useExtendedDatabase()method on thermodynamic systems to enable fallback to the chemicals database - Modifies
addComponent()to automatically fetch properties from chemicals when extended database is enabled and component is not in NeqSim's database - Adds the chemicals package as an optional dependency with a new "extended-database" extra
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_extended_database.py | Adds test verifying extended database allows adding missing components with correct properties from chemicals |
| src/neqsim/thermo/thermoTools.py | Implements extended database provider, system interface extension, and modified addComponent logic |
| pyproject.toml | Adds chemicals as optional dependency under new "extended-database" extra |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/neqsim/thermo/thermoTools.py
Outdated
| except Exception: # pragma: no cover - defensive alias resolution | ||
| pass | ||
|
|
||
| if getattr(thermoSystem, "_use_extended_database", False) and not jneqsim.util.database.NeqSimDataBase.hasComponent(alias_name): |
There was a problem hiding this comment.
[nitpick] This line exceeds reasonable length limits, making it harder to read. Consider extracting the extended database check into a helper function or breaking the condition into multiple lines with meaningful variable names like use_extended_db = getattr(thermoSystem, \"_use_extended_database\", False) and component_exists = jneqsim.util.database.NeqSimDataBase.hasComponent(alias_name).
| if getattr(thermoSystem, "_use_extended_database", False) and not jneqsim.util.database.NeqSimDataBase.hasComponent(alias_name): | |
| use_extended_db = getattr(thermoSystem, "_use_extended_database", False) | |
| component_missing = not jneqsim.util.database.NeqSimDataBase.hasComponent(alias_name) | |
| if use_extended_db and component_missing: |
src/neqsim/thermo/thermoTools.py
Outdated
| alias_name = name | ||
| try: | ||
| alias_name = jneqsim.thermo.component.Component.getComponentNameFromAlias(name) | ||
| except Exception: # pragma: no cover - defensive alias resolution |
There was a problem hiding this comment.
Catching bare Exception is too broad and may suppress unexpected errors. Consider catching a more specific exception type that getComponentNameFromAlias is expected to raise for unknown aliases.
| except Exception: # pragma: no cover - defensive alias resolution | |
| except (KeyError, ValueError, jpype.JException): # pragma: no cover - defensive alias resolution |
…-database-50j0qv Load additional properties from chemicals extended DB
…ython Add flake8 and isort pre-commit hooks
…ython-ch4r13 Require Python 3.8.1 or newer
Added a JPype implementation for SystemInterface.useExtendedDatabase, plus supporting helpers that pull critical data from the chemicals package whenever a component is absent from the built‑in NeqSim database.
Updated addComponent to fall back on the extended database for unknown species while preserving the existing paths for native components, restricting the extended lookup to mole-based additions.
Declared the optional chemicals dependency via a new Poetry extra so projects can opt into the extended database support.
Added a pytest that exercises the new extended database workflow by creating a fluid containing dimethylsulfoxide with chemicals-sourced data.