Skip to content

Commit 7321616

Browse files
committed
fix conflict in G2plot
Add option to save as csv file the bond/angle distributions from RMCProfile result
1 parent 4d22ade commit 7321616

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

GSASII/GSASIIphsGUI.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,15 +2786,52 @@ def OnCompPlots(event):
27862786
Title=r'%s Tetrahedral tilt vectors'%Oatoms,PlotName='Tet %s tilts for %s'%(bName,pName))
27872787
print(' %s-%s bond distance: %.3f(%d)'%(Oatoms,Tatoms,Bmean,Bstd*1000))
27882788
print(' %s tilt angle: %.2f(%d)'%(Oatoms,Tmean,Tstd*100))
2789-
2790-
2789+
2790+
def OnSaveDist(event):
2791+
pName = generalData['Name']
2792+
fName = os.path.abspath(os.path.splitext(G2frame.GSASprojectfile)[0]+'_TOdist.csv')
2793+
fp = open(fName,'w')
2794+
fp.write('Phase name: %s\n'%pName)
2795+
Oatoms = generalData['Compare']['Oatoms']
2796+
Tatoms = generalData['Compare']['Tatoms']
2797+
bName = '%s-%s'%(Oatoms,Tatoms)
2798+
Bonds = generalData['Compare']['Bonds'][bName]
2799+
Vects = generalData['Compare']['Vects'][bName]
2800+
dVects = generalData['Compare']['dVects'][bName]
2801+
if len(Bonds['Obonds']):
2802+
fp.write('%s-%s Octahedral bond lengths'%(Oatoms,Tatoms))
2803+
for ib,bond in enumerate(Bonds['Obonds']):
2804+
fp.write('%7.4f,'%bond)
2805+
if not (ib+1)%10: fp.write('\n')
2806+
2807+
if len(Bonds['Tbonds']):
2808+
fp.write('%s-%s Tetrahedral bond lengths\n'%(Oatoms,Tatoms))
2809+
for ib,bond in enumerate(Bonds['Tbonds']):
2810+
fp.write('%7.4f,'%bond)
2811+
if not (ib+1)%10: fp.write('\n')
2812+
2813+
fp.close()
2814+
print(' %s written'%fName)
2815+
27912816
Oatoms = generalData['Compare']['Oatoms']
27922817
Tatoms = generalData['Compare']['Tatoms']
27932818
bName = '%s-%s'%(Oatoms,Tatoms)
27942819
atTypes = generalData['AtomTypes']
27952820
compSizer = wx.BoxSizer(wx.VERTICAL)
2796-
compSizer.Add(wx.StaticText(General,label=' Compare polyhedra to ideal octahedra/tetrahedra:'),0)
2821+
topSizer = wx.BoxSizer(wx.HORIZONTAL)
2822+
topSizer.Add(wx.StaticText(General,label=' Compare polyhedra to ideal octahedra/tetrahedra:'),0,WACV)
2823+
try:
2824+
if len(generalData['Compare']['Bonds'][bName]['Obonds']) or len(generalData['Compare']['Bonds'][bName]['Tbonds']):
2825+
plotBtn = wx.Button(General,label='Show plots?')
2826+
plotBtn.Bind(wx.EVT_BUTTON,OnCompPlots)
2827+
topSizer.Add(plotBtn,0,WACV)
2828+
saveBtn = wx.Button(General,label='Save distributions?')
2829+
saveBtn.Bind(wx.EVT_BUTTON,OnSaveDist)
2830+
topSizer.Add(saveBtn,0,WACV)
2831+
except KeyError:
2832+
pass
27972833

2834+
compSizer.Add(topSizer)
27982835
atmselSizer = wx.BoxSizer(wx.HORIZONTAL)
27992836
atmselSizer.Add(wx.StaticText(General,label=' Select origin atom type: '),0,WACV)
28002837
oatmsel = wx.ComboBox(General,choices=atTypes,style=wx.CB_READONLY|wx.CB_DROPDOWN)
@@ -2808,16 +2845,9 @@ def OnCompPlots(event):
28082845
tatmsel.Bind(wx.EVT_COMBOBOX,OnTatmOsel)
28092846
atmselSizer.Add(tatmsel,0,WACV)
28102847

