Skip to content

Commit

Permalink
fix distance checker MaterSim#218#
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Jul 8, 2023
1 parent 8164b6c commit 4d8383e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include /*.py
include database/*.py
include database/*.csv
include database/*.json
include database/*.json
5 changes: 4 additions & 1 deletion pyxtal/molecular_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,12 @@ def _set_mol_wyckoffs(self, id, numMol, pyxtal_mol, valid_ori, mol_wyks):
if ms0 is not None:
# Check current WP against existing WP's
passed_wp_check = True
for ms1 in mol_sites_tmp + mol_wyks:
#print("Checking", ms0)
for ms1 in mol_wyks + mol_sites_tmp:
if not ms0.short_dist_with_wp2(ms1, tm=self.tol_matrix):
passed_wp_check = False
#else:
# print("passing", ms1)

if passed_wp_check:
if sites_list is not None:
Expand Down
27 changes: 14 additions & 13 deletions pyxtal/wyckoff_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ def _get_coords_and_species(self, absolute=False, PBC=False, first=False, unitce
#op2_m = self.wp.generators_m[point_index]
op2_m = self.wp.get_euclidean_generator(self.lattice.matrix, point_index)
rot = op2_m.affine_matrix[:3, :3].T
#NOTE=====the euclidean_generator has wrong translation vectors,
#but we don't care. This needs to be fixed later
# NOTE=====the euclidean_generator has wrong translation vectors,
# but we don't care. This needs to be fixed later

#if self.diag and self.wp.index > 0:
# tau = op2.translation_vector
Expand Down Expand Up @@ -723,7 +723,7 @@ def update(self, coords, lattice=None, absolute=False, update_mol=True):
mol.to(filename='Wrong.xyz', fmt='xyz')
self.mol.to(filename='Ref.xyz', fmt='xyz')
raise ValueError("molecular connectivity changes! Exit")
#todo check if connectivty changed
# todo check if connectivty changed

def _create_matrix(self, center=False, ignore=False):
"""
Expand All @@ -744,7 +744,7 @@ def _create_matrix(self, center=False, ignore=False):
ijk_lists = []
for id in range(3):
if self.PBC[id]:
if not ignore and abc[id] > 20 and self.radius<10:
if not ignore and abc[id] > 25 and self.radius < 10:
ijk_lists.append([0])
elif abc[id] < 7.0:
ijk_lists.append([-3, -2, -1, 0, 1, 2, 3])
Expand All @@ -762,7 +762,7 @@ def _create_matrix(self, center=False, ignore=False):
for k in ijk_lists[2]:
if [i, j, k] != [0, 0, 0]:
matrix.append([i, j, k])
#In case a,b,c are all greater than 20
# In case a,b,c are all greater than 20
if len(matrix) == 0:
matrix = [[1,0,0]]
return np.array(matrix, dtype=float)
Expand All @@ -784,15 +784,14 @@ def get_distances(self, coord1, coord2, m2=None, center=True, ignore=False):
coord2 under PBC: [pbc, m2, 3]
"""
m1 = len(coord1)
if m2 is None:
m2 = m1
if m2 is None: m2 = m1
N2 = int(len(coord2)/m2)

#peridoic images
# peridoic images
m = self._create_matrix(center, ignore) #PBC matrix
coord2 = np.vstack([coord2 + v for v in m])

#absolute xyz
# absolute xyz
coord1 = np.dot(coord1, self.lattice.matrix)
coord2 = np.dot(coord2, self.lattice.matrix)

Expand Down Expand Up @@ -839,15 +838,15 @@ def get_min_dist(self):
Returns:
minimum distance
"""
#Self image
# Self image
ds, _ = self.get_dists_auto()
min_dist = np.min(ds)

if min_dist < 0.9:
#terminate earlier
# terminate earlier
return min_dist
else:
#Other molecules
# Other molecules
if self.wp.multiplicity > 1:
ds, _ = self.get_dists_WP()
if min_dist > np.min(ds):
Expand Down Expand Up @@ -910,7 +909,9 @@ def short_dist_with_wp2(self, wp2, tm=Tol_matrix(prototype="molecular")):
m2 = m_length1

# compute the distance matrix
d, _ = self.get_distances(coord1, coord2, m2)
d, _ = self.get_distances(coord1-np.floor(coord1), coord2-np.floor(coord2), m2)
#print("short dist", len(c1), len(c2), d.min())

if np.min(d) < np.max(tols_matrix):
tols = np.min(d, axis=0)
if (tols < tols_matrix).any():
Expand Down

0 comments on commit 4d8383e

Please sign in to comment.