Skip to content

Commit

Permalink
Converted Site.probabilities to return a dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmorgan committed Jul 7, 2021
1 parent 7d9611d commit eba7f4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pyscses/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyscses.defect_species import DefectSpecies
from typing import List, Optional, Dict
from pyscses.defect_at_site import DefectAtSite
import warnings

class LabelError(Exception):
pass
Expand Down Expand Up @@ -180,6 +181,20 @@ def probabilities(self,
def probabilities_as_list(self,
phi: float,
temp: float) -> List[float]:
"""Calculates the probabilities of this site being occupied by each defect species.
Legacy interface that returns a list of site-occupation probabilities
in the same order as `Site.defects`.
Args:
phi (float): Electrostatic potential at this site in Volts.
temp (float): Temperature in Kelvin.
Returns:
list(float): Probabilities of site occupation for each defect species.
"""
warnings.warn("Site.probabilities_as_list() is deprecated and targetted for removal. Please use Site.probabilities() instead.", DeprecationWarning)
probabilities_dict = self.probabilities(phi=phi, temp=temp)
return [probabilities_dict[d.label] for d in self.defects]

Expand Down
4 changes: 4 additions & 0 deletions tests/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def test_probabilities_two(self):
temp=298.0),
{'A': exp_A, 'B': exp_B})

def test_probabilites_as_list(self):
self.site.probabilities = Mock(return_value={'E': 0.1, 'D': 0.2})
self.site.probabilities_as_list(phi=1.0, temp=298.0)


if __name__ == '__main__':
unittest.main()

0 comments on commit eba7f4c

Please sign in to comment.