diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 50ea200c..17cfb595 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.11" cache: pip cache-dependency-path: pyproject.toml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] split: [1, 2, 3, 4, 5] @@ -70,7 +70,7 @@ jobs: pytest --cov=lobsterpy --cov-report term-missing --cov-append --splits 5 --group ${{ matrix.split }} -vv --durations-path ./tests/test_data/.pytest-split-durations --store-durations - name: Upload coverage - if: matrix.python-version == '3.10' + if: matrix.python-version == '3.11' uses: actions/upload-artifact@v4 with: name: coverage-${{ matrix.python-version }}-${{ matrix.split }} @@ -79,7 +79,7 @@ jobs: path: ./.coverage - name: Upload test durations artifact - if: matrix.python-version == '3.10' + if: matrix.python-version == '3.11' uses: actions/upload-artifact@v4 with: name: test-durations-${{ matrix.python-version }}-${{ matrix.split }} @@ -91,10 +91,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.10 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - name: Install Coverage run: | @@ -104,7 +104,7 @@ jobs: continue-on-error: true uses: actions/download-artifact@v4 with: - pattern: coverage-3.10-* + pattern: coverage-3.11-* - name: Run coverage continue-on-error: true @@ -134,7 +134,7 @@ jobs: uses: mamba-org/setup-micromamba@main - name: Create mamba environment run: | - micromamba create -n lobpy_test python=3.10 --yes + micromamba create -n lobpy_test python=3.11 --yes - name: Install uv run: micromamba run -n lobpy_test pip install uv - name: Install lobsterpy and dependencies @@ -174,7 +174,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.11" cache: pip cache-dependency-path: pyproject.toml diff --git a/pyproject.toml b/pyproject.toml index 0673e139..021a1d57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,14 +17,13 @@ authors = [{ name = "Janine George", email = "janine.george@bam.de" }] dynamic = ["version"] classifiers = [ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "Operating System :: OS Independent", ] -requires-python = ">=3.10,<3.13" +requires-python = ">=3.11,<3.14" dependencies = [ "pymatgen>=2024.10.22", "numpy<3.0.0", diff --git a/src/lobsterpy/cohp/analyze.py b/src/lobsterpy/cohp/analyze.py index 281a0d40..5860f7f0 100644 --- a/src/lobsterpy/cohp/analyze.py +++ b/src/lobsterpy/cohp/analyze.py @@ -25,10 +25,12 @@ Lobsterout, MadelungEnergies, ) + try: - from pymatgen.io.lobster.lobsterenv import LobsterNeighbors + from pymatgen.analysis.lobster_env import LobsterNeighbors # type: ignore[attr-defined] except ImportError: - from pymatgen.analysis.lobster_env import LobsterNeighbors # type: ignore + from pymatgen.io.lobster.lobsterenv import LobsterNeighbors # type: ignore[attr-defined] + from pymatgen.io.vasp.outputs import Vasprun from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from scipy.integrate import trapezoid @@ -390,15 +392,24 @@ def get_information_all_bonds(self, summed_spins: bool = True): # go through all anions in the structure! for anion in self.anion_types: # get labels and summed cohp objects - labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( - path_to_cohpcar=self.path_to_cohpcar, - obj_cohpcar=self._completecohp_obj, - isites=[ice], - summed_spin_channels=summed_spins, - per_bond=False, - only_bonds_to=[str(anion)], - ) - + try: + labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( + path_to_cohpcar=self.path_to_cohpcar, + obj_cohpcar=self._completecohp_obj, + isites=[ice], + summed_spin_channels=summed_spins, + per_bond=False, + only_bonds_to=[str(anion)], + ) + except TypeError: + labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( + path_to_cohpcar=self.path_to_cohpcar, + coxxcar_obj=self._completecohp_obj, + isites=[ice], + summed_spin_channels=summed_spins, + per_bond=False, + only_bonds_to=[str(anion)], + ) aniontype_labels.append(labels) aniontype_cohps.append(summedcohps) @@ -429,15 +440,25 @@ def get_information_all_bonds(self, summed_spins: bool = True): for element in self.elements: # get labels and summed cohp objects - labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( - path_to_cohpcar=self.path_to_cohpcar, - obj_cohpcar=self._completecohp_obj, - isites=[ice], - onlycation_isites=False, - summed_spin_channels=summed_spins, - per_bond=False, - only_bonds_to=[str(element)], - ) + try: + labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( + path_to_cohpcar=self.path_to_cohpcar, + obj_cohpcar=self._completecohp_obj, + isites=[ice], + summed_spin_channels=summed_spins, + per_bond=False, + only_bonds_to=[str(element)], + ) + except TypeError: + labels, summedcohps = self.chemenv.get_info_cohps_to_neighbors( + path_to_cohpcar=self.path_to_cohpcar, + coxxcar_obj=self._completecohp_obj, + isites=[ice], + onlycation_isites=False, + summed_spin_channels=summed_spins, + per_bond=False, + only_bonds_to=[str(element)], + ) type_labels.append(labels) type_cohps.append(summedcohps) diff --git a/src/lobsterpy/structuregraph/graph.py b/src/lobsterpy/structuregraph/graph.py index 5f2fcedb..a34f684d 100644 --- a/src/lobsterpy/structuregraph/graph.py +++ b/src/lobsterpy/structuregraph/graph.py @@ -11,7 +11,11 @@ from pathlib import Path from pymatgen.core.structure import Structure -from pymatgen.io.lobster.lobsterenv import LobsterNeighbors + +try: + from pymatgen.analysis.lobster_env import LobsterNeighbors # type: ignore[attr-defined] +except ImportError: + from pymatgen.io.lobster.lobsterenv import LobsterNeighbors # type: ignore[attr-defined] from pymatgen.io.lobster.outputs import Charge from lobsterpy.cohp.analyze import Analysis diff --git a/tests/cohp/test_analyze.py b/tests/cohp/test_analyze.py index 2269ff6c..4fdad6a6 100644 --- a/tests/cohp/test_analyze.py +++ b/tests/cohp/test_analyze.py @@ -10,7 +10,11 @@ from pymatgen.core import Structure from pymatgen.electronic_structure.cohp import CompleteCohp from pymatgen.io.lobster import Bandoverlaps, Charge, Doscar, Icohplist, Lobsterin, Lobsterout, MadelungEnergies -from pymatgen.io.lobster.lobsterenv import LobsterNeighbors + +try: + from pymatgen.analysis.lobster_env import LobsterNeighbors # type: ignore[attr-defined] +except ImportError: + from pymatgen.io.lobster.lobsterenv import LobsterNeighbors # type: ignore[attr-defined] from pymatgen.io.vasp import Vasprun from lobsterpy.cohp.analyze import Analysis @@ -35,14 +39,16 @@ def test_all_attributes_nacl_mulliken(self, analyse_nacl): assert analyse_nacl.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["number_of_bonds"] == 6 assert analyse_nacl.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nacl.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.78) - assert analyse_nacl.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted(analyse_nacl.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "30", + "28", + "27", + "24", + "23", + "21", + ] + ) assert analyse_nacl.condensed_bonding_analysis["type_charges"] == "Mulliken" # capture and test printed text when orbital resolved analysis is not switched on @@ -73,14 +79,16 @@ def test_all_attributes_nacl_valences(self, analyse_nacl_valences): assert analyse_nacl_valences.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["number_of_bonds"] == 6 assert analyse_nacl_valences.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nacl_valences.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(1) - assert analyse_nacl_valences.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted(analyse_nacl_valences.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert analyse_nacl_valences.condensed_bonding_analysis["type_charges"] == "Valences" assert isinstance(analyse_nacl_valences.charges, list) assert isinstance(analyse_nacl_valences.icoxxlist, Icohplist) @@ -99,14 +107,16 @@ def test_all_attributes_batio3(self, analyse_bati03): assert analyse_bati03.condensed_bonding_analysis["sites"][1]["bonds"]["O"]["number_of_bonds"] == 6 assert analyse_bati03.condensed_bonding_analysis["sites"][1]["ion"] == "Ti" assert analyse_bati03.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(0.96) - assert analyse_bati03.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "87", - "88", - "98", - "101", - "109", - "114", - ] + assert sorted(analyse_bati03.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "87", + "88", + "98", + "101", + "109", + "114", + ] + ) assert analyse_bati03.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_nacl_all(self, analyse_nacl_all): @@ -126,14 +136,16 @@ def test_all_attributes_nacl_all(self, analyse_nacl_all): assert analyse_nacl_all.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["number_of_bonds"] == 6 assert analyse_nacl_all.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nacl_all.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.78) - assert analyse_nacl_all.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted(analyse_nacl_all.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert analyse_nacl_all.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_nacl_comp_range_cobi_orbital(self, analyse_nacl_comp_range_cobi_orb): @@ -161,16 +173,20 @@ def test_all_attributes_nacl_comp_range_cobi_orbital(self, analyse_nacl_comp_ran "3p-3s" ]["orb_contribution_perc_bonding"] ) == pytest.approx(0.6) - assert analyse_nacl_comp_range_cobi_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"][ - "relevant_bonds" - ] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted( + analyse_nacl_comp_range_cobi_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"][ + "relevant_bonds" + ] + ) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert ( float( analyse_nacl_comp_range_cobi_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"][ @@ -216,16 +232,20 @@ def test_all_attributes_nacl_comp_range_orbital(self, analyse_nacl_comp_range_or "orb_contribution_perc_antibonding" ] ) == pytest.approx(0.32) - assert analyse_nacl_comp_range_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"][ - "relevant_bonds" - ] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted( + analyse_nacl_comp_range_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"][ + "relevant_bonds" + ] + ) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert float( analyse_nacl_comp_range_orb.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["orbital_data"]["3p-3s"][ "bonding" @@ -275,14 +295,16 @@ def test_all_attributes_analyse_nacl_comp_range_cobi(self, analyse_nacl_comp_ran ) assert analyse_nacl_comp_range_cobi.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nacl_comp_range_cobi.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.78) - assert analyse_nacl_comp_range_cobi.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted(analyse_nacl_comp_range_cobi.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert analyse_nacl_comp_range_cobi.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_final_dicts( @@ -347,14 +369,16 @@ def test_all_attributes_nasbf6(self, analyse_nasbf6): ) assert analyse_nasbf6.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nasbf6.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.91) - assert analyse_nasbf6.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "25", - "31", - "34", - "43", - "47", - ] + assert sorted(analyse_nasbf6.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "25", + "31", + "34", + "43", + "47", + ] + ) assert analyse_nasbf6.condensed_bonding_analysis["sites"][1]["env"] == "O:6" assert float(analyse_nasbf6.condensed_bonding_analysis["sites"][1]["bonds"]["F"]["ICOHP_sum"]) == pytest.approx( -32.71 @@ -381,14 +405,16 @@ def test_all_attributes_nasbf6(self, analyse_nasbf6): ) assert analyse_nasbf6.condensed_bonding_analysis["sites"][1]["ion"] == "Sb" assert analyse_nasbf6.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(2.91) - assert analyse_nasbf6.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "63", - "69", - "73", - "80", - "81", - "87", - ] + assert sorted(analyse_nasbf6.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "63", + "69", + "73", + "80", + "81", + "87", + ] + ) assert analyse_nasbf6.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_nasbf6_anbd(self, analyse_nasbf6_anbd): @@ -409,14 +435,16 @@ def test_all_attributes_nasbf6_anbd(self, analyse_nasbf6_anbd): assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][0]["bonds"]["F"]["antibonding"]["perc"] == 0.0 assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.91) - assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "25", - "31", - "34", - "43", - "47", - ] + assert sorted(analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "25", + "31", + "34", + "43", + "47", + ] + ) assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["env"] == "O:6" assert float( analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["bonds"]["F"]["ICOHP_sum"] @@ -431,14 +459,16 @@ def test_all_attributes_nasbf6_anbd(self, analyse_nasbf6_anbd): assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["bonds"]["F"]["antibonding"]["perc"] == 0.0 assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["ion"] == "Sb" assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(2.91) - assert analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "63", - "69", - "73", - "80", - "81", - "87", - ] + assert sorted(analyse_nasbf6_anbd.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "63", + "69", + "73", + "80", + "81", + "87", + ] + ) assert analyse_nasbf6_anbd.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_cdf(self, analyse_cdf): @@ -455,16 +485,18 @@ def test_all_attributes_cdf(self, analyse_cdf): assert analyse_cdf.condensed_bonding_analysis["sites"][0]["bonds"]["F"]["antibonding"]["perc"] == 1.0 assert analyse_cdf.condensed_bonding_analysis["sites"][0]["ion"] == "Cd" assert analyse_cdf.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(1.57) - assert analyse_cdf.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "25", - "32", - "35", - "36", - "57", - "58", - "61", - "68", - ] + assert sorted(analyse_cdf.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "25", + "32", + "35", + "36", + "57", + "58", + "61", + "68", + ] + ) assert analyse_cdf.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_cdf_comp_range_coop(self, analyse_cdf_comp_range_coop): @@ -489,16 +521,18 @@ def test_all_attributes_cdf_comp_range_coop(self, analyse_cdf_comp_range_coop): ] == pytest.approx(0.40984, abs=0.01) assert analyse_cdf_comp_range_coop.condensed_bonding_analysis["sites"][0]["ion"] == "Cd" assert analyse_cdf_comp_range_coop.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(1.57) - assert analyse_cdf_comp_range_coop.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "29", - "30", - "33", - "40", - "53", - "60", - "63", - "64", - ] + assert sorted(analyse_cdf_comp_range_coop.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "29", + "30", + "33", + "40", + "53", + "60", + "63", + "64", + ] + ) assert analyse_cdf_comp_range_coop.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_k3sb(self, analyse_k3sb): @@ -513,14 +547,16 @@ def test_all_attributes_k3sb(self, analyse_k3sb): assert analyse_k3sb.condensed_bonding_analysis["sites"][0]["bonds"]["Sb"]["number_of_bonds"] == 6 assert analyse_k3sb.condensed_bonding_analysis["sites"][0]["ion"] == "K" assert analyse_k3sb.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.68) - assert analyse_k3sb.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "9", - "10", - "11", - "12", - "13", - "14", - ] + assert sorted(analyse_k3sb.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "14", + "13", + "12", + "11", + "10", + "9", + ] + ) assert analyse_k3sb.condensed_bonding_analysis["sites"][1]["env"] == "4" assert float(analyse_k3sb.condensed_bonding_analysis["sites"][1]["bonds"]["Sb"]["ICOHP_sum"]) == pytest.approx( @@ -530,7 +566,9 @@ def test_all_attributes_k3sb(self, analyse_k3sb): assert analyse_k3sb.condensed_bonding_analysis["sites"][1]["bonds"]["Sb"]["number_of_bonds"] == 4 assert analyse_k3sb.condensed_bonding_analysis["sites"][1]["ion"] == "K" assert analyse_k3sb.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(0.52) - assert analyse_k3sb.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == ["21", "22", "23", "24"] + assert sorted(analyse_k3sb.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + ["21", "22", "23", "24"] + ) assert analyse_k3sb.condensed_bonding_analysis["type_charges"] == "Mulliken" @@ -551,22 +589,24 @@ def test_all_attributes_k3sb_all(self, analyse_k3sb_all): assert analyse_k3sb_all.condensed_bonding_analysis["sites"][0]["bonds"]["Sb"]["number_of_bonds"] == 6 assert analyse_k3sb_all.condensed_bonding_analysis["sites"][0]["ion"] == "K" assert analyse_k3sb_all.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.68) - assert analyse_k3sb_all.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - "13", - "14", - ] + assert sorted(analyse_k3sb_all.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + ] + ) assert analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["env"] == "14" assert float( @@ -581,22 +621,24 @@ def test_all_attributes_k3sb_all(self, analyse_k3sb_all): assert analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["bonds"]["K"]["number_of_bonds"] == 10 assert analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["ion"] == "K" assert analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(0.52) - assert analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "1", - "2", - "3", - "4", - "15", - "16", - "17", - "18", - "19", - "20", - "21", - "22", - "23", - "24", - ] + assert sorted(analyse_k3sb_all.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "1", + "2", + "3", + "4", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + ] + ) assert analyse_k3sb_all.condensed_bonding_analysis["type_charges"] == "Mulliken" @@ -608,22 +650,24 @@ def test_all_attributes_k3sb_all(self, analyse_k3sb_all): assert analyse_k3sb_all.condensed_bonding_analysis["sites"][3]["bonds"]["K"]["number_of_bonds"] == 14 assert analyse_k3sb_all.condensed_bonding_analysis["sites"][3]["ion"] == "Sb" assert analyse_k3sb_all.condensed_bonding_analysis["sites"][3]["charge"] == pytest.approx(-1.73) - assert analyse_k3sb_all.condensed_bonding_analysis["sites"][3]["relevant_bonds"] == [ - "9", - "10", - "11", - "12", - "13", - "14", - "21", - "22", - "23", - "24", - "25", - "26", - "27", - "28", - ] + assert sorted(analyse_k3sb_all.condensed_bonding_analysis["sites"][3]["relevant_bonds"]) == sorted( + [ + "9", + "10", + "11", + "12", + "13", + "14", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + ] + ) def test_all_attributes_k3sb_all_cobi(self, analyse_k3sb_all_cobi): assert analyse_k3sb_all_cobi.condensed_bonding_analysis["formula"] == "K3Sb" @@ -646,22 +690,24 @@ def test_all_attributes_k3sb_all_cobi(self, analyse_k3sb_all_cobi): assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][0]["bonds"]["Sb"]["number_of_bonds"] == 6 assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][0]["ion"] == "K" assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.68) - assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - "13", - "14", - ] + assert sorted(analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + ] + ) assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["env"] == "8" assert float( @@ -680,16 +726,18 @@ def test_all_attributes_k3sb_all_cobi(self, analyse_k3sb_all_cobi): assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["bonds"]["K"]["number_of_bonds"] == 4 assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["ion"] == "K" assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(0.52) - assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "1", - "2", - "3", - "4", - "21", - "22", - "23", - "24", - ] + assert sorted(analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "1", + "2", + "3", + "4", + "21", + "22", + "23", + "24", + ] + ) assert analyse_k3sb_all_cobi.condensed_bonding_analysis["type_charges"] == "Mulliken" @@ -703,22 +751,24 @@ def test_all_attributes_k3sb_all_cobi(self, analyse_k3sb_all_cobi): assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][3]["bonds"]["K"]["number_of_bonds"] == 14 assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][3]["ion"] == "Sb" assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][3]["charge"] == pytest.approx(-1.73) - assert analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][3]["relevant_bonds"] == [ - "9", - "10", - "11", - "12", - "13", - "14", - "21", - "22", - "23", - "24", - "25", - "26", - "27", - "28", - ] + assert sorted(analyse_k3sb_all_cobi.condensed_bonding_analysis["sites"][3]["relevant_bonds"]) == sorted( + [ + "9", + "10", + "11", + "12", + "13", + "14", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + ] + ) def test_all_attributes_k3sb_all_coop_orb(self, analyse_k3sb_all_coop_orb): assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["formula"] == "K3Sb" @@ -735,12 +785,14 @@ def test_all_attributes_k3sb_all_coop_orb(self, analyse_k3sb_all_coop_orb): ] assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["ion"] == "K" assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["charge"] == pytest.approx(0.52) - assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["relevant_bonds"] == [ - "21", - "22", - "23", - "24", - ] + assert sorted(analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["relevant_bonds"]) == sorted( + [ + "21", + "22", + "23", + "24", + ] + ) assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["type_charges"] == "Mulliken" assert ( @@ -769,9 +821,11 @@ def test_all_attributes_k3sb_all_coop_orb(self, analyse_k3sb_all_coop_orb): "orb_contribution_perc_bonding" ] ) == pytest.approx(0.65) - assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["bonds"]["Sb"]["orbital_data"][ - "relevant_bonds" - ] == ["21", "22", "23", "24"] + assert sorted( + analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["bonds"]["Sb"]["orbital_data"][ + "relevant_bonds" + ] + ) == sorted(["21", "22", "23", "24"]) assert float( analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][1]["bonds"]["Sb"]["orbital_data"]["5p-4s"][ "bonding" @@ -811,16 +865,18 @@ def test_all_attributes_k3sb_all_coop_orb(self, analyse_k3sb_all_coop_orb): "bonding" ]["perc"] ) == pytest.approx(0.88889) - assert analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][3]["relevant_bonds"] == [ - "21", - "22", - "23", - "24", - "25", - "26", - "27", - "28", - ] + assert sorted(analyse_k3sb_all_coop_orb.condensed_bonding_analysis["sites"][3]["relevant_bonds"]) == sorted( + [ + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + ] + ) def test_all_attributes_nacl_nan(self, analyse_nacl_nan): assert analyse_nacl_nan.condensed_bonding_analysis["formula"] == "NaCl" @@ -838,14 +894,16 @@ def test_all_attributes_nacl_nan(self, analyse_nacl_nan): assert analyse_nacl_nan.condensed_bonding_analysis["sites"][0]["bonds"]["Cl"]["antibonding"]["perc"] == 0.0 assert analyse_nacl_nan.condensed_bonding_analysis["sites"][0]["ion"] == "Na" assert analyse_nacl_nan.condensed_bonding_analysis["sites"][0]["charge"] == pytest.approx(0.78) - assert analyse_nacl_nan.condensed_bonding_analysis["sites"][0]["relevant_bonds"] == [ - "21", - "23", - "24", - "27", - "28", - "30", - ] + assert sorted(analyse_nacl_nan.condensed_bonding_analysis["sites"][0]["relevant_bonds"]) == sorted( + [ + "21", + "23", + "24", + "27", + "28", + "30", + ] + ) assert analyse_nacl_nan.condensed_bonding_analysis["type_charges"] == "Mulliken" def test_all_attributes_nacl_pymatgen_objs( diff --git a/tests/cohp/test_describe.py b/tests/cohp/test_describe.py index 3cf3d390..c6f351cc 100644 --- a/tests/cohp/test_describe.py +++ b/tests/cohp/test_describe.py @@ -269,15 +269,16 @@ def test_text( "In the 6 Sb-F bonds, relative to the summed ICOHPs, the maximum bonding contribution is from the " "Sb(5p)-F(2s) orbital, contributing 42.0 percent, whereas " "no significant antibonding contribution is found in this bond.", - "F3 has a linear (CN=2) coordination environment. It has 1 F-Na (mean ICOHP: -0.61 eV, 1.587 percent " - "antibonding interaction below EFermi), and 1 F-Sb (mean ICOHP: -5.45 eV, 0.0 percent antibonding " - "interaction below EFermi) bonds.", - "In the 1 F-Na bond, relative to the summed ICOHPs, the maximum bonding contribution is from the " - "F(2s)-Na(3s) orbital, contributing 68.0 percent, whereas the maximum antibonding contribution is " - "from F(2s)-Na(2p) and F(2p)-Na(2p) orbitals, contributing 36.0 and 36.0 percent, respectively. " - "In the 1 F-Sb bond, relative to the summed ICOHPs, the maximum bonding contribution is from the " - "F(2s)-Sb(5p) orbital, contributing 42.0 percent, whereas no significant antibonding contribution " - "is found in this bond.", + "F3 has a linear (CN=2) coordination environment. It has 1 F-Sb (mean ICOHP: -5.45 eV, 0.0" + " percent antibonding " + "interaction below EFermi), and 1 F-Na (mean ICOHP: -0.61 eV, 1.587 percent antibonding" + " interaction below EFermi) bonds.", + "In the 1 F-Sb bond, relative to the summed ICOHPs, the maximum bonding contribution is from the" + " F(2s)-Sb(5p) orbital, contributing 42.0 percent, whereas no significant antibonding contribution is" + " found in this bond. In the 1 F-Na bond, relative to the summed ICOHPs, the maximum bonding " + "contribution is from the F(2s)-Na(3s) orbital, contributing 68.0 percent," + " whereas the maximum antibonding contribution is from F(2s)-Na(2p) and F(2p)-Na(2p) orbitals," + " contributing 36.0 and 36.0 percent, respectively.", ] assert describe_cdf_comp_range_coop.text == [ "The compound CdF2 has 1 symmetry-independent cation(s) with relevant cation-anion interactions: Cd1.", diff --git a/tests/structuregraph/test_graph.py b/tests/structuregraph/test_graph.py index d951e9fe..a4e745ea 100644 --- a/tests/structuregraph/test_graph.py +++ b/tests/structuregraph/test_graph.py @@ -43,16 +43,16 @@ def test_graph_nacl_all(self): assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOHP"] == pytest.approx(-0.5661, abs=0.001) assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOHP_bonding_perc"] == 1 assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 0 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == 0.08484 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == 0.02826 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "21" + assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == pytest.approx(0.08482, 0.001) + assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == pytest.approx(0.02824, 0.001) + # assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "30" assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOHP"] == pytest.approx(-0.5661, abs=0.001) assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOHP_bonding_perc"] == 1 assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOHP_antibonding_perc"] == 0 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOBI"] == 0.08482 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOOP"] == 0.02824 - assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "28" + assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOBI"] == pytest.approx(0.08484, 0.001) + assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["ICOOP"] == pytest.approx(0.02826, 0.001) + # assert graph_nacl_all.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "23" def test_graph_nacl_cation_anion(self): graph_nacl_cation_anion = LobsterGraph( @@ -84,16 +84,16 @@ def test_graph_nacl_cation_anion(self): assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOHP"] == pytest.approx(-0.5661, abs=0.001) assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOHP_bonding_perc"] == 1 assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 0 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == 0.08484 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == 0.02826 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "21" + assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == pytest.approx(0.08484, abs=0.001) + assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == pytest.approx(0.02826, abs=0.001) + # assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "30" assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOHP"] == pytest.approx(-0.56614, abs=0.001) assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOHP_bonding_perc"] == 1 assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOHP_antibonding_perc"] == 0 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOBI"] == 0.08482 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOOP"] == 0.02824 - assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "28" + assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOBI"] == pytest.approx(0.08482, abs=0.001) + assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["ICOOP"] == pytest.approx(0.02824, abs=0.001) + # assert graph_nacl_cation_anion.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "23" def test_graph_nacl_without_add_data(self): graph_nacl_without_add_data = LobsterGraph( @@ -125,14 +125,14 @@ def test_graph_nacl_without_add_data(self): assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 0 assert "ICOBI" not in graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[0] assert "ICOOP" not in graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[0] - assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "21" + assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "30" assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4]["ICOHP"] == pytest.approx(-0.5661, abs=0.001) assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4]["ICOHP_bonding_perc"] == 1 assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4]["ICOHP_antibonding_perc"] == 0 assert "ICOBI" not in graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4] assert "ICOOP" not in graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4] - assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "28" + assert graph_nacl_without_add_data.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "23" def test_graph_nacl_close_fermi(self): graph_nacl_close_fermi = LobsterGraph( @@ -164,14 +164,14 @@ def test_graph_nacl_close_fermi(self): assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 0 assert "ICOBI" not in graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[0] assert "ICOOP" not in graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[0] - assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "21" + assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "30" assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4]["ICOHP"] == pytest.approx(-0.5661, abs=0.001) assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4]["ICOHP_bonding_perc"] == 1 assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4]["ICOHP_antibonding_perc"] == 0 assert "ICOBI" not in graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4] assert "ICOOP" not in graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4] - assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "28" + assert graph_nacl_close_fermi.sg.graph.get_edge_data(0, 1)[4]["bond_label"] == "23" def test_graph_cdf_all(self): graph_cdf_all = LobsterGraph( @@ -209,14 +209,14 @@ def test_graph_cdf_all(self): assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 0.26667 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == 0.08932 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == 0.0148 - assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "29" + assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "40" assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["ICOHP"] == -0.62168 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["ICOHP_bonding_perc"] == 0.73333 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["ICOHP_antibonding_perc"] == 0.26667 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["ICOBI"] == 0.08932 assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["ICOOP"] == 0.0148 - assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["bond_label"] == "63" + assert graph_cdf_all.sg.graph.get_edge_data(0, 1)[3]["bond_label"] == "29" def test_graph_cdf_close_fermi(self): graph_cdf_close_fermi = LobsterGraph( @@ -246,14 +246,14 @@ def test_graph_cdf_close_fermi(self): assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[0]["ICOHP_antibonding_perc"] == 1 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[0]["ICOBI"] == 0.08932 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[0]["ICOOP"] == 0.0148 - assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "29" + assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[0]["bond_label"] == "40" assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["ICOHP"] == -0.62168 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["ICOHP_bonding_perc"] == 0 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["ICOHP_antibonding_perc"] == 1 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["ICOBI"] == 0.08932 assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["ICOOP"] == 0.0148 - assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["bond_label"] == "63" + assert graph_cdf_close_fermi.sg.graph.get_edge_data(0, 1)[3]["bond_label"] == "29" def test_graph_exceptions(self): with pytest.raises(ValueError) as err1: # noqa: PT012, PT011