Source code for ccpn.AnalysisStructure.gui.SetupXplorStructureCalcPopup


"""
Alpha version of a popup for setting up a structure calculation using Xplor-NIH calculations.
"""
#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (https://www.ccpn.ac.uk) 2014 - 2022"
__credits__ = ("Ed Brooksbank, Joanna Fox, Victoria A Higman, Luca Mureddu, Eliza Płoskoń",
               "Timothy J Ragan, Brian O Smith, Gary S Thompson & Geerten W Vuister")
__licence__ = ("CCPN licence. See https://ccpn.ac.uk/software/licensing/")
__reference__ = ("Skinner, S.P., Fogh, R.H., Boucher, W., Ragan, T.J., Mureddu, L.G., & Vuister, G.W.",
                 "CcpNmr AnalysisAssign: a flexible platform for integrated NMR analysis",
                 "J.Biomol.Nmr (2016), 66, 111-124, http://doi.org/10.1007/s10858-016-0060-y")
#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: Ed Brooksbank $"
__dateModified__ = "$dateModified: 2022-03-25 15:13:49 +0000 (Fri, March 25, 2022) $"
__version__ = "$Revision: 3.1.0 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: CCPN $"
__date__ = "$Date: 2021-04-27 16:04:57 +0100 (Tue, April 27, 2021) $"
#=========================================================================================
# Start of code
#=========================================================================================

import os
from functools import partial

from PyQt5 import QtCore, QtGui, QtWidgets

import ccpn.ui.gui.widgets.CompoundWidgets as cw
from ccpn.ui.gui.widgets.PulldownListsForObjects import PeakListPulldown, ChemicalShiftListPulldown, ChainPulldown
from ccpn.ui.gui.popups.Dialog import CcpnDialogMainWidget
from ccpn.ui.gui.widgets.ListWidget import ListWidgetPair
from ccpn.ui.gui.widgets.Button import Button
from ccpn.ui.gui.lib.GuiPath import PathEdit
from ccpn.ui.gui.widgets.Label import Label
from ccpn.ui.gui.widgets import MessageDialog
from ccpn.ui.gui.widgets import CheckBox
from ccpn.ui.gui.widgets import Entry
from ccpn.ui.gui.widgets.HLine import LabeledHLine
from ccpn.ui.gui.widgets.FileDialog import ExecutablesFileDialog
from ccpn.ui.gui.widgets.FileDialog import OtherFileDialog
from ccpn.ui.gui.widgets.MessageDialog import showWarning
from ccpn.ui.gui.widgets.Frame import Frame
from ccpn.ui.gui.popups.PreferencesPopup import PreferencesPopup

from ccpn.framework.Application import getApplication
from ccpn.framework.Preferences import getPreferences, XPLOR_NIH_PATH,TALOS_PATH

from ccpn.core.lib.ContextManagers import catchExceptions


