Пример #1
0
    def extractOut(self, sasCIFdict, sasCIFfile, data_block_id=''):
        
        sasCIFfile = os.path.split(sasCIFfile)[-1]
        
        if data_block_id:
            data_block_list = [data_block_id]
        else:
            data_block_list = sasCIFdict.keys()

        for data_block_id in data_block_list:
            if '_sas_p_of_R' in sasCIFdict[data_block_id]:
                outfile = open(sasCIFfile[0:-7] + '.out', 'w')

                intensityTable = [sasCIFdict[data_block_id]['_sas_p_of_R_extrapolated_intensity']['momentum_transfer'],
                                  sasCIFdict[data_block_id]['_sas_p_of_R_extrapolated_intensity']['intensity_reg']]
                intensityHeader = ['S', 'I REG']

                # Alignment of experimental and extrapolated intensities
                if '_sas_scan_intensity' in sasCIFdict[data_block_id]:
                    qmin = float(sasCIFdict[data_block_id]['_sas_p_of_R_details']['qmin'])
                    qmax = float(sasCIFdict[data_block_id]['_sas_p_of_R_details']['qmax'])
                    sIntensity = \
                        [float(x) for x in sasCIFdict[data_block_id]['_sas_scan_intensity']['momentum_transfer']]
                    firstPointIntensity = min(range(len(sIntensity)), key=lambda i: abs(sIntensity[i] - qmin))
                    lastPointIntensity = min(range(len(sIntensity)), key=lambda i: abs(sIntensity[i] - qmax)) + 1
                    sExtrapolated = [float(x) for x in intensityTable[0]]
                    firstPointExtrapolated = \
                        min(range(len(sExtrapolated)), key=lambda i: abs(sExtrapolated[i] - qmin))
                    lastPointExtrapolated = \
                        min(range(len(sExtrapolated)), key=lambda i: abs(sExtrapolated[i] - qmax)) + 1

                    # If the number of points were reduced by GNOM, then regrid
                    # the curve with DATREGRID
                    if not (lastPointIntensity - firstPointIntensity) \
                            == (lastPointExtrapolated - firstPointExtrapolated):
                        datFileInt = open('int.dat', 'w')
                        table = [sasCIFdict[data_block_id]['_sas_scan_intensity']['momentum_transfer'],
                                 sasCIFdict[data_block_id]['_sas_scan_intensity']['intensity'],
                                 sasCIFdict[data_block_id]['_sas_scan_intensity']['intensity_su_counting']]
                        writeDatFile = wsd.saxsdocout()
                        writeDatFile.writeCurves(table, datFileInt)
                        datFileInt.close()
                        datFileExt = open('ext.dat', 'w')
                        writeDatFile = wsd.saxsdocout()
                        writeDatFile.writeCurves(intensityTable, datFileExt)
                        datFileExt.close()
                        call(['datregrid', '-t', 'ext.dat', 'int.dat', '-o', 'intExt.dat'])
                        datFileIntExt = saxsdocument.read('intExt.dat').curve
                        call(['rm', 'ext.dat', 'int.dat', 'intExt.dat'])
                        scatVect = [float('%14E' % value)
                                    for value in list(zip(*datFileIntExt[0])[0])]
                        intensity = [str('%14E' % value)
                                     for value in list(zip(*datFileIntExt[0])[1])]
                        error = [str('%14E' % value)
                                 for value in list(zip(*datFileIntExt[0])[2])]
                        firstPointIntensity = \
                            min(range(len(scatVect)), key=lambda i: abs(scatVect[i] - qmin))
                        lastPointIntensity = \
                            min(range(len(scatVect)), key=lambda i: abs(scatVect[i] - qmax)) + 1
                    else:
                        intensity = sasCIFdict[data_block_id][
                            '_sas_scan_intensity']['intensity']
                        error = sasCIFdict[data_block_id][
                            '_sas_scan_intensity']['intensity_su_counting']

                    tailPoints = (lastPointExtrapolated - firstPointExtrapolated) - \
                        len(intensity[firstPointIntensity:lastPointIntensity])
                    Jexp = [' '] * firstPointExtrapolated + \
                        intensity[firstPointIntensity:lastPointIntensity] + [' '] * tailPoints
                    Error = [' '] * firstPointExtrapolated + \
                        error[firstPointIntensity:lastPointIntensity] + [' '] * tailPoints

                    Jreg = [' '] * firstPointExtrapolated + \
                        sasCIFdict[data_block_id]['_sas_p_of_R_extrapolated_intensity'][
                            'intensity_reg'][firstPointExtrapolated:]

                    intensityTable.insert(1, Jexp)
                    intensityTable.insert(2, Error)
                    intensityTable.insert(3, Jreg)
                    intensityHeader = ['S', 'J EXP', 'ERROR', 'J REG', 'I REG']

                pRTable = [sasCIFdict[data_block_id]['_sas_p_of_R']['r'],
                           sasCIFdict[data_block_id]['_sas_p_of_R']['P'],
                           sasCIFdict[data_block_id]['_sas_p_of_R']['P_error']]

                writeoutfile = wsd.saxsdocout()
                # Write creator&version
                creator, version = sasCIFdict[data_block_id]['_sas_p_of_R_details']['software_p_of_R'].split()
                writeoutfile.writeText(' '.join(creator) + ' Version ' + version + '\n', outfile)
                # Write curves
                writeoutfile.writeCurves(
                    intensityTable, outfile, intensityHeader)
                writeoutfile.writeText('           Distance distribution function of particle  \n', outfile)
                writeoutfile.writeCurves(
                    pRTable, outfile, ['R', 'P(R)', 'ERROR'])
                # Write properties
                propList = [
                    'Rg_from_Guinier', 'I0_from_Guinier', 'Rg_from_PR', 'I0_from_PR']
                propDict = collections.OrderedDict()
                for prop in propList:
                    if prop in sasCIFdict[data_block_id]['_sas_result'].keys():
                        propDict[prop] = sasCIFdict[data_block_id]['_sas_result'][prop]
                writeoutfile.writeProperties(propDict, outfile)
                outfile.close()
Пример #2
0
 def __init__(self, filename, sasCIFdict):
     self.sasfile = saxsdocument.read(filename)
     self.filename = filename
     self.sasCIFdict = sasCIFdict