Exemple #1
0
    def findQuanty():
        if sys.platform == "win32":
            executable = "Quanty.exe"
            localPath = resourceAbsolutePath(
                os.path.join("quanty", "bin", "win32"))
        elif sys.platform == "darwin":
            executable = "Quanty"
            localPath = resourceAbsolutePath(
                os.path.join("quanty", "bin", "darwin"))
        else:
            localPath = None
            executable = "Quanty"

        envPath = QStandardPaths.findExecutable(executable)
        if localPath is not None:
            localPath = QStandardPaths.findExecutable(executable, [localPath])

        # Check if Quanty is in the paths defined in the $PATH.
        if envPath:
            path = envPath
        # Check if Quanty is bundled with Crispy.
        elif localPath is not None:
            path = localPath
        else:
            path = None

        if path is None:
            logger.debug("Could not find the Quanty executable."
                         'Please set it up using the "Preferences" dialog.')

        return path
Exemple #2
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "results.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.detailsDialog = DetailsDialog(parent=self)

        # Add a context menu to the view.
        path = os.path.join("gui", "icons", "clipboard.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.showDetailsDialogAction = QAction(
            icon, "Show Details", self, triggered=self.showDetailsDialog
        )

        path = os.path.join("gui", "icons", "save.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.saveSelectedResultsAsAction = QAction(
            icon, "Save Selected Results As...", self, triggered=self.saveSelected
        )

        path = os.path.join("gui", "icons", "trash.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.removeSelectedResultsAction = QAction(
            icon, "Remove Selected Results", self, triggered=self.removeSelected,
        )

        path = os.path.join("gui", "icons", "folder-open.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.loadResultsAction = QAction(
            icon, "Load Results", self, triggered=self.load
        )

        self.contextMenu = QMenu("Results Context Menu", self)
        self.contextMenu.addAction(self.showDetailsDialogAction)
        self.contextMenu.addSeparator()
        self.contextMenu.addAction(self.saveSelectedResultsAsAction)
        self.contextMenu.addAction(self.removeSelectedResultsAction)
        self.contextMenu.addSeparator()
        self.contextMenu.addAction(self.loadResultsAction)

        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested[QPoint].connect(
            self.showResultsContextMenu
        )

        self.model = TreeModel(parent=self)
        self.view.setModel(self.model)
        selectionModel = self.view.selectionModel()
        selectionModel.selectionChanged.connect(self.selectionChanged)

        # TODO: How to distinguish between a dataChanged related to change in
        # the name or a change in the checked state? Only the last one should
        # trigger subsequent actions.
        self.model.dataChanged.connect(self.plot)
        self.currentIndexChanged.connect(
            lambda index: self.detailsDialog.populate(index.internalPointer())
        )

        self._currentIndex = QModelIndex()
