Beispiel #1
0
class CelluloseEditor(QtGui.QDialog):
    """
	Wolffia's dialogue to produce homopolymers.
	"""

    # Class Fields:
    # ui: stores reference to user interface
    # files: [string, string], PDB and PSF filenames
    # homopol: Mixture, an Homopolymer
    # homopolPreview: MixtureViewer

    def __init__(self, appState, parent=None, settings=None):
        """
		Constructor for homopolymer editor.
		
		Parameters used:
		parent  :	Window, widget or object that was used to call this dialogue
		settings:	Settings
		"""

        super(CelluloseEditor, self).__init__(parent, modal=1)

        self.settings = settings
        self.state = appState
        self.files = None
        self.isAdded = False
        #esto hay que arreglarlo!
        # Que hay que arreglar de aqui??? ~ Radames
        self.history = History()
        self.homopolPreview = MixtureViewer(self.history, self, None)
        self.ui = Ui_CelluloseEditor()

        self.ui.setupUi(self)
        self.generateCellulose()
        self.ui.viewerLayout.addWidget(self.homopolPreview)
        self.ui.headerLabel.setText("Cellulose Crystal Editor")
        #self.ui.stackedWidget.setCurrentIndex	(self.poly.STACK_INDEX)
        self.ui.lengthDSpinner.setSingleStep(self.poly.DISPL)
        self.ui.lengthDSpinner.setMinimum(self.poly.DISPL)
        self.ui.lengthSlider.setTickInterval(self.poly.DISPL)
        self.ui.lengthSlider.setMinimum(self.poly.DISPL)
        self.ui.nSpinBox.setValue(2)

        image = os.path.dirname(
            os.path.realpath(__file__)) + "/images/" + self.poly.IMAGE
        self.ui.diagram.setPixmap(
            QtGui.QPixmap(QtCore.QString.fromUtf8(image)).scaledToHeight(
                100, 1))

        if self.settings != None:
            self.homopolPreview.setHighResolution(self.settings.highResolution)
            self.homopolPreview.setLabeling(self.settings.showLabels)
            self.homopolPreview.showAxes(self.settings.showAxes)
            self.homopolPreview.showHelp(settings.showHelp)
            self.ui.okButton.setText("OK")

        try:
            self.setStyleSheet(open(WOLFFIA_STYLESHEET, 'r').read())
        except:
            print("WARNING: Could not read style specifications")
        self.homopolPreview.update()

    def generateCellulose(self):
        n = self.ui.nSpinBox.value()
        self.homopol = Mixture()
        from chemicalGraph.molecule.polymer.Cellulose import Cellulose
        if self.ui.buttonA.isChecked():
            self.poly = Cellulose(n, 'a')
        else:
            self.poly = Cellulose(n, 'b')
        self.homopol.add(self.poly)

        self.history.currentState().reset()
        self.history.currentState().addMixture(self.homopol)
        self.homopolPreview.update()

    def getMixture(self):
        return self.history.currentState().getMixture()

    # Signal managers
    def on_nSpinBox_valueChanged(self):
        self.generateCellulose()
        length = self.poly.DISPL * self.ui.nSpinBox.value()
        self.ui.lengthDSpinner.setValue(length)
        self.ui.lengthSlider.setValue(length)

    def on_lengthDSpinner_valueChanged(self):
        n = round(self.ui.lengthDSpinner.value() / self.poly.DISPL)
        self.ui.nSpinBox.setValue(n)
        self.ui.lengthSlider.setValue(n * self.poly.DISPL)

    def on_lengthSlider_sliderReleased(self):
        n = int(self.ui.lengthSlider.value() / self.poly.DISPL)
        self.ui.nSpinBox.setValue(n)

    #---------------------------------------------------------------------
    def on_buttonB_toggled(self, checked):
        self.ui.buttonA.setChecked(not checked)
        self.generateCellulose()

    #---------------------------------------------------------------------
    def on_buttonA_toggled(self, checked):
        self.ui.buttonB.setChecked(not checked)
        self.generateCellulose()

    #---------------------------------------------------------------------
    def on_button110_toggled(self, checked):
        if checked:
            self.ui.button100.setChecked(not checked)
            self.ui.button010.setChecked(not checked)
            self.update()

    #---------------------------------------------------------------------
    def on_button100_toggled(self, checked):
        if checked:
            self.ui.button110.setChecked(not checked)
            self.ui.button010.setChecked(not checked)
            self.update()

    #---------------------------------------------------------------------
    def on_button010_toggled(self, checked):
        if checked:
            self.ui.button100.setChecked(not checked)
            self.ui.button110.setChecked(not checked)
            self.update()

    def on_okButton_pressed(self):
        self.generateCellulose()
        self.isAdded = True
        self.close()

    def on_cancelButton_pressed(self):
        self.history.currentState().reset()
        self.close()

    def closeEvent(self, e):
        if not self.isAdded:
            self.history.currentState().updateMixture(Mixture())

    def wheelEvent(self, e):
        super(HomopolyEditor, self).wheelEvent(e)
