@@ -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
333341def 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." )
0 commit comments