Example #1
0
  def processpre21(self):
  
    mainPars = self.parFiles['acqus'].parameters
    #
    # Set pulseprogram info
    #
  
    pulseProgram = None  
    if self.parFiles.has_key('pulseprogram'):
      pulseProgram = self.parFiles['pulseprogram']
      ss = pulseProgram.get('name')
      if ss:
        self.pulProgName = ss
  
    refs = {}
    
    #
    # Try get date out
    #
    
    dateInfo = self.parFiles['acqus'].infoStrings[0]
    if dateInfo.count('T '):
      dateString = dateInfo[:dateInfo.index('T ') + 1]
    else:
      dateString = dateInfo[:19].strip()
    
    self.dateString = dateString
    
    #
    # Do quick check for 3D,4D to see if dimension order in filename matches
    # the acqu2s/acqu3s, and switch their info content if necessary.
    #
    # TODO: THIS IS NOT FOOLPROOF! NUC1 for acqu2s, acqu3s not always set to 
    # nucleus used in that dimension! Is so for some setups, though (IE)
    #
    # TODO: ONLY works for 3Ds currently!
    #
    
    if (self.numDim == 3):
    
      if not hasattr(self.parFiles['acqu3s'],'parameters'):
        print "  Illegal number of dimensions!! %s is not a 3d..." % self.fileDir
        return

      if not self.parFiles['acqu3s'].parameters.has_key('NUC1'):

        #
        # No acqu3s file... basically 3D recorded as 2D (or wrong experiment put in..)
        # Assuming that L1, L2 give npts/2, getting as much info as possible from this...
        #

        print "  Warning: no acqu3s file for Bruker 3D experiment."

        pointsProduct = self.parFiles['acqu2s'].parameters['TD'].values[0]

        npts1 =  self.parFiles['acqus'].parameters['L'].values[1]
        npts2 =  self.parFiles['acqus'].parameters['L'].values[2]

        if pointsProduct == (npts1 * npts2 * 4):
        
          print "           assuming L1,L2 give number of complex points."

          # TODO: does it make sense to set this for acqu2/3?
          self.parFiles['acqu3s'].parameters['TD'] = BrukerPar('TD')
          self.parFiles['acqu3'].parameters['TD'] = BrukerPar('TD')


          self.parFiles['acqu2s'].parameters['TD'].values[0] = npts1
          self.parFiles['acqu2'].parameters['TD'].values[0] = self.parFiles['acqu'].parameters['L'].values[1]

          self.parFiles['acqu3s'].parameters['TD'].addValues(1,[npts2])
          self.parFiles['acqu3'].parameters['TD'].addValues(1,[self.parFiles['acqu'].parameters['L'].values[2]])

          #
          # Select appropriate increment per dimension
          # Bit messy... this whole script has to be cleaned up
          # TODO: very nasty to put tk stuff in here... have to:
          #        - Make whole def a class
          """
          incrementList = []

          for value in mainPars['IN'].values:
            incrementList.append(value)  

          popup = IncrementSelect(guiParent,[2,3],incrementList)

          for i in range(0,len(popup.increments)):
            increment = popup.increments[i]
            dim = i + 1

            refs['inc'][dim] = mainPars['IN'].values.index(increment)

            # TODO: nucleus!!!

          popup.destroy()
          """

        else:
        
          print "           cannot handle current case. Contact author."
        
      
    elif (self.numDim > 3):
    
      print "  ERROR: %s had more than 3 dims for acqu<n>s file order (cannot handle this)!" % (self.fileDir)

    #
    # Set increment numbers found in pulse program
    #
    
    refs['inc'] = [-1]

    if pulseProgram and self.numDim <= len(pulseProgram['increment']):
      print "  Warning: %s number of incremented delays found does not match number of dimensions!" % (self.fileDir)
    
    for i in range(0,self.numDim-1):
      if pulseProgram and len(pulseProgram['increment']) > i:
        refs['inc'].append(int(pulseProgram['increment'][i]))
      else:
        refs['inc'].append(i)
    
    #
    # If AQSEQ == 1 and experiment is a 3D, then swap the first two indirect increments 
    # to correspond to the acqu files
    #
    
    if mainPars['AQSEQ'].values[0] == 1 and self.numDim == 3:
      tempInc = refs['inc'][1]
      refs['inc'][1] = refs['inc'][2]
      refs['inc'][2] = tempInc
      print "  Warning: swapped increments for 3D based on AQSEQ setting %d!" % mainPars['AQSEQ'].values[0]
    
    #
    # TODO: Check if acqu<n>s info corresponds to reported nucleus order - reset values if so.
    #
     
    #
    # Make a list of reference values for accessing acqus file
    #
    
    self.setupBrukerRefList()
    nullValue = 'off'

    self.getSpecRefs(mainPars,nullValue)

    #
    # Now set the fid and freq info from the file
    #
    
    for i in range(0,self.numDim):
    
      #
      # Handling depends on which dim (complex points or not)
      #
    
      if i == 0:
        
        acqusPars = mainPars
        acquPars = self.parFiles['acqu'].parameters
        complexFactor = 2.0
      
        #
        # Acquisition dimension always complex
        #
        
        #
        # Spectral width in Hz per dimension and associated increment
        #swText = '(from acqus file)'
        #incText = '(calculated from SW_h, assuming complex)'
        #
        
        swh = float(acqusPars['SW_h'].values[0])        
        valuePerPoint = 1 / swh

      else:
      
        #
        # Try to get info on acquisition mode for dimension...
        #
        
        #currentAcqusFile = self.parFiles['acqu' + str(i+1) + 's']
        acqusPars = self.parFiles['acqu' + str(i+1) + 's'].parameters
        acquPars = self.parFiles['acqu' + str(i+1)].parameters

        if acqusPars.has_key('FnMODE'):
          (fnMode,complexFactor) = self.fnModeDict[acqusPars['FnMODE'].values[0]]
          self.fnModes[i-1] = fnMode
          
        else:
          complexFactor = 2.0
        #
        # Increment (based on values read in from pulseprogram!). Multiplied by 2: assuming complex.
        #incText = "(using IN%s in acqus file)" % brukerrefs['inc'][i]
        #
        
        #
        # TODO: will this cause problems if the acqu2/3s files not switched yet?
        # Keep in mind!!
        #
        
        valuePerPoint = complexFactor * float(mainPars['IN'].values[refs['inc'][i]])

      
      # set nucleus
      #nucleus = mainPars['NUC1'].values[0]
      nucleus = self.convertNucleusCode(acqusPars['NUC1'].values[0])
      self.nuc[i] = nucleus
      # Number of COMPLEX points per dimension.
      
      # set values into parameter arrays
      numPoints = int(acquPars['TD'].values[0]) / 2 
      numPointsValid = int(acqusPars['TD'].values[0]) / 2 
      self.npts[i] = numPoints
      self.numPointsValid[i] = numPointsValid
      self.sw[i] = swhz = numPoints * valuePerPoint
      self.isComplex[i] = (complexFactor != 1.0)
      self.sf[i] = sf = float(acqusPars['SFO1'].values[0])
      self.baseFreq[i] = baseFreq = float(acqusPars['BF1'].values[0])
      # set approx referencing (starting value. Formula from Bruker manual)
      self.refpt[i] = 1.0
      self.refppm[i] = 1.0e6 * (sf / baseFreq - 1.0) + 0.5 * swhz / baseFreq
      
      #
      # Now set the values for the FID
      #

      if numPointsValid > numPoints:

        print "  ERROR: %s has greater number of valid points than actual ones" % (self.fileDir)

      self.fidDimRefs[i] = FidDimReference(numPoints,numPointsValid,
                                           valuePerPoint,nucleus)
      
      #
      # And for the Freq
      #
      (numPoints,numPointsOrig,valuePerPoint) = self.getFreqDimInfo(valuePerPoint,numPointsValid)
      self.freqDimRefs[i] = FreqDimReference(numPoints,numPointsOrig,
                                             valuePerPoint,nucleus)
