Skip to content

Commit

Permalink
added num_isolated_atoms property
Browse files Browse the repository at this point in the history
  • Loading branch information
BowenD-UCB committed Oct 7, 2023
1 parent 38a5cc4 commit 20ebc58
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions chgnet/graph/crystalgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ def __repr__(self) -> str:
f"CrystalGraph({composition=}, {atom_graph_cutoff=}, {bond_graph_cutoff=}, "
f"{n_atoms=}, {atom_graph_len=}, {bond_graph_len=})"
)

@property
def num_isolated_atoms(self):
"""Number of isolated atoms given the atom graph cutoff
Isolated atoms are disconnected nodes in the atom graph
that will not get updated in CHGNet.
These atoms will always have calculated force equal to zero.
With the default CHGNet atom graph cutoff radius, only ~ 0.1% of MPtrj dataset
structures has isolated atoms.
"""
return len(self.atomic_number) - torch.unique(self.atom_graph[:, 0]).numel()
8 changes: 8 additions & 0 deletions tests/test_crystal_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,11 @@ def test_crystal_graph_repr():
== "CrystalGraph(composition='Li2 Mn2 O4', atom_graph_cutoff=5, bond_graph_cutoff=3, "
"n_atoms=8, atom_graph_len=384, bond_graph_len=744)"
)


def test_isolated_atoms():
converter = CrystalGraphConverter(
atom_graph_cutoff=5, bond_graph_cutoff=3, on_isolated_atoms="warn"
)
graph = converter(structure)
assert graph.num_isolated_atoms == 0

0 comments on commit 20ebc58

Please sign in to comment.