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

uncertainty quantification in energy corrections #1558

Merged
merged 222 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 180 commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
ab7cbda
added correction error to compatibility module with tests
awvio Aug 21, 2019
fdf0906
merge Amanda's correction work into new branch
rkingsbury Aug 29, 2019
c18d772
Reformat .yaml keys to match correction classes
rkingsbury Aug 30, 2019
bdee700
added CorrectionCalculator class, the json files of calc/exp entries,…
awvio Aug 30, 2019
6001f99
'merged
awvio Aug 30, 2019
e305f4c
merged format changes to yaml and made corresponding changes to Anion…
awvio Aug 30, 2019
92f8e52
added docstrings and type hints to CorrectionCalculator
awvio Sep 5, 2019
ba4e971
fixed defaultdict import, switched to plotly
awvio Sep 5, 2019
24b4c27
ran style checker
awvio Sep 6, 2019
4c149fd
manually fixed other style errors
awvio Sep 6, 2019
70722e3
changed json files containing exp/calc entries to gzip, removed no lo…
awvio Sep 7, 2019
15aea74
fixed new style errors
awvio Sep 7, 2019
74ce229
changed input filename back to MPCompatibility.yaml, changed tests ac…
awvio Sep 7, 2019
7e8d5aa
Remove polysulfide logic from sulfide_type()
rkingsbury Sep 10, 2019
17a2adb
Remove polysulfide logic from sulfide_type()
rkingsbury Sep 10, 2019
133be7a
fixed merge conflicts
awvio Sep 19, 2019
643ff2d
added plotly to requirements, added in type hints
awvio Sep 20, 2019
1e6ff0e
fixed style error
awvio Sep 20, 2019
f95b8bb
fixed imports from typing
awvio Sep 20, 2019
e87d34b
one more type annotation fix
awvio Sep 20, 2019
fa49b7f
deleted unused import and variable
awvio Sep 20, 2019
05e3032
Replace GasCorrection with AnionCorrection
rkingsbury Oct 2, 2019
5db95eb
added test for correction calculator
awvio Oct 2, 2019
1e1bc7a
fixed style errors
awvio Oct 2, 2019
3cd1422
Replace diatomic formulas with elements
rkingsbury Oct 2, 2019
3223ebc
Change corrections to account for new method
rkingsbury Oct 2, 2019
cc69b92
Recalculate the corrections
rkingsbury Oct 2, 2019
56fb1dd
Shift corrections to compounds rather than elements
rkingsbury Oct 2, 2019
3e12705
fixed typos, added tests for mp aqueous compatibility, print compatib…
awvio Oct 3, 2019
7d19415
attempt to fix mypy error
awvio Oct 3, 2019
14b4f63
added error value to explanation dict
awvio Oct 3, 2019
3aa1efe
Fix H2 correction
rkingsbury Oct 19, 2019
8188ff0
Flip the sign on the corrections
rkingsbury Oct 21, 2019
77632a0
Merge Amanda's master branch
rkingsbury Oct 23, 2019
a0775df
Add fitted H2 error
rkingsbury Oct 23, 2019
53f7853
Add fitted H2 to AnionCorrection
rkingsbury Oct 23, 2019
6ee95af
Remove GasCorrection heading
rkingsbury Oct 23, 2019
78f12fe
Rename AnionCorrection to CompositionCorrection
rkingsbury Oct 23, 2019
95c5123
Deeper renaming and add H2 fit to make_yaml
rkingsbury Oct 23, 2019
4fa38f5
rm GasCorrection from errors yaml
rkingsbury Oct 24, 2019
939034d
fix linting errors and remove unneeded lines
rkingsbury Oct 24, 2019
ffe2b34
more renames
rkingsbury Oct 24, 2019
ddd0d51
merged change to comp_corr, computedreaction now also calculates erro…
awvio Oct 24, 2019
13553cf
updated tests for hydrides
awvio Nov 7, 2019
d6d2bc1
Rename 'errors' to 'uncertainties'
rkingsbury Nov 5, 2019
5c69a2b
Scale correction_uncertainty via normalize()
rkingsbury Nov 5, 2019
f50a520
fix for renaming error to uncertainty
rkingsbury Nov 7, 2019
2816eb1
resolved conflict with upstream
awvio Nov 7, 2019
f29adb4
fixed style errors
awvio Nov 7, 2019
c3c4f39
fixed more style errors
awvio Nov 7, 2019
b833765
even more style errors
awvio Nov 8, 2019
b672c36
more style errors
awvio Nov 8, 2019
1789ebd
change correction/error to initialize to 0.0 for mypy type checking
awvio Nov 8, 2019
a3f44eb
remove unused variable, change error to uncertainty
awvio Nov 8, 2019
fbaf465
changed error to uncertainty in tests
awvio Nov 20, 2019
9c2a477
resolve upstream conflict with searchindex.js
awvio Nov 20, 2019
a516fde
added test for no uncertainties, added docstrings
awvio Nov 21, 2019
ffc8b84
fixed style errors in docstrings
awvio Nov 21, 2019
8943da4
moved docstring for pydocstyle
awvio Nov 21, 2019
c35061c
renamed new classes with 2020 suffix, added deprecation warnings to o…
awvio Dec 4, 2019
f3eaac8
added correction error to compatibility module with tests
awvio Aug 21, 2019
636edb3
merge Amanda's correction work into new branch
rkingsbury Aug 29, 2019
2c11691
Reformat .yaml keys to match correction classes
rkingsbury Aug 30, 2019
154798e
added CorrectionCalculator class, the json files of calc/exp entries,…
awvio Aug 30, 2019
ee9cf90
added docstrings and type hints to CorrectionCalculator
awvio Sep 5, 2019
d069055
fixed defaultdict import, switched to plotly
awvio Sep 5, 2019
f5ee309
ran style checker
awvio Sep 6, 2019
f2ffd13
manually fixed other style errors
awvio Sep 6, 2019
77cd7cc
changed json files containing exp/calc entries to gzip, removed no lo…
awvio Sep 7, 2019
3d1e74a
fixed new style errors
awvio Sep 7, 2019
d4d5dd3
changed input filename back to MPCompatibility.yaml, changed tests ac…
awvio Sep 7, 2019
db53f00
Remove polysulfide logic from sulfide_type()
rkingsbury Sep 10, 2019
620b6d9
added plotly to requirements, added in type hints
awvio Sep 20, 2019
08882fd
fixed style error
awvio Sep 20, 2019
ed0c063
fixed imports from typing
awvio Sep 20, 2019
efd08de
one more type annotation fix
awvio Sep 20, 2019
9e8bb64
deleted unused import and variable
awvio Sep 20, 2019
d9d9fbb
Replace GasCorrection with AnionCorrection
rkingsbury Oct 2, 2019
f147017
added test for correction calculator
awvio Oct 2, 2019
46143dc
fixed style errors
awvio Oct 2, 2019
ea64c06
Replace diatomic formulas with elements
rkingsbury Oct 2, 2019
9defaeb
Change corrections to account for new method
rkingsbury Oct 2, 2019
06a85dc
Recalculate the corrections
rkingsbury Oct 2, 2019
4ea3016
Shift corrections to compounds rather than elements
rkingsbury Oct 2, 2019
5d12048
fixed typos, added tests for mp aqueous compatibility, print compatib…
awvio Oct 3, 2019
996e146
attempt to fix mypy error
awvio Oct 3, 2019
ce13201
added error value to explanation dict
awvio Oct 3, 2019
6a8c752
Fix H2 correction
rkingsbury Oct 19, 2019
b13a8f2
Flip the sign on the corrections
rkingsbury Oct 21, 2019
b8cd491
Add fitted H2 error
rkingsbury Oct 23, 2019
1428f10
Add fitted H2 to AnionCorrection
rkingsbury Oct 23, 2019
859fdcd
Rename AnionCorrection to CompositionCorrection
rkingsbury Oct 23, 2019
d1e7d4e
Deeper renaming and add H2 fit to make_yaml
rkingsbury Oct 23, 2019
7292872
fix linting errors and remove unneeded lines
rkingsbury Oct 24, 2019
3f193f5
more renames
rkingsbury Oct 24, 2019
d173a35
merged change to comp_corr, computedreaction now also calculates erro…
awvio Oct 24, 2019
43bbbfb
updated tests for hydrides
awvio Nov 7, 2019
369580c
Rename 'errors' to 'uncertainties'
rkingsbury Nov 5, 2019
48c6424
Scale correction_uncertainty via normalize()
rkingsbury Nov 5, 2019
9709d5c
fix for renaming error to uncertainty
rkingsbury Nov 7, 2019
f83e52b
fixed style errors
awvio Nov 7, 2019
12967ca
fixed more style errors
awvio Nov 7, 2019
69e9083
even more style errors
awvio Nov 8, 2019
c63c332
more style errors
awvio Nov 8, 2019
9eb3c0a
remove unused variable, change error to uncertainty
awvio Nov 8, 2019
efd526a
changed error to uncertainty in tests
awvio Nov 20, 2019
282b7c8
added test for no uncertainties, added docstrings
awvio Nov 21, 2019
f09e08c
fixed style errors in docstrings
awvio Nov 21, 2019
e8c10d8
moved docstring for pydocstyle
awvio Nov 21, 2019
65b69d4
renamed new classes with 2020 suffix, added deprecation warnings to o…
awvio Dec 4, 2019
2e95bfa
rebased on upstream master
awvio Dec 5, 2019
e625a76
removed unused imports
awvio Dec 5, 2019
a3e432d
removed mitcompatibility2020 classes, yamls, and tests
awvio Dec 5, 2019
bd1bd59
removed copper correction and added tungsten correction/compounds
awvio Dec 23, 2019
73c7254
Merge branch 'master' into master
awvio Dec 23, 2019
3f6575f
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Dec 23, 2019
8393985
Merge branch 'master' into master
rkingsbury Jan 7, 2020
c075384
fixed signs of hydrides experimental energy
awvio Jan 23, 2020
37a10bc
Merge branch 'master' of https://github.com/awvio/pymatgen
awvio Jan 24, 2020
5bd45a8
updated magnetic orderings, removed MnSiO3 and WOF4
awvio Feb 14, 2020
945290a
updated tests for new corrections
awvio Feb 14, 2020
10732f2
changed no correction uncertainty value from float(nan) to np.nan
awvio Feb 19, 2020
e896037
Merge branch 'master' into master
rkingsbury Feb 20, 2020
c87c9fb
Merge branch 'master' into master
rkingsbury Mar 4, 2020
809b874
mostly finished with ufloats, need to add one more test
awvio Mar 6, 2020
3c72edc
fixed calc_compounds.gz to updated version
awvio Mar 6, 2020
e1516cd
fixed calc_compounds.gz to lowest energy entries, updated corrections
awvio Mar 7, 2020
425c5e8
update Aqueous corrections for MP2020
rkingsbury Mar 7, 2020
40552ad
Merge pull request #2 from rkingsbury/newcorrections
rkingsbury Mar 7, 2020
ef53aef
fix H2O energy and update tests for refitted corrections
rkingsbury Mar 8, 2020
8753dc2
remove old aqueous corrections
rkingsbury Mar 8, 2020
0216023
Merge pull request #4 from rkingsbury/corrections-mp2020
rkingsbury Mar 8, 2020
07061c4
added test for nan rxn energy uncertainty
awvio Mar 9, 2020
2508dda
merged with upstream master
awvio Mar 9, 2020
18542a4
Merge branch 'uncertainties'
awvio Mar 9, 2020
3484924
added correction_uncertainty back to explanation_dict
awvio Mar 9, 2020
b2a2c57
minor adjustments to when uncertainty is set to nan
awvio Mar 9, 2020
47d7d1b
fixed style errors
awvio Mar 9, 2020
d7a216a
added uncertainties package to requirements.txt
awvio Mar 9, 2020
7bbe5e8
added uncertainties to list of imported modules for mypy to ignore in…
awvio Mar 9, 2020
5c0b7a9
removed unused imports
awvio Mar 9, 2020
a8bead5
moved module level docstring for pydocstyle
awvio Mar 9, 2020
b8132fb
update Pourbaix and AqueousCorrections for MP2020
rkingsbury Mar 10, 2020
2696396
update O2 energy for Aqueous fit
rkingsbury Apr 7, 2020
040390b
Merge branch 'master' into master
rkingsbury Apr 7, 2020
878ddcf
update test
rkingsbury Apr 7, 2020
2826bdb
Merge branch 'master' of https://github.com/awvio/pymatgen into corre…
rkingsbury Apr 7, 2020
f7e2e99
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Apr 14, 2020
d988d69
changed S to sulfide, crosschecked compounds with Hautier paper and c…
awvio Apr 14, 2020
7bbe344
fixed style
awvio Apr 14, 2020
0c53423
Merge branch 'master' of https://github.com/awvio/pymatgen
awvio Apr 14, 2020
762dfe3
Merge branch 'master' of https://github.com/awvio/pymatgen into corre…
rkingsbury Apr 14, 2020
ee48c90
update Aqueous for refitted mp2020
rkingsbury Apr 14, 2020
8b68a22
add warning for Pourbaix+Aqueous2020
rkingsbury Apr 14, 2020
109ab90
fix mypy + pytest complaining
rkingsbury Apr 14, 2020
a7c285a
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Apr 28, 2020
368c1de
merge with abstract compat
rkingsbury Apr 29, 2020
52ee7ad
Merge branch 'abstractcompat' into corrections
rkingsbury Apr 30, 2020
0caf06a
remove aqueous corr from yaml
rkingsbury Apr 30, 2020
85f965e
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury May 5, 2020
4b9afdf
integrate changes from #1826
rkingsbury May 5, 2020
45ac225
fix mypy errors
rkingsbury May 5, 2020
9f7342f
search calc dict by Composition(formula).reduced_formula for consiste…
awvio Jun 8, 2020
6a08d5c
merged with upstream master
awvio Jun 8, 2020
e3d1ade
removed extra whitespace
awvio Jun 8, 2020
f50954f
remove any corrections in calc_compounds
awvio Jun 9, 2020
897e83f
changed calc_compounds dicts keys to be consistent with Composition(f…
awvio Jun 9, 2020
85adc8a
add oxidation state check for anion corrections
rkingsbury Jun 16, 2020
e776f35
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Jun 16, 2020
9f7d357
refactor name for consistency w/other classes
rkingsbury Jun 17, 2020
e2a5e1e
db release changes
awvio Jun 20, 2020
3df58a2
performance-related oxi_state_guesses changes
rkingsbury Jun 22, 2020
13b9ead
updated how reaction_calculator accesses entry's correction_uncertainty
awvio Jun 22, 2020
5ecbf45
different approach to oxi state detection
rkingsbury Jun 29, 2020
b3acdb4
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Jun 29, 2020
b10ef57
fix ComputedReaction test
rkingsbury Jun 29, 2020
acf911e
linting
rkingsbury Jun 29, 2020
267082f
revert change to sulfide_type
rkingsbury Jul 9, 2020
d242aca
remove deprecation warnings from MIT classes
rkingsbury Jul 9, 2020
75404e3
remove deprecation tests for MIT
rkingsbury Jul 9, 2020
48a89f8
make fitting helper func private
rkingsbury Jul 14, 2020
aeb342b
added magnetic ordering to entry.data dict
awvio Jul 15, 2020
fd4b587
Merge branch 'master' of https://github.com/awvio/pymatgen
awvio Jul 15, 2020
83cb3df
reformatted correctioncalculator to pass permissions to init and entr…
awvio Jul 20, 2020
a5e8759
style fixes
awvio Jul 20, 2020
373c208
raise error with message to compute corrections first if other calcul…
awvio Jul 20, 2020
358922d
Merge branch 'master' of https://github.com/materialsproject/pymatgen
awvio Jul 20, 2020
84ca376
clarified CorrectionCalculator filters
awvio Jul 21, 2020
8348a72
reformatted comments to meet max character/line count
awvio Jul 21, 2020
111d322
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Jul 21, 2020
7ab454d
pylint fixes part 1
rkingsbury Jul 22, 2020
5af1277
pylint fixes part 2
rkingsbury Jul 22, 2020
32f7ee2
pycodestyle fixes
rkingsbury Jul 22, 2020
2fa1b77
pylint fix, CorrectionCalculator graph function returns fig
awvio Jul 22, 2020
878734b
test fixes; make uncertainty kwarg always
rkingsbury Jul 22, 2020
99fe7a7
remove pylint C0330 directive
rkingsbury Jul 22, 2020
f5f048d
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Jul 22, 2020
dfda9ef
add @staticmethod to explain
rkingsbury Jul 22, 2020
298ac4f
allow user to input species list
awvio Jul 24, 2020
2c97a94
pycodestyle fix, clarify .json.gz file in compute_from_files docstring
awvio Jul 24, 2020
19ea07f
allow_unstable can be bool or float, polyanions filtered based on use…
awvio Jul 25, 2020
9ae9d54
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Jul 30, 2020
155d2a5
missing import
rkingsbury Jul 30, 2020
e44e47f
change unknown uncertainties to np.nan instead of 0
awvio Jul 31, 2020
4c98554
pycodestyle split line with too many characters
awvio Jul 31, 2020
21d3349
pycodestyle indent
awvio Jul 31, 2020
8ffd207
pylint trailing whitespace
awvio Jul 31, 2020
2cd8073
fix merge problem
rkingsbury Aug 3, 2020
635414d
Fix typo
mkhorton Aug 3, 2020
9556fe1
revert sulfide_type docstring change
rkingsbury Aug 3, 2020
bb5543f
make kwargs more verbose
rkingsbury Aug 3, 2020
3467c57
label corrections kwarg in tests
rkingsbury Aug 3, 2020
c463246
lint docstring
rkingsbury Aug 3, 2020
255749c
Merge branch 'master' of https://github.com/awvio/pymatgen into corre…
rkingsbury Aug 3, 2020
c94963e
whitespace
rkingsbury Aug 3, 2020
3f7f475
Merge branch 'master' of https://github.com/awvio/pymatgen; branch 'm…
rkingsbury Aug 3, 2020
9e21a5e
replace .gz with .json.gz extension
rkingsbury Aug 4, 2020
9e75eaa
update file extension in test file
rkingsbury Aug 4, 2020
e03ad90
changed sulfide back to S
awvio Aug 7, 2020
eac0756
Merge branch 'master' of git://github.com/materialsproject/pymatgen i…
rkingsbury Aug 7, 2020
f24317b
Merge branch 'master' of https://github.com/awvio/pymatgen; branch 'm…
rkingsbury Aug 14, 2020
f83d344
rename corrections_calc.py
rkingsbury Aug 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ <h2 id="A">A</h2>
</li>
<li><a href="pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies.html#pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies.NormalizedAngleDistanceNbSetWeight.angninvndist">angninvndist() (NormalizedAngleDistanceNbSetWeight method)</a>
</li>
<li><a href="pymatgen.entries.compatibility.html#pymatgen.entries.compatibility.AnionCorrection">AnionCorrection (class in pymatgen.entries.compatibility)</a>
<li><a href="pymatgen.entries.compatibility.html#pymatgen.entries.compatibility.CompositionCorrection">CompositionCorrection (class in pymatgen.entries.compatibility)</a>
</li>
<li><a href="pymatgen.analysis.wulff.html#pymatgen.analysis.wulff.WulffShape.anisotropy">anisotropy() (WulffShape property)</a>
</li>
Expand Down
4 changes: 4 additions & 0 deletions docs/pymatgen.entries.compatibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
<span id="pymatgen-entries-compatibility-module"></span><h1>pymatgen.entries.compatibility module<a class="headerlink" href="#module-pymatgen.entries.compatibility" title="Permalink to this headline">¶</a></h1>
<p>This module implements Compatibility corrections for mixing runs of different
functionals.</p>
<dl class="class">
<dt id="pymatgen.entries.compatibility.CompositionCorrection">
<em class="property">class </em><code class="sig-name descname">CompositionCorrection</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pymatgen/entries/compatibility.html#CompositionCorrection"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.entries.compatibility.CompositionCorrection" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#pymatgen.entries.compatibility.CompositionCorrection" title="pymatgen.entries.compatibility.CompositionCorrection"><code class="xref py py-class docutils literal notranslate"><span class="pre">pymatgen.entries.compatibility.CompositionCorrection</span></code></a></p>
<dl class="py class">
<dt id="pymatgen.entries.compatibility.AnionCorrection">
<em class="property">class </em><code class="sig-name descname">AnionCorrection</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2020.4.29/pymatgen/entries/compatibility.py#L200-L287"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.entries.compatibility.AnionCorrection" title="Permalink to this definition">¶</a></dt>
Expand Down
88 changes: 67 additions & 21 deletions pymatgen/analysis/reaction_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from pymatgen.entries.computed_entries import ComputedEntry
from monty.json import MontyDecoder
from monty.fractions import gcd_float
from uncertainties import ufloat
Copy link
Member

Choose a reason for hiding this comment

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

I like this library, but is it necessary here (considering we would have to add as a core requirement)? It looks like the functionality of uncertainties is not used in this class beyond book-keeping, which could be done by a named_tuple or otherwise. I'd err towards keeping it but just wanted to clarify this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Beyond book-keeping, we use uncertainties to calculate the propagated uncertainty when adding/subtracting uncertain quantities. It would be possible to code this ourselves (we had it that way in a previous iteration), but I feel its more robust to let the dedicated library handle it. Also, in some of our previous discussions I thought you were in favor of adding uncertainties as a core requirement, because it will facilitate some other functionality we have in the pipeline? In any event, I'd prefer to keep unless you strongly oppose. I think the package is pretty lightweight.

Copy link
Member

Choose a reason for hiding this comment

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

Just to respond to this, yes I'm in favor of uncertainties via being in favor of pint, so I don't mind it getting added here, but mostly with a view of also addressing the unit question down the road. If this were the only place we'd use it I'd be more hesitant.


from itertools import combinations, chain


__author__ = "Shyue Ping Ong, Anubhav Jain"
__copyright__ = "Copyright 2011, The Materials Project"
__version__ = "2.0"
Expand Down Expand Up @@ -112,8 +112,10 @@ def normalize_to_element(self, element, factor=1):
"""
all_comp = self._all_comp
coeffs = self._coeffs
current_el_amount = (sum([all_comp[i][element] * abs(coeffs[i])
for i in range(len(all_comp))]) / 2)
current_el_amount = (
sum([all_comp[i][element] * abs(coeffs[i]) for i in range(len(all_comp))])
/ 2
)
scale_factor = factor / current_el_amount
self._coeffs = [c * scale_factor for c in coeffs]

Expand All @@ -127,8 +129,15 @@ def get_el_amount(self, element):
Returns:
Amount of that element in the reaction.
"""
return (sum([self._all_comp[i][element] * abs(self._coeffs[i])
for i in range(len(self._all_comp))]) / 2)
return (
sum(
[
self._all_comp[i][element] * abs(self._coeffs[i])
for i in range(len(self._all_comp))
]
)
/ 2
)

@property
def elements(self):
Expand Down Expand Up @@ -156,16 +165,18 @@ def reactants(self):
"""
List of reactants
"""
return [self._all_comp[i] for i in range(len(self._all_comp))
if self._coeffs[i] < 0]
return [
self._all_comp[i] for i in range(len(self._all_comp)) if self._coeffs[i] < 0
]

@property
def products(self):
"""
List of products
"""
return [self._all_comp[i] for i in range(len(self._all_comp))
if self._coeffs[i] > 0]
return [
self._all_comp[i] for i in range(len(self._all_comp)) if self._coeffs[i] > 0
]

def get_coeff(self, comp):
"""
Expand Down Expand Up @@ -241,8 +252,9 @@ def as_entry(self, energies):
Returns a ComputedEntry representation of the reaction.
:return:
"""
relevant_comp = [comp * abs(coeff) for coeff, comp
in zip(self._coeffs, self._all_comp)]
relevant_comp = [
comp * abs(coeff) for coeff, comp in zip(self._coeffs, self._all_comp)
]
comp = sum(relevant_comp, Composition())
entry = ComputedEntry(0.5 * comp, self.calculate_energy(energies))
entry.name = self.__str__()
Expand Down Expand Up @@ -335,7 +347,9 @@ def __init__(self, reactants, products):
diff = self._num_comp - rank
num_constraints = diff if diff >= 2 else 1

self._lowest_num_errors = np.inf # an error = a component changing sides or disappearing
self._lowest_num_errors = (
np.inf
) # an error = a component changing sides or disappearing

self._coeffs = self._balance_coeffs(comp_matrix, num_constraints)
self._els = all_elems
Expand Down Expand Up @@ -374,11 +388,16 @@ def _balance_coeffs(self, comp_matrix, max_num_constraints):

coeffs = np.matmul(np.linalg.pinv(comp_and_constraints), b)

if np.allclose(np.matmul(comp_matrix, coeffs), np.zeros((self._num_elems, 1))):
if np.allclose(
np.matmul(comp_matrix, coeffs), np.zeros((self._num_elems, 1))
):
balanced = True
expected_signs = np.array([-1] * len(self._input_reactants) +
[+1] * len(self._input_products))
num_errors = np.sum(np.multiply(expected_signs, coeffs.T) < self.TOLERANCE)
expected_signs = np.array(
[-1] * len(self._input_reactants) + [+1] * len(self._input_products)
)
num_errors = np.sum(
np.multiply(expected_signs, coeffs.T) < self.TOLERANCE
)

if num_errors == 0:
self._lowest_num_errors = 0
Expand Down Expand Up @@ -460,11 +479,17 @@ def __init__(self, reactant_entries, product_entries):
self._product_entries = product_entries
self._all_entries = reactant_entries + product_entries
reactant_comp = set(
[e.composition.get_reduced_composition_and_factor()[0]
for e in reactant_entries])
[
e.composition.get_reduced_composition_and_factor()[0]
for e in reactant_entries
]
)
product_comp = set(
[e.composition.get_reduced_composition_and_factor()[0]
for e in product_entries])
[
e.composition.get_reduced_composition_and_factor()[0]
for e in product_entries
]
)
super().__init__(list(reactant_comp), list(product_comp))

@property
Expand Down Expand Up @@ -492,10 +517,31 @@ def calculated_reaction_energy(self):
for entry in self._reactant_entries + self._product_entries:
(comp, factor) = entry.composition.get_reduced_composition_and_factor()
calc_energies[comp] = min(
calc_energies.get(comp, float("inf")), entry.energy / factor)
calc_energies.get(comp, float("inf")), entry.energy / factor
)

return self.calculate_energy(calc_energies)

@property
def calculated_reaction_energy_uncertainty(self):
"""
Calculates the uncertainty in the reaction energy based on the uncertainty in the
energies of the products and reactants
"""

calc_energies = {}

for entry in self._reactant_entries + self._product_entries:
(comp, factor) = entry.composition.get_reduced_composition_and_factor()
energy_ufloat = ufloat(
entry.energy, entry.correction_uncertainty
)
calc_energies[comp] = min(
calc_energies.get(comp, float("inf")), energy_ufloat / factor
)

return self.calculate_energy(calc_energies).std_dev

def as_dict(self):
"""
Returns:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/structure_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def oxide_type(structure, relative_cutoff=1.1, return_nbonds=False):

def sulfide_type(structure):
"""
Determines if a structure is a sulfide/polysulfide
Determines if a structure is a sulfide/polysulfide/sulfate
Copy link
Member

Choose a reason for hiding this comment

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

I understand changes here were reverted, but reading over the code for this PR...does this actually return sulfate as claimed?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the average electronegativity of the coordinating elements around S are greater than the electronegativity of S, then yes, "sulfate" is returned (see line 642)

Copy link
Member

Choose a reason for hiding this comment

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

That's for the inner function though, line 652 suggests None is then returned?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh weird, hadn't noticed that. Can you think of any reason we shouldn't return 'sulfate' there?


Args:
structure (Structure): Input structure.
Expand Down