def CH(CNCT, plH, plC, SPX, SPY, Unit):
    pul.SetPar('pCH', CNCT, "")
    pul.SetPar('aHch', plH, Unit)
    pul.SetPar('aCch', plC, Unit)
    pul.SetPar('sHch', SPX, "")
    pul.SetPar('sCch', SPY, "")
    return
def hhC(CNCT, plH, plC, SPX, SPY, Unit):
    pul.SetPar('phhC', CNCT, "")
    pul.SetPar('aHhhc', plH, Unit)
    pul.SetPar('aChhc', plC, Unit)
    pul.SetPar('sHhhc', SPX, "")
    pul.SetPar('sChhc', SPY, "")
    return
def HN(CNCT, plH, plX, SPH, SPX, Unit):
    pul.SetPar('pHN', CNCT, "")
    pul.SetPar('aHhn', plH, Unit)
    pul.SetPar('aNhn', plX, Unit)
    pul.SetPar('sHhn', SPH, "")
    pul.SetPar('sNhn', SPX, "")
    return
def HC(CNCT, plH, plX, SPH, SPX, Unit):
    pul.SetPar('pHC', CNCT, "")
    pul.SetPar('aHhc', plH, Unit)
    pul.SetPar('aChc', plX, Unit)
    pul.SetPar('sHhc', SPH, "")
    pul.SetPar('sChc', SPX, "")
    return
def NH2(CNCT, plH, plX, SPH, SPX, Unit):
    pul.SetPar('pNH2', CNCT, "")
    pul.SetPar('aHnh2', plH, Unit)
    pul.SetPar('aNnh2', plX, Unit)
    pul.SetPar('sHnh2', SPH, "")
    pul.SetPar('sNnh2', SPX, "")
    return
def CH2(CNCT, plH, plX, SPH, SPX, Unit):
    pul.SetPar('pCH2', CNCT, "")
    pul.SetPar('aHch2', plH, Unit)
    pul.SetPar('aCch2', plX, Unit)
    pul.SetPar('sHch2', SPH, "")
    pul.SetPar('sCch2', SPX, "")
    return
def NH(CNCT, plH, plN, SPX, SPY, Unit):
    pul.SetPar('pNH', CNCT, "")
    pul.SetPar('aHnh', plH, Unit)
    pul.SetPar('aNnh', plN, Unit)
    pul.SetPar('sHnh', SPX, "")
    pul.SetPar('sNnh', SPY, "")
    return
