Ignore:
Timestamp:
Dec 3, 2015 3:09:45 PM (7 years ago)
Author:
vondreele
Message:

new importer for hk6 files from 15ID

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/imports/G2sfact.py

    r2038 r2079  
    270270            return False
    271271
     272class SHELX6_ReaderClass(G2IO.ImportStructFactor):
     273    'Routines to import F**2, sig(F**2) twin/incommensurate reflections from a fixed format SHELX HKLF6 file'
     274    def __init__(self):
     275        if 'linux' in sys.platform:  # wx 3.0.0.0 on gtk does not like Unicode in menus
     276            formatName = 'Shelx HKLF 6 F2 Tw/Incom'
     277            longFormatName = 'Shelx HKLF 6 [hklm, Fo2, sig(Fo2), Tind] Twin/incommensurate structure factor text file'
     278        else:
     279            formatName = u'Shelx HKLF 6 F\u00b2 Tw/Incom'
     280            longFormatName = u'Shelx HKLF 6 [hklm, Fo\u00b2, sig(Fo\u00b2), Tind] Twin/incommensurate structure factor text file'       
     281        super(self.__class__,self).__init__( # fancy way to self-reference
     282            extensionlist=('.hk6','.HK6'),
     283            strictExtension=False,
     284            formatName=formatName,
     285            longFormatName=longFormatName)
     286        self.Super = 0
     287
     288    def ContentsValidator(self, filepointer):
     289        '''Discover how many columns before F^2 are in the SHELX HKL5 file
     290        - could be 3-6 depending on satellites'''
     291        numCols = 0
     292        for i,line in enumerate(filepointer):
     293            for j,item in enumerate(line.split()):  #find 1st col with '.'; has F^2
     294                if '.' in item:
     295                    numCols = max(numCols,j)
     296                    break
     297            if i > 20:
     298                break
     299        if numCols != 6:
     300            self.warnings += '\nInvalid hk6 file; wrong number of columns'
     301            raise self.ImportException('Invalid hk6 file; wrong number of columns')
     302        self.Super = 1
     303        return True
     304
     305    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
     306        'Read the file'
     307        TwDict = {}
     308        TwSet = {}
     309        TwMax = [-1,[]]
     310        first = True
     311        try:
     312            for line,S in enumerate(filepointer):
     313                self.errors = '  Error reading line '+str(line+1)
     314                h,k,l,m1,m2,m3,Fo,sigFo,Tw = S[:4],S[4:8],S[8:12],S[12:16],S[16:20],S[20:24],S[24:32],S[32:40],S[40:44]
     315                h,k,l,m1,m2,m3 = [int(h),int(k),int(l),int(m1),int(m2),int(m3)]
     316                if m2 or m3:
     317                    self.warnings += '\n(3+2) & (3+3) Supersymmetry not allowed in GSAS-II. Reformulate as twinned (3+1) supersymmetry'
     318                    raise self.ImportException("Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry")                               
     319                Tw = Tw.strip()
     320                if Tw in ['','0']:
     321                    Tw = '1'
     322                if not any([h,k,l]):    #look for 0 0 0 or blank line
     323                    break
     324                if '-' in Tw:
     325                    if Tw == '-1':  #fix reversed twin ids
     326                        Tw = '-2'
     327                        if first:
     328                            self.warnings += '\nPrimary twin id changed to 1'
     329                            first = False
     330                    TwId = -int(Tw)-1
     331                    TwSet[TwId] = np.array([h,k,l])
     332                    if TwId not in TwMax[1]:
     333                        TwMax[1].append(TwId)
     334                else:
     335                    if Tw != '1':  #fix reversed twin ids
     336                        if first:
     337                            self.warnings += '\nPrimary twin id changed to 1\nNB: multiple primary twins not working'
     338                            first = False
     339                        Tw = '1'
     340                    TwId = int(Tw)-1
     341                    if TwSet:
     342                        TwDict[len(self.RefDict['RefList'])] = TwSet
     343                        TwSet = {}   
     344                    Fo = float(Fo)
     345                    sigFo = float(sigFo)
     346                    # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
     347                    self.RefDict['RefList'].append([h,k,l,m1,int(Tw),0,Fo,sigFo,0,Fo,0,0,0])
     348                TwMax[0] = max(TwMax[0],TwId)
     349            self.errors = 'Error after reading reflections (unexpected!)'
     350            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
     351            self.RefDict['Type'] = 'SXC'
     352            self.RefDict['Super'] = self.Super
     353            self.RefDict['TwDict'] = TwDict
     354            self.RefDict['TwMax'] = TwMax
     355            self.UpdateParameters(Type='SXC',Wave=None) # histogram type
     356            return True
     357        except Exception as detail:
     358            self.errors += '\n  '+str(detail)
     359            print '\n\n'+self.formatName+' read error: '+str(detail) # for testing
     360            import traceback
     361            traceback.print_exc(file=sys.stdout)
     362            return False
     363
    272364class M90_ReaderClass(G2IO.ImportStructFactor):
    273365    'Routines to import F**2, sig(F**2) reflections from a JANA M90 file'
Note: See TracChangeset for help on using the changeset viewer.