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 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 DDec(): Stuff = [] p90 = float(TopCmds.GETPAR("P 32")) amp = float(TopCmds.GETPAR("PLdB 31")) MaxB1 = 1000000. / 4. / p90 CPD = TopCmds.GETPAR2("CPDPRG 5") if CPD == "mlev" or CPD == "None": TopCmds.XCMD("cpdprg5") CPD = (TopCmds.GETPAR2("CPDPRG 5")) Stuff = CPDtools.CPDparse(CPD, "2D") TopCmds.MSG(str(Stuff)) amp0 = CPDtools.Find_old_pl(Stuff[0]) decpw0 = CPDtools.Find_old_pw(Stuff[1], "2D") B1_0 = MaxB1 * (math.pow(10, (amp - amp0) / 20.)) / 1000. if B1_0 > 1.: B1out = '% .1f' % B1_0 if B1_0 <= 1.: B1out = '5.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) TopCmds.PUTPAR("CPDPRG 5", index[1]) adjust = 20 * (math.log10(1000. * float(index[0]) / MaxB1)) ampli = amp - adjust decpw = (MaxB1 / 1000. / float(index[0])) * 2 * p90 watts = dBtoW(ampli) value = TopCmds.SELECT("Adjusting the D decoupling parameters:",\ "This will set\n 2H power ("+ Stuff[0] +") to: "+ str('%3.2f' %watts)+ " W\n \ Pulse width (" + Stuff[1] +"= 180deg) to: " +str('%3.2f' %decpw) + " us",["Update", "Keep Previous"]) if value != 1: if Stuff[0] == '': TopCmds.PUTPAR("PLdB 25", str('%3.2f' % ampli)) elif Stuff[0] == 'pl3': TopCmds.PUTPAR("PLdB 25", str('%3.2f' % ampli)) elif Stuff[0] == 'pl12': TopCmds.MSG( "You are using pl12 for 2H decouling. It is usually reserved for 1H \n Please verify" ) #TopCmds.PUTPAR("PLdB 12",str('%3.2f' %ampli)) elif Stuff[0] == 'pl13': TopCmds.MSG( "You are using pl13 for 2H decouling. It is usually reserved for 1H \n Please verify" ) #TopCmds.PUTPAR("PLdB 13",str('%3.2f' %ampli)) elif Stuff[0] == 'pl14': TopCmds.MSG( "You are using pl14 for 2H decouling. It is usually reserved for 1H \n Please verify" ) #TopCmds.PUTPAR("PLdB 14",str('%3.2f' %ampli)) if Stuff[1] == 'pcpd': TopCmds.PUTPAR("PCPD 5", str('%3.2f' % decpw)) elif Stuff[1] == 'p31': TopCmds.PUTPAR("P 31", str('%3.2f' % decpw)) TopCmds.PUTPAR("P 30", str('%3.2f' % decpw)) elif Stuff[1] == 'p62': TopCmds.PUTPAR("P 61", str('%3.2f' % decpw)) TopCmds.PUTPAR("P 62", str('%3.2f' % decpw))
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 CalHN(): p90H = float(TopCmds.GETPAR("P 3")) ampH = float(TopCmds.GETPAR("PLdB 2")) p90N = float(TopCmds.GETPAR("P 21")) ampN = float(TopCmds.GETPAR("PLdB 3")) MAS = float(TopCmds.GETPAR("CNST 31")) CNCT = float(TopCmds.GETPAR("P 25")) SPH = TopCmds.GETPAR2("SPNAM 42") SPX = TopCmds.GETPAR2("SPNAM 43") if CNCT <= 1.: CNCT = 1000. if SPH == "gauss" or SPH == "None" or SPH == "": #TopCmds.MSG("Please set spnam1") TopCmds.PUTPAR("SPNAM 42", "ramp.100") TopCmds.XCMD("spnam42") SPH = (TopCmds.GETPAR2("SPNAM 42")) SPH.join() #TopCmds.MSG("Please set spnam0") if SPX == "gauss" or SPX == "None" or SPX == "": #TopCmds.MSG("Please set spnam11") TopCmds.PUTPAR("SPNAM 43", "square.100") TopCmds.XCMD("spnam43") SPX = (TopCmds.GETPAR2("SPNAM 43")) SPX.join() 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)],\ ["kHz","","kHz","","us"],\ ["1","1","1","1","1"],\ ["Accept","Close"], ['a','c'], 10) adjust = 20 * (math.log10(float(index[0]) / MaxB1H)) Hamp1 = ampH - adjust 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 #Ramp integration adjustment 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)) Hwatts = dBtoW(Hamp) Nwatts = dBtoW(Namp) value = TopCmds.SELECT("Adjusting the HN CP parameters:",\ "This will set\n 1H power to: " + str('%3.2f' %Hwatts)+ " W\n \ 15N power to: " +str('%3.2f' %Nwatts) + " W",["Update", "Keep Previous"]) if value != 1: TopCmds.PUTPAR("SPdB 42", str('%3.2f' % Hamp)) TopCmds.PUTPAR("SPdB 43", str('%3.2f' % Namp)) TopCmds.PUTPAR("PLdB 42", str('%3.2f' % Hamp)) TopCmds.PUTPAR("PLdB 43", str('%3.2f' % Namp)) TopCmds.PUTPAR("P 25", str('%.2f' % CNCT)) TopCmds.PUTPAR("SPNAM 42", index[1]) TopCmds.PUTPAR("SPNAM 43", index[3])
def CalNCO(): p90C = float(TopCmds.GETPAR("P 1")) ampC = float(TopCmds.GETPAR("PLdB 1")) p90N = float(TopCmds.GETPAR("P 21")) ampN = float(TopCmds.GETPAR("PLdB 3")) MAS = float(TopCmds.GETPAR("CNST 31")) SP = TopCmds.GETPAR2("SPNAM 51") CNCT = float(TopCmds.GETPAR("P 17")) if CNCT <= 1.: CNCT = 3500. if SP == "gauss" or SP == "None" or SP == "": #TopCmds.MSG("Please set spnam2") TopCmds.XCMD("spnam51") SP = (TopCmds.GETPAR2("SPNAM 51")) SP.join() 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", \ ["Carbon B1 field","Nitrogen B1 field","Contact Time(P17)","Ramp Name"],\ [str(CCond),str(NCond),str(CNCT),SP],\ ["kHz","kHz","us",""],\ ["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 #Insert ramp calibration here AvgAmp = IntShape.Integrate(SP) / 100. adjust = 20 * (math.log10(1. / AvgAmp)) Camp = Camp - adjust CNCT = float(index[2]) Nwatts = dBtoW(Namp) Cwatts = dBtoW(Camp) value = TopCmds.SELECT("Adjusting the NC CP parameters:",\ "This will set\n 13C power to: " + str('%3.2f' %Cwatts)+ " W\n \ 15N power to: " +str('%3.2f' %Nwatts) + " W",["Update", "Keep Previous"]) if value != 1: TopCmds.PUTPAR("PLdB 6", str('%3.2f' % Namp)) TopCmds.PUTPAR("PLdB 51", str('%3.2f' % Camp)) TopCmds.PUTPAR("SPdB 51", str('%3.2f' % Camp)) TopCmds.PUTPAR("P 17", str('%3.2f' % CNCT)) TopCmds.PUTPAR("SPNAM 51", SP)
def CalHC(): p90H = float(TopCmds.GETPAR("P 3")) ampH = float(TopCmds.GETPAR("PLdB 2")) p90C = float(TopCmds.GETPAR("P 1")) ampC = float(TopCmds.GETPAR("PLdB 1")) MAS = float(TopCmds.GETPAR("CNST 31")) CNCT = float(TopCmds.GETPAR("P 15")) SPH = TopCmds.GETPAR2("SPNAM 40") SPX = TopCmds.GETPAR2("SPNAM 41") if CNCT <= 1.: CNCT = 1000. if SPH == "gauss" or SPH == "None" or SPH == "": #TopCmds.MSG("Please set spnam40") TopCmds.PUTPAR("SPNAM 40", "ramp.100") TopCmds.XCMD("spnam40") SPH = (TopCmds.GETPAR2("SPNAM 40")) SPH.join() if SPX == "gauss" or SPX == "None" or SPX == "": #TopCmds.MSG("Please set spnam10") TopCmds.PUTPAR("SPNAM 41", "square.100") TopCmds.XCMD("spnam41") SPX = (TopCmds.GETPAR2("SPNAM 41")) SPX.join() MaxB1H = 1000000. / 4. / p90H MaxB1C = 1000000. / 4. / p90C #find the channel with the lowest B1 if MaxB1C < MaxB1H: Ratio = int(math.floor(MaxB1C / MAS)) #TopCmds.MSG(str(Ratio)) 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),SPH,str(CCond),SPX,str(CNCT)],\ ["kHz","","kHz","","us"],\ ["1","1","1","1","1"],\ ["Accept","Close"], ['a','c'], 10) adjust = 20 * (math.log10(float(index[0]) / MaxB1H)) Hamp1 = ampH - adjust 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 #Ramp integration adjustment AvgAmp = IntShape.Integrate(index[3]) / 100. adjust = 20 * (math.log10(1. / AvgAmp)) Camp = Camp1 - adjust CNCT = float(index[4]) Hwatts = dBtoW(Hamp) Cwatts = dBtoW(Camp) value = TopCmds.SELECT("Adjusting the HC CP parameters:",\ "This will set\n 1H power to: " + str('%3.2f' %Hwatts)+ " W\n \ 13C power to: " +str('%3.2f' %Cwatts) + " W",["Update", "Keep Previous"]) if value != 1: TopCmds.PUTPAR("SPdB 40", str('%3.2f' % Hamp)) TopCmds.PUTPAR("SPdB 41", str('%3.2f' % Camp)) TopCmds.PUTPAR("PLdB 40", str('%3.2f' % Hamp)) TopCmds.PUTPAR("PLdB 41", str('%3.2f' % Camp)) TopCmds.PUTPAR("P 15", str('%3.2f' % CNCT)) TopCmds.PUTPAR("SPNAM 40", index[1]) TopCmds.PUTPAR("SPNAM 41", index[3])
def HC(units): #44,45 p90H = float(TopCmds.GETPAR("P 3")) ampH = float(TopCmds.GETPAR("PLdB 2")) p90C = float(TopCmds.GETPAR("P 1")) ampC = float(TopCmds.GETPAR("PLdB 1")) MAS = float(TopCmds.GETPAR("CNST 31")) SPH = TopCmds.GETPAR2("SPNAM 44") SPH0 = TopCmds.GETPAR2("SPNAM 40") CNCT = float(TopCmds.GETPAR("P 44")) CNCT0 = float(TopCmds.GETPAR("P 15")) MaxB1H = 1000000. / 4. / p90H MaxB1C = 1000000. / 4. / p90C if CNCT <= 1.00: CNCT = CNCT0 if SPH == "gauss" or SPH == "None" or SPH == "": SPH = SPH0 TopCmds.PUTPAR("SPNAM 44", SPH) TopCmds.XCMD("spnam44") SPH = (TopCmds.GETPAR2("SPNAM 44")) SPH.join() Hav = IntShape.Integrate(SPH) Hav0 = IntShape.Integrate(SPH0) Hint = 0.01 * ((Hav)**2) / Hav0 #TopCmds.MSG("Hint "+str(Hint)) Hamp0 = float(TopCmds.GETPAR("SPdB 40")) Camp0 = float(TopCmds.GETPAR("SPdB 41")) B1H = MaxB1H * Hint * math.pow(10, (ampH - Hamp0) / 20.) B1C = MaxB1C * math.pow(10, (ampC - Camp0) / 20.) index = TopCmds.INPUT_DIALOG("H-C CP", "Contact and Ramp", \ ["Proton B1 Field","H Ramp","Carbon B1 Field","Contact Time(P44)"],\ [str('%3.0f' %B1H),SPH,str('%3.0f' %B1C),str(CNCT)],\ ["kHz","","kHz","us"],\ ["1","1","1","1"],\ ["Accept","Close"], ['a','c'], 10) SP = index[1] CNCT = float(index[3]) adjust = 20 * (math.log10(float(index[0]) / MaxB1H)) Hamp1 = ampH - adjust AvgAmp = IntShape.Integrate(index[1]) / 100. adjust = 20 * (math.log10(1. / AvgAmp)) Hamp = Hamp1 - adjust adjust = 20 * (math.log10(float(index[2]) / MaxB1C)) Camp = ampC - adjust if units == "W": Hamp = Setup.dBtoW(Hamp) Camp = Setup.dBtoW(Camp) value = TopCmds.SELECT("Adjusting the CH 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: TopCmds.PUTPAR("SP" + units + " 44", str('%3.2f' % Hamp)) TopCmds.PUTPAR("SP" + units + " 45", str('%3.2f' % Camp)) TopCmds.PUTPAR("PL" + units + " 44", str('%3.2f' % Hamp)) TopCmds.PUTPAR("PL" + units + " 45", str('%3.2f' % Camp)) TopCmds.PUTPAR("P 44", str('%3.2f' % CNCT)) TopCmds.PUTPAR("SPNAM 44", SP)
def Nucl(): Amino=[] aa=[] Appm=[] Bppm=[] App=[] Bpp=[] suffix=[] Nuclei=TopCmds.SELECT("Select matching condidtion for which nuclei?",\ "Calculate match for which nuclei?",\ ["Aliph","CO-Cali","CA-CB","CB-CG","CG-CD","CO-CA","CO-CB","CO-CG","CO-CD"]) #0,1 #CA-CB if Nuclei==2 or Nuclei==0 : Amino="A","R","D","N","C","E","Q","H","I","L","K","M","F","P","S","T","W","Y","V" #ALA, ARG, ASP, ASN, CYS, GLU, GLN, HIS, ILE, LEU, LYS, MET, PHE, PRO, SER, THR, TRP, TYR, VAL) # [w/o GLY] Appm=53.16,56.95,54.52,53.43,57.43,57.42,56.62,56.37,61.59,55.65,56.84,56.16,58.25,63.30,58.57,62.15,57.71,58.02,62.48 Bppm=18.90,30.66,40.70,38.66,34.15,30.07,29.10,29.95,38.58,42.37,32.83,32.90,39.95,31.81,63.80,69.64,30.16,39.16,32.66 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=2 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cacb" #CB-CG if Nuclei==3 or Nuclei==0 : Amino="R","E","Q","I","I","L","K","M","P","T","V" # ARG GLU GLN IG1 IG2 LEU LYS MET PRO THR VAL) Appm=30.66,30.07,29.10,38.58,38.58,42.37,32.83,32.90,31.81,69.64,32.66 Bppm=27.31,36.01,33.72,27.65,17.36,26.77,24.91,32.07,27.14,21.44,21.38 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=3 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cbcg" #CG-CD if Nuclei==4 or Nuclei==0 : Amino="R","I","I","L","K","P" Appm=27.31,27.65,17.36,26.77,24.91,27.14 Bppm=43.10,13.41,13.41,24.73,28.78,50.28 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=4 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cgcd" #CO-CA if Nuclei==5 or Nuclei==1 : Amino="A","R","D","N","C","E","Q","G","H","I","L","K","M","F","P","S","T","W","Y","V" # ALA ARG ASP ASN CYS GLU GLN GLY HIS ILE LEU LYS MET PHE PRO SER THR TRP TYR VAL) Appm=53.16,56.95, 54.52, 53.43, 57.43, 57.42, 56.62, 45.33, 56.37, 61.59, 55.65, 56.84, 56.16, 58.25, 63.30, 58.57, 62.15, 57.71, 58.02, 62.48 Bppm=177.8,176.49,176.41,175.16,174.78,176.93,176.39,174.04,175.19,175.82,176.97,176.46,176.30,175.49,176.70,174.53,174.60,176.10,175.39,175.69 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=5 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-coca" #CO-CB if Nuclei==6 or Nuclei==1 : Amino="A","R","D","N","C","E","Q","H","I","L","K","M","F","P","S","T","W","Y","V" # ALA ARG ASP ASN CYS GLU GLN HIS ILE LEU LYS MET PHE PRO SER THR TRP TYR VAL # [w/o GLY] Appm=177.8,176.49, 176.41,175.16,174.78,176.93,176.39,175.19,175.82,176.97,176.46,176.30,175.49,176.70,174.53,174.60,176.10,175.39,175.69 Bppm=18.90,30.66, 40.70, 38.66, 34.15, 30.07, 29.10, 29.95, 38.58, 42.37, 32.83, 32.90, 39.95, 31.81, 63.80, 69.64, 30.16, 39.16, 32.66 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=6 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cocb" #CO-CG if Nuclei==7 or Nuclei==1 : Amino="R","E","Q","I","I","L","K","M","P","T","V" # ARG GLU GLN IG1 IG2 LEU LYS MET PRO THR VAL Appm=176.49,176.93,176.39,175.82,175.82,176.97,176.46,176.30,176.70,174.60,175.69 Bppm=27.31,36.01, 33.72, 27.65, 17.36, 26.77, 24.91, 32.07, 27.14, 21.44, 21.38 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=7 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cocg" #CO-CD if Nuclei==8 or Nuclei==1 : Amino="R","I","L","K","P" Appm=176.49,175.82,176.97,176.46,176.70 Bppm=43.10, 13.41, 24.73, 28.78, 50.28 aa.extend(list(Amino)) App.extend(list(Appm)) Bpp.extend(list(Bppm)) if Nuclei!=8 : for i in range(len(aa)-len(Amino), len(aa)): aa[i]=str(aa[i])+"-cocd" # Now I want to sort into ABC order name=aa Count=len(aa) for i in range(Count): for j in range(Count): if aa[j] > aa[i]: aa[j], aa[i] = aa[i], aa[j] App[j], App[i] = App[i], App[j] Bpp[j], Bpp[i] = Bpp[i], Bpp[j] return aa, App, Bpp
def CMatch(): #Nuc is a string such as 1H or 13C Nucs=NUC.list() for i in range(len(Nucs)): if Nucs[i]=='13C':Frq=fq.fq(Nucs[i],i+1) p90 =pul.GetPar('pC90',"") MAS =pul.GetPar('MAS',"") NomRF = 1000000./4./p90 nomatch=[] Af=[] Bf=[] Ap=[] Bp=[] Condition=[] mfaa=[] #message=[] aa, Ap, Bp = Nucl() hits=0 mm=1 SPOFF=pul.GetPar('oCdrm',"")-Frq.offs #TopCmds.MSG(str(SPOFF)) for i in range(len(aa)): Af.append(Frq.ppm2offs(Ap[i])-SPOFF) Bf.append(Frq.ppm2offs(Bp[i])-SPOFF) m=1 Match=m*MAS-math.fabs(Af[i])-(math.fabs(Bf[i])) #if Match < 0 : # m=2; mm=2 # Match=m*MAS-(math.fabs(Af[i]))-(math.fabs(Bf[i])) if Match < 0: nomatch.append(aa[i]) if Match >= 0: hits=hits+1 if len(nomatch) > 0 : TopCmds.MSG("Cannot find match conditions for:\n "\ + str(nomatch)+ "\n at this carrier or spinning frequency") if hits == 0: TopCmds.MSG("Cannot find any match conditions, please consider changing frequencies") TopCmds.EXIT() Upper=0 Lower=MAS*2 NotCount=len(nomatch) #Determine if we want to skip for i in range(len(aa)): skip=0 found=0 for j in range(NotCount): if nomatch[j] == aa[i]: skip=1 if not skip: for n in range(int(MAS*2)): if not found : WAeff = math.sqrt(Af[i]*Af[i]+float(n*n)) WBeff = math.sqrt(Bf[i]*Bf[i]+float(n*n)) Match=(mm*MAS)-WAeff-WBeff #mm is the match multiplier if Match <= 0.0: found=1 mfaa.append(aa[i]) Condition.append(n) if n > Upper : Upper=n if n < Lower : Lower=n if not found: nomatch.append(aa[i]) #Condition.append('N/A') #TopCmds.MSG(str(nomatch)) #TopCmds.MSG(aa[i]+ " " + str(Ap[i]) + " " +str(Bp[i]) + " " + str(Upper) + " " +str(Lower)) if len(nomatch) > 0 : TopCmds.MSG("Cannot find match conditions for:\n "\ + str(nomatch)+ "\n at this carrier or spinning frequency") # Report average, deviation and the extremes, # Offer a detailed report after a dialog. # These numbers are used to generate a wave file Avg=0.0 Dev=0.0 for i in range(len(Condition)): Avg=Avg+float(Condition[i]) Avg=Avg/float(len(Condition)) for i in range(len(Condition)): Dev=Dev+(float(Condition[i])-Avg)**2 Dev=math.sqrt(Dev/float(len(Condition)-1)) Continue=TopCmds.SELECT("Scaling",\ "The mean match is %.2f Hz" % Avg \ + " \n With a deviation of %.2f Hz" % Dev \ + "\n with a maximum at %i Hz " % Upper\ + "\n and a minimum at %i Hz " % Lower\ ,["Details","Proceed"]) #0,1 #TopCmds.MSG(str(SeeMore)) if not Continue: for i in range(int(math.ceil(len(mfaa)/20.))): message="Here is set #"+str(i+1)+" of the match conditions alphabetically by nucleus\n\n" for j in range(i*20,min((i+1)*20,len(mfaa))): message=message+str(mfaa[j])+": "+ str(Condition[j]) + "Hz\n " TopCmds.MSG(message) # Now I want to sort into order by increasing match for i in range(len(aa)): for j in range(len(aa)): if Condition[j] > Condition[i]: Condition[j], Condition[i] = Condition[i], Condition[j] mfaa[j], mfaa[i] = mfaa[i], mfaa[j] for i in range(int(math.ceil(len(mfaa)/20.))): message="Here is set #"+str(i+1)+" of the match conditions by match\n\n" for j in range(i*20,min((i+1)*20,len(mfaa))): message=message + str(Condition[j]) + " Hz : "+str(mfaa[j])+"\n " TopCmds.MSG(message) #TopCmds.MSG(str(NomRF)) # Finally I'm going to pass the result back # It is best to do this as a percentage to suggest a pulse shape. # I need a delta, beta, and scale. #TopCmds.MSG(str(Avg)) AvgPC =100.*Avg/NomRF DeltaPC=100.*(Upper-Lower)/NomRF BetaPC =100.*Dev/NomRF #return AvgPC, DeltaPC, BetaPC return Avg, Upper-Lower, Dev
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")