Exemple #3
0
    def successful(self, successful):
        # Scroll to the bottom of the logger widget.
        scrollBar = self.parent().loggerWidget.verticalScrollBar()
        scrollBar.setValue(scrollBar.maximum())

        self.calculationPushButton.disconnect()

        path = os.path.join("gui", "icons", "play.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.calculationPushButton.setIcon(icon)
        self.calculationPushButton.setText("Run")
        self.calculationPushButton.setToolTip("Run Quanty.")
        self.calculationPushButton.clicked.connect(self.run)

        if not successful:
            return

        # If the "Hamiltonian Setup" page is currently selected, when the
        # current widget is set to the "Results Page", the former is not
        # displayed. To avoid this we switch first to the "General Setup" page.
        self.toolBox.setCurrentWidget(self.generalPage)
        self.toolBox.setCurrentWidget(self.resultsPage)

        # Move the state to the results model.
        self.state.setParent(self.resultsPage.model.rootItem())
        self.state.checkState = Qt.Checked
        index = self.state.index()
        self.resultsPage.view.setCurrentIndex(index)

        removeFiles = Config().settings.value("Quanty/RemoveFiles", type=bool)
        if removeFiles:
            self.state.clean()
Exemple #4
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "details", "axis.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.mappers = list()
Exemple #5
0
    def __init__(self, parent):
        super(UpdateAvailableDialog, self).__init__(parent)

        uiPath = os.path.join("gui", "uis", "update.ui")
        loadUi(resourceAbsolutePath(uiPath),
               baseinstance=self,
               package="crispy.gui")
Exemple #6
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "main.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.setWindowTitle("Crispy")

        # Set the icon.
        iconPath = os.path.join("gui", "icons", "crispy.png")
        self.setWindowIcon(QIcon(resourceAbsolutePath(iconPath)))

        # Setup the logger widget.
        self.loggerWidget.setFont(fixedFont())
        self.loggerWidget.setLineWrapMode(QPlainTextEdit.NoWrap)

        # Setup the about dialog.
        self.aboutDialog = AboutDialog(parent=self)

        # Instantiate the Quanty dock widget.
        self.quantyDockWidget = DockWidget(parent=self)
        self.quantyDockWidget.setVisible(True)
        self.addDockWidget(Qt.RightDockWidgetArea, self.quantyDockWidget)

        # Compose the menu.
        menu = self.menuBar().addMenu("Quanty")
        menu.addAction(self.quantyDockWidget.preferencesAction)
        menu.addSeparator()
        menu.addAction(self.quantyDockWidget.saveInputAction)
        menu.addAction(self.quantyDockWidget.saveInputAsAction)
        menu.addSeparator()
        menu.addAction(self.quantyDockWidget.showHideAction)

        menu = self.menuBar().addMenu("Help")
        self.openAboutDialogAction = QAction(
            "About Crispy", self, triggered=self.openAboutDialog
        )
        menu.addAction(self.openAboutDialogAction)

        # Register a handler to display messages in the status bar.
        l = logging.getLogger("crispy")
        handler = StatusBarHandler()
        l.addHandler(handler)
        handler.logUpdated.connect(self.updateStatusBar)

        handler = OutputHandler()
        l.addHandler(handler)
Exemple #7
0
    def started(self):
        self.calculationPushButton.disconnect()

        path = os.path.join("gui", "icons", "stop.svg")
        icon = QIcon(resourceAbsolutePath(path))
        self.calculationPushButton.setIcon(icon)
        self.calculationPushButton.setText("Stop")
        self.calculationPushButton.setToolTip("Stop Quanty.")
        self.calculationPushButton.clicked.connect(self.stop)
Exemple #8
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "hamiltonian.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.mappers = list()
        # This is needed for the updateAutoStates.
        self.hamiltonian = None
Exemple #9
0
    def __init__(self, parent):
        super(AboutDialog, self).__init__(parent)

        uiPath = os.path.join("gui", "uis", "about.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.nameLabel.setText(f"Crispy {version}")

        self.updateCheckBox.stateChanged.connect(self.updateCheckBoxStateChanged)
        self.updateCheckBox.setChecked(settings.value("CheckForUpdates", type=bool))

        if settings.value("CheckForUpdates", type=bool):
            self.runUpdateCheck()
Exemple #10
0
    def __init__(self, parent):
        super().__init__(parent)

        uiPath = os.path.join("gui", "uis", "quanty", "preferences.ui")
        loadUi(resourceAbsolutePath(uiPath),
               baseinstance=self,
               package="crispy.gui")

        self.pathBrowsePushButton.clicked.connect(self.setExecutablePath)

        ok = self.buttonBox.button(QDialogButtonBox.Ok)
        ok.clicked.connect(self.acceptSettings)

        cancel = self.buttonBox.button(QDialogButtonBox.Cancel)
        cancel.clicked.connect(self.rejectSettings)
Exemple #11
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "main.ui")
        loadUi(resourceAbsolutePath(uiPath),
               baseinstance=self,
               package="crispy.gui")

        self.model = TreeModel()

        self.preferencesDialog = PreferencesDialog(self)

        # Remove the placeholder page.
        self.toolBox.removeItem(0)

        self.generalPage = GeneralSetupPage()
        self.toolBox.addItem(self.generalPage, "General Setup")

        self.hamiltonianPage = HamiltonianSetupPage()
        self.toolBox.addItem(self.hamiltonianPage, "Hamiltonian Setup")

        self.resultsPage = ResultsPage()
        self.toolBox.addItem(self.resultsPage, "Results")

        # Setup the initial state and populate the widgets.
        self.state = Calculation(parent=self.model.rootItem())

        self.generalPage.comboBoxChanged.connect(self.populate)
        self.resultsPage.currentIndexChanged.connect(self.populate)

        self.saveInputAsPushButton.clicked.connect(self.saveInputAs)
        self.calculationPushButton.clicked.connect(self.run)

        # Set up the actions.
        self.preferencesAction = QAction("Preferences...",
                                         self,
                                         triggered=self.preferencesDialog.show)
        self.preferencesAction.setMenuRole(QAction.NoRole)

        self.saveInputAction = QAction("Save Input",
                                       self,
                                       triggered=self.saveInput)
        self.saveInputAsAction = QAction("Save Input As...",
                                         self,
                                         triggered=self.saveInputAs)
        self.showHideAction = QAction("Show/Hide Module",
                                      self,
                                      triggered=self.showHide)
Exemple #12
0
    def replacements(self):
        replacements = super().replacements

        # Read term specific parameters.
        path = resourceAbsolutePath(
            os.path.join("quanty", "parameters", f"{self.element.symbol}.h5")
        )

        initial_configuration, *_ = self.configurations
        with h5py.File(path, "r") as h5:
            parameters = h5[f"{initial_configuration}/{self.name}"]
            for parameterName, value in parameters.items():
                value = float(value[()])
                replacements[parameterName] = value

        return replacements
Exemple #13
0
    def __init__(self, parent=None):
        super().__init__(parent)

        uiPath = os.path.join("gui", "uis", "quanty", "progress.ui")
        loadUi(resourceAbsolutePath(uiPath),
               baseinstance=self,
               package="crispy.gui")

        self.message = "The calculation is running. Please wait"
        self.dots = cycle([".", "..", "..."])
        self.currentMessage = self.message + next(self.dots)

        self.label.setText(self.currentMessage)
        self.cancelButton.clicked.connect(self.reject)

        timer = QTimer(self, interval=750, timeout=self.changeMessage)
        timer.start()
Exemple #14
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "general.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        self.xAxis = AxisWidget()
        self.yAxis = AxisWidget()
        self.axesTabWidget.addTab(self.xAxis, None)

        self.mappers = list()

        self.symbolComboBox.currentTextChanged.connect(self.comboBoxChanged)
        self.chargeComboBox.currentTextChanged.connect(self.comboBoxChanged)
        self.symmetryComboBox.currentTextChanged.connect(self.comboBoxChanged)
        self.experimentComboBox.currentTextChanged.connect(self.comboBoxChanged)
        self.edgeComboBox.currentTextChanged.connect(self.comboBoxChanged)
Exemple #15
0
    def __init__(self, parent=None, name="Atomic"):
        super().__init__(parent=parent, name=name)

        path = resourceAbsolutePath(
            os.path.join("quanty", "parameters", f"{self.element.symbol}.h5")
        )

        with h5py.File(path, "r") as h5:
            for configuration, (hamiltonianName, _) in zip(
                self.configurations, self.hamiltonianNames
            ):
                hamiltonian = BaseItem(self, hamiltonianName)
                parameters = h5[f"{configuration}/{self.name}"]
                for parameterName, value in parameters.items():
                    value = float(value[()])
                    scaleFactor = self.scaleFactorFromName(parameterName)
                    HamiltonianParameter(hamiltonian, parameterName, value, scaleFactor)

        self._checkState = Qt.Checked
Exemple #16
0
    def findQuanty():
        if sys.platform == "win32":
            executable = "Quanty.exe"
        else:
            executable = "Quanty"

        envPath = QStandardPaths.findExecutable(executable)
        localPath = resourceAbsolutePath(os.path.join("quanty", "bin"))
        localPath = QStandardPaths.findExecutable(executable, [localPath])

        # Check if Quanty is in the paths defined in the $PATH.
        if envPath:
            path = envPath
        # Check if Quanty is bundled with Crispy.
        elif localPath:
            path = localPath
        else:
            path = None

        return path
Exemple #17
0
    def input(self):
        path = resourceAbsolutePath(
            os.path.join("quanty", "templates", f"{self.templateName}"))
        try:
            with open(path) as fp:
                template = fp.read()
        except FileNotFoundError as e:
            message = f"Could not find the template file {self.templateName}."
            logger.error(message)
            raise e

        for pattern, replacement in self.replacements.items():
            # True/False in Lua are lowercase.
            if isinstance(replacement, bool):
                replacement = str(replacement).lower()
            else:
                replacement = str(replacement)
            template = template.replace(f"${pattern}", str(replacement))

        return template
Exemple #18
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        uiPath = os.path.join("gui", "uis", "quanty", "details", "main.ui")
        loadUi(resourceAbsolutePath(uiPath), baseinstance=self, package="crispy.gui")

        font = fixedFont()
        self.inputText.setFont(font)
        self.outputText.setFont(font)
        # self.summaryText.setFont(font)

        self.xAxis = AxisWidget()
        self.yAxis = AxisWidget()
        self.axesTabWidget.addTab(self.xAxis, None)

        self.mappers = list()

        # This avoids closing the window after changing the value in a line
        # edit and then pressing return.
        self.closePushButton.setAutoDefault(False)
        self.closePushButton.clicked.connect(self.close)
Exemple #19
0
# coding: utf-8
###################################################################
# Copyright (c) 2016-2020 European Synchrotron Radiation Facility #
#                                                                 #
# Author: Marius Retegan                                          #
#                                                                 #
# This work is licensed under the terms of the MIT license.       #
# For further information, see https://github.com/mretegan/crispy #
###################################################################
"""This package provides functionality related to Quanty calculations."""

import os
import json
import xraydb

from crispy import resourceAbsolutePath

XDB = xraydb.XrayDB()

path = os.path.join("quanty", "calculations.json")
with open(resourceAbsolutePath(path)) as fp:
    CALCULATIONS = json.load(fp, object_hook=dict)