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

avoid repeat calculations of distance_matrix #199

Merged
merged 1 commit into from
Jul 29, 2022
Merged
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
7 changes: 4 additions & 3 deletions src/xtal2png/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,15 @@ def structures_to_arrays(
num_sites.append(s.num_sites)
space_group.append(_get_space_group(s))

if n_sites != s.distance_matrix.shape[0]:
dm = s.distance_matrix # avoid repeat calculation
if n_sites != dm.shape[0]:
raise ValueError(
f"len(atomic_numbers) {n_sites} and distance_matrix.shape[0] {s.distance_matrix.shape[0]} do not match" # noqa
f"len(atomic_numbers) {n_sites} and distance_matrix.shape[0] {dm.shape[0]} do not match" # noqa
) # noqa

# assume that distance matrix is square
padwidth = (0, self.max_sites - n_sites)
distance_matrix_tmp.append(np.pad(s.distance_matrix, padwidth))
distance_matrix_tmp.append(np.pad(dm, padwidth))
# [0:max_sites, 0:max_sites]

frac_coords = np.stack(frac_coords_tmp)
Expand Down