def abort(Home, Source, winfil): if winfil ==0 : TopCmds.SET_SELECTED_WIN(Source) TopCmds.CLOSEWIN(TopCmds.CURDATA()) TopCmds.SET_SELECTED_WIN(Home) TopCmds.EXIT() if winfil ==1 : TopCmds.RE(Source) TopCmds.CLOSEWIN(TopCmds.CURDATA()) TopCmds.RE(Home) TopCmds.EXIT()
def name(input): Cname = str("EXPORT_C_C" + input[4] + "_B" + input[5] + "_MAS" + input[2] + "_np" + input[3] + ".wave") Nname = str("EXPORT_N_C" + input[4] + "_B" + input[6] + "_MAS" + input[2] + "_np" + input[3] + ".wave") Cwave = pul.pulDict['sCexp'] Nwave = pul.pulDict['sNexp'] Wave = str(INPUT_DIALOG("EXPORT Files", "", ["C File = ","C Wave =","N File = ","N Wave =",],\ [Cname,Cwave,Nname,Nwave],["","","",""],["1","1","1","1"],["Accept","Close"], [spc,ret], 30)) if wave == None: TopCmds.EXIT() Files = Wave[8:len(Wave) - 21] #get rid of Java formatting i = Files.find(",") ii = Files[i + 3:].find(",") + 3 iii = Files[i + ii + 3:].find(",") + 3 Cfile = Files[0:i - 1] Cwave = Files[i + 3:i + ii - 1] Nfile = Files[i + ii + 3:i + ii + iii - 1] Nwave = Files[i + ii + iii + 3:] #MSG( Cfile ) #MSG( Cwave ) #MSG( Nfile ) #MSG( Nwave ) pul.SetPar(str(Cwave), str(Cfile), "") pul.SetPar(str(Nwave), str(Nfile), "") return Cfile, Nfile
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 dialog(): input = TopCmds.INPUT_DIALOG("DUOinput", "", \ ["RF field = ", "MAS = ","steps" ,"B = ", "C = "], \ ["100","10000","100","3.5","0.5"],\ ["kHz","Hz","","lit=3.5","lit=0.5",], ["1", "1", "1", "1", "1"],\ ["Accept","Close"], [spc,ret],10) if input == None: TopCmds.EXIT() return input
def Find_PWdec(Text): while i < len(Text): about = '' if Text[i].find("pcpd") >= 0: type = "PCPD" elif Text[i].find("p31") >= 0: type = "P 31" elif Text[i].find("p63") >= 0: type = "P 63" elif Text[i].find("p62") >= 0: type = "P 62" else: TopCmds.MSG("File for Decoupling not found; Exiting") TopCmds.EXIT()
def name(input): name = str("DUO_C" + input[4] + "_B" + input[3] + "_MAS" + input[1] + "_np" + input[2] + ".wave") Wavename = str( TopCmds.INPUT_DIALOG("DUO File", "", ["Filename = "], [name], [""], ["1"], ["Accept", "Close"], [spc, ret], 30)) if Wavename == None: TopCmds.EXIT() Filename = Wavename[8:len(Wavename) - 21] #get rid of Java formatting #MSG( Filename + ' \n is the file name') return Filename
def dialog(): MAS = TopCmds.GETPAR("CNST 31") #MSG(MAS) input = TopCmds.INPUT_DIALOG("EXPORTinput", "", \ ["13C field ","15N field ","MAS ", "steps in Export Element", "C(Ix+Sx)=CFx", "B Iy", "B Sy", "Initial Phase"],\ ["50","50",str(MAS),"100", "7.0", "0.375", "0.625", "90"],\ ["kHz","kHz","Hz","","","","",""],\ ["1","1", "1", "1", "1", "1", "1", "1"],\ ["Accept","Close"], [spc,ret], 10) if input == None: TopCmds.EXIT() return input
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 dialog(): MAS = pul.GetPar('MAS', "") TauR = float(1000000 / MAS) Data = TopCmds.INPUT_DIALOG("Tangent Ramp Input", "", \ ["Scaling","steps","Ramp (Delta)","Adiabicity (Beta)"],\ ["50","500","20","4"],\ ["%","","%",""],\ ["1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if Data == None: TopCmds.EXIT() return Data
def find_match(input): import math NomRF = 1000 * float(input[0]) MAS = float(input[1]) Ioffs = 1000 * float(input[6]) Soffs = 1000 * float(input[7]) m = 1 Match = m * MAS - Ioffs - Soffs if Match < 0: m = 2 Match = m * MAS - Ioffs - Soffs if Match < 0: TopCmds.MSG("Cannot find match conditions, spinning too slowly") TopCmds.EXIT() found = 0 for n in range(10000): WIeff = math.sqrt(Ioffs * Ioffs + float(n * n)) WSeff = math.sqrt(Soffs * Soffs + float(n * n)) Match = (m * MAS) - WIeff - WSeff #mm is the amplitude in Hz if Match > 0.0: mm = n if Match < 0.0: found = 1 if found == 0: TopCmds.MSG("Match condition not found within 10kHz, aborting") TopCmds.EXIT() YorN = TopCmds.SELECT( "Scaling", "The match condition is around %i Hz \n\n Which scaling should be used?" % mm, ["Calibration", "0.5", "None(1.0)"]) # CONFIRM("Scale Shape Pulse for Match","The amplitude should be approximately %i Hz \n \nUse scaling?" % Match) if YorN < 0: Scale = 1.0 if YorN == 0: Scale = float(Match) / NomRF if YorN == 1: Scale = 0.5 if YorN == 2: Scale = 1.0 return Scale
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
def name_confirm(): adbname = pul.GetPar('sCadb', "") if adbname == "gauss": adbname = "TanhTan" SP = pul.pulDict['sCadb'] Wave = str(TopCmds.INPUT_DIALOG("Adiabatic TOBSY", "",\ ["SP File = ","SP Wave =",],\ [adbname,SP],["",""],["1","1"],["Accept","Close"], [spc,ret], 30)) if Wave == None: TopCmds.EXIT() Files = Wave[8:len(Wave) - 21] #get rid of Java formatting i = Files.find(",") File = Files[0:i - 1] SP = Files[i + 3:] pul.SetPar(SP, str(File), "") pul.SetPar('sCadb', File, "")
def LoadDefault(units): # # Read the Prosol data (Defaults remain if no Prosol) # Still under development :( p90H = 2.5 p90C = 3.0 p90N = 5.0 if units == "W": ampH = 100. ampC = 200. ampN = 400. else: ampH = 0. ampC = 0. ampN = 0. MAS = 10000 #Read the Prosol data if it exists #XCMD('rprosol') #p90H, p90C, p90N, ampH, ampC, ampN, MAS = ReadHPFromData(units) index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Pulse Widths and Power", \ ["1H 90 pw","1H ampl","13C 90 pw","13C ampl","15N 90 pw","15N ampl","MAS"],\ [str(p90H),str(ampH),str(p90C),str(ampC),str(p90N),str(ampN),str(MAS)],\ ["us",units,"us",units,"us",units," Hz"],\ ["1","1","1","1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index == None: TopCmds.EXIT() p90H = float(index[0]) ampH = float(index[1]) p90C = float(index[2]) ampC = float(index[3]) p90N = float(index[4]) ampN = float(index[5]) MAS = float(index[6]) TauR = 1000000. / MAS PutPars(p90H, ampH, p90C, ampC, p90N, ampN, MAS, units)
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]
def find_file(dirs, name): found = 0 i = 0 path = '' while i <= (len(dirs) - 1): #print (dirs[i], found ) if found == 0: search = str(dirs[i]) + '/' + str(name) """ TopCmds.MSG("This is here to remind you that the os package is removed") found=1 path=search """ if os.path.exists(search) == 1: found = 1 path = search i = i + 1 if found == 0: TopCmds.MSG("File named " + name + " not found\n Exiting") TopCmds.EXIT() return path
def load_templt(templt, expname, stan_dir): """ Load Topspin parameter set from stand_dir and creates a new dataset. Args: templt: Name of topspin parameter set expname: Name of the new dataset stand_dir: Directory from where Topspin stores new data set """ try: TC.NEWDATASET([expname, '1', '1', stan_dir]) TC.RE([expname, '1', '1', stan_dir], 'y') TC.XCMD('rpar %s all' % templt) except: TC.MSG( '''You need to define the parameter set "%s" defining the correct routing to continue. First define the correct routing using edasp. Then save the parmeterset using: wpar %s all ''' % (templt, templt)) TC.EXIT()
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, "")
def LoadFromData(units): p90H, p90C, p90N, ampH, ampC, ampN, MAS = ReadHPFromData(units) index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Pulse Widths and Power", \ ["1H 90 pw","1H ampl","13C 90 pw","13C ampl","15N 90 pw","15N ampl","MAS"],\ [str('%.2f' %p90H),str('%.2f' %ampH),str('%.2f' %p90C),str('%.2f' %ampC),\ str('%.2f' %p90N),str('%.2f' %ampN),str('%.2f' %MAS)],\ ["us",units,"us",units,"us",units," Hz"],\ ["1","1","1","1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index == None: TopCmds.EXIT() p90H = float(index[0]) ampH = float(index[1]) p90C = float(index[2]) ampC = float(index[3]) p90N = float(index[4]) ampN = float(index[5]) MAS = float(index[6]) TauR = 1000000. / MAS PutPars(p90H, ampH, p90C, ampC, p90N, ampN, MAS, 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 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 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 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 CMatch(): #Nuc is a string such as 1H or 13C Nucs = NUC.list() if Nucs[0] == "13C": Frq = fq.O1() elif Nucs[1] == "13C": Frq = fq.O2() elif Nucs[2] == "13C": Frq = fq.O3() p90 = float(TopCmds.GETPAR("P 1")) MAS = float(TopCmds.GETPAR("CNST 31")) NomRF = 1000000. / 4. / p90 nomatch = [] Af = [] Bf = [] Ap = [] Bp = [] Condition = [] mfaa = [] #message=[] # It should default to CA-CB matching for DREAM, and CA-CO for R2T # I'm not sure the best way to select these but I'm putting it in as a dialog aa, Ap, Bp = Nucl() #TopCmds.MSG(str(aa)) #TopCmds.MSG(str(Ap)) #TopCmds.MSG(str(Bp)) # Now we'll convert the ppm averages from above into frequencies hits = 0 mm = 1 SPOFF = float(TopCmds.GETPAR("SPOFFS 5")) for i in range(len(aa)): Af.append(SPOFF + Frq.ppm2offs(Ap[i])) Bf.append(SPOFF + Frq.ppm2offs(Bp[i])) # The offsets should be less than 1/2 (or 1*) the MAS frequency, or we can't match. # We will store a list for those aa's that we can't match. 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])) #TopCmds.MSG(str(Match)+" "+str(math.fabs(Af[i]))+" "+str(math.fabs(Bf[i]))) if Match < 0: nomatch.append(aa[i]) if Match >= 0: hits = hits + 1 #TopCmds.MSG(str(len(nomatch))) 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() # Now, we want to determine the matches and store the results and extrema, # but not for things we know can't be matched 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(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") # Now I want to report what we've found. I'll start with an average, deviation and the extremes, # And offer a detailed report after a dialog. # I guess these numbers could be 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)) #TopCmds.MSG("DEV(DONE): " + str(Dev)) #TopCmds.MSG(str(Avg)+":Average \n"+str(Dev) +":StDev") 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(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(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
def PPDIM(): ppdim = 1 aqseq = "" ph2D = "" ph3D = "" ph4D = "" Nucl1D = "" Nucl2D = "" Nucl3D = "" Nucl4D = "" #Acquisition dimension from acq file Nucl1D = "".join(letter for letter in Nuc.list()[0] if letter.isalpha()) #TopCmds.MSG(Nucl1D) pp = TopCmds.GETPAR("PULPROG") dir = get_dir("PP_DIRS") Name = find_file(dir, pp) #TopCmds.MSG(Name) if os.path.exists(Name) == 1: f = open(Name, 'r') text = f.readlines() f.close() else: TopCmds.MSG("Pulse Program not found: Exiting") TopCmds.EXIT() # Determine pulse sequence dimension and TPPI phases for line in text: lines = line.rstrip() if lines.find("aqseq") >= 0: #Check for comments if lines.find(";") < 0: aqseq = "".join(letter for letter in lines if letter.isdigit()) elif lines.find(";") > lines.find("aqseq"): aqseq = "".join(letter for letter in lines if letter.isdigit()) if lines.find("F1PH") >= 0 or lines.find("F1EA") >= 0: if lines.find("F1PH") >= 0: search = "F1PH" if lines.find("F1EA") >= 0: search = "F1EA" #Check for comments if lines.find(";") < 0: if ppdim < 2: ppdim = 2 ph2D = find_phase(lines, search) ph2Dp = ph2D + ")" ph2D = ph2D + " " elif lines.find(";") > lines.find(search): if ppdim < 2: ppdim = 2 ph2D = find_phase(lines, search) ph2Dp = ph2D + ")" ph2D = ph2D + " " if lines.find("F1QF") >= 0: #Check for comments if lines.find(";") < 0: if ppdim < 2: ppdim = 2 Nucl2D = "_" elif lines.find(";") > lines.find("F1QF"): if ppdim < 2: ppdim = 2 Nucl2D = "_" if lines.find("F2PH") >= 0 or lines.find("F2EA") >= 0: if lines.find("F2PH") >= 0: search = "F2PH" if lines.find("F2EA") >= 0: search = "F2EA" #Check for comments if lines.find(";") < 0: if ppdim < 3: ppdim = 3 ph3D = find_phase(lines, search) ph3Dp = ph3D + ")" ph3D = ph3D + " " elif lines.find(";") > lines.find(search): if ppdim < 3: ppdim = 3 ph3D = find_phase(lines, search) ph3Dp = ph3D + ")" ph3D = ph3D + " " if lines.find("F2QF") >= 0: #Check for comments if lines.find(";") < 0: if ppdim < 3: ppdim = 3 Nucl3D = "_" elif lines.find(";") > lines.find("F2QF"): if ppdim < 3: ppdim = 3 Nucl3D = "_" if lines.find("F3PH") >= 0 or lines.find("F3EA") >= 0: if lines.find("F3PH") >= 0: search = "F3PH" if lines.find("F3EA") >= 0: search = "F3EA" #Check for comments if lines.find(";") < 0: if ppdim < 4: ppdim = 4 ph4D = find_phase(lines, search) ph4Dp = ph4D + ")" ph4D = ph4D + " " elif lines.find(";") > lines.find("F3PH"): if ppdim < 4: ppdim = 4 ph4D = find_phase(lines, search) ph4Dp = ph4D + ")" ph4D = ph4D + " " if lines.find("F3QF") >= 0: #Check for comments if lines.find(";") < 0: if ppdim < 4: ppdim = 4 Nucl4D = "_" elif lines.find(";") > lines.find("F3QF"): if ppdim < 4: ppdim = 4 Nucl4D = "_" #TopCmds.MSG(ph2D+":2D\n"+ph3D+": 3D\n"+ph4D+": 4D") #TopCmds.MSG(str(ppdim)+" ppdim\n"+str(ph2D)+" ph2D") # From TPPI phases make a string corresponding to pulse nucleus for line in text: lines = line.rstrip() if ppdim >= 2: if lines.find(ph2D) >= 0 and Nucl2D == "": #TopCmds.MSG(lines) Nucl2D = find_nuc(lines, ph2D) #TopCmds.MSG(Nucl2D) elif lines.find(ph2Dp) >= 0 and Nucl2D == "": #TopCmds.MSG(lines) Nucl2D = find_nuc(lines, ph2Dp) #TopCmds.MSG(Nucl2D) if ppdim >= 3: if lines.find(ph3D) >= 0 and Nucl3D == "": #TopCmds.MSG(lines) Nucl3D = find_nuc(lines, ph3D) #TopCmds.MSG(Nucl3D) elif lines.find(ph3Dp) >= 0 and Nucl3D == "": #TopCmds.MSG(lines) Nucl3D = find_nuc(lines, ph3Dp) #TopCmds.MSG(Nucl3D) if ppdim >= 4: if lines.find(ph4D) >= 0 and Nucl4D == "": #TopCmds.MSG(lines) Nucl4D = find_nuc(lines, ph4D) elif lines.find(ph4Dp) >= 0 and Nucl4D == "": #TopCmds.MSG(lines) Nucl4D = find_nuc(lines, ph4Dp) #TopCmds.MSG(str(ppdim)+" :ppdim\n"+Nucl2D+" :Nucl2D\n"+Nucl3D+" :Nucl3D\n"+Nucl4D+" :Nucl4D\n") # Translate, Concatenate and return the Nucls if ppdim >= 4 and Nucl4D.isdigit(): Nucl4D = "".join(letter for letter in Nuc.list()[int(Nucl4D) - 1] if letter.isalpha()) if ppdim >= 3 and Nucl3D.isdigit(): Nucl3D = "".join(letter for letter in Nuc.list()[int(Nucl3D) - 1] if letter.isalpha()) if ppdim >= 2 and Nucl2D.isdigit(): Nucl2D = "".join(letter for letter in Nuc.list()[int(Nucl2D) - 1] if letter.isalpha()) #TopCmds.MSG(Nucl1D+" :Nucl1D\n"+Nucl2D+" :Nucl2D\n"+Nucl3D+" :Nucl3D\n"+Nucl4D+" :Nucl4D\n") if ppdim == 4: EXP = Nucl4D + Nucl3D + Nucl2D aqseq = "4321" if ppdim == 3: if aqseq == "321": EXP = Nucl3D + Nucl2D if aqseq == "312": EXP = Nucl2D + Nucl3D if aqseq == "": EXP = Nucl3D + Nucl2D aqseq = "321" if ppdim == 2: EXP = Nucl2D aqseq = "21" return ppdim, aqseq, Nucl1D + EXP
def NCO(MAS0,MAS,units): p90X=float(TopCmds.GETPAR("P 1")) ampX=float(TopCmds.GETPAR("PL"+units+" 1")) ampXdB=float(TopCmds.GETPAR("PLdB 1")) ampXCP0=float(TopCmds.GETPAR("SP"+units+" 51")) ampXCP0dB=float(TopCmds.GETPAR("SPdB 51")) #ampXCP0=float(TopCmds.GETPAR("PL"+units+" 50")) #ampXCP0dB=float(TopCmds.GETPAR("PLdB 50")) SPX=TopCmds.GETPAR2("SPNAM 51") p90Y=float(TopCmds.GETPAR("P 21")) ampY=float(TopCmds.GETPAR("PL"+units+" 3")) ampYdB=float(TopCmds.GETPAR("PLdB 3")) ampYCP0=float(TopCmds.GETPAR("PL"+units+" 6")) ampYCP0dB=float(TopCmds.GETPAR("PLdB 6")) SPY="None" avgY0=1. # Get the integration before possibly changing the shape. if SPX != "None" and SPX != None: avgX0=IntShape.Integrate(SPX)/100. if SPX == "None" or SPX == None: avgX0=1. CNCT=float(TopCmds.GETPAR("P 17")) #Interact with user about MAS and power levels, likely not needed params = TopCmds.INPUT_DIALOG("NCO CP MAS adjustment", "Nitrogen Carbonyl Cross Polarization", \ ["Old MAS rate","New MAS rate","Old 13C power","Old 15N power","Contact Time(P16)","C-Ramp"],\ [str(MAS0),str(MAS),str(ampXCP0),str(ampYCP0),str(CNCT),SPX],\ ["kHz","kHz",units,units,"us",""],\ ["1","1","1","1","1","1"],\ ["Accept","Close"], ['a','c'], 10) if params == None: TopCmds.EXIT() params.append(SPY) # 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]))) if SPX != "None" and SPX != None: avgX0=IntShape.Integrate(SPX)/100. if SPX == "None" or SPX == None: avgX0=1. pulses=p90X,ampXdB,p90Y,ampYdB,avgX0,avgY0 SelectorText="Adjust the NCA CP parameters:","Calculate New Power Level for:",\ ["Carbon","Nitrogen","Both"] ampXCPdB, ampYCPdB = FindMatch(params,pulses,SelectorText) if units == "W": ampXCP=Setup.dBtoW(ampXCPdB) ampYCP=Setup.dBtoW(ampYCPdB) 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: TopCmds.PUTPAR("PLdB 51",str('%3.2f' %ampXCPdB)) TopCmds.PUTPAR("SPdB 51",str('%3.2f' %ampXCPdB)) TopCmds.PUTPAR("PLdB 6",str('%3.2f' %ampYCPdB)) TopCmds.PUTPAR("P 17" ,str('%3.2f' %CNCT)) TopCmds.PUTPAR("SPNAM 51",SPX)
def HN(MAS0,MAS,units): p90H=float(TopCmds.GETPAR("P 3")) ampH=float(TopCmds.GETPAR("PL"+units+" 2")) ampHdB=float(TopCmds.GETPAR("PLdB 2")) ampHCP0=float(TopCmds.GETPAR("SP"+units+" 42")) ampHCP0dB=float(TopCmds.GETPAR("SPdB 42")) #ampHCP0=float(TopCmds.GETPAR("PL"+units+" 42")) #ampHCP0dB=float(TopCmds.GETPAR("PLdB 42")) SPH=TopCmds.GETPAR2("SPNAM 42") p90X=float(TopCmds.GETPAR("P 21")) ampX=float(TopCmds.GETPAR("PL"+units+" 3")) ampXdB=float(TopCmds.GETPAR("PLdB 3")) ampXCP0=float(TopCmds.GETPAR("SP"+units+" 43")) ampXCP0dB=float(TopCmds.GETPAR("SPdB 43")) #ampXCP0=float(TopCmds.GETPAR("PL"+units+" 43")) #ampXCP0dB=float(TopCmds.GETPAR("PLdB 43")) SPX=TopCmds.GETPAR2("SPNAM 43") CNCT=float(TopCmds.GETPAR("P 25")) #Interact with user about MAS and power levels, likely not needed params = TopCmds.INPUT_DIALOG("HN CP MAS adjustment", "Proton Nitrogen Cross Polarization", \ ["Old MAS rate","New MAS rate","Old 15N power","Old 1H power","Contact Time(P15)","H-Ramp","N-Ramp"],\ [str(MAS0),str(MAS),str(ampXCP0),str(ampHCP0),str(CNCT),SPH,SPX],\ ["kHz","kHz",units,units,"us","",""],\ ["1","1","1","1","1","1","1"],\ ["Accept","Close"], ['a','c'], 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]))) if SPH != "None" and SPH != None: avgH0=1. avgH0=IntShape.Integrate(SPH)/100. if SPX != "None" and SPX != None: avgX0=1. avgX0=IntShape.Integrate(SPX)/100. pulses=p90H,ampHdB,p90X,ampXdB,avgH0,avgX0 SelectorText="Adjust the HN CP parameters:","Calculate New Match for:",\ ["Proton","Nitrogen","Maximum for Both"] ampHCPdB, ampXCPdB = FindMatch(params,pulses,SelectorText) if units == "W": ampXCP=Setup.dBtoW(ampXCPdB) ampHCP=Setup.dBtoW(ampHCPdB) 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: TopCmds.PUTPAR("PLdB 42",str('%3.2f' %ampHCPdB)) TopCmds.PUTPAR("SPdB 42",str('%3.2f' %ampHCPdB)) TopCmds.PUTPAR("PLdB 43",str('%3.2f' %ampXCPdB)) TopCmds.PUTPAR("SPdB 43",str('%3.2f' %ampXCPdB)) TopCmds.PUTPAR("P 25" ,str('%3.2f' %CNCT)) TopCmds.PUTPAR("SPNAM 42",SPH) TopCmds.PUTPAR("SPNAM 43",SPX)
def FindMatch(params,pulses,Dia): p90H,ampHdB,p90X,ampXdB,avgH0,avgX0=pulses MAS0 =float(params[0]) MAS =float(params[1]) ampXCP0dB=float(params[2]) ampHCP0dB=float(params[3]) CNCT =float(params[4]) SPH =params[5] SPX =params[6] avgH=1. avgX=1. if SPH != "None" and SPH != None: avgH=IntShape.Integrate(SPH)/100. if SPH == "None" or SPH == None: avgH=1. if SPX != "None" and SPX != None: avgX=IntShape.Integrate(SPX)/100. if SPX == "None" or SPX == None: avgX=1. MaxB1H = 1000000./4./p90H MaxB1X = 1000000./4./p90X HCPpw0=(p90H/avgH0)*(math.pow(10,((ampHCP0dB-ampHdB)/20.))) XCPpw0=(p90X/avgX0)*(math.pow(10,((ampXCP0dB-ampXdB)/20.))) HB1_0=1000000./HCPpw0/4. XB1_0=1000000./XCPpw0/4. HR0=HB1_0/MAS0 XR0=XB1_0/MAS0 ### Choices for adjusting the match ### value = TopCmds.SELECT(Dia[0],Dia[1],Dia[2]) if value == 0: XB1=XB1_0 if HB1_0 > XB1_0 : HB1=XB1_0+MAS if HB1_0 <= XB1_0 : HB1=XB1_0-MAS HR=HB1/MAS XR=XB1/MAS elif value == 1: HB1=HB1_0 if HB1_0 > XB1_0 : XB1=HB1_0-MAS if HB1_0 <= XB1_0 : XB1=HB1_0+MAS HR=HB1/MAS XR=XB1/MAS elif value == 2: HB1=HR0*MAS XB1=XR0*MAS HR=HR0 XR=XR0 # If we are slowing down, keep CP levels similar to previous if MAS0 < MAS: if XB1 <= HB1: while XB1 <= XB1_0 : XR=XR+1 XB1=XR*MAS HR=HR+1 if XB1 >> HB1: while HB1 <= HB1_0 : HR=HR+1 HB1=HR*MAS XR=XR+1 XR=XR-1 #the above should always go one step too far HR=HR-1 XB1=XR*MAS HB1=HR*MAS else: TopCmds.EXIT() # Don't allow feilds higher than max while XB1 > MaxB1X : HR=HR-1 XR=XR-1 HB1=HR*MAS XB1=XR*MAS while HB1 > MaxB1H : HR=HR-1 XR=XR-1 HB1=HR*MAS XB1=XR*MAS adjust=20*(math.log10(HB1/HB1_0)) ampHCPdB = ampHCP0dB-adjust adjust=20*(math.log10(avgH/avgH0)) #in case there is a Ramp change ampHCPdB = ampHCP0dB-adjust adjust=20*(math.log10(XB1/XB1_0)) ampXCPdB = ampXCP0dB-adjust adjust=20*(math.log10(avgX/avgX0)) #in case there is a Ramp change ampXCPdB = ampXCP0dB-adjust return ampHCPdB, ampXCPdB
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 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, "")
def LoadFromData(Nuc,offs,units): """ Nuc : Nucleus for DREAM mixing offs : dict key for Dream offset units: dB or Watts """ p90H, p90C, p90N, ampH, ampC, ampN, MAS = Setup.ReadHPFromData(units) #Define frequencies Nucs=NUC.list() i=0 for item in Nucs: if item==Nuc: if item =='13C':Frq=fq.fq(item,i+1) if item =='15N':Frq=fq.fq(item,i+1) if item =='1H' :Frq=fq.fq(item,i+1) if item =='2H' :Frq=fq.fq(item,i+1) i=i+1 FqUnit=pul.GetPar('uoffs',"") FqMeth=pul.GetPar('oFrom',"") #TopCmds.MSG(FqUnit + " "+FqMeth+" "+str(Frq.bf)) # Everything in absolute PPM if FqMeth=="Carrier": if FqUnit=="Hz" :OffsPPM=Frq.offs2ppm(pul.GetPar(offs,"")) if FqUnit=="ppm":OffsPPM=Frq.offsp-pul.GetPar(offs,"") else: if FqUnit=="Hz" :OffsPPM=Frq.offs2ppm(pul.GetPar(offs,"")-Frq.offs) if FqUnit=="ppm":OffsPPM=pul.GetPar(offsp,"") index = TopCmds.INPUT_DIALOG("Mr Setup Input", "Pulse Widths and Power", \ ["1H 90 pw","1H ampl","13C 90 pw","13C ampl","15N 90 pw","15N ampl","DREAM Offset","MAS"],\ [str('%.2f' %p90H),str('%.2f' %ampH),str('%.2f' %p90C),str('%.2f' %ampC),\ str('%.2f' %p90N),str('%.2f' %ampN),str('%.2f' %Offsppm),str('%.2f' %MAS)],\ ["us",units,"us",units,"us",units,"ppm"," Hz"],\ ["1","1","1","1","1","1","1","1"],\ ["Accept","Close"], [spc,ret], 10) if index == None:TopCmds.EXIT() p90H=float(index[0]) ampH=float(index[1]) p90C=float(index[2]) ampC=float(index[3]) p90N=float(index[4]) ampN=float(index[5]) MAS =float(index[7]) TauR= 1000000./MAS Setup.PutPars(p90H,ampH,p90C,ampC,p90N,ampN,MAS,units) if FqMeth=="Carrier": if FqUnit=="Hz" :OffsPPM=Frq.offsp-float(index[6]) 2ppm(pul.GetPar(offs,"")) if FqUnit=="ppm":OffsPPM=Frq.offsp-pul.GetPar(offs,"") else: if FqUnit=="Hz" :OffsPPM=Frq.offs2ppm(pul.GetPar(offs,"")-Frq.offs) if FqUnit=="ppm":OffsPPM=pul.GetPar(offsp,"") if FqMeth=="Zero" : Offsppm= if FqMeth=="Carrier": Offsppm=Frq.offsp+float(index[6]) # Everything in the right units if FqUnit=="Hz" :pul.Setpar(offs,Frq.ppm2offs(Offsppm,""),"") if FqUnit=="ppm":pul.Setpar(offs,Offsppm,"")