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

Faster LENS calculation using FastNS #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
23 changes: 15 additions & 8 deletions src/dynsight/_internal/lens/lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from MDAnalysis import AtomGroup, Universe

import numpy as np
from MDAnalysis.lib.NeighborSearch import AtomNeighborSearch
from MDAnalysis.lib.nsgrid import FastNS


def list_neighbours_along_trajectory(
Expand Down Expand Up @@ -34,15 +34,22 @@ def list_neighbours_along_trajectory(
if trajslice is None:
trajslice = slice(None)
neigh_list_per_frame = []

for _ in input_universe.universe.trajectory[trajslice]:
neigh_search = AtomNeighborSearch(
input_universe.atoms, box=input_universe.dimensions
)
atom_pos = input_universe.atoms.positions
box_dim = input_universe.dimensions
gridsearch = FastNS(cutoff, atom_pos, box=box_dim, pbc=True)
max_cutoff = gridsearch._prepare_box(box=box_dim, pbc=True)
if cutoff > max_cutoff:
cutoff = max_cutoff
fastns_results = gridsearch.self_search()
pairs = fastns_results.get_pairs()
neigh_list_per_atom = [[] for _ in range(len(input_universe.atoms))]
for x, y in pairs:
neigh_list_per_atom[x].append(y)
neigh_list_per_atom[y].append(x)
neigh_list_per_frame.append(neigh_list_per_atom)

neigh_list_per_atom = [
neigh_search.search(atom, cutoff) for atom in input_universe.atoms
]
neigh_list_per_frame.append([at.ix for at in neigh_list_per_atom])
return neigh_list_per_frame


Expand Down
Loading