@@ -4998,21 +4998,25 @@ def HAPvalue(self, param=None, newValue=None, targethistlist='all'):
49984998 """Retrieves or sets individual HAP parameters for one histogram or
49994999 multiple histograms.
50005000
5001-
50025001 :param str param: is a parameter name, which can be 'Scale' or
50035002 'PhaseFraction' (either can be used for phase
5004- fraction), 'Use', 'Extinction' or 'LeBail'.
5003+ fraction), 'Use', 'Extinction', 'LeBail', 'PO'
5004+ (for Prefered Orientation).
50055005 If not specified or invalid
50065006 an exception is generated showing the list of valid parameters.
50075007 At present, these HAP parameters cannot be access with this function:
5008- 'Pref.Ori.', ' Size', 'Mustrain', 'HStrain', 'Babinet'. On request this
5008+ 'Size', 'Mustrain', 'HStrain', 'Babinet'. On request this
50095009 might be addressed in the future. Some of these values can be set via
50105010 :meth:`G2Phase.set_HAP_refinements`.
50115011 :param newValue: the value to use when setting the HAP parameter for the
50125012 appropriate histogram(s). Will be converted to the proper type or
50135013 an exception will be generated if not possible. If not specified,
50145014 and only one histogram is selected, the value is retrieved and
50155015 returned.
5016+ When param='PO' then this value is interpreted as the following:
5017+ if the value is 0 or an even integer, then the preferred
5018+ orientation model is set to "Spherical harmonics". If the value is
5019+ 1, then "March-Dollase" is used. Any other value generates an error.
50165020 :param list targethistlist: a list of histograms where each item in the
50175021 list can be a histogram object (:class:`G2PwdrData`),
50185022 a histogram name or the index number of the histogram.
@@ -5022,7 +5026,8 @@ def HAPvalue(self, param=None, newValue=None, targethistlist='all'):
50225026 are used.
50235027
50245028 targethistlist must correspond to a single histogram if a value
5025- is to be returned (when argument newValue is not specified).
5029+ is to be returned (i.e. when argument newValue is not specified).
5030+ :param int order: is a value for the order when
50265031
50275032 :returns: the value of the parameter, when argument newValue is not specified.
50285033
@@ -5050,17 +5055,20 @@ def HAPvalue(self, param=None, newValue=None, targethistlist='all'):
50505055 refFloatParam = ('Scale' ,'Extinction' )
50515056 useBool = False
50525057 useFloat = False
5058+ useInt = False
50535059 if param == 'PhaseFraction' : param = 'Scale'
50545060 if param in boolParam :
50555061 useBool = True
50565062 elif param in refFloatParam :
50575063 useFloat = True
5064+ elif param in ['PO' ]:
5065+ useInt = True
50585066 else :
50595067 s = ''
5060- for i in boolParam + refFloatParam + ['PhaseFraction' ]:
5068+ for i in boolParam + refFloatParam + ['PhaseFraction' , 'PO' ]:
50615069 if s != '' : s += ', '
50625070 s += f'"{ i } "'
5063- raise G2ScriptException ('Invalid parameter. Valid choices are: ' + s )
5071+ raise G2ScriptException (f 'Invalid parameter. Valid choices are: { s } ' )
50645072 if not doSet and len (targethistlist ) > 1 :
50655073 raise G2ScriptException (f'Unable to report value from { len (targethistlist )} histograms' )
50665074 for h in targethistlist :
@@ -5076,6 +5084,28 @@ def HAPvalue(self, param=None, newValue=None, targethistlist='all'):
50765084 self .data ['Histograms' ][h ][param ] = bool (newValue )
50775085 elif useFloat :
50785086 self .data ['Histograms' ][h ][param ][0 ] = float (newValue )
5087+ elif useInt :
5088+ if newValue is None :
5089+ return self .data ['Histograms' ][h ]['Pref.Ori.' ]
5090+ try :
5091+ intval = int (newValue )
5092+ except :
5093+ intval = None
5094+ if intval == 1 :
5095+ self .data ['Histograms' ][h ]['Pref.Ori.' ][0 ] = 'MD'
5096+ elif intval is not None and 2 * int (intval // 2 ) == intval :
5097+ SGData = self .data ['General' ]['SGData' ]
5098+ cofNames = G2lat .GenSHCoeff (SGData ['SGLaue' ],'0' ,intval ,False ) #cylindrical & no M
5099+
5100+ self .data ['Histograms' ][h ]['Pref.Ori.' ][0 ] = 'SH'
5101+ self .data ['Histograms' ][h ]['Pref.Ori.' ][4 ] = intval
5102+ olddict = self .data ['Histograms' ][h ]['Pref.Ori.' ][5 ]
5103+ newdict = dict (zip (cofNames ,len (cofNames )* [0. ]))
5104+ # retain any old values in existing dict
5105+ newdict .update ({i :olddict [i ] for i in olddict if i in newdict })
5106+ self .data ['Histograms' ][h ]['Pref.Ori.' ][5 ] = newdict
5107+ else :
5108+ raise G2ScriptException (f'Preferred orientation value of { newValue } is invalid' )
50795109 else :
50805110 print ('unexpected action' )
50815111
0 commit comments