diff --git a/src/koopmans/processes/_process.py b/src/koopmans/processes/_process.py index bcbe27b17..5362ca132 100644 --- a/src/koopmans/processes/_process.py +++ b/src/koopmans/processes/_process.py @@ -29,7 +29,6 @@ def __eq__(self, other): if isinstance(cond, np.ndarray): cond = cond.all() if not cond: - raise ValueError(f'Debug: {key} differs: {getattr(self, key)} != {getattr(other, key)}') return False return True diff --git a/src/koopmans/processes/ui/_atoms.py b/src/koopmans/processes/ui/_atoms.py index 219453271..16eb2c9cd 100644 --- a/src/koopmans/processes/ui/_atoms.py +++ b/src/koopmans/processes/ui/_atoms.py @@ -81,28 +81,3 @@ def fromatoms(cls, atoms: Atoms, supercell_matrix: Optional[np.ndarray] = None): # Return the new UIAtoms object return ui_atoms - - def __eq__(self, other): - # Patching for test - if not isinstance(other, UIAtoms): - return False - a = self.arrays - b = other.arrays - if len(self) != len(other): - utils.warn('Atoms have different lengths') - return False - if (a['numbers'] != b['numbers']).any(): - utils.warn('Atoms have different numbers') - return False - if (a['positions'] != b['positions']).any(): - utils.warn('Atoms have different positions') - utils.warn(f'{a["positions"]}\n{b["positions"]}') - utils.warn(f'{a["positions"] == b["positions"]}') - return False - if not (self.cell == other.cell).all(): - utils.warn('Atoms have different cells') - return False - if not (self.pbc == other.pbc).all(): - utils.warn('Atoms have different pbc') - return False - return True diff --git a/src/koopmans/workflows/_unfold_and_interp.py b/src/koopmans/workflows/_unfold_and_interp.py index f5fcc4dae..82bfe3c42 100644 --- a/src/koopmans/workflows/_unfold_and_interp.py +++ b/src/koopmans/workflows/_unfold_and_interp.py @@ -115,8 +115,7 @@ def _run(self) -> None: dft_smooth_ham_file = None process = self.new_ui_process(presets, centers=centers[mask], spreads=spreads[mask].tolist(), - dft_smooth_ham_file=dft_smooth_ham_file, - dft_ham_file=self._dft_ham_files[(filling, spin)]) + dft_smooth_ham_file=dft_smooth_ham_file) # Run the process self.run_process(process) @@ -178,8 +177,7 @@ def new_ui_process(self, presets: str, **kwargs) -> UnfoldAndInterpolateProcess: preset_tuple = (presets, None) kwargs['kc_ham_file'] = self._koopmans_ham_files[preset_tuple] - if self.calculator_parameters['ui'].do_smooth_interpolation: - kwargs['dft_ham_file'] = self._dft_ham_files[preset_tuple] + kwargs['dft_ham_file'] = self._dft_ham_files[preset_tuple] parameters = self.calculator_parameters['ui'] parameters.kgrid = self.kpoints.grid diff --git a/tests/helpers/patches/_mock.py b/tests/helpers/patches/_mock.py index 964b92f14..2839cc1a3 100644 --- a/tests/helpers/patches/_mock.py +++ b/tests/helpers/patches/_mock.py @@ -6,6 +6,7 @@ from typing import Union import numpy as np +from ase import Atoms from koopmans.files import FilePointer from koopmans.io import read_pkl @@ -15,6 +16,19 @@ recursively_find_files) +def atoms_eq(self, other): + # Patching the Atoms class to compare positions and cell with np.allclose rather than strict equality + if not isinstance(other, Atoms): + return False + a = self.arrays + b = other.arrays + return (len(self) == len(other) and + np.allclose(a['positions'], b['positions']) and + (a['numbers'] == b['numbers']).all() and + np.allclose(self.cell, other.cell) and + (self.pbc == other.pbc).all()) + + def write_mock_file(filename: Union[Path, str], written_by: str): filename = Path(filename) with chdir(filename.parent): @@ -173,3 +187,6 @@ def monkeypatch_mock(monkeypatch): # Processes for p in [ExtractCoefficientsFromXMLProcess, ComputePowerSpectrumProcess, Bin2XMLProcess, ConvertFilesFromSpin1To2, ConvertFilesFromSpin2To1, ExtendProcess, MergeProcess, UnfoldAndInterpolateProcess, MergeEVCProcess]: monkeypatch.setattr(p, '_run', mock_process_run) + + # Patch the Atoms class + monkeypatch.setattr(Atoms, '__eq__', atoms_eq)