@@ -126,14 +126,14 @@ def get_cell_params(spg, hkls, two_thetas, wave_length=1.54184):
126126 A [:, 1 ] = hkls [:, 1 ] ** 2
127127 A [:, 2 ] = hkls [:, 2 ] ** 2
128128 B = np .reshape (ds , [len_solutions , 3 ])
129- A = np .reshape (A , [len_solutions , 3 , 3 ])#; print(A.shape, B.shape)
129+ A = np .reshape (A , [len_solutions , 3 , 3 ])
130130 xs = np .linalg .solve (A , B )#; print(xs); import sys; sys.exit()
131131 mask1 = np .all (xs [:, :] > 0 , axis = 1 )
132132 hkls_out = np .reshape (hkls , (len_solutions , 9 ))
133133 hkls_out = hkls_out [mask1 ]
134134 xs = xs [mask1 ]
135135 cells = np .sqrt (1 / xs )
136- mask2 = np .all (cells [:, :3 ] < 50 .0 , axis = 1 )
136+ mask2 = np .all (cells [:, :3 ] < 65 .0 , axis = 1 )
137137 cells = cells [mask2 ]
138138 hkls_out = hkls_out [mask2 ]
139139
@@ -336,6 +336,45 @@ def get_seeds(spg, hkls, two_thetas):
336336 return seed_hkls , seed_thetas
337337
338338
339+ def get_unique_thetas (xrd , spg ):
340+
341+ if spg >= 195 :
342+ unique_thetas = xrd .pxrd [:20 ,0 ]
343+ else :
344+ # deal with (001, 002, 003) for spg < 195
345+ int_counts = []
346+ for jj in range (1 , 5 ):
347+ ratio = np .sin (np .radians (xrd .pxrd [jj ,0 ]/ 2 ))/ np .sin (np .radians (xrd .pxrd [0 ,0 ]/ 2 ))
348+ if ratio > 1.1 and abs (ratio - round (ratio )) < 0.01 :
349+ int_counts .append (jj )
350+ # in case two are related
351+ if 1 not in int_counts :
352+ for jj in range (2 , 10 ):
353+ ratio = np .sin (np .radians (xrd .pxrd [jj ,0 ]/ 2 ))/ np .sin (np .radians (xrd .pxrd [1 ,0 ]/ 2 ))
354+ if ratio > 1.1 and abs (ratio - round (ratio )) < 0.01 :
355+ int_counts .append (jj )
356+
357+ # if more than three ratios are close to integers, only keep the first peak
358+ if len (int_counts ) > 0 :
359+ unique_thetas = []
360+ for jj in range (min (15 , len (xrd .pxrd ))):
361+ if jj == 0 or jj not in int_counts :
362+ unique_thetas .append (xrd .pxrd [jj , 0 ])
363+ unique_thetas = np .array (unique_thetas )
364+ print ('processed' , unique_thetas )
365+ else :
366+ unique_thetas = xrd .pxrd [:min ([15 , len (xrd .pxrd )]), 0 ]
367+
368+ # Remove two consecutive peaks that are very close
369+ filtered_thetas = [unique_thetas [0 ]]
370+ for jj in range (1 , len (unique_thetas )):
371+ if abs (unique_thetas [jj ] - unique_thetas [jj - 1 ]) > 0.02 :
372+ filtered_thetas .append (unique_thetas [jj ])
373+ unique_thetas = np .array (filtered_thetas )
374+ print ("Final thetas:" , unique_thetas )
375+ return unique_thetas
376+
377+
339378def get_cell_from_multi_hkls (spg , hkls , two_thetas , long_thetas = None , wave_length = 1.54184 ,
340379 tolerance = 0.1 , use_seed = True , min_score = 0.999 ):
341380 """
@@ -427,11 +466,12 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
427466 n_matched = len (matched_peaks )
428467 coverage = n_matched / len (long_thetas )
429468 avg_error = np .mean ([match [- 1 ] for match in matched_peaks ])
430- consistency_score = 1.0 / (1.0 + avg_error )
469+ consistency_score = 1.0 / (1.0 + avg_error )
431470 score = coverage * consistency_score
432471 #unmatches = exp_thetas[~within_tolerance.all(axis=0)]
433472 #mask = (unmatches > long_thetas[0]) & (unmatches < long_thetas[-1])
434473 #unmatches = exp_hkls[mask]
474+ #print(cell, score, hkls[i], two_thetas)
435475
436476 if score > min_score :
437477 solutions .append ({
@@ -465,7 +505,12 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
465505 #'pyxtal/database/cifs/JVASP-28565.cif', # Cm, 100s
466506 #'pyxtal/database/cifs/JVASP-36885.cif', # Cm, 100s
467507 #'pyxtal/database/cifs/JVASP-42300.cif', # C2, 178s
468- 'pyxtal/database/cifs/JVASP-47532.cif' , # P2/m,
508+ #'pyxtal/database/cifs/JVASP-47532.cif', # P2/m,
509+ #'pyxtal/database/cifs/JVASP-25063.cif', # bad slab
510+ #'pyxtal/database/cifs/JVASP-119184.cif', # Imm2 44
511+ #'pyxtal/database/cifs/JVASP-141590.cif', # R-3m 166
512+ #'pyxtal/database/cifs/JVASP-45907.cif', # R-3m 166
513+ 'pyxtal/database/cifs/JVASP-119739.cif' , # C2/m 12
469514 ]:
470515 t0 = time ()
471516 xtal .from_seed (cif )
@@ -474,7 +519,7 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
474519 long_thetas = xrd .pxrd [:15 , 0 ]
475520 spg = xtal .group .number
476521 print ("\n " , cif , xtal .lattice , xtal .group .symbol , xtal .group .number )
477- print (xrd .by_hkl (N_max = 10 ))
522+ print (xrd .by_hkl (N_max = 20 ))
478523
479524 # Get the a list of hkl guesses and sort them by d^2
480525 if spg >= 195 :
@@ -484,13 +529,16 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
484529 else :
485530 min_score , N_add , N_batch = 0.999 , 8 , 20
486531
487- if spg >= 16 :
532+ if spg >= 75 :
533+ guesses = xtal .group .generate_hkl_guesses (2 , 3 , 10 , max_square = 101 , total_square = 110 , verbose = True )
534+ elif spg >= 16 :
488535 guesses = xtal .group .generate_hkl_guesses (2 , 2 , 5 , max_square = 29 , total_square = 40 , verbose = True )
536+ #guesses = xtal.group.generate_hkl_guesses(2, 2, 2, max_square=29, total_square=40, verbose=True)
489537 else :
490538 if spg in [5 , 8 , 12 , 15 ]:
491539 guesses = xtal .group .generate_hkl_guesses (3 , 3 , 5 , max_square = 29 , total_square = 40 , verbose = True )
492540 else :
493- guesses = xtal .group .generate_hkl_guesses (3 , 3 , 4 , max_square = 29 , total_square = 35 , verbose = True )
541+ guesses = xtal .group .generate_hkl_guesses (4 , 3 , 4 , max_square = 29 , total_square = 35 , verbose = True )
494542 #guesses = xtal.group.generate_hkl_guesses(3, 3, 3, max_square=15, total_square=36, verbose=True)
495543
496544 guesses = np .array (guesses )
@@ -499,7 +547,7 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
499547 sorted_indices = np .argsort (sum_squares )
500548 guesses = guesses [sorted_indices ]
501549 if len (guesses ) > 500000 : guesses = guesses [:500000 ]
502- #guesses = np.array([[[2 , 0, 0 ], [1, 1, 0], [0, 1, 1 ], [0, 0, 2 ]]])
550+ #guesses = np.array([[[0 , 0, 2 ], [1, 0, 1 ], [0, 1, 3 ]]])
503551 #guesses = np.array([[[2, 0, 0], [1, 1, 0], [0, 0, 2], [2, 0, -2]]])
504552 #guesses = np.array([[[0, 0, -1], [1, 1, 0], [1, 1, -1], [0, 2, -5]]])
505553
@@ -509,9 +557,10 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
509557 cells_all = np .reshape (cell2 , (1 , len (cell2 )))
510558
511559 # Try each combination of n peaks from the first n+1 peaks
560+ unique_thetas = get_unique_thetas (xrd , spg )
512561 n_peaks = len (guesses [0 ])
513- N = min (n_peaks + N_add , len (xrd . pxrd ))
514- available_peaks = xrd . pxrd [:N , 0 ]
562+ N = min (n_peaks + N_add , len (unique_thetas ))
563+ available_peaks = unique_thetas [:N ]; print ( available_peaks )
515564
516565 thetas = []
517566 for peak_combo in combinations (range (n_peaks + N_add ), n_peaks ):
@@ -532,7 +581,7 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
532581 hkls_t = np .reshape (hkls_t , (- 1 , 3 ))#, order='F')
533582 solutions = get_cell_from_multi_hkls (spg , hkls_t , thetas , long_thetas , min_score = min_score , use_seed = False )
534583 if i % 1000 == 0 :
535- print (f"Processed { N_batch * ( i ) } /{ d2 } , found { len (cells_all )- 1 } cells." )
584+ print (f"Processed { N_batch * i } /{ d2 } , found { len (cells_all )- 1 } cells." )
536585
537586 for sol in solutions :
538587 cell1 = np .sort (np .array (sol ['cell' ]))
@@ -555,9 +604,9 @@ def get_cell_from_multi_hkls(spg, hkls, two_thetas, long_thetas=None, wave_lengt
555604 if found :
556605 break
557606 t1 = time ()
558- data .append ((cif , spg , d2 , len (cells_all ), score , t1 - t0 ))
607+ data .append ((cif , spg , d2 , i * N_batch , len (cells_all ), score , t1 - t0 ))
559608
560- for d in data :
609+ for d in data :
561610 print (d )
562611"""
563612('pyxtal/database/cifs/JVASP-97915.cif', 225, 11, 1, 0.9944178674744656, 0.8724310398101807)
0 commit comments