Example #8
0
def HN(MAS0, MAS, units):

    p90H = pul.GetPar('pH90', "")
    ampH = pul.GetPar('aH', units)
    SPH = pul.GetPar('sHhn', "")
    ampHCP = pul.GetPar('aHhn', units)
    avgH = 1.0

    p90X = pul.GetPar('pN90', "")
    ampX = pul.GetPar('aN', units)
    SPX = pul.GetPar('sNhn', "")
    ampXCP = pul.GetPar('aNhn', units)
    avgX = 1.0

    CNCT = pul.GetPar('pHN', "")

    params = TopCmds.INPUT_DIALOG("HN CP MAS adjustment", "Proton Nitrogen Cross Polarization", \
    ["Old MAS rate","New MAS rate","Old 1H power ("+pul.pulDict['aHhc']+")",\
    "Old 15N power ("+pul.pulDict['aNhn']+")","Contact Time ("+pul.pulDict['pHN']+")",\
    "H-Ramp ("+pul.pulDict['sHhc']+")","N-Ramp ("+pul.pulDict['sChc']+")"],\
    [str(MAS0),str(MAS),str(ampXCP),str(ampHCP),str(CNCT),SPH,SPX],\
    ["Hz","Hz",units,units,"us","",""],\
    ["1","1","1","1","1","1","1"],\
    ["Accept","Close"], [spc,ret], 10)

    if params == None: TopCmds.EXIT()

    if units == "W":
        params[2] = str(Setup.WtodB(float(params[2])))
        params[3] = str(Setup.WtodB(float(params[3])))
        ampH = Setup.WtodB(ampH)
        ampX = Setup.WtodB(ampX)

    if SPH != "None" and SPH != None and SPH != "Unused":
        avgH = IntShape.Integrate(SPH) / 100.
    if SPX != "None" and SPX != None and SPX != "Unused":
        avgX = IntShape.Integrate(SPX) / 100.

    pulses = p90H, ampH, p90X, ampX, avgH, avgX

    SelectorText="Adjust the HN CP parameters:","Calculate New Match for:",\
    ["Proton","Nitrogen","Maximum for Both"]

    ampHCP, ampXCP = FindMatch(params, pulses, SelectorText)

    if units == "W":
        ampXCP = Setup.dBtoW(ampXCP)
        ampHCP = Setup.dBtoW(ampHCP)

    value = TopCmds.SELECT("Adjusting the HN CP parameters:",\
    "This will set\n 1H power to:  " + str('%3.2f' %ampHCP)+ " "+units+"\n \
  15N power to:  "                     +str('%3.2f' %ampXCP) + " "+units,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aHhn', ampHCP, units)
        pul.SetPar('aNhn', ampXCP, units)
        pul.SetPar('pHN', CNCT, "")
        pul.SetPar('sHhn', SPH, "")
        pul.SetPar('sNhn', SPX, "")
def Phases(Phase):
    pul.SetPar('PHC0', Phase[0], "")
    pul.SetPar('PHC1', Phase[1], "")
    #Reload so everything updates.
    TopCmds.SLEEP(0.05)
    TopCmds.RE(TopCmds.CURDATA())
    TopCmds.SLEEP(0.05)
    return
Example #10
0
def PutPars(p90H, ampH, p90C, ampC, p90N, ampN, MAS, units):

    pul.SetPar('pH90', p90H, "")
    pul.SetPar('pC90', p90C, "")
    pul.SetPar('pN90', p90N, "")
    pul.SetPar('pH180', 2 * p90H, "")
    pul.SetPar('pC180', 2 * p90C, "")
    pul.SetPar('pN180', 2 * p90N, "")
    pul.SetPar('aH', ampH, units)
    pul.SetPar('aC', ampC, units)
    pul.SetPar('aN', ampN, units)
    pul.SetPar('MAS', MAS, "")
Example #11
0
def SPC5_2(units):
    p90 = pul.GetPar('pC90', "")
    amp = pul.GetPar('aC', units)
    MAS = pul.GetPar('MAS', "")

    if units == "W":
        amp = WtodB(amp)

    MaxB1 = 1000000. / 4. / p90
    C5B1 = 5.0 * MAS
    adjust = 20 * (math.log10(C5B1 / MaxB1))
    Condition = amp - adjust

    if units == "W":
        Condition = dBtoW(Condition)

    pul.SetPar('aCc5', Condition, units)
    pul.SetPar('lC5', "10", "")
Example #12
0
def DDec(units):

    dfltWv = "garp"
    dfltB0 = 15.0
    dfltPH = 90.0
    aOption = ['aDdec']
    aFaults = ['aHdec', 'aHdec2', 'aHdec3', 'aNdec', 'aCdec']

    pulse = CalDec('pD90', 'aD', 'prgDDec', "2H", units, dfltWv, dfltB0,
                   dfltPH, aOption, aFaults)

    if pulse[0] == 'pcpd':
        for i in range(len(Nucs)):
            if Nucs[i] == '2H': pcpd = "PCPD " + str(i + 1)
        if pcpd != None: pul.SetPar(pcpd, pulse[1], "")
    if pulse[0] == 'p31':
        pul.SetPar("P31", pulse[1], "")
        pul.SetPar("P30", pulse[1], "")
    if pulse[0] == 'p62':
        pul.SetPar("P61", pulse[1], "")
        pul.SetPar("P62", pulse[1], "")
Example #13
0
def HDec(units):

    dfltWv = "tppm15"
    dfltB0 = 75.0
    dfltPH = 170.0
    aOption = ['aHdec', 'aHdec2', 'aHdec3']
    aFaults = ['aNdec']

    pulse = CalDec('pH90', 'aH', 'prgHDec', "1H", units, dfltWv, dfltB0,
                   dfltPH, aOption, aFaults)

    if pulse[0] == 'pcpd':
        for i in range(len(Nucs)):
            if Nucs[i] == '1H': pcpd = "PCPD " + str(i + 1)
        if pcpd != None: pul.SetPar(pcpd, pulse[1], "")
    if pulse[0] == 'p31':
        pul.SetPar("P31", pulse[1], "")
        pul.SetPar("P30", pulse[1], "")
    if pulse[0] == 'p62':
        pul.SetPar("P61", pulse[1], "")
        pul.SetPar("P62", pulse[1], "")
Example #14
0
def name_confirm(Ttot,RIRO,Sc,Del,Bet,key):
   Name = "DRM_" + str('%.0f'%Sc) +"Sc_"+str('%.0f'%Del)+"D_"+str('%.0f'%Bet)+"B.wave"
   SP=pul.pulDict[key]
   
   index=TopCmds.INPUT_DIALOG("DREAM Files", "", \
   ["File = ","Wave =",],[Name,SP],["",""],["1","1"],\
   ["Accept","Close"], [spc,ret], 30)

   if index == None:TopCmds.EXIT()

   pul.SetPar(key,index[0],"")

   return index[0]
def NCO(CNCT, plH, plC, plN, SPX, SPY, Unit):
    pul.SetPar('pNCO', CNCT, "")
    pul.SetPar('aHnco', plH, Unit)
    pul.SetPar('aNnco', plN, Unit)
    pul.SetPar('aCnco', plC, Unit)
    pul.SetPar('sCnco', SPX, "")
    pul.SetPar('sNnco', SPY, "")
    return
Example #16
0
def SPC5(MASR, MAS, units):

    oldC5 = pul.GetPar('aCc5', units)
    LoopC5 = pul.GetPar('lC5', "")

    index = TopCmds.INPUT_DIALOG("SPC5 MAS", "SPC5 changes for MAS change", \
    ["Old MAS rate","New MAS rate","Old 13C power ("+pul.pulDict['aCc5']+")",\
    "Mixing Loop ("+pul.pulDict['lC5']+")"],\
    [str(MASR),str(MAS),str(oldC5),str(LoopC5)],\
    ["kHz","kHz",units,""],\
    ["1","1","1","1"],\
    ["Accept","Close"], [spc,ret], 10)

    if index == None: TopCmds.EXIT()

    OldMAS = float(index[0])
    NewMAS = float(index[1])
    oldC = float(index[2])
    newL = float(index[3])

    if units == "W":
        oldC = Setup.WtodB(oldC)

    adjust = 20 * (math.log10(NewMAS / OldMAS))
    newC = oldC - adjust

    if units == "W":
        newC = Setup.dBtoW(newC)

    value = TopCmds.SELECT("Adjusting the SPC5 parameters:",\
    "This will set\n 13C power "+pul.pulDict['aCc5']+" to:  " +\
    str('%3.2f' %newC)+ " "+units+"\n"+\
    "Loop "+pul.pulDict['lC5']+" to:  "+ str(newL)\
    ,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aCc5', newC, units)
        pul.SetPar('lC5', newL, "")
Example #17
0
def CPdec(amp, units, In, Out):
    """
  amp   : dict key for CP decoupling amp     
  units : Watts (W) or decibel (dB)
  In    : Title, Subtitle, and Label for Input Dialog
  Out   : Title and Label for Selection/Confirmation Window
  """

    P90 = pul.GetPar('pH90', "")

    Amp90 = pul.GetPar('aH', "dB")
    AmpD0 = pul.GetPar(amp, "dB")

    MaxB1D = 1000000. / 4. / P90

    B1_0 = MaxB1D * (math.pow(10, (Amp90 - AmpD0) / 20.))

    if B1_0 > 100.: Dcond = '% .1f' % B1_0
    if B1_0 > MaxB1D: Dcond = '85000.0'
    if B1_0 <= 100.: Dcond = '85000.0'
    Val = [str('%3.3f' % (float(Dcond) / 1000.))]

    index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\
      Val,["kHz"],["1"],\
      ["Accept","Close"], [spc,ret], 10)

    if index == None:
        TopCmds.EXIT()

    #Safety
    Damp = DecSafely(1000. * float(index[0]), amp, MaxB1D, 150000., Amp90,
                     units)

    if units == "W":
        Damp = dBtoW(Damp)

    value = TopCmds.SELECT(Out[0],"This will set\n "+\
      Out[1]+" power to:  " + str('%3.2f' %Damp)+" "+ units,\
      ["Update", "Keep Previous"],[spc,ret])

    if value != 1:
        pul.SetPar(amp, Damp, units)

    return
Example #18
0
def MakeRamp(Scale, Delta, Beta, Nuc):

   MAS =pul.GetPar('MAS',"")
   TauR=float(1000000/MAS)
   
   if Nuc=="1H" :
     MaxB1=1000./4./(pul.GetPar('pH90',""))
     Amp=pul.GetPar('aH','dB')
     Time=pul.GetPar('pHdrm',"")
     TimeKey='pHdrm'
     key='sHdrm'
   if Nuc=="13C":
     MaxB1=1000./4./(pul.GetPar('pC90',""))
     Amp=pul.GetPar('aC','dB')
     Time=pul.GetPar('pCdrm',"")
     TimeKey='pCdrm'
     key='sCdrm'

   PctScal=Scale/MaxB1
   PctRamp=2.*Delta/MaxB1
   PctAdia=Beta/MaxB1
   
   Index = TopCmds.INPUT_DIALOG("DREAM RAMP", "", \
   ["Total Contact","Read-In/Out","Ampl","Ramp","Adiabicity"],\
   [str(Time/1000.),str( '%3.2f' % (2*TauR)),str('%3.1f'%(Scale/1000.)),\
   str('%3.1f'%(Delta/1000.)),str('%3.1f' % Beta)],\
   ["ms"           ,"us"         ,"kHz" ,"+/- kHz","Hz"],\
   ["1"            ,"1"          ,"1"   ,"1"      ,"1"],\
   ["Accept","Close"], [spc,ret], 10)
   if Index == None:TopCmds.EXIT()
   
   PctAmpl=100.*float(Index[2])/MaxB1
   PctDel=PctAmpl*float(Index[3])
   PctBet=float(Index[2])*float(Index[4])/MaxB1/10.
   
   Name=name_confirm(Index[0],Index[1],str(PctAmpl),str(PctDel),str(PctBet),key)
   make(Index[0],Index[1],str(PctAmpl),str(PctRamp),PctBet,Name,key)

   pul.SetPar(TimeKey,1000.*float(Index[0]),"")
   
   return Name, Index[0]
Example #19
0
def DDec(units):

    Stuff = []
    p90 = pul.GetPar('pD90', "")
    amp = pul.GetPar('aD', units)
    CPD = pul.GetPar('prgDDec', "")
    MaxB1 = 1000000. / 4. / p90

    if units == "W":
        amp = WtodB(amp)

    if CPD == "mlev" or CPD == "None":
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['prgDDec']))
        CPD = pul.GetPar('prgDDec', "")

    Stuff = CPDtools.CPDparse(CPD, "2H")
    amp0 = CPDtools.Find_old_pl(Stuff[0])
    decpw0 = CPDtools.Find_old_pw(Stuff[1], "2H")

    B1_0 = MaxB1 * (math.pow(10, (amp - amp0) / 20.)) / 1000.
    if B1_0 > 1.: B1out = '% .1f' % B1_0
    if B1_0 <= 1.: B1out = '15.0'

    index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Decoupling Window", \
    ["Desired 2H Decoupling Amplitude","File"],\
    [B1out,CPD],["kHz",""],["1","1",],\
    ["Accept","Close"], ['a','c'], 10)

    pul.SetPar('aDdec', index[1], "")
    adjust = 20 * (math.log10(1000. * float(index[0]) / MaxB1))
    ampli = amp - adjust
    decpw = (MaxB1 / 1000. / float(index[0])) * 2 * p90

    if units == "W":
        ampli = dBtoW(ampli)

    value = TopCmds.SELECT("Adjusting the 2H decoupling parameters:",\
    "This will set\n 2H power ("+ Stuff[0] +") to:  "+ str('%3.2f' %ampli)+" "+ units+"\n \
  Pulse width ("                  + Stuff[1] +"= 180deg) to:  " +str('%3.2f' %decpw) + " us",["Update", "Keep Previous"])

    if value != 1:
        pl = ""
        if Stuff[0] != "": pl = pul.pp_2_xcmd(Stuff[0], "")

        if pl == "":
            pul.SetPar('aDdec', ampli, units)
        elif pl == pul.pulDict['aDdec']:
            pul.SetPar('aDdec', ampli, units)
        elif pl == pul.pulDict['aHdec']:
            DecError('aHdec', "13C")
        elif pl == pul.pulDict['aHdec2']:
            DecError('aHdec2', "13C")
        elif pl == pul.pulDict['aHdec3']:
            DecError('aHdec3', "13C")

        if Stuff[1] == 'pcpd':
            pul.SetPar("PCPD 3", decpw, "")
        elif Stuff[1] == 'p31':
            pul.SetPar("P31", decpw, "")
            pul.SetPar("P30", decpw, "")
        elif Stuff[1] == 'p62':
            pul.SetPar("P61", decpw, "")
            pul.SetPar("P62", decpw, "")