2811-
atmselSizer.Add(wx.StaticText(General,label=' Sampling fraction:: '),0,WACV)
2848+
atmselSizer.Add(wx.StaticText(General,label=' Sampling fraction: '),0,WACV)
28122849
atmselSizer.Add(G2G.ValidatedTxtCtrl(General,generalData['Compare'],'Sampling',nDig=(8,3),xmin=0.0,xmax=1.0,),0,WACV)
28132850

2814-
try:
2815-
if len(generalData['Compare']['Bonds'][bName]['Obonds']) or len(generalData['Compare']['Bonds'][bName]['Tbonds']):
2816-
plotBtn = wx.Button(General,label='Show plots?')
2817-
plotBtn.Bind(wx.EVT_BUTTON,OnCompPlots)
2818-
atmselSizer.Add(plotBtn)
2819-
except KeyError:
2820-
pass
28212851
compSizer.Add(atmselSizer,0)
28222852
return compSizer
28232853

@@ -5542,22 +5572,26 @@ def OnDistAngle(event,fp=None,hist=False):
55425572
DisAglData['covData'] = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Covariance'))
55435573
try:
55445574
if hist:
5575+
Bonds = DisAglData['Bonds'] = DisAglData.get('Bonds',{})
5576+
Angles = DisAglData['Angles'] = DisAglData.get('Angles',{})
55455577
pgbar = wx.ProgressDialog('Distance Angle calculation','Atoms done=',len(Oxyz)+1,
55465578
style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE)
55475579
AtomLabels,DistArray,AngArray = G2stMn.RetDistAngle(DisAglCtls,DisAglData,pgbar)
55485580
pgbar.Destroy()
5549-
Bonds = []
5581+
bonds = []
55505582
for dists in DistArray:
5551-
Bonds += [item[3] for item in DistArray[dists]]
5552-
G2plt.PlotBarGraph(G2frame,Bonds,Xname=r'$\mathsf{Bonds,\AA}$',
5583+
bonds += [item[3] for item in DistArray[dists]]
5584+
G2plt.PlotBarGraph(G2frame,bonds,Xname=r'$\mathsf{Bonds,\AA}$',
55535585
Title='Bond distances for %s'%Atypes,PlotName='%s Bonds'%Atypes)
5554-
print('Total number of bonds to %s is %d'%(Atypes,len(Bonds)))
5555-
Angles = []
5556-
for angles in AngArray:
5557-
Angles += [item[2][0] for item in AngArray[angles]]
5558-
G2plt.PlotBarGraph(G2frame,Angles,Xname=r'$\mathsf{Angles,{^o}}$',
5586+
print('Total number of bonds to %s is %d'%(Atypes,len(bonds)))
5587+
Bonds[Atypes] = bonds
5588+
angles = []
5589+
for Item in AngArray:
5590+
angles += [item[2][0] for item in AngArray[Item]]
5591+
G2plt.PlotBarGraph(G2frame,angles,Xname=r'$\mathsf{Angles,{^o}}$',
55595592
Title='Bond angles about %s'%Atypes,PlotName='%s Angles'%Atypes)
5560-
print('Total number of angles about %s is %d'%(Atypes,len(Angles)))
5593+
print('Total number of angles about %s is %d'%(Atypes,len(angles)))
5594+
Angles[Atypes] = angles
55615595

55625596
elif fp:
55635597
#from importlib import reload

GSASII/GSASIIplot.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ def SetToolTipString(self,text):
234234
return self.canvas.SetToolTipString(text)
235235

236236
def ToolBarDraw(self):
237-
mplv = eval(mpl.__version__.replace('.',','))
238-
if mplv[0] >= 3 and mplv[1] >= 3:
237+
try:
239238
self.toolbar.canvas.draw_idle()
240-
else:
239+
except:
241240
self.toolbar.draw()
242241

243242
class G2PlotOgl(_tabPlotWin):
@@ -292,7 +291,7 @@ def SetToolTipString(self,text):
292291
def ToolBarDraw(self):
293292
try:
294293
self.toolbar.canvas.draw_idle()
295-
except: # patch: used for MLP <3.3
294+
except:
296295
self.toolbar.draw()
297296

298297
class G2PlotNoteBook(wx.Panel):

0 commit comments

Comments
 (0)