Skip to content

Add a parameter for selecting for calculating the charge methodulation - #8

Merged
gdmiron merged 40 commits into
masterfrom
charge_calculation
Dec 3, 2025
Merged

Add a parameter for selecting for calculating the charge methodulation#8
gdmiron merged 40 commits into
masterfrom
charge_calculation

Conversation

@sdmytrievs

Copy link
Copy Markdown
Contributor

Global default settings for calculating the charge method.
If get_charge_from_formula is false, calculate the charge based on the elements and their default
or specified valence; otherwise, take the charge based on the symbol in the given formula.

@sdmytrievs
sdmytrievs requested a review from gdmiron November 19, 2025 14:38
@sdmytrievs

Copy link
Copy Markdown
Contributor Author
  1. Added for C++ and Python API the properties function and dependent on it functions parameter for selection of type charge calculation:
/// Calculate charge, molar mass, elemental entropy, atoms per formula unit
 /// for chemical formulae.
 /// If use_formula_charge false, calculate the charge based on the elements and their default
 /// or specified valence; otherwise, take the charge based on the symbol in the given formula.
 FormulaProperties properties(const ElementsData& dbelements,
                                 bool use_formula_charge = charge_from_formula());
  1. Added global settings for the default type of charge calculation and set/get functions for changing it.
bool charge_from_formula();
void set_charge_from_formula(bool cond);
  1. Implemented tests for C++ and Python API

@gdmiron

gdmiron commented Nov 20, 2025

Copy link
Copy Markdown
Member

Is it possible to return false or some error/777777 if formula charge and charge from formula do not agree?

Please add example of formula charge to main readme.

@sdmytrievs

Copy link
Copy Markdown
Contributor Author
  1. Into the function properties, implemented an info message if a charge imbalance:
[chemicalfun] [info] In the formula: Am|3|(Oxa)3-3 calculated charge: 3.000000 != -3.000000
[chemicalfun] [info] In the formula: CaC2 calculated charge: 10.000000 != 0.0000000
  1. Changed implementation of the function testChargeImbalance. Now, it can return true if a charge imbalance is detected or throw an exception, depending on the second parameter.

@gdmiron

gdmiron commented Nov 24, 2025

Copy link
Copy Markdown
Member

I have checked the usage with:

Image

as you can see the token.charge() always returns the charge calculated base on valence.
Maybe we need this use_charge_from_formula at a level of setting the formula token. By default this is False.

@gdmiron
gdmiron merged commit 88d0879 into master Dec 3, 2025
4 checks passed
@gdmiron
gdmiron deleted the charge_calculation branch December 3, 2025 16:32
@gdmiron gdmiron linked an issue Dec 3, 2025 that may be closed by this pull request
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.

GEMS-T0012 Unintuitive charge calculation for some compounds

2 participants