@@ -4493,7 +4493,7 @@ def LoadUnitCell(event):
44934493
44944494 # TODO: I think this used to work, but this needs to be revisited due to
44954495 # AttributeError: 'G2DataWindow' object has no attribute 'ReImportMenuId'
4496- # from:
4496+ # from:
44974497 # reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId())
44984498 #
44994499 # def ImportUnitCell(event):
@@ -5163,15 +5163,15 @@ def _showWebPage(event):
51635163 txt = event .GetEventObject ().page
51645164 tmp = tempfile .NamedTemporaryFile (suffix = '.html' ,delete = False )
51655165 with open (tmp .name ,'w' ) as fp :
5166- fp .write (txt .replace ('<HEAD>' ,'<head><base href="https://stokes.byu.edu/iso/ ">' ,))
5166+ fp .write (txt .replace ('<HEAD>' ,'<head><base href="https://stokes.byu.edu/">' ,))
51675167 fileList .append (tmp .name )
51685168 G2G .ShowWebPage ('file://' + tmp .name ,G2frame )
51695169
51705170 def showWebtext (txt ):
51715171 import tempfile
51725172 tmp = tempfile .NamedTemporaryFile (suffix = '.html' ,delete = False )
51735173 with open (tmp .name ,'w' ) as fp :
5174- fp .write (txt .replace ('<HEAD>' ,'<head><base href="https://stokes.byu.edu/iso/ ">' ,))
5174+ fp .write (txt .replace ('<HEAD>' ,'<head><base href="https://stokes.byu.edu/">' ,))
51755175 fileList .append (tmp .name )
51765176 G2G .ShowWebPage ('file://' + tmp .name ,G2frame )
51775177
@@ -5180,82 +5180,131 @@ def _get_opt_val(opt_name, out):
51805180 opt_match = re .search (opt_pattern , out )
51815181
51825182 return opt_match .group (1 )
5183-
5184- def setup_kvec_input (k_vec ):
5183+
5184+ def grab_all_kvecs (out_html ):
5185+ """Extract all k-vectors from the ISODISTORT output HTML."""
5186+ from fractions import Fraction
5187+ import re
5188+
5189+ kvec1_pattern = r'<SELECT NAME="kvec1">(.*?)</SELECT>'
5190+ kvec1_match = re .search (kvec1_pattern , out_html , re .DOTALL )
5191+
5192+ if kvec1_match :
5193+ select_content = kvec1_match .group (1 )
5194+
5195+ # Extract option values
5196+ option_pattern = r'<OPTION VALUE="([^"]*)"[^>]*>([^<]*)</OPTION>'
5197+ options = re .findall (option_pattern , select_content )
5198+
5199+ final_kvec_keys = []
5200+ for value , _ in options :
5201+ final_kvec_keys .append (value )
5202+
5203+ all_kvecs = {}
5204+ for key in final_kvec_keys :
5205+ pattern_str = key .split ("(" )[1 ].split (")" )[0 ]
5206+ a_val = pattern_str .split ("," )[0 ]
5207+ b_val = pattern_str .split ("," )[1 ]
5208+ c_val = pattern_str .split ("," )[2 ]
5209+ if a_val == "1/2" :
5210+ a_val = Fraction (1 , 2 )
5211+ elif a_val == "1/3" :
5212+ a_val = Fraction (1 , 3 )
5213+ elif a_val == "1" :
5214+ a_val = 1
5215+ elif a_val == "0" :
5216+ a_val = 0
5217+
5218+ if b_val == "1/2" :
5219+ b_val = Fraction (1 , 2 )
5220+ elif b_val == "1/3" :
5221+ b_val = Fraction (1 , 3 )
5222+ elif b_val == "1" :
5223+ b_val = 1
5224+ elif b_val == "0" :
5225+ b_val = 0
5226+
5227+ if c_val == "1/2" :
5228+ c_val = Fraction (1 , 2 )
5229+ elif c_val == "1/3" :
5230+ c_val = Fraction (1 , 3 )
5231+ elif c_val == "1" :
5232+ c_val = 1
5233+ elif c_val == "0" :
5234+ c_val = 0
5235+
5236+ all_kvecs [key ] = (a_val , b_val , c_val )
5237+
5238+ return all_kvecs
5239+ else :
5240+ return None
5241+
5242+ def setup_kvec_input (k_vec , k_vec_dict , symmetry = None ):
51855243 """Set up the input for isodistort post request
51865244
51875245 Args:
51885246 k_vec (str): The k-vector to use for the isodistort request.
5247+ k_vec_dict (dict): The dictionary containing the k-vector
5248+ form extracted from isodistort.
5249+ symmetry (str, optional): The crystal system.
51895250
51905251 Returns:
51915252 dict: New entries and those need to be corrected in the data
51925253 to be used in the post request.
51935254 """
5194- from fractions import Fraction
5195-
5196- k_vec_dict = {
5197- " 1 *GM, k16 (0,0,0)" : (0 , 0 , 0 ),
5198- " 2 *DT, k11 (0,0,g)" : (0 , 0 , "a" ),
5199- " 3 *LD, k6 (a,a,0)" : ("a" , "a" , 0 ),
5200- " 4 *SM, k5 (a,0,0)" : ("a" , 0 , 0 ),
5201- " 5 *A, k17 (0,0,1/2)" : (0 , 0 , Fraction (1 , 2 )),
5202- " 6 *H, k15 (1/3,1/3,1/2)" : (
5203- Fraction (1 , 3 ),
5204- Fraction (1 , 3 ),
5205- Fraction (1 , 2 )
5206- ),
5207- " 7 *K, k13 (1/3,1/3,0)" : (Fraction (1 , 3 ), Fraction (1 , 3 ), 0 ),
5208- " 8 *L, k14 (1/2,0,1/2)" : (Fraction (1 , 2 ), 0 , Fraction (1 , 2 )),
5209- " 9 *M, k12 (1/2,0,0)" : (Fraction (1 , 2 ), 0 , 0 ),
5210- "10 *P, k10 (1/3,1/3,g)" : (
5211- Fraction (1 , 3 ),
5212- Fraction (1 , 3 ),
5213- "g"
5214- ),
5215- "11 *Q, k8 (a,a,1/2)" : ("a" , "a" , Fraction (1 , 2 )),
5216- "12 *R, k7 (a,0,1/2)" : ("a" , 0 , Fraction (1 , 2 )),
5217- "13 *U, k9 (1/2,0,g)" : (Fraction (1 , 2 ), 0 , "g" ),
5218- "14 *B, k1 (a,b,0)" : ("a" , "b" , 0 ),
5219- "15 *C, k4 (a,a,g)" : ("a" , "a" , "g" ),
5220- "16 *D, k3 (a,0,g)" : ("a" , 0 , "g" ),
5221- "17 *E, k2 (a,b,1/2)" : ("a" , "b" , Fraction (1 , 2 )),
5222- "18 *GP, k0 (a,b,g)" : ("a" , "b" , "g" )
5223- }
5224-
5225- def match_vector_pattern (k_vec , k_vec_dict ):
5255+ def match_vector_pattern (k_vec , k_vec_dict , symmetry = None ):
52265256 """Check the k-vector against the standard form in isodistort.
52275257
52285258 Args:
5229- k_vec (str): The k-vector to use for the isodistort
5230- request.
5231- k_vec_dict (dict): The standard k-vector form in
5232- isodistort.
5259+ k_vec (str): The k-vector to use for the isodistort request.
5260+ k_vec_dict (dict): The standard k-vector form in isodistort.
5261+ symmetry (str, optional): The crystal system.
52335262
52345263 Returns:
52355264 str: The standard k-vector form in isodistort.
52365265 """
5266+ from itertools import permutations
5267+
52375268 all_matches = list ()
5269+
52385270 for desc , pattern in k_vec_dict .items ():
52395271 if len (pattern ) != len (k_vec ):
52405272 continue
5241- placeholders = {}
5242- match = True
5243- for p_val , k_val in zip (pattern , k_vec ):
5244- if isinstance (p_val , str ):
5245- if p_val .isalpha ():
5246- if p_val not in placeholders :
5247- placeholders [p_val ] = k_val
5248- elif placeholders [p_val ] != k_val :
5273+
5274+ # Generate sequences to check based on symmetry
5275+ if symmetry == 'cubic' :
5276+ # For cubic symmetry, check all permutations of k_vec
5277+ k_vec_sequences = list (permutations (k_vec ))
5278+ else :
5279+ # For other symmetries, maintain original order
5280+ k_vec_sequences = [k_vec ]
5281+
5282+ # Check if any permutation matches the pattern
5283+ pattern_matched = False
5284+ for k_vec_seq in k_vec_sequences :
5285+ placeholders = {}
5286+ match = True
5287+ for p_val , k_val in zip (pattern , k_vec_seq ):
5288+ if isinstance (p_val , str ):
5289+ if p_val .isalpha ():
5290+ if p_val not in placeholders :
5291+ placeholders [p_val ] = k_val
5292+ elif placeholders [p_val ] != k_val :
5293+ match = False
5294+ break
5295+ else :
52495296 match = False
52505297 break
52515298 else :
5252- match = False
5253- break
5254- else :
5255- if p_val != k_val :
5256- match = False
5257- break
5258- if match :
5299+ if p_val != k_val :
5300+ match = False
5301+ break
5302+
5303+ if match :
5304+ pattern_matched = True
5305+ break
5306+
5307+ if pattern_matched :
52595308 all_matches .append (desc )
52605309
52615310 idp_params_num = 3
@@ -5271,7 +5320,7 @@ def match_vector_pattern(k_vec, k_vec_dict):
52715320
52725321 return final_match
52735322
5274- k_vec_form = match_vector_pattern (k_vec , k_vec_dict )
5323+ k_vec_form = match_vector_pattern (k_vec , k_vec_dict , symmetry = "cubic" )
52755324
52765325 data_update = dict ()
52775326 data_update ['kvec1' ] = k_vec_form
@@ -5298,7 +5347,7 @@ def match_vector_pattern(k_vec, k_vec_dict):
52985347 from fractions import Fraction
52995348 from GSASII .exports import G2export_CIF
53005349 from . import ISODISTORT as ISO
5301- isoformsite = 'https://iso.byu.edu/iso/ isodistortform.php'
5350+ isoformsite = 'https://iso.byu.edu/isodistortform.php'
53025351
53035352 if not G2frame .kvecSearch ['mode' ]:
53045353 return
@@ -5313,7 +5362,7 @@ def match_vector_pattern(k_vec, k_vec_dict):
53135362
53145363 if kpoint is None :
53155364 wx .MessageBox (
5316- "Please select a k-vector from the table." ,
5365+ "Please select a k-vector from the table." ,
53175366 style = wx .ICON_INFORMATION ,
53185367 caption = 'Isotropic Subgroup Generation'
53195368 )
@@ -5329,7 +5378,7 @@ def match_vector_pattern(k_vec, k_vec_dict):
53295378 This can take up to a few minutes. Check the terminal for progress.
53305379 '''
53315380 wx .MessageBox (
5332- f"{ isoCite } \n \n { info_str } " ,
5381+ f"{ isoCite } \n \n { info_str } " ,
53335382 style = wx .ICON_INFORMATION ,
53345383 caption = 'Isotropic Subgroup Generation'
53355384 )
@@ -5438,7 +5487,9 @@ def match_vector_pattern(k_vec, k_vec_dict):
54385487 data ['input' ] = 'kvector'
54395488 data ['irrepcount' ] = '1'
54405489
5441- data_update = setup_kvec_input (kpoint_frac )
5490+ kvec_dict = grab_all_kvecs (out2 )
5491+
5492+ data_update = setup_kvec_input (kpoint_frac , kvec_dict )
54425493 for key , value in data_update .items ():
54435494 data [key ] = value
54445495
@@ -5552,7 +5603,7 @@ def match_vector_pattern(k_vec, k_vec_dict):
55525603 # reopen tree to the original phase
55535604 def _ShowPhase ():
55545605 phId = G2gd .GetGPXtreeItemId (G2frame , G2frame .root , 'Phases' )
5555- G2frame .GPXtree .Expand (phId )
5606+ G2frame .GPXtree .Expand (phId )
55565607 phId = G2gd .GetGPXtreeItemId (G2frame , phId , phsnam )
55575608 G2frame .GPXtree .SelectItem (phId )
55585609
@@ -5563,7 +5614,7 @@ def _ShowPhase():
55635614 { os .getcwd ()}
55645615 '''
55655616 wx .MessageBox (
5566- info_msg ,
5617+ info_msg ,
55675618 style = wx .ICON_INFORMATION ,
55685619 caption = 'Isotropic Subgroup Generation'
55695620 )
@@ -7470,7 +7521,7 @@ def setBackgroundColors(im,it):
74707521 def OnToggleExt (event ):
74717522 G2frame .Hide = not G2frame .Hide
74727523 UpdateReflectionGrid (G2frame ,data ,HKLF = True ,Name = Name )
7473-
7524+
74747525 def OnPageChanged (event ):
74757526 '''Respond to a press on a phase tab by displaying the reflections. This
74767527 routine is needed because the reflection table may not have been created yet.
0 commit comments