Beispiel #2
0
class NanotubeBuilder(QtGui.QDialog):
    """
	Wolffia's dialogue box to produce nanotubes.
	"""

    # Class Fields:
    # ui: stores reference to user interface
    # files: [string, string], PDB and PSF filenames
    # tubes: Mixture, a Tube
    # tubePreview: MixtureViewer

    def __init__(self, parent=None, settings=None):
        """
		Constructor for nanotube editor.
		
		Parameters used:
		parent  :	Window, widget or object that was used to call this dialogue
		settings:	Settings
		"""

        super(NanotubeBuilder, self).__init__(parent, modal=1)

        self.settings = settings
        self.isAdded = False
        self.files = None
        # esto hay que arreglarlo!
        self.history = History()
        self.tubePreview = MixtureViewer(self.history, self, None)
        self.ui = Ui_NanotubeEditor()

        self.ui.setupUi(self)
        self.ui.viewerLayout.addWidget(self.tubePreview)
        self.generateTubes()
        self.ui.nSpinBox.setMaximum(200)
        self.ui.mSpinBox.setMaximum(200)
        if self.settings:
            self.tubePreview.setHighResolution(settings.highResolution)
            self.tubePreview.setLabeling(settings.showLabels)
            self.tubePreview.showAxes(settings.showAxes)
            self.tubePreview.showHelp(settings.showHelp)
            self.ui.OKButton.setText("OK")

        try:
            self.setStyleSheet(open(WOLFFIA_STYLESHEET, 'r').read())
        except:
            print("WARNING: Could not read style specifications")
        self.tubePreview.update()

    def generateTubes(self):
        n = self.ui.nSpinBox.value()
        m = self.ui.mSpinBox.value()
        tubeLength = self.ui.tubeLengthSpinBox.value()

        self.history.currentState().reset()
        self.history.currentState().addMolecule(Tube(n, m, tubeLength))
        self.modified = False

    def getMixture(self):
        return self.history.currentState().getMixture()

    # Signal managers
    def on_horizontalSlider_valueChanged(self, pos):
        self.ui.tubeLengthSpinBox.setValue(pos / 10.)
        self.modified = True

    def on_tubeLengthSpinBox_valueChanged(self, val):
        self.ui.horizontalSlider.setValue(int(float(val) * 10))
        self.modified = True

    def on_mSpinBox_valueChanged(self, val):
        if self.ui.armchairButton.isChecked():
            self.ui.nSpinBox.setValue(self.ui.mSpinBox.value())
        self.modified = True

    # Toggles between the three different types of nanotube layouts
    def on_armchairButton_toggled(self, selected):
        if selected:
            self.ui.nSpinBox.setValue(self.ui.mSpinBox.value())
            self.ui.nSpinBox.setDisabled(True)
        self.modified = True

    def on_chiralButton_toggled(self, selected):
        if selected:
            self.ui.nSpinBox.setEnabled(True)
        self.modified = True

    def on_zigZagButton_toggled(self, selected):
        if selected:
            self.ui.nSpinBox.setValue(0)
            self.ui.nSpinBox.setDisabled(True)
        self.modified = True

    @QtCore.pyqtSlot()
    def on_cancelButton_pressed(self):
        self.close()

    @QtCore.pyqtSlot()
    def on_OKButton_pressed(self):
        if self.modified: self.generateTubes()
        if self.settings:
            self.isAdded = True
            self.close()
        else:
            from .NanotubeSaveDialog import NanotubeSaveDialog
            ntDialog = NanotubeSaveDialog(self.getMixture(),
                                          files=self.files,
                                          parent=self)
            ntDialog.show()
            ntDialog.exec_()
            self.files = ntDialog.getFileNames()
            print(self.files)

    @QtCore.pyqtSlot()
    def on_previewButton_pressed(self):
        self.generateTubes()
        self.tubePreview.update()

    def closeEvent(self, e):
        if not self.isAdded:
            self.history.currentState().updateMixture(Mixture())
