Line data Source code
1 : # SPDX-FileCopyrightText: 2025 Pairinteraction Developers 2 : # SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 0 : import logging 5 0 : from typing import Any 6 : 7 0 : from pairinteraction_gui.calculate.calculate_two_atoms import ParametersTwoAtoms, ResultsTwoAtoms, calculate_two_atoms 8 0 : from pairinteraction_gui.config import ( 9 : BasisConfigTwoAtoms, 10 : KetConfigTwoAtoms, 11 : SystemConfigTwoAtoms, 12 : ) 13 0 : from pairinteraction_gui.page.base_page import CalculationPage 14 : 15 0 : logger = logging.getLogger(__name__) 16 : 17 : 18 0 : class TwoAtomsPage(CalculationPage): 19 : """Page for configuring and analyzing pair systems.""" 20 : 21 0 : title = "Two Atoms" 22 0 : tooltip = "Configure and analyze pair systems" 23 : 24 0 : def setupWidget(self) -> None: 25 0 : super().setupWidget() 26 : 27 : # all attributes of instance BaseConfig will be added to the toolbox in postSetupWidget 28 0 : self.ket_config = KetConfigTwoAtoms(self) 29 0 : self.basis_config = BasisConfigTwoAtoms(self) 30 0 : self.system_config = SystemConfigTwoAtoms(self) 31 : 32 0 : def before_calculate(self) -> None: 33 0 : self.basis_config.clear_basis_pair_label() 34 0 : return super().before_calculate() 35 : 36 0 : def calculate(self) -> tuple[ParametersTwoAtoms, ResultsTwoAtoms]: 37 0 : parameters = ParametersTwoAtoms.from_page(self) 38 0 : results = calculate_two_atoms(parameters) 39 0 : return parameters, results 40 : 41 0 : def update_plot(self, parameters: ParametersTwoAtoms, results: ResultsTwoAtoms) -> None: # type: ignore[override] 42 0 : super().update_plot(parameters, results) 43 : 44 0 : if results.basis_0_label is not None: 45 0 : self.basis_config.update_basis_pair_label(results.basis_0_label) 46 : 47 0 : def _get_export_replacements(self) -> dict[str, Any]: 48 0 : parameters = ParametersTwoAtoms.from_page(self) 49 0 : return parameters.to_replacement_dict() 50 : 51 0 : def _get_export_notebook_template_name(self) -> str: 52 0 : ranges = self.system_config.get_ranges_dict() 53 0 : if all(v[0] == v[-1] for k, v in ranges.items() if k in ["Ex", "Ey", "Ez", "Bx", "By", "Bz"]): 54 0 : return "two_atoms.ipynb" 55 0 : return "two_atoms_variable_fields.ipynb"