Skip to content

Commit d177f5c

Browse files
committed
Merge remote-tracking branch 'origin/main' into TOFgroup
2 parents df1849d + c2e165c commit d177f5c

File tree

15 files changed

+577
-177
lines changed

15 files changed

+577
-177
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def __init__(self,parent,loc,key,nDig=None,notBlank=True,xmin=None,xmax=None,
429429
else:
430430
self.invalid = True
431431
self._IndicateValidity()
432+
wx.CallAfter(self._TestValidity) # test/show validity
432433
else:
433434
if self.CIFinput:
434435
wx.TextCtrl.__init__(
@@ -468,7 +469,7 @@ def SetValue(self,val,warn=True):
468469
# for debugging flag calls. Set warn to False for calls that are not in callbacks
469470
# and thus are OK
470471
if GSASIIpath.GetConfigValue('debug') and warn:
471-
print('ValidatedTxtCtrl.SetValue() used in callback. Batter as ChangeValue()?')
472+
print('ValidatedTxtCtrl.SetValue() used in callback. Better as ChangeValue()?')
472473
G2obj.HowDidIgetHere(True)
473474
if self.result is not None:
474475
self.result[self.key] = val
@@ -567,9 +568,12 @@ def _onStringKey(self,event):
567568

568569
def _TestValidity(self):
569570
'Check validity and change colors accordingly'
570-
if self.Validator:
571-
self.Validator.TestValid(self)
572-
self._IndicateValidity()
571+
try:
572+
if self.Validator:
573+
self.Validator.TestValid(self)
574+
self._IndicateValidity()
575+
except RuntimeError: #bandaid to avoid C++ error; deleted self.Validator?
576+
pass
573577

574578
def _IndicateValidity(self):
575579
'Set the control colors to show invalid input'

GSASII/GSASIIdataGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8126,9 +8126,9 @@ def ClearGroups(event):
81268126
G2frame.dataWindow.SetDataSize()
81278127
# G2frame.SendSizeEvent()
81288128

8129-
#### Main PWDR panel ########################################################
8129+
#### Main PWDR & HKLF panel ########################################################
81308130
def UpdatePWHKPlot(G2frame,kind,item):
8131-
'''Called when the histogram main tree entry is called. Displays the
8131+
'''Called when the PWDR & HKLF histogram main tree entry is called. Displays the
81328132
histogram weight factor, refinement statistics for the histogram
81338133
and the range of data for a simulation.
81348134

GSASII/GSASIIimgGUI.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,12 +3036,8 @@ def OnSetCol(event):
30363036
StrainGrid.SetTable(StrainTable,True)
30373037
StrainGrid.AutoSizeColumns(True)
30383038
for r in range(len(data['d-zero'])):
3039-
StrainGrid.SetCellStyle(r,2,VERY_LIGHT_GREY,True)
3040-
StrainGrid.SetCellStyle(r,5,VERY_LIGHT_GREY,True)
3041-
StrainGrid.SetCellStyle(r,6,VERY_LIGHT_GREY,True)
3042-
StrainGrid.SetCellStyle(r,7,VERY_LIGHT_GREY,True)
3043-
StrainGrid.SetCellStyle(r,9,VERY_LIGHT_GREY,True)
3044-
StrainGrid.SetCellStyle(r,10,VERY_LIGHT_GREY,True)
3039+
for c in [2,5,6,7,9,10]:
3040+
StrainGrid.SetCellStyle(r,c,VERY_LIGHT_GREY,True)
30453041
if 'phoenix' in wx.version():
30463042
StrainGrid.Bind(wg.EVT_GRID_CELL_CHANGED, OnStrainChange)
30473043
else:

GSASII/GSASIIlattice.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,8 +2989,8 @@ def SetUVvec(Neigh):
29892989
return UVvec,UVchoice
29902990

29912991
def SHarmcal(SytSym,SHFln,psi,gam):
2992-
'''Perform a surface spherical harmonics computation.
2993-
Presently only used for plotting
2992+
'''Perform a surface spherical harmonics computation & return sum of squares.
2993+
Only used for plotting
29942994
Note that the the number of gam values must either be 1 or must match psi
29952995
29962996
:param str SytSym: site symmetry - only looking for cubics
@@ -3008,9 +3008,8 @@ def SHarmcal(SytSym,SHFln,psi,gam):
30083008
if SytSym in ['m3m','m3','43m','432','23'] or 'c' in trm:
30093009
Ksl = CubicSHarm(l,m,psi,gam)
30103010
else:
3011-
# p = SHFln[term][2]
30123011
Ksl = SphHarmAng(l,m,1.0,psi,gam)
3013-
SHVal += SHFln[term][0]*Ksl
3012+
SHVal += (SHFln[term][0]*Ksl)**2
30143013
return SHVal
30153014

30163015
def KslCalc(trm,psi,gam):

GSASII/GSASIIpath.py

Lines changed: 103 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,69 +1095,145 @@ def runScript(cmds=[], wait=False, G2frame=None):
10951095
sys.exit()
10961096

10971097
def IPyBreak_base(userMsg=None):
1098-
'''A routine that invokes an IPython session at the calling location
1098+
'''A routine that invokes an IPython session at the calling location.
1099+
Called by a call to :func:`IPyBreak` or command ``breakpoint()``.
10991100
This routine is only used when debug=True is set in the configuration
1100-
settings
1101+
settings.
11011102
'''
11021103
savehook = sys.excepthook # save the exception hook
11031104
try:
1104-
from IPython.terminal.embed import InteractiveShellEmbed
1105+
import IPython.core
1106+
# get the Ipython shell routine
1107+
if IPython.core.getipython.get_ipython() is None:
1108+
ipshell = IPython.terminal.embed.InteractiveShellEmbed.instance(banner1='')
1109+
else: # older IPython (still needed?)
1110+
ipshell = IPython.terminal.embed.InteractiveShellEmbed()
1111+
import inspect
11051112
except ImportError:
1106-
try:
1107-
# try the IPython 0.12 approach
1108-
from IPython.frontend.terminal.embed import InteractiveShellEmbed
1109-
except ImportError:
1110-
print ('IPython InteractiveShellEmbed not found')
1111-
return
1112-
import inspect
1113-
#from IPython import __version__
1114-
#if __version__.startswith('8.12.'): # see https://github.com/ipython/ipython/issues/13966
1115-
from IPython.core import getipython
1116-
if getipython.get_ipython() is None:
1117-
ipshell = InteractiveShellEmbed.instance()
1118-
else:
1119-
ipshell = InteractiveShellEmbed()
1113+
return
1114+
1115+
stack = inspect.stack() # Get the full stack
1116+
current_level = [1] # mutable so inner function can modify it
1117+
1118+
def up(levels=1):
1119+
'''Move the IPython shell environment up the call stack.
1120+
Initially coded by Claude Sonnet 4.5
1121+
'''
1122+
new_level = current_level[0] + levels
1123+
if new_level < len(stack):
1124+
current_level[0] = new_level
1125+
frame = stack[current_level[0]].frame
1126+
print(f"Moving to: {stack[current_level[0]].filename}:{stack[current_level[0]].lineno} in {stack[current_level[0]].function}")
1127+
# Replace the IPython namespace (not update), but preserve IPython internals
1128+
# Save IPython internal variables and built-in commands
1129+
ipython_preserve = {k: v for k, v in ipshell.user_ns.items()
1130+
if k.startswith('_') or k in ('exit', 'quit', 'get_ipython')}
1131+
ipshell.user_ns.clear()
1132+
ipshell.user_ns.update(ipython_preserve) # Restore IPython internals
1133+
ipshell.user_ns.update(frame.f_globals)
1134+
ipshell.user_ns.update(frame.f_locals)
1135+
ipshell.user_ns['TB'] = TB
1136+
ipshell.user_ns['up'] = up
1137+
ipshell.user_ns['down'] = down
1138+
ipshell.user_ns['where'] = where
1139+
else:
1140+
print(f"Already at top of stack (level {current_level[0]} of {len(stack)-1})")
1141+
1142+
def down(levels=1):
1143+
'''Move the IPython shell environment down the call stack.
1144+
Initially coded by Claude Sonnet 4.5
1145+
'''
1146+
new_level = current_level[0] - levels
1147+
if new_level >= 0:
1148+
current_level[0] = new_level
1149+
frame = stack[current_level[0]].frame
1150+
print(f"Moving to: {stack[current_level[0]].filename}:{stack[current_level[0]].lineno} in {stack[current_level[0]].function}")
1151+
# Replace the IPython namespace (not update), but preserve IPython internals
1152+
# Save IPython internal variables and built-in commands
1153+
ipython_preserve = {k: v for k, v in ipshell.user_ns.items()
1154+
if k.startswith('_') or k in ('exit', 'quit', 'get_ipython')}
1155+
ipshell.user_ns.clear()
1156+
ipshell.user_ns.update(ipython_preserve) # Restore IPython internals
1157+
ipshell.user_ns.update(frame.f_globals)
1158+
ipshell.user_ns.update(frame.f_locals)
1159+
ipshell.user_ns['TB'] = TB
1160+
ipshell.user_ns['up'] = up
1161+
ipshell.user_ns['down'] = down
1162+
ipshell.user_ns['where'] = where
1163+
else:
1164+
print(f"Already at bottom of stack (level 0)")
1165+
1166+
def where():
1167+
'''Show current position in stack related to up/down commands.
1168+
Initially coded by Claude Sonnet 4.5 & revised to reverse display order.
1169+
'''
1170+
i = len(stack)
1171+
for frame_info in reversed(stack):
1172+
i -= 1
1173+
marker = ">>>" if i == current_level[0] else " "
1174+
print(f"{marker} [{i}] {frame_info.filename}:{frame_info.lineno} in {frame_info.function}")
1175+
1176+
def TB(depth=None):
1177+
'''Show a traceback (to the optional specified depth) to how we got to
1178+
the breakpoint. Omit the current level as the calling level to here
1179+
and above is likely all that we would be interested in.
1180+
'''
1181+
if depth is not None: depth += 1
1182+
for frame_info in reversed(stack[1:depth]):
1183+
print(f' File "{frame_info.filename}", line {frame_info.lineno}, in {frame_info.function}')
1184+
if frame_info.code_context:
1185+
print(f' {frame_info.code_context[0].strip()}')
11201186

11211187
frame = inspect.currentframe().f_back
11221188
msg = 'Entering IPython console inside {0.f_code.co_filename} at line {0.f_lineno}\n'.format(frame)
1189+
msg += '\n[up()/down()/where() to navigate stack; TB()/TB(n) for n level tracebacks]'
11231190
if userMsg: msg += userMsg
1191+
1192+
# Add commands to shell namespace
1193+
locals = frame.f_locals
1194+
locals['TB'] = TB
1195+
locals['up'] = up
1196+
locals['down'] = down
1197+
locals['where'] = where
1198+
11241199
# globals().update(locals()) # This might help with vars inside list comprehensions, etc.
1125-
ipshell(msg,stack_depth=2) # Go up one level, to see the calling routine
1200+
ipshell(msg,stack_depth=2,local_ns=locals,global_ns=frame.f_globals)
11261201
sys.excepthook = savehook # reset IPython's change to the exception hook
11271202

11281203
def exceptHook(*args):
11291204
'''A routine to be called when an exception occurs. It prints the traceback
11301205
with fancy formatting and then calls an IPython shell with the environment
11311206
of the exception location.
11321207
1133-
This routine is only used when debug=True is set in the configuration settings
1208+
This routine is only used when debug=True is set in the configuration
1209+
settings.
11341210
'''
11351211
import IPython.core
11361212
savehook = sys.excepthook # save the exception hook
11371213
# show the error location
1138-
tb_formatter = IPython.core.ultratb.FormattedTB()
1139-
#tb_formatter = IPython.core.ultratb.ListTB() # better for windows?
1140-
print() # blank line
1214+
if sys.platform == "win32":
1215+
tb_formatter = IPython.core.ultratb.ListTB() # better for windows?
1216+
else:
1217+
tb_formatter = IPython.core.ultratb.FormattedTB()
11411218
print(tb_formatter.text(*args,-1),end='') # show only last routine
11421219
# get the Ipython shell routine
11431220
if IPython.core.getipython.get_ipython() is None:
11441221
ipshell = IPython.terminal.embed.InteractiveShellEmbed.instance(banner1='')
11451222
else: # older IPython (still needed?)
11461223
ipshell = IPython.terminal.embed.InteractiveShellEmbed()
11471224
# traceback display routines
1148-
def TB(): print(IPython.core.ultratb.FormattedTB().text(*args))
1149-
def vTB(): print(IPython.core.ultratb.VerboseTB().text(*args))
1150-
def bwTB(): print(IPython.core.ultratb.ListTB().text(*args)) # uncolored
1225+
def TB(depth=None): print(IPython.core.ultratb.FormattedTB().text(*args,depth))
1226+
def vTB(depth=-1): print(IPython.core.ultratb.VerboseTB().text(*args,depth))
1227+
def bwTB(depth=None): print(IPython.core.ultratb.ListTB().text(*args,depth)) # uncolored
11511228
try: # get to the right frame
11521229
import inspect
11531230
frame = inspect.getinnerframes(args[2])[-1][0]
1154-
import copy
11551231
locals = frame.f_locals # add traceback commands to shell namespace
11561232
locals['TB'] = TB
11571233
locals['vTB'] = vTB
11581234
locals['bwTB'] = bwTB
11591235
msg = f'IPython console: {frame.f_code.co_filename}, line {frame.f_lineno}'
1160-
msg += '\n[TB(), vTB() & bwTB() for tracebacks]'
1236+
msg += '\n[TB()/TB(-n), vTB()/vTB(-n)/vTB(0) & bwTB() for tracebacks to n levels back]'
11611237
ipshell(msg,local_ns=locals,global_ns=frame.f_globals)
11621238
except:
11631239
msg = 'Entering IPython console (not in error contex)'
@@ -1854,16 +1930,6 @@ def postURL(URL,postdict,getcookie=None,usecookie=None,
18541930
if r.status_code == 200:
18551931
if GetConfigValue('debug'): print('request OK')
18561932
page = r.text
1857-
if 'cryst.ehu.es' in URL and "currently down" in page:
1858-
# Bilbao is down. Tell user
1859-
import re
1860-
print(f"Website down? See message below:\n\n{re.sub('<.+>','',page)}")
1861-
try:
1862-
import wx
1863-
import GSASII.GSASIIctrlGUI as G2G
1864-
dlg = G2G.viewWebPage(wx.GetApp().GetMainTopWindow(),URL,HTML=page)
1865-
except:
1866-
pass
18671933
if getcookie is not None:
18681934
getcookie.update(r.cookies)
18691935
return page # success

GSASII/GSASIIphsGUI.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,7 @@ def _showWebPage(event):
32523252
with open(tmp.name,'w') as fp:
32533253
fp.write(pagelist[num].replace(
32543254
'<head>',
3255-
'<head><base href="https://www.cryst.ehu.es/">',
3255+
f'<head><base href="{SUBGROUPS.bilbaoURL}/">',
32563256
))
32573257
fileList.append(tmp.name)
32583258
G2G.ShowWebPage('file://'+tmp.name,G2frame)
@@ -3439,7 +3439,7 @@ def _showWebPage(event):
34393439
with open(tmp.name,'w') as fp:
34403440
fp.write(f.replace(
34413441
'<head>',
3442-
'<head><base href="https://www.cryst.ehu.es/">',
3442+
f'<head><base href="{SUBGROUPS.bilbaoURL}/">',
34433443
))
34443444
fileList.append(tmp.name)
34453445
G2G.ShowWebPage('file://'+tmp.name,G2frame)
@@ -3919,6 +3919,9 @@ def OnTransform2Std(event):
39193919
generalData = data['General']
39203920
cx,ct,cs,cia = generalData['AtomPtrs']
39213921
sgnum,sgsym,xmat,xoff = SUBGROUPS.GetStdSGset(generalData['SGData'])
3922+
if xmat is None:
3923+
G2G.G2MessageBox(G2frame,"Unable to reach web site.",'No connection')
3924+
return
39223925
if np.allclose(np.eye(3),xmat) and np.allclose(xoff,np.zeros_like(xoff)):
39233926
msg = "Nothing to do. Structure is already set in the standard setting."
39243927
G2G.G2MessageBox(G2frame,msg,'No change needed')

GSASII/GSASIIphsGUI2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,20 @@ def OnRadFxn(event):
207207
wx.CallAfter(UpdateDeformation,G2frame,data,dId)
208208

209209
def MakeUVmat(defData,U,V):
210-
MX = U
210+
MX = U/nl.norm(U)
211211
if 'A' in defData['MUV']:
212-
MY = V
212+
MY = V/nl.norm(V)
213213
MZ = np.cross(MX,MY)
214214
MZ /= nl.norm(MZ)
215215
MY = np.cross(MZ,MX)
216216
MY /= nl.norm(MY)
217217
else:
218-
MZ = V
218+
MZ = V/nl.norm(V)
219219
MY = np.cross(MZ,MX)
220220
MY /= nl.norm(MY)
221221
MZ = np.cross(MX,MY)
222222
MZ /= nl.norm(MZ)
223-
return np.array([MX,MY,MZ])
223+
return np.array([MX,MY,MZ]).T
224224

225225
def OnDeformRef(event):
226226
Obj = event.GetEventObject()
@@ -507,10 +507,10 @@ def OnAtCol(event):
507507
oriSizer.Add(delHarm,0,WACV)
508508
mainSizer.Add(oriSizer)
509509
G2G.HorizontalLine(mainSizer,deformation)
510-
Names = {'D(1,-1)':'px','D(1,0)':'pz','D(1,1)':'py',
511-
'D(2,-2)':'dxy','D(2,-1)':'dxz','D(2,0)':'dz2','D(2,1)':'dyz','D(2,2)':'dx2-y2',
512-
'D(3,-3)':'fy(3x2-y2)','D(3,-2)':'fz(x2-y2)','D(3,-1':'fyz2','D(3,0)':'fz3',
513-
'D(3,1)':'fxz2','D(3,2)':'fxyz','D(3,3)':'fy(3x2-y2)',}
510+
Names = {'D(1,-1)':'py','D(1,0)':'pz','D(1,1)':'px',
511+
'D(2,-2)':'dxy','D(2,-1)':'dyz','D(2,0)':'dz2','D(2,1)':'dxz','D(2,2)':'dx2-y2',
512+
'D(3,-3)':'fy(3x2-y2)','D(3,-2)':'fxyz','D(3,-1)':'fyz2','D(3,0)':'fz3',
513+
'D(3,1)':'fxz2','D(3,2)':'fz(x2-y2)','D(3,3)':'fx(x2-3y2)',}
514514
mainSizer.Add(wx.StaticText(deformation,label=' Deformation parameters:'))
515515
orbSizer = wx.FlexGridSizer(0,9,2,2)
516516
for iorb,orb in enumerate(deformationData[dId]):

0 commit comments

Comments
 (0)