Skip to content

Commit a22ba18

Browse files
committed
enable all tests
1 parent 34c2c5e commit a22ba18

File tree

5 files changed

+423
-17
lines changed

5 files changed

+423
-17
lines changed

pyxtal/XRD_indexer.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ def get_cell_params(spg, hkls, two_thetas, wave_length=1.54184):
7373
if spg >= 195: # cubic, only need a
7474
h_sq_sum = np.sum(hkls**2, axis=1)
7575
cells = d_spacings * np.sqrt(h_sq_sum)
76-
cells = cells[cells < 50.0]
76+
for m in range(len(cells)):
77+
print(cells[m], hkls[m], d_spacings[m], two_thetas[m])
78+
mask = cells < 50.0
79+
cells = cells[mask]
7780
cells = np.reshape(cells, [len(cells), 1])
81+
hkls_out = hkls[mask]
7882

7983
elif 143 <= spg <= 194: # hexagonal, need a and c
8084
# need two hkls to determine a and c
@@ -86,10 +90,14 @@ def get_cell_params(spg, hkls, two_thetas, wave_length=1.54184):
8690
B = np.reshape(ds, [len_solutions, 2])
8791
A = np.reshape(A, [len_solutions, 2, 2])#; print(A.shape, B.shape)
8892
xs = np.linalg.solve(A, B)#; print(xs); import sys; sys.exit()
89-
xs = xs[xs[:, 0] > 0]
90-
xs = xs[xs[:, 1] > 0]
93+
mask1 = np.all(xs[:, :] > 0, axis=1)
94+
hkls_out = np.reshape(hkls, (len_solutions, 6))
95+
hkls_out = hkls_out[mask1]
96+
xs = xs[mask1]
9197
cells = np.sqrt(1/xs)
92-
cells = cells[cells[:, 0] < 50.0]
98+
mask2 = cells[:, 0] < 50.0
99+
cells = cells[mask2]
100+
hkls_out = hkls_out[mask2]
93101

94102
elif 75 <= spg <= 142: # tetragonal, need a and c
95103
# need two hkls to determine a and c
@@ -102,13 +110,13 @@ def get_cell_params(spg, hkls, two_thetas, wave_length=1.54184):
102110
A = np.reshape(A, [len_solutions, 2, 2])#; print(A.shape, B.shape)
103111
xs = np.linalg.solve(A, B)#; print(xs); import sys; sys.exit()
104112
mask1 = np.all(xs[:, :] > 0, axis=1)
105-
hkls = np.reshape(hkls, (len_solutions, 6))
106-
hkls = hkls[mask1]
113+
hkls_out = np.reshape(hkls, (len_solutions, 6))
114+
hkls_out = hkls_out[mask1]
107115
xs = xs[mask1]
108116
cells = np.sqrt(1/xs)
109117
mask2 = np.all(cells[:, :2] < 50.0, axis=1)
110118
cells = cells[mask2]
111-
hkls = hkls[mask2]
119+
hkls_out = hkls_out[mask2]
112120

113121
elif 16 <= spg <= 74: # orthorhombic, need a, b, c
114122
# need three hkls to determine a, b, c
@@ -331,7 +339,7 @@ def get_seeds(spg, hkls, two_thetas):
331339

332340

