Hi,
I didn't know how to append the body() function and keep all the other
buttons in the right place. Can you advice on this, Tim? Would be useful
for other things. As a temporary solution I attached the renamed "old"
BrowseResonancesPopup.py and slightly changed ResTbl_igb.py. Save them
into the same directory and the macro should work. The table will not
have the latest button, but in my macro the table is not fully
functional anyway. I'm looking forward to have fully integrated Tim's
version.
Cheers
Igor
Tim Stevens wrote:
>>Unfortunately it stopped working after I upgarded to the latest files
>>for Analysis.
>>
>>line 378, in __getattr__
>> raise AttributeError, "%s instance has no attribute '%s'" %
>>(self.__class__.__name__, name)
>>AttributeError: ResTblSc instance has no attribute 'typeButton'
>>
>>Any idea of whats wrong?
>>
>>
>
>Igor's macro subclasses the ResonanceBrowser and re-writes (rather than
>append) the body() function, hence when I added a new button recently to
>the browser (to set the atom types for resonances en masse) the macro
>does not contain the widget, but the functions for the superclass assume
>it is there...
>
>I am in the process of incorporating Igor's ideas into Analysis proper,
>which should eliminate such issues. However, in the mean time the macro
>could be upgraded to include the extra button.
>
>T.
>
>
>-------------------------------------------------------------------------------
> Dr Tim Stevens Email: [log in to unmask]
> Department of Biochemistry [log in to unmask]
> University of Cambridge Phone: +44 1223 766022 (office)
> 80 Tennis Court Road +44 7816 338275 (mobile)
> Old Addenbrooke's Site +44 1223 364613 (home)
> Cambridge CB2 1GA WWWeb: http://www.bio.cam.ac.uk/~tjs23
> United Kingdom http://www.pantonia.co.uk
>-------------------------------------------------------------------------------
>------ +NH3CH(CH(CH3)OH)C(O)NHCH(CH(CH3)CH2CH3)C(O)NHCH(CH2CH2SCH3)CO2- -------
>-------------------------------------------------------------------------------
>
>
--
Dr. Igor Barsukov
Biological NMR Centre,
University of Leicester
PO Box 138,
University Road,
Henry Wellcome Building,
Leicester LE1 9HN
UK
E-mail: [log in to unmask]
Tel: +44 (0)116 229 7098
FAX: +44 (0)116 229 7053
import re,os,sys
import Tkinter
from ccpnmr.analysis.WindowBasic import getActiveWindows
from ccpnmr.api import Analysis
from memops.general import Implementation
from memops.gui.ButtonList import ButtonList
#from ccpnmr.analysis.BrowseResonancesPopup import BrowseResonancesPopup
from BrowseResonancesPopup_nmrc import BrowseResonancesPopup
from igorFuncs import getResidueProtElementResFromRes, getBoundProtonResonances, getProtonResFromCarbRes
from memops.gui.Button import Button
from memops.gui.Entry import Entry
from memops.gui.FloatEntry import FloatEntry
from memops.gui.Frame import Frame
from memops.gui.LabelFrame import LabelFrame
from memops.gui.Label import Label
from memops.gui.PulldownMenu import PulldownMenu
from memops.gui.MessageReporter import showOkCancel, showWarning, showYesNo
from memops.gui.ScrolledMatrix import ScrolledMatrix
from memops.gui.Text import Text
from memops.gui.Spacer import Spacer
from memops.editor.Util import createDismissHelpButtonList
from ccpnmr.analysis.AssignmentBasic import getResonanceResidue, findResonanceSet, deassignResonance, getResonanceAtomTuple, removeSpinSystemResonance, makeResonanceGuiName, assignAtomsToRes, mergeResonances, addSpinSystemResonance, removeSpinSystemResonance, assignResonanceResidue
from ccpnmr.analysis.MarkBasic import createPeakMark, createNonPeakMark, createRuler, \
removeMarks, removeRulers, createPeakDimRuler, markCounter
class SlimButton(Button):
def __init__(self, parent,*args, **kw):
Button.__init__(self, parent, borderwidth=1,padx=2,pady=2, *args, **kw)
class ResTblSc(BrowseResonancesPopup):
def __init__(self,parent,project = None,argServer=None):
BrowseResonancesPopup.__init__(self, parent,project = parent.project)
self.winDic={}
self.WindowPositionDic={}
self.WindowPositionDic2D={}
self.argServer=argServer
self.project = argServer.getProject()
self.orthogonalDict={}
def body(self, guiFrame):
self.isotope = 'Any'
self.status = 'Any'
self.waitingForAtoms = 0
self.waitingForSpinSystem = None
hilightColor = '#%02x%02x%02x' % (128, 128, 200)
self.titleColor = '#%02x%02x%02x' % (0, 0, 128)
self.untoggledDict = { 'fg': 'black', 'relief': 'raised' , 'bg': 'grey83'}
self.toggledDict = { 'fg': 'white', 'relief': 'raised' , 'bg': hilightColor}
self.isotopeNames = ['Any','1H','15N','13C','unknown']
self.statusNames = ['Any','Assigned','Unassigned','Orphaned']
shiftListNames = self.getShiftListNames(self.project)
shiftLists = list(self.project.findAllNmrMeasurementLists(className = 'ShiftList'))
self.shiftList = None
self.chain = None
self.ccpCode = None
row = 0
frame=LabelFrame(guiFrame, text='Navigation')
frame.grid(row=row, column=0, columnspan=10, rowspan=2, sticky=Tkinter.EW)
frame.grid_columnconfigure(1, weight=1)
self.orthogPulldown = PulldownMenu(frame, entries=['None'], callback=None)
self.orthogPulldown.grid(row=0, column=0, sticky=Tkinter.W)
self.orthogPulldown1 = PulldownMenu(frame, entries=['None'], callback=None)
self.orthogPulldown1.grid(row=0, column=1, sticky=Tkinter.W)
self.orthogPulldown2D = PulldownMenu(frame, entries=['None'], callback=None)
self.orthogPulldown2D.grid(row=0, column=2, sticky=Tkinter.W)
self.orthogButton = SlimButton(frame,text='Goto position:',command=self.gotoOrthogPlaneAll)
self.orthogButton.grid(row=0, column=3, sticky=Tkinter.EW)
self.markButton = SlimButton(frame,text='Nxt strip',command=self.incrementActiveStripAll)
self.markButton.grid(row=0, column=4, sticky=Tkinter.EW)
self.markButton = SlimButton(frame,text='Prv strip',command=self.decrementActiveStripAll)
self.markButton.grid(row=0, column=5, sticky=Tkinter.EW)
self.markButton = SlimButton(frame,text='0 strip',command=self.zeroActiveStrip)
self.markButton.grid(row=0, column=6, sticky=Tkinter.EW)
self.markButton = SlimButton(frame,text='Mark Res',command=self.markAllResShift)
self.markButton.grid(row=0, column=7, sticky=Tkinter.EW)
self.showAllRes = SlimButton(frame,text='Shw All Rs',command=self.showAllRes)
self.showAllRes.grid(row=1, column=3, sticky=Tkinter.EW)
self.markAllRes = SlimButton(frame,text='Mrk All Rs',command=self.markAllRes)
self.markAllRes.grid(row=1, column=4, sticky=Tkinter.EW)
self.markRemoveButton = SlimButton(frame,text='Del Marks',command=self.removeAllMarks)
self.markRemoveButton.grid(row=1, column=5, sticky=Tkinter.EW)
row += 1
row += 1
if shiftLists:
self.shiftList = shiftLists[0]
guiFrame.grid_columnconfigure(9, weight=1)
# row = 0
self.shiftValueEntry = FloatEntry(self, returnCallback=self.setShiftValue, width=10)
self.nameEntry = Entry(self, returnCallback=self.setName, width=12)
self.shiftListLabel = Label(guiFrame, text = 'ShiftList:')
self.shiftListPulldown = PulldownMenu(guiFrame, self.changeShiftList, shiftListNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.isotopeLabel = Label(guiFrame, text = ' Isotope:')
self.isotopePulldown = PulldownMenu(guiFrame, self.changeIsotope, self.isotopeNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.statusLabel = Label(guiFrame, text = ' Status:')
self.statusPulldown = PulldownMenu(guiFrame, self.changeStatus, self.statusNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.chainLabel = Label(guiFrame, text = ' Chain:')
self.chainPulldown = PulldownMenu(guiFrame, self.changeChain, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.ccpCodeLabel = Label(guiFrame, text = ' CcpCode:')
self.ccpCodePulldown = PulldownMenu(guiFrame, self.changeCcpCode, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
#self.spacer2 = Spacer(guiFrame)
self.shiftListLabel.grid (row=row, column=0, columnspan=1, sticky=Tkinter.W)
self.shiftListPulldown.grid(row=row, column=1, columnspan=1, sticky=Tkinter.W)
self.isotopeLabel.grid (row=row, column=2, columnspan=1, sticky=Tkinter.W)
self.isotopePulldown.grid (row=row, column=3, columnspan=1, sticky=Tkinter.W)
self.statusLabel.grid (row=row, column=4, columnspan=1, sticky=Tkinter.W)
self.statusPulldown.grid (row=row, column=5, columnspan=1, sticky=Tkinter.W)
self.chainLabel.grid (row=row, column=6, columnspan=1, sticky=Tkinter.W)
self.chainPulldown.grid (row=row, column=7, columnspan=1, sticky=Tkinter.W)
self.ccpCodeLabel.grid (row=row, column=8, columnspan=1, sticky=Tkinter.W)
self.ccpCodePulldown.grid (row=row, column=9, columnspan=1, sticky=Tkinter.W)
row += 1
guiFrame.grid_rowconfigure(row, weight=1)
#shift list experiments
#shift list unit
justifyList = ['center','right','left','left','center','center','center','center','center','center']
colHeadings = ['#',"Shift","SD",'Assign\nName','Residue','Isotope','Other\nName','Total\nPeaks','Shift List\nPeaks','Spin\nSystem #']
editWidgets = [None,self.shiftValueEntry,None,None,None,None,self.nameEntry,None,None,None]
editGetCallbacks = [None,self.getShiftValue, None,None,None,None,self.getName ,self.showPeaks, self.showShiftListPeaks,None]
editSetCallbacks = [None,self.setShiftValue, None,None,None,None,self.setName ,None,None,None]
self.scrolledMatrix = ScrolledMatrix(guiFrame, justifyList=justifyList, initialRows=16, headingList=colHeadings,
editWidgets=editWidgets,
editGetCallbacks=editGetCallbacks,
editSetCallbacks=editSetCallbacks,
font=self.smallFont, callback=self.selectCell, multiSelect=1)
self.scrolledMatrix.grid (row=row, column=0, columnspan=10, sticky = Tkinter.NSEW, padx=1)
self.scrolledMatrix.doEditMarkExtraRules = self.doEditMarkExtraRules
texts = ['Deassign','Assign','Add to\nSpin System','Remove from\nSpin System','Swap\nProchirals']
commands = [self.disconnectAtoms,self.waitForAtoms,self.addToSpinSys,self.removeFromSpinSys,self.swapProchiral]
buttonList = ButtonList(guiFrame, texts=texts, commands=commands, expands=True)
buttonList.grid(row = 4, column = 0, columnspan=10, sticky = Tkinter.EW)
self.assignButton = buttonList.buttons[1]
self.assSpinSysButton = buttonList.buttons[2]
self.swapProchiralButton = buttonList.buttons[4]
texts = ['Delete','Delete\nOrphans','Merge','Show Total\nPeaks','Show Shift List\nPeaks']
commands = [self.deleteResonance,self.deleteOrphans,self.mergeResonances,self.showPeaks, self.showShiftListPeaks]
self.bottomButtons = createDismissHelpButtonList(guiFrame, texts=texts, expands=1,
commands=commands, help_url=self.help_url)
self.bottomButtons.grid(row = 5, columnspan = 10, sticky = Tkinter.EW)
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'setName')
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', '__init__')
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'delete')
for func in ('__init__', 'delete'):
for clazz in ('ccp.Nmr.PeakDimContrib', 'ccp.Nmr.Shift','ccp.Nmr.ResonanceSet', 'ccp.Nmr.Resonance'):
self.registerNotify(self.updateAfter, clazz, func)
self.registerNotify(self.updateAfter, 'ccp.Nmr.ResonanceSet', 'addResonance')
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setValue')
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setError')
for func in ('setDetails', 'setIsotopeCode', 'setName','removeAssignName','setAssignNames','addAssignName'):
self.registerNotify(self.updateAfter, 'ccp.Nmr.Resonance', func)
for func in ('setCcpCode', 'addResonance', 'removeResonance', 'setResonances','addAtomSet', 'delete'):
self.registerNotify(self.updateAfter, 'ccp.Nmr.ResonanceGroup', func)
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'getResonance')
self.resonances=[]
self.resonance = None
self.refresh = 0
self.update()
def gotoOrthogPlane(self,windowName,col=0,active='y'):
if windowName!='None':
if active=='y':
col=self.activeStrip(windowName)
popup=self.argServer.parent.getWindowPopup(windowName)
if windowName in self.WindowPositionDic.keys():
position=self.WindowPositionDic[windowName]
else:
position=self.WindowPositionDic2D[windowName]
popup.gotoPosition(position,col=col)
def gotoOrthogPlaneAll(self):
self.gotoOrthogPlane(self.orthogPulldown.getSelected())
self.gotoOrthogPlane(self.orthogPulldown1.getSelected())
self.gotoOrthogPlane(self.orthogPulldown2D.getSelected())
def activeStrip(self,windowName):
window=self.orthogonalDict[windowName]
for n in range(0,len(window.axisPanels[0].axisRegions)):
if window.axisPanels[0].axisRegions[n].isActive: return n
def zeroActiveStrip(self):
windowName=self.orthogPulldown.getSelected()
if windowName!='None':
popup=self.argServer.parent.getWindowPopup(windowName)
popup.activateStrip(0)
windowName=self.orthogPulldown1.getSelected()
if windowName!='None':
popup=self.argServer.parent.getWindowPopup(windowName)
popup.activateStrip(0)
windowName=self.orthogPulldown2D.getSelected()
if windowName!='None':
popup=self.argServer.parent.getWindowPopup(windowName)
popup.activateStrip(0)
def incrementActiveStripAll(self):
self.incrementActiveStrip(self.orthogPulldown.getSelected())
self.incrementActiveStrip(self.orthogPulldown1.getSelected())
self.incrementActiveStrip(self.orthogPulldown2D.getSelected())
#mark all resonances from the residue identified by the selected resonance
def markAllRes(self):
resonance = self.scrolledMatrix.currentObjects[0]
if resonance.resonanceSet:
for r in getResidueProtElementResFromRes(resonance,elementSymbol='C'):
self.markResShift(r)
for r1 in getProtonResFromCarbRes(r): self.markResShift(r1)
for r in getResidueProtElementResFromRes(resonance,elementSymbol='N'):
self.markResShift(r)
for r1 in getProtonResFromCarbRes(r): self.markResShift(r1)
#display strips for the whole residue, alphabetical order
def showAllRes(self):
self.zeroActiveStrip()
resonance = self.scrolledMatrix.currentObjects[0]
ResPairs=[]
CarbResDic={}
if resonance.resonanceSet:
for r in getResidueProtElementResFromRes(resonance,elementSymbol='C'):
(molSystem, chain, residue, name) = getResonanceAtomTuple(r)
CarbResDic[name]=r
CarbNames=CarbResDic.keys()
CarbNames.sort()
print CarbNames
for name in CarbNames:
r=CarbResDic[name]
for r1 in getProtonResFromCarbRes(r):
(molSystem1, chain1, residue1, name1) = getResonanceAtomTuple(r1)
if name=='Cga' or name=='Cgb' or name=='Cda' or name=='Cdb':
if name[1:3]!=name1[1:3]: continue
ResPairs.append([r,r1])
#windows may have different number of pannels, ans smaller than numer of atoms
cntMax=0
windowName=self.orthogPulldown.getSelected()
if windowName!='None':
window=self.orthogonalDict[self.orthogPulldown.getSelected()]
cntMax=len(window.axisPanels[0].axisRegions)
cntMax1=0
windowName=self.orthogPulldown1.getSelected()
if windowName!='None':
window=self.orthogonalDict[self.orthogPulldown1.getSelected()]
cntMax1=len(window.axisPanels[0].axisRegions)
cntMax2D=0
windowName=self.orthogPulldown2D.getSelected()
if windowName!='None':
window=self.orthogonalDict[self.orthogPulldown2D.getSelected()]
cntMax2D=len(window.axisPanels[0].axisRegions)
for ResPair in ResPairs:
if cntMax>0:
self.goToPosition(self.orthogPulldown.getSelected(),ResPair)
if cntMax1>0:
self.goToPosition(self.orthogPulldown1.getSelected(),ResPair)
if cntMax2D>0:
self.goToPosition(self.orthogPulldown2D.getSelected(),ResPair)
self.incrementActiveStripAll()
cntMax-=1
cntMax1-=1
cntMax2D-=1
#resonances = [r1,r2]
def goToPosition(self,windowName,resonances):
if windowName=='None': return
window=self.orthogonalDict[windowName]
resTypesDic={}
if len(resonances)>2: return
if len(resonances)==2:
if resonances[0].isotope.massNumber==resonances[1].isotope.massNumber: return
for resonance in resonances:
isotopeText = '%d%s' % (resonance.isotope.massNumber, resonance.isotope.chemElement.symbol)
resTypesDic[isotopeText]=resonance
position={}
for axisPanel in window.axisPanels:
if axisPanel.label=='y' and len(window.axisPanels)!=2: continue
for key in resTypesDic.keys():
if key == axisPanel.axisType.name:
position[axisPanel.label]=self.getResShift(resTypesDic[key])
if len(resTypesDic.keys())!=len(position.keys()): return
# print position
popup=self.argServer.parent.getWindowPopup(windowName)
col=self.activeStrip(windowName)
popup.gotoPosition(position,col=col)
##~ if len(window.axisPanels)==2:
##~ self.WindowPositionDic2D[window.name]=d_tmp
##~ else:
##~ self.WindowPositionDic[window.name]=d_tmp
#
def incrementActiveStrip(self,windowName):
if windowName!='None':
window=self.orthogonalDict[windowName]
popup=self.argServer.parent.getWindowPopup(windowName)
col=popup.getActiveStrip()
if col=='all': col=0
if col<len(window.axisPanels[0].axisRegions)-1: col+=1
popup.activateStrip(col)
def decrementActiveStrip(self,windowName):
if windowName!='None':
window=self.orthogonalDict[windowName]
popup=self.argServer.parent.getWindowPopup(windowName)
col=popup.getActiveStrip()
if col=='all': col=0
if col>0: col-=1
popup.activateStrip(col)
def decrementActiveStripAll(self):
self.decrementActiveStrip(self.orthogPulldown.getSelected())
self.decrementActiveStrip(self.orthogPulldown1.getSelected())
self.decrementActiveStrip(self.orthogPulldown2D.getSelected())
def selectCell(self, resonance, row, col):
self.resonance = resonance
self.findWindows()
def getResShift(self, resonance):
if self.shiftList:
shift= resonance.findFirstShift(parentList = self.shiftList)
return shift.value
else: return None
def markResShift(self, resonance):
positions=[self.getResShift(resonance)]
isotopeText = '%d%s' % (resonance.isotope.massNumber, resonance.isotope.chemElement.symbol)
axisType =None
activeWindows = getActiveWindows(self.project)
for window in activeWindows:
if axisType: break
for axisPanel in window.axisPanels:
if isotopeText == axisPanel.axisType.name:
axisTypes=[axisPanel.axisType]
break
createNonPeakMark1(positions, axisTypes)
def markAllResShift(self):
for resonance in self.scrolledMatrix.currentObjects:
self.markResShift(resonance)
def removeAllMarks(self):
removeMarks(self.project,removeAll=True)
def findWindows(self):
resTypesDic={}
if len(self.scrolledMatrix.currentObjects)>2: return
if len(self.scrolledMatrix.currentObjects)==2:
if self.scrolledMatrix.currentObjects[0].isotope.massNumber==self.scrolledMatrix.currentObjects[1].isotope.massNumber: return
for resonance in self.scrolledMatrix.currentObjects:
isotopeText = '%d%s' % (resonance.isotope.massNumber, resonance.isotope.chemElement.symbol)
resTypesDic[isotopeText]=resonance
activeWindows = getActiveWindows(self.project)
self.WindowPositionDic={}
self.WindowPositionDic2D={}
self.orthogonalDict={}
for window in activeWindows:
self.orthogonalDict[window.name]=window
d_tmp={}
for axisPanel in window.axisPanels:
if axisPanel.label=='y' and len(window.axisPanels)!=2: continue
for key in resTypesDic.keys():
if key == axisPanel.axisType.name:
d_tmp[axisPanel.label]=self.getResShift(resTypesDic[key])
if len(resTypesDic.keys())==len(d_tmp.keys()):
if len(window.axisPanels)==2:
self.WindowPositionDic2D[window.name]=d_tmp
else:
self.WindowPositionDic[window.name]=d_tmp
list=self.WindowPositionDic.keys()
list.append('None')
n=0
try:
n=list.index(self.orthogPulldown.getSelected())
except: pass
self.orthogPulldown.setup(list,n)
n=0
try:
n=list.index(self.orthogPulldown1.getSelected())
except: pass
self.orthogPulldown1.setup(list,n)
list=self.WindowPositionDic2D.keys()
list.append('None')
n=0
try:
n=list.index(self.orthogPulldown2D.getSelected())
except: pass
self.orthogPulldown2D.setup(list,n)
def ResTblScGui(argServer=None):
# popup = self.openPopup('browse_resonances', ResTblSc)
# popup.update() # TBD: not sure if this is really needed
RT=ResTblSc(argServer.parent,argServer=argServer)
def createNonPeakMark1(positions, axisTypes, lineWidth = 1,
dashLength = 2, gapLength = 2, color = None, remove=False):
"""Descrn: Create a mark at a general (i.e. non-peak) position.
Inputs: List of Floats (Analysis.Mark.positions), List of Analysis.AxisTypes,
Int, Int, Int, Word (Analysis.Color.name)
Output: Analysis.Mark
"""
global markCounter
project = axisTypes[0].project
if (not color):
name = project.application.getValue(project, keyword='marksColor',
defaultValue='red')
colorScheme = project.findFirstColorScheme(name=name)
if (colorScheme):
names = colorScheme.colorNames
ncolors = len(names)
color = project.findFirstColor(name=names[markCounter % ncolors])
if (not color):
color = project.findFirstColor(name='black')
markCounter = markCounter + 1
else:
color = project.findFirstColor(name='black')
mark = Analysis.Mark(project, lineWidth=lineWidth, dashLength=dashLength,
gapLength=gapLength, color=color)
for n in range(len(positions)):
markDim = Analysis.MarkDim(mark, position=positions[n], axisType=axisTypes[n])
mark.peak = None
if remove:
removeMarks(project)
return mark
"""
======================COPYRIGHT/LICENSE START==========================
BrowseResonancesPopup.py: Part of the CcpNmr Analysis program
Copyright (C) 2005 Wayne Boucher and Tim Stevens (University of Cambridge)
=======================================================================
This file contains reserved and/or proprietary information
belonging to the author and/or organisation holding the copyright.
It may not be used, distributed, modified, transmitted, stored,
or in any way accessed, except by members or employees of the CCPN,
and by these people only until 31 December 2005 and in accordance with
the guidelines of the CCPN.
A copy of this license can be found in ../../../license/CCPN.license.
======================COPYRIGHT/LICENSE END============================
for further information, please contact :
- CCPN website (http://www.ccpn.ac.uk/)
- email: [log in to unmask]
- contact the authors: [log in to unmask], [log in to unmask]
=======================================================================
If you are using this software for academic purposes, we suggest
quoting the following references:
===========================REFERENCE START=============================
R. Fogh, J. Ionides, E. Ulrich, W. Boucher, W. Vranken, J.P. Linge, M.
Habeck, W. Rieping, T.N. Bhat, J. Westbrook, K. Henrick, G. Gilliland,
H. Berman, J. Thornton, M. Nilges, J. Markley and E. Laue (2002). The
CCPN project: An interim report on a data model for the NMR community
(Progress report). Nature Struct. Biol. 9, 416-418.
Wim F. Vranken, Wayne Boucher, Tim J. Stevens, Rasmus
H. Fogh, Anne Pajon, Miguel Llinas, Eldon L. Ulrich, John L. Markley, John
Ionides and Ernest D. Laue (2005). The CCPN Data Model for NMR Spectroscopy:
Development of a Software Pipeline. Proteins 59, 687 - 696.
===========================REFERENCE END===============================
"""
import re
import Tkinter
from memops.general import Implementation
from memops.gui.Button import Button
from memops.gui.ButtonList import ButtonList
from memops.gui.Entry import Entry
from memops.gui.FloatEntry import FloatEntry
from memops.gui.Frame import Frame
from memops.gui.Label import Label
from memops.gui.PulldownMenu import PulldownMenu
from memops.gui.MessageReporter import showOkCancel, showWarning, showYesNo
from memops.gui.ScrolledMatrix import ScrolledMatrix
from memops.gui.Text import Text
from memops.gui.Spacer import Spacer
from memops.editor.Util import createDismissHelpButtonList
from ccpnmr.analysis.BasePopup import BasePopup
from ccpnmr.analysis.AssignmentBasic import assignResonanceType, getResonanceResidue, findResonanceSet, \
deassignResonance, getResonanceAtomTuple, removeSpinSystemResonance, \
makeResonanceGuiName, assignAtomsToRes, mergeResonances, \
addSpinSystemResonance, removeSpinSystemResonance, assignResonanceResidue, \
swapProchiralResonance
class BrowseResonancesPopup(BasePopup):
atomColorDict = {'H':'#a0d0a0','N':'#a0a0d0','C':'#d0d0a0','O':'#d0a0a0','P':'#d0a0d0','S':'#d0c090','Se':'#e0b0a0',}
def __init__(self, parent, *args, **kw):
self.guiParent = parent
self.smallFont = '-schumacher-clean-medium-r-normal--14-140-75-75-c-70-iso646.1991-irv'
kw['borderwidth'] = 6
BasePopup.__init__(self, parent=parent, title="Browse resonances", **kw)
self.geometry("+150+150")
def open(self):
self.updateAfter()
BasePopup.open(self)
def body(self, guiFrame):
self.isotope = 'Any'
self.status = 'Any'
self.waitingForAtoms = 0
self.waitingForSpinSystem = None
hilightColor = '#%02x%02x%02x' % (128, 128, 200)
self.titleColor = '#%02x%02x%02x' % (0, 0, 128)
self.untoggledDict = { 'fg': 'black', 'relief': 'raised' , 'bg': 'grey83'}
self.toggledDict = { 'fg': 'white', 'relief': 'raised' , 'bg': hilightColor}
self.isotopeNames = ['Any','1H','15N','13C','unknown']
self.statusNames = ['Any','Assigned','Unassigned','Orphaned']
shiftListNames = self.getShiftListNames(self.project)
shiftLists = list(self.project.findAllNmrMeasurementLists(className = 'ShiftList'))
self.shiftList = None
self.chain = None
self.ccpCode = None
if shiftLists:
self.shiftList = shiftLists[0]
guiFrame.grid_columnconfigure(9, weight=1)
row = 0
self.shiftValueEntry = FloatEntry(self, returnCallback=self.setShiftValue, width=10)
self.nameEntry = Entry(self, returnCallback=self.setName, width=12)
self.shiftListLabel = Label(guiFrame, text = 'ShiftList:')
self.shiftListPulldown = PulldownMenu(guiFrame, self.changeShiftList, shiftListNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.isotopeLabel = Label(guiFrame, text = ' Isotope:')
self.isotopePulldown = PulldownMenu(guiFrame, self.changeIsotope, self.isotopeNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.statusLabel = Label(guiFrame, text = ' Status:')
self.statusPulldown = PulldownMenu(guiFrame, self.changeStatus, self.statusNames, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.chainLabel = Label(guiFrame, text = ' Chain:')
self.chainPulldown = PulldownMenu(guiFrame, self.changeChain, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
self.ccpCodeLabel = Label(guiFrame, text = ' CcpCode:')
self.ccpCodePulldown = PulldownMenu(guiFrame, self.changeCcpCode, selected_index=0, label_color = self.titleColor, do_initial_callback=False)
#self.spacer2 = Spacer(guiFrame)
self.shiftListLabel.grid (row=row, column=0, columnspan=1, sticky=Tkinter.W)
self.shiftListPulldown.grid(row=row, column=1, columnspan=1, sticky=Tkinter.W)
self.isotopeLabel.grid (row=row, column=2, columnspan=1, sticky=Tkinter.W)
self.isotopePulldown.grid (row=row, column=3, columnspan=1, sticky=Tkinter.W)
self.statusLabel.grid (row=row, column=4, columnspan=1, sticky=Tkinter.W)
self.statusPulldown.grid (row=row, column=5, columnspan=1, sticky=Tkinter.W)
self.chainLabel.grid (row=row, column=6, columnspan=1, sticky=Tkinter.W)
self.chainPulldown.grid (row=row, column=7, columnspan=1, sticky=Tkinter.W)
self.ccpCodeLabel.grid (row=row, column=8, columnspan=1, sticky=Tkinter.W)
self.ccpCodePulldown.grid (row=row, column=9, columnspan=1, sticky=Tkinter.W)
row += 1
guiFrame.grid_rowconfigure(row, weight=1)
#shift list experiments
#shift list unit
justifyList = ['center','right','left','left','center','center','center','center','center','center']
colHeadings = ['#',"Shift","SD",'Assign\nName','Residue','Isotope','Other\nName','Total\nPeaks','Shift List\nPeaks','Spin\nSystem #']
editWidgets = [None,self.shiftValueEntry,None,None,None,None,self.nameEntry,None,None,None]
editGetCallbacks = [None,self.getShiftValue, None,None,None,None,self.getName ,self.showPeaks, self.showShiftListPeaks,None]
editSetCallbacks = [None,self.setShiftValue, None,None,None,None,self.setName ,None,None,None]
self.scrolledMatrix = ScrolledMatrix(guiFrame, justifyList=justifyList, initialRows=16, headingList=colHeadings,
editWidgets=editWidgets,
editGetCallbacks=editGetCallbacks,
editSetCallbacks=editSetCallbacks,
font=self.smallFont, callback=self.selectCell, multiSelect=1)
self.scrolledMatrix.grid (row=row, column=0, columnspan=10, sticky = Tkinter.NSEW, padx=1)
self.scrolledMatrix.doEditMarkExtraRules = self.doEditMarkExtraRules
texts = ['Deassign','Assign','Add to\nSpin System','Remove from\nSpin System','Swap\nProchirals']
commands = [self.disconnectAtoms,self.waitForAtoms,self.addToSpinSys,self.removeFromSpinSys,self.swapProchiral]
buttonList = ButtonList(guiFrame, texts=texts, commands=commands, expands=True)
buttonList.grid(row = 2, column = 0, columnspan=10, sticky = Tkinter.EW)
self.assignButton = buttonList.buttons[1]
self.assSpinSysButton = buttonList.buttons[2]
self.swapProchiralButton = buttonList.buttons[4]
texts = ['Delete','Delete\nOrphans','Merge','Show Total\nPeaks','Show Shift List\nPeaks']
commands = [self.deleteResonance,self.deleteOrphans,self.mergeResonances,self.showPeaks, self.showShiftListPeaks]
self.bottomButtons = createDismissHelpButtonList(guiFrame, texts=texts, expands=1,
commands=commands, help_url=self.help_url)
self.bottomButtons.grid(row = 3, columnspan = 10, sticky = Tkinter.EW)
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'setName')
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', '__init__')
self.registerNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'delete')
for func in ('__init__', 'delete'):
for clazz in ('ccp.Nmr.PeakDimContrib', 'ccp.Nmr.Shift','ccp.Nmr.ResonanceSet', 'ccp.Nmr.Resonance'):
self.registerNotify(self.updateAfter, clazz, func)
self.registerNotify(self.updateAfter, 'ccp.Nmr.ResonanceSet', 'addResonance')
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setValue')
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setError')
for func in ('setDetails', 'setIsotopeCode', 'setName','removeAssignName','setAssignNames','addAssignName'):
self.registerNotify(self.updateAfter, 'ccp.Nmr.Resonance', func)
for func in ('setCcpCode', 'addResonance', 'removeResonance', 'setResonances','addAtomSet', 'delete'):
self.registerNotify(self.updateAfter, 'ccp.Nmr.ResonanceGroup', func)
self.registerNotify(self.updateAfter, 'ccp.Nmr.Shift', 'getResonance')
self.resonances=[]
self.resonance = None
self.refresh = 0
self.update()
def updateButtons(self):
if self.resonance:
resonanceSet = self.resonance.resonanceSet
if resonanceSet and (len(resonanceSet.atomSets) == 1):
chemAtom = resonanceSet.atomSets[0].atoms[0].chemAtom
if chemAtom.chemAtomSet:
self.swapProchiralButton.enable()
return
self.swapProchiralButton.disable()
def swapProchiral(self):
if self.resonance:
swapProchiralResonance(self.resonance)
def doEditMarkExtraRules(self, resonance, row, col):
if (col == 1) and resonance and self.shiftList:
shift = resonance.findFirstShift(parentList = self.shiftList)
for contrib in resonance.peakDimContribs:
peak = contrib.peakDim.peak
if self.shiftList is peak.peakList.dataSource.experiment.shiftList:
return 0
return 1
def getShiftValue(self, resonance):
if self.resonance and self.shiftList:
shift = self.resonance.findFirstShift(parentList = self.shiftList)
self.shiftValueEntry.set(shift.value)
def setShiftValue(self, *whatever):
if self.resonance:
value = self.shiftValueEntry.get()
shift = self.resonance.findFirstShift(parentList = self.shiftList)
shift.setValue(value)
def getName(self, resonance):
if self.resonance:
self.nameEntry.set(self.resonance.name)
def setName(self, *whatever):
if self.resonance:
value = self.nameEntry.get().strip() or None
self.resonance.setName(value)
def updateChains(self):
chains = self.getChains()
names = [self.getChainName(x) for x in chains]
index = 0
if self.chain in chains:
index = chains.index(self.chain)
self.chainPulldown.setup(names, index)
def updateCcpCodes(self):
names = self.getCcpCodes()
index = 0
if self.ccpCode and (self.ccpCode in names):
index = names.index(self.ccpCode)
self.ccpCodePulldown.setup(names, index)
def changeChain(self, i, name):
if name == '<Any>':
self.chain = None
else:
self.chain = self.getChains()[i]
self.update()
def changeCcpCode(self, i, name):
if name == '<Any>':
self.ccpCode = None
else:
self.ccpCode = name
self.update()
def getChainName(self, chain):
if chain is None:
return '<Any>'
return '%s:%s-%s' % (chain.molSystem.code, chain.code, chain.molecule.molType)
def getChains(self):
chains = [None,]
if self.project:
for molSystem in self.project.molSystems:
for chain in molSystem.chains:
chains.append(chain)
return chains
def getCcpCodes(self):
dict = {}
if self.chain:
for residue in self.chain.residues:
dict[residue.ccpCode] = 1
else:
for chain in self.getChains():
if chain:
for residue in chain.residues:
dict[residue.ccpCode] = 1
codes = ['<Any>',] + dict.keys()
codes.sort()
return codes
def cancelSpinSystemWait(self):
self.waitingForSpinSystem = None
self.assSpinSysButton.config(self.untoggledDict)
self.assSpinSysButton.config(text='Add to\nSpin System')
def addToSpinSys(self):
self.cancelAtomsWait()
if self.waitingForSpinSystem:
self.cancelSpinSystemWait()
else:
self.waitingForSpinSystem = 1
self.guiParent.editSpinSystems(doClear=True)
self.assSpinSysButton.config(self.toggledDict)
self.assSpinSysButton.config(text='Cancel Add')
def chooseSpinSystem(self, spinSystem):
if self.resonance and self.waitingForSpinSystem:
for resonance in self.scrolledMatrix.currentObjects:
addSpinSystemResonance(spinSystem,resonance)
def removeFromSpinSys(self):
resonances = self.scrolledMatrix.currentObjects
if resonances:
for resonance in resonances:
spinSystem = resonance.resonanceGroup
if spinSystem:
removeSpinSystemResonance(spinSystem, resonance)
def changeStatus(self, i, name):
self.status = name
self.update()
def changeIsotope(self, i, name):
self.isotope = name
self.update()
def selectCell(self, resonance, row, col):
self.resonance = resonance
self.updateButtons()
def getShiftListNames(self,project):
shiftListNames = []
shiftLists = self.project.findAllNmrMeasurementLists(className = 'ShiftList')
for shiftList in shiftLists:
if not hasattr(shiftList, 'name'):
shiftList.name = "ShiftList "+ str(shiftList.serial)
elif not shiftList.name:
shiftList.name = "ShiftList "+ str(shiftList.serial)
shiftListNames.append(shiftList.name)
shiftListNames.append('None')
return shiftListNames
def changeShiftList(self, i, name):
self.shiftList = None
if name != 'None':
shiftLists = self.project.findAllNmrMeasurementLists(className = 'ShiftList')
if shiftLists:
self.shiftList = shiftLists[i]
self.updateAfter()
def deleteOrphans(self):
self.cancelAllWaits()
orphans = []
for resonance in self.resonances:
for contrib in resonance.peakDimContribs:
if contrib.peakDim.peak.peakList.dataSource.experiment.shiftList is self.shiftList:
break
else:
orphans.append(resonance)
if len(orphans) > 0:
if showOkCancel('Remove Orphans', 'Are you sure you want to\ndelete %d orphaned shifts?' % len(orphans) ):
doomed = []
for resonance in orphans:
shift = resonance.findFirstShift(parentList=self.shiftList)
if shift:
shift.delete()
if not resonance.shifts:
doomed.append(resonance)
if doomed and showOkCancel('Delete Resonances', 'Also delete %d resonances which now have no shifts?' % len(doomed)):
for resonance in doomed:
resonanceSet = resonance.resonanceSet
if resonanceSet:
if len(resonanceSet.resonances) == 1:
resonanceSet.delete()
else:
resonanceSet.removeResonance(resonance)
resonance.delete()
self.update()
def mergeResonances(self):
resonances = self.scrolledMatrix.currentObjects
if len(resonances) == 1:
showWarning('Merge failed','More than one resonance must be selected.')
elif len(resonances) > 1:
if ( showOkCancel('Merge resonances', 'Are you sure you want to\nmerge %d resonances?' % len(resonances) ) ):
resonance1 = resonances[0]
for resonance2 in resonances[1:]:
mergeResonances(resonance2, resonance1)
def cancelAtomsWait(self):
self.waitingForAtoms = 0
self.assignButton.config(self.untoggledDict)
self.assignButton.config(text = 'Assign')
def waitForAtoms(self):
self.cancelSpinSystemWait()
if self.waitingForAtoms:
self.cancelAtomsWait()
else:
self.assignButton.config(self.toggledDict)
self.assignButton.config(text = 'Cancel Assign')
self.guiParent.browseAtoms(requestor=self)
self.waitingForAtoms = 1
def assignResonance(self, atomSetMapping):
if self.waitingForAtoms:
if self.resonance:
element = self.resonance.isotope.chemElement.symbol
if atomSetMapping.elementSymbol == element:
if atomSetMapping.mappingType == 'ambiguous':
showWarning('Assign failed', 'Cannot assign resonance to\nambiguous atom selection')
self.waitingForAtoms = 0
self.assignButton.config(self.untoggledDict)
return
serials = list(atomSetMapping.resonanceSerials)
serial = self.resonance.serial
atomSets = atomSetMapping.atomSets
resonanceSet = findResonanceSet(self.resonance,atomSets)
for atomSet in atomSets:
self.checkSpinSystem(self.resonance, atomSet)
resonanceSet = assignAtomsToRes(atomSets,self.resonance,resonanceSet)
#if serial not in serials:
# serials.append(serial)
# atomSetMapping.setResonanceSerials(serials)
self.waitingForAtoms = 0
self.assignButton.config(self.untoggledDict)
def assignResidue(self,residue):
if self.waitingForAtoms:
if self.resonance:
assignResonanceResidue(self.resonance,residue)
self.waitingForAtoms = 0
self.assignButton.config(self.untoggledDict)
def disconnectAtoms(self):
self.cancelAllWaits()
resonances = self.scrolledMatrix.currentObjects
for resonance in resonances:
if resonance.resonanceSet:
if showOkCancel('Confirm', 'Really deassign resonance?'):
deassignResonance(resonance)
elif resonance.assignNames:
if showOkCancel('Confirm', 'Really remove atom type information?'):
assignResonanceType(resonance, None)
def deleteResonance(self):
self.cancelAllWaits()
resonances = self.scrolledMatrix.currentObjects
if len(resonances) == 1:
resonance = resonances[0]
n = len(resonance.peakDimContribs)
if n > 0:
showWarning('Delete failed', 'Resonance still assigned to %d peaks' % n)
return
else:
if ( showOkCancel('Delete Resonance', 'Delete resonance %d?' % resonance.serial) ):
resonanceSet = resonance.resonanceSet
if resonanceSet:
if len(resonanceSet.resonances) == 1:
resonanceSet.delete()
else:
resonanceSet.removeResonance(resonance)
resonance.delete()
self.update()
elif len(resonances) > 1:
if ( showOkCancel('Delete Resonance', 'Delete %d resonances' % len(resonances)) ):
toDelete = []
stillAssigned = 0
for r in resonances:
if len(r.peakDimContribs) > 0:
stillAssigned += 1
else:
toDelete.append(r)
for resonance in toDelete:
resonanceSet = resonance.resonanceSet
if resonanceSet:
if len(resonanceSet.resonances) == 1:
resonanceSet.delete()
else:
resonanceSet.removeResonance(resonance)
resonance.delete()
if stillAssigned > 0:
showWarning('Delete failed', '%d resonances not deleted: still assigned to peaks' % stillAssigned)
self.update()
def showPeaks(self, resonance=None):
self.cancelAllWaits()
if resonance:
resonances = [resonance,]
else:
resonances = self.scrolledMatrix.currentObjects
if resonances:
peaksDict = {}
for resonance in resonances:
for contrib in resonance.peakDimContribs:
peaksDict[contrib.peakDim.peak] = 1
peaks = peaksDict.keys()
if len(peaks) > 0:
self.guiParent.viewPeaks(peaks)
def showShiftListPeaks(self, resonance=None):
self.cancelAllWaits()
if resonance:
resonances = [resonance,]
else:
resonances = self.scrolledMatrix.currentObjects
if resonances:
peaks = []
for resonance in resonances:
for contrib in resonance.peakDimContribs:
if contrib.peakDim.peak.peakList.dataSource.experiment.shiftList is self.shiftList:
peaks.append(contrib.peakDim.peak)
if len(peaks) > 0:
self.guiParent.viewPeaks(peaks)
def cancelAllWaits(self):
self.cancelSpinSystemWait()
self.cancelAtomsWait()
def updateShiftLists(self, *opt):
shiftLists = list(self.project.findAllNmrMeasurementLists(className = 'ShiftList'))
shiftListNames = self.getShiftListNames(self.project)
if shiftListNames:
if self.shiftList is None:
i = len(shiftListNames) -1
elif self.shiftList in shiftLists:
i = shiftLists.index(self.shiftList)
else:
i = 0
self.shiftList = shiftLists[0]
self.shiftListPulldown.setup(shiftListNames,i)
else:
self.shiftList = None
self.shiftListPulldown.setup(['None',],0)
def close(self):
self.cancelAllWaits()
BasePopup.close(self)
def destroy(self):
self.unregisterNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'setName')
self.unregisterNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', '__init__')
self.unregisterNotify(self.updateShiftLists, 'ccp.Nmr.ShiftList', 'delete')
for func in ('__init__', 'delete'):
for clazz in ('ccp.Nmr.PeakDimContrib', 'ccp.Nmr.Shift','ccp.Nmr.ResonanceSet', 'ccp.Nmr.Resonance'):
self.unregisterNotify(self.updateAfter, clazz, func)
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.ResonanceSet', 'addResonance')
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setValue')
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.Shift', 'setError')
for func in ('setDetails', 'setIsotopeCode', 'setName'):
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.Resonance', func)
for func in ('setCcpCode', 'addResonance', 'removeResonance', 'setResonances','addAtomSet', 'delete'):
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.ResonanceGroup', func)
self.unregisterNotify(self.updateAfter, 'ccp.Nmr.Shift', 'getResonance')
BasePopup.destroy(self)
def updateAfter(self, object=None):
if self.refresh:
return
shift = None
if object:
if object.className == 'Resonance':
shift = object.findFirstShift(parentList=self.shiftList)
elif object.className == 'ResonanceSet':
for resonance in object.resonances:
shift = resonance.findFirstShift(parentList=self.shiftList)
if shift:
break
elif object.className == 'Shift':
if object.parentList is self.shiftList:
shift = object
elif object.className == 'PeakDimContrib':
shift = object.resonance.findFirstShift(parentList=self.shiftList)
elif object.className == 'ResonanceGroup':
for resonance in object.resonances:
shift = resonance.findFirstShift(parentList=self.shiftList)
if shift:
break
if shift or ( (shift is None) and (self.shiftList is None) ):
self.refresh = 1
self.after_idle(self.update)
else:
self.refresh = 1
self.after_idle(self.update)
def update(self,inp=None):
self.cancelAllWaits()
self.updateChains()
self.updateCcpCodes()
project = self.project
doChain = project.application.getValue(project, keyword='doChainAnnotations', defaultValue=True, isBoolean=True)
doMolSys = project.application.getValue(project, keyword='doMolSysAnnotations', defaultValue=False, isBoolean=True)
resonances = []
shifts = []
matrixData = []
colorMatrix= []
tryResonances = []
tryShifts = []
if self.shiftList:
tryShifts = self.shiftList.measurements
for shift in tryShifts:
tryResonances.append(shift.resonance)
else:
for resonance in project.resonances:
if not resonance.shifts:
tryResonances.append(resonance)
tryShifts.append(None)
i = 0
for resonance in tryResonances:
shift = tryShifts[i]
if self.chain:
residue = getResonanceResidue(resonance)
if not residue or (residue.chain is not self.chain):
i += 1
continue
if self.ccpCode:
residue = getResonanceResidue(resonance)
if not residue or (residue.ccpCode is not self.ccpCode):
i += 1
continue
if resonance.isotopeCode == 'unknown':
if resonance.peakDimContribs:
resonance.isotopeCode = resonance.peakDimContribs[0].peakDim.dataDimRef.expDimRef.isotopeCodes[0]
#print self.isotope, resonance.isotope
if (self.isotope == 'Any') or (self.isotope == resonance.isotopeCode):
if self.status == 'Any':
resonances.append(resonance)
shifts.append(shift)
elif resonance.resonanceSet and (self.status == 'Assigned'):
resonances.append(resonance)
shifts.append(shift)
elif (not resonance.resonanceSet) and (self.status == 'Unassigned'):
resonances.append(resonance)
shifts.append(shift)
elif (len(resonance.peakDimContribs) == 0) and (self.status == 'Orphaned'):
resonances.append(resonance)
shifts.append(shift)
i += 1
i = 0
for resonance in resonances:
data = []
shift = shifts[i]
if shift is None:
shiftValue = None
shiftError = None
else:
shiftValue = shift.value
shiftError = shift.error
if resonance.isotope:
isotopeText = '%d%s' % (resonance.isotope.massNumber, resonance.isotope.chemElement.symbol)
else:
isotopeText = None
data.append(resonance.serial)
data.append(shiftValue)
data.append(shiftError)
(molSystem, chain, residue, name) = getResonanceAtomTuple(resonance)
data.append(name)
if not doChain:
chain = ''
if not doMolSys:
molSystem = ''
if molSystem:
data.append('%s:%s %s' % (molSystem, chain, residue))
elif chain:
data.append('%s %s' % (chain, residue))
else:
data.append(residue)
data.append(isotopeText)
data.append(resonance.name)
#data.append(spinSystemText)
totalDict = {}
sListDict = {}
for contrib in resonance.peakDimContribs:
peak = contrib.peakDim.peak
totalDict[peak] = 1
if self.shiftList is peak.peakList.dataSource.experiment.shiftList:
sListDict[peak] = 1
data.append( len( totalDict.keys() ) )
data.append( len( sListDict.keys() ) )
spinSystemSerial = None
if resonance.resonanceGroup:
spinSystemSerial = resonance.resonanceGroup.serial
data.append( spinSystemSerial )
if resonance.isotope:
color = self.atomColorDict.get(resonance.isotope.chemElement.symbol) or None
else:
color = None
matrixData.append( data )
colorMatrix.append( [color, None, None, None, None, None, None, None, None] )
i += 1
self.waitingForAtoms = 0
self.assignButton.config(self.untoggledDict)
self.updateButtons()
#self.resonance = None
self.resonances = resonances
self.scrolledMatrix.update(objectList = resonances, textMatrix =matrixData, colorMatrix=colorMatrix)
self.refresh = 0
def checkSpinSystem(self, resonance, atomSet):
spinSystem = resonance.resonanceGroup
if spinSystem:
if not spinSystem.residue:
return
if len(spinSystem.resonances) < 2:
return
if spinSystem.residue is not atomSet.atoms[0].residue:
if not showYesNo('Question','Re-assign all resonances in the same residue?'):
removeSpinSystemResonance(spinSystem, resonance)
def exportNmrStar2(self):
if not self.shiftList:
return
chemShiftFile = 'ChemShiftExport.str'
fileHandle = open(chemShiftFile, 'w')
data = []
for shift in self.shiftList.measurements:
resonance = shift.resonance
resonanceSet = resonance.resonanceSet
if resonanceSet:
residue = resonanceSet.atomSets[0].atoms[0].residue
(ms, c, r, name) = getResonanceAtomTuple(resonance)
i = len(resonanceSet.atomSets)
seqId = residue.seqCode
if 'a' in name:
name = resonanceSet.atomSets[0].name
elif 'b' in name:
name = resonanceSet.atomSets[-1].name
else:
name = resonanceSet.atomSets[0].name
if name[-1] == '*':
name = name[:-1]
datum = ['%3.3d%s' % (seqId,name),]
chemElement = resonance.isotope.chemElement.symbol
if chemElement == 'C':
error = 0.12
elif chemElement == 'N':
error = 0.15
else:
error = 0.03
string = '%-6s %-6s %-6s %-4s %6.2f %3.2f %d' % (str(seqId),residue.ccpCode,name,chemElement,shift.value,error,i)
datum.append(string)
data.append(datum)
data.sort()
sortedData = [x[1] for x in data]
i = 0
for datum in sortedData:
i += 1
fileHandle.write('%-6s %s\n' % (str(i),datum))
|