Changeset 5041


Ignore:
Timestamp:
Sep 30, 2021 8:12:56 AM (8 months ago)
Author:
vondreele
Message:

begin to add PDFfit to RMC stuff

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIobj.py

    r5038 r5041  
    11411141CIFs prepared with the ISODISTORT web site
    11421142https://stokes.byu.edu/iso/isodistort_version5.6.1/isodistort.php
    1143 [B. J. Campbell, H. T. Stokes, D. E. Tanner, and D. M. Hatch, "ISODISPLACE: An Internet Tool for Exploring Structural Distortions." J. Appl. Cryst. 39, 607-614 (2006).]
    1144 can be read into GSAS-II using import CIF. This will cause constraints to be established for structural distortion modes read from the CIF.
    1145 At present, of the five types of modes  only displacive(``_iso_displacivemode``...) and occupancy (``_iso_occupancymode``...) are processed. Not yet processed: ``_iso_magneticmode``..., ``_iso_rotationalmode``... & ``_iso_strainmode``...
    1146 
    1147 The CIF importer :mod:`G2phase_CIF` implements class :class:`G2phase_CIF.CIFPhaseReader` which offers two methods associated with ISODISTORT (ID) input. Method :meth:`G2phase_CIF.CIFPhaseReader.ISODISTORT_test`
    1148 checks to see if a CIF block contains the loops with ``_iso_displacivemode_label`` or  ``_iso_occupancymode_label`` items.
    1149 If so, method :meth:`G2phase_CIF.CIFPhaseReader.ISODISTORT_proc` is called to read and interpret them.
    1150 The results are placed into the reader object's ``.Phase`` class variable as a dict item with key ``'ISODISTORT'``.
    1151 
    1152 Note that each mode ID has a long label with a name such as  Pm-3m[1/2,1/2,1/2]R5+(a,a,0)[La:b:dsp]T1u(a). Function :func:`G2phase_CIF.ISODISTORT_shortLbl` is used to create a short name for this,
    1153 such as R5_T1u(a) which is made unique by addition of _n if the short name is duplicated.
    1154 As each mode is processed, a constraint corresponding to that mode is
    1155 created and is added to list in the reader object's ``.Constraints`` class variable. Items placed into that list can either be a list, which corresponds to a function (new var) type :ref:`constraint definition <Constraints_table>` entry, or an item can be a dict, which provides help information for each constraint.
     1143[B. J. Campbell, H. T. Stokes, D. E. Tanner, and D. M. Hatch, "ISODISPLACE: An Internet Tool for Exploring Structural Distortions."
     1144 J. Appl. Cryst. 39, 607-614 (2006).] can be read into GSAS-II using import CIF. This will cause constraints to be established for
     1145structural distortion modes read from the CIF. At present, of the five types of modes  only displacive(``_iso_displacivemode``...)
     1146and occupancy (``_iso_occupancymode``...) are processed. Not yet processed: ``_iso_magneticmode``...,
     1147``_iso_rotationalmode``... & ``_iso_strainmode``...
     1148
     1149The CIF importer :mod:`G2phase_CIF` implements class :class:`G2phase_CIF.CIFPhaseReader` which offers two methods associated
     1150with ISODISTORT (ID) input. Method :meth:`G2phase_CIF.CIFPhaseReader.ISODISTORT_test` checks to see if a CIF block contains
     1151the loops with ``_iso_displacivemode_label`` or  ``_iso_occupancymode_label`` items. If so, method
     1152:meth:`G2phase_CIF.CIFPhaseReader.ISODISTORT_proc` is called to read and interpret them. The results are placed into the
     1153reader object's ``.Phase`` class variable as a dict item with key ``'ISODISTORT'``.
     1154
     1155Note that each mode ID has a long label with a name such as  Pm-3m[1/2,1/2,1/2]R5+(a,a,0)[La:b:dsp]T1u(a). Function
     1156:func:`G2phase_CIF.ISODISTORT_shortLbl` is used to create a short name for this, such as R5_T1u(a) which is made unique
     1157by addition of _n if the short name is duplicated. As each mode is processed, a constraint corresponding to that mode is
     1158created and is added to list in the reader object's ``.Constraints`` class variable. Items placed into that list can either
     1159be a list, which corresponds to a function (new var) type :ref:`constraint definition <Constraints_table>` entry, or an item
     1160can be a dict, which provides help information for each constraint.
    11561161
    11571162------------------------------
     
    11591164------------------------------
    11601165
    1161 The coordinate variables, as named by ISODISTORT, are placed in
    1162 ``.Phase['ISODISTORT']['IsoVarList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2VarList']``. The mode variables,
    1163 as named by ISODISTORT, are placed in ``.Phase['ISODISTORT']['IsoModeList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2ModeList']``.
    1164 [Use ``str(G2VarObj)`` to get the variable name from the G2VarObj object, but note that the phase number, *n*, for the prefix "*n*::" cannot be determined as the phase number is not yet assigned.]
    1165 
    1166 Displacive modes are a bit complex in that they relate to delta displacements, relative to an offset value for each coordinate, and because the modes are normalized, while GSAS-II also uses displacements, but these are added to the coordinates after each refinement cycle and the delta values are set to zero. ISODISTORT uses fixed offsets (subtracted from the actual position to obtain the delta values) that are taken from ``_iso_coordinate_formula`` and these are placed in ``.Phase['ISODISTORT']['ParentStructure]`` (keyed by atom label). The normalization factors (which the delta values are divided by) are taken from ``_iso_displacivemodenorm_value`` and are placed in ``.Phase['ISODISTORT']['NormList']`` in the same order as as ``...['IsoModeList']`` and
    1167 ``...['G2ModeList']``.
    1168 
    1169 The CIF contains a sparse matrix, from the ``loop_`` containing
    1170 ``_iso_displacivemodematrix_value`` which provides the equations for determining the mode values from the coordinates, that matrix is placed in ``.Phase['ISODISTORT']['Mode2VarMatrix']``. The matrix is inverted to produce
    1171 ``.Phase['ISODISTORT']['Var2ModeMatrix']``, which determines how to compute the
    1172 mode values from the delta coordinate values. These values are used for the
    1173 in :func:`GSASIIconstrGUI.ShowIsoDistortCalc` which shows coordinate and mode
    1174 values, the latter with s.u. values.
     1166The coordinate variables, as named by ISODISTORT, are placed in ``.Phase['ISODISTORT']['IsoVarList']`` and the
     1167corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2VarList']``.
     1168The mode variables, as named by ISODISTORT, are placed in ``.Phase['ISODISTORT']['IsoModeList']`` and the
     1169corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2ModeList']``.
     1170[Use ``str(G2VarObj)`` to get the variable name from the G2VarObj object, but note that the phase number, *n*, for the prefix
     1171 "*n*::" cannot be determined as the phase number is not yet assigned.]
     1172
     1173Displacive modes are a bit complex in that they relate to delta displacements, relative to an offset value for each coordinate,
     1174and because the modes are normalized, while GSAS-II also uses displacements, but these are added to the coordinates after
     1175each refinement cycle and the delta values are set to zero. ISODISTORT uses fixed offsets (subtracted from the actual position
     1176to obtain the delta values) that are taken from ``_iso_coordinate_formula`` and these are placed in
     1177``.Phase['ISODISTORT']['ParentStructure]`` (keyed by atom label). The normalization factors (which the delta values are divided by)
     1178are taken from ``_iso_displacivemodenorm_value`` and are placed in ``.Phase['ISODISTORT']['NormList']`` in the same order as as
     1179``...['IsoModeList']`` and ``...['G2ModeList']``.
     1180
     1181The CIF contains a sparse matrix, from the ``loop_`` containing ``_iso_displacivemodematrix_value`` which provides the equations
     1182for determining the mode values from the coordinates, that matrix is placed in ``.Phase['ISODISTORT']['Mode2VarMatrix']``.
     1183The matrix is inverted to produce ``.Phase['ISODISTORT']['Var2ModeMatrix']``, which determines how to compute the
     1184mode values from the delta coordinate values. These values are used for the in :func:`GSASIIconstrGUI.ShowIsoDistortCalc`
     1185which shows coordinate and mode values, the latter with s.u. values.
    11751186
    11761187
     
    11811192
    11821193The delta occupancy variables, as named by ISODISTORT, are placed in
    1183 ``.Phase['ISODISTORT']['OccVarList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2OccVarList']``. The mode variables, as named by ISODISTORT, are placed in ``.Phase['ISODISTORT']['OccModeList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed in ``.Phase['ISODISTORT']['G2OccModeList']``.
    1184 
    1185 Occupancy modes, like Displacive modes, are also refined as delta values.  However, GSAS-II directly refines the fractional occupancies.
    1186 Offset values for each atom, are taken from ``_iso_occupancy_formula`` and are placed in
    1187 ``.Phase['ISODISTORT']['ParentOcc]``.
    1188 (Offset values are subtracted from the actual position to obtain the delta values.)
    1189 Modes are normalized (where the mode values are divided by the normalization factor)
    1190 are taken from ``_iso_occupancymodenorm_value`` and are placed in ``.Phase['ISODISTORT']['OccNormList']`` in the same order as as ``...['OccModeList']`` and
     1194``.Phase['ISODISTORT']['OccVarList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed
     1195in ``.Phase['ISODISTORT']['G2OccVarList']``. The mode variables, as named by ISODISTORT, are placed in
     1196``.Phase['ISODISTORT']['OccModeList']`` and the corresponding :class:`GSASIIobj.G2VarObj` objects for each are placed
     1197in ``.Phase['ISODISTORT']['G2OccModeList']``.
     1198
     1199Occupancy modes, like Displacive modes, are also refined as delta values.  However, GSAS-II directly refines the fractional
     1200occupancies. Offset values for each atom, are taken from ``_iso_occupancy_formula`` and are placed in
     1201``.Phase['ISODISTORT']['ParentOcc]``. (Offset values are subtracted from the actual position to obtain the delta values.)
     1202Modes are normalized (where the mode values are divided by the normalization factor) are taken from ``_iso_occupancymodenorm_value``
     1203and are placed in ``.Phase['ISODISTORT']['OccNormList']`` in the same order as as ``...['OccModeList']`` and
    11911204``...['G2OccModeList']``.
    11921205
    1193 The CIF contains a sparse matrix, from the ``loop_`` containing
    1194 ``_iso_occupancymodematrix_value``, which provides the equations for determining the mode values from the coordinates. That matrix is placed in ``.Phase['ISODISTORT']['Occ2VarMatrix']``. The matrix is inverted to produce
    1195 ``.Phase['ISODISTORT']['Var2OccMatrix']``, which determines how to compute the
     1206The CIF contains a sparse matrix, from the ``loop_`` containing ``_iso_occupancymodematrix_value``, which provides the
     1207equations for determining the mode values from the coordinates. That matrix is placed in ``.Phase['ISODISTORT']['Occ2VarMatrix']``.
     1208The matrix is inverted to produce ``.Phase['ISODISTORT']['Var2OccMatrix']``, which determines how to compute the
    11961209mode values from the delta coordinate values.
    11971210
     
    12011214------------------------------
    12021215
    1203 Constraints are processed after the CIF has been read in
    1204 :meth:`GSASIIdataGUI.GSASII.OnImportPhase` or 
    1205 :meth:`GSASIIscriptable.G2Project.add_phase` by moving them from the reader
    1206 object's ``.Constraints`` class variable to
    1207 the Constraints tree entry's ['Phase'] list (for list items defining constraints) or
     1216Constraints are processed after the CIF has been read in :meth:`GSASIIdataGUI.GSASII.OnImportPhase` or 
     1217:meth:`GSASIIscriptable.G2Project.add_phase` by moving them from the reader object's ``.Constraints``
     1218class variable to the Constraints tree entry's ['Phase'] list (for list items defining constraints) or
    12081219the Constraints tree entry's ['_Explain'] dict (for dict items defining constraint help information)
    12091220
    1210 The information in ``.Phase['ISODISTORT']`` is used
    1211 in :func:`GSASIIconstrGUI.ShowIsoDistortCalc` which shows coordinate and mode
     1221The information in ``.Phase['ISODISTORT']`` is used in :func:`GSASIIconstrGUI.ShowIsoDistortCalc` which shows coordinate and mode
    12121222values, the latter with s.u. values. This can be called from the Constraints and Phase/Atoms tree items.
    12131223
    1214 Before each refinement, constraints are processed as
    1215 :ref:`described elsewhere <Constraints_processing>`. After a refinement
    1216 is complete, :func:`GSASIImapvars.PrintIndependentVars` shows the
    1217 shifts and s.u.'s on the refined modes, using GSAS-II values, but
    1218 :func:`GSASIIstrIO.PrintISOmodes` prints the ISODISTORT modes as computed
    1219 in the web site.
     1224Before each refinement, constraints are processed as :ref:`described elsewhere <Constraints_processing>`. After a refinement
     1225is complete, :func:`GSASIImapvars.PrintIndependentVars` shows the shifts and s.u.'s on the refined modes,
     1226using GSAS-II values, but :func:`GSASIIstrIO.PrintISOmodes` prints the ISODISTORT modes as computed in the web site.
    12201227
    12211228
  • trunk/GSASIIphsGUI.py

    r5037 r5041  
    47644764                    pairSizer.Add(G2G.ValidatedTxtCtrl(pnl,RMCPdict['Pairs'][pair],0,xmin=0.,xmax=10.,size=(50,25)),0,WACV)
    47654765                pairSizer.Add(wx.StaticText(pnl,label='%14s'%' Search from: '),0,WACV)
    4766             else:
     4766            elif G2frame.RMCchoice == 'fullrmc':
    47674767                pairSizer.Add(wx.StaticText(pnl,label='%14s'%' Distance min: '),0,WACV)
    47684768            for pair in RMCPdict['Pairs']:
     
    49684968        mainSizer = wx.BoxSizer(wx.VERTICAL)
    49694969        runFile = ' '
    4970         choice = ['RMCProfile','fullrmc',]
     4970        choice = ['RMCProfile','fullrmc','PDFfit']
    49714971        RMCsel = wx.RadioBox(G2frame.FRMC,-1,' Select RMC method:',choices=choice)
    49724972        RMCsel.SetStringSelection(G2frame.RMCchoice)
     
    52895289            subSizer.Add(wx.StaticText(G2frame.FRMC,label='RMCProfile setup'),0,WACV)
    52905290            subSizer.Add((-1,-1),1,wx.EXPAND)
    5291             mainSizer.Add(subSizer,0,wx.EXPAND)
     5291            mainSizer.Add(subSizer,0,WACV)
    52925292            mainSizer.Add((5,5))
    52935293            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=
     
    57375737
    57385738            FileSizer(RMCPdict,mainSizer)
    5739    
     5739        else:
     5740            subSizer = wx.BoxSizer(wx.HORIZONTAL)
     5741            subSizer.Add((-1,-1),1,wx.EXPAND)
     5742            subSizer.Add(wx.StaticText(G2frame.FRMC,label='PDFfit setup'),0,WACV)
     5743            subSizer.Add((-1,-1),1,wx.EXPAND)
     5744            mainSizer.Add(subSizer,0,WACV)
     5745            mainSizer.Add((5,5))
     5746            mainSizer.Add(wx.StaticText(G2frame.FRMC,label=
     5747'''"PDFfit2 and PDFgui: computer progerama for studying nanostructures in crystals",
     5748C.L. Farrow, P.Juhas, J.W. Liu, D. Bryndin, E.S. Bozin, J. Bloch, Th. Proffen &&
     5749S.J.L. Billinge, J. Phys, Condens. Matter 19, 335219 (2007)., Jour. Phys.: Cond. Matter
     5750(2007), 19, 335218. doi: https://doi.org/10.1088/0953-8984/19/33/335219'''))
     5751            mainSizer.Add((5,5))
     5752            if 'PDFfit' not in data['RMC']:
     5753                Atypes = [atype.split('+')[0].split('-')[0] for atype in data['General']['AtomTypes']]
     5754                aTypes = dict(zip(Atypes,len(Atypes)*[0.10,]))
     5755                files = {'Neutron real space data; G(r): ':['Select',0.05,'G(r)','RMC',],
     5756                          'Xray real space data; G(r): ':['Select',0.01,'G(r)','RMC',],}
     5757                data['RMC']['PDFfit'] = {'files':files}
     5758               
     5759            RMCPdict = data['RMC']['PDFfit']
    57405760        bigSizer.Add(mainSizer,1,wx.EXPAND)
    5741         # add help button to bring up help web page - at right sede of window
     5761        # add help button to bring up help web page - at right side of window
    57425762        bigSizer.Add(G2G.HelpButton(G2frame.FRMC,helpIndex=G2frame.dataWindow.helpKey))
    57435763        SetPhaseWindow(G2frame.FRMC,bigSizer)
     
    57655785            rname = G2pwd.MakefullrmcRun(pName,data,RMCPdict)
    57665786            print('build of fullrmc file {} completed'.format(rname))
    5767         else:
     5787        elif G2frame.RMCchoice == 'RMCProfile':
    57685788            pName = generalData['Name'].replace(' ','_')
    57695789            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
     
    58085828                print('RMCProfile file build failed - no histogram selected')
    58095829                G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
     5830        elif G2frame.RMCchoice == 'PDFfit':
     5831            print('PDFfit2 prep under construction')
    58105832           
    58115833    def OnRunRMC(event):
    5812         '''Run a previously created RMCProfile/fullrmc script
     5834        '''Run a previously created RMCProfile/fullrmc/PDFfit2 script
    58135835        '''
    58145836        generalData = data['General']
     
    58925914                    # TODO: better to create this in a new terminal on Linux
    58935915                    subp.Popen(['/bin/bash','fullrmc.sh'])
    5894         else:
     5916        elif G2frame.RMCchoice == 'RMCProfile':
    58955917            pName = generalData['Name'].replace(' ','_')
    58965918            RMCPdict = data['RMC']['RMCProfile']
     
    59475969            batch.close()
    59485970            subp.Popen('runrmc.bat',creationflags=subp.CREATE_NEW_CONSOLE)
     5971        elif G2frame.RMCchoice == 'PDFfit':
     5972            PDFfit_exec = G2pwd.findPDFfit()
     5973            if PDFfit_exec is None:
     5974                G2G.G2MessageBox(G2frame,'PDFfit2 Python not found. How did we get here?')
     5975                return
     5976            pName = generalData['Name'].replace(' ','_')
     5977            rname = pName+'_PDFfit.py'
     5978            if not os.path.exists(rname):
     5979                G2G.G2MessageBox(G2frame,
     5980                    'The PDFfit script has not been created. Running setup.',
     5981                    'Not setup')
     5982                OnSetupRMC(event)
     5983            wx.MessageBox(''' For use of PDFfit2, please cite:
     5984      PDFfit2 and PDFgui: computer progerama for studying nanostructures in crystals,
     5985C.L. Farrow, P.Juhas, J.W. Liu, D. Bryndin, E.S. Bozin, J. Bloch, Th. Proffen &
     5986S.J.L. Billinge, J. Phys, Condens. Matter 19, 335219 (2007)., Jour. Phys.: Cond. Matter
     5987(2007), 19, 335218. doi: https://doi.org/10.1088/0953-8984/19/33/335219''',
     5988      caption='PDFfit2',style=wx.ICON_INFORMATION)
     5989            G2frame.OnFileSave(event)
     5990            print (' GSAS-II project saved')
     5991            if sys.platform.lower().startswith('win'):
     5992                batch = open('pdffit2.bat','w')
     5993                batch.write(PDFfit_exec+' '+rname+'\n')
     5994                batch.write('pause')
     5995                batch.close()
     5996                subp.Popen('pdffit2.bat',creationflags=subp.CREATE_NEW_CONSOLE)
     5997            else:
     5998                batch = open('pdffit2.sh','w')
     5999                batch.write('#!/bin/bash\n')
     6000                batch.write('cd ' + os.path.split(os.path.abspath(rname))[0] + '\n')
     6001                batch.write(PDFfit_exec + ' ' + os.path.abspath(rname) + '\n')
     6002                batch.close()
     6003                if sys.platform == "darwin":
     6004                    GSASIIpath.MacRunScript(os.path.abspath('pdffit2.sh'))
     6005                else:
     6006                    # TODO: better to create this in a new terminal on Linux
     6007                    subp.Popen(['/bin/bash','pdffit2.sh'])
    59496008           
    59506009    def OnStopRMC(event):
     
    60616120                                lines=True,names=plotLbls)
    60626121            return
    6063         else:
     6122        elif G2frame.RMCchoice == 'RMCProfile':
    60646123            generalData = data['General']
    60656124            RMCPdict = data['RMC']['RMCProfile']
     
    63216380                            newPlot=False,Title='Number of %s-%s Bonds'%(bond[0],bond[1]),Centro=True) 
    63226381                    OutFile.close()
     6382        elif G2frame.RMCchoice == 'PDFfit':
     6383            generalData = data['General']
     6384            RMCPdict = data['RMC']['PDFfit']
     6385            pName = generalData['Name'].replace(' ','_')
     6386            print('PDFfit plots under construction')
    63236387       
    63246388           
  • trunk/GSASIIpwd.py

    r5037 r5041  
    29272927            return os.path.abspath(sorted(fl)[0])
    29282928       
     2929def findPDFfit():
     2930    '''Find where PDFfit2 is installed. Does the following:
     2931    :returns: the full path to a python executable that is assumed to
     2932      have PDFfit2 installed or None, if it was not found.
     2933    '''
     2934    try:
     2935        import diffpy.pdffit2
     2936        return sys.executable
     2937    except:
     2938        return None
     2939       
    29292940def MakefullrmcRun(pName,Phase,RMCPdict):
    29302941    '''Creates a script to run fullrmc. Returns the name of the file that was
Note: See TracChangeset for help on using the changeset viewer.