Hi
I modified Graeme Balls macro so I could get it to would work in v2.
I attach it here.
Cheers
Ben
from Tkinter import *
from tkMessageBox import *
from ScrolledText import ScrolledText
from tkFileDialog import asksaveasfilename
import math
from memops.gui.Frame import Frame
from memops.gui.Label import Label
from memops.gui.ScrolledMatrix import ScrolledMatrix
from ccp.api.nmr import Nmr
from ccpnmr.analysis.core.ExperimentBasic import getSpectra
from ccpnmr.analysis.core.Util import getSpectrumActivePeakList
from ccpnmr.analysis.core.PeakBasic import getPeakDimPpm
class InputError: pass
class MyError: pass
def RDCcalculator(argServer=None):
assert argServer
class calculator(Frame):
def __init__(self, root, spectra):
Frame.__init__(self, root)
self.root=root
self.master.title("RDC calculator")
self._main()
self.spectra=spectra
def _main(self):
num = 1 # row number for grid
self.vars=[] # self.vars stores sepctrum selection
self.results=[] # empty self.results
self.restraints=[] # empty self.restraints
self.atms=[] # empty restraint atom names
# 4 spectra (IPAP) or 2 spectra (doublet) must be selected - see Help
Label(self.root, text = ' Spectrum Name').grid(row=0, column=0, columnspan=2, sticky=W)
Label(self.root, text = ' J(+)').grid(row=0, column=2, sticky=W)
Label(self.root, text = ' J(-)').grid(row=0, column=3, sticky=W)
Label(self.root, text = ' JD(+)').grid(row=0, column=4, sticky=W)
Label(self.root, text = ' JD(-)').grid(row=0, column=5, sticky=W)
# creates a row for each spectrum - TBD: display only RDC spectra
for spectrum in spectra:
spectrumname = spectrum.name
Label(self.root, text=spectrumname).grid(row=num, column=0, columnspan=2, sticky=W)
var=IntVar()
Checkbutton(root, text=None, variable=var).grid(row=num, column=2, sticky=NSEW)
self.vars.append(var)
var=IntVar()
Checkbutton(root, text=None, variable=var).grid(row=num, column=3, sticky=NSEW)
self.vars.append(var)
var=IntVar()
Checkbutton(root, text=None, variable=var).grid(row=num, column=4, sticky=NSEW)
self.vars.append(var)
var=IntVar()
Checkbutton(root, text=None, variable=var).grid(row=num, column=5, sticky=NSEW)
self.vars.append(var)
var=IntVar()
num = num + 1
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
# ask user to specify experiment type (Radiobutton exptVar - stored in self.exptType)
# choices: 1 = IPAP, 2 = doublet
Label(self.root, text = ' Experiment Type:').grid(row=num, column=0, columnspan=5, sticky=W)
num = num + 1
exptVar = IntVar()
Label(self.root, text = ' IPAP').grid(row=num, column=0, columnspan=2, sticky=W)
exptRad = Radiobutton(root, variable=exptVar, value=1).grid(row=num, column=2, sticky=W)
num = num + 1
Label(self.root, text = ' doublet').grid(row=num, column=0, columnspan=2, sticky=W)
exptRad = Radiobutton(root, variable=exptVar, value=2).grid(row=num, column=2, sticky=W)
num = num + 1
self.exptType=exptVar
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
# ask user to specify nuclei for which J or J+D is being measured
# NB - not necessarily the same as the nuclei represented by the axes!
Label(self.root, text = ' Coupling Type: Atom Name Residue').grid(row=num, column=0, columnspan=5, sticky=W)
num = num + 1
atm1 = 'HN'
atm2 = 'N'
resid1 = '0'
resid2 = '0'
Label(self.root, text = ' Atom 1').grid(row=num, column=0, columnspan=2, sticky=W)
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, atm1)
ent.grid(row=num, column=2)
self.coupAtm1=ent
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, resid1)
ent.grid(row=num, column=4)
self.coupResid1=ent
num = num + 1
Label(self.root, text = ' Atom 2').grid(row=num, column=0, columnspan=2, sticky=W)
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, atm2)
ent.grid(row=num, column=2)
self.coupAtm2=ent
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, resid2)
ent.grid(row=num, column=4)
self.coupResid2=ent
num = num + 1
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
# allow user to scale couplings and supply error estimates - see Help
scaleF='1.0'
# get scaling factor that includes gyromagnetic ratio / bond length and, potentially, other scaling
Label(self.root, text = 'Scaling Factor:').grid(row=num, column=0, columnspan=2, sticky=W)
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, scaleF)
ent.grid(row=num, column=2)
self.scaleF=ent
num = num + 1
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
# get error estimate for each spectrum (or for IPAP, each pair of spectra)
JErr='1.0'
JDErr='1.0'
Label(self.root, text = ' Error estimates J JD').grid(row=num, column=0, columnspan=5, sticky=W)
num = num + 1
Label(self.root, text = 'Error Estimate (Hz): ').grid(row=num, column=0, columnspan=2, sticky=W)
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, JErr)
ent.grid(row=num, column=2)
self.JErr=ent
ent=Entry(root)
ent.config(bg='white', width=5)
ent.insert(0, JDErr)
ent.grid(row=num, column=4)
self.JDErr=ent
num = num + 1
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
# ask user to specify whether JorJD, or D to be calculated (Radiobutton calcVar - stored in self.calcType)
# choices: 1 = D, 2 = (J or J+D)
Label(self.root, text = ' Calculate what?').grid(row=num, column=0, columnspan=5, sticky=W)
num = num + 1
calcVar = IntVar()
Label(self.root, text = ' D').grid(row=num, column=0, columnspan=2, sticky=W)
calcRad = Radiobutton(root, variable=calcVar, value=1).grid(row=num, column=2, sticky=W)
num = num + 1
Label(self.root, text = ' J or J+D').grid(row=num, column=0, columnspan=2, sticky=W)
calcRad = Radiobutton(root, variable=calcVar, value=2).grid(row=num, column=2, sticky=W)
num = num + 1
self.calcType=calcVar
Label(self.root, text = '').grid(row=num, column=0, sticky=NSEW)
num = num + 1
Button(root, text='Next', command=self._onNext).grid(row=num, column=0)
Button(root, text='Close', command=root.destroy).grid(row=num, column=1)
Button(root, text='Help', command=self._onHelp).grid(row=num, column=2)
def _onNext(self):
# get selected spectra and calc type
selection = []
for var in self.vars:
selection.append(var.get())
exptType=self.exptType.get()
calcType=self.calcType.get()
# run through the selected spectra and store names
ctr = 0
self.spectrumJplus = None
self.spectrumJminus = None
self.spectrumJDplus = None
self.spectrumJDminus = None
for spectrum in self.spectra:
spectrumname = spectrum.name
if((selection[ctr] == 1)or(selection[ctr+1] == 1)or(selection[ctr+2] == 1)or(selection[ctr+3] == 1)):
if(selection[ctr] == 1):
self.spectrumJplus = spectrum
elif(selection[ctr+1] == 1):
self.spectrumJminus = spectrum
elif(selection[ctr+2] == 1):
self.spectrumJDplus = spectrum
elif(selection[ctr+3] == 1):
self.spectrumJDminus = spectrum
ctr=ctr+4
# collect remaining user input from main and store in 'self.atms'
coupAtm1=self.coupAtm1.get()
coupAtm2=self.coupAtm2.get()
coupResid1=int(self.coupResid1.get())
coupResid2=int(self.coupResid2.get())
self.atms = [ coupAtm1, coupResid1, coupAtm2, coupResid2 ]
# check the input makes some sense at least
if not ( (self.spectrumJplus and self.spectrumJminus and self.spectrumJDplus and self.spectrumJDminus and exptType==1 and calcType==1) or \
( (self.spectrumJplus or self.spectrumJminus) and (self.spectrumJDplus or self.spectrumJDminus) and exptType==2 and calcType==1) or \
( ( (self.spectrumJplus and self.spectrumJminus) or (self.spectrumJDplus and self.spectrumJDminus) ) and exptType==1 and calcType==2) or \
( (self.spectrumJplus or self.spectrumJminus or self.spectrumJDplus or self.spectrumJDminus) and exptType==2 and calcType==2) ):
print '\n RDCcalculator user input error - please read Help!\n'
raise InputError
# ask user to choose frequency axis which encodes RDC
# NB - uses spectrumJplus or spectrumJminus,
# i.e. assumes all experiments the same
win=Toplevel()
win.title("Select Axis")
axisChoice = Frame(win)
axisChoice.pack()
num = 0
axes = []
self.aXvar = []
spectrum = None
if(self.spectrumJplus):
spectrum = self.spectrumJplus
elif(self.spectrumJminus):
spectrum = self.spectrumJminus
elif(self.spectrumJDplus):
spectrum = self.spectrumJDplus
elif(self.spectrumJDminus):
spectrum = self.spectrumJDminus
for dataDim in spectrum.dataDims:
expDimRef = dataDim.expDim.findFirstExpDimRef()
isotopeCode = expDimRef.isotopeCodes[0]
sf = expDimRef.sf
axes.append( (expDimRef.expDim.dim, isotopeCode, sf) )
self.axes = axes
for axis in axes:
Label(axisChoice, text=axis).grid(row=num, column=0, columnspan=2, sticky=W)
aXvar=IntVar()
Checkbutton(axisChoice, text=None, variable=aXvar).grid(row=num, column=2, sticky=NSEW)
self.aXvar.append(aXvar)
num += 1
optButtons=Frame(win)
optButtons.pack()
Button(optButtons, text='Go', command=self._onGo).grid(row=num, column=0)
Button(optButtons, text='Close', command=win.destroy).grid(row=num, column=1)
Button(optButtons, text='Help', command=self._onHelp).grid(row=num, column=2)
def _onGo(self):
# which axis was selected ? (to get spectrometer freq for calc)
ctr=0
aXselect = []
self.freq = None
self.dim = None
for var in self.aXvar:
aXselect.append(var.get())
for axis in self.axes:
if(aXselect[ctr]==1):
if(self.freq==None and self.dim==None):
self.freq = axis[2]
self.dim = axis[0]
else:
raise InputError
ctr = ctr+1
exptType=self.exptType.get()
calcType=self.calcType.get()
self.results = {}
# check calcType (D=1 or JorJD=2) and exptType (IPAP=1 or doublet=2) and run appropriate calc
if(calcType==1 and exptType==1):
self.results = self._calcDIPAP(self.spectrumJplus,self.spectrumJminus,self.spectrumJDplus,self.spectrumJDminus)
self._displayResults('D')
elif(calcType==1 and exptType==2):
if(self.spectrumJplus and self.spectrumJDplus):
self.results = self._calcDdoub(self.spectrumJplus,self.spectrumJDplus,'+','+')
self._displayResults('D')
elif(self.spectrumJplus and self.spectrumJDminus):
self.results = self._calcDdoub(self.spectrumJplus,self.spectrumJDminus,'+','-')
self._displayResults('D')
elif(self.spectrumJminus and self.spectrumJDplus):
self.results = self._calcDdoub(self.spectrumJminus,self.spectrumJDplus,'-','+')
self._displayResults('D')
elif(self.spectrumJminus and self.spectrumJDminus):
self.results = self._calcDdoub(self.spectrumJminus,self.spectrumJDminus,'-','-')
self._displayResults('D')
else:
raise MyError
elif(calcType==2 and exptType==1):
if(self.spectrumJplus and self.spectrumJminus):
JErr=float(self.JErr.get())
self.results = self._calcJorJDIPAP(self.spectrumJplus,self.spectrumJminus,JErr)
self._displayResults('J')
elif(self.spectrumJDplus and self.spectrumJDminus):
JDErr=float(self.JDErr.get())
self.results = self._calcJorJDIPAP(self.spectrumJDplus,self.spectrumJDminus,JDErr)
self._displayResults('JD')
else:
raise MyError
elif(calcType==2 and exptType==2):
if(self.spectrumJplus):
JErr=float(self.JErr.get())
self.results = self._calcJorJDdoub(self.spectrumJplus,JErr,'+')
self._displayResults('J')
elif(self.spectrumJminus):
JErr=float(self.JErr.get())
self.results = self._calcJorJDdoub(self.spectrumJminus,JErr,'-')
self._displayResults('J')
elif(self.spectrumJDplus):
JDErr=float(self.JDErr.get())
self.results = self._calcJorJDdoub(self.spectrumJDplus,JDErr,'+')
self._displayResults('JD')
elif(self.spectrumJDminus):
JDErr=float(self.JDErr.get())
self.results = self._calcJorJDdoub(self.spectrumJDminus,JDErr,'-')
self._displayResults('JD')
else:
raise MyError
def _calcDIPAP(self,spec1,spec2,spec3,spec4):
# results[] consists of (D, errD) pairs
results = {}
resid = []
JplusHz = {}
JminusHz = {}
JDplusHz = {}
JDminusHz = {}
sf = self.freq
dim = self.dim
# get RDC scaling and error estimates from main
scaleF=float(self.scaleF.get())
JErr=float(self.JErr.get())
JDErr=float(self.JDErr.get())
# will calculate spec1 - spec2 + spec3 - spec4
self._fillPpmDict(JplusHz,spec1,dim)
self._fillPpmDict(JminusHz,spec2,dim)
self._fillPpmDict(JDplusHz,spec3,dim)
self._fillPpmDict(JDminusHz,spec4,dim)
# to calculate splitting, go through Dicts and check there's
# only one entry for each residue - otherwise return string
# containing number of entries instead
for resid in JplusHz.keys():
result = None
error = None
try:
if ( len(JplusHz[resid]) != 1) or \
( len(JminusHz[resid]) != 1) or \
( len(JDplusHz[resid]) != 1) or \
( len(JDminusHz[resid]) != 1) :
results[resid] = 'Missing or duplicated peaks'
else:
# NB - the order of Dicts for Jresult below is intentional
Jresult = (JminusHz[resid][0] - JplusHz[resid][0]) * sf * scaleF
JDresult = (JDplusHz[resid][0] - JDminusHz[resid][0]) * sf * scaleF
result = JDresult - Jresult
error = scaleF * math.sqrt( (JErr**2) + (JDErr**2) )
results[resid] = ( str(Jresult), str(JDresult), str(result), str(error) )
except KeyError:
results[resid] = 'Missing or duplicated peaks'
return results
def _calcDdoub(self,spec1,spec2,signJ,signJD):
# results[] consists of (D, errD) pairs
results = {}
resid = []
JHz = {}
JDHz = {}
sf = self.freq
dim = self.dim
# get RDC scaling and error estimates from main
scaleF=float(self.scaleF.get())
JErr=float(self.JErr.get())
JDErr=float(self.JDErr.get())
self._fillPpmDict(JHz,spec1,dim)
self._fillPpmDict(JDHz,spec2,dim)
# to calculate splitting, go through Dicts and check there are
# two entries for each residue - otherwise return string
# containing number of entries instead
for resid in JHz.keys():
result = None
error = None
try:
if ( len(JHz[resid]) != 2 ) or ( len(JDHz[resid]) != 2 ):
results[resid] = 'Missing or duplicated peaks'
else:
# ensure if J(+) has been selected J is +ve
# ensure if JD(+) has been selected J+D is +ve
# - bit of a fudge - otherwise sign of each coupling depends on
# which of a pair of a peaks was picked first
bigJHz = JHz[resid][0]
littleJHz = JHz[resid][0]
if JHz[resid][1] > bigJHz:
bigJHz = JHz[resid][1]
else:
littleJHz = JHz[resid][1]
bigJDHz = JDHz[resid][0]
littleJDHz = JDHz[resid][0]
Jresult = None
JDresult = None
if JDHz[resid][1] > bigJDHz:
bigJDHz = JDHz[resid][1]
else:
littleJDHz = JDHz[resid][1]
if signJ == '+':
Jresult = (bigJHz - littleJHz) * sf * scaleF
else:
Jresult = (littleJHz - bigJHz) * sf * scaleF
if signJD == '+':
JDresult = (bigJDHz - littleJDHz) * sf * scaleF
else:
JDresult = (littleJDHz - bigJDHz) * sf * scaleF
result = JDresult-Jresult
error = math.sqrt((JErr**2)+(JDErr**2)) * scaleF
results[resid] = ( str(Jresult), str(JDresult), str(result), str(error) )
except KeyError:
results[resid] = 'Missing or duplicated peaks'
return results
def _calcJorJDIPAP(self,spec1,spec2,err):
# results[] consists of (JD, errJD) pairs
results = {}
resid = []
JorJDplusHz = {}
JorJDminusHz = {}
JorJDErr=err
sf = self.freq
dim = self.dim
# get RDC scaling and error estimates from main
scaleF=float(self.scaleF.get())
# will calculate spec1 - spec2
self._fillPpmDict(JorJDplusHz,spec1,dim)
self._fillPpmDict(JorJDminusHz,spec2,dim)
# to calculate splitting, go through Dicts and check there's
# only one entry for each residue - otherwise return string
# containing number of entries instead
for resid in JorJDplusHz.keys():
result = None
error = None
try:
if ( len(JorJDplusHz[resid]) != 1) or \
( len(JorJDminusHz[resid]) != 1):
results[resid] = 'Missing or duplicated peaks'
else:
result = (JorJDplusHz[resid][0] - JorJDminusHz[resid][0]) * sf * scaleF
error = float(1)
results[resid] = ( str(result), str(error) )
except KeyError:
results[resid] = 'Missing or duplicated peaks'
return results
def _calcJorJDdoub(self,spec1,err,sign):
# results[] consists of (JD, errJD) pairs
results = {}
resid = []
JorJDHz = {}
JorJDErr=err
sf = self.freq
dim = self.dim
# get RDC scaling and error estimates from main
scaleF=float(self.scaleF.get())
self._fillPpmDict(JorJDHz,spec1,dim)
# to calculate splitting, go through a Dict and check there are
# two entries for each residue - otherwise return string
# containing number of entries instead
for resid in JorJDHz.keys():
result = None
error = None
try:
if ( len(JorJDHz[resid]) != 2):
results[resid] = 'Missing or duplicated peaks'
else:
# ensure if JorJD(+) has been selected the result is +ve
# - bit of a fudge - otherwise sign depends on which of a pair of
# peaks was picked first
bigHz = JorJDHz[resid][0]
littleHz = JorJDHz[resid][0]
if JorJDHz[resid][1] > bigHz:
bigHz = JorJDHz[resid][1]
else:
littleHz = JorJDHz[resid][1]
if sign == '+':
result = (bigHz - littleHz) * sf * scaleF
else:
result = (littleHz - bigHz) * sf * scaleF
error = err * scaleF
results[resid] = ( str(result), str(error) )
except KeyError:
results[resid] = 'Missing or duplicated peaks'
return results
def _fillPpmDict(self,ppmDict,spectrum,dim):
activList = getSpectrumActivePeakList(spectrum)
for peak in activList.peaks:
# the 'dim-1' is a bit of a fudge...
peakDims = peak.sortedPeakDims()
peakDim = peakDims[ dim-1 ]
ppm = getPeakDimPpm( peakDim )
# note - you'll get the last contrib if there's >1 (RDC probably meaningless anyway)
for contrib in peakDim.sortedPeakDimContribs():
residue = contrib.resonance.resonanceGroup.residue
if residue:
resid = residue.seqCode
# note - ppm values stored in a Dict of Lists (to cope with spectra containing doublets)
# TBD with subpeaks instead
if ppmDict.has_key(resid):
ppmDict[resid].append(ppm)
else:
ppmList = []
ppmList.append(ppm)
ppmDict[resid] = ppmList
def _displayResults(self,resultType):
# build the basic frame
win=Toplevel()
win.title("Results")
scrollyBit=Frame(win)
scrollyBit.pack(expand=YES, fill=BOTH)
sbar=Scrollbar(scrollyBit)
sbar.pack(side=RIGHT, fill=Y)
resultBox=Listbox(scrollyBit)
resultBox.pack(side=LEFT, expand=YES, fill=BOTH)
sbar.config(command=resultBox.yview)
resultBox.config(yscrollcommand=sbar.set)
outputStr = ''
# check what was calculated and display
if resultType == 'J':
resultBox.insert(END, 'Res J(Hz) errJ(Hz)')
keyList = self.results.keys()
keyList.sort()
for key in keyList:
thisStr = ''
if self.results[key][0] == 'M' :
thisStr = str(key) + ' ' + self.results[key]
else:
thisStr = ( "%d %.3f %.3f" % (key, float(self.results[key][0]), float(self.results[key][1])) )
resultBox.insert(END, thisStr)
outputStr = outputStr + thisStr + '\n'
self.output = outputStr
# final packing and buttons
optButtons=Frame(win)
optButtons.pack()
Button(optButtons, text='Save Results', command=self._onSave).pack(side=LEFT)
Button(optButtons, text='Close', command=win.destroy).pack(side=LEFT)
elif resultType == 'JD':
resultBox.insert(END, 'Res JD(Hz) errJD(Hz)')
keyList = self.results.keys()
keyList.sort()
for key in keyList:
if self.results[key][0] == 'M' :
thisStr = str(key) + ' ' + self.results[key]
else:
thisStr = ( "%d %.3f %.3f" % (key, float(self.results[key][0]), float(self.results[key][1])) )
resultBox.insert(END, thisStr)
outputStr = outputStr + thisStr + '\n'
self.output = outputStr
# final packing and buttons
optButtons=Frame(win)
optButtons.pack()
Button(optButtons, text='Save Results', command=self._onSave).pack(side=LEFT)
Button(optButtons, text='Close', command=win.destroy).pack(side=LEFT)
else:
resultBox.insert(END, 'Res J(Hz) JD(Hz) D(Hz) errD(Hz)')
keyList = self.results.keys()
keyList.sort()
for key in keyList:
if self.results[key][0] == 'M' :
thisStr = str(key) + ' ' + self.results[key]
else:
thisStr = ( "%d %.3f %.3f %.3f %.3f" % (key, float(self.results[key][0]), float(self.results[key][1]),float(self.results[key][2]), float(self.results[key][3])) )
resultBox.insert(END, thisStr)
outputStr = outputStr + thisStr + '\n'
self.output = outputStr
# final packing and buttons
optButtons=Frame(win)
optButtons.pack()
Button(optButtons, text='Save Results', command=self._onSave).pack(side=LEFT)
Button(optButtons, text='TENSO tbl', command=self._onTENSO).pack(side=LEFT)
Button(optButtons, text='SANI tbl', command=self._onSANI).pack(side=LEFT)
Button(optButtons, text='Close', command=win.destroy).pack(side=LEFT)
# Save Results in a text file
def _onSave(self):
filename=asksaveasfilename()
if filename:
open(filename, 'w').write(self.output)
# TBD - store RDCs in project
def _onStore(self):
filename=asksaveasfilename()
if filename:
open(filename, 'w').write(self.output)
# export a CNS sani-style table
def _onSANI(self):
saniStr = ''
atensorAtmStr = 'assign ( resid 999 and name OO )\n ( resid 999 and name Z )\n'
atensorAtmStr = atensorAtmStr + ' ( resid 999 and name X )\n ( resid 999 and name Y )\n'
atm1 = self.coupAtm1.get()
atm2 = self.coupAtm2.get()
offs1 = int(self.coupResid1.get())
offs2 = int(self.coupResid2.get())
keyList = self.results.keys()
keyList.sort()
for resid in keyList:
if self.results[resid][0] != 'M' :
rdc = float(self.results[resid][2])
err = float(self.results[resid][3])
saniStr = saniStr + atensorAtmStr
saniStr = saniStr + ( ' (resid %d and name %s) (resid %d and name %s) %.3f %.3f\n\n' % (resid+offs1, atm1, resid+offs2, atm2, rdc, err) )
filename=asksaveasfilename()
if filename:
open(filename, 'w').write(saniStr)
# export a CNS tenso-style table
def _onTENSO(self):
tensoStr = ''
atm1 = self.coupAtm1.get()
atm2 = self.coupAtm2.get()
offs1 = int(self.coupResid1.get())
offs2 = int(self.coupResid2.get())
keyList = self.results.keys()
keyList.sort()
for resid in keyList:
if self.results[resid][0] != 'M' :
rdc = float(self.results[resid][2])
err = float(self.results[resid][3])
tensoStr = tensoStr + ( 'assign (resid %d and name %s) (resid %d and name %s) %.3f %.3f\n' % (resid+offs1, atm1, resid+offs2, atm2, rdc, err) )
filename=asksaveasfilename()
if filename:
open(filename, 'w').write(tensoStr)
def _onHelp(self):
win=Toplevel()
win.title("Help")
helpbox = ScrolledText(win,height=40,width=80)
helpbox.pack(side=LEFT, expand=YES, fill=BOTH)
helpstr = \
"""
Used for:
Measuring J or J+D or D from experiments in which the coupling is
encoded as a splitting - i.e. doublet or IPAP methods - uses peaks
rather than subpeaks for the moment.
Before using:
To assign a pair of split peaks to the same resonance you must increase
the tolerance for the dimension in which the splitting appears: given 3
peaks - e.g. 1 assigned HSQC peak and 2 unassigned NH IPAP peaks - the
macro 'ipap_ass' can be used to perform the copying for each assigned peak
in the HSQC in turn - go to the peak list and use Find peak. Helpful to give
ipap_ass a keyboard shortcut for this.
Usage:
The main RDCcalculator popup displays a list of available spectra in
columns marked J(+), J(-), JD(+) and JD(-): the meaning of these labels
depends on whether Experiment Type is 'IPAP' or 'doublet'. It is
possible to calculate J, J+D or D as follows:
- to calculate J or J+D for IPAP spectra,
- select a spectrum for J(+) and J(-) to calculate J
- select a spectrum for JD(+) and JD(-) to calculate J+D
- swap selection of J(+)/JD(+) and J(-)/JD(-) to change sign
- to calculate J or J+D for a single spectrum containing doublets,
- select a spectrum for J(+) OR J(-) to calculate J
- select a spectrum for JD(+) OR JD(-) to calculate J+D
- switch selection J(+) to J(-) or JD(+) to JD(-) to change sign
- to calculate D for IPAP spectra,
- select a spectrum for J(+), J(-), JD(+) and JD(-)
- D is calculated as D = ( JD(+) - JD(-) ) - ( J(-) - J(+) )
- play with selection of four spectra to change sign
- the signs of J and J+D are shown in the results window!
- to calculate D using two spectra that contain doublets,
- select a spectrum for ( J(+) OR J(-) ) and ( JD(+) OR JD(-) )
- switch selection J(+) to J(-) / JD(+) to JD(-) to change signs
- again, signs of J and J+D are shown in the results window
You can specify atom names (e.g. HN, N, C', CA, HA) in the 'Atom Name'
entry boxes - the neighbouring 'Residue' entry boxes modify the
residue number of the restraint for this atom (taken from the assignment
for Atom1). e.g. for NC' RDCs, enter N 0, C' -1 (the carbonyl carbon is
from the previous residue). Scaling factor is required to scale all RDCs
relative to the NH RDC for use as restraints (e.g. 8.33 for NC', -5.05
for CaC', -0.481 for CaHa). Error estimates for J and J+D will be used
to calculate a corresponding error in D according to:
errD = scaling * sqrt( (errJ^2) + (errJD^2) )
Estimates for errJ and errJD (error in a splitting) e.g. from:
err = LW / SN
where LW = linewidth and SN = signal-to-noise. This error estimation
procedure and the scaling factors for gyromagnetic ratio / bond length
are empirical and are taken from: Bax A, Kontaxis G, Tjandra N.
Methods Enzymol. 2001;339:127-174.
A second popup requests selection of the spectrum axis along which
the splitting appears. The Results can be printed to a text file or
restraint file for CNS/XPLOR (either SANI or TENSO).
Limitations:
- When changing selections, it's best to close and restart the macro...
- Not all residues with missing peaks will be reported - only those for
which a peak is present in the first spectrum.
- Experiments measuring J and J+D must be of the same type (using
different experiments is a bad idea anyway).
Questions?
E-mail: [log in to unmask]
Phone: +44 131 650 7111
Graeme Ball
Wellcome Trust Centre for Cell Biology
School of Biological Sciences
University of Edinburgh
Mayfield Road
Edinburgh EH9 3JR
"""
helpbox.insert(END, helpstr)
# RUNNING THE CALCULATOR STARTS HERE
project = argServer.getProject()
spectra = getSpectra(project)
root=Toplevel()
top=calculator(root, spectra)
top.mainloop()
|