Example #20
0
def HDec(units):

    Stuff = []
    p90 = pul.GetPar('pH90', "")
    amp = pul.GetPar('aH', units)
    CPD = pul.GetPar('prgHDec', "")
    MaxB1 = 1000000. / 4. / p90

    if CPD == "mlev" or CPD == "None":
        pul.SetPar('prgHDec', "tppm15", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['prgHDec']))
        CPD = pul.GetPar('prgHDec', "")

    TopCmds.MSG(str(CPD) + " CPD")

    Stuff = CPDtools.CPDparse(CPD, "1H")
    TopCmds.MSG(str(Stuff) + " Stuff")
    amp0 = CPDtools.Find_old_pl(Stuff[0], units)
    TopCmds.MSG(str(amp0) + " amp0")

    if units == "W":
        amp = WtodB(amp)
        amp0 = WtodB(amp0)

    decpw0 = CPDtools.Find_old_pw(Stuff[1], "1H")

    B1_0 = MaxB1 * (math.pow(10, (amp - amp0) / 20.)) / 1000.
    if B1_0 > 1.: B1out = '% .1f' % B1_0
    if B1_0 > MaxB1 / 1000.: B1out = '75.0'
    if B1_0 <= 1.: B1out = '75.0'

    index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Decoupling Window", \
    ["Desired 1H Decoupling Amplitude","File"],\
    [B1out,CPD],["kHz",""],["1","1",],\
    ["Accept","Close"], ['a','c'], 10)

    pul.SetPar('prgHDec', index[1], "")

    adjust = 20 * (math.log10(1000. * float(index[0]) / MaxB1))
    Hamp = amp - adjust
    decpwH = (MaxB1 / 1000. / float(index[0])) * (170. / 180.) * 2 * p90

    if units == "W":
        Hamp = dBtoW(Hamp)

    value = TopCmds.SELECT("Adjusting the H decoupling parameters:",\
    "This will set\n 1H power ("+ Stuff[0] +") to:  "+ str('%.2f' %Hamp)+" "+ units+"\n \
  Pulse width ("                  + Stuff[1] +") to:  " +str('%3.2f' %decpwH)+" us",["Update", "Keep Previous"])

    if value != 1:
        pl = ""
        if Stuff[0] != "": pl = pul.pp_2_xcmd(Stuff[0], "")

        if pl == pul.pulDict['aHdec']:
            pul.SetPar('aHdec', Hamp, units)
        elif pl == pul.pulDict['aHdec2']:
            pul.SetPar('aHdec2', Hamp, units)
        elif pl == pul.pulDict['aHdec3']:
            pul.SetPar('aHdec3', Hamp, units)

        if Stuff[1] == 'pcpd':
            pul.SetPar("PCPD 2", decpwH, "")
        elif Stuff[1] == 'p31':
            pul.SetPar("P31", decpwH, "")
            pul.SetPar("P30", decpwH, "")
        elif Stuff[1] == 'p62':
            pul.SetPar("P61", decpwH, "")
            pul.SetPar("P62", decpwH, "")
