Changeset 4005
- Timestamp:
- May 30, 2019 5:24:34 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r4004 r4005 24 24 :func:`PlotStructure` Crystal structure plotting with balls, sticks, lines, 25 25 ellipsoids, polyhedra and magnetic moments 26 :func: 'Plot1DSngl'1D stick plots of structure factors26 :func:`Plot1DSngl` 1D stick plots of structure factors 27 27 :func:`PlotSngl` Structure factor plotting 28 28 :func:`Plot3DSngl` 3D Structure factor plotting -
trunk/GSASIIscriptable.py
r4003 r4005 131 131 :meth:`G2Project.set_refinement` This is passed a single dict which is used to set parameters and flags. 132 132 These actions can be performed also in :meth:`G2Project.do_refinements`. 133 :meth:`G2Project.get_Variable' Retrieves the value and esd for a parameter 134 :meth:`G2Project.get_Covariance' Retrieves values and covariance for a set of refined parameters 133 :meth:`G2Project.get_Variable` Retrieves the value and esd for a parameter 134 :meth:`G2Project.get_Covariance` Retrieves values and covariance for a set of refined parameters 135 :meth:`G2Project.set_Controls` Set overall GSAS-II control settings such as number of cycles and to set up a sequential 136 fit. (Also see :meth:`G2Project.get_Controls` to read values.) 135 137 ================================================== =============================================================================================================== 136 138 … … 161 163 :meth:`G2Phase.get_cell` Returns unit cell parameters (also see :meth:`G2Phase.get_cell_and_esd`) 162 164 :meth:`G2Phase.export_CIF` Writes a CIF for the phase 163 :meth:`G2Phase.set_Controls` Set overall GSAS-II control settings such as number of cycles and to set up a sequential164 fit. (Also see :meth:`G2Phase.get_Controls` to read values.)165 165 ================================================== =============================================================================================================== 166 166 … … 242 242 :meth:`G2SeqRefRes.histograms` Provides a list of histograms used in the Sequential Refinement 243 243 :meth:`G2SeqRefRes.get_cell_and_esd` Returns cell dimensions and standard uncertainies for a phase and histogram from the Sequential Refinement 244 :meth:`G2SeqRefRes.get_Variable 'Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement245 :meth:`G2SeqRefRes.get_Covariance 'Retrieves values and covariance for a set of refined parameters for a particular histogram244 :meth:`G2SeqRefRes.get_Variable` Retrieves the value and esd for a parameter from a particular histogram in the Sequential Refinement 245 :meth:`G2SeqRefRes.get_Covariance` Retrieves values and covariance for a set of refined parameters for a particular histogram 246 246 ================================================== =============================================================================================================== 247 247 … … 3366 3366 3367 3367 def histograms(self): 3368 '''Returns a list of histogram names associated with the current phase. 3369 ''' 3370 output = [] 3371 for hname in self.data.get('Histograms', {}).keys(): 3372 output.append(self.proj.histogram(hname)) 3373 return output 3368 '''Returns a list of histogram names associated with the current phase ordered 3369 as they appear in the tree (see :meth:`G2Project.histograms`). 3370 ''' 3371 return [i.name for i in self.proj.histograms() if i.name in self.data.get('Histograms', {})] 3374 3372 3375 3373 @property … … 3584 3582 3585 3583 def set_HAP_refinements(self, refs, histograms='all'): 3586 """Sets the given HAP refinement parameters between th isphase and3587 the givenhistograms.3584 """Sets the given HAP refinement parameters between the current phase and 3585 the specified histograms. 3588 3586 3589 3587 :param dict refs: A dictionary of the parameters to be set. See 3590 3588 the :ref:`HAP_parameters_table` table for a description of this 3591 3589 dictionary. 3592 :param histograms: Either 'all' (default) or a list of the histograms 3590 :param histograms: Either 'all' (default) or a list of the histograms by index, name 3591 or object. The index number is relative to all histograms in the tree, not to 3592 those in the phase. 3593 Histograms not associated with the current phase will be ignored. 3593 3594 whose HAP parameters will be set with this phase. Histogram and phase 3594 must already be associated 3595 3595 must already be associated. 3596 3596 :returns: None 3597 3597 """ 3598 if not self.data ['Histograms']:3598 if not self.data.get('Histograms',[]): 3599 3599 print("Error likely: Phase {} has no linked histograms".format(self.name)) 3600 3600 return 3601 3601 3602 3602 if histograms == 'all': 3603 histograms = self.data['Histograms']. values()3603 histograms = self.data['Histograms'].keys() 3604 3604 else: 3605 histograms = [self.data['Histograms'][h.name] for h in histograms 3606 if h.name in self.data['Histograms']] 3607 3605 histograms = [self._decodeHist(h) for h in histograms 3606 if self._decodeHist(h) in self.data['Histograms']] 3608 3607 if not histograms: 3609 3608 print("Skipping HAP set for phase {}, no selected histograms".format(self.name)) … … 3619 3618 raise ValueError("Not sure what to do with" + param) 3620 3619 for h in histograms: 3621 h['Babinet'][param][1] = True3620 self.data['Histograms'][h]['Babinet'][param][1] = True 3622 3621 elif key == 'Extinction': 3623 3622 for h in histograms: 3624 h['Extinction'][1] = bool(val)3623 self.data['Histograms'][h]['Extinction'][1] = bool(val) 3625 3624 elif key == 'HStrain': 3626 3625 if isinstance(val,list) or isinstance(val,tuple): 3627 3626 for h in histograms: 3628 if len( h['HStrain'][1]) != len(val):3629 raise Exception('Need {} HStrain terms for phase {} '3630 .format(len( h['HStrain'][1]),self.name))3627 if len(self.data['Histograms'][h]['HStrain'][1]) != len(val): 3628 raise Exception('Need {} HStrain terms for phase {} hist {}' 3629 .format(len(self.data['Histograms'][h]['HStrain'][1]),self.name,h)) 3631 3630 for i,v in enumerate(val): 3632 h['HStrain'][1][i] = bool(v)3631 self.data['Histograms'][h]['HStrain'][1][i] = bool(v) 3633 3632 else: 3634 3633 for h in histograms: 3635 h['HStrain'][1] = [bool(val) for p in h['HStrain'][1]]3634 self.data['Histograms'][h]['HStrain'][1] = [bool(val) for p in self.data['Histograms'][h]['HStrain'][1]] 3636 3635 elif key == 'Mustrain': 3637 3636 for h in histograms: 3638 mustrain = h['Mustrain']3637 mustrain = self.data['Histograms'][h]['Mustrain'] 3639 3638 newType = None 3640 3639 direction = None … … 3692 3691 newSize = float(val['value']) 3693 3692 for h in histograms: 3694 size = h['Size']3693 size = self.data['Histograms'][h]['Size'] 3695 3694 newType = None 3696 3695 direction = None … … 3706 3705 if newType: 3707 3706 size[0] = newType 3708 refine = True == val.get('refine')3707 refine = bool(val.get('refine')) 3709 3708 if newType == 'isotropic' and refine is not None: 3710 3709 size[2][0] = bool(refine) … … 3725 3724 elif key == 'Pref.Ori.': 3726 3725 for h in histograms: 3727 h['Pref.Ori.'][2] = bool(val)3726 self.data['Histograms'][h]['Pref.Ori.'][2] = bool(val) 3728 3727 elif key == 'Show': 3729 3728 for h in histograms: 3730 h['Show'] = bool(val)3729 self.data['Histograms'][h]['Show'] = bool(val) 3731 3730 elif key == 'Use': 3732 3731 for h in histograms: 3733 h['Use'] = bool(val)3732 self.data['Histograms'][h]['Use'] = bool(val) 3734 3733 elif key == 'Scale': 3735 3734 for h in histograms: 3736 h['Scale'][1] = bool(val)3735 self.data['Histograms'][h]['Scale'][1] = bool(val) 3737 3736 else: 3738 3737 print(u'Unknown HAP key: '+key) … … 3754 3753 3755 3754 :param histogram: is a histogram object (:class:`G2PwdrData`) or 3756 a histogram name or the index number of the histogram 3757 3755 a histogram name or the index number of the histogram. 3756 The index number is relative to all histograms in the tree, not to 3757 those in the phase. 3758 3758 :returns: HAP value dict 3759 3759 """ 3760 3760 return self.data['Histograms'][self._decodeHist(histname)] 3761 3761 3762 def copyHAPvalues(self, sourcehist, targethistlist, skip=[]): 3763 """Returns a dict with HAP values for the selected histogram 3762 def copyHAPvalues(self, sourcehist, targethistlist='all', skip=[], use=None): 3763 """Copies HAP parameters for one histogram to a list of other histograms. 3764 Use skip or use to select specific entries to be copied or not used. 3764 3765 3765 3766 :param sourcehist: is a histogram object (:class:`G2PwdrData`) or 3766 a histogram name or the index number of the histogram 3767 a histogram name or the index number of the histogram to copy 3768 parameters from. 3769 The index number is relative to all histograms in the tree, not to 3770 those in the phase. 3767 3771 :param list targethistlist: a list of histograms where each item in the 3768 3772 list can be a histogram object (:class:`G2PwdrData`), 3769 3773 a histogram name or the index number of the histogram. 3770 if the string 'all', then all histograms in the phase are used. 3774 If the string 'all' (default), then all histograms in the phase 3775 are used. 3771 3776 :param list skip: items in the HAP dict that should not be 3772 3777 copied. The default is an empty list, which causes all items 3773 3778 to be copied. To see a list of items in the dict, use 3774 3779 :meth:`getHAPvalues` or use an invalid item, such as '?'. 3780 :param list use: specifies the items in the HAP dict should be 3781 copied. The default is None, which causes all items 3782 to be copied. 3783 3784 examples:: 3785 3786 ph0.copyHAPvalues(0,[1,2,3]) 3787 ph0.copyHAPvalues(0,use=['HStrain','Size']) 3788 3789 The first example copies all HAP parameters from the first histogram to 3790 the second, third and fourth histograms (as listed in the project tree). 3791 The second example copies only the 'HStrain' (Dij parameters and 3792 refinement flags) and the 'Size' (crystallite size settings, parameters 3793 and refinement flags) from the first histogram to all histograms. 3775 3794 """ 3776 3795 sourcehist = self._decodeHist(sourcehist) 3777 3796 if targethistlist == 'all': 3778 targethistlist = list(self.data['Histograms'].keys())3797 targethistlist = self.histograms() 3779 3798 3780 3799 copydict = copy.deepcopy(self.data['Histograms'][sourcehist]) 3781 3800 for item in skip: 3782 if item in copydict:3801 if item in list(copydict.keys()): 3783 3802 del copydict[item] 3784 3803 else: 3785 3804 print('items in HAP dict are: {}'.format( 3786 3805 list(self.data['Histograms'][sourcehist]))) 3787 raise Exception('HAP dict entry {} invalid'.format(item)) 3806 raise Exception('HAP skip list entry {} invalid'.format(item)) 3807 if use: 3808 for item in list(copydict.keys()): 3809 if item not in use: 3810 del copydict[item] 3811 3812 print('Copying items {} from histgram {}'.format(list(copydict.keys()),sourcehist)) 3813 print(' to histograms {}'.format([self._decodeHist(h) for h in targethistlist])) 3788 3814 for h in targethistlist: 3789 3815 h = self._decodeHist(h) 3790 self.data['Histograms'][h].update(copydict) 3816 if h not in self.data['Histograms']: 3817 print('Warning: histogram {} not in phase {}'.format(h,self.name)) 3818 continue 3819 self.data['Histograms'][h].update(copy.deepcopy(copydict)) 3791 3820 3792 #GSASIIpath.IPyBreak_base()3793 3794 3821 def clear_HAP_refinements(self, refs, histograms='all'): 3795 3822 """Clears the given HAP refinement parameters between this phase and … … 3798 3825 :param dict refs: A dictionary of the parameters to be cleared. 3799 3826 See the the :ref:`HAP_parameters_table` table for what can be specified. 3800 :param histograms: Either 'all' (default) or a list of the histograms 3801 whose HAP parameters will be cleared with this phase. Histogram and 3802 phase must already be associated 3803 3827 :param histograms: Either 'all' (default) or a list of the histograms by index, name 3828 or object. 3829 The index number is relative to all histograms in the tree, not to 3830 those in the phase. 3831 Histograms not associated with the current phase will be ignored. 3832 whose HAP parameters will be set with this phase. Histogram and phase 3833 must already be associated 3804 3834 :returns: None 3805 3835 """ 3806 3836 if histograms == 'all': 3807 histograms = self.data['Histograms']. values()3837 histograms = self.data['Histograms'].keys() 3808 3838 else: 3809 histograms = [self. data['Histograms'][h.name] for h in histograms3810 if h.name in self.data['Histograms']]3839 histograms = [self._decodeHist(h) for h in histograms 3840 if self._decodeHist(h) in self.data['Histograms']] 3811 3841 3812 3842 for key, val in refs.items(): … … 3820 3850 if param not in ['BabA', 'BabU']: 3821 3851 raise ValueError("Not sure what to do with" + param) 3822 for h istin histograms:3823 hist['Babinet'][param][1] = False3852 for h in histograms: 3853 self.data['Histograms'][h]['Babinet'][param][1] = False 3824 3854 elif key == 'Extinction': 3825 3855 for h in histograms: 3826 h['Extinction'][1] = False3856 self.data['Histograms'][h]['Extinction'][1] = False 3827 3857 elif key == 'HStrain': 3828 3858 for h in histograms: 3829 h['HStrain'][1] = [False for p in h['HStrain'][1]]3859 self.data['Histograms'][h]['HStrain'][1] = [False for p in self.data['Histograms'][h]['HStrain'][1]] 3830 3860 elif key == 'Mustrain': 3831 3861 for h in histograms: 3832 mustrain = h['Mustrain']3862 mustrain = self.data['Histograms'][h]['Mustrain'] 3833 3863 mustrain[2] = [False for p in mustrain[2]] 3834 3864 mustrain[5] = [False for p in mustrain[4]] 3835 3865 elif key == 'Pref.Ori.': 3836 3866 for h in histograms: 3837 h['Pref.Ori.'][2] = False3867 self.data['Histograms'][h]['Pref.Ori.'][2] = False 3838 3868 elif key == 'Show': 3839 3869 for h in histograms: 3840 h['Show'] = False3870 self.data['Histograms'][h]['Show'] = False 3841 3871 elif key == 'Size': 3842 3872 for h in histograms: 3843 size = h['Size']3873 size = self.data['Histograms'][h]['Size'] 3844 3874 size[2] = [False for p in size[2]] 3845 3875 size[5] = [False for p in size[5]] 3846 3876 elif key == 'Use': 3847 3877 for h in histograms: 3848 h['Use'] = False3878 self.data['Histograms'][h]['Use'] = False 3849 3879 elif key == 'Scale': 3850 3880 for h in histograms: 3851 h['Scale'][1] = False3881 self.data['Histograms'][h]['Scale'][1] = False 3852 3882 else: 3853 3883 print(u'Unknown HAP key: '+key) … … 3907 3937 :param hist: Specify a histogram or using the histogram name (str) 3908 3938 or the index number (int) of the histogram in the sequential 3909 refinement (not the project), numbered starting from 0. 3939 refinement (not the project), numbered as in in the project tree 3940 starting from 0. 3910 3941 :returns: cell,cellESD,uniqCellIndx where cell (list) 3911 3942 with the unit cell parameters (a,b,c,alpha,beta,gamma,Volume); … … 4017 4048 :param hist: Specify a histogram or using the histogram name (str) 4018 4049 or the index number (int) of the histogram in the sequential 4019 refinement (not the project), numbered starting from 0. 4050 refinement (not the project), numbered as in the project tree 4051 starting from 0. 4020 4052 :returns: a list of parameters or None if no refinement has been 4021 4053 performed. … … 4034 4066 :param hist: Specify a histogram or using the histogram name (str) 4035 4067 or the index number (int) of the histogram in the sequential 4036 refinement (not the project), numbered starting from 0. 4068 refinement (not the project), numbered as in the project tree 4069 starting from 0. 4037 4070 :param str var: a variable name of form '<p>:<h>:<name>', such as 4038 4071 ':0:Scale' … … 4060 4093 :param hist: Specify a histogram or using the histogram name (str) 4061 4094 or the index number (int) of the histogram in the sequential 4062 refinement (not the project), numbered starting from 0. 4095 refinement (not the project), numbered as in the project tree 4096 starting from 0. 4063 4097 :param tuple varList: a list of variable names of form '<p>:<h>:<name>' 4064 4098 :returns: (valueList,CovMatrix) where valueList contains the (n) values … … 4095 4129 :param hist: Specify a histogram or using the histogram name (str) 4096 4130 or the index number (int) of the histogram in the sequential 4097 refinement (not the project), numbered starting from 0. 4131 refinement (not the project), numbered as in the project tree 4132 starting from 0. 4098 4133 :returns: a list of dicts where the first element has sequential 4099 4134 refinement results and the second element has the contents of
Note: See TracChangeset
for help on using the changeset viewer.