Changeset 951
 Timestamp:
 Jun 14, 2013 2:38:20 PM (9 years ago)
 Location:
 trunk
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIgrid.py
r939 r951 80 80 ] = [wx.NewId() for item in range(4)] 81 81 82 [ wxID_ADDMCSAATOM,wxID_ADDMCSARB,wxID_CLEARMCSARB,wxID_MOVEMCSA, 83 ] = [wx.NewId() for item in range( 4)]82 [ wxID_ADDMCSAATOM,wxID_ADDMCSARB,wxID_CLEARMCSARB,wxID_MOVEMCSA,wxID_MCSACLEARRESULTS, 83 ] = [wx.NewId() for item in range(5)] 84 84 85 85 [ wxID_CLEARTEXTURE,wxID_REFINETEXTURE, … … 1742 1742 text='Clear map') 1743 1743 self.GeneralCalc.Append(help='Run Monte Carlo  Simulated Annealing',id=wxID_RUNMCSA, kind=wx.ITEM_NORMAL, 1744 text=' RunMC/SA')1744 text='MC/SA') 1745 1745 self.PostfillDataMenu() 1746 1746 … … 1873 1873 self.MCSAEdit.Append(id=wxID_MOVEMCSA, kind=wx.ITEM_NORMAL,text='Move MC/SA solution', 1874 1874 help='Move MC/SA solution to atom list' ) 1875 self.MCSAEdit.Append(id=wxID_MCSACLEARRESULTS, kind=wx.ITEM_NORMAL,text='Clear results', 1876 help='Clear table of MC/SA results' ) 1875 1877 self.PostfillDataMenu() 1876 1878 
trunk/GSASIImath.py
r950 r951 2460 2460 if parmDict[pfx+'Type'] in ['Vector','Residue']: 2461 2461 if parmDict[pfx+'Type'] == 'Vector': 2462 RBId = parmDict[pfx+' :RBId']2462 RBId = parmDict[pfx+'RBId'] 2463 2463 RBRes = RBdata['Vector'][RBId] 2464 2464 aTypes = RBRes['rbTypes'] … … 2469 2469 Cart += vec*mag 2470 2470 elif parmDict[pfx+'Type'] == 'Residue': 2471 RBId = parmDict[pfx+' :RBId']2471 RBId = parmDict[pfx+'RBId'] 2472 2472 RBRes = RBdata['Residue'][RBId] 2473 2473 aTypes = RBRes['rbTypes'] 2474 2474 Cart = np.array(RBRes['rbXYZ']) 2475 2475 for itor,seq in enumerate(RBRes['rbSeq']): 2476 tName = pfx+' :Tor'+str(itor)2476 tName = pfx+'Tor'+str(itor) 2477 2477 QuatA = AVdeg2Q(parmDict[tName],Cart[seq[0]]Cart[seq[1]]) 2478 2478 for ride in seq[3]: 2479 2479 Cart[ride] = prodQVQ(QuatA,Cart[ride]Cart[seq[1]])+Cart[seq[1]] 2480 if parmDict[pfx+' :MolCent'][1]:2481 Cart = parmDict[pfx+' :MolCent'][0]2482 Qori = np.array([parmDict[pfx+' :Qa'],parmDict[pfx+':Qi'],parmDict[pfx+':Qj'],parmDict[pfx+':Qk']])2483 Pos = np.array([parmDict[pfx+' :Px'],parmDict[pfx+':Py'],parmDict[pfx+':Pz']])2480 if parmDict[pfx+'MolCent'][1]: 2481 Cart = parmDict[pfx+'MolCent'][0] 2482 Qori = np.array([parmDict[pfx+'Qa'],parmDict[pfx+'Qi'],parmDict[pfx+'Qj'],parmDict[pfx+'Qk']]) 2483 Pos = np.array([parmDict[pfx+'Px'],parmDict[pfx+'Py'],parmDict[pfx+'Pz']]) 2484 2484 for i,x in enumerate(Cart): 2485 2485 X = np.inner(Bmat,prodQVQ(Qori,x))+Pos … … 2490 2490 elif parmDict[pfx+'Type'] == 'Atom': 2491 2491 atNo = parmDict[pfx+'atNo'] 2492 afx = pfx+str(atNo)2493 2492 for key in keys: 2494 parm = afx+key2493 parm = pfx+key[1:] #remove extra ':' 2495 2494 if parm in parmDict: 2496 2495 keys[key][atNo] = parmDict[parm] … … 2575 2574 parmDict['nfixAt'] = len(fixAtoms) 2576 2575 MCSA = generalData['MCSA controls'] 2577 Results = MCSA.get('Results',[])2578 2576 reflName = MCSA['Data source'] 2579 2577 phaseName = generalData['Name'] … … 2587 2585 getMDparms(item,mfx,parmDict,varyList) 2588 2586 elif item['Type'] == 'Atom': 2589 pfx = mfx+str(atNo)+':' 2590 getAtomparms(item,pfx,aTypes,SGData,parmDict,varyList) 2587 getAtomparms(item,mfx,aTypes,SGData,parmDict,varyList) 2591 2588 parmDict[mfx+'atNo'] = atNo 2592 2589 atNo += 1 2593 2590 elif item['Type'] in ['Residue','Vector']: 2594 pfx = mfx+':' 2595 atNo = getRBparms(item,pfx,aTypes,RBdata,SGData,atNo,parmDict,varyList) 2591 atNo = getRBparms(item,mfx,aTypes,RBdata,SGData,atNo,parmDict,varyList) 2596 2592 parmDict['atNo'] = atNo #total no. of atoms 2597 2593 parmDict['nObj'] = len(MCSAObjs) … … 2673 2669 x0 = [parmDict[val] for val in varyList] 2674 2670 ifInv = SGData['SGInv'] 2675 for i in range(MCSA['Cycles']): 2676 results = anneal(mcsaCalc,x0,args=(refs,rcov,ifInv,RBdata,varyList,parmDict), 2677 schedule=MCSA['Algorithm'], full_output=True,maxiter=MCSA['nRuns'], 2678 T0=MCSA['Annealing'][0], Tf=MCSA['Annealing'][1],dwell=MCSA['Annealing'][2], 2679 boltzmann=MCSA['boltzmann'], learn_rate=0.5, feps=MCSA['Annealing'][3], 2680 quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2], 2681 lower=lower, upper=upper, slope=MCSA['log slope'],dlg=pgbar) 2682 Results.append([results[1],results[2],results[0],varyList]) 2671 results = anneal(mcsaCalc,x0,args=(refs,rcov,ifInv,RBdata,varyList,parmDict), 2672 schedule=MCSA['Algorithm'], full_output=True, 2673 T0=MCSA['Annealing'][0], Tf=MCSA['Annealing'][1],dwell=MCSA['Annealing'][2], 2674 boltzmann=MCSA['boltzmann'], learn_rate=0.5, 2675 quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2], 2676 lower=lower, upper=upper, slope=MCSA['log slope'],dlg=pgbar) 2677 return [False,results[1],results[2],results[0],varyList] 2683 2678 2684 2679 
trunk/GSASIIphsGUI.py
r950 r951 70 70 71 71 :param wx.frame G2frame: the main GSASII frame object 72 73 72 :param wx.TreeItemId Item: the tree item that was selected 74 75 73 :param dict data: all the information on the phase in a dictionary 76 77 74 :param int oldPage: This sets a tab to select when moving 78 75 from one phase to another, in which case the same tab is selected … … 86 83 if 'RBModels' not in data: 87 84 data['RBModels'] = {} 85 if isinstance(data['MCSA']['Results'],dict): 86 data['MCSA']['Results'] = [] 88 87 if 'MCSA' not in data: 89 data['MCSA'] = {'Models':[{'Type':'MD','Coef':[1.0,False,[0. ,3.],],'axis':[0,0,1]}],'Results':[],'AtInfo':{}}88 data['MCSA'] = {'Models':[{'Type':'MD','Coef':[1.0,False,[0.3,3.],],'axis':[0,0,1]}],'Results':[],'AtInfo':{}} 90 89 #end patch 91 90 … … 126 125 if 'Algolrithm' in generalData.get('MCSA controls',{}) or \ 127 126 'MCSA controls' not in generalData: 128 generalData['MCSA controls'] = {'Data source':'','Annealing':[50.,0.001,50 ,1.e6],129 'dmin':2.0,'Algorithm':'fast','Jump coeff':[0.95,0.5],' nRuns':50,'boltzmann':1.0,127 generalData['MCSA controls'] = {'Data source':'','Annealing':[50.,0.001,50], 128 'dmin':2.0,'Algorithm':'fast','Jump coeff':[0.95,0.5],'boltzmann':1.0, 130 129 'fast parms':[1.0,1.0,1.0],'log slope':0.9,'Cycles':1,'Results':[]} 131 130 # end of patches … … 659 658 660 659 def OnCycles(event): 661 MCSA['Cycles'] = int( noRuns.GetValue())660 MCSA['Cycles'] = int(cycles.GetValue()) 662 661 663 def OnNoRuns(event):664 MCSA['nRuns'] = int(noRuns.GetValue())665 666 662 def OnAlist(event): 667 663 MCSA['Algorithm'] = Alist.GetValue() … … 697 693 MCSA['Annealing'][ind] = val 698 694 except ValueError: 699 pass695 Obj.SetValue(fmt%(MCSA['Annealing'][ind])) 700 696 else: 701 697 try: … … 703 699 if .0 <= val: 704 700 MCSA['Annealing'][ind] = val 701 Obj.SetValue(fmt%(MCSA['Annealing'][ind])) 705 702 except ValueError: 706 pass707 Obj.SetValue(fmt%(MCSA['Annealing'][ind]))703 MCSA['Annealing'][ind] = None 704 Obj.SetValue(str(MCSA['Annealing'][ind])) 708 705 709 # MCSA = {'boltzmann':1.0,710 706 refList = [] 711 707 if len(data['Pawley ref']): … … 726 722 dmin.Bind(wx.EVT_KILL_FOCUS,OnDmin) 727 723 lineSizer.Add(dmin,0,wx.ALIGN_CENTER_VERTICAL) 728 lineSizer.Add(wx.StaticText(General,label=' Cycles: '),0,wx.ALIGN_CENTER_VERTICAL) 724 mcsaSizer.Add(lineSizer) 725 mcsaSizer.Add((5,5),) 726 line2Sizer = wx.BoxSizer(wx.HORIZONTAL) 727 line2Sizer.Add(wx.StaticText(General,label=' Cycles: '),0,wx.ALIGN_CENTER_VERTICAL) 729 728 Cchoice = ['1','2','3','5','10','15','20','30'] 730 729 cycles = wx.ComboBox(General,1,value=str(MCSA.get('Cycles',1)),choices=Cchoice, 731 730 style=wx.CB_READONLYwx.CB_DROPDOWN) 732 731 cycles.Bind(wx.EVT_COMBOBOX,OnCycles) 733 lineSizer.Add(cycles,0,wx.ALIGN_CENTER_VERTICAL) 734 mcsaSizer.Add(lineSizer) 735 mcsaSizer.Add((5,5),) 736 line2Sizer = wx.BoxSizer(wx.HORIZONTAL) 737 Rchoice = ['10','15','20','50','100','200','500'] 738 line2Sizer.Add(wx.StaticText(General,label=' No. temp. steps: '),0,wx.ALIGN_CENTER_VERTICAL) 739 noRuns = wx.ComboBox(General,1,value=str(MCSA.get('nRuns',1)),choices=Rchoice, 740 style=wx.CB_READONLYwx.CB_DROPDOWN) 741 noRuns.Bind(wx.EVT_COMBOBOX,OnNoRuns) 742 line2Sizer.Add(noRuns,0,wx.ALIGN_CENTER_VERTICAL) 732 line2Sizer.Add(cycles,0,wx.ALIGN_CENTER_VERTICAL) 743 733 Achoice = ['log','fast','cauchy','boltzmann','Tremayne'] 744 734 line2Sizer.Add(wx.StaticText(General,label=' MC/SA schedule: '),0,wx.ALIGN_CENTER_VERTICAL) … … 772 762 line3Sizer = wx.BoxSizer(wx.HORIZONTAL) 773 763 line3Sizer.Add(wx.StaticText(General,label=' Annealing schedule: '),0,wx.ALIGN_CENTER_VERTICAL) 774 names = [' Start temp: ',' Final temp: ',' No. trials: ' ,' feps: ']775 fmts = ['%.1f','%.5f','%d' ,'%.2g']764 names = [' Start temp: ',' Final temp: ',' No. trials: '] 765 fmts = ['%.1f','%.5f','%d'] 776 766 for i,[name,fmt] in enumerate(zip(names,fmts)): 767 if MCSA['Annealing'][i]: 768 text = fmt%(MCSA['Annealing'][i]) 769 else: 770 text = 'None' 777 771 line3Sizer.Add(wx.StaticText(General,label=name),0,wx.ALIGN_CENTER_VERTICAL) 778 anneal = wx.TextCtrl(General,1,value= fmt%(MCSA['Annealing'][i]),style=wx.TE_PROCESS_ENTER)772 anneal = wx.TextCtrl(General,1,value=text,style=wx.TE_PROCESS_ENTER) 779 773 anneal.Bind(wx.EVT_TEXT_ENTER,OnAnneal) 780 774 anneal.Bind(wx.EVT_KILL_FOCUS,OnAnneal) … … 4161 4155 try: 4162 4156 rmin,rmax = [float(Range[i]) for i in range(2)] 4163 if rmin >= rmax: 4157 if 0. < rmin < rmax: 4158 pass 4159 else: 4164 4160 raise ValueError 4165 4161 except (ValueError,IndexError): … … 4202 4198 poSizer.Add(poAxis,0,wx.ALIGN_CENTER_VERTICAL) 4203 4199 return poSizer 4200 4201 def ResultsSizer(Results): 4202 4203 def OnCellChange(event): 4204 r,c = event.GetRow(),event.GetCol() 4205 if c == 0: 4206 Models = data['MCSA']['Models'] 4207 for row in range(resultsGrid.GetNumberRows()): 4208 resultsTable.SetValue(row,c,False) 4209 resultsTable.SetValue(r,c,True) 4210 resultsGrid.ForceRefresh() 4211 result = Results[r] 4212 for key,val in zip(result[4],result[3]): 4213 vals = key.split(':') 4214 nObj,name = int(vals[0]),vals[1] 4215 if 'A' in name: 4216 ind = ['Ax','Ay','Az'].index(name) 4217 Models[nObj]['Pos'][0][ind] = val 4218 elif 'O' in name: 4219 ind = ['Oa','Oi','Oj','Ok'].index(name) 4220 Models[nObj]['Ori'][0][ind] = val 4221 elif 'P' in name: 4222 ind = ['Px','Py','Pz'].index(name) 4223 Models[nObj]['Pos'][0][ind] = val 4224 elif 'T' in name: 4225 tnum = int(name.split('Tor')) 4226 Models[nObj]['Tor'][0][tnum] = val 4227 else: #March Dollase 4228 Models[0]['Coef'][0] = val 4229 UpdateMCSA() 4230 G2plt.PlotStructure(G2frame,data) 4231 4232 resultsSizer = wx.BoxSizer(wx.VERTICAL) 4233 maxVary = 0 4234 resultVals = [] 4235 for result in Results: 4236 maxVary = max(maxVary,len(result[3])) 4237 resultVals.append(result[:3]+list(result[3])) 4238 rowLabels = [] 4239 for i in range(len(Results)): rowLabels.append(str(i)) 4240 colLabels = ['Select','Residual','Tmin',] 4241 for i in range(maxVary): colLabels.append('variable:'+str(i)) 4242 Types = [wg.GRID_VALUE_BOOL,wg.GRID_VALUE_FLOAT+':10,4', 4243 wg.GRID_VALUE_FLOAT+':10,4',]+maxVary*[wg.GRID_VALUE_FLOAT+':10,5',] 4244 resultsTable = G2gd.Table(resultVals,rowLabels=rowLabels,colLabels=colLabels,types=Types) 4245 resultsGrid = G2gd.GSGrid(MCSA) 4246 resultsGrid.SetTable(resultsTable, True) 4247 resultsGrid.Bind(wg.EVT_GRID_CELL_LEFT_CLICK, OnCellChange) 4248 resultsGrid.AutoSizeColumns(True) 4249 for r in range(resultsGrid.GetNumberRows()): 4250 for c in range(resultsGrid.GetNumberCols()): 4251 if c == 0: 4252 resultsGrid.SetReadOnly(r,c,isReadOnly=False) 4253 else: 4254 resultsGrid.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 4255 resultsSizer.Add(resultsGrid) 4256 return resultsSizer 4257 4204 4258 4205 4259 # UpdateMCSA executable code starts here … … 4238 4292 mainSizer.Add((5,5),0) 4239 4293 else: 4240 for result in data['MCSA']['Results']: 4241 print result 4294 mainSizer.Add((5,5),0) 4295 mainSizer.Add(wx.StaticText(MCSA,1,'MC/SA results:'),0,wx.ALIGN_CENTER_VERTICAL) 4296 mainSizer.Add((5,5),0) 4297 Results = data['MCSA']['Results'] 4298 mainSizer.Add(ResultsSizer(Results)) 4242 4299 4243 4300 MCSA.SetSizer(mainSizer) … … 4294 4351 pgbar.SetSize(Size) 4295 4352 try: 4296 G2mth.mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar) 4353 for i in range(mcsaControls['Cycles']): 4354 MCSAdata['Results'].append(G2mth.mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar)) 4297 4355 finally: 4298 4356 pgbar.Destroy() 4299 if not data['Drawing']: #if new drawing  no drawing data!4300 SetupDrawingData()4301 4357 UpdateMCSA() 4358 G2plt.PlotStructure(G2frame,data) 4302 4359 4303 4360 def OnMCSAaddAtom(event): … … 4363 4420 AtomAdd(x,y,z,atype,Name=atype+'(%d)'%(iat+1)) 4364 4421 G2plt.PlotStructure(G2frame,data) 4422 4423 def OnClearResults(event): 4424 data['MCSA']['Results'] = [] 4425 UpdateMCSA() 4365 4426 4366 4427 ################################################################################ … … 4946 5007 G2frame.dataFrame.Bind(wx.EVT_MENU, OnMCSAclear, id=G2gd.wxID_CLEARMCSARB) 4947 5008 G2frame.dataFrame.Bind(wx.EVT_MENU, OnMCSAmove, id=G2gd.wxID_MOVEMCSA) 5009 G2frame.dataFrame.Bind(wx.EVT_MENU, OnClearResults, id=G2gd.wxID_MCSACLEARRESULTS) 4948 5010 UpdateMCSA() 4949 5011 wx.CallAfter(G2plt.PlotStructure,G2frame,data) 
trunk/GSASIIplot.py
r939 r951 2616 2616 ''' 2617 2617 2618 def FindPeaksBonds(XYZ): 2619 rFact = drawingData['radiusFactor'] 2620 Bonds = [[] for x in XYZ] 2621 for i,xyz in enumerate(XYZ): 2622 Dx = XYZxyz 2623 dist = np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1)) 2624 IndB = ma.nonzero(ma.masked_greater(dist,rFact*2.2)) 2625 for j in IndB[0]: 2626 Bonds[i].append(Dx[j]/2.) 2627 Bonds[j].append(Dx[j]/2.) 2628 return Bonds 2629 2618 2630 ForthirdPI = 4.0*math.pi/3.0 2619 2631 generalData = data['General'] … … 2624 2636 A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 2625 2637 B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 2638 SGData = generalData['SGData'] 2626 2639 Mydir = generalData['Mydir'] 2627 2640 atomData = data['Atoms'] … … 2643 2656 MCSA = data.get('MCSA',{}) 2644 2657 mcsaModels = MCSA.get('Models',[]) 2658 if mcsaModels: 2659 mcsaXYZ,atTypes = G2mth.UpdateMCSAxyz(Bmat,MCSA) 2660 XYZeq = [] 2661 for xyz in mcsaXYZ: 2662 XYZeq += G2spc.GenAtom(xyz,SGData)[0][1:] #skip self xyz 2663 2664 mcsaBonds = FindPeaksBonds(mcsaXYZ) 2645 2665 drawAtoms = drawingData.get('Atoms',[]) 2646 2666 mapData = {} … … 2673 2693 ctrlDown = False 2674 2694 2675 def FindPeaksBonds(XYZ):2676 rFact = drawingData['radiusFactor']2677 Bonds = [[] for x in XYZ]2678 for i,xyz in enumerate(XYZ):2679 Dx = XYZxyz2680 dist = np.sqrt(np.sum(np.inner(Dx,Amat)**2,axis=1))2681 IndB = ma.nonzero(ma.masked_greater(dist,rFact*2.2))2682 for j in IndB[0]:2683 Bonds[i].append(Dx[j]/2.)2684 Bonds[j].append(Dx[j]/2.)2685 return Bonds2686 2687 2695 def OnKeyBox(event): 2688 2696 import Image … … 3496 3504 RenderLabel(x,y,z,name,0.2,Or) 3497 3505 if len(mcsaModels) > 1 and pageName == 'MC/SA': #skip the default MD entry 3498 XYZ,atTypes = G2mth.UpdateMCSAxyz(Bmat,MCSA) 3499 rbBonds = FindPeaksBonds(XYZ) 3500 for ind,[x,y,z] in enumerate(XYZ): 3506 for ind,[x,y,z] in enumerate(mcsaXYZ): 3501 3507 aType = atTypes[ind] 3502 3508 name = ' '+aType+str(ind) 3503 3509 color = np.array(MCSA['AtInfo'][aType][1]) 3504 3510 RenderSphere(x,y,z,0.2,color/255.) 3505 RenderBonds(x,y,z, rbBonds[ind],0.03,Gr)3511 RenderBonds(x,y,z,mcsaBonds[ind],0.03,Gr) 3506 3512 RenderLabel(x,y,z,name,0.2,Or) 3507 3513 if Backbones:
Note: See TracChangeset
for help on using the changeset viewer.