def Reader(self, filename, ParentFrame=None, **unused):
     '''Read a phase from a .GPX file. Does not (yet?) support selecting and reading
     more than one phase at a time.'''
     try:
         phasenames = G2stIO.GetPhaseNames(filename)
     except:
         self.errors = 'Reading of phase names failed'
         return False
     if not phasenames:
         self.errors = 'No phases found in ' + str(filename)
         return False  # no blocks with coordinates
     elif len(phasenames) == 1:  # one block, no choices
         selblk = 0
     else:  # choose from options
         selblk = G2IO.PhaseSelector(
             phasenames,
             ParentFrame=ParentFrame,
             title='Select a phase from the list below',
         )
         if selblk is None:
             self.errors = 'No phase selected'
             return False  # User pressed cancel
     self.Phase = G2stIO.GetAllPhaseData(filename, phasenames[selblk])
     self.Phase['Histograms'] = {}  #remove any histograms
     self.Phase['Pawley ref'] = []  # & any Pawley refl.
     self.Phase['RBModels'] = {}
     if 'MCSA' in self.Phase:
         del self.Phase['MCSA']
     if 'Map Peaks' in self.Phase:
         del self.Phase['Map Peaks']
     if 'Map' in self.Phase['General']:
         del self.Phase['General']['Map']
     self.Phase['ranId'] = ran.randint(0, sys.maxsize)
     return True
Example #2
0
 def Reader(self, filename, filepointer, ParentFrame=None, **unused):
     '''Read a phase from a .GPX file. Does not (yet?) support selecting and reading
     more than one phase at a time.'''
     try:
         phasenames = G2stIO.GetPhaseNames(filename)
     except:
         self.errors = 'Reading of phase names failed'
         return False
     if not phasenames:
         self.errors = 'No phases found in ' + str(filename)
         return False  # no blocks with coordinates
     elif len(phasenames) == 1:  # one block, no choices
         selblk = 0
     else:  # choose from options
         selblk = self.PhaseSelector(
             phasenames,
             ParentFrame=ParentFrame,
             title='Select a phase from the list below',
         )
         if selblk is None:
             self.errors = 'No phase selected'
             return False  # User pressed cancel
     try:
         self.Phase = G2stIO.GetAllPhaseData(filename, phasenames[selblk])
         self.Phase['Histograms'] = {}  #remove any histograms
         self.Phase['Pawley ref'] = []  # & any Pawley refl.
         self.Phase['ranId'] = ran.randint(0, sys.maxint)
         return True
     except Exception as detail:
         self.errors = 'Error reading selected phase'
         self.errors += '\n  ' + str(detail)
         print self.formatName + ' error:', detail  # for testing
         print sys.exc_info()[0]  # for testing
         import traceback
         print traceback.format_exc()
Example #3
0
    def __init__(self, GPXfile=None):
        '''
        Initialize the setup using an existing GPXfile
        '''
        if not GPXfile:
            # TO DO: Raise name error
            raise NameError('Must input some GPX file')
        # Initallizing variables from input file GPXfile
        G2path.SetBinaryPath()
        varyList = []
        parmDict = {}
        symmetry = {}
        Controls = G2stIO.GetControls(GPXfile)
        calcControls = {}
        calcControls.update(Controls)
        constrDict, fixedList = G2stIO.GetConstraints(GPXfile)
        restraintDict = G2stIO.GetRestraints(GPXfile)
        Histograms, Phases = G2stIO.GetUsedHistogramsAndPhases(GPXfile)
        rigidbodyDict = G2stIO.GetRigidBodies(GPXfile)
        rbIds = rigidbodyDict.get('RBIds', {'Vector': [], 'Residue': []})
        rbVary, rbDict = G2stIO.GetRigidBodyModels(rigidbodyDict, Print=False)
        (Natoms, atomIndx, phaseVary, phaseDict, pawleyLookup, FFtables,
         BLtables, MFtables, maxSSwave) = G2stIO.GetPhaseData(Phases,
                                                              restraintDict,
                                                              rbIds,
                                                              Print=False)
        calcControls['atomIndx'] = atomIndx
        calcControls['Natoms'] = Natoms
        calcControls['FFtables'] = FFtables
        calcControls['BLtables'] = BLtables
        calcControls['MFtables'] = MFtables
        calcControls['maxSSwave'] = maxSSwave
        hapVary, hapDict, controlDict = G2stIO.GetHistogramPhaseData(
            Phases, Histograms, Print=False)
        calcControls.update(controlDict)
        histVary, histDict, controlDict = G2stIO.GetHistogramData(Histograms,
                                                                  Print=False)
        calcControls.update(controlDict)
        varyList = rbVary + phaseVary + hapVary + histVary
        parmDict.update(rbDict)
        parmDict.update(phaseDict)
        parmDict.update(hapDict)
        parmDict.update(histDict)
        G2stIO.GetFprime(calcControls, Histograms)
        # define phase symmetries, currently only works for one phase
        phase = G2stIO.GetPhaseNames(GPXfile)
        phaseData = {}
        for name in phase:
            phaseData[name] = G2stIO.GetAllPhaseData(GPXfile, name)
            symmetry[name] = phaseData[name]['General']['SGData']['SGSys']

        # Save the instance parameters
        self._Histograms = Histograms
        self._varyList = varyList
        self._parmDict = parmDict
        self._Phases = Phases
        self._calcControls = calcControls
        self._pawleyLookup = pawleyLookup
        self._restraintDict = restraintDict
        self._rigidbodyDict = rigidbodyDict
        self._rbIds = rbIds
        self._symmetry = symmetry
        self._phase = phase
        try:
            self._lowerLimit = Histograms[list(
                Histograms.keys())[0]][u'Limits'][1][0]
            self._upperLimit = Histograms[list(
                Histograms.keys())[0]][u'Limits'][1][1]
            self._tth = Histograms[list(Histograms.keys())[0]]['Data'][0][0:-1]
            self._tthsample = self._tth[np.where(
                (self._tth > self._lowerLimit)
                & (self._tth < self._upperLimit) == True)]  # noqa: E712
            self._SingleXtal = False
        except:  # noqa: E722
            self._tth = None
            self._MaxDiffSig = None
            self._Fosq = 0
            self._FoSig = 0
            self._Fcsq = 0
            self._SingleXtal = True