Skip to content

Commit

Permalink
Fix coordination number bug (#3954)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn authored Jul 26, 2024
1 parent 98c5788 commit 5256fce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 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 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

0 comments on commit 5256fce

Please sign in to comment.