Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to run PBC in single system mode #795

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions src/fairchem/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def generate_graph(
use_pbc=None,
otf_graph=None,
enforce_max_neighbors_strictly=None,
use_pbc_single=False,
):
cutoff = cutoff or self.cutoff
max_neighbors = max_neighbors or self.max_neighbors
Expand Down Expand Up @@ -84,12 +85,47 @@ def generate_graph(

if use_pbc:
if otf_graph:
edge_index, cell_offsets, neighbors = radius_graph_pbc(
data,
cutoff,
max_neighbors,
enforce_max_neighbors_strictly,
)
if use_pbc_single:
(
edge_index_per_system,
cell_offsets_per_system,
neighbors_per_system,
) = list(
zip(
*[
radius_graph_pbc(
data[idx],
cutoff,
max_neighbors,
enforce_max_neighbors_strictly,
)
for idx in range(len(data))
]
)
)

# atom indexs in the edge_index need to be offset
atom_index_offset = data.natoms.cumsum(dim=0).roll(1)
atom_index_offset[0] = 0
edge_index = torch.hstack(
[
edge_index_per_system[idx] + atom_index_offset[idx]
for idx in range(len(data))
]
)
cell_offsets = torch.vstack(cell_offsets_per_system)
neighbors = torch.hstack(neighbors_per_system)
else:
## TODO this is the original call, but blows up with memory
## using two different samples
## sid='mp-675045-mp-675045-0-7' (MPTRAJ)
## sid='75396' (OC22)
edge_index, cell_offsets, neighbors = radius_graph_pbc(
data,
cutoff,
max_neighbors,
enforce_max_neighbors_strictly,
)

out = get_pbc_distances(
data.pos,
Expand Down