Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if index is False:
return coor, False, None
if point is None:
printx("Error: Could not find generating point.", priority=1)
printx("coordinates:")
printx(str(coor))
printx("Lattice: ")
printx(str(lattice))
printx("group: ")
group.print_all()
return coor, False, None
PBC = group.PBC
# Main loop for merging multiple times
while True:
# Check distances of current WP. If too small, merge
dm = distance_matrix([coor[0]], coor, lattice, PBC=PBC)
passed_distance_check = True
x = np.argwhere(dm < tol)
for y in x:
# Ignore distance from atom to itself
if y[0] == 0 and y[1] == 0:
pass
else:
passed_distance_check = False
break
if passed_distance_check is False:
mult1 = group[index].multiplicity
# Find possible wp's to merge into
possible = []
for i, wp in enumerate(group):
mult2 = wp.multiplicity
v0 = np.array([0.0, 0.0, 0.0])
for v in m:
if not (v == v0).all():
m2.append(v)
if len(m2) > 0:
coords_PBC = np.vstack([coords_mol + v for v in m2])
d = distance_matrix(coords_PBC, coords_mol, self.lattice, PBC=[0, 0, 0])
# only check if small distance is detected
if np.min(d) < np.max(self.tols_matrix):
tols = np.min(d.reshape([len(m2), m_length, m_length]), axis=0)
if (tols < self.tols_matrix).any():
return False
if self.multiplicity > 1:
# Check inter-atomic distances
d = distance_matrix(coords, coords_mol, self.lattice, PBC=self.PBC)
if np.min(d) < np.max(self.tols_matrix):
tols = np.min(
d.reshape([self.multiplicity - 1, m_length, m_length]), axis=0
)
if (tols < self.tols_matrix).any():
return False
return True
"""New method - only checks some atoms/molecules"""
# #Store length of molecule
# m_length = len(self.mol)
# #Get coordinates of center molecule and Wyckoff position
# coords, species = self._get_coords_and_species(absolute=True)
# coords_mol = coords[:m_length]
coords_mol = coords[:m_length]
# Remove generating molecule's coords from large array
coords = coords[m_length:]
if self.PBC != [0, 0, 0]:
# Check periodic images
m = self.create_matrix()
# Remove original coordinates
m2 = []
v0 = np.array([0.0, 0.0, 0.0])
for v in m:
if not (v == v0).all():
m2.append(v)
if len(m2) > 0:
coords_PBC = np.vstack([coords_mol + v for v in m2])
d = distance_matrix(coords_PBC, coords_mol, self.lattice, PBC=[0, 0, 0])
# only check if small distance is detected
if np.min(d) < np.max(self.tols_matrix):
tols = np.min(d.reshape([len(m2), m_length, m_length]), axis=0)
if (tols < self.tols_matrix).any():
return False
if self.multiplicity > 1:
# Check inter-atomic distances
d = distance_matrix(coords, coords_mol, self.lattice, PBC=self.PBC)
if np.min(d) < np.max(self.tols_matrix):
tols = np.min(
d.reshape([self.multiplicity - 1, m_length, m_length]), axis=0
)
if (tols < self.tols_matrix).any():
return False
for i1, number1 in enumerate(ms1.numbers):
for i2, number2 in enumerate(ms2.numbers):
tols[i1][i2] = tm.get_tol(number1, number2)
tols = np.repeat(tols, ms2.multiplicity, axis=1)
d = distance_matrix(coords_mol, c2, ms1.lattice, PBC=ms1.PBC)
# Case 2
elif size1 > size2:
coords_mol = c2[:m_length2]
# Calculate tol matrix for species pairs
tols = np.zeros((m_length2, m_length1))
for i1, number1 in enumerate(ms2.numbers):
for i2, number2 in enumerate(ms1.numbers):
tols[i1][i2] = tm.get_tol(number1, number2)
tols = np.repeat(tols, ms1.multiplicity, axis=1)
d = distance_matrix(coords_mol, c1, ms1.lattice, PBC=ms1.PBC)
# Check if distances are smaller than tolerances
if (d < tols).any():
return False
return True
# Check that length of points and wp are equal
if len(wp) != len(points):
continue
failed = False
# Search for a generating point
for p in points:
failed = False
# Check that point works as x,y,z value for wp
xyz = filtered_coords_euclidean(wp[0].operate(p) - p, PBC=PBC)
if xyz.dot(xyz) > t:
continue
# Calculate distances between original and generated points
pw = np.array([op.operate(p) for op in wp])
dw = distance_matrix(points, pw, None, PBC=PBC, metric="sqeuclidean")
# Check each row for a zero
for row in dw:
num = (row < t).sum()
if num < 1:
failed = True
break
if failed is True:
continue
# Check each column for a zero
for column in dw.T:
num = (column < t).sum()
if num < 1:
failed = True
break
merging, and index is a single index of the Wyckoff position within
the spacegroup. If merging is unsuccesful, or no index is found,
returns the original coordinates and False. point is a 3-vector which can
be plugged into the Wyckoff position to generate the rest of the points
"""
# Get index of current Wyckoff position. If not one, return False
index, point = check_wyckoff_position(coor, group)
if index is False:
return coor, False, None
if point is None:
return coor, False, None
PBC = group.PBC
# Main loop for merging multiple times
while True:
# Check distances of current WP. If too small, merge
dm = distance_matrix([coor[0]], coor, lattice, PBC=PBC)
passed_distance_check = True
for i, x in enumerate(dm):
for j, y in enumerate(x):
if i != j and y < tol:
passed_distance_check = False
break
if passed_distance_check is False:
break
# if check_images([coor[0]], ['C'], lattice, PBC=PBC, tol=tol) is False:
if check_images([coor[0]], [6], lattice, PBC=PBC, tol=tol) is False:
passed_distance_check = False
if passed_distance_check is False:
mult1 = group[index].multiplicity
# Find possible wp's to merge into
possible = []
for i, wp in enumerate(group):
printx("Error: PBC values do not match between Wyckoff sites")
return
# Get tolerance
tol = tm.get_tol(ws1.specie, ws2.specie)
# Symmetry shortcut method: check only some atoms
if same_group is True:
# We can either check one atom in WS1 against all WS2, or vice-versa
# Check which option is faster
if ws1.multiplicity > ws2.multiplicity:
coords1 = [ws1.coords[0]]
coords2 = ws2.coords
else:
coords1 = [ws2.coords[0]]
coords2 = ws1.coords
# Calculate distances
dm = distance_matrix(coords1, coords2, lattice, PBC=ws1.PBC)
# Check if any distances are less than the tolerance
if (dm < tol).any():
return False
else:
return True
# No symmetry method: check all atomic pairs
else:
dm = distance_matrix(ws1.coords, ws2.coords, lattice, PBC=ws1.PBC)
# Check if any distances are less than the tolerance
if (dm < tol).any():
return False
else:
return True