Skip to content

Commit 5256fce

Browse files
authored
Fix coordination number bug (materialsproject#3954)
1 parent 98c5788 commit 5256fce

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/pymatgen/analysis/graphs.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,7 @@ def get_coordination_of_site(self, n: int) -> int:
808808
Returns:
809809
int: number of neighbors of site n.
810810
"""
811-
n_self_loops = sum(1 for n, v in self.graph.edges(n) if n == v)
812-
return self.graph.degree(n) - n_self_loops
811+
return self.graph.degree(n)
813812

814813
def draw_graph_to_file(
815814
self,
@@ -2478,8 +2477,7 @@ def get_coordination_of_site(self, n) -> int:
24782477
Returns:
24792478
int: the number of neighbors of site n.
24802479
"""
2481-
n_self_loops = sum(1 for n, v in self.graph.edges(n) if n == v)
2482-
return self.graph.degree(n) - n_self_loops
2480+
return self.graph.degree(n)
24832481

24842482
def draw_graph_to_file(
24852483
self,

tests/analysis/test_graphs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def test_from_local_env_and_equality_and_diff(self):
409409
diff = struct_graph.diff(sg2)
410410
assert diff["dist"] == 0
411411

412-
assert self.square_sg.get_coordination_of_site(0) == 2
412+
assert self.square_sg.get_coordination_of_site(0) == 4
413413

414414
def test_from_edges(self):
415415
edges = {

0 commit comments

Comments
 (0)