Example #21
0
def NCO(units):
    p90H = pul.GetPar('pH90', "")
    p90C = pul.GetPar('pC90', "")
    p90N = pul.GetPar('pN90', "")
    ampH = pul.GetPar('aH', units)
    ampC = pul.GetPar('aC', units)
    ampN = pul.GetPar('aN', units)
    MAS = pul.GetPar('MAS', "")
    CNCT = pul.GetPar('pNCO', "")
    SPX = pul.GetPar('sCnco', "")
    SPY = pul.GetPar('sNnco', "")

    #TopCmds.MSG(str(CNCT))
    MaxB1H = 1000000. / 4. / p90H

    if units == "W":
        ampN = WtodB(ampN)
        ampC = WtodB(ampC)
        ampH = WtodB(ampH)

    if CNCT <= 1.: CNCT = 3500.
    if SPX == "gauss" or SPX == "None" or SPX == "" or SPX == "0":
        pul.SetPar('sCnco', "ramp.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sCnco']))
        SPX = pul.GetPar('sCnco', "")
    if SPY == "gauss" or SPY == "None" or SPY == "" or SPY == "0":
        pul.SetPar('sNnco', "ramp.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sNnco']))
        SPY = pul.GetPar('sNnco', "")

    MaxB1N = 1000000. / 4. / p90N
    MaxB1C = 1000000. / 4. / p90C
    #find the channel with the lowest B1
    NCond = (5. / 2.) * MAS
    CCond = (7. / 2.) * MAS

    while NCond > MaxB1N:
        NCond = NCond - MAS
        CCond = NCond + MAS

    while CCond > MaxB1C:
        NCond = NCond - MAS
        CCond = NCond + MAS

    if NCond < MAS:
        NCond = 0.25 * MAS
        CCond = 0.75 * MAS

    index = TopCmds.INPUT_DIALOG("NCO CP Input", "N-CO  SPECIFIC 7/2*C; 5/2*N", \
    ["CO B1 field","N B1 field","H B1 decoupler","Contact Time","Carbon Ramp","Nitrogen Ramp"],\
    [str(CCond),str(NCond),"85000.0",str(CNCT),SPX,SPY],\
    ["Hz","Hz","Hz","us","",""],\
    ["1","1","1","1","1","1"],\
    ["Accept","Close"], ['a','c'], 10)

    adjust = 20 * (math.log10(float(index[0]) / MaxB1C))
    Camp = ampC - adjust
    adjust = 20 * (math.log10(float(index[1]) / MaxB1N))
    Namp = ampN - adjust
    adjust = 20 * (math.log10(float(index[2]) / MaxB1H))
    Hamp = ampH - adjust

    CNCT = float(index[3])

    #Insert ramp calibration here
    if SPX == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[4]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Camp = Camp - adjust

    if SPY == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[5]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Namp = Namp - adjust

    if units == "W":
        Namp = dBtoW(Namp)
        Camp = dBtoW(Camp)
        Hamp = dBtoW(Hamp)

    value = TopCmds.SELECT("Adjusting the NCO CP parameters:",\
    "This will set\n \
  13C power to:  "                     + str('%3.2f' %Camp) + " " + units +"\n \
  15N power to:  "                     + str('%3.2f' %Namp) + " " + units +"\n \
  1H power to:   "                     + str('%3.2f' %Hamp) + " " + units,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aNnco', Namp, units)
        pul.SetPar('aCnco', Camp, units)
        pul.SetPar('aHnco', Hamp, units)
        pul.SetPar('pNCO', CNCT, "")
        if SPX != "Unused":
            pul.SetPar('sCnco', index[4], "")
        if SPY != "Unused":
            pul.SetPar('sNnco', index[5], "")
Example #22
0
def HN(units):
    p90H = pul.GetPar('pH90', "")
    p90N = pul.GetPar('pN90', "")
    ampH = pul.GetPar('aH', units)
    ampN = pul.GetPar('aN', units)
    MAS = pul.GetPar('MAS', "")
    CNCT = pul.GetPar('pHN', "")
    SPH = pul.GetPar('sHhn', "")
    SPX = pul.GetPar('sNhn', "")

    if units == "W":
        ampH = WtodB(ampH)
        ampN = WtodB(ampN)

    if CNCT <= 1.: CNCT = 1000.

    if SPH == "gauss" or SPH == "None" or SPH == "" or SPH == "0":
        pul.SetPar('sHhn', "ramp.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sHhn']))
        SPH = pul.GetPar('sHhn', "")

    if SPX == "gauss" or SPX == "None" or SPX == "" or SPX == "0":
        pul.SetPar('sNhn', "square.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sNhn']))
        SPX = pul.GetPar('sNhn', "")

    MaxB1H = 1000000. / 4. / p90H
    MaxB1N = 1000000. / 4. / p90N

    #find the channel with the lowest B1
    if MaxB1N < MaxB1H:
        Ratio = int(math.floor(MaxB1N / MAS))
        NCond = (Ratio - 0.5) * MAS
        HCond = (Ratio + 0.5) * MAS

        if HCond > MaxB1H:
            Ratio = Ratio - 1
            NCond = (Ratio - 0.5) * MAS
            HCond = (Ratio + 0.5) * MAS

        # If spinning very fast or using weak B1s
        if Ratio <= 1:
            NCond = .25 * MAS
            HCond = .75 * MAS

    if MaxB1N >= MaxB1H:
        Ratio = int(math.floor(MaxB1H / MAS))
        HCond = (Ratio - 0.5) * MAS
        NCond = (Ratio + 0.5) * MAS

        if NCond > MaxB1N:
            Ratio = Ratio - 1
            HCond = (Ratio - 0.5) * MAS
            NCond = (Ratio + 0.5) * MAS

        # If spinning very fast or using weak B1s
        if Ratio <= 1:
            NCond = .25 * MAS
            HCond = .75 * MAS

    adjust = 20 * (math.log10(NCond / MaxB1N))
    Namp = ampN - adjust
    adjust = 20 * (math.log10(HCond / MaxB1H))
    Hamp = ampH - adjust

    index = TopCmds.INPUT_DIALOG("HN CP Input", "Proton Nitrogen Cross Polarization", \
    ["Proton B1 Field","H Ramp","Nitrogen B1 Field","N Ramp","Contact Time(P25)"],\
    [str(HCond),SPH,str(NCond),SPX,str(CNCT)],\
    ["Hz","","Hz","","us"],\
    ["1","1","1","1","1"],\
    ["Accept","Close"], ['a','c'], 10)

    adjust = 20 * (math.log10(float(index[0]) / MaxB1H))
    Hamp1 = ampH - adjust
    if SPH == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[1]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Hamp = Hamp1 - adjust

    adjust = 20 * (math.log10(float(index[2]) / MaxB1N))
    Namp = ampN - adjust
    if SPX == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[3]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Namp = Namp - adjust

    CNCT = float(index[4])

    #TopCmds.MSG("Adjusting the HC CP parameters:\n Your Proton Amplitude is set to " + str('%3.2f' %Hamp)+ "dB\n Your Nitrogen Ammplitude is set to " +str('%3.2f' %Namp))

    if units == "W":
        Hamp = dBtoW(Hamp)
        Namp = dBtoW(Namp)

    value = TopCmds.SELECT("Adjusting the HN CP parameters:",\
    "This will set\n 1H power to:  " + str('%3.2f' %Hamp)+" "+ units+"\n \
  15N power to:  "                     +str('%3.2f' %Namp) + units,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aHhn', Hamp, units)
        pul.SetPar('aNhn', Namp, units)
        pul.SetPar('pHN', CNCT, "")
        if SPH != "Unused":
            pul.SetPar('sHhn', index[1], "")
        if SPX != "Unused":
            pul.SetPar('sNhn', index[3], "")
Example #23
0
def HC(units):
    p90H = pul.GetPar('pH90', "")
    p90C = pul.GetPar('pC90', "")
    ampH = pul.GetPar('aH', units)
    ampC = pul.GetPar('aC', units)
    MAS = pul.GetPar('MAS', "")
    CNCT = pul.GetPar('pHC', "")
    SPH = pul.GetPar('sHhc', "")
    SPX = pul.GetPar('sChc', "")

    if units == "W":
        ampH = WtodB(ampH)
        ampC = WtodB(ampC)

    if CNCT <= 1.: CNCT = 1000.

    if SPH == "gauss" or SPH == "None" or SPH == "" or SPH == "0":
        pul.SetPar('sHhc', "ramp.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sHhc']))
        SPH = pul.GetPar('sHhc', "")

    if SPX == "gauss" or SPX == "None" or SPX == "" or SPX == "0":
        pul.SetPar('sChc', "square.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict['sChc']))
        SPX = pul.GetPar('sChc', "")

    MaxB1H = 1000000. / 4. / p90H
    MaxB1C = 1000000. / 4. / p90C

    #find the channel with the lowest B1
    if MaxB1C < MaxB1H:
        Ratio = int(math.floor(MaxB1C / MAS))
        CCond = (Ratio - 0.5) * MAS
        HCond = (Ratio + 0.5) * MAS

        if HCond > MaxB1H:
            Ratio = Ratio - 1
            CCond = (Ratio - 0.5) * MAS
            HCond = (Ratio + 0.5) * MAS

        # If spinning very fast or using weak B1s
        if Ratio <= 1:
            CCond = .25 * MAS
            HCond = .75 * MAS

    if MaxB1C >= MaxB1H:
        Ratio = int(math.floor(MaxB1H / MAS))
        HCond = (Ratio - 0.5) * MAS
        CCond = (Ratio + 0.5) * MAS

        if CCond > MaxB1C:
            Ratio = Ratio - 1
            HCond = (Ratio - 0.5) * MAS
            CCond = (Ratio + 0.5) * MAS

        # If spinning very fast or using weak B1s
        if Ratio <= 1:
            CCond = .75 * MAS
            HCond = .25 * MAS

    adjust = 20 * (math.log10(CCond / MaxB1C))
    Camp = ampC - adjust
    adjust = 20 * (math.log10(HCond / MaxB1H))
    Hamp = ampH - adjust

    index = TopCmds.INPUT_DIALOG("HC CP Input", "Proton Carbon Cross Polarization", \
    ["Proton B1 Field","H Ramp","Carbon B1 Field","C Ramp","Contact Time(P15)"],\
    [str(HCond),str(SPH),str(CCond),str(SPX),str(CNCT)],\
    ["Hz","","Hz","","us"],\
    ["1","1","1","1","1"],\
    ["Accept","Close"], ['a','c'], 10)

    adjust = 20 * (math.log10(float(index[0]) / MaxB1H))
    Hamp1 = ampH - adjust
    if SPH == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[1]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Hamp = Hamp1 - adjust

    adjust = 20 * (math.log10(float(index[2]) / MaxB1C))
    Camp1 = ampC - adjust
    if SPX == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[3]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Camp = Camp1 - adjust

    CNCT = float(index[4])

    if units == "W":
        Hamp = dBtoW(Hamp)
        Camp = dBtoW(Camp)

    value = TopCmds.SELECT("Adjusting the HC CP parameters:",\
    "This will set\n 1H power to:  " + str('%3.2f' %Hamp)+" "+ units+"\n \
  13C power to:  "                     +str('%3.2f' %Camp) + " "+units,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aHhc', Hamp, units)
        pul.SetPar('aChc', Camp, units)
        pul.SetPar('pHC', CNCT, "")
        if SPH != "Unused":
            pul.SetPar('sHhc', index[1], "")
        if SPX != "Unused":
            pul.SetPar('sChc', index[3], "")
def CalBSH(p90, ppm, amp, ampD, Cnct, shp, dfltramp, pflp, pflp2k, units, In,
           Out):
    """
  p90   : Dictionary Key for Nucleus 90 degree pulse; determines Nuc (Decoupling flag)
  ppm   : float of ppm difference
  amp   : dict key for CP amp
  ampD  : dict key for Decoupler (assumed to be 1H) or "empty"
  Cnct  : dict key for CP contact
  shp   : dict key of CP shape file
  dfltshp: Default pulse shape
  pflp  : dict key for trim pulse
  pflp2k: dict key for flip back pulse
  units : Watts (W) or decibel (dB)
  In    : Title, Subtitle, and Label for Input Dialog
  Out   : Title and Label for Selection/Confirmation Window
  """

    P90 = pul.GetPar(p90, "")
    P90D = pul.GetPar('pH90', "")

    if p90.find('H') >= 0:
        Amp = pul.GetPar('aH', units)
        nuc = "1H"
    if p90.find('C') >= 0:
        Amp = pul.GetPar('aC', units)
        nuc = "13C"
    if p90.find('N') >= 0:
        Amp = pul.GetPar('aN', units)
        nuc = "15N"
    frq = fq.fq(nuc, 1)

    AmpD = pul.GetPar('aH', units)

    i = 0
    Nucs = NUC.list()
    for label in Nucs:
        if label == nuc: frq = fq.fq(nuc, i + 1)
        i = i + 1

    SP = pul.GetPar(shp, "")
    MAS = pul.GetPar('MAS', "") / 1000.  #kHz not Hz
    CNCT = pul.GetPar(Cnct, "")

    ## Check that the values aren't stupid
    if CNCT <= 1.: CNCT = 1000.
    if CNCT >= 10000.: CNCT = 10000.

    MaxB1 = 1000000. / 4. / P90
    MaxB1D = 1000000. / 4. / P90D

    ##Set Decoupler if Appropriate
    if nuc != "1H":
        AmpD0 = pul.GetPar(ampD, "dB")
        B1_0 = MaxB1D * (math.pow(10, (AmpD - AmpD0) / 20.))

        if B1_0 > 100.: Dcond = '% .1f' % B1_0
        if B1_0 > MaxB1D: Dcond = '85000.0'
        if B1_0 <= 100.: Dcond = '85000.0'

    #Use a reasonable ramp name (passed in as dfltramp)
    if SP == "gauss" or SP == "None" or SP == "" or SP == "0":
        pul.SetPar(shp, dfltramp, "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict[shp]))
        SP = pul.GetPar(shp, "")

    ## change everything into dB for calculations.
    if units == "W":
        Amp = Setup.WtodB(Amp)
        AmpD = Setup.WtodB(AmpD)

    bf = math.floor(float(frq.bf))
    ppm = float(str('%.0f' % ppm))
    changedPPM = 'y'

    while changedPPM == 'y':
        #TopCmds.MSG(str(ppm)+":ppm  bf:"+str(bf))
        DHz = (float(ppm) * bf) / 1000.
        bshkHz = round(float(((MAS * MAS) - ((DHz * DHz) / 4)) / MAS), 2)

        if nuc != "1H":
            index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\
              [str('%.2f' %bshkHz),SP,str('%.0f' %ppm),\
              str('%.0f' %(CNCT/1000.)),str('%.2f' %(float(Dcond)/1000.))],\
              ["kHz","","ppm","ms","kHz"],\
              ["1","1","1","1","1"],\
              ["Accept","Close"], [spc,ret], 10)
            Dcond = float(index[4]) * 1000.

        if nuc == "1H":
            index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\
              [str('%.2f' %bshkHz),str(SP),str('%.2f' %ppm),\
              str('%.0f' %(Cnct/1000.))],\
              ["kHz","","ppm","ms"],\
              ["1","1","1","1"],\
              ["Accept","Close"], [spc,ret], 10)

        bshkHz = float(index[0])
        SP = index[1]
        Cnct = float(index[3]) * 1000.

        if str('%.2f' % ppm) == str('%.2f' % float(index[2])): changedPPM = 'n'
        if str('%.2f' % ppm) != str('%.2f' % float(index[2])):
            changedPPM = 'y'
            ppm = float(index[2])

    DHz = (float(ppm) * bf) / 1000.

    flip = (math.atan(DHz / bshkHz) * 180) / 3.1415
    pflip = round(((P90 * flip) / 90.), 2)

    #TopCmds.MSG(str(P90)+" "+str(flip)+" "+str(pflip)+" "+str(DHz)+" "+str(bshkHz))
    flip2k = (DHz * DHz) / bshkHz
    pflip2k = round(((0.25 / flip2k) * 1000), 2)

    w1bsh = float(index[0])
    adjust = 20 * (math.log10(w1bsh * 1000 / MaxB1))
    AmpBsh = Amp - adjust

    # Adjust for the ramp.
    if SP == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(SP) / 100.
    AmpBsh = AmpBsh - 20 * (math.log10(1. / AvgAmp))

    # For the Decoupling
    if nuc != "1H":
        AmpDec = Setup.DecSafely(Dcond, ampD, MaxB1D, 150000., AmpD, units)

    # Convert to Watts, if wanted
    if units == "W":
        AmpBsh = Setup.dBtoW(AmpBsh)
        if nuc != "1H": Damp = Setup.dBtoW(AmpDec)

    if nuc == "1H":
        value = TopCmds.SELECT(Out[0],"This will set\n "+\
          Out[1]+" power ("+pul.pulDict[amp]+") to: " + str('%3.2f' %AmpBsh)+" "+ units+"\n"+\
          "With shape (" + pul.pulDict[shp] + ") of "+ str(SP) +"\n"\
          "Flip pulse (" + pul.pulDict[pflp] +  ") of "+ str(pflip) +"us\n"\
          "Flip pulse 2k(" + pul.pulDict[pflp2k] +  ") of "+ str(pflip2k) +"us\n",\
          ["Update", "Keep Previous"],[spc,ret])

    else:
        value = TopCmds.SELECT(Out[0],\
          "This will set\n "+\
          Out[1][0]+" power ("+pul.pulDict[amp]+") to: " + str('%3.2f' %AmpBsh)+" "+ units+"\n"+\
          Out[1][1]+" power ("+pul.pulDict[ampD]+") to: " + str('%3.2f' %AmpD)+" "+ units+"\n"+\
          "With shape (" + pul.pulDict[shp] + ") of "+ str(SP) +"\n"\
          "Flip pulse (" + pul.pulDict[pflp] +  ") of "+ str(pflip) +"us\n"\
          "Flip pulse 2k(" + pul.pulDict[pflp2k] +  ") of "+ str(pflip2k) +"us\n",\
          ["Update", "Keep Previous"],[spc,ret])

    if value != 1:
        pul.SetPar(amp, AmpBsh, units)
        pul.SetPar(shp, SP, units)
        pul.SetPar(pflp, pflip, units)
        pul.SetPar(pflp2k, pflip2k, units)
        if nuc == "1H":
            pul.SetPar(ampD, AmpD, units)

    return
Example #25
0
def NCO(MAS0, MAS, units):

    p90X = pul.GetPar('pC90', "")
    ampX = pul.GetPar('aC', units)
    ampXCP = pul.GetPar('aCnco', units)
    SPX = pul.GetPar('sCnco', "")
    avgX = 1.

    p90Y = pul.GetPar('pN90', "")
    ampY = pul.GetPar('aN', units)
    ampYCP = pul.GetPar('aNnco', units)
    SPY = pul.GetPar('sNnco', "")
    avgY = 1.

    CNCT = pul.GetPar('pNCO', "")

    # Get the integration before possibly changing the shape.
    if SPX != "None" and SPX != None and SPX != "Unused":
        avgX = IntShape.Integrate(SPX) / 100.
    if SPY == "None" or SPY == None and SPY != "Unused":
        avgY = IntShape.Integrate(SPY) / 100.

    #Interact with user about MAS and power levels, likely not needed
    params = TopCmds.INPUT_DIALOG("NCO CP MAS adjustment", "NCO", \
    ["Old MAS rate","New MAS rate","Old CO power ("+pul.pulDict['aCnco']+")",\
    "Old 15N power ("+pul.pulDict['aNnco']+")","Contact Time ("+pul.pulDict['pNCO']+")",\
    "CO-Ramp ("+pul.pulDict['sCnco']+")","N-Ramp ("+pul.pulDict['sNnco']+")"],\
    [str(MAS0),str(MAS),str(ampXCP),str(ampYCP),str(CNCT),SPX,SPY],\
    ["Hz","Hz",units,units,"us","",""],\
    ["1","1","1","1","1","1","1"],\
    ["Accept","Close"], [spc,ret], 10)

    if params == None: TopCmds.EXIT()

    # Everything is written with dB, so we might have to convert
    if units == "W":
        params[2] = str(Setup.WtodB(float(params[2])))
        params[3] = str(Setup.WtodB(float(params[3])))
        ampX = Setup.WtodB(ampX)
        ampY = Setup.WtodB(ampY)

    pulses = p90X, ampX, p90Y, ampY, avgX, avgY

    SelectorText="Adjust the NCO CP parameters:","Calculate New Power Level for:",\
    ["Carbon","Nitrogen","Both"]

    ampXCP, ampYCP = FindMatch(params, pulses, SelectorText)

    if units == "W":
        ampXCP = Setup.dBtoW(ampXCP)
        ampYCP = Setup.dBtoW(ampYCP)

    value = TopCmds.SELECT("Adjusting the NCO CP parameters:",\
    "This will set\n 13C power to:  " + str('%3.2f' %ampXCP)+ " "+units+"\n \
  15N power to:  "                     +str('%3.2f' %ampYCP) + " "+units,["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar('aCnco', ampXCP, units)
        pul.SetPar('aNnco', ampYCP, units)
        pul.SetPar('pNCO', CNCT, "")
        pul.SetPar('sCnco', SPX, "")
        pul.SetPar('sNnco', SPY, "")
Example #26
0
def copyCP(aH,sH,aL,sL,pCP,aH0,sH0,aL0,sL0,pCP0,Input,Output,units):
  """
  aH/L(0)  : dict key for High/Low G CP amp (0 for default)
  pCP(0)   : dict key for CP contact (0 default)
  shH/L(0) : dict key of CP shape files
  units    : Watts (W) or decibel (dB)
  In       : Title, Subtitle, and Label for Input Dialog
  Out      : Title and Label for Selection/Confirmation Window
  """  

  #Use Dictionary Definitions to find hard pulse powers
  if aH.find('H') >= 0:AmpH=pul.GetPar('aH',"dB"); P90H=pul.GetPar('pH90',""); Hnuc="1H"
  if aH.find('C') >= 0:AmpH=pul.GetPar('aC',"dB"); P90H=pul.GetPar('pC90',""); Hnuc="13C"
  if aH.find('N') >= 0:AmpH=pul.GetPar('aN',"dB"); P90H=pul.GetPar('pN90',""); Hnuc="15N"

  if aL.find('H') >= 0:AmpL=pul.GetPar('aH',"dB"); P90L=pul.GetPar('pH90',""); Lnuc="1H"
  if aL.find('C') >= 0:AmpL=pul.GetPar('aC',"dB"); P90L=pul.GetPar('pC90',""); Lnuc="13C"
  if aL.find('N') >= 0:AmpL=pul.GetPar('aN',"dB"); P90L=pul.GetPar('pN90',""); Lnuc="15N"
  
  MaxB1H=1000000./4./P90H
  MaxB1L=1000000./4./P90L

  SPH =pul.GetPar(sH,"")
  SPL =pul.GetPar(sL,"")

  Hamp0=pul.GetPar(aH0,"dB")
  Lamp0=pul.GetPar(aL0,"dB")
  
  if pul.GetPar(pCP,"") <=   1.00  :
    pul.SetPar(pCP,pul.GetPar(pCP0,""),"")

  CNCT = pul.GetPar(pCP,"")/1000.

  if SPH == "gauss" or SPH == "None" or SPH == ""  or SPH == "0" :
    pul.SetPar(sH,pul.GetPar(sH0,""),"")
    TopCmds.XCMD(pul.xcmd_name(pul.pulDict[sH]))
    SPH = pul.GetPar(sH,"")

  if SPL == "gauss" or SPL == "None" or SPL == "" or SPL == "0":
    pul.SetPar(sL,pul.GetPar(sL0,""),"")
    TopCmds.XCMD(pul.xcmd_name(pul.pulDict[sL]))
    SPX=pul.GetPar(sL0,"")

  if SPH == "Unused":
    Hav  = 1.
    Hav0 = 1.
  else:
    Hav  = IntShape.Integrate(pul.GetPar(sH,""))/100.
    Hav0 = IntShape.Integrate(pul.GetPar(sH0,""))/100.
  
  if SPL == "Unused":
    Lav  = 1.
    Lav0 = 1.
  else:
    Lav  = IntShape.Integrate(pul.GetPar(sL,""))/100.
    Lav0 = IntShape.Integrate(pul.GetPar(sL0,""))/100.

  #This is the new integration times the change in new/old
  Hint = ((Hav)**2)/Hav0
  Lint = ((Lav)**2)/Lav0
  
  B1H = MaxB1H*Hint*math.pow(10,(AmpH-Hamp0)/20.)
  B1L = MaxB1L*Lint*math.pow(10,(AmpL-Lamp0)/20.)
  
  index=TopCmds.INPUT_DIALOG(Input[0],Input[1],Input[2],\
  [str('%.3f' %(B1H/1000.)),SPH,str('%.3f' %(B1L/1000.)),SPL,str(CNCT)],\
  ["kHz","","kHz","","ms"],\
  ["1","1","1","1","1",],\
  ["Accept","Close"], [spc,ret], 10)
  
  if index == None:TopCmds.EXIT()
  SPH=index[1]
  SPX=index[3]
  CNCT=1000*float(index[4])

  adjust=20*(math.log10(1000.*float(index[0])/MaxB1H))
  Hamp1 = AmpH-adjust
  if SPH == "Unused":
    AvgAmp=1.
  else:
    AvgAmp=IntShape.Integrate(index[1])/100.
  adjust=20*(math.log10(1./AvgAmp))
  Hamp = Hamp1-adjust

  adjust=20*(math.log10(1000.*float(index[2])/MaxB1L))
  Lamp = AmpL-adjust
  if SPL == "Unused":
    AvgAmp=1.
  else:
    AvgAmp=IntShape.Integrate(index[3])/100.
  adjust=20*(math.log10(1./AvgAmp))
  Lamp = Lamp-adjust

  if units == "W":
    Hamp=Setup.dBtoW(Hamp)
    Lamp=Setup.dBtoW(Lamp)

  value = TopCmds.SELECT(Output[0],\
  "This will set\n"+\
  Hnuc+" power to:  " + str('%3.2f' %Hamp)+" "+units+"\n"+ \
  Lnuc+" power to:  " +str('%3.2f' %Lamp) + units,\
  ["Update", "Keep Previous"],[spc,ret])
    
  if value != 1:
    pul.SetPar(aH,Hamp,units)
    pul.SetPar(aL,Lamp,units)
    pul.SetPar(pCP,CNCT,"")
    if SPH != "Unused":
      pul.SetPar(sH,index[1],"")
    if SPX != "Unused":
      pul.SetPar(sL,index[3],"")
Example #27
0
def CalCP(p90H, p90L, ampH, ampL, ampD, Cnct, shH, shL, HXorXY, iGuess, units,
          In, Out):

    P90H = pul.GetPar(p90H, "")
    P90L = pul.GetPar(p90L, "")
    P90D = pul.GetPar('pH90', "")

    #Use Definitions to find hard pulse powers
    if p90H.find('H') >= 0: AmpH = pul.GetPar('aH', units)
    if p90H.find('C') >= 0: AmpH = pul.GetPar('aC', units)
    if p90H.find('N') >= 0: AmpH = pul.GetPar('aN', units)

    if p90L.find('H') >= 0: AmpL = pul.GetPar('aH', units)
    if p90L.find('C') >= 0: AmpL = pul.GetPar('aC', units)
    if p90L.find('N') >= 0: AmpL = pul.GetPar('aN', units)

    SPH = pul.GetPar(shH, "")
    SPL = pul.GetPar(shL, "")

    MAS = pul.GetPar('MAS', "")
    CNCT = pul.GetPar(Cnct, "")

    if CNCT <= 1.: CNCT = 1000.
    if CNCT >= 10000.: CNCT = 10000.

    MaxB1H = 1000000. / 4. / P90H
    MaxB1L = 1000000. / 4. / P90L
    MaxB1D = 1000000. / 4. / P90D

    #Set Decoupler if Appropriate
    if HXorXY == "XY":
        AmpD = pul.GetPar('aH', "dB")
        AmpD0 = pul.GetPar(ampD, "dB")

        B1_0 = MaxB1D * (math.pow(10, (AmpD - AmpD0) / 20.))
        if B1_0 > 100.: Dcond = '% .1f' % B1_0
        if B1_0 > MaxB1D: Dcond = '85000.0'
        if B1_0 <= 100.: Dcond = '85000.0'

    if units == "W":
        AmpH = WtodB(AmpH)
        AmpL = WtodB(AmpL)

    if pul.GetPar(shH,"") == "gauss" or pul.GetPar(shH,"") == "None" or \
    pul.GetPar(shH,"") == "" or pul.GetPar(shH,"") == "0" :
        pul.SetPar(shH, "ramp.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict[shH]))
        SPH = pul.GetPar(shH, "")

    if pul.GetPar(shL,"") == "gauss" or pul.GetPar(shL,"") == "None" or \
    pul.GetPar(shL,"") == "" or pul.GetPar(shL,"") == "0" :
        pul.SetPar(shL, "square.100", "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict[shL]))
        SPH = pul.GetPar(shL, "")

    if iGuess == "Max":
        #find the channel with the lowest B1
        if MaxB1L < MaxB1H:
            Ratio = int(math.floor(MaxB1L / MAS))
            HCond = (Ratio + 0.5) * MAS
            LCond = (Ratio - 0.5) * MAS

        if MaxB1L >= MaxB1H:
            Ratio = int(math.floor(MaxB1H / MAS))
            HCond = (Ratio - 0.5) * MAS
            LCond = (Ratio + 0.5) * MAS

        while HCond > MaxB1H or LCond > MaxB1L:
            Ratio = Ratio - 1
            if MaxB1L < MaxB1H:
                HCond = (Ratio + 0.5) * MAS
                LCond = (Ratio - 0.5) * MAS
            if MaxB1L >= MaxB1H:
                HCond = (Ratio - 0.5) * MAS
                LCond = (Ratio + 0.5) * MAS

        # If spinning very fast or using weak B1s
        if Ratio == 2:
            LCond = 0.75 * MAS
            HCond = 1.75 * MAS
        if Ratio <= 1 or HCond > MaxB1H or LCond > MaxB1L:
            LCond = .25 * MAS
            HCond = .75 * MAS

    else:
        LCond = (5. / 2.) * MAS
        if iGuess == "Low":
            HCond = (3. / 2.) * MAS
        else:
            #iGuess == "High":
            HCond = (7. / 2.) * MAS

        while LCond > MaxB1L:
            LCond = LCond - MAS
            CCond = LCond + MAS

        while HCond > MaxB1H:
            LCond = LCond - MAS
            CCond = LCond + MAS

        if LCond < MAS:
            LCond = 0.25 * MAS
            HCond = 0.75 * MAS

    adjust = 20 * (math.log10(LCond / MaxB1L))
    Lamp = AmpL - adjust
    adjust = 20 * (math.log10(HCond / MaxB1H))
    Hamp = AmpH - adjust

    if HXorXY == "HX":
        index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\
          [str(HCond),str(SPH),str(LCond),str(SPL),str(CNCT)],\
          ["Hz","","Hz","","us"],\
          ["1","1","1","1","1"],\
          ["Accept","Close"], ['a','c'], 10)

    if HXorXY == "XY":
        index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\
          [str(HCond),str(SPH),str(LCond),str(SPL),str(CNCT),str(Dcond)],\
          ["Hz","","Hz","","us","Hz"],\
          ["1","1","1","1","1","1"],\
          ["Accept","Close"], ['a','c'], 10)

    adjust = 20 * (math.log10(float(index[0]) / MaxB1H))
    Hamp1 = AmpH - adjust
    if SPH == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[1]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Hamp = Hamp1 - adjust

    adjust = 20 * (math.log10(float(index[2]) / MaxB1L))
    Lamp1 = AmpL - adjust
    if SPL == "Unused":
        AvgAmp = 1.
    else:
        AvgAmp = IntShape.Integrate(index[3]) / 100.
    adjust = 20 * (math.log10(1. / AvgAmp))
    Lamp = Lamp1 - adjust

    CNCT = float(index[4])

    if HXorXY == "XY":
        adjust = 20 * (math.log10(float(index[5]) / MaxB1D))
        Damp = AmpD - adjust

    if units == "W":
        Hamp = dBtoW(Hamp)
        Lamp = dBtoW(Lamp)
        if HXorXY == "XY": Damp = dBtoW(Damp)

    if HXorXY == "HX":
        value = TopCmds.SELECT(Out[0],\
        "This will set\n "+\
        Out[1][0]+" power to:  " + str('%3.2f' %Hamp)+" "+ units+"\n"+\
        Out[1][1]+" power to:  " + str('%3.2f' %Lamp)+" "+ units,\
        ["Update", "Keep Previous"])

    if HXorXY == "XY":
        value = TopCmds.SELECT(Out[0],\
        "This will set\n "+\
        Out[1][0]+" power to:  " + str('%3.2f' %Hamp)+" "+ units+"\n"+\
        Out[1][1]+" power to:  " + str('%3.2f' %Lamp)+" "+ units+"\n"+\
        Out[1][2]+" power to:  " + str('%3.2f' %Damp)+" "+ units,\
        ["Update", "Keep Previous"])

    if value != 1:
        pul.SetPar(ampH, Hamp, units)
        pul.SetPar(ampL, Lamp, units)

        if HXorXY == "XY":
            pul.SetPar(ampD, Damp, units)
        pul.SetPar(Cnct, CNCT, "")
        if SPH != "Unused":
            pul.SetPar(shH, index[1], "")
        if SPL != "Unused":
            pul.SetPar(shL, index[3], "")

    return
Example #28
0
def CalDec(p90, amp, cpd, nuc, units, dfltWave, dfltB0, dfltPH, aOption,
           aFaults):
    """
  p90     : Dict key for Hard Pulse of Decoupled Nucleus
  amp     : Dict key for Hard Pulse Amplitude
  cpd     : Dict key for CPD file
  nuc     : Decoupled Nucleus
  units   : Watts (W) or Decibels (dB)
  dfltWave: Default CPD
  dfltB0  : Default field
  dfltPH  : Default tip angle used in CPD
  aOption : List of accepted amplitude dict keys
  aFaults : List of amplitude dict keys that will cause a PLEASE CONFIRM Message
  """
    Stuff = []

    P90 = pul.GetPar(p90, "")
    Amp = pul.GetPar(amp, units)
    CPD = pul.GetPar(cpd, "")

    MaxB1 = 1000000. / 4. / P90

    if CPD == "mlev" or CPD == "None" or CPD == None or CPD == "":
        pul.SetPar(cpd, dfltWave, "")
        TopCmds.XCMD(pul.xcmd_name(pul.pulDict[cpd]))
        CPD = pul.GetPar(cpd, "")

    Stuff = CPDtools.CPDparse(CPD, nuc)
    Amp0 = CPDtools.Find_old_pl(Stuff[0], units)

    if units == "W":
        Amp = WtodB(Amp)
        Amp0 = WtodB(Amp0)

    decpw0 = CPDtools.Find_old_pw(Stuff[1], nuc)

    B1_0 = MaxB1 * (math.pow(10, (Amp - Amp0) / 20.)) / 1000.
    if B1_0 > 1.: B1out = '% .3f' % B1_0
    if B1_0 > MaxB1 / 1000.: B1out = '% .3f' % dfltB0
    if B1_0 <= 1.: B1out = '% .3f' % dfltB0

    index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Decoupling Window", \
    ["Desired "+nuc+" Decoupling Amplitude","File"],\
    [B1out,CPD],["kHz",""],["1","1"],\
    ["Accept","Close"], [spc,ret], 10)

    if index == None:
        TopCmds.EXIT()

    pul.SetPar(cpd, index[1], "")
    pl = pul.pp_2_xcmd(Stuff[0], "")

    matched = 0

    for a in aOption:
        if pl == pul.pulDict[a]:
            matched = 1
            Hamp = DecSafely(
                float(index[0]) * 1000, a, MaxB1, 2 * 1000. * dfltB0, Amp,
                units)

    if matched == 0:
        Hamp = DecSafely(
            float(index[0]) * 1000, aOption[0], MaxB1, 2 * 1000. * dfltB0, Amp,
            units)

    decpw = (MaxB1 / 1000. / float(index[0])) * (dfltPH / 180.) * 2 * P90

    if units == "W":
        Hamp = dBtoW(Hamp)

    value = TopCmds.SELECT("Adjusting the "+nuc+" decoupling parameters:",\
    "This will set\n "+nuc+" power ("+ Stuff[0] +") to:  "+ str('%.2f' %Hamp)+" "+ units+"\n \
  Pulse width ("                  + Stuff[1] +") to:  " +str('%3.2f' %decpw)+" us",["Update", "Keep Previous"])

    if value != 1:
        if Stuff[0] == "":
            pul.SetPar(aOption[0], Hamp, units)

        for i in aFaults:
            if pl == pul.pulDict[i]:
                DecError(f, nuc)

        for a in aOption:
            if pl == pul.pulDict[a]:
                pul.SetPar(a, Hamp, units)

    return Stuff[1], decpw
def CalSP(nuc,units,para,dflt,limits,dia,conf,tip):
  """
  nuc     : Nucleus, 13C or 1H
  units   : Watts (W) or Decibels (dB)
  para    : Dict keys for soft pulse wave (time,amp,shape,offs)
  dflt    : Defaults (time,shape,offs(in ppm))
  limits  : ppm frequency limits (upper, lower)
  """
	
  if nuc=="13C":p90=pul.GetPar('pC90',""); amp=pul.GetPar('aC',units)
  if nuc=="1H": p90=pul.GetPar('pH90',""); amp=pul.GetPar('aH',units)
  MAS =pul.GetPar('MAS',"")
  
  if units == "W":
    amp=Setup.WtodB(amp)  

  MaxB1 = 1000000./4./p90
  pSft  = pul.GetPar(para[0],"")
  if pSft == 0: pSft = dflt[0]
  SP=pul.GetPar(para[2],"")
  offs0 = pul.GetPar(para[3],"")
  
  #Check for existence and default
  if SP == "gauss" or SP == "None" or SP == "0"  or SP == "" :
    pul.SetPar(para[2],dflt[1],"")
    TopCmds.XCMD(pul.xcmd_name(pul.pulDict[para[2]]))
    SP=pul.GetPar(para[2],"")
  
  if pul.pulDict['uoffs']=='ppm':
    ppm=offs0
    offs=Cfrq.ppm2offs(offs0)
  else:
    #offs0 is in Hz
    ppm=Cfrq.offs2ppm(offs0)
    offs=offs0
  
  if ppm > limits[0] : ppm=dflt[2]
  if ppm < limits[1] : ppm=dflt[2]

  index = TopCmds.INPUT_DIALOG(dia[0],dia[1],dia[2],\
  [str('%3.2f' %pSft),str('%3.2f' %ppm),SP],\
  dia[3],["1","1","1"],\
  ["Accept","Close"], [spc,ret], 10)

  if index == None:TopCmds.EXIT()

  pSft=float(index[0])
  ppm=float(index[1])
  SP=index[2]
  offs=Cfrq.ppm2offs(ppm)

  AvgAmp=IntShape.Integrate(SP)/100.
  adjust=20*math.log10((tip/90.)*p90/pSft/AvgAmp)
  Power =amp-adjust

  if units == "W":
    Power=Setup.dBtoW(Power)  

  confirm = TopCmds.SELECT(conf,\
  "This will set\n "+\
  nuc+" amp "+pul.pulDict[para[1]]+" to : " + str('%3.2f' %Power)+ " "+units+"\n \
  Pulse offset to   : " + str('%8.0f' %offs) + " Hz\n \
  Equivalent to     : " + str('%3.1f' %ppm ) + " ppm\n "+\
  pul.pulDict[para[0]]+" to     :" + str('%6.1f' %pSft)+ " us\n "\
  ,["Update", "Keep Previous"])
  
  if confirm != 1:
    pul.SetPar(para[0],pSft,"")
    pul.SetPar(para[1],Power,units)
    pul.SetPar(para[2],SP,"")

    if pul.pulDict['uoffs']=='ppm':
      pul.SetPar(para[3],ppm,"")
    elif pul.pulDict['uoffs']=='Hz':
      pul.SetPar(para[3],offs,"")
    else :
      pul.SetPar(para[3],ppm,"")
Example #30
0
def CalcSym(CorR, N, n, v, mult, p90, amp, Wave, time, dfltT, nuc, dec, units):
    """
  CorR    : Symmetry Element
  N       : Step Number
  n       : Space Winding Number
  v       : Spin Winding Number (not used here, yet)
  mult    : Mulitplier for Composite Pulses
  p90     : Dict key for Hard Pulse of Nucleus
  amp     : Dict key for recoupling Amplitude
  Wave    : Shaped pulse (None or Unused)
  nuc     : Recoupled Nucleus
  dec     : Dict key for Decoupler Nucleus
  dfltT   : Default Time or Loop
  """
    value = 0
    if pul.pulDict[time].find("D") >= 0:
        lblT = "Delay", "s"
    elif pul.pulDict[time].find("L") >= 0:
        lblT = "Loop", "cycles"
    elif pul.pulDict[time].find("P") >= 0:
        lblT = "Pulse", "us"

    #Use Dictionary Definitions to find hard pulse powers
    if p90.find('H') >= 0: Amp = pul.GetPar('aH', "dB")
    if p90.find('C') >= 0: Amp = pul.GetPar('aC', "dB")
    if p90.find('N') >= 0: Amp = pul.GetPar('aN', "dB")

    #Assume 1H decoupling if neccessary
    P90 = pul.GetPar(p90, "")
    P90D = pul.GetPar('pH90', "")
    MAS = pul.GetPar('MAS', "")

    Tau_r = 1. / float(MAS)
    MaxB1 = 1000000. / 4. / P90
    MaxB1D = 1000000. / 4. / P90D
    #Calculate the RF field
    if CorR == "C":
        Cond = mult * 1. * N * MAS / n
    if CorR == "R":
        Cond = mult * 2. * N * MAS / n

    #Set Decoupler if Appropriate
    if dec != "None":
        AmpD = pul.GetPar('aH', "dB")
        AmpD0 = pul.GetPar(dec, "dB")

        B1_0 = MaxB1D * (math.pow(10, (AmpD - AmpD0) / 20.))

        if B1_0 > 100.: Dcond = B1_0
        if B1_0 > MaxB1D: Dcond = 85000.0
        if B1_0 <= 100.: Dcond = 85000.0

    if Cond > MaxB1:
        TopCmds.MSG("The match condition for " + CorR+str(N)+unb+str(n)+crt+str(v)+" is "+\
        str('%.3f' %(Cond/1000.))+" kHz \n\nIt is greater than the Max B1 ("+ str('%.3f' %(MaxB1/1000.))+" kHz)\n\n"+\
        pul.pulDict[amp]+" will NOT be set  ")

        TopCmds.EXIT()
    else:
        if dec == "None":
            Title = "Adjusting " + nuc + " Power for Symmetry-Based Recoupling"
            Subtit = CorR + str(N) + unb + str(n) + crt + str(
                v) + "Symmetry Match"
            Label = [nuc + " Amplitude", lblT[0] + " " + pul.pulDict[time]]
            Values = [str('%.3f' % (Cond / 1000.)), str(dfltT)]
            Units = ["kHz", lblT[1]]
            Types = ["1", "1"]
            Buttons = ["Accept", "Cancel"]
            ShortCuts = [spc, ret]
            columns = 10

        else:
            Title = "Adjusting " + nuc + " Power for Symmetry-Based Recoupling"
            Subtit = CorR + str(N) + unb + str(n) + crt + str(
                v) + " Symmetry Match"
            Label = [nuc+" Amplitude",lblT[0]+" "+pul.pulDict[time],\
                     "1H decoupling field"]

            temp1 = Cond / 1000.
            temp2 = Dcond / 1000.
            Values = [str('%.3f' % temp1), str(dfltT), str('%.3f' % temp2)]
            Units = ["kHz", lblT[1], "kHz"]
            Types = ["1", "1", "1"]
            Buttons = ["Accept", "Cancel"]
            ShortCuts = [spc, ret]
            columns = 10

        index = TopCmds.INPUT_DIALOG(Title, Subtit, Label, Values, Units,
                                     Types, Buttons, ShortCuts, columns)

        if index == None:
            TopCmds.EXIT()
        if index != None:
            Cond = float(index[0]) * 1000.
            Time = str(index[1])
            if dec != "None":
                #Safety
                Damp = DecSafely(1000. * float(index[2]), dec, MaxB1D, 150000.,
                                 AmpD, units)

    #Calculate the power
    adjust = 20 * (math.log10(Cond / MaxB1))
    Condition = Amp - adjust

    #Calculate the Integration if shaped pulses are used
    if Wave != "None" and Wave != "Unused":

        if pul.GetPar(Wave,"") == "gauss" or pul.GetPar(Wave,"") == "None" or \
        pul.GetPar(Wave,"") == "" or pul.GetPar(Wave,"") == "0" :
            pul.SetPar(Wave, "square.100", "")
            TopCmds.XCMD(pul.xcmd_name(pul.pulDict[Wave]))
            SP = pul.GetPar(Wave, "")

        AvgAmp = IntShape.Integrate(SP) / 100.

        adjust = 20 * (math.log10(1. / AvgAmp))
        Condition = Condition - adjust

    if units == "W":
        Condition = dBtoW(Condition)
        if dec != "None": Damp = dBtoW(Damp)

    if dec == "None":
        Confirm = nuc + " Power for " + CorR + str(N) + "_" + str(
            n) + "^" + str(v) + "Symmetry Match"
        Power  ="Set\n "+ pul.pulDict[amp]+" to:  "+str('%3.2f' %Condition)+" "+ units+"\n"+\
                            pul.pulDict[time]+" "+lblT[1]+" to: "+index[1]
    else:
        Confirm = "Adjusting " + nuc + " and 1H Power for " + CorR + str(
            N) + "_" + str(n) + "^" + str(v) + "Symmetry Match"
        Power  ="Set\n "+ pul.pulDict[amp]+" to:  "+str('%3.2f' %Condition)+" "+ units+"\n"+\
                          pul.pulDict[dec]+" (Dec) power to:  "+str('%3.2f' %Damp)+" "+ units+"\n"+\
                          pul.pulDict[time]+" "+lblT[1]+" to: "+index[1]

    if Confirm == "None":
        value = 1
    else:
        value = TopCmds.SELECT(Confirm, Power, ["Update", "Keep Previous"],
                               [spc, ret])

    if value != 1:
        pul.SetPar(amp, Condition, units)
        pul.SetPar(time, index[1], "")
        if dec != "None": pul.SetPar(dec, Damp, units)