Example #2
0
    def process(self):

        #
        # Only one file...
        #

        mainPars = self.parFiles['procpar'].parameters

        if mainPars.has_key('nt'):
            self.numScans = returnInt(mainPars['nt'].values[0])
        else:
            print "No num scans for %s" % (self.fileDir)
            self.numScans = 0

        #
        # Get frequencies for nuclei (TODO: REFLIST IN settings?)
        #

        self.refList = [['sfrq', 'tof', 'tn'], ['dfrq', 'dof', 'dn'],
                        ['dfrq2', 'dof2', 'dn2'], ['dfrq3', 'dof3', 'dn3'],
                        ['dfrq4', 'dof4', 'dn4']]
        nullValue = ''

        self.getSpecRefs(mainPars, nullValue, specTypeRef='console')

        refsNp = ['np', 'ni', 'ni2', 'ni3']
        refsSw = ['sw', 'sw1', 'sw2', 'sw3']

        self.fidDimRefs = []
        self.freqDimRefs = []

        for i in range(0, self.numDim):

            if i == 0:

                #
                # Different handling for acquisition dimension!
                # TODO: if data is NOT COMPLEX, take out factor 2!
                # In CCPN data model, npoints is number of COMPLEX points!
                #

                numPoints = mainPars[refsNp[i]].values[0] / 2

            else:

                #
                # Data always complex in indirect? Assuming so...
                # Note that ni, ni2, ... HAS A DIFFERENT DEFINITION than np!!! Is number of COMPLEX points!
                #

                numPoints = mainPars[refsNp[i]].values[0]

            #
            # TODO: this is assumed for Varian
            #

            numPointsValid = numPoints

            #
            # Set sw and increment
            # TODO: If data is NOT COMPLEX, divide valppoint by 2!
            # (one half of spectrum is redundant)
            #

            swh = mainPars[refsSw[i]].values[0]
            valuePerPoint = 1 / swh

            #
            # Set FID info
            #

            self.fidDimRefs.append(
                FidDimReference(numPoints, numPointsValid, valuePerPoint,
                                None))

            #
            # Set freq domain info
            # PROBLEM with acquisition time: Rasmus uses valppoint * (npointsvalid-1)
            # But this doesn't correspond to value from Varian (is valppoint * npointsvalid)
            # WHY? Contact Varian. Have to VERY SPECIFICALLY define these parameters!!!
            # How does this work for Bruker?
            #

            (numPoints, numPointsOrig,
             valuePerPoint) = self.getFreqDimInfo(valuePerPoint,
                                                  numPointsValid)
            self.freqDimRefs.append(
                FreqDimReference(numPoints, numPointsOrig, valuePerPoint,
                                 None))

            #
            # Try to get phasing info (often not correct...)
            #

            refsPhase = 2 * ['']
            refsPhase[0] = ['rp', 'rp1', 'rp2', 'rp3']
            refsPhase[1] = ['lp', 'lp1', 'lp2', 'lp3']

            for po in range(0, 2):
                if mainPars.has_key(refsPhase[po][i]):
                    self.freqDimRefs[-1].phase[po] = mainPars[refsPhase[po]
                                                              [i]].values[0]
                else:
                    print "  ERROR: %s has no phase for %d (dim %d)" % (
                        self.fileDir, po, i)
