diff --git a/src/easyreflectometry/project.py b/src/easyreflectometry/project.py index 66358de4..116a62e0 100644 --- a/src/easyreflectometry/project.py +++ b/src/easyreflectometry/project.py @@ -78,29 +78,18 @@ def parameters(self) -> List[Parameter]: parameters.append(vertice_obj) return parameters - # @property - # def count_free_parameters(self) -> int: - # count = 0 - # for parameter in self.parameters: - # if parameter.free: - # count = count + 1 - # return count - - # @property - # def count_fixed_parameters(self) -> int: - # count = 0 - # for parameter in self.parameters: - # if not parameter.free: - # count = count + 1 - # return count - - # @property - # def count_parameter_user_constraints(self) -> int: - # count = 0 - # parameters = self.parameters - # for parameter in parameters: - # count = count + len(parameter.user_constraints.keys()) - # return count + def count_free_parameters(self) -> int: + return sum(1 for parameter in self.parameters if parameter.free) + + def count_fixed_parameters(self) -> int: + return sum(1 for parameter in self.parameters if not parameter.free) + + def count_parameter_user_constraints(self) -> int: + count = 0 + parameters = self.parameters + for parameter in parameters: + count = count + len(parameter.user_constraints.keys()) + return count @property def q_min(self): diff --git a/src/easyreflectometry/summary/summary.py b/src/easyreflectometry/summary/summary.py index 758038b9..de521259 100644 --- a/src/easyreflectometry/summary/summary.py +++ b/src/easyreflectometry/summary/summary.py @@ -162,12 +162,12 @@ def _experiments_section(self) -> str: def _refinement_section(self) -> str: html_refinement = HTML_REFINEMENT_TEMPLATE - num_free_params = self._project.count_free_parameters - num_fixed_params = self._project.count_fixed_parameters + num_free_params = self._project.count_free_parameters() + num_fixed_params = self._project.count_fixed_parameters() num_params = num_free_params + num_fixed_params # goodness_of_fit = self._project.status.goodnessOfFit # goodness_of_fit = goodness_of_fit.split(' → ')[-1] - num_constraints = self._project.count_parameter_user_constraints + num_constraints = self._project.count_parameter_user_constraints() html_refinement = html_refinement.replace('calculation_engine', f'{self._project._calculator.current_interface_name}') html_refinement = html_refinement.replace('minimization_engine', f'{self._project.minimizer.name}') diff --git a/tests/test_project.py b/tests/test_project.py index 803cf1d0..2c7b7355 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -642,7 +642,7 @@ def test_count_free_parameters(self): project.parameters[0].free = True # Then - count = project.count_free_parameters + count = project.count_free_parameters() # Expect assert count == 1 @@ -654,7 +654,7 @@ def test_count_fixed_parameters(self): project.parameters[0].free = True # Then - count = project.count_fixed_parameters + count = project.count_fixed_parameters() # Expect assert count == 13 @@ -666,7 +666,7 @@ def test_count_parameter_user_constraints(self): project.parameters[0].user_constraints['name_other_parameter'] = 'constraint' # Then - count = project.count_parameter_user_constraints + count = project.count_parameter_user_constraints() # Expect assert count == 1