@@ -5502,6 +5502,27 @@ def setup_kvec_input(k_vec, k_vec_dict, isocif_cif):
55025502 phase_nam = G2frame.kvecSearch['phase']
55035503 phaseTreeId = G2gd.GetGPXtreeItemId(G2frame, phaseID, phase_nam) # save reference
55045504 Phase = G2frame.GPXtree.GetItemPyData(phaseTreeId)
5505+
5506+ if mag:
5507+ atom_names = [atom[1] for atom in Phase['Atoms']]
5508+ atom_names = list(set(atom_names))
5509+ dlg = G2G.G2MultiChoiceDialog(G2frame,
5510+ 'Select magnetic atom(s)',
5511+ 'Select magnetic atom(s) from the list below:',
5512+ atom_names, filterBox=False)
5513+ try:
5514+ if dlg.ShowModal() != wx.ID_OK:
5515+ return
5516+ selected_indices = dlg.GetSelections()
5517+ finally:
5518+ dlg.Destroy()
5519+ if not selected_indices:
5520+ wx.MessageBox('No atoms selected. Aborting.',
5521+ caption='No Selection', style=wx.ICON_EXCLAMATION)
5522+ return
5523+ selected_atoms = [atom_names[i] for i in selected_indices]
5524+ G2frame.kvecSearch['magAtoms'] = selected_atoms
5525+
55055526 fileList = []
55065527 # write a CIF as a scratch file
55075528 obj = G2export_CIF.ExportPhaseCIF(G2frame)
@@ -5572,23 +5593,21 @@ def setup_kvec_input(k_vec, k_vec_dict, isocif_cif):
55725593 isocif_out_cif = requests.post(isocifformsite, data=isocif_formDict).text
55735594
55745595 if mag:
5575- atom_names = [atom[0] for atom in Phase['Atoms']]
5576- dlg = G2G.G2MultiChoiceDialog(G2frame,
5577- 'Select magnetic atom(s)',
5578- 'Select magnetic atom(s) from the list below:',
5579- atom_names, filterBox=False)
5580- try:
5581- if dlg.ShowModal() != wx.ID_OK:
5582- return
5583- selected_indices = dlg.GetSelections()
5584- finally:
5585- dlg.Destroy()
5586- if not selected_indices:
5587- wx.MessageBox('No atoms selected. Aborting.',
5588- caption='No Selection', style=wx.ICON_EXCLAMATION)
5589- return
5590- selected_atoms = [atom_names[i] for i in selected_indices]
5591- G2frame.kvecSearch['magAtoms'] = selected_atoms
5596+ # Parse out2 to map element symbol -> includemagnetic field name
5597+ # Pattern: "Er<INPUT TYPE="checkbox" NAME="includemagnetic001" VALUE="true">"
5598+ mag_elem_map = dict(re.findall(
5599+ r'(\w+)<INPUT\s+TYPE="checkbox"\s+NAME="(includemagnetic\d+)"',
5600+ out2, re.IGNORECASE
5601+ ))
5602+ G2frame.kvecSearch['magElemMap'] = mag_elem_map
5603+ # Enable magnetic distortions only for the user-selected elements
5604+ for elem, field in mag_elem_map.items():
5605+ if elem in selected_atoms:
5606+ data[field] = 'true'
5607+ # Remove displacive and strain keys when doing magnetic search
5608+ for key in list(data.keys()):
5609+ if key.startswith('includedisplacive') or key == 'includestrain':
5610+ del data[key]
55925611
55935612 kvec_dict = grab_all_kvecs(out2)
55945613 #lat_sym = Phase['General']['SGData']
0 commit comments