Example #3
0
  def processv21(self):
    """process function for TOPSPIN versions >= 2.1
    """
    
    # Tolerance for letting SW_h override SW * sf
    swhzTolerance = 0.001
  
    mainPars = self.parFiles['acqus'].parameters
    
    # get date string
    match = self.patt[self.format + "Date"].match(self.parFiles['acqus'].infoStrings[0])
    if match:
      self.dateString = match.group()
    else:
      self.dateString = ""
    self.specRefs = specRefs = {}
    
    # default specType
    specType = None
    
    #get pulProgName:
    if mainPars.has_key('PULPROG'):
      self.pulProgName =  mainPars['PULPROG'].values[0]
    
    # convert data one dimension at a time
    for ii in range(self.numDim):
      
      # set up file names
      if ii == 0:
        acquname = 'acqu'
      else:
        acquname = 'acqu' + str(ii+1)
      acquPars =  self.parFiles[acquname].parameters
      acqusPars =  self.parFiles[acquname + 's'].parameters
      
      # set complexFactor (complex/real handling). 
      # NB assumes acq dim is alwasy complex
      if acqusPars.has_key('FnMODE') and ii != 0:
        (fnMode,complexFactor) = self.fnModeDict[acqusPars['FnMODE'].values[0]]
        self.fnModes[ii-1] = fnMode
      else:
        complexFactor = 2.0
      
      # set 
      self.isComplex[ii] = (complexFactor != 1.0)
      npts = int(acquPars['TD'].values[0])
      if npts != 1:
        # npts == 1 is default for unused/projection dimensions. Keep as ia.
        npts = int(npts/complexFactor)
      self.npts[ii] = npts
      numPointsValid = int(acqusPars['TD'].values[0])/complexFactor
      self.numPointsValid[ii] = numPointsValid
      nucleus = self.convertNucleusCode(acqusPars['NUC1'].values[0])
      self.nuc[ii] = nucleus
      self.sf[ii] = sf = float(acqusPars['SFO1'].values[0])
      self.baseFreq[ii] = baseFreq = float(acqusPars['BF1'].values[0])
      swppm = float(acqusPars['SW'].values[0])
      swhz = swppm * sf
      if acqusPars.has_key('SW_h'):
        # NB SW seems more reliable than SW_h. 
        # Use SW_h only for greater precision where the values fit.
        val = float(acqusPars['SW_h'].values[0])
        if abs(val/swhz - 1.0) < swhzTolerance:
          swhz = val
      self.sw[ii] = swhz
      if numPointsValid > npts:
        print ("  WARNING: %s dim %s has greater number of valid points than actual ones" 
               % (self.fileDir, ii))

      # set approx referencing (starting value. Formula from Bruker manual)
      self.refpt[ii] = 1.0
      self.refppm[ii] = 1.0e6 * (sf / baseFreq - 1.0) + 0.5 * swhz / baseFreq
      
      # set self.specRefs for FormatConverter purposes
      self.specRefs[nucleus] = SpectrometerReference(sf, baseFreq)
      
      #if ii != 0:
      #  from ccp.general.Constants import chemShiftRefRatios
      #  refRatio = chemShiftRefRatios.get(nucleus)
      #  if refRatio is not None:
      #    bf2 = self.baseFreq[0] * refRatio
      #    xx = 1.0e6*(sf/bf2 -1.0)
      #    print '###1', baseFreq, bf2, xx, xx + 0.5*swhz/bf2 - self.refppm[ii]
      #
      #print ('###2', ii, acquname, sf, baseFreq, swhz, swppm, self.refppm[ii], 
      #       1.0e6 * (sf / baseFreq - 1.0),  0.5 * swhz / baseFreq)
      
      # set self.fidDimRefs - for FormatCOnverter use
      timePerPoint = complexFactor / (2.0 * swhz)
      self.fidDimRefs[ii] = FidDimReference(npts, numPointsValid, 
                                            timePerPoint, nucleus)
      
      # set self.freqDimRefs - for FormatConverter use 
      # for setting up future procesasing.
      # For actual processing data read procs (etc.) file
      (nPoints,nPointsOrig,valuePerPoint) = self.getFreqDimInfo(timePerPoint,
                                                                numPointsValid)
      self.freqDimRefs[ii] = FreqDimReference(nPoints, nPointsOrig,
                                              timePerPoint, nucleus)
