Skip to content

Commit

Permalink
Merge remote-tracking branch 'trunk/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Jul 26, 2024
2 parents 50044ce + 5256fce commit 35260ee
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 41 deletions.
6 changes: 2 additions & 4 deletions src/pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,7 @@ def get_coordination_of_site(self, n: int) -> int:
Returns:
int: number of neighbors of site n.
"""
n_self_loops = sum(1 for n, v in self.graph.edges(n) if n == v)
return self.graph.degree(n) - n_self_loops
return self.graph.degree(n)

def draw_graph_to_file(
self,
Expand Down Expand Up @@ -2478,8 +2477,7 @@ def get_coordination_of_site(self, n) -> int:
Returns:
int: the number of neighbors of site n.
"""
n_self_loops = sum(1 for n, v in self.graph.edges(n) if n == v)
return self.graph.degree(n) - n_self_loops
return self.graph.degree(n)

def draw_graph_to_file(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def chemical_system(self) -> str:
sorted alphabetically and joined by dashes, by convention for use
in database keys.
"""
return "-".join(sorted(el.symbol for el in self.elements))
return "-".join(sorted(self.chemical_system_set))

@property
def num_atoms(self) -> float:
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def test_from_local_env_and_equality_and_diff(self):
diff = struct_graph.diff(sg2)
assert diff["dist"] == 0

assert self.square_sg.get_coordination_of_site(0) == 2
assert self.square_sg.get_coordination_of_site(0) == 4

def test_from_edges(self):
edges = {
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ def test_elements(self):
def test_chemical_system(self):
assert Composition({"Na": 1, "Cl": 1}).chemical_system == "Cl-Na"
assert Composition({"Na+": 1, "Cl-": 1}).chemical_system == "Cl-Na"
assert Composition({"Na+": 1, "Na2+": 1, "Cl-": 1}).chemical_system == "Cl-Na"

def test_chemical_system_set(self):
assert Composition({"Na": 1, "Cl": 1}).chemical_system_set == {"Cl", "Na"}
Expand Down
Binary file added tests/files/io/abinit/28ni.paw.tar.xz
Binary file not shown.
Binary file not shown.
Binary file not shown.
35 changes: 22 additions & 13 deletions tests/io/abinit/test_netcdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import annotations

import os
import tarfile

import numpy as np
import pytest
from monty.tempfile import ScratchDir
from numpy.testing import assert_allclose, assert_array_equal
from pymatgen.core.structure import Structure
from pymatgen.io.abinit import EtsfReader
Expand Down Expand Up @@ -81,19 +85,24 @@ def test_read_si2(self):

@pytest.mark.skipif(netCDF4 is None, reason="Requires Netcdf4")
def test_read_fe(self):
path = self.GSR_paths["Fe_magmoms_collinear"]
ref_magmom_collinear = [-0.5069359730980665]

with EtsfReader(path) as data:
structure = data.read_structure()
assert structure.site_properties["magmom"] == ref_magmom_collinear

path = self.GSR_paths["Fe_magmoms_noncollinear"]
ref_magmom_noncollinear = [[0.357939487, 0.357939487, 0]]

with EtsfReader(path) as data:
structure = data.read_structure()
assert structure.site_properties["magmom"] == ref_magmom_noncollinear
with ScratchDir(".") as tmp_dir:
with tarfile.open(f"{TEST_DIR}/Fe_magmoms_collinear_GSR.tar.xz", mode="r:xz") as t:
t.extractall(tmp_dir)
ref_magmom_collinear = [-0.5069359730980665]
path = os.path.join(tmp_dir, "Fe_magmoms_collinear_GSR.nc")

with EtsfReader(path) as data:
structure = data.read_structure()
assert structure.site_properties["magmom"] == ref_magmom_collinear

with tarfile.open(f"{TEST_DIR}/Fe_magmoms_noncollinear_GSR.tar.xz", mode="r:xz") as t:
t.extractall(tmp_dir)
ref_magmom_noncollinear = [[0.357939487, 0.357939487, 0]]
path = os.path.join(tmp_dir, "Fe_magmoms_noncollinear_GSR.nc")

with EtsfReader(path) as data:
structure = data.read_structure()
assert structure.site_properties["magmom"] == ref_magmom_noncollinear


class TestAbinitHeader(PymatgenTest):
Expand Down
50 changes: 28 additions & 22 deletions tests/io/abinit/test_pseudos.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import os.path
import tarfile
from collections import defaultdict

import pytest
from monty.tempfile import ScratchDir
from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pytest import approx
Expand Down Expand Up @@ -110,28 +112,32 @@ def test_nc_pseudos(self):

def test_paw_pseudos(self):
"""Test 28ni.paw."""
for symbol, pseudos in self.paw_pseudos.items():
for pseudo in pseudos:
assert repr(pseudo)
assert str(pseudo)
assert not pseudo.isnc
assert pseudo.ispaw
assert pseudo.Z == 28
assert pseudo.symbol == symbol
assert pseudo.Z_val == 18
assert pseudo.paw_radius >= 0.0

# Test pickle
self.serialize_with_pickle(pseudo)

# Test MSONable
self.assert_msonable(pseudo)

pseudo = self.Ni_paw
assert pseudo.l_max == 2
assert pseudo.l_local == 0
assert pseudo.supports_soc
assert pseudo.md5 is not None
file_name = f"{TEST_DIR}/28ni.paw.tar.xz"
symbol = "Ni"
with ScratchDir(".") as tmp_dir, tarfile.open(file_name, mode="r:xz") as t:
t.extractall(tmp_dir)
path = os.path.join(tmp_dir, "28ni.paw")
pseudo = Pseudo.from_file(path)

assert repr(pseudo)
assert str(pseudo)
assert not pseudo.isnc
assert pseudo.ispaw
assert pseudo.Z == 28
assert pseudo.symbol == symbol
assert pseudo.Z_val == 18
assert pseudo.paw_radius >= 0.0

assert pseudo.l_max == 2
assert pseudo.l_local == 0
assert pseudo.supports_soc
assert pseudo.md5 is not None

# Test pickle
self.serialize_with_pickle(pseudo)

# Test MSONable
self.assert_msonable(pseudo)

def test_pawxml_pseudos(self):
"""Test O.GGA_PBE-JTH-paw.xml."""
Expand Down

0 comments on commit 35260ee

Please sign in to comment.