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)
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())
class Load(QtGui.QDialog): def __init__(self, parent=None, dropedPdb=None): super(Load, self).__init__(parent, modal = 1) print("Load dropedPdb=", dropedPdb) #Dialog settings self.uiLoad = Ui_Load() self.uiLoad.setupUi(self) self.history = History() self.isAdded = False self.history.currentState().reset() #Viewer print("Load setting viewer") self.previewArea = MixtureViewer(self.history, self, None) self.previewArea.showHelp(False) self.uiLoad.moleculeViewerLayout.addWidget(self.previewArea) #Mixture print("Load setting getting mixture") self.myMixture = self.history.currentState().getMixture() self.mixAndRows = list() #Table Settings self.loadTable = self.uiLoad.tableWidget self.loadTableRows = 0 self.equalMolecules = [] self.saveCheckBox = None #Information Button Settings self.uiLoad.hint.setFlat(True) self.uiLoad.hint.setIcon(QtGui.QIcon().fromTheme("dialog-information", QtGui.QIcon(str(NANOCAD_BASE+"\\interface\\graphics\\") +"dialog-information.png"))) self.uiLoad.connectDataBaseButton.setFlat(True) self.uiLoad.connectDataBaseButton.setIcon(QtGui.QIcon().fromTheme("network-server", QtGui.QIcon(str(NANOCAD_BASE+"\\interface\\graphics\\") +"dialog-information.png"))) #PDB droped from MixtureViewer print("Load setting pdbDirectory") self.pdbDirectory = dropedPdb if self.pdbDirectory != None: print("Load setting self.pdbDirectory != None") self.uiLoad.lineEdit_1.setText(self.pdbDirectory) print("Load animateClick") self.uiLoad.loadButton.animateClick() print("Load end") def update(self): self.previewArea.update() return mix = Mixture() for i in range(self.loadTable.rowCount()): #for j in range(3,6): ##print "Load update", self.loadTable.item(i,5).text(),self.loadTable.cellWidget(i,1).show if self.loadTable.cellWidget(i,1).show: mix.add(self.myMixture.getMolecule(str(self.loadTable.item(i,5).text()))) self.previewArea.setMixture(mix) #-------------------------------------- Methods ------------------------------------ #loadPsfOrNot(): Asks the user if wants to change all the names of the molecules that are the same def loadPsfOrNot(self,filename): msg = QtGui.QMessageBox.question(self, 'Loading Fi\les...', 'Would you like to load the psf file associated with: '+filename+'?\n'+'\n NO, will imply to only read the pdb file.', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) return msg == QtGui.QMessageBox.Yes #-------------------------------------- #changeNameOrNotMessage(): Asks the user if wants to change all the names of the molecules that are the same def changeNameOrNotMessage(self): msg = QtGui.QMessageBox.question(self, 'Change all Names...', 'Would you like to change all the names of the molecules with that color?', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) return msg == QtGui.QMessageBox.Yes #-------------------------------------- #getLineEditInfo(): Gets the paths and constructs the Mixture def getLineEditInfo(self): # Gets paths path_1 = str(self.uiLoad.lineEdit_1.displayText()) print("Load getLineEditInfo",path_1) self.uiLoad.lineEdit_1.clear() path_2 = str(self.uiLoad.lineEdit_2.displayText()) print("Load getLineEditInfo",path_2) self.uiLoad.lineEdit_2.clear() print("Load getLineEditInfo loadInfo") self.loadInfo(path_1, path_2) print("Load getLineEditInfo end") #-------------------------------------- def loadInfo(self,path_1='',path_2= ''): if path_1 != '' and path_2 == '': try: self.history.currentState().getMixture().load(path_1) except: QtGui.QMessageBox.warning(self,"Error 1 !!!","There is a problem loading the file " + path_1 + " in box 1.") print(sys.exc_info()) elif not(path_2 == '') and path_1 == '': try: self.history.currentState().getMixture().load(path_2) except: QtGui.QMessageBox.warning(self,"Error 2 !!!","There is a problem loading the file " + path_2 + " in box 2.") elif not(path_1 == '') and not(path_2 == ''): if (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'pdb' and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'psf': try: self.history.currentState().getMixture().load(path_1,path_2) except Exception as e: QtGui.QMessageBox.warning(self,"Error 3 !!!","There is a problem with the file."+str(e)) elif (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'psf' and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'pdb': try: self.history.currentState().getMixture().load(path_2,path_1) except Exception as e: QtGui.QMessageBox.warning(self,"Error 4 !!!","There is a problem with the file."+str(e)) else:QtGui.QMessageBox.warning(self,"Error 5 !!!","There is a problem with the file.") elif not(path_1 == '') and (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'pdb': filePath = None #Search if the *.psf file associated with the *.pdb file exists in the same folder for f in os.listdir(os.path.dirname(path_1)) : path1 = os.path.basename(path_1) if f == path1[0:len(path1)-2]+'s'+'f': filePath = os.path.dirname(path_1)+'/'+f #print "filePath",filePath if not(filePath == None): if self.loadPsfOrNot(f): try: self.history.currentState().getMixture().load(path_1,filePath) except: QtGui.QMessageBox.warning(self,"Error 6 !!!","There is a problem with the file.") else: try: self.history.currentState().getMixture().load(path_1,None) except: QtGui.QMessageBox.warning(self,"Error 7 !!!","There is a problem with the file.") else: try: self.history.currentState().getMixture().load(path_1,None) except: QtGui.QMessageBox.warning(self,"Error 8 !!!","There is a problem with the file.") elif not(path_1 == '') and (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'psf': for f in os.listdir(os.path.dirname(path_1)) : path1 = os.path.basename(path_1) if f == path1[0:len(path1)-2]+'d'+'b': filePath = os.path.dirname(path_1)+'/'+f try: self.history.currentState().getMixture().load(filePath,path_1) except: QtGui.QMessageBox.warning(self,"Error 9 !!!","There is a problem with the file.") elif path_1 == '' and not(path_2 == '') and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'pdb': filePath = None for f in os.listdir(os.path.dirname(path_2)) : path2 = os.path.basename(path_2) if f == path2[0:len(path2)-2]+'s'+'f': filePath = os.path.dirname(path_2)+'/'+f if not(filePath == None): if self.loadPsfOrNot(f): try: self.history.currentState().getMixture().load(path_2,filePath) except: QtGui.QMessageBox.warning(self,"Error 10 !!!","There is a problem with the file.") else: try: self.history.currentState().getMixture().load(path_2,None) except: QtGui.QMessageBox.warning(self,"Error 11 !!!","There is a problem with the file.") else: try: self.history.currentState().getMixture().load(path_2,None) except: QtGui.QMessageBox.warning(self,"Error 12 !!!","There is a problem with the file.") elif path_1 == '' and not(path_2 == '') and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'psf': for f in os.listdir(os.path.dirname(path_2)) : path2 = os.path.basename(path_2) if f == path2[0:len(path2)-2]+'d'+'b': filePath = os.path.dirname(path_2)+'/'+f try: self.history.currentState().getMixture().load(filePath,path_2) except: QtGui.QMessageBox.warning(self,"Error 13 !!!","There is a problem with the file.") else:QtGui.QMessageBox.warning(self,"Error 14 !!!","There is a problem with the file.**") #This is how we can obtain the atoms... #for m in self.history.currentState().getMixture().nodes(): #print "@Load:mixture",self.history.currentState().getMixture().getMolecule(m).nodes() #print "myMixture",self.myMixture.order() #-------------------------------------- #addCheckBox(): Adds a CheckBox into the column's cell to select the molecules that would be loaded def addCheckBox(self,row,name): #---CheckBox--- self.saveCheckBox = CheckBox(self,row,self.loadTable) self.saveCheckBox.setObjectName(str(name+str(row))) self.saveCheckBox.setCheckState(QtCore.Qt.Checked) self.saveCheckBox.setFixedSize(25,25) #---Cell--- self.loadTable.setCellWidget(row,0,self.saveCheckBox) #-------------------------------------- #addButtonintoCell(): Adds a button into the column's cell to preview the molecules def addButtonintoCell(self,row,name): self.viewToolButton = PreviewButton(self.history.currentState(), self.previewArea,parent=self.loadTable, molname=str(name), initState=True) #initState=self.history.currentState().shownMolecules.isShown(str(name))) self.history.currentState().shownMolecules.show(str(name)) #QtCore.QObject.connect(self.viewToolButton, QtCore.SIGNAL('clicked()'), self.on_viewToolButton_clicked()) #self.viewToolButton.clicked.connect(self.on_viewToolButton_clicked) self.viewToolButton.setObjectName(str(name)) self.viewToolButton.setFixedSize(25,25) #---Cell--- self.loadTable.setCellWidget(row,1,self.viewToolButton) #-------------------------------------- #showHideAllMessage(): Asks the user if wants to show/hide all the molecules painted with the same color def loadMessage(self): msg = QtGui.QMessageBox.information(self, 'Information...', 'This may take a while. Please be patient ... ', QtGui.QMessageBox.Ok) #-------------------------------------- #showHideAllMessage(): Asks the user if wants to show/hide all the molecules painted with the same color def showHideAllMessage(self): msg = QtGui.QMessageBox.question(self, 'Show or Hide...', 'Would you like to show/hide all the molecules with that color?', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) return msg == QtGui.QMessageBox.Yes #-------------------------------------- #reviewIsomorphisms(): Verify graph's isomorphism between two graphs def reviewIsomorphisms(self): tempList = [] theColors = [] self.equalMolecules = [] row = -1 for c in range(0,self.myMixture.order()): color = createColors() theColors.append(color) #Check equal molecules remainingMols = list(self.myMixture) for each in self.myMixture: row = row + 1 searchList = list(remainingMols) for theMol in searchList: if self.myMixture.getMolecule(each) == self.myMixture.getMolecule(theMol): tempList.append(theMol) remainingMols.remove(theMol) if len(tempList) > 0: self.equalMolecules.append([tempList, None]) tempList = [] #creating colors for c in range(0,len(self.equalMolecules)): color = createColors() self.equalMolecules[c][1] = color #for molecule in self.equalMolecules[c][0]: #self.myMixture.getMolecule(molecule).rename(molecule + str(c)) #************************************************ #addSelectAllCheckBox(): Create a checkBox to select all the molecules in the table def addSelectAllCheckBox(self): self.selectAllCheckBox = QtGui.QCheckBox() self.deSelectAll = True font = QtGui.QFont() font.setPointSize(9) self.selectAllCheckBox.setFont(font) self.selectAllCheckBox.setText(QtGui.QApplication.translate("Load", "Select All", None, QtGui.QApplication.UnicodeUTF8)) self.selectAllCheckBox.setObjectName("selectAllCheckBox") self.selectAllCheckBox.setCheckState(QtCore.Qt.Checked) self.selectAllCheckBox.setTristate(on = False) self.uiLoad.SelectAllLayout.addWidget(self.selectAllCheckBox) self.connect(self.selectAllCheckBox, QtCore.SIGNAL('stateChanged(int)'), self.checkBoxState) def checkBoxState(self, value): if self.selectAllCheckBox.checkState() == QtCore.Qt.Checked: for row in range(0,self.loadTableRows): self.loadTable.cellWidget(row,0).setCheckState(QtCore.Qt.Checked) elif self.selectAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.deSelectAll == True: for row in range(0,self.loadTableRows): self.loadTable.cellWidget(row,0).setCheckState(QtCore.Qt.Unchecked) elif self.selectAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.deSelectAll == False: self.deSelectAll = True #************************************************ #addSelectAllCheckBox(): Create a checkBox to select all the molecules in the table def addShowHideAllCheckBox(self): self.showHideAllCheckBox = QtGui.QCheckBox() #print "Entre aqui" self.showAll = True font = QtGui.QFont() font.setPointSize(9) self.showHideAllCheckBox.setFont(font) self.showHideAllCheckBox.setText(QtGui.QApplication.translate("Load", "Show All", None, QtGui.QApplication.UnicodeUTF8)) self.showHideAllCheckBox.setObjectName("showHideAllCheckBox") self.showHideAllCheckBox.setCheckState(QtCore.Qt.Checked) self.showHideAllCheckBox.setTristate(on = False) self.uiLoad.ShowAllLayout.addWidget(self.showHideAllCheckBox) self.connect(self.showHideAllCheckBox, QtCore.SIGNAL('stateChanged(int)'), self.showHideAllState) def showHideAllState(self, value): if self.showHideAllCheckBox.checkState() == QtCore.Qt.Checked: for row in range(0,self.loadTableRows): self.loadTable.cellWidget(row,1).setShown() #self.loadTable.cellWidget(row,1).click() elif self.showHideAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.showAll == True: for row in range(0,self.loadTableRows): self.loadTable.cellWidget(row,1).setHidden() elif self.showHideAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.showAll == False: self.showAll = True #************************************************* #setTable(): Creates and show the table def setTable(self): self.reviewIsomorphisms() #creates rows and columns self.loadTable.setColumnCount(6) self.loadTableRows = self.myMixture._len() self.loadTable.setRowCount(self.loadTableRows) item = QtGui.QTableWidgetItem() self.loadTable.setHorizontalHeaderItem(0, item) self.loadTable.horizontalHeaderItem(0).setText(QtGui.QApplication.translate("Load", "Save", None, QtGui.QApplication.UnicodeUTF8)) item = QtGui.QTableWidgetItem() self.loadTable.setHorizontalHeaderItem(1, item) self.loadTable.horizontalHeaderItem(1).setText(QtGui.QApplication.translate("Load", "Prev", None, QtGui.QApplication.UnicodeUTF8)) item = QtGui.QTableWidgetItem() self.loadTable.setHorizontalHeaderItem(2, item) self.loadTable.horizontalHeaderItem(2).setText(QtGui.QApplication.translate("Load", "Molecule Name", None, QtGui.QApplication.UnicodeUTF8)) item = QtGui.QTableWidgetItem() self.loadTable.setHorizontalHeaderItem(3, item) self.loadTable.horizontalHeaderItem(3).setText(QtGui.QApplication.translate("Load", "No. of Atoms", None, QtGui.QApplication.UnicodeUTF8)) item = QtGui.QTableWidgetItem() item.setTextAlignment(0x0001) self.loadTable.setHorizontalHeaderItem(4, item) self.loadTable.horizontalHeaderItem(4).setText(QtGui.QApplication.translate("Load", "Atoms Found", None, QtGui.QApplication.UnicodeUTF8)) item = QtGui.QTableWidgetItem() self.loadTable.setHorizontalHeaderItem(5, item) self.loadTable.horizontalHeaderItem(5).setText(QtGui.QApplication.translate("Load", "Atom_ID", None, QtGui.QApplication.UnicodeUTF8)) row = 0 temp =[] #Adding the molecule information into the rows for eqCassInd in range(len(self.equalMolecules)): for molName in self.equalMolecules[eqCassInd][0]: for column in range(0,6): item = QtGui.QTableWidgetItem() self.loadTable.setItem(row, column, item) if column == 0: self.addCheckBox(row,molName) self.loadTable.resizeColumnToContents(column) elif column == 1: self.addButtonintoCell(row,molName) self.loadTable.resizeColumnToContents(column) temp.append(molName) temp.append(row) self.mixAndRows.append(temp) temp = [] elif column == 2: newTableWidgetItem = myTableWidgetItem(self, self.myMixture.getMolecule(molName)._name, molName) newTableWidgetItem.setBackgroundColor(self.equalMolecules[eqCassInd][1]) self.loadTable.setItem(row,column,newTableWidgetItem) self.loadTable.resizeColumnToContents(column) elif column == 3: newitem = myTableWidgetItem(self,str(self.myMixture.getMolecule(molName).order())) newitem.setFlags(QtCore.Qt.ItemIsEnabled) self.loadTable.setItem(row, column, newitem) self.loadTable.resizeColumnToContents(column) elif column == 4: molecule = self.myMixture.getMolecule(molName) newitem = myTableWidgetItem(self,str(molecule.getElements())) newitem.setFlags(QtCore.Qt.ItemIsEnabled) self.loadTable.setItem(row, column, newitem) self.loadTable.resizeColumnToContents(column) elif column == 5: newitem = QtGui.QTableWidgetItem(str(molName)) newitem.setFlags(QtCore.Qt.ItemIsEnabled) self.loadTable.setItem(row, column, newitem) self.loadTable.resizeColumnToContents(column) row += 1 self.update() #---------------- Dialog's signals ------------------- def on_Browse_1_pressed(self): d = WFileDialog(self, 'Browse File','','') if d.accepted(): filename = d.fullFilename() if not os.path.exists(str(filename)): QtGui.QMessageBox.information(self, "Wolffia's message", "Did not find file " + filename + ". File not loaded.", QtGui.QMessageBox.Ok) return self.uiLoad.lineEdit_1.setText(str(d.fullFilename())) def on_Browse_2_pressed(self): d = WFileDialog(self, 'Browse File','','') if d.accepted(): filename = d.fullFilename() if not os.path.exists(str(filename)): QtGui.QMessageBox.information(self, "Wolffia's message", "Did not find file " + filename + ". File not loaded.", QtGui.QMessageBox.Ok) return self.uiLoad.lineEdit_2.setText(str(d.fullFilename())) def on_hint_pressed(self): from .AboutLoad import AboutLoad about = AboutLoad(self) about.show() about.exec_() def on_connectDataBaseButton_pressed(self): #print"on_connectDataBaseButton_pressed" from .ImportMolecules import ImportMolecules importMoleculeDialog = ImportMolecules() importMoleculeDialog.show() importMoleculeDialog.exec_() #print "PDB \n",importMoleculeDialog.getFileType() if importMoleculeDialog.proceed(): try: #print importMoleculeDialog.getMoleculeFile() self.history.currentState().getMixture().load(None,None,importMoleculeDialog.getMoleculeFile(),importMoleculeDialog.getFileType(),importMoleculeDialog.inputName()) except Exception as err: #print "Load on_connectDataBaseButton_pressed: There is a problem with the file ", importMoleculeDialog.getMoleculeFile() QtGui.QMessageBox.warning(self,"Error 15 !!!","There is a problem with the file."+ err) self.loadTable.clear() self.loadTableRows = 0 self.mixAndRows = [] self.setTable() if self.uiLoad.SelectAllLayout.isEmpty() and self.uiLoad.ShowAllLayout.isEmpty(): self.addSelectAllCheckBox() self.addShowHideAllCheckBox() self.previewArea.setMixture(self.history.currentState().getMixture()) def on_cancelButton_pressed(self): #print "Load: Cancel Button: history",self.history.currentState() self.close() def on_loadButton_pressed(self,dropedPdb=None): print("Load on_loadButton_pressed",dropedPdb) if dropedPdb == None: print("Load on_loadButton_pressed getLineEditInfo") self.getLineEditInfo() print("Load on_loadButton_pressed loadTable.clear") self.loadTable.clear() self.loadTableRows = 0 self.mixAndRows = [] print("Load on_loadButton_pressed setTable") self.setTable() if self.uiLoad.SelectAllLayout.isEmpty(): self.addSelectAllCheckBox() self.addShowHideAllCheckBox() print("Load on_loadButton_pressed previewArea.setMixture") self.previewArea.setMixture(self.history.currentState().getMixture()) print("Load on_loadButton_pressed end") def on_okButton_pressed(self): if self.myMixture._len() == 0: msg = QtGui.QMessageBox.warning(self, 'Warning', 'No molecule has been loaded!',QtGui.QMessageBox.Ok) else: progressMax = self.myMixture._len() progressCount = 0 progress = QtGui.QProgressDialog("Loading mixture...", "Abort", 0, progressMax, self,QtCore.Qt.Dialog|QtCore.Qt.WindowTitleHint) progress.setWindowModality(QtCore.Qt.WindowModal) for row in range(0,self.myMixture._len()): if progress.wasCanceled(): progress.hide() self.history.currentState().reset() self.myMixture = self.history.currentState().getMixture() self.update() self.close() return else: #Delete unchecked molecules if (self.loadTable.cellWidget(row,0).checkState()) == QtCore.Qt.Unchecked: self.myMixture.remove(str(self.loadTable.item(row,5).text())) #Add remaining molecules to the state progressCount += 1 progress.setValue(progressCount) self.isAdded = True self.close() def closeEvent(self, e): if not self.isAdded: self.myMixture = Mixture() def getMixture(self): return self.myMixture #------------- Table's signals --------- def on_tableWidget_itemChanged(self, wi): if isinstance(wi, myTableWidgetItem) and wi.name != "(no name)" and wi.isSelected(): self.loadTable.setItemSelected (wi, False) multipleMolecules = False for row in range(0,self.loadTable.rowCount()): if not(self.loadTable.currentRow() == row) \ and self.loadTable.item(self.loadTable.currentRow(),2).backgroundColor() == self.loadTable.item(row,2).backgroundColor(): multipleMolecules = True break if multipleMolecules and self.changeNameOrNotMessage(): # changes names of all isomorphic molecules selColor = wi.backgroundColor() for eqClass in range(0,len(self.equalMolecules)): if selColor == self.equalMolecules[eqClass][1]: for mol in self.equalMolecules[eqClass][0]: self.myMixture.getMolecule(mol)._name = str(wi.text()) self.setTable() else: mol = self.myMixture.getMolecule(wi.name) mol._name = str(wi.text()) #-------------------------------------- #on_viewToolButton_clicked(): When a viewToolButton is clicked, the user can show/hide all the molecules painted with the same color def on_viewToolButton_clicked(self): #print "_mySignal" value = self.viewToolButton.show #print "@WWidget _mySignal value",value multipleMolecules = False #print "self.loaded.rowCount()",self.loadTable.rowCount() for row in range(0,self.loadTable.rowCount()): if not(self.viewToolButton.row == row) and self.loadTable.item(self.viewToolButton.row,2).backgroundColor() == self.loadTable.item(row,2).backgroundColor(): multipleMolecules = True #print "multipleMolecules = True" break if isinstance(self, PreviewButton) and multipleMolecules and self.showHideAllMessage() : selColor = self.loadTable.item(self.viewToolButton.row,2).backgroundColor() for row in range(0,self.loadTable.rowCount()): if selColor == self.loadTable.item(row,2).backgroundColor(): if value == True: self.loadTable.cellWidget(row,1).setShown() else: self.loadTable.cellWidget(row,1).setHidden() self.loadTable.showAll = False self.loadTable.showHideAllCheckBox.setCheckState(QtCore.Qt.Unchecked) else: if value == False: self.loadTable.showAll = False self.loadTable.showHideAllCheckBox.setCheckState(QtCore.Qt.Unchecked)
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())
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())