Example #4
0
    def process(self):

        mainPars = self.parFiles['acqus'].parameters

        pulseProgram = None
        if self.parFiles.has_key('pulseprogram'):
            pulseProgram = self.parFiles['pulseprogram']

        refs = {}

        self.numScans = returnInt(mainPars['NS'].values[0])

        #
        # Try get date out
        #

        dateInfo = self.parFiles['acqus'].infoStrings[0]
        if dateInfo.count('T '):
            dateString = dateInfo[:dateInfo.index('T ') + 1]
        else:
            dateString = ""

        self.dateString = dateString

        #
        # Do quick check for 3D,4D to see if dimension order in filename matches
        # the acqu2s/acqu3s, and switch their info content if necessary.
        #
        # TODO: THIS IS NOT FOOLPROOF! NUC1 for acqu2s, acqu3s not always set to
        # nucleus used in that dimension! Is so for some setups, though (IE)
        #
        # TODO: ONLY works for 3Ds currently!
        #

        if (self.numDim == 3):

            if not hasattr(self.parFiles['acqu3s'], 'parameters'):
                print "  Illegal number of dimensions!! %s is not a 3d..." % self.fileDir
                return

            if not self.parFiles['acqu3s'].parameters.has_key('NUC1'):

                #
                # No acqu3s file... basically 3D recorded as 2D (or wrong experiment put in..)
                # Assuming that L1, L2 give npts/2, getting as much info as possible from this...
                #

                print "  Warning: no acqu3s file for Bruker 3D experiment."

                pointsProduct = self.parFiles['acqu2s'].parameters[
                    'TD'].values[0]

                npts1 = self.parFiles['acqus'].parameters['L'].values[1]
                npts2 = self.parFiles['acqus'].parameters['L'].values[2]

                if pointsProduct == (npts1 * npts2 * 4):

                    print "           assuming L1,L2 give number of complex points."

                    # TODO: does it make sense to set this for acqu2/3?
                    self.parFiles['acqu3s'].parameters['TD'] = BrukerPar('TD')
                    self.parFiles['acqu3'].parameters['TD'] = BrukerPar('TD')

                    self.parFiles['acqu2s'].parameters['TD'].values[0] = npts1
                    self.parFiles['acqu2'].parameters['TD'].values[
                        0] = self.parFiles['acqu'].parameters['L'].values[1]

                    self.parFiles['acqu3s'].parameters['TD'].addValues(
                        1, [npts2])
                    self.parFiles['acqu3'].parameters['TD'].addValues(
                        1, [self.parFiles['acqu'].parameters['L'].values[2]])

                    #
                    # Select appropriate increment per dimension
                    # Bit messy... this whole script has to be cleaned up
                    # TODO: very nasty to put tk stuff in here... have to:
                    #        - Make whole def a class
                    """
          incrementList = []

          for value in mainPars['IN'].values:
            incrementList.append(value)  

          popup = IncrementSelect(guiParent,[2,3],incrementList)

          for i in range(0,len(popup.increments)):
            increment = popup.increments[i]
            dim = i + 1

            refs['inc'][dim] = mainPars['IN'].values.index(increment)

            # TODO: nucleus!!!

          popup.destroy()
          """

                else:

                    print "           cannot handle current case. Contact author."

        elif (self.numDim > 3):

            print "  ERROR: %s had more than 3 dims for acqu<n>s file order (cannot handle this)!" % (
                self.fileDir)

        #
        # Set increment numbers found in pulse program
        #

        refs['inc'] = [-1]

        if pulseProgram and self.numDim <= len(pulseProgram['increment']):
            print "  Warning: %s number of incremented delays found does not match number of dimensions!" % (
                self.fileDir)

        for i in range(0, self.numDim - 1):
            if pulseProgram and len(pulseProgram['increment']) > i:
                refs['inc'].append(int(pulseProgram['increment'][i]))
            else:
                refs['inc'].append(i)

        #
        # If AQSEQ == 1 and experiment is a 3D, then swap the first two indirect increments
        # to correspond to the acqu files
        #

        if mainPars['AQSEQ'].values[0] == 1 and self.numDim == 3:
            tempInc = refs['inc'][1]
            refs['inc'][1] = refs['inc'][2]
            refs['inc'][2] = tempInc
            print "  Warning: swapped increments for 3D based on AQSEQ setting %d!" % mainPars[
                'AQSEQ'].values[0]

        #
        # TODO: Check if acqu<n>s info corresponds to reported nucleus order - reset values if so.
        #

        #
        # Make a list of reference values for accessing acqus file
        #

        self.setupBrukerRefList()
        nullValue = 'off'

        self.getSpecRefs(mainPars, nullValue)

        #
        # Now set the fid and freq info from the file
        #

        self.fidDimRefs = []
        self.freqDimRefs = []

        for i in range(0, self.numDim):

            #
            # Handling depends on which dim (complex points or not)
            #

            if i == 0:

                #
                # Acquisition dimension always complex
                #

                #
                # Number of COMPLEX points per dimension.
                #

                numPoints = int(
                    self.parFiles['acqu'].parameters['TD'].values[0]) / 2
                numPointsValid = int(mainPars['TD'].values[0]) / 2

                #
                # Spectral width in Hz per dimension and associated increment
                #swText = '(from acqus file)'
                #incText = '(calculated from SW_h, assuming complex)'
                #

                swh = float(mainPars['SW_h'].values[0])
                valuePerPoint = 1 / swh

                #
                # Keep nucleus info
                #

                nucleus = mainPars['NUC1'].values[0]

            else:

                #
                # Try to get info on acquisition mode for dimension...
                #

                currentAcqusFile = self.parFiles['acqu' + str(i + 1) + 's']

                if currentAcqusFile.parameters.has_key('FnMODE'):
                    (fnMode, complexFactor) = self.fnModeDict[
                        currentAcqusFile.parameters['FnMODE'].values[0]]
                    self.fnModes[i - 1] = fnMode

                else:
                    complexFactor = 2.0

                #
                # Number of COMPLEX points per dimension.
                #

                numPoints = int(self.parFiles['acqu' + str(i + 1)].
                                parameters['TD'].values[0]) / complexFactor
                numPointsValid = int(currentAcqusFile.parameters['TD'].
                                     values[0]) / complexFactor

                #
                # Increment (based on values read in from pulseprogram!). Multiplied by 2: assuming complex.
                #incText = "(using IN%s in acqus file)" % brukerrefs['inc'][i]
                #

                #
                # TODO: will this cause problems if the acqu2/3s files not switched yet?
                # Keep in mind!!
                #

                valuePerPoint = complexFactor * float(
                    mainPars['IN'].values[refs['inc'][i]])

                #print
                #print "COMPARE"
                #print "  ", valuePerPoint, refs['inc'][i]
                #print "  ", 1 / currentAcqusFile.parameters['SW_h'].values[0]
                #print
                # swh not calculated here? If it is, use that?

            #
            # Now set the values for the FID
            #

            if numPointsValid > numPoints:

                print "  ERROR: %s has greater number of valid points than actual ones" % (
                    self.fileDir)

            self.fidDimRefs.append(
                FidDimReference(numPoints, numPointsValid, valuePerPoint,
                                nucleus))

            #
            # And for the Freq
            #

            (numPoints, numPointsOrig,
             valuePerPoint) = self.getFreqDimInfo(valuePerPoint,
                                                  numPointsValid)
            self.freqDimRefs.append(
                FreqDimReference(numPoints, numPointsOrig, valuePerPoint,
                                 nucleus))

            #
            # Phase is automatically set to 0.0 each
            # TODO: Could in principle access Bruker procpars for this
            #

        #
        # Special additions
        #

        if mainPars.has_key('AQ_mod'):

            acqModeCode = mainPars['AQ_mod'].values[0]
            self.acqMode = 'QSIM'

            if acqModeCode == 3:
                self.acqMode = 'DQD'

                for par in ('DECIM', 'DSPFVS'):
                    if mainPars.has_key(par):
                        self.acqModeValues[par] = mainPars[par].values[0]

            elif acqModeCode == 1:
                pass

            else:
                print "ERROR: Bruker AQ_mod %d not recognized. Using QSIM." % acqModeCode

        #
        # Reset specType if DQD data (must be DMX or higher)
        #

        if mainPars.has_key('DECIM'):
            for nucleus in self.specRefs.keys():
                self.specRefs[nucleus].setSpecType('DMX')