Changeset 4192 for trunk/GSASIIpwd.py


Ignore:
Timestamp:
Nov 22, 2019 1:28:42 PM (2 years ago)
Author:
vondreele
Message:

fix OnFileReopen?; broke when some file were deleted beforehand
Some preliminaries for rmc stuff
allow use of default instrument parameters upon Load command - same idea; cancel brings up default list choice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r4191 r4192  
    20662066    WYI = np.where(WYI>0.,WYI,0.)
    20672067    return YI,WYI
     2068
     2069################################################################################
     2070#### RMCutilities
     2071################################################################################
     2072   
     2073def MakeInst(G2frame,Name,PWId):
     2074    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2075    inst = PWDdata['Instrument Parameters'][0]
     2076    prms = ['Bank',
     2077            'difC','difA','Zero','2-theta',
     2078            'alpha','beta-0','beta-1','sig-0',
     2079            'sig-1','sig-2','X','Y']
     2080    fname = Name+'.inst'
     2081    fl = open(fname,'w')
     2082    fl.write('      1\n')
     2083    fl.write('%10d\n'%int(inst[prms[0]][1]))
     2084    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]))
     2085    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]))
     2086    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]))   
     2087    fl.write('%10.4f%10.3f%10.3f%10.3f\n'%(inst[prms[11]][1],0.0,0.0,0.0))
     2088    fl.close()
     2089    return fname
     2090   
     2091def MakeBack(G2frame,Name,PWId):
     2092    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2093    Back = PWDdata['Background'][0]
     2094    if 'chebyschev' not in Back[0]:
     2095        return None
     2096    Nback = Back[2]
     2097    BackVals = Back[3:]
     2098    fname = Name+'.back'
     2099    fl = open(fname,'w')
     2100    fl.write('%10d\n'%Nback)
     2101    for val in BackVals:
     2102        fl.write('%12.6g\n'%val)
     2103    fl.close()
     2104    return fname
     2105
     2106def MakeRMC6f(G2frame,Name,Phase,Meta,Supercell,PWId):
     2107    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2108    generalData = Phase['General']
     2109    Sample = PWDdata['Sample Parameters']
     2110    Meta['temperature'] = Sample['Temperature']
     2111    Meta['pressure'] = Sample['Pressure']
     2112    Cell = generalData['Cell'][1:7]
     2113    Trans = np.eye(3)*np.array(Supercell)
     2114    newPhase = copy.deepcopy(Phase)
     2115    newPhase['General']['SGData'] = G2spc.SpcGroup('P 1')[1]
     2116    newPhase['General']['Cell'][1:] = G2lat.TransformCell(Cell,Trans.T)
     2117    newPhase,Atcodes = G2lat.TransformPhase(Phase,newPhase,Trans,np.zeros(3),np.zeros(3),ifMag=False)
     2118    Atoms = newPhase['Atoms']
     2119    Cell = newPhase['General']['Cell'][1:7]
     2120    fname = Name+'.rmc6f'
     2121    fl = open(fname,'w')
     2122    fl.write('(Version 6f format configuration file)\n')
     2123    for item in Meta:
     2124        fl.write('%-20s:  %s\n'%('Metadata '+item,Meta[item]))
     2125    fl.write('Supercell dimensions: %d %d %d\n'%(Supercell[0],Supercell[1],Supercell[2]))
     2126    fl.write('Cell (Ang/deg): %f %f %f %f %f %f\n'%(
     2127            Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5]))
     2128    fl.write('Atoms (fractional coordinates):\n')
     2129    for iat,atom in enumerate(Atoms):
     2130        atcode = Atcodes[iat].split(':')
     2131        cell = [0,0,0]
     2132        if '+' in atcode[1]:
     2133            cell = eval(atcode[1].split('+')[1])
     2134        fl.write('%6d%6s [%s]%10.6f%10.6f%10.6f%5d%5d%5d%5d\n'%(       
     2135                iat,atom[1],atcode[0],atom[3],atom[4],atom[5],0,cell[0],cell[1],cell[2]))
     2136    fl.close()
     2137    return fname
     2138
     2139def MakeBragg(G2frame,Name,Phase,PWId):
     2140    PWDdata = G2frame.GetPWDRdatafromTree(PWId)
     2141    generalData = Phase['General']
     2142    Vol = generalData['Cell'][7]
     2143    Data = PWDdata['Data']
     2144    Inst = PWDdata['Instrument Parameters'][0]
     2145    Bank = int(Inst['Bank'][1])
     2146    Sample = PWDdata['Sample Parameters']
     2147    Scale = Sample['Scale'][0]
     2148    Limits = PWDdata['Limits'][1]
     2149    Ibeg = np.searchsorted(Data[0],Limits[0])
     2150    Ifin = np.searchsorted(Data[0],Limits[1])+1
     2151    fname = Name+'.bragg'
     2152    fl = open(fname,'w')
     2153    fl.write('%10d%10d%12.4f%12.4f\n'%(Ifin-Ibeg,Bank,Scale,Vol))
     2154    fl.write('%12s%12s\n'%('   TOF,ms','  I(obs)'))
     2155    for i in range(Ibeg,Ifin-1):
     2156        fl.write('%12.8f%12.6f\n'%(Data[0][i]/1000.,Data[1][i]))
     2157    fl.close()
     2158    return fname
    20682159   
    20692160################################################################################
Note: See TracChangeset for help on using the changeset viewer.