diff --git a/src/aiida_quantumespresso/data/hubbard_structure.py b/src/aiida_quantumespresso/data/hubbard_structure.py index f41457a0..fe7d2faf 100644 --- a/src/aiida_quantumespresso/data/hubbard_structure.py +++ b/src/aiida_quantumespresso/data/hubbard_structure.py @@ -5,6 +5,7 @@ from aiida.orm import StructureData import numpy as np +from pymatgen.core import Lattice, PeriodicSite from aiida_quantumespresso.common.hubbard import Hubbard, HubbardParameters @@ -110,8 +111,11 @@ def append_hubbard_parameter( :param hubbard_type: hubbard type (U, V, J, ...), defaults to 'Ueff' (see :class:`~aiida_quantumespresso.common.hubbard.Hubbard` for full allowed values) """ - pymat = self.get_pymatgen_structure() - sites = pymat.sites + sites = [ + PeriodicSite( + species=site.species, coords=site.coords, lattice=Lattice(self.cell), coords_are_cartesian=True + ) for site in self.get_pymatgen().sites + ] if any((atom_index > len(sites) - 1, neighbour_index > len(sites) - 1)): raise ValueError( diff --git a/tests/data/test_hubbard_structure.py b/tests/data/test_hubbard_structure.py index 812bda40..b07860cf 100644 --- a/tests/data/test_hubbard_structure.py +++ b/tests/data/test_hubbard_structure.py @@ -62,7 +62,7 @@ def test_from_structure(generate_structure, generate_hubbard): @pytest.mark.usefixtures('aiida_profile') -@pytest.mark.parametrize('structure_name', ('silicon',)) +@pytest.mark.parametrize('structure_name', ('silicon', '2D-xy-arsenic')) @pytest.mark.parametrize( 'parameters', ( ((0, '1s', 0, '1s', 5.0, (0, 0, 0), 'Ueff'),), @@ -88,13 +88,14 @@ def test_append_hubbard_parameters(data_regression, generate_structure, structur assert len(hubbard_structure.hubbard.parameters) == len(set(parameters)) +@pytest.mark.parametrize('structure_name', ('cobalt-prim', '1D-x-carbon')) @pytest.mark.parametrize('parameter', ( (0, '1s', 1, '1s', 5.0, None, 'V'), (0, '1s', 1, '1s', 5.0, (0, 0, 0), 'V'), )) -def test_append_hubbard_parameters_invalid_index(generate_structure, parameter): +def test_append_hubbard_parameters_invalid_index(generate_structure, structure_name, parameter): """Test the `append_hubbard_parameters` method with invalid index.""" - hubbard_structure = HubbardStructureData.from_structure(generate_structure('cobalt-prim')) + hubbard_structure = HubbardStructureData.from_structure(generate_structure(structure_name)) with pytest.raises(ValueError, match='atom_index and neighbour_index must be within the range'): hubbard_structure.append_hubbard_parameter(*parameter) diff --git a/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters0_2D_xy_arsenic_.yml b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters0_2D_xy_arsenic_.yml new file mode 100644 index 00000000..af0e1049 --- /dev/null +++ b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters0_2D_xy_arsenic_.yml @@ -0,0 +1,9 @@ +- - 0 + - 1s + - 0 + - 1s + - 5.0 + - - 0 + - 0 + - 0 + - Ueff diff --git a/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters1_2D_xy_arsenic_.yml b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters1_2D_xy_arsenic_.yml new file mode 100644 index 00000000..577587c2 --- /dev/null +++ b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters1_2D_xy_arsenic_.yml @@ -0,0 +1,9 @@ +- - 0 + - 1s + - 1 + - 1s + - 5.0 + - - 0 + - 0 + - 0 + - V diff --git a/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters2_2D_xy_arsenic_.yml b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters2_2D_xy_arsenic_.yml new file mode 100644 index 00000000..af0e1049 --- /dev/null +++ b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters2_2D_xy_arsenic_.yml @@ -0,0 +1,9 @@ +- - 0 + - 1s + - 0 + - 1s + - 5.0 + - - 0 + - 0 + - 0 + - Ueff diff --git a/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters3_2D_xy_arsenic_.yml b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters3_2D_xy_arsenic_.yml new file mode 100644 index 00000000..59b94e60 --- /dev/null +++ b/tests/data/test_hubbard_structure/test_append_hubbard_parameters_parameters3_2D_xy_arsenic_.yml @@ -0,0 +1,18 @@ +- - 0 + - 1s + - 0 + - 1s + - 5.0 + - - 0 + - 0 + - 0 + - Ueff +- - 0 + - 1s + - 1 + - 1s + - 5.0 + - - 0 + - 1 + - 0 + - V