Skip to content

Commit

Permalink
Merge pull request #199 from sparks-baird/distance-matrix
Browse files Browse the repository at this point in the history
avoid repeat calculations of distance_matrix
  • Loading branch information
sgbaird committed Jul 29, 2022
2 parents 8075f24 + c71ac04 commit 4bf6f6d
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 4bf6f6d

Please sign in to comment.