MCPcopy Create free account
hub / github.com/SINGROUP/dscribe / get_displacement_tensor

Method get_displacement_tensor

dscribe/core/system.py:147–179  ·  view source on GitHub ↗

A matrix where the entry A[i, j, :] is the vector self.cartesian_pos[j] - self.cartesian_pos[i]. For periodic systems the distance of an atom from itself is the smallest displacement of an atom from one of it's periodic copies, and the distance of two different atoms

(self)

Source from the content-addressed store, hash-verified

145 return cartesian_positions
146
147 def get_displacement_tensor(self):
148 """A matrix where the entry A[i, j, :] is the vector
149 self.cartesian_pos[j] - self.cartesian_pos[i].
150
151 For periodic systems the distance of an atom from itself is the
152 smallest displacement of an atom from one of it's periodic copies, and
153 the distance of two different atoms is the distance of two closest
154 copies.
155
156 Returns:
157 np.array: 3D matrix containing the pairwise distance vectors.
158 """
159 if self._displacement_tensor is None:
160 D, D_len = ase.geometry.geometry.get_distances(
161 self.get_positions(), cell=self.get_cell(), pbc=self.get_pbc()
162 )
163
164 # Figure out the smallest basis vector and set it as
165 # displacement for diagonal
166 if self.get_pbc().any():
167 cell = self.get_cell()
168 basis_lengths = np.linalg.norm(cell, axis=1)
169 min_index = np.argmin(basis_lengths)
170 min_basis = cell[min_index]
171 diag_indices = np.diag_indices(len(D))
172 D[diag_indices] = min_basis
173 diag_indices = np.diag_indices(len(D_len))
174 D_len[diag_indices] = basis_lengths[min_index]
175
176 self._displacement_tensor = D
177 self._distance_matrix = D_len
178
179 return self._displacement_tensor
180
181 def get_distance_matrix(self):
182 """Calculates the distance matrix A defined as:

Callers 3

get_distance_matrixMethod · 0.95
test_distancesFunction · 0.95
get_matrixMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_distancesFunction · 0.76