CcpNmr Analysis Windows

Introduction

CcpNmr Analysis displays spectra using contour displays that are equivalent to the SpectrumWindow object in the CCPN data model. Analysis itself will create SpectrumWindows automatically whenever a spectrum is opened if there is no existing matching SpectrumWindow. Nonetheless new SpectrumWindows can also be created at any time.

 

Analysis Projects

This guide assumes that you have analysis installed and a relevant analysis project containing NMR spectra.  If you do not have such a project, then you can use the analysis tutorial project.  Firstly we get hold of the top-level AnalysisProject that will contain all of the data model objects specific to CcpNmr Analysis. Normally there is only one AnalysisProject in each CCPN project (MemopsRoot).  The following code will try to find an existing AnalysisProject in the main CCPN project, and if none exists then it will create one:

# Standard way to get the MemopsRoot project on the analysis command line.

project = top.project

nmrProject = project.currentNmrProject

analysisProject = project.findFirstAnalysisProject()

if not analysisProject:

  analysisProject = project.newAnalysisProject(name="myAnalysisProject", nmrProject=nmrProject)

Spectrum Windows

To create a new SpectrumWindow one only needs to specify a name when calling the creation function from an AnalysisProject:

spectrumWindow = analysisProject.newSpectrumWindow(name="myWindow")

However, this is not a complete solution and does not work if you try it from inside Analysis.  So when you create a window this way then by default the new window is only 2D, and the display region in each of the dimensions is set to a not-very useful default (0.0 to 1.0) and the types of the window's axes are not set.  Inside Analysis when you create a SpectrumWindow object then it tries to create a popup window, and that fails if in particular the axis types are not set.

There is a high-level utility function, createSpectrumWindow(), which deals with most of these issues.  It requires the desired axis types to be specified.  Here is an example of a 3D SpectrumWindow created with ("1H", "15N", "1H") axes (via the axisTypes variable), assuming that those AxisType objects themselves have already been created (and Analysis does that for you):

from ccpnmr.analysis.core.WindowBasic import createSpectrumWindow

axisTypeH = analysisProject.findFirstAxisType(isotopeCodes=("1H",))

axisTypeN = analysisProject.findFirstAxisType(isotopeCodes=("15N",))

axisTypes = (axisTypeH, axisTypeN, axisTypeH)

spectrumWindow = createSpectrumWindow(project, 'myWindow', [axisTypes,])

If you have a list of peaks and want to zoom out so that all are visible then there is a utility function for that:

from ccpnmr.analysis.core.WindowBasic import zoomToShowPeaks

spectrumWindowPane = spectrumWindow.findFirstSpectrumWindowPane()

zoomToShowPeaks(peaks, spectrumWindowPane)

# For example for the analysis tutorial

spectrum = nmrProject.findFirstExperiment(name='HSQC').findFirstDataSource(dataType='processed')

peaks = spectrum.findFirstPeakList().sortedPeaks()[:10]

Much of the functionality available for the manipulation of the Analysis-specific objects like SpectrumWindows only makes sense in the context where Analysis is running.  In this case there is available a "top" object which represents the main Analysis dialog.  This top object is instantiated at run time and has links to all the other objects.

The top object is available (for example) either directly at the Analysis Python prompt or indirectly via the argServer argument in Analysis macros.

For example, there is a utility function that displays each of the peaks in its own strip and that requires the top object as the first argument:

from ccpnmr.analysis.core.WindowBasic import displayPeakStrips

spectrumWindowPane = spectrumWindow.findFirstSpectrumWindowPane()

displayPeakStrips(top, peaks, spectrumWindowPane)

Analysis Spectrum

The AnalysisSpectrum class exists only because there is some information about spectra that is Analysis-specific, in particular things like colours and contour levels used for drawing spectra.

Analysis will automatically create an AnalysisSpectrum object for a given spectrum (DataSource) if one does not already exist.  Once one exists one can access it directly from the spectrum object:

analysisSpectrum = spectrum.analysisSpectrum

print "positive contour colours = %s" % analysisSpectrum.posColors

Spectrum Window View

The SpectrumWindowView class exists only because there is some information about windows that is spectrum-specific, for example, whether the positive contours are drawn for a given spectrum in a given window.

Analysis will automatically create a SpectrumWindowView object in a given SpectrumWindow everytime a new Spectrum (DataSource) object is created that can be mapped onto that window.  And it will also automatically create a SpectrumWindowView for every Spectrum that gets mapped into a new SpectrumWindow.

If you want to list all spectra that are mapped into a given SpectrumWindow and say whether the positive contours are drawn, then you can do:

spectrumWindowPane = spectrumWindow.findFirstSpectrumWindowPane()

for spectrumWindowView in spectrumWindowPane.spectrumWindowViews:

  spectrum = spectrumWindowView.analysisSpectrum.dataSource

  print "Spectrum %s:%s positive contours drawn: %s" % (

       spectrum.experiment.name, spectrum.name, spectrumWindowView.isPosVisible)