Changeset 4195


Ignore:
Timestamp:
Dec 3, 2019 3:00:37 AM (4 years ago)
Author:
vondreele
Message:

add a find utility to GSASIIfiles for finding a file within a directory tree
faster version of ExpandCell? & define SwapItems? in GSASIIlattice
changes to RMCProfile interface

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4192 r4195  
    28422842                    print('Value for config {} {} is invalid'.format(var,GSASIIpath.GetConfigValue(var)))
    28432843                    win.Center()
    2844 
     2844################################################################################
     2845#### init_vars
     2846################################################################################
    28452847    def init_vars(self):
    28462848        # initialize default values for GSAS-II "global" variables (saved in main Frame)
  • trunk/GSASIIfiles.py

    r4026 r4195  
    6868        G2Print('G2SetPrintLevel Error: level={} cannot be interpreted.',
    6969                    'Use all, warn, error or none.')
     70       
     71def find(name, path):
     72    '''find 1st occurance of file in path
     73    '''
     74    for root, dirs, files in os.walk(path):
     75        if name in files:
     76            return os.path.join(root, name)
    7077       
    7178def G2Print(*args,**kwargs):
  • trunk/GSASIIlattice.py

    r4175 r4195  
    278278
    279279def ExpandCell(Atoms,atCodes,cx,Trans):
    280     Unit =[int(max(abs(np.array(unit)))-1) for unit in Trans.T]
    281     for i,unit in enumerate(Unit):
    282         if unit > 0:
    283             for j in range(unit):
    284                 moreAtoms = copy.deepcopy(Atoms)
    285                 moreCodes = []
    286                 for atom,code in zip(moreAtoms,atCodes):
    287                     atom[cx+i] += 1.
    288                     if '+' in code:
    289                         cell = list(eval(code.split('+')[1]))
    290                         ops = code.split('+')[0]
    291                     else:
    292                         cell = [0,0,0]
    293                         ops = code
    294                     cell[i] += 1
    295                     moreCodes.append('%s+%d,%d,%d'%(ops,cell[0],cell[1],cell[2]))
    296                 Atoms += moreAtoms
    297                 atCodes += moreCodes
    298     return Atoms,atCodes
     280    Unit = [int(max(abs(np.array(unit)))-1) for unit in Trans.T]
     281    nUnit = (Unit[0]+1)*(Unit[1]+1)*(Unit[2]+1)
     282    Ugrid = np.mgrid[0:Unit[0]+1,0:Unit[1]+1,0:Unit[2]+1]
     283    Ugrid = np.reshape(Ugrid,(3,nUnit)).T
     284    Codes = copy.deepcopy(atCodes)
     285    newAtoms = copy.deepcopy(Atoms)
     286    for unit in Ugrid[1:]:
     287        moreAtoms = copy.deepcopy(Atoms)
     288        for atom in moreAtoms:
     289            atom[cx:cx+3] += unit
     290        newAtoms += moreAtoms
     291        codes = copy.deepcopy(atCodes)
     292        moreCodes = [code+'+%d,%d,%d'%(unit[0],unit[1],unit[2]) for code in codes]
     293        Codes += moreCodes
     294    return newAtoms,Codes
    299295   
    300296def TransformPhase(oldPhase,newPhase,Trans,Uvec,Vvec,ifMag):
     
    992988    else:
    993989        return [H[2],H[0],H[1]]
     990   
     991def SwapItems(Alist,pos1,pos2):
     992    'exchange 2 items in a list'
     993    try:
     994        get = Alist[pos1],Alist[pos2]
     995        Alist[pos2],Alist[pos1] = get
     996    except IndexError:
     997        pass
     998    return Alist
    994999       
    9951000def Rh2Hx(Rh):
  • trunk/GSASIIphsGUI.py

    r4194 r4195  
    5959import GSASIIobj as G2obj
    6060import GSASIIctrlGUI as G2G
     61import GSASIIfiles as G2fl
    6162import GSASIIconstrGUI as G2cnstG
    6263import numpy as np
     
    10941095        self.Phase = Phase
    10951096        self.SuperCell = [1,1,1]
     1097        self.aTypes = self.Phase['General']['AtomTypes']
     1098        self.atSeq = self.aTypes[:]
    10961099        self.histogram = ''
    10971100        self.metadata = {'title':'none','owner':'no one','date':str(time.ctime()),
     
    11031106        def OnHisto(event):
    11041107            self.histogram = histo.GetStringSelection()
     1108           
     1109        def OnAtSel(event):
     1110            Obj = event.GetEventObject()
     1111            itype = Indx[Obj.GetId()]
     1112            tid = Obj.GetSelection()
     1113            if itype < nTypes-1:
     1114                if itype == tid:
     1115                    tid += 1
     1116                self.atSeq = G2lat.SwapItems(self.atSeq,itype,tid)
     1117            wx.CallAfter(self.Draw)
    11051118       
    11061119        self.panel.Destroy()
     
    11141127            superSizer.Add(G2G.ValidatedTxtCtrl(self.panel,self.SuperCell,i,min=1,max=10,size=(50,25)),0,WACV)
    11151128        mainSizer.Add(superSizer,0,WACV)
     1129        nTypes = len(self.aTypes)
     1130        atmChoice = wx.BoxSizer(wx.HORIZONTAL)
     1131        atmChoice.Add(wx.StaticText(self.panel,label=' Set atom ordering: '),0,WACV)
     1132        Indx = {}
     1133        for iType in range(nTypes):
     1134            atChoice = self.atSeq[iType:]
     1135            atmSel = wx.ComboBox(self.panel,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
     1136            atmSel.SetStringSelection(self.atSeq[iType])
     1137            atmSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
     1138            Indx[atmSel.GetId()] = iType
     1139            atmChoice.Add(atmSel,0,WACV)
     1140        mainSizer.Add(atmChoice,0,WACV)
    11161141        histograms = self.Phase['Histograms']
    11171142        histNames = list(histograms.keys())
     
    11261151            metaSizer.Add(G2G.ValidatedTxtCtrl(self.panel,self.metadata,item),0,WACV)
    11271152        mainSizer.Add(metaSizer,0,WACV)
     1153        mainSizer.Add(wx.StaticText(self.panel,label=' WARNING: this can take time - be patient'),0,WACV)
    11281154        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
    11291155        OKBtn = wx.Button(self.panel,-1,"OK")
     
    11411167    def GetData(self):
    11421168        'Returns the values from the dialog'
    1143         return self.SuperCell,self.histogram,self.metadata
     1169        return self.SuperCell,self.histogram,self.metadata,self.atSeq
    11441170       
    11451171    def OnOK(self,event):
     
    44754501            dlg = SetUpRMCProfileDialog(G2frame,Name=pName,Phase=data)
    44764502            if dlg.ShowModal() == wx.ID_OK:
    4477                 superCell,histoName,meta = dlg.GetData()
     4503                superCell,histoName,meta,atSeq = dlg.GetData()
    44784504                PWId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,histoName)
    44794505                if PWId:
     4506#                    Progress
    44804507                    print(G2pwd.MakeInst(G2frame,pName,PWId)+ ' written')
    44814508                    backfile = G2pwd.MakeBack(G2frame,pName,PWId)
     
    44854512                        print(backfile+ ' written')
    44864513                    print(G2pwd.MakeBragg(G2frame,pName,data,PWId)+ ' written')
    4487                     print(G2pwd.MakeRMC6f(G2frame,pName,data,meta,superCell,PWId)+ ' written')
     4514                    print(G2pwd.MakeRMC6f(G2frame,pName,data,meta,atSeq,superCell,PWId)+ ' written')
    44884515                    print('RMCProfile file build completed')
    44894516                else:
     
    45414568            dlg = wx.FileDialog(G2frame, 'Choose fullrmc python file to execute',
    45424569                wildcard='fullrmc python file (*.py)|*.py',style=wx.FD_CHANGE_DIR)
     4570            try:
     4571                if dlg.ShowModal() == wx.ID_OK:
     4572                    import subprocess as sb
     4573                    batch = open('fullrmc.bat','w')
     4574                    batch.write(sys.exec_prefix+'\\activate\n')
     4575                    batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n')
     4576                    batch.write('pause')
     4577                    batch.close()
     4578                    sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE)
     4579                else:
     4580                    return
     4581            finally:
     4582                dlg.Destroy()
     4583               
    45434584           
    45444585        else:
     4586            rmcfile = G2fl.find('rmcprofile.exe',GSASIIpath.path2GSAS2)
     4587            rmcexe = os.path.split(rmcfile)[0]
     4588            print(rmcexe)
     4589            if rmcfile is None:
     4590                wx.MessageBox(''' RMCProfile is not correctly installed for use in GSAS-II
     4591      Obtain the zip file distribution from www.rmcprofile.org,
     4592      unzip it and place the RMCProfile main directory in the main GSAS-II directory ''',
     4593          caption='RMCProfile',style=wx.ICON_INFORMATION)
     4594                return
    45454595            wx.MessageBox(''' For use of RMCProfile, please cite:
    45464596      RMCProfile: Reverse Monte Carlo for polycrystalline materials,
    45474597      M.G. Tucker, D.A. keen, M.T. Dove, A.L. Goodwin and Q. Hui,
    45484598      Jour. Phys.: Cond. matter 2007, 19, 335218.
    4549       doi: https://doi.org/10.1088/0953-8984/19/33/335218''',caption='RMCProfile',style=wx.ICON_INFORMATION)
    4550             return
    4551         try:
    4552             if dlg.ShowModal() == wx.ID_OK:
    4553                 import subprocess as sb
    4554                 batch = open('fullrmc.bat','w')
    4555                 batch.write(sys.exec_prefix+'\\activate\n')
    4556                 batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n')
    4557                 batch.write('pause')
    4558                 batch.close()
    4559                 sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE)
    4560             else:
    4561                 return
    4562         finally:
    4563             dlg.Destroy()
    4564                
     4599      doi: https://doi.org/10.1088/0953-8984/19/33/335218''',
     4600      caption='RMCProfile',style=wx.ICON_INFORMATION)
     4601            import subprocess as sb
     4602            generalData = data['General']
     4603            pName = generalData['Name'].replace(' ','_')
     4604            batch = open('runrmc.bat','w')
     4605            batch.write('::PATH=%PATH%;'+rmcexe+';c:'+rmcexe+'\cygwin_libs\n')
     4606            batch.write('SET RMCPROFILE_DIR='+G2frame.dirname+'\n')
     4607            batch.write('SET RMCPROFILE_DRIVE=%~d1\n')
     4608            batch.write('::PATH=%PATH%;%RMCPROFILE_DIR%\exe;%RMCPROFILE_DIR%\exe\cygwin_libs\n')
     4609            batch.write('PATH=%RMCPROFILE_DIR%\exe;%RMCPROFILE_DIR%\exe\cygwin_libs;%PATH%\n')
     4610            batch.write('PATH\n')
     4611            batch.write('Title RMCProfile\n')
     4612            batch.write(rmcexe+'\\rmcprofile.exe '+pName+'\n')
     4613            batch.write('pause\n')
     4614            batch.close()
     4615            sb.Popen('runrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE)
     4616
     4617#            dlg = wx.FileDialog(G2frame, 'Find rmcprofile.bat file to execute',
     4618#                wildcard='RMCProfile (rmcprofile.bat)|*.bat',style=wx.FD_CHANGE_DIR)
     4619#            try:
     4620#                if dlg.ShowModal() == wx.ID_OK:
     4621#                    pass
     4622#                else:
     4623#                    return
     4624#            finally:
     4625#                dlg.Destroy()
    45654626
    45664627           
  • trunk/GSASIIpwd.py

    r4194 r4195  
    20922092    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
    20932093    inst = PWDdata['Instrument Parameters'][0]
    2094     prms = ['Bank',
    2095             'difC','difA','Zero','2-theta',
    2096             'alpha','beta-0','beta-1','sig-0',
    2097             'sig-1','sig-2','X','Y']
    2098     fname = Name+'.inst'
    2099     fl = open(fname,'w')
    2100     fl.write('      1\n')
    2101     fl.write('%10d\n'%int(inst[prms[0]][1]))
    2102     fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(inst[prms[1]][1],inst[prms[2]][1],inst[prms[3]][1],inst[prms[4]][1]))
    2103     fl.write('%10.3f%10.6f%10.6f%10.3f\n'%(inst[prms[5]][1],inst[prms[6]][1],inst[prms[7]][1],inst[prms[8]][1]))
    2104     fl.write('%10.3f%10.3f%10.3f%10.4f\n'%(inst[prms[9]][1],inst[prms[10]][1],0.0,inst[prms[12]][1]))   
    2105     fl.write('%10.4f%10.3f%10.3f%10.3f\n'%(inst[prms[11]][1],0.0,0.0,0.0))
    2106     fl.close()
     2094    if 'T' in inst['Type'][1]:
     2095        prms = ['Bank',
     2096                'difC','difA','Zero','2-theta',
     2097                'alpha','beta-0','beta-1','sig-0',
     2098                'sig-1','sig-2','X','Y']
     2099        fname = Name+'.inst'
     2100        fl = open(fname,'w')
     2101        fl.write('1\n')
     2102        fl.write('%d\n'%int(inst[prms[0]][1]))
     2103        fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(inst[prms[1]][1],inst[prms[2]][1],inst[prms[3]][1],inst[prms[4]][1]))
     2104        fl.write('%10.3f%10.6f%10.6f%10.3f\n'%(inst[prms[5]][1],inst[prms[6]][1],inst[prms[7]][1],inst[prms[8]][1]))
     2105        fl.write('%10.3f%10.3f%10.3f%10.4f\n'%(inst[prms[9]][1],inst[prms[10]][1],0.0,inst[prms[12]][1]))   
     2106        fl.write('%10.4f%10.3f%10.3f%10.3f\n'%(inst[prms[11]][1],0.0,0.0,0.0))
     2107        fl.write('%10.4f%10.3f%10.3f%10.3f\n'%(0.0,0.0,0.0,0.0))
     2108        fl.close()
     2109    else:
     2110        prms = ['Bank',
     2111                'Lam','Zero',
     2112                'U','V','W',
     2113                'X','Y',]
     2114        fname = Name+'.inst'
     2115        fl = open(fname,'w')
     2116        fl.write('1\n')
     2117        fl.write('%d\n'%int(inst[prms[0]][1]))
     2118        fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(inst[prms[1]][1],inst[prms[2]][1],0.0,0.0))
     2119        fl.write('%10.3f%10.6f%10.6f%10.3f\n'%(inst[prms[3]][1],inst[prms[4]][1],inst[prms[5]][1],0.0))
     2120        fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(inst[prms[6]][1],inst[prms[7]][1],0.0,0.0))   
     2121        fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(0.0,0.0,0.0,0.0))
     2122        fl.close()
    21072123    return fname
    21082124   
     
    21222138    return fname
    21232139
    2124 def MakeRMC6f(G2frame,Name,Phase,Meta,Supercell,PWId):
     2140def MakeRMC6f(G2frame,Name,Phase,Meta,Atseq,Supercell,PWId):
    21252141    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
    21262142    generalData = Phase['General']
     
    21402156    fl.write('(Version 6f format configuration file)\n')
    21412157    for item in Meta:
    2142         fl.write('%-20s:  %s\n'%('Metadata '+item,Meta[item]))
    2143     fl.write('Supercell dimensions: %d %d %d\n'%(Supercell[0],Supercell[1],Supercell[2]))
    2144     fl.write('Cell (Ang/deg): %f %f %f %f %f %f\n'%(
     2158        fl.write('%-20s%s\n'%('Metadata '+item+':',Meta[item]))
     2159    fl.write('%-35s%3d%3d%3d\n'%('Supercell dimensions:',Supercell[0],Supercell[1],Supercell[2]))
     2160    fl.write('Cell (Ang/deg): %12.6f%12.6f%12.6f%12.6f%12.6f%12.6f\n'%(
    21452161            Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5]))
     2162    A,B = G2lat. cell2AB(Cell)
     2163    fl.write('Lattice vectors (Ang):\n')
     2164    for i in [0,1,2]:
     2165        fl.write('%12.6f%12.6f%12.6f\n'%(A[i,0],A[i,1],A[i,2]))
    21462166    fl.write('Atoms (fractional coordinates):\n')
    2147     for iat,atom in enumerate(Atoms):
    2148         atcode = Atcodes[iat].split(':')
    2149         cell = [0,0,0]
    2150         if '+' in atcode[1]:
    2151             cell = eval(atcode[1].split('+')[1])
    2152         fl.write('%6d%6s [%s]%10.6f%10.6f%10.6f%5d%5d%5d%5d\n'%(       
    2153                 iat,atom[1],atcode[0],atom[3],atom[4],atom[5],0,cell[0],cell[1],cell[2]))
     2167    Natm = np.core.defchararray.count(np.array(Atcodes),'+')
     2168    Natm = np.count_nonzero(Natm-1)
     2169    nat = 0
     2170    for atm in Atseq:
     2171        for iat,atom in enumerate(Atoms):
     2172            if atom[1] == atm:
     2173                nat += 1
     2174                atcode = Atcodes[iat].split(':')
     2175                cell = [0,0,0]
     2176                if '+' in atcode[1]:
     2177                    cell = eval(atcode[1].split('+')[1])
     2178                fl.write('%6d%4s  [%s]%19.15f%19.15f%19.15f%6d%4d%4d%4d\n'%(       
     2179                        nat,atom[1],atcode[0],atom[3],atom[4],atom[5],(iat)%Natm+1,cell[0],cell[1],cell[2]))
    21542180    fl.close()
    21552181    return fname
     
    21692195    fname = Name+'.bragg'
    21702196    fl = open(fname,'w')
    2171     fl.write('%10d%10d%12.4f%12.4f\n'%(Ifin-Ibeg,Bank,Scale,Vol))
    2172     fl.write('%12s%12s\n'%('   TOF,ms','  I(obs)'))
    2173     for i in range(Ibeg,Ifin-1):
    2174         fl.write('%12.8f%12.6f\n'%(Data[0][i]/1000.,Data[1][i]))
     2197    fl.write('%12d%6d%15.7f%15.4f\n'%(Ifin-Ibeg-1,Bank,Scale,Vol))
     2198    if 'T' in Inst['Type'][0]:
     2199        fl.write('%12s%12s\n'%('   TOF,ms','  I(obs)'))
     2200        for i in range(Ibeg,Ifin-1):
     2201            fl.write('%12.8f%12.6f\n'%(Data[0][i]/1000.,Data[1][i]))
     2202    else:
     2203        fl.write('%12s%12s\n'%('   2-theta, deg','  I(obs)'))
     2204        for i in range(Ibeg,Ifin-1):
     2205            fl.write('%11.6f%15.2f\n'%(Data[0][i],Data[1][i]))       
    21752206    fl.close()
    21762207    return fname
Note: See TracChangeset for help on using the changeset viewer.