333341
def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_length=1.54184,
334-
tolerance=0.05, use_seed=True, min_score=0.999):
342+
tolerance=0.05, use_seed=True, min_score=0.99):
335343
"""
336344
Estimate the cell parameters from multiple (hkl, two_theta) inputs.
337345
The idea is to use the Bragg's law and the lattice spacing formula to estimate the lattice parameters.
@@ -427,7 +435,7 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
427435
avg_error = np.mean([match[-1] for match in matched_peaks])
428436
consistency_score = 1.0 / (1.0 + avg_error) # lower error = higher score
429437
score = coverage * consistency_score
430-
#print("Cell:", cell, "Matched:", n_matched, "Score:", score)
438+
#print("Cell:", cell, hkls[i], "Score:", score)
431439

432440
if score > min_score:
433441
solutions.append({
@@ -449,8 +457,11 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
449457
#xtal.from_seed('pyxtal/database/cifs/JVASP-62168.cif') # 52s -> 16s
450458
#xtal.from_seed('pyxtal/database/cifs/JVASP-98225.cif') # P21/c -> 33s -> 12s
451459
#xtal.from_seed('pyxtal/database/cifs/JVASP-50935.cif') # Pm -> 45s -> 7.6s
452-
#xtal.from_seed('pyxtal/database/cifs/JVASP-28565.cif') # 207s -> 91s -> 80s -> 72s
453-
xtal.from_seed('pyxtal/database/cifs/JVASP-47532.cif') #
460+
xtal.from_seed('pyxtal/database/cifs/JVASP-28565.cif') # 207s -> 91s -> 80s -> 72s
461+
#xtal.from_seed('pyxtal/database/cifs/JVASP-47532.cif') #
462+
#xtal.from_seed('pyxtal/database/cifs/JVASP-28634.cif', tol=1e-4) # P21/c -> 33s -> 12s
463+
#xtal.from_seed('pyxtal/database/cifs/JVASP-97915.cif', tol=1e-4) # P21/c -> 33s -> 12s
464+
#xtal.from_seed('pyxtal/database/cifs/JVASP-86205.cif', tol=1e-4) # P21/c -> 33s -> 12s
454465

455466
xrd = xtal.get_XRD(thetas=[0, 120], SCALED_INTENSITY_TOL=0.5)
456467
cell_ref = np.sort(np.array(xtal.lattice.encode()))
@@ -466,7 +477,8 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
466477
if spg in [5, 8, 12, 15]:
467478
guesses = xtal.group.generate_hkl_guesses(3, 3, 6, max_square=38, total_square=40, verbose=True)
468479
else:
469-
guesses = xtal.group.generate_hkl_guesses(3, 3, 4, max_square=29, total_square=35, verbose=True)
480+
#guesses = xtal.group.generate_hkl_guesses(3, 3, 4, max_square=29, total_square=35, verbose=True)
481+
guesses = xtal.group.generate_hkl_guesses(3, 3, 3, max_square=15, total_square=36, verbose=True)
470482
guesses = np.array(guesses)
471483
print("Total guesses:", len(guesses))
472484
sum_squares = np.sum(guesses**2, axis=(1,2))
@@ -483,16 +495,19 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
483495
cell2 = np.sort(np.array(xtal.lattice.encode()))
484496
if spg <= 15 and cell2[3] > 90: cell2[3] = 180 - cell2[3]
485497
cells_all = np.reshape(cell2, (1, len(cell2)))
498+
486499
# Try each combination of n peaks from the first n+1 peaks
487500
n_peaks = len(guesses[0])
488-
available_peaks = xrd.pxrd[:n_peaks + N_add, 0]
501+
N = min(n_peaks + N_add, len(xrd.pxrd))
502+
available_peaks = xrd.pxrd[:N, 0]
503+
489504
thetas = []
490505
for peak_combo in combinations(range(n_peaks + N_add), n_peaks):
491506
thetas.extend(available_peaks[list(peak_combo)])
492507
N_thetas = len(thetas) // n_peaks
493508
thetas = np.array(thetas)
494509
thetas = np.tile(thetas, N_batch)
495-
510+
print(n_peaks, len(long_thetas))#; import sys; sys.exit()
496511
found = False
497512
d2 = 0
498513
for i in range(len(guesses)//N_batch + 1):
@@ -503,7 +518,13 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
503518
else:
504519
thetas = thetas[:N_thetas * n_peaks * N_batch]
505520
hkls_b = np.reshape(guesses[N_batch*i:N_batch*(i+1)], [N_batch*n_peaks, 3])
506-
hkls_t = np.tile(hkls_b, (N_thetas, 1))
521+
if spg >= 195:
522+
hkls_t = np.tile(hkls_b, (1, N_thetas))
523+
hkls_t = np.reshape(hkls_t, [N_batch*N_thetas*n_peaks, 3])
524+
else:
525+
hkls_t = np.tile(hkls_b, (N_thetas, 1))
526+
#print('hkl shape:', hkls_b.shape, hkls_t.shape)
527+
#print('thetas shape:', thetas.shape)
507528
solutions = get_cell_from_multi_hkls(spg, hkls_t, thetas, long_thetas, use_seed=False)
508529
if i % 1000 == 0:
509530
print(f"Processed {N_batch*(i)}/{d2}, found {len(cells_all)-1} cells so far.")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#############################################################
2+
# ______ _ _ _ #
3+
# (_____ \ \ \ / / | | #
4+
# _____) ) _ \ \/ / |_ ____| | #
5+
# | ____/ | | | ) (| _)/ _ | | #
6+
# | | | |_| |/ /\ \ |_( (_| | |___ #
7+
# |_| \__ /_/ \_\___)__|_|_____) #
8+
# (____/ #
9+
#---------------------(version 1.1.1)--------------------#
10+
# A Python package for random crystal generation #
11+
# url: https://github.com/qzhu2017/pyxtal #
12+
# @Zhu's group at U. North Carolina at Charlotte #
13+
#############################################################
14+
data_from_pyxtal
15+
16+
_symmetry_space_group_name_H-M 'Cm'
17+
_symmetry_Int_Tables_number 8
18+
_symmetry_cell_setting monoclinic
19+
_cell_length_a 5.585948
20+
_cell_length_b 3.225049
21+
_cell_length_c 34.140684
22+
_cell_angle_alpha 90.000000
23+
_cell_angle_beta 90.000337
24+
_cell_angle_gamma 90.000000
25+
_cell_volume 615.043027
26+
27+
loop_
28+
_symmetry_equiv_pos_site_id
29+
_symmetry_equiv_pos_as_xyz
30+
1 'x, y, z'
31+
2 'x, -y, z'
32+
3 'x+1/2, y+1/2, z'
33+
4 'x+1/2, -y+1/2, z'
34+
35+
loop_
36+
_atom_site_label
37+
_atom_site_type_symbol
38+
_atom_site_symmetry_multiplicity
39+
_atom_site_fract_x
40+
_atom_site_fract_y
41+
_atom_site_fract_z
42+
_atom_site_occupancy
43+
Mo Mo 2 0.666685 0.000000 0.906546 1
44+
W W 2 0.666683 0.000000 0.527914 1
45+
W W 2 0.333330 0.000000 0.717520 1
46+
W W 2 0.333301 0.000000 0.345107 1
47+
Se Se 2 0.666656 0.000000 0.667102 1
48+
Se Se 2 0.666672 0.000000 0.767938 1
49+
S S 2 0.666626 0.000000 0.299323 1
50+
S S 2 0.333352 0.000000 0.952081 1
51+
S S 2 0.333351 0.000000 0.573744 1
52+
S S 2 0.333352 0.000000 0.860953 1
53+
S S 2 0.333349 0.000000 0.482099 1
54+
S S 2 0.666643 0.000000 0.390925 1
55+
#END
56+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#############################################################
2+
# ______ _ _ _ #
3+
# (_____ \ \ \ / / | | #
4+
# _____) ) _ \ \/ / |_ ____| | #
5+
# | ____/ | | | ) (| _)/ _ | | #
6+
# | | | |_| |/ /\ \ |_( (_| | |___ #
7+
# |_| \__ /_/ \_\___)__|_|_____) #
8+
# (____/ #
9+
#---------------------(version 1.1.1)--------------------#
10+
# A Python package for random crystal generation #
11+
# url: https://github.com/qzhu2017/pyxtal #
12+
# @Zhu's group at U. North Carolina at Charlotte #
13+
#############################################################
14+
data_from_pyxtal
15+
16+
_symmetry_space_group_name_H-M 'Im-3'
17+
_symmetry_Int_Tables_number 204
18+
_symmetry_cell_setting cubic
19+
_cell_length_a 9.442214
20+
_cell_length_b 9.442214
21+
_cell_length_c 9.442214
22+
_cell_angle_alpha 90.000000
23+
_cell_angle_beta 90.000000
24+
_cell_angle_gamma 90.000000
25+
_cell_volume 841.824379
26+
27+
loop_
28+
_symmetry_equiv_pos_site_id
29+
_symmetry_equiv_pos_as_xyz
30+
1 'x, y, z'
31+
2 '-x, -y, z'
32+
3 '-x, y, -z'
33+
4 'x, -y, -z'
34+
5 'z, x, y'
35+
6 'z, -x, -y'
36+
7 '-z, -x, y'
37+
8 '-z, x, -y'
38+
9 'y, z, x'
39+
10 '-y, z, -x'
40+
11 'y, -z, -x'
41+
12 '-y, -z, x'
42+
13 '-x, -y, -z'
43+
14 'x, y, -z'
44+
15 'x, -y, z'
45+
16 '-x, y, z'
46+
17 '-z, -x, -y'
47+
18 '-z, x, y'
48+
19 'z, x, -y'
49+
20 'z, -x, y'
50+
21 '-y, -z, -x'
51+
22 'y, -z, x'
52+
23 '-y, z, x'
53+
24 'y, z, -x'
54+
25 'x+1/2, y+1/2, z+1/2'
55+
26 '-x+1/2, -y+1/2, z+1/2'
56+
27 '-x+1/2, y+1/2, -z+1/2'
57+
28 'x+1/2, -y+1/2, -z+1/2'
58+
29 'z+1/2, x+1/2, y+1/2'
59+
30 'z+1/2, -x+1/2, -y+1/2'
60+
31 '-z+1/2, -x+1/2, y+1/2'
61+
32 '-z+1/2, x+1/2, -y+1/2'
62+
33 'y+1/2, z+1/2, x+1/2'
63+
34 '-y+1/2, z+1/2, -x+1/2'
64+
35 'y+1/2, -z+1/2, -x+1/2'
65+
36 '-y+1/2, -z+1/2, x+1/2'
66+
37 '-x+1/2, -y+1/2, -z+1/2'
67+
38 'x+1/2, y+1/2, -z+1/2'
68+
39 'x+1/2, -y+1/2, z+1/2'
69+
40 '-x+1/2, y+1/2, z+1/2'
70+
41 '-z+1/2, -x+1/2, -y+1/2'
71+
42 '-z+1/2, x+1/2, y+1/2'
72+
43 'z+1/2, x+1/2, -y+1/2'
73+
44 'z+1/2, -x+1/2, y+1/2'
74+
45 '-y+1/2, -z+1/2, -x+1/2'
75+
46 'y+1/2, -z+1/2, x+1/2'
76+
47 '-y+1/2, z+1/2, x+1/2'
77+
48 'y+1/2, z+1/2, -x+1/2'
78+
79+
loop_
80+
_atom_site_label
81+
_atom_site_type_symbol
82+
_atom_site_symmetry_multiplicity
83+
_atom_site_fract_x
84+
_atom_site_fract_y
85+
_atom_site_fract_z
86+
_atom_site_occupancy
87+
Sm Sm 2 0.000000 0.000000 0.000000 1
88+
Sb Sb 24 0.000000 0.337974 0.155972 1
89+
Os Os 8 0.250000 0.250000 0.250000 1
90+
#END
91+

0 commit comments

Comments
 (0)