From eba7f4ca75eab8c8905700cef3049e7785e1f851 Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Wed, 7 Jul 2021 17:12:26 +0000 Subject: [PATCH] Converted Site.probabilities to return a dict. --- pyscses/site.py | 15 +++++++++++++++ tests/test_site.py | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/pyscses/site.py b/pyscses/site.py index c126a73..13e33fd 100644 --- a/pyscses/site.py +++ b/pyscses/site.py @@ -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 @@ -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] diff --git a/tests/test_site.py b/tests/test_site.py index c1dc99d..7df00be 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -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()