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

Fix solvaion radical bug #1773

Merged
merged 3 commits into from
Nov 27, 2019
Merged

Fix solvaion radical bug #1773

merged 3 commits into from
Nov 27, 2019

Conversation

yunsiechung
Copy link
Contributor

@yunsiechung yunsiechung commented Oct 18, 2019

Motivation or Problem

Solvation correction for radical groups were not applied for radical species even if their radical groups were found in the solvation radical database.

Description of Changes

Before, when the radical solvation correction would apply, it applied the correction for each individual radical electron found by using such for loop:
for electron in range(1, atom.radical_electrons):
But this was wrong, because the range should start from 0, not 1. If the number of radical electron is 1, then the range is from (1,1), which doesn't really start the for loop at all.
I changed this for loop to:
for electron in range(atom.radical_electrons):
such that if the number of electron is 1, the range will be from [0, 1], making the correction to be applied once. Since the number of radical electrons are always 0 or positive integer, this change should be appropriate.

Testing

I also added a unit test in solvationTest.py, which checks whether the solvation radical group is found for the radical speices '[OH]' when calculating its solute data from group additivity method.

Reviewer Tips

fixes #1743

@yunsiechung yunsiechung requested a review from mliu49 October 18, 2019 19:20
@codecov
Copy link

codecov bot commented Oct 18, 2019

Codecov Report

Merging #1773 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1773   +/-   ##
=======================================
  Coverage   43.98%   43.98%           
=======================================
  Files          83       83           
  Lines       21581    21581           
  Branches     5653     5653           
=======================================
  Hits         9492     9492           
+ Misses      11043    11029   -14     
- Partials     1046     1060   +14
Impacted Files Coverage Δ
rmgpy/data/solvation.py 65.12% <100%> (ø) ⬆️
arkane/kinetics.py 12.14% <0%> (ø) ⬆️
rmgpy/data/statmech.py 42.2% <0%> (ø) ⬆️
rmgpy/rmg/pdep.py 12.21% <0%> (ø) ⬆️
rmgpy/data/kinetics/family.py 48.35% <0%> (ø) ⬆️
rmgpy/statmech/ndTorsions.py 59.78% <0%> (ø) ⬆️
rmgpy/yml.py 15.71% <0%> (ø) ⬆️
arkane/sensitivity.py 10% <0%> (ø) ⬆️
rmgpy/data/kinetics/database.py 50.61% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eac768...8e93013. Read the comment docs.

species = Species(molecule=[Molecule(smiles='[OH]')])
solute_data = self.database.get_solute_data_from_groups(species)
self.assertTrue('radical' in solute_data.comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought, should we add a test to check if we get the same (we shouldn't) Abraham solute parameters for OH radical and water? If we get the same values then we know something is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add that test. I will just add an additional test for checking whether their A parameters are different

@oscarwumit
Copy link
Contributor

Thanks for the PR. I add a minor comment.

@mliu49
Copy link
Contributor

mliu49 commented Nov 22, 2019

What's the status on this PR?

@yunsiechung
Copy link
Contributor Author

@mliu49 I'll make the change and force-push this PR again!!

@yunsiechung yunsiechung force-pushed the fix_solvaion_radical_bug branch from bc182fd to 5c007e7 Compare November 26, 2019 20:45
@yunsiechung
Copy link
Contributor Author

@oscarwumit I added another unittest that you suggested before. Could you review it and approve it if it's okay?

oscarwumit
oscarwumit previously approved these changes Nov 26, 2019
Copy link
Contributor

@oscarwumit oscarwumit left a comment

Choose a reason for hiding this comment

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

Tests look good. Thanks for the contribution :-)

Copy link
Contributor

@mliu49 mliu49 left a comment

Choose a reason for hiding this comment

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

I made two minor suggestions. Let me know what you think.

solvent_data = self.database.get_solvent_data('water')
rad_solvation_correction = self.database.get_solvation_correction(rad_solute_data, solvent_data)
sat_solvation_correction = self.database.get_solvation_correction(sat_solute_data, solvent_data)
self.assertNotEqual(rad_solvation_correction.gibbs / 1000, sat_solvation_correction.gibbs / 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to use assertNotAlmostEqual here since you're comparing (I assume) floats which have gone through some calculations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment! I applied this change

def test_radical_solute_group(self):
"""Test that the existing radical group is found for the radical species when using group additivity"""
# First check whether the radical group is found for the radical species
rad_species = Species(molecule=[Molecule(smiles='[OH]')])
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify this species creation to Species(smiles='[OH]').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I applied this change!

@mliu49
Copy link
Contributor

mliu49 commented Nov 27, 2019

Thanks! Could you rebase?

The solvation group additivty method had a bug that it cannot apply
radical correction to the radical species even if its radical group
exists in solvation radical database.
It was because originally, when it was applying correction for each
radical found, the for-loop range started from
range(1, number of radical), instead of starting from
range(0, number of radical). Because of that, if the number of radical
is 1, the correction was never applied.

This commits fixes this error by letting the range to be just
range(number of radical) since the number of radical is always integer
I added one more unit test in solvationTest.py to make sure that the
radical group is found for the radical species if its radical group
exists in the solvation radical database
Another uniitest is added to compare the radical and its saturated
species solvation free energy in water. The test makes sure the two
solvation energies are different.
@yunsiechung yunsiechung force-pushed the fix_solvaion_radical_bug branch from 7bddcb0 to 8e93013 Compare November 27, 2019 02:46
@yunsiechung
Copy link
Contributor Author

@mliu49 I just rebased and pushed again!

@mliu49 mliu49 merged commit 7e62adf into master Nov 27, 2019
@mliu49 mliu49 deleted the fix_solvaion_radical_bug branch November 27, 2019 15:36
@mliu49 mliu49 mentioned this pull request Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abraham GAV for estimating dG for radicals is malfunctioning
3 participants