Beispiel #3
0
class GrapheneBuilder(QtGui.QDialog):
    """
	Wolffia's dialogue box to produce graphenes
	"""

    # Class Fields:
    # ui: stores reference tu user interface
    # files: [string, string], PDB and PSF filenames
    # graphene: Mixture, a Graphene
    # graphenePreview: MixtureViewer

    def __init__(self, parent=None, settings=None):
        """
		Constructor for graphene editor.
		
		Parameters used:
		parent  :	Window, widget or object that was used to call this dialogue
		settings:	Settings
		"""

        super(GrapheneBuilder, self).__init__(parent, modal=1)

        self.ui = Ui_GrapheneEditor()
        self.isAdded = False
        self.settings = settings
        self.history = History()
        self.graphenePreview = MixtureViewer(self.history, self, None)
        self.files = None

        self.ui.setupUi(self)
        self.ui.viewerLayout.addWidget(self.graphenePreview)
        self.generateGraphene()

        if self.settings:
            self.graphenePreview.setHighResolution(
                self.settings.highResolution)
            self.graphenePreview.setLabeling(self.settings.showLabels)
            self.graphenePreview.showAxes(self.settings.showAxes)
            self.graphenePreview.showHelp(self.settings.showHelp)
            self.ui.OKButton.setText("OK")

        try:
            self.setStyleSheet(open(WOLFFIA_STYLESHEET, 'r').read())
        except:
            print("WARNING: Could not read style specifications")

        self.graphenePreview.update()

    def generateGraphene(self):
        n = self.ui.nSpinBox.value()
        m = self.ui.mSpinBox.value()
        grapheneLength = self.ui.grapheneLengthSpinBox.value()
        self.history.currentState().reset()
        self.history.currentState().addMolecule(Graphene(n, m, grapheneLength))
        self.graphenePreview.update()

    def getMixture(self):
        return self.history.currentState().getMixture()

    # Manages signals
    def on_horizontalSlider_valueChanged(self, pos):
        self.ui.grapheneLengthSpinBox.setValue(pos / 10.)

    def on_grapheneLengthSpinBox_valueChanged(self, val):
        self.ui.horizontalSlider.setValue(int(float(val) * 10))

    @QtCore.pyqtSlot()
    def on_OKButton_pressed(self):
        if self.settings:
            self.generateGraphene()
            #self.state.addMixture(self.graphene)
            self.isAdded = True
            self.close()
        else:
            from .GrapheneSaveDialog import GrapheneSaveDialog
            self.generateGraphene()
            ntDialog = GrapheneSaveDialog(self.graphene,
                                          files=self.files,
                                          parent=self)
            ntDialog.show()
            ntDialog.exec_()
            self.files = ntDialog.getFileNames()
            print(self.files)

    @QtCore.pyqtSlot()
    def on_previewButton_pressed(self):
        self.generateGraphene()

    @QtCore.pyqtSlot()
    def on_cancelButton_pressed(self):
        self.close()

    def closeEvent(self, e):
        if not self.isAdded:
            self.history.currentState().updateMixture(Mixture())
Beispiel #4
0
class DiamondBuilder(QtGui.QDialog):
    """
	Wolffia's dialogue box to produce nanotubes.
	"""

    # Class Fields:
    # ui: stores reference to user interface
    # files: [string, string], PDB and PSF filenames
    # tubes: Mixture, a Tube
    # diamondPreview: MixtureViewer

    def __init__(self, parent=None, settings=None):
        """
		Constructor for nanotube editor.
		
		Parameters used:
		parent  :	Window, widget or object that was used to call this dialogue
		settings:	Settings
		"""

        super(DiamondBuilder, self).__init__(parent, modal=1)

        self.settings = settings
        self.isAdded = False
        self.files = None
        # esto hay que arreglarlo!
        self.history = History()
        self.diamondPreview = MixtureViewer(self.history, self, None)
        self.ui = Ui_DiamondEditor()

        self.ui.setupUi(self)
        self.ui.viewerLayout.addWidget(self.diamondPreview)
        self.generateDimond()

        if self.settings:
            self.diamondPreview.setHighResolution(settings.highResolution)
            self.diamondPreview.setLabeling(settings.showLabels)
            self.diamondPreview.showAxes(settings.showAxes)
            self.diamondPreview.showHelp(settings.showHelp)
            self.ui.OKButton.setText("OK")

        try:
            self.setStyleSheet(open(WOLFFIA_STYLESHEET, 'r').read())
        except:
            print("WARNING: Could not read style specifications")

    def generateDimond(self):
        n = self.ui.nSpinBox.value()
        m = self.ui.mSpinBox.value()
        q = self.ui.qSpinBox.value()

        self.history.currentState().reset()
        self.history.currentState().addMolecule(Diamond(n, m, q))
        self.diamondPreview.update()
        self.modified = False

    def getMixture(self):
        return self.history.currentState().getMixture()

    @QtCore.pyqtSlot()
    def on_cancelButton_pressed(self):
        self.close()

    def on_nSpinBox_valueChanged(self, val):
        self.modified = True

    def on_mSpinBox_valueChanged(self, val):
        self.modified = True

    def on_qSpinBox_valueChanged(self, val):
        self.modified = True

    @QtCore.pyqtSlot()
    def on_OKButton_pressed(self):
        if self.settings:
            if self.modified: self.generateDimond()
            self.isAdded = True
            self.close()
        else:
            from NanotubeSaveDialog import NanotubeSaveDialog
            self.generateTubes()
            ntDialog = NanotubeSaveDialog(self.tubes,
                                          files=self.files,
                                          parent=self)
            ntDialog.show()
            ntDialog.exec_()
            self.files = ntDialog.getFileNames()
            print(self.files)

    @QtCore.pyqtSlot()
    def on_previewButton_pressed(self):
        self.generateDimond()

    def closeEvent(self, e):
        if not self.isAdded:
            self.history.currentState().updateMixture(Mixture())