Skip to content

option to import component properties from chemicals database#337

Closed
EvenSol wants to merge 12 commits intoequinor:masterfrom
EvenSol:master
Closed

option to import component properties from chemicals database#337
EvenSol wants to merge 12 commits intoequinor:masterfrom
EvenSol:master

Conversation

@EvenSol
Copy link
Collaborator

@EvenSol EvenSol commented Oct 26, 2025

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.

@EvenSol EvenSol requested a review from Copilot October 26, 2025 07:01
Copy link

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 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.

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):
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

[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).

Suggested change
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:

Copilot uses AI. Check for mistakes.
alias_name = name
try:
alias_name = jneqsim.thermo.component.Component.getComponentNameFromAlias(name)
except Exception: # pragma: no cover - defensive alias resolution
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
except Exception: # pragma: no cover - defensive alias resolution
except (KeyError, ValueError, jpype.JException): # pragma: no cover - defensive alias resolution

Copilot uses AI. Check for mistakes.
@EvenSol EvenSol closed this Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants