Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

125 molar amount missing in solution #127

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

ka-sarthak
Copy link
Collaborator

@ka-sarthak ka-sarthak commented Dec 18, 2024

Resolves #125

Summary by Sourcery

Add 'amount_of_substance' to the SolutionComponent class and enhance mass calculation logic. Improve description formatting for concentration fields in MolarConcentration.

New Features:

  • Introduce 'amount_of_substance' as a new quantity in the SolutionComponent class, allowing automatic calculation if mass and molecular mass are available.

Enhancements:

  • Improve the description formatting for 'calculated_concentration' and 'measured_concentration' in the MolarConcentration class for better readability.
  • Enhance the mass calculation logic in the SolutionComponent class to automatically compute mass if volume and density or amount of substance and molecular mass are available.

@ka-sarthak ka-sarthak requested a review from schumannj December 18, 2024 13:32
@ka-sarthak ka-sarthak linked an issue Dec 18, 2024 that may be closed by this pull request
@ka-sarthak ka-sarthak self-assigned this Dec 18, 2024
Copy link

sourcery-ai bot commented Dec 18, 2024

Reviewer's Guide by Sourcery

This PR adds support for tracking the molar amount (amount of substance) of solution components and improves the calculation of molar concentrations. The implementation includes automatic calculation of mass and molar amounts based on available properties, and updates the concentration calculation to use the new amount_of_substance field directly.

Updated class diagram for SolutionComponent

classDiagram
    class SolutionComponent {
        +float mass
        +float density
        +float amount_of_substance
        +calculate_molar_concentration(volume: Quantity, logger: BoundLogger)
        +normalize(archive: EntryArchive, logger: BoundLogger)
    }
    class MolarConcentration {
        +float calculated_concentration
        +float measured_concentration
    }
    SolutionComponent --> MolarConcentration
    note for SolutionComponent "Added amount_of_substance attribute and updated methods for calculation."
Loading

File-Level Changes

Change Details Files
Added new amount_of_substance field to track molar quantities
  • Added new Quantity field with mole unit and appropriate metadata
  • Added description explaining automatic calculation from mass and molecular mass
src/nomad_material_processing/solution/general.py
Enhanced mass field documentation and calculation logic
  • Updated mass field description to explain automatic calculation scenarios
  • Added bidirectional calculation between mass and amount_of_substance
src/nomad_material_processing/solution/general.py
Improved molar concentration calculation
  • Simplified concentration calculation to use amount_of_substance directly
  • Removed dependency on _calculate_moles helper method for concentration calculation
src/nomad_material_processing/solution/general.py
Code formatting and documentation improvements
  • Reformatted multi-line string descriptions to use triple quotes consistently
  • Improved line wrapping for better readability
src/nomad_material_processing/solution/general.py

Assessment against linked issues

Issue Objective Addressed Explanation
#125 Add a quantity to store the molar amount (amount of substance) in a solution component

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ka-sarthak - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ka-sarthak
Copy link
Collaborator Author

@schumannj Can you check if it works as intended? You can pull this branch and create solution entries.

@schumannj
Copy link
Collaborator

Hi Sartak. I had a look at the code and it looks good so far. I will try out locally now.

@schumannj
Copy link
Collaborator

There is one thing I was wondering about, in how far things get overwritten, if an entry gets reprocessed and e.g. a single value, e.g. mass gets corrected. How does nomad figure out which quantities are written in person and what was calculated previously. Not entirely sure if that could be a problem. And probably not really related to this issue. I try to see if I can make an example.

@ka-sarthak
Copy link
Collaborator Author

I think NOMAD does not provide a way to keep track of what came from the user and what is written by the normalizer.

Every time the normalizer runs, self gives the current state (which usually contains data entered from the ELN). But it also might contain data from a previous normalization. Both of these data are indiscernible. You are right, this can be confusing. Ideally, quantities that are interactable should not have a lot of automation.

Currently mass and amount_of_substance can be changed by the normalizer. Do you think this can lead to confusion and we should remove some of the automation?

@schumannj
Copy link
Collaborator

I find this is a difficult question. and really depends on how it is used. Initially I was thinking of having nomad calculate the mass from a desired concentration/amount_of_substance and then correcting the mass accoring to the real value that was measured on the balance. But maybe this is to much overthinking. I guess the most important thing is for the community plugins to represent the final data for publishing.

@schumannj
Copy link
Collaborator

I just tested the branch. Looks in principle good. I noticed that when I create a solution with 1L of H2O and 1.5 mol NaCl, the mass of the total solution is only given as the mass of the solute.

@schumannj
Copy link
Collaborator

Ah I see, there is a warning in the logs, it is missing the mass, of course. should this rather be an error? so it flags up more visibly? But maybe not, once the density is picked up from pubchem it should be resolved anyway.

@ka-sarthak
Copy link
Collaborator Author

Yeah, thing is we are not getting density from the PubChem, so you have to supply either the mass, or both volume and density, to calculate the mass

@schumannj
Copy link
Collaborator

schumannj commented Dec 18, 2024

Oh why not? it is marked as a todo in the code. I thought this was planned.

Oh I guess there are too many different values to choose from.

@ka-sarthak
Copy link
Collaborator Author

Exactly, it depends on the external factors like temperature and pressure. So it's much safer to get this input from the user

@ka-sarthak
Copy link
Collaborator Author

Or they can simply add mass and volume. The final density of the solution will be computed based on these values for all the components.

@schumannj
Copy link
Collaborator

Makes sense. Then you can remove the line 171.
The default value of density is a bit strange. In the main solution section it is g/ml, which is more standard compared to 'gram/liter'. I wondered why my solution is so light, with a density of 1

@ka-sarthak
Copy link
Collaborator Author

I will make all the units for density to be g/ml as it seems to be the standard

@schumannj
Copy link
Collaborator

The options for the units of mass are very diverse, I have never seen all those crazy units, where are they suddenly coming from? has nomad.units been updated? but I cannot find mg or mikro gram. (Probably not an issue for here.)
I will approve the review. Looks good!

@ka-sarthak
Copy link
Collaborator Author

Ah yeah, there's a bunch of new empirical units. Like bag? No idea where they came from.

@ka-sarthak ka-sarthak merged commit e6ed114 into main Dec 19, 2024
5 checks passed
@ka-sarthak ka-sarthak deleted the 125-molar-amount-missing-in-solution branch December 19, 2024 08:53
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.

molar amount missing in solution
2 participants