File: panel_spectrum_generator.py

package info (click to toggle)
mmass 5.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 9,448 kB
  • ctags: 3,272
  • sloc: python: 33,626; xml: 8,150; ansic: 1,731; makefile: 84; sh: 2
file content (643 lines) | stat: -rw-r--r-- 23,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# -------------------------------------------------------------------------
#     Copyright (C) 2005-2013 Martin Strohalm <www.mmass.org>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 3 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#     GNU General Public License for more details.

#     Complete text of GNU GPL can be found in the file LICENSE.TXT in the
#     main directory of the program.
# -------------------------------------------------------------------------

# load libs
import threading
import wx
import numpy

# load modules
import mwx
import images
import config
import mspy
import mspy.plot


# FLOATING PANEL WITH SPECTRUM GENERATOR TOOL
# -------------------------------------------

class panelSpectrumGenerator(wx.MiniFrame):
    """Spectrum generator tool."""
    
    def __init__(self, parent):
        wx.MiniFrame.__init__(self, parent, -1, 'Spectrum Generator', size=(700, 400), style=wx.DEFAULT_FRAME_STYLE & ~ wx.MAXIMIZE_BOX)
        
        self.parent = parent
        
        self.processing = None
        
        self.currentDocument = None
        self.currentProfile = None
        self.currentPeaks = None
        
        # init container
        self.spectrumContainer = mspy.plot.container([])
        
        # make gui items
        self.makeGUI()
        wx.EVT_CLOSE(self, self.onClose)
    # ----
    
    
    def makeGUI(self):
        """Make panel gui."""
        
        # make toolbar
        toolbar = self.makeToolbar()
        controlbar = self.makeControlbar()
        
        # make panels
        canvas = self.makeSpectrumCanvas()
        gauge = self.makeGaugePanel()
        
        # pack element
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainSizer.Add(toolbar, 0, wx.EXPAND, 0)
        self.mainSizer.Add(controlbar, 0, wx.EXPAND, 0)
        self.mainSizer.Add(canvas, 1, wx.EXPAND, 0)
        self.mainSizer.Add(gauge, 0, wx.EXPAND, 0)
        
        # hide gauge
        self.mainSizer.Hide(3)
        
        # fit layout
        self.mainSizer.Fit(self)
        self.SetSizer(self.mainSizer)
        self.SetMinSize(self.GetSize())
        mwx.layout(self, self.mainSizer)
    # ----
    
    
    def makeToolbar(self):
        """Make toolbar."""
        
        # init toolbar
        panel = mwx.bgrPanel(self, -1, images.lib['bgrToolbar'], size=(-1, mwx.TOOLBAR_HEIGHT))
        
        # make elements
        peakShape_label = wx.StaticText(panel, -1, "Peak shape:")
        peakShape_label.SetFont(wx.SMALL_FONT)
        self.peakShape_choice = wx.Choice(panel, -1, choices=['Symmetrical', 'Asymmetrical'], size=(125, mwx.CHOICE_HEIGHT))
        self.peakShape_choice.Select(0)
        if config.spectrumGenerator['peakShape'] == 'gausslorentzian':
            self.peakShape_choice.Select(1)
        
        fwhm_label = wx.StaticText(panel, -1, "Default FWHM:")
        fwhm_label.SetFont(wx.SMALL_FONT)
        self.fwhm_value = wx.TextCtrl(panel, -1, str(config.spectrumGenerator['fwhm']), size=(60, -1), validator=mwx.validator('floatPos'))
        
        self.forceFwhm_check = wx.CheckBox(panel, -1, "Force")
        self.forceFwhm_check.SetFont(wx.SMALL_FONT)
        self.forceFwhm_check.SetValue(config.spectrumGenerator['forceFwhm'])
        
        points_label = wx.StaticText(panel, -1, "Points/peak:")
        points_label.SetFont(wx.SMALL_FONT)
        self.points_value = wx.TextCtrl(panel, -1, str(config.spectrumGenerator['points']), size=(60, -1), validator=mwx.validator('intPos'))
        
        noise_label = wx.StaticText(panel, -1, "Noise width:")
        noise_label.SetFont(wx.SMALL_FONT)
        self.noise_value = wx.TextCtrl(panel, -1, str(config.spectrumGenerator['noise']), size=(80, -1), validator=mwx.validator('floatPos'))
        
        self.generate_butt = wx.Button(panel, -1, "Generate", size=(-1, mwx.SMALL_BUTTON_HEIGHT))
        self.generate_butt.Bind(wx.EVT_BUTTON, self.onGenerate)
        
        self.apply_butt = wx.Button(panel, -1, "Apply", size=(-1, mwx.SMALL_BUTTON_HEIGHT))
        self.apply_butt.Bind(wx.EVT_BUTTON, self.onApply)
        
        # pack elements
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddSpacer(mwx.CONTROLBAR_LSPACE)
        sizer.Add(peakShape_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        sizer.Add(self.peakShape_choice, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.Add(fwhm_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        sizer.Add(self.fwhm_value, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        sizer.Add(self.forceFwhm_check, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.Add(points_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        sizer.Add(self.points_value, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.Add(noise_label, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 5)
        sizer.Add(self.noise_value, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.AddStretchSpacer()
        sizer.Add(self.generate_butt, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 10)
        sizer.Add(self.apply_butt, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(mwx.CONTROLBAR_RSPACE)
        
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(sizer, 1, wx.EXPAND)
        panel.SetSizer(mainSizer)
        mainSizer.Fit(panel)
        
        return panel
    # ----
    
    
    def makeControlbar(self):
        """Make controlbar."""
        
        # init toolbar
        panel = mwx.bgrPanel(self, -1, images.lib['bgrControlbar'], size=(-1, mwx.CONTROLBAR_HEIGHT))
        
        # make elements
        self.collapse_butt = wx.BitmapButton(panel, -1, images.lib['arrowsDown'], size=(mwx.TOOLBAR_TOOLSIZE), style=wx.BORDER_NONE)
        self.collapse_butt.Bind(wx.EVT_BUTTON, self.onCollapse)
        
        self.showPeaks_check = wx.CheckBox(panel, -1, "Show peaks")
        self.showPeaks_check.SetFont(wx.SMALL_FONT)
        self.showPeaks_check.SetValue(config.spectrumGenerator['showPeaks'])
        self.showPeaks_check.Bind(wx.EVT_CHECKBOX, self.onShowPeaks)
        
        self.showOverlay_check = wx.CheckBox(panel, -1, "Show overlay")
        self.showOverlay_check.SetFont(wx.SMALL_FONT)
        self.showOverlay_check.SetValue(config.spectrumGenerator['showOverlay'])
        self.showOverlay_check.Bind(wx.EVT_CHECKBOX, self.onShowOverlay)
        
        self.showFlipped_check = wx.CheckBox(panel, -1, "Flip overlay")
        self.showFlipped_check.SetFont(wx.SMALL_FONT)
        self.showFlipped_check.SetValue(config.spectrumGenerator['showFlipped'])
        self.showFlipped_check.Bind(wx.EVT_CHECKBOX, self.onShowFlipped)
        
        # pack elements
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddSpacer(mwx.CONTROLBAR_LSPACE)
        sizer.Add(self.collapse_butt, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(10)
        sizer.Add(self.showPeaks_check, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.Add(self.showOverlay_check, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(20)
        sizer.Add(self.showFlipped_check, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(mwx.CONTROLBAR_RSPACE)
        
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(sizer, 1, wx.EXPAND)
        mainSizer.Fit(panel)
        panel.SetSizer(mainSizer)
        
        return panel
    # ----
    
    
    def makeSpectrumCanvas(self):
        """Make plot canvas and set defalt parameters."""
        
        # init canvas
        self.spectrumCanvas = mspy.plot.canvas(self, size=(700, 350), style=mwx.PLOTCANVAS_STYLE_PANEL)
        
        # set default params
        self.updateCanvasProperties(refresh=False)
        self.spectrumCanvas.setProperties(showZero=True)
        self.spectrumCanvas.setProperties(showLegend=False)
        self.spectrumCanvas.setProperties(showGel=False)
        self.spectrumCanvas.setProperties(showCurXPos=True)
        self.spectrumCanvas.setProperties(showCurYPos=True)
        self.spectrumCanvas.setProperties(showCurCharge=True)
        self.spectrumCanvas.setProperties(zoomAxis='x')
        self.spectrumCanvas.setProperties(reverseScrolling=config.main['reverseScrolling'])
        self.spectrumCanvas.setProperties(reverseDrawing=True)
        
        self.spectrumCanvas.setLMBFunction('xDistance')
        
        self.spectrumCanvas.draw(self.spectrumContainer)
        
        return self.spectrumCanvas
    # ----
    
    
    def makeGaugePanel(self):
        """Make processing gauge."""
        
        panel = wx.Panel(self, -1)
        
        # make elements
        self.gauge = mwx.gauge(panel, -1)
        
        stop_butt = wx.BitmapButton(panel, -1, images.lib['stopper'], style=wx.BORDER_NONE)
        stop_butt.Bind(wx.EVT_BUTTON, self.onStop)
        
        # pack elements
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.gauge, 1, wx.ALIGN_CENTER_VERTICAL)
        sizer.AddSpacer(10)
        sizer.Add(stop_butt, 0, wx.ALIGN_CENTER_VERTICAL)
        
        # fit layout
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        if wx.Platform == '__WXMAC__':
            mainSizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP, -1)
        mainSizer.Add(sizer, 1, wx.EXPAND|wx.ALL, mwx.GAUGE_SPACE)
        panel.SetSizer(mainSizer)
        mainSizer.Fit(panel)
        
        return panel
    # ----
    
    
    def onClose(self, evt):
        """Close panel."""
        
        # check processing
        if self.processing != None:
            wx.Bell()
            return
        
        self.parent.updateTmpSpectrum(None)
        self.Destroy()
    # ----
    
    
    def onProcessing(self, status=True):
        """Show processing gauge."""
        
        self.gauge.SetValue(0)
        
        if status:
            self.MakeModal(True)
            self.mainSizer.Show(3)
        else:
            self.MakeModal(False)
            self.mainSizer.Hide(3)
            self.processing = None
            mspy.start()
        
        # fit layout
        self.Layout()
        self.mainSizer.Fit(self)
        try: wx.Yield()
        except: pass
    # ----
    
    
    def onStop(self, evt):
        """Cancel current processing."""
        
        if self.processing and self.processing.isAlive():
            mspy.stop()
        else:
            wx.Bell()
    # ----
    
    
    def onGenerate(self, evt):
        """Generate compounds ions."""
        
        # check processing
        if self.processing:
            return
        
        # clear recent
        self.currentProfile = None
        self.currentPeaks = None
        
        # check document
        if not self.currentDocument or len(self.currentDocument.spectrum.peaklist) == 0:
            wx.Bell()
            return
        
        # get params
        if not self.getParams():
            self.updateSpectrumCanvas()
            self.parent.updateTmpSpectrum(None)
            return
        
        # show processing gauge
        self.onProcessing(True)
        self.generate_butt.Enable(False)
        self.apply_butt.Enable(False)
        
        # do processing
        self.processing = threading.Thread(target=self.runSpectrumGenerator)
        self.processing.start()
        
        # pulse gauge while working
        while self.processing and self.processing.isAlive():
            self.gauge.pulse()
        
        # update spectrum canvas
        self.updateSpectrumCanvas(rescale=False)
        
        # update spectrum overlay
        self.updateSpectrumOverlay()
        
        # hide processing gauge
        self.onProcessing(False)
        self.generate_butt.Enable(True)
        self.apply_butt.Enable(True)
    # ----
    
    
    def onApply(self, evt):
        """Apply current profile to current document."""
        
        # check data and document
        if self.currentDocument == None or self.currentProfile == None:
            wx.Bell()
            return
        
        # ask to owerwrite spectrum
        if self.currentDocument.spectrum.hasprofile():
            title = 'Do you really want to apply generated spectrum\nto current document?'
            message = 'Original profile data will be lost.'
            buttons = [(wx.ID_CANCEL, "Cancel", 80, False, 15), (wx.ID_OK, "Apply", 80, True, 0)]
            dlg = mwx.dlgMessage(self, title, message, buttons)
            if dlg.ShowModal() != wx.ID_OK:
                dlg.Destroy()
                return
            else:
                dlg.Destroy()
        
        # backup document
        self.currentDocument.backup(('spectrum'))
        
        # set profile to document
        points = self.currentProfile.copy()
        self.currentDocument.spectrum.setprofile(points)
        
        # update document
        self.parent.onDocumentChanged(items=('spectrum'))
    # ----
    
    
    def onCollapse(self, evt):
        """Collapse spectrum panel."""
        
        # Show / hide panel
        if self.mainSizer.IsShown(2):
            self.mainSizer.Hide(2)
            self.collapse_butt.SetBitmapLabel(images.lib['arrowsRight'])
        else:
            self.mainSizer.Show(2)
            self.collapse_butt.SetBitmapLabel(images.lib['arrowsDown'])
        
        # fit layout
        self.SetMinSize((-1,-1))
        self.Layout()
        self.mainSizer.Fit(self)
        self.SetMinSize(self.GetSize())
    # ----
    
    
    def onShowPeaks(self, evt):
        """Show / hide individual peaks."""
        
        # get value
        config.spectrumGenerator['showPeaks'] = self.showPeaks_check.GetValue()
        
        # update spectrum canvas
        self.updateSpectrumCanvas(rescale=False)
    # ----
    
    
    def onShowOverlay(self, evt):
        """Show / hide profile overlay in main viewer."""
        
        # get value
        config.spectrumGenerator['showOverlay'] = self.showOverlay_check.GetValue()
        
        # update tmp spectrum
        self.updateSpectrumOverlay()
    # ----
    
    
    def onShowFlipped(self, evt):
        """Flip profile overlay in main viewer."""
        
        # get value
        config.spectrumGenerator['showFlipped'] = self.showFlipped_check.GetValue()
        
        # update tmp spectrum
        self.updateSpectrumOverlay()
    # ----
    
    
    def setData(self, document):
        """Set data."""
        
        # set new document
        self.currentDocument = document
        self.currentProfile = None
        self.currentPeaks = None
        
        # update gui
        self.updateSpectrumCanvas()
        self.parent.updateTmpSpectrum(None)
    # ----
    
    
    def getParams(self):
        """Get all params from dialog."""
        
        # try to get values
        try:
            config.spectrumGenerator['fwhm'] = abs(float(self.fwhm_value.GetValue()))
            config.spectrumGenerator['points'] = abs(int(self.points_value.GetValue()))
            config.spectrumGenerator['noise'] = abs(float(self.noise_value.GetValue()))
            config.spectrumGenerator['forceFwhm'] = self.forceFwhm_check.GetValue()
            
            config.spectrumGenerator['peakShape'] = 'gaussian'
            if self.peakShape_choice.GetStringSelection() == 'Asymmetrical':
                config.spectrumGenerator['peakShape'] = 'gausslorentzian'
            
            return True
            
        except:
            wx.Bell()
            return False
    # ----
    
    
    def updateCanvasProperties(self, refresh=True):
        """Set current canvas properties."""
        
        # set common properties
        self.spectrumCanvas.setProperties(xLabel=config.spectrum['xLabel'])
        self.spectrumCanvas.setProperties(yLabel=config.spectrum['yLabel'])
        self.spectrumCanvas.setProperties(showGrid=config.spectrum['showGrid'])
        self.spectrumCanvas.setProperties(showMinorTicks=config.spectrum['showMinorTicks'])
        self.spectrumCanvas.setProperties(showXPosBar=config.spectrum['showPosBars'])
        self.spectrumCanvas.setProperties(showYPosBar=config.spectrum['showPosBars'])
        self.spectrumCanvas.setProperties(posBarSize=config.spectrum['posBarSize'])
        self.spectrumCanvas.setProperties(showCurImage=config.spectrum['showCursorImage'])
        self.spectrumCanvas.setProperties(checkLimits=config.spectrum['checkLimits'])
        self.spectrumCanvas.setProperties(autoScaleY=config.spectrum['autoscale'])
        self.spectrumCanvas.setProperties(overlapLabels=config.spectrum['overlapLabels'])
        self.spectrumCanvas.setProperties(xPosDigits=config.main['mzDigits'])
        self.spectrumCanvas.setProperties(yPosDigits=config.main['intDigits'])
        self.spectrumCanvas.setProperties(distanceDigits=config.main['mzDigits'])
        
        # set font
        axisFont = wx.Font(config.spectrum['axisFontSize'], wx.SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0)
        self.spectrumCanvas.setProperties(axisFont=axisFont)
        
        # set cursor
        cursor = (wx.StockCursor(wx.CURSOR_ARROW), images.lib['cursorsCrossMeasure'])
        self.spectrumCanvas.setCursorImage(cursor[bool(config.spectrum['showTracker'])])
        self.spectrumCanvas.setMFunction([None, 'cross'][config.spectrum['showTracker']])
        
        # set spectum properties
        if len(self.spectrumContainer):
            self.spectrumContainer[0].setProperties(showPoints=config.spectrum['showDataPoints'])
            self.spectrumContainer[0].setProperties(showLabels=config.spectrum['showLabels'])
            self.spectrumContainer[0].setProperties(labelBgr=config.spectrum['labelBgr'])
            self.spectrumContainer[0].setProperties(labelAngle=config.spectrum['labelAngle'])
        
        # refresh canvas
        if refresh:
            self.spectrumCanvas.refresh()
    # ----
    
    
    def updateSpectrumCanvas(self, rescale=True):
        """Show current profile and peaks in canvas."""
        
        # clear container
        self.spectrumContainer.empty()
        
        # check document
        if not self.currentDocument:
            self.spectrumCanvas.draw(self.spectrumContainer)
            return
        
        # get current peaklist
        peaklist = self.currentDocument.spectrum.peaklist
        
        # get current profile data
        profile = []
        if self.currentProfile != None:
            profile = self.currentProfile
        
        # add main profile spectrum to container
        labelFont = wx.Font(config.spectrum['labelFontSize'], wx.SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0)
        spectrum = mspy.plot.spectrum(
            scan = mspy.scan(profile=profile, peaklist=peaklist),
            spectrumColour = (16,71,185),
            tickColour = (255,0,0),
            showPoints = config.spectrum['showDataPoints'],
            showLabels = config.spectrum['showLabels'],
            showTicks = True,
            labelDigits = config.main['mzDigits'],
            labelBgr = config.spectrum['labelBgr'],
            labelAngle = config.spectrum['labelAngle'],
            labelFont = labelFont
        )
        self.spectrumContainer.append(spectrum)
        
        # add individual peaks to container
        if config.spectrumGenerator['showPeaks']:
            if self.currentPeaks != None:
                for peak in self.currentPeaks:
                    spectrum = mspy.plot.points(
                        points = peak,
                        lineColour = (50,140,0),
                        showLines = True,
                        showPoints = False,
                        exactFit = True
                    )
                    self.spectrumContainer.append(spectrum)
        
        # get current axis
        if not rescale:
            xAxis = self.spectrumCanvas.getCurrentXRange()
            yAxis = self.spectrumCanvas.getCurrentYRange()
        else:
            xAxis = None
            yAxis = None
        
        # draw spectra
        self.spectrumCanvas.draw(self.spectrumContainer, xAxis=xAxis, yAxis=yAxis)
    # ----
    
    
    def updateSpectrumOverlay(self):
        """Show / hide profile overlay in main viewer."""
        
        # update tmp spectrum
        if self.currentProfile == None or not config.spectrumGenerator['showOverlay']:
            self.parent.updateTmpSpectrum(None)
        else:
            self.parent.updateTmpSpectrum(self.currentProfile, flipped=config.spectrumGenerator['showFlipped'])
    # ----
    
    
    def runSpectrumGenerator(self):
        """Generate spectrum."""
        
        self.currentProfile = None
        self.currentPeaks = None
        
        # run task
        try:
            
            # make profile spectrum
            self.currentProfile = mspy.profile(
                peaklist = self.currentDocument.spectrum.peaklist,
                fwhm = config.spectrumGenerator['fwhm'],
                points = config.spectrumGenerator['points'],
                noise = config.spectrumGenerator['noise'],
                forceFwhm = config.spectrumGenerator['forceFwhm'],
                model = config.spectrumGenerator['peakShape'],
            )
            
            # make peak spectra
            self.currentPeaks = []
            for peak in self.currentDocument.spectrum.peaklist:
                
                # get fwhm
                fwhm = config.spectrumGenerator['fwhm']
                if peak.fwhm and not config.spectrumGenerator['forceFwhm']:
                    fwhm = peak.fwhm
                
                # gaussian shape
                if config.spectrumGenerator['peakShape'] == 'gaussian':
                    points = mspy.gaussian(
                        x = peak.mz,
                        minY = peak.base,
                        maxY = peak.ai,
                        fwhm = fwhm
                    )
                
                # lorentzian shape
                elif config.spectrumGenerator['peakShape'] == 'lorentzian':
                    points = mspy.lorentzian(
                        x = peak.mz,
                        minY = peak.base,
                        maxY = peak.ai,
                        fwhm = fwhm
                    )
                
                # gauss-lorentzian shape
                elif config.spectrumGenerator['peakShape'] == 'gausslorentzian':
                    points = mspy.gausslorentzian(
                        x = peak.mz,
                        minY = peak.base,
                        maxY = peak.ai,
                        fwhm = fwhm
                    )
                
                self.currentPeaks.append(points)
        
        # task canceled
        except mspy.ForceQuit:
            self.currentProfile = None
            self.currentPeaks = None
    # ----