Changeset 4389


Ignore:
Timestamp:
Apr 2, 2020 1:44:42 PM (5 years ago)
Author:
vondreele
Message:

adding fullrmc View & Execute methods. Still to do Setup.
Replace SetText? with SetItemLabel? for the Refine menu item . SetText? is obsolete
remove Load/Save? menu items in RMC tab - won't be used
put in citation info for RMCProfile & fullrmc
remove G2frame from RMCProfile Make routines in G2pwdr. It's a wx object & shouldn't be in there.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIdataGUI.py

    r4379 r4389  
    391391       
    392392###############################################################################
    393 # GUI creation
     393#### GUI creation
    394394###############################################################################
    395395def GSASIImain(application):
     
    441441
    442442################################################################################
    443 # Create main frame (window) for GUI
     443#### Create main frame (window) for GUI
    444444################################################################################
    445445class GSASII(wx.Frame):
     
    599599        if seqSetting:
    600600            for item in self.Refine:
    601                 item.SetText('Se&quential refine\tCtrl+R')
     601                item.SetItemLabel('Se&quential refine\tCtrl+R')    #might fail on old wx
    602602            seqMode = True
    603603        else:
    604604            for item in self.Refine:
    605                 item.SetText('&Refine\tCtrl+R')
     605                item.SetItemLabel('&Refine\tCtrl+R')    #might fail on old wx
    606606            seqMode = False
    607607        for menu,Id in self.ExportSeq:
     
    58355835       
    58365836        #Phase / fullrmc & RMCprofile (Reverse Monte Carlo method) tab
    5837         G2G.Define_wxId('wxID_SETUPRMC','wxID_LOADRMC','wxID_SAVERMC','wxID_RUNRMC','wxID_VIEWRMC' )       
     5837        G2G.Define_wxId('wxID_SETUPRMC','wxID_RUNRMC','wxID_VIEWRMC' )       
    58385838        self.FRMCMenu = wx.MenuBar()
    58395839        self.PrefillDataMenu(self.FRMCMenu)
     
    58425842        self.FRMCMenu.Append(menu=self.FRMCDataEdit, title='Operations')
    58435843        self.FRMCDataEdit.Append(G2G.wxID_SETUPRMC,'Setup RMC','Setup new fullrmc or RMCprofile file')
    5844         self.FRMCDataEdit.Append(G2G.wxID_LOADRMC,'Load','Load fullrmc or RMCprofile file')
    5845         self.FRMCDataEdit.Append(G2G.wxID_SAVERMC,'Save','Save fullrmc or RMCprofile file')
    58465844        self.FRMCDataEdit.Append(G2G.wxID_RUNRMC,'Execute','Run fullrmc or RMCprofile file')
    58475845        self.FRMCDataEdit.Append(G2G.wxID_VIEWRMC,'View','View fullrmc or RMCprofile results')
  • TabularUnified trunk/GSASIIphsGUI.py

    r4378 r4389  
    10891089        parent.Raise()
    10901090        self.EndModal(wx.ID_CANCEL)
    1091 
    1092        
    1093 class SetUpFullrmcDialog(wx.Dialog):
    1094     ''' Get from user the super cell size & selected histogram to make various files
    1095     '''
    1096     def __init__(self,parent,Name,Phase):
    1097         title = 'fullrmc setup'
    1098         wx.Dialog.__init__(self,parent,wx.ID_ANY,title,
    1099             pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    1100         self.panel = wxscroll.ScrolledPanel(self)         #just a dummy - gets destroyed in Draw!
    1101         self.Name = Name
    1102         self.Phase = Phase
    1103         self.SuperCell = [1,1,1]
    1104         self.aTypes = self.Phase['General']['AtomTypes']
    1105         self.atSeq = self.aTypes[:]
    1106 #        self.histogram = ''
    1107 #        self.metadata = {'title':'none','owner':'no one','date':str(time.ctime()),
    1108 #                         'material':'nothing','comment':'none ','source':'nowhere'}
    1109         self.Draw()
    1110        
    1111     def Draw(self):
    1112        
    1113 #        def OnHisto(event):
    1114 #            self.histogram = histo.GetStringSelection()
    1115            
    1116         def OnAtSel(event):
    1117             Obj = event.GetEventObject()
    1118             itype = Indx[Obj.GetId()]
    1119             tid = Obj.GetSelection()
    1120             if itype < nTypes-1:
    1121                 if itype == tid:
    1122                     tid += 1
    1123                 self.atSeq = G2lat.SwapItems(self.atSeq,itype,tid)
    1124             wx.CallAfter(self.Draw)
    1125        
    1126         self.panel.Destroy()
    1127         self.panel = wxscroll.ScrolledPanel(self,style = wx.DEFAULT_DIALOG_STYLE)
    1128         mainSizer = wx.BoxSizer(wx.VERTICAL)
    1129         mainSizer.Add(wx.StaticText(self.panel,label=' Setup for: %s'%self.Name),0,WACV)
    1130         superSizer = wx.BoxSizer(wx.HORIZONTAL)
    1131         axes = ['X','Y','Z']
    1132         for i,ax in enumerate(axes):
    1133             superSizer.Add(wx.StaticText(self.panel,label=' %s-axis: '%ax),0,WACV)
    1134             superSizer.Add(G2G.ValidatedTxtCtrl(self.panel,self.SuperCell,i,min=1,max=15,size=(50,25)),0,WACV)
    1135         mainSizer.Add(superSizer,0,WACV)
    1136         nTypes = len(self.aTypes)
    1137         atmChoice = wx.BoxSizer(wx.HORIZONTAL)
    1138         atmChoice.Add(wx.StaticText(self.panel,label=' Set atom ordering: '),0,WACV)
    1139         Indx = {}
    1140         for iType in range(nTypes):
    1141             atChoice = self.atSeq[iType:]
    1142             atmSel = wx.ComboBox(self.panel,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
    1143             atmSel.SetStringSelection(self.atSeq[iType])
    1144             atmSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
    1145             Indx[atmSel.GetId()] = iType
    1146             atmChoice.Add(atmSel,0,WACV)
    1147         mainSizer.Add(atmChoice,0,WACV)
    1148         mainSizer.Add(wx.StaticText(self.panel,label=' WARNING: this can take time - be patient'),0,WACV)
    1149         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
    1150         OKBtn = wx.Button(self.panel,-1,"OK")
    1151         OKBtn.Bind(wx.EVT_BUTTON, self.OnOK)
    1152         btnSizer.Add(OKBtn)           
    1153        
    1154         mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
    1155         self.panel.SetSizer(mainSizer)
    1156         size = np.array(self.GetSize())
    1157         self.panel.SetupScrolling()
    1158         self.panel.SetAutoLayout(1)
    1159         size = [size[0]-5,size[1]-20]       #this fiddling is needed for older wx!
    1160         self.panel.SetSize(size)
    1161        
    1162     def GetData(self):
    1163         'Returns the values from the dialog'
    1164         return self.SuperCell,self.atSeq
    1165        
    1166     def OnOK(self,event):
    1167         parent = self.GetParent()
    1168         parent.Raise()
    1169         self.EndModal(wx.ID_OK)
    11701091
    11711092################################################################################
     
    46044525        if G2frame.RMCchoice == 'RMCProfile':
    46054526            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SETUPRMC,True)
    4606             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_LOADRMC,False)
    4607             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SAVERMC,False)
    46084527            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
    46094528            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True)
    46104529        elif G2frame.RMCchoice == 'fullrmc':
    46114530            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SETUPRMC,False)
    4612             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_LOADRMC,False)
    4613             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SAVERMC,False)
    46144531            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
    46154532            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,False)
    4616             wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
    4617       Install it in your python according to the instructions in
    4618       https://bachiraoun.github.io/fullrmc/index.html. ''',
    4619                 caption='fullrmc not installed',style=wx.ICON_INFORMATION)
    46204533        if G2frame.FRMC.GetSizer():
    46214534            G2frame.FRMC.GetSizer().Clear(True)
     
    46324545                from fullrmc import Engine
    46334546            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)
    46344551                return
     4552            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=''' "Fullrmc, a Rigid Body Reverse Monte Carlo Modeling Package Enabled with Machine Learning and Artificial Intelligence",     
     4553 B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111. doi: https://doi.org/10.1002/jcc.24304
     4554 '''))
    46354555            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SETUPRMC,True)
    4636             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_LOADRMC,True)
    4637             G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SAVERMC,True)
    46384556            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
    46394557            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True)
    46404558            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc run.py file preparation:'),0,WACV)
    4641 #            font1 = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')
    4642             G2frame.runtext = wx.TextCtrl(G2frame.FRMC,style=wx.TE_MULTILINE|wx.TE_DONTWRAP,size=(850,450))
    4643 #            G2frame.runtext.SetFont(font1)
    4644             mainSizer.Add(G2frame.runtext)
    46454559        elif G2frame.RMCchoice ==  'RMCProfile':
     4560            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,
     4561 Jour. Phys.: Cond. Matter 2007, 19, 335218. doi: https://doi.org/10.1088/0953-8984/19/33/335218
     4562 '''))
    46464563            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' RMCProfile setup:'))
    46474564            if not data['RMC']['RMCProfile']:
     
    52035120        generalData = data['General']
    52045121        pName = generalData['Name'].replace(' ','_')
     5122        if not G2frame.GSASprojectfile:     #force a project save
     5123            G2frame.OnFileSaveas(event)
    52055124        if G2frame.RMCchoice == 'fullrmc':
    5206             dlg = SetUpFullrmcDialog(G2frame,Name=pName,Phase=data)
    5207             if dlg.ShowModal() == wx.ID_OK:
    5208                 superCell,atSeq = dlg.GetData()
    5209 #                    Progress
    5210                 print(G2pwd.MakePDB(G2frame,pName,data,atSeq,superCell)+ ' written')
    5211                 print('fullrmc file build completed')
    5212             else:
    5213                 pass
    5214             dlg.Destroy()         
    5215             rundata = '''
    5216 ##########################################################################################
    5217 ##############################  IMPORTING USEFUL DEFINITIONS  ############################
    5218 # standard libraries imports
    5219 import os
    5220 
    5221 # external libraries imports
    5222 import numpy as np
    5223 
    5224 # fullrmc library imports - these are some examples; others may be needed for your problem
    5225 from fullrmc.Globals import LOGGER, FLOAT_TYPE
    5226 from fullrmc.Engine import Engine
    5227 from fullrmc.Constraints.PairDistributionConstraints import PairDistributionConstraint
    5228 from fullrmc.Constraints.PairCorrelationConstraints import PairCorrelationConstraint
    5229 from fullrmc.Constraints.DistanceConstraints import InterMolecularDistanceConstraint
    5230 from fullrmc.Constraints.BondConstraints import BondConstraint
    5231 from fullrmc.Constraints.AngleConstraints import BondsAngleConstraint
    5232 from fullrmc.Constraints.ImproperAngleConstraints import ImproperAngleConstraint
    5233 from fullrmc.Core.Collection import convert_Gr_to_gr
    5234 from fullrmc.Core.MoveGenerator import MoveGeneratorCollector
    5235 from fullrmc.Core.GroupSelector import RecursiveGroupSelector
    5236 from fullrmc.Selectors.RandomSelectors import RandomSelector
    5237 from fullrmc.Selectors.OrderedSelectors import DefinedOrderSelector
    5238 from fullrmc.Generators.Translations import TranslationGenerator, TranslationAlongSymmetryAxisGenerator
    5239 from fullrmc.Generators.Rotations import RotationGenerator, RotationAboutSymmetryAxisGenerator
    5240 from fullrmc.Generators.Agitations import DistanceAgitationGenerator, AngleAgitationGenerator
    5241 
    5242 
    5243 ##########################################################################################
    5244 #####################################  CREATE ENGINE  ####################################
    5245 # dirname
    5246 DIR_PATH = os.path.dirname( os.path.realpath(__file__) )
    5247 
    5248 # engine file names - replace name with phase name
    5249 engineFileName = "name_engine.rmc"
    5250 expFileName    = "name_pdf.exp"
    5251 pdbFileName    = "nme.pdb"
    5252 freshStart     = False      #make TRUE for a restart
    5253 
    5254             '''           
    5255             G2frame.runtext.SetValue(rundata)
     5125            print ('TBD')
     5126            return
     5127            print('set up rmcfull *.pdb & *.py files TBD')
     5128            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
     5129            RMCPdict = data['RMC']['fullrmc']
     5130            print(G2pwd.MakePDB(pName,data,RMCPdict)+ ' written')
     5131            print(G2pwd.MakefullrmcRun(pName,data,RMCPdict)+ ' written')
     5132            print('fullrmc file build completed')
    52565133        else:
    52575134            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
     
    52595136            PWId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,RMCPdict['histogram'][0])
    52605137            if PWId:
     5138                PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     5139                histoName = G2frame.GPXtree.GetItemPyData(PWId)[2]
     5140                Size = data['Histograms'][histoName]['Size']
     5141                Mustrain = data['Histograms'][histoName]['Mustrain']
    52615142                reset = False
    5262                 print(G2pwd.MakeInst(G2frame,pName,data,RMCPdict['UseSampBrd'],PWId)+ ' written')
    5263                 backfile = G2pwd.MakeBack(G2frame,pName,PWId)
     5143                print(G2pwd.MakeInst(PWDdata,pName,Size,Mustrain,RMCPdict['UseSampBrd'])+ ' written')
     5144                backfile = G2pwd.MakeBack(PWDdata,pName)
    52645145                if backfile is None:
    52655146                    print(' Chebyschev-1 background not used; no .back file written')
     
    52705151                else:
    52715152                    print(backfile+ ' written')
    5272                 print(G2pwd.MakeBragg(G2frame,pName,data,PWId)+ ' written')
     5153                print(G2pwd.MakeBragg(PWDdata,pName,data)+ ' written')
    52735154                if RMCPdict['ReStart'][0]:
    52745155                    if os.path.isfile(pName+'.his6f'):
    52755156                        os.remove(pName+'.his6f')
    5276                     RMC6f,reset = G2pwd.MakeRMC6f(G2frame,pName,data,RMCPdict,PWId)
     5157                    RMC6f,reset = G2pwd.MakeRMC6f(PWDdata,pName,data,RMCPdict)
    52775158                    print(RMC6f+ ' written')
    5278                 print(G2pwd.MakeRMCPdat(G2frame,pName,data,RMCPdict,PWId)+ ' written')
     5159                print(G2pwd.MakeRMCPdat(PWDdata,pName,data,RMCPdict)+ ' written')
    52795160                print('RMCProfile file build completed')
    52805161                RMCPdict['ReStart'] = [False,False]
     
    52875168                G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
    52885169           
    5289     def OnLoadRMC(event):
    5290         global runFile
    5291         if G2frame.RMCchoice == 'fullrmc':
    5292             dlg = wx.FileDialog(G2frame, 'Choose fullrmc run file to open', G2G.GetImportPath(G2frame), runFile,
    5293                 wildcard='fullrmc run.py file (*.py)|*.py',style=wx.FD_OPEN| wx.FD_CHANGE_DIR)
    5294         try:
    5295             if dlg.ShowModal() == wx.ID_OK:
    5296                 runFile = dlg.GetPath()
    5297                 runpy = open(runFile,'r')
    5298                 G2frame.runtext.SetValue(runpy.read())
    5299                 runpy.close()
    5300             else:
    5301                 return
    5302         finally:
    5303             dlg.Destroy()
    5304        
    5305     def OnSaveRMC(event):
    5306         global runFile
    5307         if G2frame.RMCchoice == 'fullrmc':
    5308             dlg = wx.FileDialog(G2frame, 'Choose fullrmc run.py file to save',  G2G.GetImportPath(G2frame), runFile,
    5309                 wildcard='fullrmc run.py file (*.py)|*.py',style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
    5310         try:
    5311             if dlg.ShowModal() == wx.ID_OK:
    5312                 runFile = dlg.GetPath()
    5313                 runpy = open(runFile,'w')
    5314                 runpy.write(G2frame.runtext.GetValue())
    5315                 runpy.close()
    5316             else:
    5317                 return
    5318         finally:
    5319             dlg.Destroy()
    5320 
    53215170    def OnRunRMC(event):
    53225171       
     
    53295178      B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111.
    53305179      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
    53315181            dlg = wx.FileDialog(G2frame, 'Choose fullrmc python file to execute', G2G.GetImportPath(G2frame),
    53325182                wildcard='fullrmc python file (*.py)|*.py',style=wx.FD_CHANGE_DIR)
     
    53365186                    batch = open('fullrmc.bat','w')
    53375187                    batch.write('run '+sys.exec_prefix+'\\Scripts\\activate\n')
    5338                     batch.write('SET PYTHONPATH=%s\\fullrmc\n'%GSASIIpath.path2GSAS2)
    53395188                    batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n')
    53405189                    batch.write('pause')
     
    54015250    def OnViewRMC(event):
    54025251        if G2frame.RMCchoice == 'fullrmc':
     5252            generalData = data['General']
     5253            pName = generalData['Name'].replace(' ','_')
     5254            from fullrmc import Engine
     5255            # load
     5256            engineFilePath = pName+'.rmc'
     5257            ENGINE = Engine(path=None)
    54035258            try:
    5404                 from fullrmc import Engine
    5405             except ModuleNotFoundError:
    5406                 wx.MessageBox(''' fullrmc is not correctly installed for use in GSAS-II
    5407       Install it in your python according to the instructions in
    5408       https://bachiraoun.github.io/fullrmc/index.html. ''',
    5409           caption='fullrmc not installed',style=wx.ICON_INFORMATION)
    5410                 return
    5411             DIR_PATH = os.path.dirname( os.path.realpath(__file__) )
    5412             engineFilePath = os.path.join(DIR_PATH, "engine.rmc")
    5413            
    5414             # load
    5415             ENGINE = Engine(path=None)
    5416             result, mes = ENGINE.is_engine(engineFilePath, mes=True)
    5417             if result:
    5418                 ENGINE = ENGINE.load(engineFilePath)
    5419                 GR, SQ, CN, MD = ENGINE.constraints
     5259                if engineFilePath is not None:
     5260                    result, mes = ENGINE.is_engine(engineFilePath, mes=True)
     5261                    if result:
     5262                        ENGINE = ENGINE.load(engineFilePath)
     5263                        found = False
     5264                        for frame in list(ENGINE.frames):
     5265                            ENGINE.set_used_frame(frame)
     5266                            FRitems = ENGINE.constraints
     5267                            for item in FRitems:
     5268                                sitem = str(type(item))
     5269                                if 'PairDistribution' in sitem or 'StructureFactor' in sitem or 'PairCorrelation' in sitem:
     5270                                    found = True
     5271                                    Xlab = r'$\mathsf{r,\AA}$'
     5272                                    Ylab = r'$\mathsf{g(r),\AA^{-2}}$'
     5273                                    title = ' g(r) for '
     5274                                    if 'StructureFactor' in sitem:
     5275                                        Xlab = r'$\mathsf{Q,\AA^{-1}}$'
     5276                                        Ylab = 'S(Q)'
     5277                                        title = ' S(Q) for '
     5278                                    if frame != '0':
     5279                                        title = frame+title
     5280                                    dataDict= item.get_constraints_properties(frame)
     5281                                    X = dataDict['frames-experimental_x'][0]
     5282                                    Y = dataDict['frames-experimental_y'][0]
     5283                                    rdfDict = item.get_constraint_value()
     5284                                    Z = rdfDict['total']
     5285                                    XY = [[X,Y],[X,Z]]
     5286                                    Names = ['Obs','Calc']
     5287                                    G2plt.PlotXY(G2frame,XY,labelX=Xlab,
     5288                                        labelY=Ylab,newPlot=True,Title=title+pName,
     5289                                        lines=True,names=Names)
     5290                                    PXY = []
     5291                                    PXYT = []
     5292                                    Names = []
     5293                                    NamesT = []
     5294                                    for item in rdfDict:
     5295                                        PXYT.append([X,rdfDict[item]])
     5296                                        NamesT.append(item)
     5297                                        if 'total' in item:
     5298                                            PXY.append([X,rdfDict[item]])
     5299                                            Names.append(item)
     5300                                    G2plt.PlotXY(G2frame,PXYT,labelX=Xlab,
     5301                                        labelY=Ylab,newPlot=True,Title=' All partials of '+title+pName,
     5302                                        lines=True,names=NamesT)
     5303                                    G2plt.PlotXY(G2frame,PXY,labelX=Xlab,
     5304                                        labelY=Ylab,newPlot=True,Title=' Total partials of '+title+pName,
     5305                                        lines=True,names=Names)
     5306                                   
     5307                                else:
     5308                                    found = True
     5309                                    if 'BondConstraint' in sitem:
     5310                                        bonds = item.get_constraint_value()['bondsLength']
     5311                                        bondList = item.bondsList[:2]
     5312                                        atoms = ENGINE.get_original_data("allElements",frame)
     5313                                        bondNames = ['%s-%s'%(atoms[bondList[0][iat]],atoms[bondList[1][iat]]) for iat in range(bonds.shape[0])]
     5314                                        bondSet = list(set(bondNames))
     5315                                        Bonds = list(zip(bondNames,bonds))
     5316                                        for Bname in bondSet:
     5317                                            bondLens = [bond[1] for bond in Bonds if bond[0]==Bname]
     5318                                            G2plt.PlotBarGraph(G2frame,bondLens,Xname=r'%s $Bond,\ \AA$'%Bname,Title='%s Bond lengths for %s'%(Bname,pName),
     5319                                                PlotName='%s Bonds for %s'%(Bname,pName),maxBins=20)
     5320                                    elif 'BondsAngleConstraint' in sitem:
     5321                                        angles = 180.*item.get_constraint_value()['angles']/np.pi
     5322                                        angleList = item.anglesList[:3]
     5323                                        atoms = ENGINE.get_original_data("allElements",frame)
     5324                                        angleNames = ['%s-%s-%s'%(atoms[angleList[1][iat]],atoms[angleList[0][iat]],atoms[angleList[2][iat]]) for iat in range(angles.shape[0])]
     5325                                        angleSet = list(set(angleNames))
     5326                                        Angles = list(zip(angleNames,angles))
     5327                                        for Aname in angleSet:
     5328                                            bondAngs = [angle[1] for angle in Angles if angle[0]==Aname]
     5329                                            G2plt.PlotBarGraph(G2frame,bondAngs,Xname=r'%s Angle, deg'%Aname,Title='%s Bond angles for %s'%(Aname,pName),
     5330                                                PlotName='%s Angles for %s'%(Aname,pName),maxBins=20)
     5331                                    elif 'ImproperAngleConstraint' in sitem:
     5332                                        impangles = 180.*item.get_constraint_value()['angles']/np.pi
     5333                                        impangleList = item.anglesList[:4]
     5334                                        atoms = ENGINE.get_original_data("allElements",frame)
     5335                                        impangleNames = ['%s-%s-%s-%s'%(atoms[impangleList[0][iat]],atoms[impangleList[1][iat]],
     5336                                            atoms[impangleList[2][iat]],atoms[impangleList[3][iat]]) for iat in range(impangles.shape[0])]
     5337                                        impangleSet = list(set(impangleNames))
     5338                                        impAngles = list(zip(impangleNames,impangles))
     5339                                        for Aname in impangleSet:
     5340                                            impAngs = [angle[1] for angle in impAngles if angle[0]==Aname]
     5341                                            G2plt.PlotBarGraph(G2frame,impAngs,Xname=r'%s $Improper Angle, deg$'%Aname,Title='%s Improper angles for %s'%(Aname,pName),
     5342                                                PlotName='%s Improper Angles for %s'%(Aname,pName),maxBins=20)
     5343                                    elif 'AtomicCoordinationNumber' in sitem or 'InterMolecular' in sitem:
     5344                                        print(sitem+' not plotted')
     5345                                    else:
     5346                                        print(sitem)
     5347                                        item.plot(show=True)
     5348                                        pass
     5349                        if not found:
     5350                            print(' No saved information yet, wait until fullrms does a Save')
     5351            except AssertionError:
     5352                 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()
     5359            start = 0
     5360            while True:
     5361                line = loglines[start]               
     5362                if 'Err:' in line:
     5363                    break
     5364                else:
     5365                    start += 1
     5366            Gen = []
     5367            Tr = []
     5368            Acc = []
     5369            Rem = []
     5370            Err = []
     5371            start -= 1
     5372            while True:
     5373                start += 1
     5374                try:
     5375                    line = loglines[start]
     5376                except:
     5377                    break
     5378                if 'Err' not in line:
     5379                    continue
     5380                items = line.split(' - ')
     5381                try:    # could be a trashed line at end
     5382                    Err.append(float(items[5][:-1].split('Err:')[1]))
     5383                except ValueError:
     5384                    break
     5385                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]))
     5389           
     5390            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)
     5400                     
    54205401        else:
    54215402            generalData = data['General']
     
    1125411235        FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.FRMCMenu)
    1125511236        G2frame.Bind(wx.EVT_MENU, OnSetupRMC, id=G2G.wxID_SETUPRMC)
    11256         G2frame.Bind(wx.EVT_MENU, OnLoadRMC, id=G2G.wxID_LOADRMC)
    11257         G2frame.Bind(wx.EVT_MENU, OnSaveRMC, id=G2G.wxID_SAVERMC)
    1125811237        G2frame.Bind(wx.EVT_MENU, OnRunRMC, id=G2G.wxID_RUNRMC)
    1125911238        G2frame.Bind(wx.EVT_MENU, OnViewRMC, id=G2G.wxID_VIEWRMC)
  • TabularUnified trunk/GSASIIplot.py

    r4380 r4389  
    53845384################################################################################
    53855385           
    5386 def PlotBarGraph(G2frame,Xarray,Xname='',Yname='Number',Title='',PlotName=None,ifBinned=False):
     5386def PlotBarGraph(G2frame,Xarray,Xname='',Yname='Number',Title='',PlotName=None,ifBinned=False,maxBins=None):
    53875387    'Needs a description'
    53885388   
     
    54155415    else:
    54165416        nBins= max(10,len(Xarray)//10)
     5417        if maxBins is not None:
     5418            nBins = min(nBins,maxBins)
    54175419        Bins,Dbins = np.histogram(Xarray,nBins)
    54185420        wid = Dbins[1]-Dbins[0]
     
    83338335        if key in ['+','-','=','0']:
    83348336            if generalData['Modulated']:
     8337                tstep = 1./36 #0.05
    83358338                if key == '0':
    83368339                    G2frame.tau = 0.
    83378340                elif key in ['+','=']:
    8338                     G2frame.tau += 0.05
     8341                    G2frame.tau += tstep
    83398342                elif key == '-':
    8340                     G2frame.tau -= 0.05
     8343                    G2frame.tau -= tstep
    83418344                G2frame.tau %= 1.   #force 0-1 range; makes loop
    83428345                G2frame.G2plotNB.status.SetStatusText('Modulation tau = %.4f'%(G2frame.tau),1)
  • TabularUnified trunk/GSASIIpwd.py

    r4366 r4389  
    21072107################################################################################
    21082108   
    2109 def MakeInst(G2frame,Name,Phase,useSamBrd,PWId):
    2110     PWDdata = G2frame.GetPWDRdatafromTree(PWId)
    2111     histoName = G2frame.GPXtree.GetItemPyData(PWId)[2]
    2112     Size = Phase['Histograms'][histoName]['Size']
    2113     Mustrain = Phase['Histograms'][histoName]['Mustrain']
     2109def MakeInst(PWDdata,Name,Size,Mustrain,useSamBrd):
    21142110    inst = PWDdata['Instrument Parameters'][0]
    21152111    Xsb = 0.
     
    21602156    return fname
    21612157   
    2162 def MakeBack(G2frame,Name,PWId):
    2163     PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2158def MakeBack(PWDdata,Name):
    21642159    Back = PWDdata['Background'][0]
    21652160    inst = PWDdata['Instrument Parameters'][0]
     
    21792174    return fname
    21802175
    2181 def MakeRMC6f(G2frame,Name,Phase,RMCPdict,PWId):
     2176def MakeRMC6f(PWDdata,Name,Phase,RMCPdict):
    21822177   
    21832178    def findDup(Atoms):
     
    21992194    Atseq = RMCPdict['atSeq']
    22002195    Supercell =  RMCPdict['SuperCell']
    2201     PWDdata = G2frame.GetPWDRdatafromTree(PWId)
    22022196    generalData = Phase['General']
    22032197    Dups,Fracs = findDup(Phase['Atoms'])
     
    22792273    return fname,reset
    22802274
    2281 def MakeBragg(G2frame,Name,Phase,PWId):
    2282     PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2275def MakeBragg(PWDdata,Name,Phase):
    22832276    generalData = Phase['General']
    22842277    Vol = generalData['Cell'][7]
     
    23072300    return fname
    23082301
    2309 def MakeRMCPdat(G2frame,Name,Phase,RMCPdict,PWId):
     2302def MakeRMCPdat(PWDdata,Name,Phase,RMCPdict):
    23102303    Meta = RMCPdict['metadata']
    23112304    Times = RMCPdict['runTimes']
     
    23152308    Files = RMCPdict['files']
    23162309    BraggWt = RMCPdict['histogram'][1]
    2317     PWDdata = G2frame.GetPWDRdatafromTree(PWId)
    23182310    inst = PWDdata['Instrument Parameters'][0]
    23192311    refList = PWDdata['Reflection Lists'][Name]['RefList']
     
    24682460    fl.write('END  ::\n')
    24692461    fl.close()
    2470     return fname   
    2471 
    2472 def MakePDB(G2frame,Name,Phase,Atseq,Supercell):
    2473     generalData = Phase['General']
    2474     Cell = generalData['Cell'][1:7]
    2475     Trans = np.eye(3)*np.array(Supercell)
    2476     newPhase = copy.deepcopy(Phase)
    2477     newPhase['General']['SGData'] = G2spc.SpcGroup('P 1')[1]
    2478     newPhase['General']['Cell'][1:] = G2lat.TransformCell(Cell,Trans.T)
    2479     newPhase,Atcodes = G2lat.TransformPhase(Phase,newPhase,Trans,np.zeros(3),np.zeros(3),ifMag=False)
    2480     Atoms = newPhase['Atoms']
    2481     Cell = newPhase['General']['Cell'][1:7]
    2482     A,B = G2lat. cell2AB(Cell)
    2483     fname = Name+'.pdb'
    2484     fl = open(fname,'w')
    2485     fl.write('REMARK    this file is generated using GSASII\n')
    2486     fl.write('CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1           1\n'%(
    2487             Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5]))
    2488     fl.write('ORIGX1      1.000000  0.000000  0.000000        0.00000\n')
    2489     fl.write('ORIGX2      0.000000  1.000000  0.000000        0.00000\n')
    2490     fl.write('ORIGX3      0.000000  0.000000  1.000000        0.00000\n')
    2491 
    2492     Natm = np.core.defchararray.count(np.array(Atcodes),'+')
    2493     Natm = np.count_nonzero(Natm-1)
    2494     nat = 0
    2495     for atm in Atseq:
    2496         for iat,atom in enumerate(Atoms):
    2497             if atom[1] == atm:
    2498                 nat += 1
    2499                 XYZ = np.inner(A,np.array(atom[3:6])-0.5)    #shift origin to middle & make Cartesian
    2500 #ATOM      1 Ni   RMC     1     -22.113 -22.113 -22.113  1.00  0.00          ni                     
    2501                 fl.write('ATOM  %5d %-4s RMC%6d%12.3f%8.3f%8.3f  1.00  0.00          %-2s\n'%(       
    2502                         nat,atom[0],nat,XYZ[0],XYZ[1],XYZ[2],atom[1]))
    2503     fl.close()
    25042462    return fname
     2463
     2464def MakefullrmcRun(Name,Phase,RMCPdict):
     2465    print(' nothing happened yet')
     2466    rname = Name+'-run.py'
     2467    rundata = ''
     2468    rundata += '#### fullrmc $s file; edit by hand if you so choose #####\n'&rname
     2469    rundata += '''
     2470import numpy as np
     2471
     2472# fullrmc library imports
     2473from fullrmc.Globals import LOGGER, FLOAT_TYPE
     2474from fullrmc.Engine import Engine
     2475from fullrmc.Constraints.PairDistributionConstraints import PairDistributionConstraint
     2476from fullrmc.Constraints.PairCorrelationConstraints import PairCorrelationConstraint
     2477from fullrmc.Constraints.DistanceConstraints import InterMolecularDistanceConstraint
     2478from fullrmc.Constraints.BondConstraints import BondConstraint
     2479from fullrmc.Constraints.AngleConstraints import BondsAngleConstraint
     2480from fullrmc.Constraints.ImproperAngleConstraints import ImproperAngleConstraint
     2481from fullrmc.Core.Collection import convert_Gr_to_gr
     2482from fullrmc.Core.MoveGenerator import MoveGeneratorCollector
     2483from fullrmc.Core.GroupSelector import RecursiveGroupSelector
     2484from fullrmc.Selectors.RandomSelectors import RandomSelector
     2485from fullrmc.Selectors.OrderedSelectors import DefinedOrderSelector
     2486from fullrmc.Generators.Translations import TranslationGenerator, TranslationAlongSymmetryAxisGenerator
     2487from fullrmc.Generators.Rotations import RotationGenerator, RotationAboutSymmetryAxisGenerator
     2488from fullrmc.Generators.Agitations import DistanceAgitationGenerator, AngleAgitationGenerator
     2489
     2490# engine file names - replace name with phase name
     2491engineFileName = "name_engine.rmc"
     2492expFileName    = "name_pdf.exp"
     2493pdbFileName    = "nme.pdb"
     2494freshStart     = False      #make TRUE for a restart
     2495
     2496            '''
     2497    rfile = open(rname,'w')
     2498    rfile.writelines(rundata)
     2499    rfile.close()
     2500   
     2501
     2502def 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
    25052535
    25062536def GetRMCBonds(general,RMCPdict,Atoms,bondList):
Note: See TracChangeset for help on using the changeset viewer.