[docs]class SetupXplorStructureCalculationPopup(CcpnDialogMainWidget): """ Setup the Xplor calculation """ FIXEDWIDTH = True FIXEDHEIGHT = False _GREY = '#888888' title = 'Setup Xplor_nih Structure Calculation (Alpha)' def __init__(self, parent=None, mainWindow=None, title=title, **kwds): super().__init__(parent, setLayout=True, windowTitle=title, size=(500, 10), minimumSize=None, **kwds) if mainWindow: self.mainWindow = mainWindow self.application = mainWindow.application self.current = self.application.current self.project = mainWindow.project else: self.mainWindow = None self.application = None self.current = None self.project = None self._createWidgets() # enable the buttons # self.tipText = '' # self.setOkButton(callback=self._okCallback, tipText =self.tipText, text='Setup', enabled=True) self.setCloseButton(callback=self.reject, tipText='Close') self.setDefaultButton(CcpnDialogMainWidget.CLOSEBUTTON) self.__postInit__() # self._okButton = self.dialogButtons.button(self.OKBUTTON) def _createWidgets(self): """Create the widgets""" _height = 30 row = -1 # row += 1 # self.pathLabel = Label(self.mainWidget, text="Xplor Run Directory", grid=(row, 0)) # self.pathData = PathEdit(self.mainWidget, grid=(row, 1), vAlign='t', ) # self.pathDataButton = Button(self.mainWidget, grid=(row, 2), callback=self._getPathFromDialog, # icon='icons/directory', hPolicy='fixed') row += 1 Label(self.mainWidget, text="Run name", grid=(row, 0), hAlign='right' ) self.runName = Entry.Entry(self.mainWidget, grid=(row, 1)) self.runName.set('run') row += 1 Label(self.mainWidget, text="Run number", grid=(row, 0), hAlign='right') self.runEntry = Entry.IntEntry(self.mainWidget, grid=(row, 1)) self.runEntry.set(1) row += 1 Label(self.mainWidget, text="Use timestamp", grid=(row, 0), hAlign='right') self.useTimeStamp = CheckBox.CheckBox(self.mainWidget, grid=(row, 1), checked=True) self.useTimeStamp.setEnabled(True) row += 1 Label(self.mainWidget, text="State", grid=(row, 0), hAlign='right') doneFrame = Frame(self.mainWidget, grid=(row, 1), gridSpan=(1,2), setLayout=True) self.setupDone = CheckBox.CheckBox(doneFrame, grid=(0, 0), text='setup done', checked=False) self.setupDone.setEnabled(False) self.calculationDone = CheckBox.CheckBox(doneFrame, grid=(0, 1), text='calculated', checked=False) self.calculationDone.setEnabled(False) self.processDone = CheckBox.CheckBox(doneFrame, grid=(0, 2), text='processed', checked=False) self.processDone.setEnabled(False) self.importDone = CheckBox.CheckBox(doneFrame, grid=(0, 3), text='imported', checked=False) self.importDone.setEnabled(False) # settings row += 1 LabeledHLine(self.mainWidget, text='Settings', grid=(row,0), gridSpan=(1,2), style='DashLine', colour=self._GREY) _preferences = getPreferences() row += 1 Label(self.mainWidget, text="xplor_nih path", grid=(row, 0), hAlign='right') self.xplorPath = Entry.Entry(self.mainWidget, grid=(row, 1), editable=True) self.xplorPath.set(_preferences.get(XPLOR_NIH_PATH)) Button(self.mainWidget, grid=(row, 2), icon='icons/directory', hPolicy='fixed', callback=self._openPreferencesPopup ) row += 1 Label(self.mainWidget, text="talosN path", grid=(row, 0), hAlign='right') self.talosnPath = Entry.Entry(self.mainWidget, grid=(row, 1), editable=True) self.talosnPath.set(_preferences.get(TALOS_PATH)) Button(self.mainWidget, grid=(row, 2), icon='icons/directory', hPolicy='fixed', callback=self._openPreferencesPopup ) row += 1 self.checkLabel = Label(self.mainWidget, text="Use multicore CPU", grid=(row, 0), hAlign='right') self.useParallel = CheckBox.CheckBox(self.mainWidget, grid=(row, 1)) row += 1 self.entryLabel = Label(self.mainWidget, text="Number of CPU Cores", grid=(row, 0), hAlign='right') self.numberOfCores = Entry.IntEntry(self.mainWidget, grid=(row, 1)) self.numberOfCores.set(os.cpu_count()) # input data row += 1 LabeledHLine(self.mainWidget, text='Input data', grid=(row,0), gridSpan=(1,2), style='DashLine', colour=self._GREY) row += 1 Label(self.mainWidget, text="ChemicalShiftList:", grid=(row, 0), hAlign='right') self.cslWidget = ChemicalShiftListPulldown(parent=self.mainWidget, mainWindow=self.mainWindow, grid=(row, 1), showSelectName=True, callback=None, labelText='' # effectively not showing the label ) row += 1 Label(self.mainWidget, text="Chain:", grid=(row, 0), hAlign='right') self.mcWidget = ChainPulldown(parent=self.mainWidget, mainWindow=self.mainWindow, grid=(row, 1), showSelectName=True, # fixedWidths=(None, 300), callback=None, labelText = '' ) row += 1 self.plsLabel = Label(self.mainWidget, text='PeakLists:', grid=(row, 0), hAlign='right') self.plsWidget = ListWidgetPair(self.mainWidget, grid=(row, 1), gridSpan=(1,1)) self.plsWidget.setMinimumHeight(150) # Actions row += 1 LabeledHLine(self.mainWidget, text='Actions', grid=(row,0), gridSpan=(1,2), style='DashLine', colour=self._GREY) # row += 1 # Label(self.mainWidget, text="setup done", grid=(row, 0), hAlign='right') # self.setupDone = CheckBox.CheckBox(self.mainWidget, grid=(row, 1), checked=False) # self.setupDone.setEnabled(False) # # row += 1 # Label(self.mainWidget, text="calculation done", grid=(row, 0), hAlign='right') # self.calculationDone = CheckBox.CheckBox(self.mainWidget, grid=(row, 1), checked=False) # self.calculationDone.setEnabled(False) row += 1 self.setupButton = Button(self.mainWidget, grid=(row, 1), text='Setup', callback=self._setupXplorCalculation, hPolicy='expanding') self.setupButton.setFixedHeight(_height) self._populateWsFromProjectInfo() def _openPreferencesPopup(self): """Open the preferences popup to adjust the executable paths """ _preferences = getPreferences() popup = PreferencesPopup(parent=self.mainWindow, mainWindow=self.mainWindow, preferences = _preferences ) popup.tabWidget.setCurrentIndex(3) popup.exec() self.xplorPath.set(_preferences.get(XPLOR_NIH_PATH)) self.talosnPath.set(_preferences.get(TALOS_PATH)) def _populateWsFromProjectInfo(self): if self.project: self.cslWidget.selectFirstItem() self.mcWidget.selectFirstItem() self.plsWidget._populate(self.plsWidget.rightList, self.project.peakLists) def _getPathFromDialog(self): dialog = OtherFileDialog(parent=self.mainWindow, _useDirectoryOnly=True,) dialog._show() path = dialog.selectedFile() if path: self.pathData.setText(str(path)) def _setupXplorCalculation(self): """Clicked 'setup': setup the calculation """ from ccpn.AnalysisStructure.lib.runManagers.XplorNihRunManager import XplorNihRunManager if self.project is None: raise RuntimeError('Undefined project') runName = self.runName.get() runID = self.runEntry.get() useTimeStamp = self.useTimeStamp.get() csList = self.cslWidget.getSelectedObject() chain = self.mcWidget.getSelectedObject() plsPids = self.plsWidget.rightList.getTexts() if not csList: MessageDialog.showWarning(self.title, 'Please select a ChemicalShiftList first') return if not chain: MessageDialog.showWarning(self.title, 'Please select a Chain first') return if not plsPids: MessageDialog.showWarning(self.title, 'Please include at least one PeakList') return # set up the calculation # xplorPath = self.xplorPath.get() # talosnPath = self.talosnPath.get() myRun = XplorNihRunManager(project = self.project, runName = runName, runId =runID, # xplorPath=xplorPath, talosnPath=talosnPath ) myRun.chemicalShiftList = csList myRun.chain = chain myRun.peakLists = [self.project.getByPid(pl) for pl in plsPids] myRun.useParallel = self.useParallel.isChecked() myRun.numberOfCores = self.numberOfCores.get() with catchExceptions(errorStringTemplate=self.title + '\n%s'): with MessageDialog.progressManager(self, f'Setting-up {myRun.runPath}'): _runDir = myRun.setupCalculation(useTimeStamp=useTimeStamp) myRun.saveState() self.setupDone.set(myRun.setupDone) self.setupButton.setEnabled(not myRun.setupDone) MessageDialog.showInfo(self.title, f'Created directory {_runDir}\n\nplease run "{myRun.scriptPath}" in there' )
if __name__ == '__main__': from ccpn.ui.gui.widgets.Application import newTestApplication from ccpn.framework.Application import getApplication _app = newTestApplication() application = getApplication() popup = SetupXplorStructureCalculationPopup() popup.exec_()