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
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,"")
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, "")
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
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], "")
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, "")
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 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], "")
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],"")
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)
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 CalCP(p90H, p90L, ampH, ampL, ampD, Cnct, shH, shL, HXorXY, iGuess, units, offsCP, In, Out): """ p90H/L: Dictionary Key for High/Low Gamma Nucleus 90 degree pulse ampH/L: dict key for High/Low G CP amp ampD : dict key for Decoupler (assumed to be 1H) or "empty" Cnct : dict key for CP contact shH/L : dict key of CP shape files HXorXY: Determines whether decoupling is used iGuess: "Max", "High", "Low", "LG" Max : determine highest allowed condition High : High G = 3/2 Wr Low G = 5/2 Wr Low : High G = 7/2 Wr Low G = 5/2 Wr LG : Use Max, but adjust for Lee-Goldburg units : Watts (W) or decibel (dB) offsCP: offset for CP in Hz (LG or off-resonance CP) In : Title, Subtitle, and Label for Input Dialog Out : Title and Label for Selection/Confirmation Window """ P90H = pul.GetPar(p90H, "") P90L = pul.GetPar(p90L, "") P90D = pul.GetPar('pH90', "") #Use Dictionary 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 == "LG": #Adjust MaxB1H for Lee-Goldburg MaxB1H = MaxB1H * math.sqrt(3.0 / 2.) if iGuess == "Max" or iGuess == "LG": #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 HCond = LCond + MAS while HCond > MaxB1H: LCond = LCond - MAS HCond = LCond + MAS if LCond < MAS: LCond = 0.25 * MAS HCond = 0.75 * MAS if iGuess == "LG": #Change MaxB1H back for proper conversion MaxB1H = 1000000. / 4. / P90H if HXorXY == "HX": index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\ [str('%.3f' %(HCond/1000.)),str(SPH),str('%.3f' %(LCond/1000.)),str(SPL),\ str('%.3f' %(CNCT/1000.))],\ ["kHz","","kHz","","ms"],\ ["1","1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if HXorXY == "XY": index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\ [str('%.3f' %(HCond/1000.)),str(SPH),str('%.3f' %(LCond/1000.)),str(SPL),\ str('%.3f' %(CNCT/1000.)),str('%.3f' %(float(Dcond)/1000.))],\ ["kHz","","kHz","","ms","kHz"],\ ["1","1","1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index == None: TopCmds.EXIT() if iGuess == "LG": w1H = float(index[0]) * math.sqrt(2. / 3.) LGoffs = 1000 * float(index[0]) / math.sqrt(3.) else: w1H = float(index[0]) #TopCmds.MSG("w1H "+str('%.2f' %(w1H*1000.))+" MaxB1H: "+str('%.2f' %(MaxB1H))) adjust = 20 * (math.log10(w1H * 1000. / 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]) * 1000. / 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]) * 1000. if HXorXY == "XY": #Decouple Safely Damp = DecSafely(1000. * float(index[5]), ampD, MaxB1D, 150000., AmpD, units) if units == "W": Hamp = dBtoW(Hamp) Lamp = dBtoW(Lamp) if HXorXY == "XY": Damp = dBtoW(Damp) if HXorXY == "HX": if iGuess == "LG": value = TopCmds.SELECT(Out[0],\ "This will set\n "+\ Out[1][0]+" power ("+ pul.pulDict[ampH] +") to: " + str('%3.2f' %Hamp)+" "+ units+"\n"+\ Out[1][1]+" power ("+ pul.pulDict[ampL] +") to: " + str('%3.2f' %Lamp)+" "+ units+"\n"+\ "1H LG offset ("+ pul.pulDict[offsCP] +") to: "+ str('%3.2f' %LGoffs)+ " Hz",\ ["Update", "Keep Previous"],[spc,ret]) else: value = TopCmds.SELECT(Out[0],\ "This will set\n "+\ Out[1][0]+" power ("+ pul.pulDict[ampH] +") to: " + str('%3.2f' %Hamp)+" "+ units+"\n"+\ Out[1][1]+" power ("+ pul.pulDict[ampL] +") to: " + str('%3.2f' %Lamp)+" "+ units,\ ["Update", "Keep Previous"],[spc,ret]) if HXorXY == "XY": value = TopCmds.SELECT(Out[0],\ "This will set\n "+\ Out[1][0]+" power ("+ pul.pulDict[ampH] +") to: " + str('%3.2f' %Hamp)+" "+ units+"\n"+\ Out[1][1]+" power ("+ pul.pulDict[ampL] +") to: " + str('%3.2f' %Lamp)+" "+ units+"\n"+\ Out[1][2]+" power ("+ pul.pulDict[ampD] +") to: " + str('%3.2f' %Damp)+" "+ units,\ ["Update", "Keep Previous"],[spc,ret]) if value != 1: pul.SetPar(ampH, Hamp, units) pul.SetPar(ampL, Lamp, units) pul.SetPar(Cnct, CNCT, "") if iGuess == "LG": pul.SetPar(offsCP, LGoffs, "") if HXorXY == "XY": pul.SetPar(ampD, Damp, units) if SPH != "Unused": pul.SetPar(shH, index[1], "") if SPL != "Unused": pul.SetPar(shL, index[3], "") return
def CalDREAM(p90,match,amp,ampD,Cnct,SP,dfltSP,shpdict,units,In,Out): """ p90 : Dictionary Key for Nucleus 90 degree pulse; determines Nuc (Decoupling flag) match : float of precalculated match amp : dict key for DREAM amp ampD : dict key for Decoupler (assumed to be 1H) or "empty" Cnct : dict key for DREAM contact shp : dict key of DREAM shape file dfltSP: Default pulse shape shpdict:dict key for DREAM shape units : Watts (W) or decibel (dB) In : Title, Subtitle, and Label for Input Dialog Out : Title and Label for Selection/Confirmation Window """ MAS=pul.GetPar('MAS',"") TauR=float(1000000/MAS) P90D=pul.GetPar('pH90',"") AmpD =pul.GetPar('aH',"dB") MaxB1D = 1000000./4./P90D if p90.find('H') >=0:MaxB1=1000000./4./(pul.GetPar('pH90',""));Amp=pul.GetPar('aH','dB') if p90.find('C') >=0:MaxB1=1000000./4./(pul.GetPar('pC90',""));Amp=pul.GetPar('aC','dB') CNCT=pul.GetPar(Cnct,"") if CNCT <= 1. : CNCT = 1000. if CNCT >= 10000.: CNCT = 10000. if p90.find('H') <=0: 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": Amp=WtodB(Amp) if SP == "gauss" or SP == "None" or SP=="" or SP == "0" : SP=dfltSP pul.SetPar(shpdict,SP,"") TopCmds.XCMD(pul.xcmd_name(pul.pulDict[shpdict])) SP=pul.GetPar(shp,"") if p90.find('H') >=0: index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\ [str('%.3f' %(match/1000.)),str(SP),str('%.3f' %(CNCT/1000.))],\ ["kHz","","ms"],\ ["1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index== None: TopCmds.EXIT() else: index=TopCmds.INPUT_DIALOG(In[0],In[1],In[2],\ [str('%.3f' %(match/1000.)),str(SP),str('%.3f' %(CNCT/1000.)),\ str('%.3f' %(float(Dcond)/1000.))],\ ["kHz","","ms","kHz"],\ ["1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index== None: TopCmds.EXIT() wD=float(index[3]) w1=float(index[0]) SP=index[1] CNCT=float(index[2])*1000. #Integrate Dream ramp adjust=20*(math.log10(w1*1000./MaxB1)) Amp1 = Amp-adjust AvgAmp=(IntShape.Integrate(SP))/100. adjust=20*(math.log10(1./AvgAmp)) AmpX = Amp1-adjust if units == "W": AmpX=dBtoW(AmpX) #TopCmds.MSG(str(Out)) if p90.find('H') <=0: AmpD = Setup.DecSafely(1000.*wD,ampD,MaxB1D,150000.,AmpD,units) value = TopCmds.SELECT(Out[0],\ "This will set\n "+\ Out[1][1]+" power ("+ pul.pulDict[amp] +") to: " + str('%3.2f' %AmpX)+" "+ units+"\n"+\ Out[1][0]+" power ("+ pul.pulDict[ampD] +") to: " + str('%3.2f' %AmpD)+" "+ units,\ ["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' %Hamp)+" "+ units+"\n"+\ ["Update", "Keep Previous"],[spc,ret]) if value != 1: pul.SetPar(amp,AmpX,units) pul.SetPar(Cnct,CNCT,"") if p90.find('H') <=0: pul.SetPar(ampD,AmpD,"dB")