Changeset 4397 for trunk


Ignore:
Timestamp:
Apr 10, 2020 9:57:11 PM (3 years ago)
Author:
vondreele
Message:

fullrmc interface for run & view done (for now)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4389 r4397  
    45214521            G2frame.RMCchoice = RMCsel.GetStringSelection()
    45224522            UpdateRMC()
     4523           
     4524        def GetAtmChoice(RMCPdict):
     4525           
     4526            Indx = {}
     4527            def OnAtSel(event):
     4528                Obj = event.GetEventObject()
     4529                itype = Indx[Obj.GetId()]
     4530                tid = RMCPdict['atSeq'].index(Obj.GetStringSelection())
     4531                if itype < nTypes:
     4532                    if itype == tid:
     4533                        tid += 1
     4534                    RMCPdict['atSeq'] = G2lat.SwapItems(RMCPdict['atSeq'],itype,tid)
     4535                Pairs= []
     4536                atSeq = RMCPdict['atSeq']
     4537                lenA = len(atSeq)
     4538                for pair in [[' %s-%s'%(atSeq[i],atSeq[j]) for j in range(i,lenA)] for i in range(lenA)]:
     4539                    Pairs += pair
     4540                RMCPdict['Pairs'] = {pairs:[0.0,0.0,0.0] for pairs in Pairs}
     4541                if RMCPdict['useBVS']:
     4542                    BVSpairs = []
     4543                    for pair in [[' %s-%s'%(atSeq[i],atSeq[j]) for j in range(i+1,lenA)] for i in range(lenA)]:
     4544                        BVSpairs += pair
     4545                    RMCPdict['BVS'] = {pairs:[0.0,0.0,0.0,0.0] for pairs in BVSpairs}
     4546                wx.CallAfter(UpdateRMC)           
     4547           
     4548            def OnValSel(event):
     4549                Obj = event.GetEventObject()
     4550                itype = Indx[Obj.GetId()]
     4551                RMCPdict['Oxid'][itype][0] = Obj.GetStringSelection()           
     4552                wx.CallAfter(UpdateRMC)
     4553   
     4554            nTypes = len(RMCPdict['aTypes'])
     4555            atmChoice = wx.FlexGridSizer(nTypes+1,5,5)
     4556            atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Set atom ordering: '),0,WACV)
     4557            for iType in range(nTypes):
     4558                atChoice = RMCPdict['atSeq'][iType:]
     4559                atmSel = wx.ComboBox(G2frame.FRMC,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
     4560                atmSel.SetStringSelection(RMCPdict['atSeq'][iType])
     4561                atmSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
     4562                Indx[atmSel.GetId()] = iType
     4563                atmChoice.Add(atmSel,0,WACV)
     4564            if RMCPdict['useBVS']:   
     4565                atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Select valence: '),0,WACV)
     4566                for itype in range(nTypes):
     4567                    valChoice = atmdata.BVSoxid[RMCPdict['atSeq'][itype]]
     4568                    valSel = wx.ComboBox(G2frame.FRMC,choices=valChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
     4569                    try:
     4570                        valSel.SetStringSelection(RMCPdict['Oxid'][itype][0])
     4571                    except IndexError:
     4572                        RMCPdict['Oxid'].append([RMCPdict['atSeq'][itype],0.0])
     4573                    valSel.Bind(wx.EVT_COMBOBOX,OnValSel)
     4574                    Indx[valSel.GetId()] = itype
     4575                    atmChoice.Add(valSel,0,WACV)
     4576                atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' BVS weight: '),0,WACV)
     4577                for itype in range(nTypes):
     4578                    atmChoice.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['Oxid'][itype],1,min=0.),0,WACV)
     4579            atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Set max shift: '),0,WACV)
     4580            for iType in range(nTypes):
     4581                atId = RMCPdict['atSeq'][iType]
     4582                atmChoice.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['aTypes'],atId,min=0.,max=1.),0,WACV)
     4583            return atmChoice
     4584           
    45234585       
    45244586        G2frame.GetStatusBar().SetStatusText('',1)
     
    45424604        mainSizer.Add((5,5),0,WACV)
    45434605        if G2frame.RMCchoice == 'fullrmc':
    4544             try:
    4545                 from fullrmc import Engine
    4546             except ModuleNotFoundError:
    4547                 wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
    4548           Install it in your python according to the instructions in
    4549           https://bachiraoun.github.io/fullrmc/index.html. ''',
    4550                     caption='fullrmc not installed',style=wx.ICON_INFORMATION)
    4551                 return
     4606          #   try:
     4607          #       from fullrmc import Engine
     4608          #   except ModuleNotFoundError:
     4609          #       wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
     4610          # Install it in your python according to the instructions in
     4611          # https://bachiraoun.github.io/fullrmc/index.html. ''',
     4612          #           caption='fullrmc not installed',style=wx.ICON_INFORMATION)
     4613          #       return
    45524614            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=''' "Fullrmc, a Rigid Body Reverse Monte Carlo Modeling Package Enabled with Machine Learning and Artificial Intelligence",     
    45534615 B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111. doi: https://doi.org/10.1002/jcc.24304
     
    45574619            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True)
    45584620            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc run.py file preparation:'),0,WACV)
     4621            if not data['RMC']['fullrmc']:
     4622                Atypes = data['General']['AtomTypes']
     4623                aTypes = dict(zip(Atypes,len(Atypes)*[0.10,]))
     4624                atSeq = list(aTypes.keys())
     4625                lenA = len(atSeq)
     4626                Pairs= []
     4627                for pair in [[' %s-%s'%(atSeq[i],atSeq[j]) for j in range(i,lenA)] for i in range(lenA)]:
     4628                    Pairs += pair
     4629                Pairs = {pairs:[0.0,0.0,0.0] for pairs in Pairs}
     4630                files = {'Neutron real space data; G(r): ':['',0.05,'G(r)','RMC',],
     4631                          'Neutron reciprocal space data; F(Q): ':['',0.05,'F(Q)','RMC',],
     4632                          'Neutron reciprocal space data; S(Q): ':['',0.05,'S(Q)','RMC',],
     4633                          'Xray real space data; G(r): ':['',0.01,'G(r)','RMC',],
     4634                          'Xray reciprocal space data; F(Q): ':['',0.01,'F(Q)','RMC',],}
     4635                data['RMC']['fullrmc'] = {'ifBox':True,'SuperCell':[1,1,1],'Box':[10.,10.,10.],'aTypes':aTypes,
     4636                    'atSeq':atSeq,'Pairs':Pairs,'files':files,'ReStart':[False,False],'Swaps':[],'useBVS':False,
     4637                    'AveCN':[],'FxCN':[],}
     4638            RMCPdict = data['RMC']['fullrmc']
     4639
     4640            def GetSuperSizer():
     4641                superSizer = wx.BoxSizer(wx.HORIZONTAL)
     4642                axes = ['X','Y','Z']
     4643                for i,ax in enumerate(axes):
     4644                    superSizer.Add(wx.StaticText(G2frame.FRMC,label=' %s-axis: '%ax),0,WACV)
     4645                    superSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['SuperCell'],
     4646                        i,min=1,max=20,size=(50,25)),0,WACV)
     4647                return superSizer
     4648
     4649            def GetBoxSizer():
     4650                boxSizer = wx.BoxSizer(wx.HORIZONTAL)
     4651                axes = ['X','Y','Z']
     4652                for i,ax in enumerate(axes):
     4653                    boxSizer.Add(wx.StaticText(G2frame.FRMC,label=' %s-axis: '%ax),0,WACV)
     4654                    boxSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['Box'],
     4655                        i,min=10.,max=50.,size=(50,25)),0,WACV)
     4656                return boxSizer
     4657           
     4658            def OnBoxChoice(event):
     4659                RMCPdict['ifBox'] = not RMCPdict['ifBox']
     4660                UpdateRMC()
     4661               
     4662            def OnReStart(event):
     4663                RMCPdict['ReStart'][0] = not RMCPdict['ReStart'][0]
     4664#patches
     4665            if 'useBVS' not in RMCPdict:
     4666                RMCPdict['useBVS'] = False
     4667#end patches
     4668            restart = wx.CheckBox(G2frame.FRMC,label=' Restart fullrmc Engine? (will clear old result!) ')
     4669            restart.SetValue(RMCPdict['ReStart'][0])
     4670            restart.Bind(wx.EVT_CHECKBOX,OnReStart)
     4671            mainSizer.Add(restart,0,WACV)
     4672
     4673            lineSizer = wx.BoxSizer(wx.HORIZONTAL)
     4674            if RMCPdict['ifBox']:
     4675                lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Big box dimensions:'),0,WACV)               
     4676                lineSizer.Add(GetBoxSizer(),0,WACV)
     4677                boxBtn = wx.Button(G2frame.FRMC,label='Use super lattice')
     4678            else:
     4679                lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Lattice multipliers:'),0,WACV)
     4680                lineSizer.Add(GetSuperSizer(),0,WACV)
     4681                boxBtn = wx.Button(G2frame.FRMC,label='Use big box dimensions')
     4682            boxBtn.Bind(wx.EVT_BUTTON,OnBoxChoice)
     4683            lineSizer.Add(boxBtn,0,WACV)
     4684            mainSizer.Add(lineSizer,0,WACV)
     4685           
     4686            mainSizer.Add(GetAtmChoice(RMCPdict),0,WACV)
     4687           
     4688           
     4689               
    45594690        elif G2frame.RMCchoice ==  'RMCProfile':
    45604691            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=''' "RMCProfile: Reverse Monte Carlo for polycrystalline materials", M.G. Tucker, D.A. Keen, M.T. Dove, A.L. Goodwin and Q. Hui,
     
    45914722                    'Stretch search':10.,'Pot. Temp.':300.,
    45924723                    }}
     4724               
    45934725            RMCPdict = data['RMC']['RMCProfile']
    45944726#patches
    45954727            if 'FitScale' not in RMCPdict:
    45964728                RMCPdict['FitScale'] = False
     4729               
    45974730#end patches
    45984731               
     
    46804813                        i,min=1,max=20,size=(50,25),OnLeave=SetRestart),0,WACV)
    46814814                return superSizer
    4682            
    4683             def GetAtmChoice():
    4684                
    4685                 def OnAtSel(event):
    4686                     Obj = event.GetEventObject()
    4687                     itype = Indx[Obj.GetId()]
    4688                     tid = RMCPdict['atSeq'].index(Obj.GetStringSelection())
    4689                     if itype < nTypes:
    4690                         if itype == tid:
    4691                             tid += 1
    4692                         RMCPdict['atSeq'] = G2lat.SwapItems(RMCPdict['atSeq'],itype,tid)
    4693                     Pairs= []
    4694                     atSeq = RMCPdict['atSeq']
    4695                     lenA = len(atSeq)
    4696                     for pair in [[' %s-%s'%(atSeq[i],atSeq[j]) for j in range(i,lenA)] for i in range(lenA)]:
    4697                         Pairs += pair
    4698                     RMCPdict['Pairs'] = {pairs:[0.0,0.0,0.0] for pairs in Pairs}
    4699                     if RMCPdict['useBVS']:
    4700                         BVSpairs = []
    4701                         for pair in [[' %s-%s'%(atSeq[i],atSeq[j]) for j in range(i+1,lenA)] for i in range(lenA)]:
    4702                             BVSpairs += pair
    4703                         RMCPdict['BVS'] = {pairs:[0.0,0.0,0.0,0.0] for pairs in BVSpairs}
    4704                     wx.CallAfter(UpdateRMC)           
    4705                
    4706                 def OnValSel(event):
    4707                     Obj = event.GetEventObject()
    4708                     itype = Indx[Obj.GetId()]
    4709                     RMCPdict['Oxid'][itype][0] = Obj.GetStringSelection()           
    4710                     wx.CallAfter(UpdateRMC)
    4711        
    4712                 nTypes = len(RMCPdict['aTypes'])
    4713                 atmChoice = wx.FlexGridSizer(nTypes+1,5,5)
    4714                 atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Set atom ordering: '),0,WACV)
    4715                 for iType in range(nTypes):
    4716                     atChoice = RMCPdict['atSeq'][iType:]
    4717                     atmSel = wx.ComboBox(G2frame.FRMC,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
    4718                     atmSel.SetStringSelection(RMCPdict['atSeq'][iType])
    4719                     atmSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
    4720                     Indx[atmSel.GetId()] = iType
    4721                     atmChoice.Add(atmSel,0,WACV)
    4722                 if RMCPdict['useBVS']:   
    4723                     atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Select valence: '),0,WACV)
    4724                     for itype in range(nTypes):
    4725                         valChoice = atmdata.BVSoxid[RMCPdict['atSeq'][itype]]
    4726                         valSel = wx.ComboBox(G2frame.FRMC,choices=valChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
    4727                         try:
    4728                             valSel.SetStringSelection(RMCPdict['Oxid'][itype][0])
    4729                         except IndexError:
    4730                             RMCPdict['Oxid'].append([RMCPdict['atSeq'][itype],0.0])
    4731                         valSel.Bind(wx.EVT_COMBOBOX,OnValSel)
    4732                         Indx[valSel.GetId()] = itype
    4733                         atmChoice.Add(valSel,0,WACV)
    4734                     atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' BVS weight: '),0,WACV)
    4735                     for itype in range(nTypes):
    4736                         atmChoice.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['Oxid'][itype],1,min=0.),0,WACV)
    4737                 atmChoice.Add(wx.StaticText(G2frame.FRMC,label=' Set max shift: '),0,WACV)
    4738                 for iType in range(nTypes):
    4739                     atId = RMCPdict['atSeq'][iType]
    4740                     atmChoice.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['aTypes'],atId,min=0.,max=1.),0,WACV)
    4741                 return atmChoice
    4742          
     4815                     
    47434816            def GetPairSizer():
    47444817                pairSizer = wx.FlexGridSizer(len(RMCPdict['Pairs'])+1,5,5)
     
    49875060           
    49885061            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' NB: be sure to set cations first && anions last in atom ordering'),0,WACV)
    4989             mainSizer.Add(GetAtmChoice(),0,WACV)
     5062            mainSizer.Add(GetAtmChoice(RMCPdict),0,WACV)
    49905063           
    49915064            G2G.HorizontalLine(mainSizer,G2frame.FRMC)
     
    51235196            G2frame.OnFileSaveas(event)
    51245197        if G2frame.RMCchoice == 'fullrmc':
    5125             print ('TBD')
    5126             return
    5127             print('set up rmcfull *.pdb & *.py files TBD')
    51285198            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
    51295199            RMCPdict = data['RMC']['fullrmc']
    5130             print(G2pwd.MakePDB(pName,data,RMCPdict)+ ' written')
    5131             print(G2pwd.MakefullrmcRun(pName,data,RMCPdict)+ ' written')
     5200            if RMCPdict['ifBox']:
     5201                print(G2pwd.MakepdparserPDB(pName,data,RMCPdict)+ ' written')
     5202            else:
     5203                print(G2pwd.MakefullrmcPDB(pName,data,RMCPdict)+ ' written')
     5204            #print(G2pwd.MakefullrmcRun(pName,data,RMCPdict)+ ' written')
    51325205            print('fullrmc file build completed')
    51335206        else:
     
    51735246        pName = generalData['Name'].replace(' ','_')
    51745247        if G2frame.RMCchoice == 'fullrmc':
     5248            RMCPdict = data['RMC']['fullrmc']
    51755249            wx.MessageBox(''' For use of fullrmc, please cite:
    51765250      Fullrmc, a Rigid Body Reverse Monte Carlo Modeling Package Enabled with
    51775251      Machine Learning and Artificial Intelligence,
    5178       B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111.
     5252      B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111. 
    51795253      doi: https://doi.org/10.1002/jcc.24304''',caption='fullrmc',style=wx.ICON_INFORMATION)
    5180             # TBD - remove filedialog & use defined run.py file name here
     5254            rmcname = pName+'.rmc'           
     5255            while os.path.isdir(rmcname) and RMCPdict['ReStart']:
     5256                msg = wx.MessageBox(''' fullrmc will fail to restart if %s exists. You must delete %s by hand now.'''%(rmcname,rmcname),
     5257                    caption='fullrmc file error',style=wx.ICON_EXCLAMATION|wx.OK|wx.CANCEL)
     5258                if msg != wx.OK:
     5259                    return
     5260            ilog = 0
     5261            while True:
     5262                logname = 'fullrmc_%d.log'%ilog
     5263                if os.path.isfile(logname):
     5264                    os.remove(logname)
     5265                else:
     5266                    break
     5267                ilog += 1
     5268# TBD - remove filedialog & use defined run.py file name here
    51815269            dlg = wx.FileDialog(G2frame, 'Choose fullrmc python file to execute', G2G.GetImportPath(G2frame),
    51825270                wildcard='fullrmc python file (*.py)|*.py',style=wx.FD_CHANGE_DIR)
     
    51855273                    import subprocess as sb
    51865274                    batch = open('fullrmc.bat','w')
    5187                     batch.write('run '+sys.exec_prefix+'\\Scripts\\activate\n')
     5275                    batch.write('CALL '+sys.exec_prefix+'\\Scripts\\activate\n')
    51885276                    batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n')
    51895277                    batch.write('pause')
    51905278                    batch.close()
    5191                     sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE)
     5279                    RMCPdict['pid'] = sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE).pid
    51925280                else:
    51935281                    return
     
    51955283                dlg.Destroy()
    51965284        else:
     5285            RMCPdict = data['RMC']['RMCProfile']
    51975286            rmcfile = G2fl.find('rmcprofile.exe',GSASIIpath.path2GSAS2)
    51985287            rmcexe = os.path.split(rmcfile)[0]
     
    52505339    def OnViewRMC(event):
    52515340        if G2frame.RMCchoice == 'fullrmc':
     5341            RMCPdict = data['RMC']['fullrmc']
    52525342            generalData = data['General']
    52535343            pName = generalData['Name'].replace(' ','_')
     5344            import psutil
     5345            pid = RMCPdict.get('pid',-1)
     5346            Proc = None
     5347            if pid and psutil.pid_exists(pid):
     5348                proc = psutil.Process(pid).children()
     5349                for child in proc:
     5350                    if 'conhost' in child.name():       #probably very Windows specific
     5351                        Proc = child
    52545352            from fullrmc import Engine
    52555353            # load
    52565354            engineFilePath = pName+'.rmc'
    52575355            ENGINE = Engine(path=None)
     5356            eNames = ['Total',]
     5357            nObs = [0,]
    52585358            try:
    52595359                if engineFilePath is not None:
    52605360                    result, mes = ENGINE.is_engine(engineFilePath, mes=True)
    52615361                    if result:
     5362                        if Proc is not None:
     5363                            Proc.suspend()
    52625364                        ENGINE = ENGINE.load(engineFilePath)
    52635365                        found = False
     
    52735375                                    title = ' g(r) for '
    52745376                                    if 'StructureFactor' in sitem:
     5377                                        eNames.append('S(Q)')
    52755378                                        Xlab = r'$\mathsf{Q,\AA^{-1}}$'
    52765379                                        Ylab = 'S(Q)'
    52775380                                        title = ' S(Q) for '
    5278                                     if frame != '0':
     5381                                    else:
     5382                                        eNames.append('g(r)')
    52795383                                        title = frame+title
    52805384                                    dataDict= item.get_constraints_properties(frame)
    52815385                                    X = dataDict['frames-experimental_x'][0]
    52825386                                    Y = dataDict['frames-experimental_y'][0]
     5387                                    nObs.append(X.shape[0])
    52835388                                    rdfDict = item.get_constraint_value()
     5389                                    if 'total' not in rdfDict:
     5390                                        print('No data yet - wait for a save')
     5391                                        if Proc is not None:
     5392                                            Proc.resume()
     5393                                        return
    52845394                                    Z = rdfDict['total']
    52855395                                    XY = [[X,Y],[X,Z]]
     
    53085418                                    found = True
    53095419                                    if 'BondConstraint' in sitem:
    5310                                         bonds = item.get_constraint_value()['bondsLength']
     5420                                        try:
     5421                                            bonds = item.get_constraint_value()['bondsLength']
     5422                                        except TypeError:
     5423                                            break
    53115424                                        bondList = item.bondsList[:2]
    53125425                                        atoms = ENGINE.get_original_data("allElements",frame)
     
    53475460                                        item.plot(show=True)
    53485461                                        pass
     5462                            nObs[0] = np.sum(nObs[1:])
    53495463                        if not found:
    5350                             print(' No saved information yet, wait until fullrms does a Save')
     5464                            print(' No saved information yet, wait until fullrmc does a Save')
     5465                            eNames = []
     5466                        ENGINE.close()      #return lock on ENGINE repository & close it
     5467                        if Proc is not None:
     5468                            Proc.resume()
    53515469            except AssertionError:
    53525470                 print("Can't open fullrmc engine while running")
    5353             try:
    5354                 logfile = open('fullrmc.log','r')
    5355             except FileNotFoundError:
    5356                 logfile = open('fullrmc_0.log','r')
    5357             loglines = logfile.readlines()
    5358             logfile.close()
     5471            loglines = []
     5472            ilog = 0
     5473            while True:
     5474                fname = 'fullrmc_%d.log'%ilog
     5475                try:
     5476                    logfile = open(fname,'r')
     5477                    loglines += logfile.readlines()
     5478                    logfile.close()
     5479                except FileNotFoundError:
     5480                    break
     5481                ilog += 1
     5482            if not len(loglines):
     5483                print('no log file found')
     5484                return
    53595485            start = 0
    53605486            while True:
     5487                if start == len(loglines):
     5488                    print('No log info to plot')
     5489                    return
    53615490                line = loglines[start]               
    53625491                if 'Err:' in line:
     
    53655494                    start += 1
    53665495            Gen = []
    5367             Tr = []
    5368             Acc = []
    5369             Rem = []
     5496            # Tr = []
     5497            # Acc = []
     5498            # Rem = []
    53705499            Err = []
    53715500            start -= 1
     
    53805509                items = line.split(' - ')
    53815510                try:    # could be a trashed line at end
    5382                     Err.append(float(items[5][:-1].split('Err:')[1]))
     5511                    errStr = items[5][:-1].split('Err:')[1]
     5512                    Err.append([float(val) for val in errStr.split(',')])
    53835513                except ValueError:
    53845514                    break
    53855515                Gen.append(int(items[1].split('Gen:')[1]))
    5386                 Tr.append(float(items[2].split('(')[1].split('%)')[0]))
    5387                 Acc.append(float(items[3].split('(')[1].split('%)')[0]))
    5388                 Rem.append(float(items[4].split('(')[1].split('%)')[0]))
    53895516           
    53905517            Gen = np.array(Gen)
    5391             Tr = np.array(Tr)
    5392             Acc = np.array(Acc)
    5393             Rem = np.array(Rem)
    5394             Err = np.log10(np.array(Err))
    5395             Names = ['Tr','Acc','Rem','Err']
    5396             XY = [[Gen,Tr],[Gen,Acc],[Gen,Rem],[Gen,Err]]
    5397             G2plt.PlotXY(G2frame,XY,labelX='no. generated',
    5398                 labelY=r'$log_{10}(Err)\ &\ residuals,\ %$',newPlot=True,Title='fullrmc residuals for '+pName,
    5399                 lines=True,names=Names)
     5518            Err = np.array(Err)
     5519            nObs = np.array(nObs)
     5520            if np.any(nObs):
     5521                Err /= nObs[:Err.shape[1]]
     5522                ptstr1 = ''
     5523                ptstr2 = ''
     5524                for it,item in enumerate(eNames):
     5525                    ptstr1 += ' %s obs: %d'%(item,nObs[it])
     5526                    ptstr2 += ' %s reduced chi^2: %.5f'%(item,Err[-1][it])
     5527                print(ptstr1)
     5528                print(ptstr2)
     5529                Err = np.log10(Err)
     5530                XY = [[Gen,Erri] for Erri in Err.T]
     5531                G2plt.PlotXY(G2frame,XY,labelX='no. generated',
     5532                    labelY=r'$log_{10}$ (reduced $\mathsf{\chi^2})$',newPlot=True,Title='fullrmc residuals for '+pName,
     5533                    lines=True,names=eNames)
    54005534                     
    54015535        else:
     
    1033610470        startDmin = generalData['Pawley dmin']
    1033710471        genDlg = wx.Dialog(G2frame,wx.ID_ANY,'Set Pawley Parameters',
    10338                         style=wx.DEFAULT_DIALOG_STYLE)
     10472                    style=wx.DEFAULT_DIALOG_STYLE)
    1033910473        mainSizer = wx.BoxSizer(wx.VERTICAL)
    1034010474        mainSizer.Add(wx.StaticText(genDlg,wx.ID_ANY,
    10341                                     'Set Pawley Extraction Parameters for phase '+
    10342                                     generalData.get('Name','?')))
     10475            'Set Pawley Extraction Parameters for phase '+generalData.get('Name','?')))
    1034310476        mainSizer.Add([5,10])
    1034410477        pawleySizer = wx.BoxSizer(wx.HORIZONTAL)
    1034510478        pawleySizer.Add(wx.StaticText(genDlg,label=' Do Pawley refinement?: '),0,WACV)
    10346         pawlRef = G2G.G2CheckBox(genDlg,'',generalData,'doPawley',
    10347                              DisablePawleyOpts)
     10479        pawlRef = G2G.G2CheckBox(genDlg,'',generalData,'doPawley',DisablePawleyOpts)
    1034810480        pawleySizer.Add(pawlRef,0,WACV)
    1034910481        mainSizer.Add(pawleySizer)
     
    1035410486            pawlQVal.SetValue(temp['Qmax'])
    1035510487        pawlVal = G2G.ValidatedTxtCtrl(genDlg,generalData,'Pawley dmin',
    10356                min=0.25,max=20.,nDig=(10,5),typeHint=float,OnLeave=d2Q)
     10488            min=0.25,max=20.,nDig=(10,5),typeHint=float,OnLeave=d2Q)
    1035710489        pawleySizer.Add(pawlVal,0,WACV)
    1035810490        pawleySizer.Add(wx.StaticText(genDlg,label='   Qmax: '),0,WACV)
     
    1036210494            pawlVal.SetValue(generalData['Pawley dmin'])       
    1036310495        pawlQVal = G2G.ValidatedTxtCtrl(genDlg,temp,'Qmax',
    10364                min=0.314,max=25.,nDig=(10,5),typeHint=float,OnLeave=Q2D)
     10496            min=0.314,max=25.,nDig=(10,5),typeHint=float,OnLeave=Q2D)
    1036510497        pawleySizer.Add(pawlQVal,0,WACV)
    1036610498        mainSizer.Add(pawleySizer)
     
    1036810500        pawleySizer.Add(wx.StaticText(genDlg,label=' Pawley neg. wt.: '),0,WACV)
    1036910501        pawlNegWt = G2G.ValidatedTxtCtrl(genDlg,generalData,'Pawley neg wt',
    10370                     min=0.,max=1.,nDig=(10,4),typeHint=float)
     10502            min=0.,max=1.,nDig=(10,4),typeHint=float)
    1037110503        pawleySizer.Add(pawlNegWt,0,WACV)
    1037210504        mainSizer.Add(pawleySizer)
  • trunk/GSASIIpwd.py

    r4389 r4397  
    25002500   
    25012501
    2502 def MakePDB(Name,Phase,RMCPdict):
    2503     return None
    2504     # generalData = Phase['General']
    2505     # Cell = generalData['Cell'][1:7]
    2506     # Trans = np.eye(3)*np.array(Supercell)
    2507     # newPhase = copy.deepcopy(Phase)
    2508     # newPhase['General']['SGData'] = G2spc.SpcGroup('P 1')[1]
    2509     # newPhase['General']['Cell'][1:] = G2lat.TransformCell(Cell,Trans.T)
    2510     # newPhase,Atcodes = G2lat.TransformPhase(Phase,newPhase,Trans,np.zeros(3),np.zeros(3),ifMag=False)
    2511     # Atoms = newPhase['Atoms']
    2512     # Cell = newPhase['General']['Cell'][1:7]
    2513     # A,B = G2lat. cell2AB(Cell)
    2514     # fname = Name+'.pdb'
    2515     # fl = open(fname,'w')
    2516     # fl.write('REMARK    this file is generated using GSASII\n')
    2517     # fl.write('CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n'%(
    2518     #         Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5]))
    2519     # fl.write('ORIGX1      1.000000  0.000000  0.000000        0.00000\n')
    2520     # fl.write('ORIGX2      0.000000  1.000000  0.000000        0.00000\n')
    2521     # fl.write('ORIGX3      0.000000  0.000000  1.000000        0.00000\n')
    2522 
    2523     # Natm = np.core.defchararray.count(np.array(Atcodes),'+')
    2524     # Natm = np.count_nonzero(Natm-1)
    2525     # nat = 0
    2526     # for atm in Atseq:
    2527     #     for iat,atom in enumerate(Atoms):
    2528     #         if atom[1] == atm:
    2529     #             nat += 1
    2530     #             XYZ = np.inner(A,np.array(atom[3:6])-0.5)    #shift origin to middle & make Cartesian
    2531     #             fl.write('ATOM  %5d %-4s RMC%6d%12.3f%8.3f%8.3f  1.00  0.00          %-2s\n'%(       
    2532     #                     nat,atom[0],nat,XYZ[0],XYZ[1],XYZ[2],atom[1]))
    2533     # fl.close()
    2534     # return fname
     2502def MakefullrmcPDB(Name,Phase,RMCPdict):
     2503    generalData = Phase['General']
     2504    Atseq = RMCPdict['atSeq']
     2505    Supercell = RMCPdict['SuperCell']
     2506    Cell = generalData['Cell'][1:7]
     2507    Trans = np.eye(3)*np.array(Supercell)
     2508    newPhase = copy.deepcopy(Phase)
     2509    newPhase['General']['SGData'] = G2spc.SpcGroup('P 1')[1]
     2510    newPhase['General']['Cell'][1:] = G2lat.TransformCell(Cell,Trans.T)
     2511    newPhase,Atcodes = G2lat.TransformPhase(Phase,newPhase,Trans,np.zeros(3),np.zeros(3),ifMag=False)
     2512    Atoms = newPhase['Atoms']
     2513    XYZ = np.array([atom[3:6] for atom in Atoms]).T
     2514    XYZptp = np.array([ma.ptp(XYZ[0]),ma.ptp(XYZ[1]),ma.ptp(XYZ[2])])/2.
     2515    Cell = newPhase['General']['Cell'][1:7]
     2516    A,B = G2lat. cell2AB(Cell)
     2517    fname = Name+'.pdb'
     2518    fl = open(fname,'w')
     2519    fl.write('REMARK    this file is generated using GSASII\n')
     2520    fl.write('REMARK    Boundary Conditions:%6.2f  0.0  0.0  0.0%7.2f  0.0  0.0  0.0%7.2f\n'%(
     2521             Cell[0],Cell[1],Cell[2]))
     2522    fl.write('CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n'%(
     2523            Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5]))
     2524    fl.write('ORIGX1      1.000000  0.000000  0.000000        0.00000\n')
     2525    fl.write('ORIGX2      0.000000  1.000000  0.000000        0.00000\n')
     2526    fl.write('ORIGX3      0.000000  0.000000  1.000000        0.00000\n')
     2527
     2528    Natm = np.core.defchararray.count(np.array(Atcodes),'+')
     2529    Natm = np.count_nonzero(Natm-1)
     2530    nat = 0
     2531    for atm in Atseq:
     2532        for iat,atom in enumerate(Atoms):
     2533            if atom[1] == atm:
     2534                nat += 1
     2535                XYZ = np.inner(A,np.array(atom[3:6])-XYZptp)    #shift origin to middle & make Cartesian
     2536                fl.write('ATOM  %5d %-4s RMC%6d%12.3f%8.3f%8.3f  1.00  0.00          %-2s\n'%(       
     2537                        nat,atom[0],nat,XYZ[0],XYZ[1],XYZ[2],atom[1].lower()))
     2538    fl.close()
     2539    return fname
     2540   
     2541def MakepdparserPDB(Name,Phase,RMCPdict):
     2542    import pdbparser as pdp
     2543    fname = Name+'.pdb'
     2544    fl = open(fname,'w')
     2545    fl.write('REMARK    this file to be generated using pdbparser\n')
     2546    fl.close()
     2547    return fname
    25352548
    25362549def GetRMCBonds(general,RMCPdict,Atoms,bondList):
Note: See TracChangeset for help on using the changeset viewer.