From d04699d872cfb97b153ef1de7f773bee1f2910ef Mon Sep 17 00:00:00 2001 From: Eric Sivonxay Date: Fri, 22 Dec 2023 17:17:31 -0800 Subject: [PATCH] Better handle legacy calculations --- src/NanoParticleTools/species_data/species.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/NanoParticleTools/species_data/species.py b/src/NanoParticleTools/species_data/species.py index bea6eee..dc209e9 100644 --- a/src/NanoParticleTools/species_data/species.py +++ b/src/NanoParticleTools/species_data/species.py @@ -199,9 +199,19 @@ def species_data(self) -> dict[str, tuple[list[str], list[float]]]: symbol = self.SURFACE_DOPANT_SYMBOLS_TO_NAMES[self.symbol] else: symbol = self.symbol - # Load Data from json file - with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'), 'r') as f: - species_data = json.load(f) + try: + # Load Data from json file + with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'), + 'r') as f: + species_data = json.load(f) + except FileNotFoundError: + # File was not found, check if it is a legacy calc + if self.symbol in self.LEGACY_SURFACE_NAMES: + # This is a legacy calc. Load the corresponding calc + symbol = self.LEGACY_SURFACE_NAMES[self.symbol] + with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'), + 'r') as f: + species_data = json.load(f) return species_data