Ejemplo n.º 1
0
 def generateHomopol(self):
     self.ui.headerLabel.setText(str(self.type) + " Editor")
     n = self.ui.nSpinBox.value()
     self.homopol = Mixture()
     exec("from chemicalGraph.molecule.polymer." + str(self.type) +
          " import " + str(self.type))
     self.homopol.add(eval(str(self.type) + "(n)"))
     self.homopolPreview.setMixture(self.homopol)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def reset(self):
     #print "PropertyEditor reset "
     self.mixture  = Mixture(None)
     self.registry = dict()
     #self.ident    = None
     
     self.resetBoxes()
     self.setToolTip("Select molecules to activate.")
     self.setEnabled(False)
     self.update()
Ejemplo n.º 4
0
 def __init__(self, mixture):
     print("ShownMoleculesSet,__init__ caller=",
           inspect.stack()[1])  #[3], mixture, type(mixture)
     if isinstance(mixture, list):
         self.mixture = Mixture()
         for m in mixture:
             self.mixture.add(m)
         self.showAll()
     else:
         self.mixture = mixture
Ejemplo n.º 5
0
    def generateHomopol(self):
        n = self.ui.nSpinBox.value()
        self.homopol = Mixture()
        exec("from chemicalGraph.molecule.polymer." + str(self.type) +
             " import " + str(self.type))
        self.poly = eval(str(self.type) + "(n)")
        self.homopol.add(self.poly)

        self.history.currentState().reset()
        self.history.currentState().addMixture(self.homopol)
        self.homopolPreview.update()
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
 def copy(self):
     selected = self.editor.selectedMolecules()
     #print "copy ", selected
     if selected == []:
         errorgui = QtGui.QErrorMessage(self)
         errorgui.setModal(True)  # blocks Wolffia
         errorgui.showMessage("Error: no molecule chosen.")
     else:
         self.clipboard = Mixture("Clipboard")
         for mol in selected:
             #print "copy", mol
             #self.clipboard.add(self.history.currentState().getMixture().getMolecule(molname).copy(), False)
             self.clipboard.add(mol.copy(), False)
     #print "copy update<", self.editor.selected()
     self.update()
Ejemplo n.º 8
0
	def _processNextFrame(self):
		"""
		Gets next pybel Molecule and puts its Wolffia equivalent Mixture in self.currentMolecule.
		Returns the next frame.
		Assumes that _processFirstFrame() has been called earlier.
		Raises whichever exception that pybel throws (probably StopIteration).
		"""
		self.currentMolecule = Mixture(self.currentMolecule)  # copy mixture
		mol = next(self.molIterator)
		print("_processNextFrame", mol)
		coordinates = []
		for atom in mol.atoms:
			coordinates.append(atom.coords)
		self.currentMolecule.updateCoordinatesFromArray(coordinates)
		return self.currentMolecule
Ejemplo n.º 9
0
    def reset(self):
        #self.forceFieldStorage    =    None
        #self.mixture        =    Mixture(mixName = WOLFFIA_DEFAULT_MIXTURE_NAME)
        self.mixture = Mixture(mixName=self.mixture.getMixtureName())
        self.wolffiaVerion = WOLFFIA_VERSION
        self.simTabValues = None
        self.minTabValues = None

        #self.mixture.setChanged()
        #self.forceFieldStorage = dict()

        #self.buildDir = WOLFFIA_DEFAULT_MIXTURE_LOCATION + "/" + self.mixture.getMixtureName()
        #self.workingDir = os.getcwd()
        self.drawer = Drawer()
        self.shownMolecules = ShownMoleculesSet(self.mixture)
        self.fixedMolecules = FixedMolecules()
Ejemplo n.º 10
0
    def __init__(self, parent=None, filename=None, log=None):
        #import inspect
        #print "NanoCADState.init, caller=",inspect.stack()[1]
        self.parent = parent
        self.log = log
        self.wolffiaVerion = WOLFFIA_VERSION
        self.mixture = Mixture(mixName=WOLFFIA_DEFAULT_MIXTURE_NAME)
        self.workingDir = WOLFFIA_DEFAULT_MIXTURE_LOCATION + "/"
        self.drawer = None
        self.simTabValues = None
        self.minTabValues = None
        self.shownMolecules = None
        self.fixedMolecules = None

        self.reset()
        if not filename == None:
            self.load(filename)
Ejemplo n.º 11
0
    def generatePolymer(self):
        n = self.ui.nSpinBox.value()
        m = self.ui.mSpinBox.value()
        monomers = self.ui.monomersSpinBox.value()
        self.pss = Mixture()

        self.history.currentState().reset()
        self.history.currentState().addMolecule(PSS(n, m, monomers))
        self.pssPreview.update()
Ejemplo n.º 12
0
    def on_addMixtureButton_pressed(self):
        '''
        Creates a new, nameless mixture on the QWidgetTree.
        '''
        self.loadTable.blockSignals(True)
        newName, ok = QtGui.QInputDialog.getText(
            self, 'Renaming a mixture', 'Enter the new name for the mixture:')
        newName = str(newName).strip('\/\\')
        if ok and newName and not newName.isspace():
            for mixName in self.mixtures:
                if mixName == newName:
                    QtGui.QMessageBox.information(
                        self, "Error", "That mixture name already exists",
                        QtGui.QMessageBox.Ok)

        elif not ok:
            return
        else:
            QtGui.QMessageBox.information(self, "Error", "Bad mixture name",
                                          QtGui.QMessageBox.Ok)
            return

        from lib.chemicalGraph.Mixture import Mixture  #@UnresolvedImport

        self.wolffia.setDefaultTabs()
        row = self.loadTable.rowCount()
        self.loadTable.setRowCount(row + 1)
        self.loadTable.setItem(row, 0, QtGui.QTableWidgetItem())
        newTableWidgetItem = QtGui.QTableWidgetItem("")
        self.loadTable.setItem(row, 0, newTableWidgetItem)
        newTableWidgetItem.setFlags(QtCore.Qt.ItemIsEditable
                                    | QtCore.Qt.ItemIsEnabled)
        self.settings.setMixtureLocation(newName)
        #print newName
        self.history.currentState().setBuildDirectory(
            self.settings.currentMixtureLocation())
        self.wolffia.reset()
        newMix = Mixture(mixName=newName)

        for row in range(self.loadTable.rowCount()):
            self.loadTable.item(row,
                                0).setBackgroundColor(QtGui.QColor("white"))

        self.lastSelectedItem = newTableWidgetItem
        newTableWidgetItem.setBackgroundColor(QtGui.QColor("blue"))
        self.history.currentState().updateMixture(newMix)
        self.history.currentState().setBuildDirectory(
            self.settings.currentMixtureLocation())
        self.history.currentState().save(
            self.settings.currentMixtureLocation() + newMix.mixName + ".wfy")
        self.wolffia.update()
        self.mixtures.append(newName)
        self.setTable()
        self.loadTable.blockSignals(False)
Ejemplo n.º 13
0
class Cellulose(Polymer):
    ALL_MONOMERS = Mixture()
    ALL_MONOMERS.loadWFM(WOLFFIA_WFY_DIR + "/Cellulose.wfm")
    print(ALL_MONOMERS.molecules())

    IMAGE = "/Cellulose.png"

    MONOMERS_MOLS={ 'Cs':ALL_MONOMERS.getMolecule('Cellulose_s_1'),\
      'C_a_b':ALL_MONOMERS.getMolecule('Cellulose_b_1'),\
      'C_a_e':ALL_MONOMERS.getMolecule('Cellulose_e_1'),\
      'C_a_1':ALL_MONOMERS.getMolecule('Cellulose_1_1'),\
      'C_a_s':ALL_MONOMERS.getMolecule('Cellulose_s_1'),\
      'C_b_s':ALL_MONOMERS.getMolecule('CelluloseB_s_1'),\
      'C_b_b':ALL_MONOMERS.getMolecule('CelluloseB_b_1'),\
      'C_b_e':ALL_MONOMERS.getMolecule('CelluloseB_e_1'),\
      'C_b_1':ALL_MONOMERS.getMolecule('CelluloseB_1_1')}

    NUM_ATOMS_BACKBONE_MONOMER = MONOMERS_MOLS['C_a_b'].order()

    END_ATOM = 2  #!!!
    START_ATOM = 0
    DISPL = 10.4
    ANGLE = 0.

    def __init__(self, numMonomers, type='b'):
        # initialize base class
        assert (numMonomers > 0)
        molname = "Cellulose_" + type + "(" + str(numMonomers) + ")"

        if numMonomers == 1:  # only one monomer
            #print "Cellulose ", self.MONOMERS_MOLS['P1'].bonds()
            chain = ['C_' + type + '_1']
        else:
            chain = ['C_' + type + '_s']
            for i in range(numMonomers - 2):
                chain.append('C_' + type + '_b')
            chain.append('C_' + type + '_e')

        #print "Cellulose ", chain
        Polymer.__init__(self, chain, molname)
        self.type = type

        # add FF parameters for monomer junctions
        #self.getForceField().setAngle(('C','C','C'), 60., 0)
        #self.getForceField().setAngle(('C','C','C'), 109.47, 1)
        self.getForceField().setDihedral(('C100', 'O400', 'C400', 'C300'), 0.6,
                                         0)
        self.getForceField().setDihedral(('C100', 'O400', 'C400', 'C300'), 1,
                                         1)
        self.getForceField().setDihedral(('C100', 'O400', 'C400', 'C300'),
                                         3.14, 2)

        for atom in self:
            self.getAtomAttributes(atom).getInfo().setResidue('CEL')
Ejemplo n.º 14
0
 def __init__(self):
     mix = Mixture()
     mix.loadWFM(WOLFFIA_WFY_DIR + "/PABApentane.wfm")
     print(mix.molecules())
     Molecule.__init__(self,
                       "PABA-Pentane",
                       molecule=mix.getMolecule("PABA-Pentane_1"))
     self.changeResidues("PAB")
Ejemplo n.º 15
0
	def __init__(self):
		Mixture.__init__(self, "SDS")

		#print NANOCAD_PDB_DIR + "/Solvents/THF.pdb" , NANOCAD_PDB_DIR + "/Solvents/THF.psf" 
		self.load(NANOCAD_PDB_DIR + "/Surfactant/SDS.pdb" , NANOCAD_PDB_DIR + "/Surfactant/SDS.psf")

		#print "SDS ff", _FORCE_FIELD._NONBONDED
		#print "SDS a", NANOCAD_FORCE_FIELDS + "/SDS.prm"
		p1, p2 = [self.getMolecule(p) for p in self.molecules()]
		if p1.order() == 1:
			p1.rename("NA")
			SDS._FORCE_FIELD_NA = ForceField(p1, NANOCAD_FORCE_FIELDS + "/SDS.prm")
			p1.setForceField(SDS._FORCE_FIELD_NA )
			SDS._FORCE_FIELD_SDS = ForceField(p2, NANOCAD_FORCE_FIELDS + "/SDS.prm")
			p2.setForceField(SDS._FORCE_FIELD_SDS )
		else:
			p2.rename("NA")
			SDS._FORCE_FIELD_NA = ForceField(p2, NANOCAD_FORCE_FIELDS + "/SDS.prm")
			p2.setForceField(SDS._FORCE_FIELD_NA )
			SDS._FORCE_FIELD_SDS = ForceField(p1, NANOCAD_FORCE_FIELDS + "/SDS.prm")
			p1.setForceField(SDS._FORCE_FIELD_SDS )
		
		p1.copyChargesToForceField()
		p2.copyChargesToForceField()
Ejemplo n.º 16
0
    def on_saveButton_pressed3(self, saveFiles=True):
        if not saveFiles: return
        selected = self.editor.selectedMolecules()
        #print "on_saveButton_pressed ", selected
        if selected == []:
            QtGui.QMessageBox.warning(
                self, "Wolffia's warning",
                "Could not determine the molecule to be saved.\nPlease select one.",
                QtGui.QMessageBox.Ok)
            return

        mixtureToSave = Mixture("To save")
        molName = ""
        for mol in selected:
            mixtureToSave.add(mol.copy(), False)
            if molName == "":
                molName = mol.molname()
            else:
                molName += ("-" + mol.molname())

        d = WDirectoryDialog(
            self, 'Specify directory to save ' + molName + ".pdb and " +
            molName + ".psf", self.settings.workingFolder)

        try:
            if d.accepted():
                basename = str(d.path() + "/" + molName)
                #import os
                if not (os.path.exists(basename + ".pdb") or os.path.exists(
                        basename + ".psf")) or QtGui.QMessageBox.question(
                            self, "Wolffia's message", "File exists.",
                            "Overwrite", "Cancel") == 0:
                    #mix = self.history.currentState().getMixture()
                    #print "on_saveButton_pressed ", basename
                    mixtureToSave.writePDB(basename + ".pdb")
                    mixtureToSave.writePSF(basename + ".psf")

                    QtGui.QMessageBox.information(
                        self, "Wolffia's message",
                        molName + ".pdb and " + molName + ".psf saved.",
                        QtGui.QMessageBox.Ok)
        except:
            QtGui.QMessageBox.warning(
                self, "Wolffia's warning",
                molName + ".pdb and " + molName + ".psf could not be saved.",
                QtGui.QMessageBox.Ok)
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
 def closeEvent(self, e):
     if not self.isAdded:
         self.history.currentState().updateMixture(Mixture())
Ejemplo n.º 19
0
		
	def __init2__(self,n,m,q):
		super(Diamond,self).__init__(ident="Diamond")
		
		allCells = Mixture()
		allCells.loadWFM(WOLFFIA_WFY_DIR + "/diamond.wfm")
		#print allCells.moleculeNames()
		#print allCells.nodes()
		cell = allCells.getMolecule(allCells.nodes()[0])

		for x in range(n):
			for y in range(m):
				line = Molecule()
				for z in range(q):
					newCell = cell.copy()
					newCell.moveBy([x*self._CELL_WIDTH_,y*self._CELL_WIDTH_,z*self._CELL_WIDTH_])
					addAndJoin(line, newCell)
				print "Diamond __init__",x,y
				addAndJoin(self, line)
		#print allCells.enclosingBox()
'''
#==========================================================================
#==========================================================================
if __name__ == '__main__':
    d = Diamond(3, 3, 3)
    print(d.edges())
    d.writePDB("/home/jse/Desktop/Diamantito.pdb")

    m = Mixture()
    m.add(d)
    m.save("/home/jse/Desktop/Diamantito.wfm")
Ejemplo n.º 20
0
	def _processFirstFrame(self):
		"""
		Gets the first pybel Molecule and puts its Wolffia equivalent Mixture in self.currentMolecule.
		Returns the first frame.
		Raises whichever exception that pybel throws (probably StopIteration).
		"""
		
		mol = next(self.molIterator)
		chemicalGraphMixed = ChemicalGraph()
		etable			 = openbabel.OBElementTable()

		
		n = 0
		for atom in mol.atoms:
			atomType = atom.OBAtom.GetResidue().GetAtomID(atom.OBAtom)
			symbol = etable.GetSymbol(atom.atomicnum)
			coords = list(atom.coords)
			name	 = etable.GetName(atom.atomicnum) 
			residue = atom.OBAtom.GetResidue().GetName()
			psfType = atom.OBAtom.GetResidue().GetAtomID(atom.OBAtom).strip()
			#print "_processFirstFrame: '" + psfType + "'"
			charge = atom.partialcharge
			mass	 = atom.atomicmass	
			if self.psf != None:
				psfType = self.psf.getType(n)
				charge = self.psf.getCharge(n)
				mass	 = self.psf.getMass(n)
				print("CoordinateFile _processFirstFrame charge  ", charge)
		
		
			ai  = AtomInfo(atomType, symbol, psfType, charge, mass, 1, 1, 1, name, residue)
			atr = AtomAttributes(ai, coords, [])
			chemicalGraphMixed.add_node(n + 1, attrs=[atr])
			n += 1
		
		# add edges
		print('_processFirstFrame add edges')
		if self.psf != None:
			for b in self.psf.bonds:
				try:  # avoids adding an edge twice
					chemicalGraphMixed.add_edge(b)
				except AdditionError:
					pass			
			if len(mol.atoms) != len(self.psf.atoms):
				raise MixtureError("Amount of atoms in " + self.fileName + " and psf File files are different (" + str(len(self.atoms)) + " vs " + str(len(self.psf.atoms)) + ").")
		else:			
			for bond in openbabel.OBMolBondIter(mol.OBMol):   
				chemicalGraphMixed.add_edge([bond.GetBeginAtom().GetIdx(), bond.GetEndAtom().GetIdx()])	   
					
		molecules = list(chemicalGraphMixed.connectedComponents())
		self.currentMolecule = Mixture()
		
		#print '_processFirstFrame Añadir'+  str(list(molecules)) + ' moléculas a mezcla:  ', 
		if len(molecules) == 1:
			self.currentMolecule.add(Molecule(self.mixtureName, molecule=molecules[0]))
		else:
			n = 0
			for m in molecules:
				self.currentMolecule.add(
							Molecule(self.mixtureName + "(" + str(n) + ")", molecule=m),
							checkForInconsistentNames=False)
				n += 1

		return self.currentMolecule
Ejemplo n.º 21
0
 def closeEvent(self, e):
     if not self.isAdded:
         self.myMixture = Mixture()
Ejemplo n.º 22
0
    def on_catalogButton_pressed(self):
        if not self.ui.catalogButton.isFlat():
            selected = self.editor.selectedMolecules()
            #print "SELCTEDDDDDD >>." , selected[0]
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()

            elif selected == []:
                QtGui.QMessageBox.warning(self, "Wolffia's warning",
                                          "Please select a molecule.",
                                          QtGui.QMessageBox.Ok)
                return

            else:
                #print "on_catalogButton_pressed",  self.ui.molCatalog.topLevelItemCount()
                customTreeWidget = self.ui.molCatalog.topLevelItem(
                    self.ui.molCatalog.topLevelItemCount() - 1)
                #print "on_catalogButton_pressed childCount", customTreeWidget.childCount ()

                print("SELCTEDDDDDD >>.", selected)
                mixtureToSave = Mixture()
                print("mixtureToSave >>>>", mixtureToSave)
                molName = ""
                print("molName >>>>", molName)
                for mol in selected:
                    print("mol >>>>", mol)
                    mixtureToSave.add(mol.copy(), True)
                    print("mixtureToSave agregados >>>>", mixtureToSave)
                    if molName == "":
                        molName = mol.molname()
                    else:
                        molName += ("-" + mol.molname())

                print("SELECETEDDDD: ", selected, "mixtureToSave Final",
                      mixtureToSave)
                print(
                    "############################################################"
                )
                #Pregunta el nombre de la molecula que quiere guardar en el catalogo
                nameMolGUI = QtGui.QInputDialog(self)
                nameMolGUI.setTextValue(str(selected[0]))

                nameMol, ok = nameMolGUI.getText(self, "Custom Molecule",
                                                 "Set Molecule Name:", 0,
                                                 str(selected[0]))

                print("value ", nameMol, " ok ", ok)
                if ok:
                    #Guarda archivo en .cMolecule dentro de .wolffia
                    cMixFileName = "/" + nameMol + ".wfm"
                    cMixFileDir = WOLFFIA_DIR + C_MOLECULE_CATALOG + cMixFileName
                    if os.path.exists(cMixFileDir):
                        print("archivo existe", cMixFileDir)
                        nameMol = nameMol + "*"
                        cMixFileName = "/" + nameMol + ".wfm"
                        cMixFileDir = WOLFFIA_DIR + C_MOLECULE_CATALOG + cMixFileName

                    print("cMixFileDir>>>>>", cMixFileDir)
                    #Add a child to Custom Molecule in the Molecular Structure Catalog
                    nameQT = QtGui.QTreeWidgetItem()
                    nameQT.setText(0, nameMol)
                    customTreeWidget.addChild(nameQT)
                    #customTreeWidget.addChild(QtGui.QTreeWidgetItem())
                    print("NAMEMOL1", nameMol)
                    self.history.currentState().getMixture().save(cMixFileDir)
Ejemplo n.º 23
0
class PEDOT(Polymer):
    ALL_MONOMERS = Mixture()
    ALL_MONOMERS.loadWFM(WOLFFIA_WFY_DIR + "/PEDOT.wfm")
    #print allMonomers.molecules()

    BACKBONE_MONOMER_MOL = ALL_MONOMERS.getMolecule('PEDOT_1')
    START_MONOMER_MOL = ALL_MONOMERS.getMolecule('PEDOT0_1')
    END_MONOMER_MOL = ALL_MONOMERS.getMolecule('PEDOTF_1')
    ONE_MONOMER_MOL = ALL_MONOMERS.getMolecule('PEDOT1_1')

    IMAGE = "/PEDOT.png"

    NUM_ATOMS_BACKBONE_MONOMER = BACKBONE_MONOMER_MOL.order()
    NUM_ATOMS_START_MONOMER = START_MONOMER_MOL.order()
    NUM_ATOMS_LAST_MONOMER = END_MONOMER_MOL.order()

    END_ATOM = 2  #!!!
    START_ATOM = 21
    DISPL = 3
    ANGLE = 3.14

    MONOMERS_MOLS={ 'Rs':ALL_MONOMERS.getMolecule('PEDOT0_1'),\
      'Rb':ALL_MONOMERS.getMolecule('PEDOT_1'),\
      'Re':ALL_MONOMERS.getMolecule('PEDOTF_1'),\
      'Os':ALL_MONOMERS.getMolecule('PEDOTp0_1'),\
      'Ob':ALL_MONOMERS.getMolecule('PEDOTp_1'),\
      'Oe':ALL_MONOMERS.getMolecule('PEDOTpF_1'),\
      'P1':ALL_MONOMERS.getMolecule('PEDOT1_1')}

    def __init__(self, n, m, numMonomers):
        # initialize base class
        assert (n > 0 or m > 0)
        molname = "PEDOT(" + str(n) + ", " + str(m) + ", " + str(
            numMonomers) + ")"

        baseChain = []
        for i in range(n):
            baseChain.append('Rb')
        for i in range(m):
            baseChain.append('Ob')
        #for i in range(n):
        #	baseChain.append('Rb')

        chain = []
        for i in range(numMonomers):
            chain += baseChain
        if n > 0:
            chain[0] = 'Rs'
            chain[-1] = 'Re'
        else:
            chain[0] = 'Os'
            chain[-1] = 'Oe'

        Polymer.__init__(self, chain, molname)

        # add FF parameters for monomer junctions
        self.getForceField().setBond(('C', 'C'), 305., NonBond._EPSILON)
        self.getForceField().setBond(('C', 'C'), 1.3750, NonBond._SIGMA)
        self.getForceField().setBond(('C', 'C3'), 222.500, NonBond._EPSILON)
        self.getForceField().setBond(('C', 'C3'), 1.5300, NonBond._SIGMA)
        self.getForceField().setBond(('C3', 'C3'), 305.000, NonBond._EPSILON)
        self.getForceField().setBond(('C3', 'C3'), 1.3750, NonBond._SIGMA)

        self.getForceField().setAngle(('C', 'C3', 'S1'), 40., 0)
        self.getForceField().setAngle(('C', 'C3', 'S1'), 120., 1)
        self.getForceField().setAngle(('C', 'C3', 'C4'), 45.8, 0)
        self.getForceField().setAngle(('C', 'C3', 'C4'), 120., 1)

        self.getForceField().setAngle(('C3', 'C4', 'C4'), 51.8, 0)
        self.getForceField().setAngle(('C3', 'C4', 'C4'), 107.5, 1)
        self.getForceField().setAngle(('C3', 'C3', 'S1'), 40., 0)
        self.getForceField().setAngle(('C3', 'C3', 'S1'), 120., 1)
        self.getForceField().setAngle(('C3', 'C3', 'C4'), 45.8, 0)
        self.getForceField().setAngle(('C3', 'C3', 'C4'), 120., 1)

        self.getForceField().setDihedral(('C', 'C3', 'S1', 'C3'), 1.75, 0)
        self.getForceField().setDihedral(('C', 'C3', 'S1', 'C3'), 2, 1)
        self.getForceField().setDihedral(('C', 'C3', 'S1', 'C3'), 180, 2)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C'), 1.75, 0)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C'), 2, 1)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C'), 180, 2)

        self.getForceField().setDihedral(('C3', 'C3', 'S1', 'C3'), 1.75, 0)
        self.getForceField().setDihedral(('C3', 'C3', 'S1', 'C3'), 2, 1)
        self.getForceField().setDihedral(('C3', 'C3', 'S1', 'C3'), 180, 2)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C3'), 1.75, 0)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C3'), 2, 1)
        self.getForceField().setDihedral(('C3', 'S1', 'C3', 'C3'), 180, 2)
Ejemplo n.º 24
0
class PSS(Polymer):
    ALL_MONOMERS = Mixture()
    ALL_MONOMERS.loadWFM(WOLFFIA_WFY_DIR + "/PSS.wfm")
    '''
	BACKBONE_MONOMER_MOL = ALL_MONOMERS.getMolecule('PSS_1')
	START_MONOMER_MOL    = ALL_MONOMERS.getMolecule('PSS0_1')
	END_MONOMER_MOL      = ALL_MONOMERS.getMolecule('PSSF_1')
	ONE_MONOMER_MOL      = ALL_MONOMERS.getMolecule('PSS1_1')
	'''

    IMAGE = "/PSS.png"

    MONOMERS_MOLS={ 'Rs':ALL_MONOMERS.getMolecule('PSSs_1'),\
      'Rb':ALL_MONOMERS.getMolecule('PSS_1'),\
      'Re':ALL_MONOMERS.getMolecule('PSSe_1'),\
      'Os':ALL_MONOMERS.getMolecule('PSSns_1'),\
      'Ob':ALL_MONOMERS.getMolecule('PSSn_1'),\
      'Oe':ALL_MONOMERS.getMolecule('PSSne_1'),\
      'P1':ALL_MONOMERS.getMolecule('PSS1_1')}

    NUM_ATOMS_BACKBONE_MONOMER = MONOMERS_MOLS['Rb'].order()
    '''
	NUM_ATOMS_START_MONOMER    = MONOMERS_MOLS[].order()
	NUM_ATOMS_LAST_MONOMER     = MONOMERS_MOLS[].order()
	'''

    END_ATOM = 2  #!!!
    START_ATOM = 21
    DISPL = 1.0
    ANGLE = 3.14

    def __init__(self, n, m, numMonomers):
        # initialize base class
        assert (n >= 0 or m >= 0 or numMonomers > 0)
        molname = "PSS(" + str(n) + ", " + str(m) + ", " + str(
            numMonomers) + ")"

        if n == 0 and m == 0 and numMonomers == 1:  # only one monomer
            #print "PSS ", self.MONOMERS_MOLS['P1'].bonds()
            chain = ['P1']
        else:
            baseChain = []
            for i in range(n):
                baseChain.append('Rb')
            for i in range(m):
                baseChain.append('Ob')
            for i in range(n):
                baseChain.append('Rb')

            chain = []
            for i in range(numMonomers):
                chain += baseChain
            if n > 0:
                chain[0] = 'Rs'
                chain[-1] = 'Re'
            else:
                chain[0] = 'Os'
                chain[-1] = 'Oe'

        #print "PSS ", chain
        Polymer.__init__(self, chain, molname)

        # add FF parameters for monomer junctions
        self.getForceField().setAngle(('C', 'C', 'C'), 60., 0)
        self.getForceField().setAngle(('C', 'C', 'C'), 109.47, 1)
        self.getForceField().setDihedral(('C', 'C', 'C', 'C'), 1.4, 0)
        self.getForceField().setDihedral(('C', 'C', 'C', 'C'), 3, 2)
Ejemplo n.º 25
0
class HomopolyEditor(QtGui.QDialog):
    # Class Fields:
    # ui: stores reference tu user interface
    # files: [string, string], PDF and PSF filenames
    # homopol: Mixture, an Homopolymer
    # homopolPreview: MixtureViewer

    DISPL = {"PMMA": [3.7, 0], "PolyCYT": [6.0, 1]}

    def __init__(self, key, appState, parent=None):
        super(HomopolyEditor, self).__init__(parent, modal=1)

        self.ui = Ui_HomopolyEditor()
        self.ui.setupUi(self)

        self.state = appState
        self.type = key
        #self.slideFactor = 50
        #self.files 	= None

        self.homopolPreview = MixtureViewer()
        self.ui.viewerLayout.addWidget(self.homopolPreview)

        self.ui.lengthDSpinner.setValue(self.DISPL[self.type][0])
        self.ui.lengthDSpinner.setSingleStep(self.DISPL[self.type][0])
        self.ui.lengthDSpinner.setMinimum(self.DISPL[self.type][0])
        self.ui.lengthSlider.setValue(self.DISPL[self.type][0])
        self.ui.lengthSlider.setTickInterval(self.DISPL[self.type][0])
        self.ui.lengthSlider.setMinimum(self.DISPL[self.type][0])
        self.ui.stackedWidget.setCurrentIndex(self.DISPL[self.type][1])

        self.generateHomopol()
        self.generateHomopol()

        if __name__ != '__main__':
            self.ui.saveButton.setHidden(True)

    def generateHomopol(self):
        self.ui.headerLabel.setText(str(self.type) + " Editor")
        n = self.ui.nSpinBox.value()
        self.homopol = Mixture()
        exec("from chemicalGraph.molecule.polymer." + str(self.type) +
             " import " + str(self.type))
        self.homopol.add(eval(str(self.type) + "(n)"))
        self.homopolPreview.setMixture(self.homopol)

    # Manages signals
    def on_nSpinBox_valueChanged(self, value):
        self.generateHomopol()
        length = self.DISPL[self.type][0] * value
        self.ui.lengthDSpinner.setValue(length)
        self.ui.lengthSlider.setValue(length)

    def on_lengthDSpinner_valueChanged(self, value):
        n = int(math.floor(value / self.DISPL[self.type][0]))
        self.ui.nSpinBox.setValue(n)
        self.generateHomopol()
        #self.ui.lengthSlider.setValue(value)

    def on_lengthSlider_sliderMoved(self, value):
        n = int(math.floor(value / self.DISPL[self.type][0]))
        self.ui.nSpinBox.setValue(n)
        self.generateHomopol()
        self.ui.lengthDSpinner.setValue(value)

    def on_okButton_pressed(self):
        self.generateHomopol()
        self.state.addMixture(self.homopol)
        self.close()

    '''
	def on_saveButton_pressed(self):
		from NanotubeSaveDialog import NanotubeSaveDialog

		# generate tube
		self.generateTubes()

		ntDialog = NanotubeSaveDialog(self.tubes,files=self.files, parent=self)
		ntDialog.show()
		ntDialog.exec_()
		self.files = ntDialog.getFileNames()
		print self.files 
	'''

    def on_cancelButton_pressed(self):
        self.close()
Ejemplo n.º 26
0
# Lists of densities and and names for output files
#densities = [100.0,0.90,0.80,0.70,0.60,0.50,0.40,0.30,0.20,0.10,0.05]
#d_names   = ["100","09","08","07","06","05","04","03","02","01","005"]
densities = [0.05]
d_names = ["005"]

# Iterate through every density
for i in range(len(densities)):

    # Density value
    PABAratio = densities[i]
    FileName = "Cellulose_PABA_Tetradecane_D" + d_names[i] + ".wfm"

    # Define mixture
    mixture = Mixture()

    # Generate crystal minus last layer
    monomer = Cellulose(POLY_LENGTH)
    for j in range(VERTICAL_N - 1):
        for i in range(HORIZONTAL_N):
            newMonomer = monomer.copy()
            newMonomer.moveBy([dx * i + dxz * (j % 2), dy * (i % 2), dz * j])
            mixture.add(newMonomer)
            print "layer " + str(j) + ", row " + str(i)

    # Generate last layer
    for i in range(HORIZONTAL_N):
        newMonomer = monomer.copy()
        newMonomer.moveBy([
            dx * i + dxz * ((VERTICAL_N - 1) % 2), dy * (i % 2),
Ejemplo n.º 27
0
class BuildTab(QtWidgets.QFrame):
    def __init__(self, hist, parent=None, previewer=None, settings=None):
        super(BuildTab, self).__init__(parent)

        #print "buildTab init in"
        self.history = hist
        self.mixModification = 0
        self.wolffia = parent
        self.allowUpdate = True
        self.buildPreview = previewer
        self.settings = settings
        self.clipboard = None
        self.prevSelection = None
        self.prevShow = None
        self.prevFixed = None

        #widgets import
        self.ui = Ui_buildTab()
        self.ui.setupUi(self)
        self.ui.structManager.setSortingEnabled(False)

        px = QtGui.QPixmap()
        self._WOLFFIA_OS = platform.system()
        px.load(WOLFFIA_GRAPHICS + "hide.gif", format=None)
        ico = QtGui.QIcon()
        ico.addPixmap(px, state=QtGui.QIcon.On)
        self.ui.structManager.horizontalHeaderItem(0).setIcon(ico)

        px2 = QtGui.QPixmap()
        px2.load(WOLFFIA_GRAPHICS + "pin16.png", format=None)
        fixico = QtGui.QIcon()
        fixico.addPixmap(px2, state=QtGui.QIcon.On)
        self.ui.structManager.horizontalHeaderItem(1).setIcon(fixico)

        #initialize editor
        self.editor = PropertyEditor(self.buildPreview, self.history)
        self.ui.editorLayout.addWidget(self.editor)
        self.buildPreview.setBuildTab(self)

        #initialize tool buttons
        self.ui.removeButton.setIcon(QtGui.QIcon().fromTheme(
            "edit-cut", QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "edit-cut.png")))
        self.ui.updateButton.setIcon(QtGui.QIcon().fromTheme(
            "system-software-update",
            QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "system-software-update.png")))
        self.ui.removeButton.setFlat(True)
        self.ui.duplicateButton.setIcon(QtGui.QIcon().fromTheme(
            "edit-paste",
            QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "edit-paste.png")))
        self.ui.copyButton.setIcon(QtGui.QIcon().fromTheme(
            "edit-copy", QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "edit-copy.png")))
        self.ui.saveWFMbutton.setIcon(QtGui.QIcon().fromTheme(
            "document-save",
            QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "document-save.png")))
        self.ui.addCustomButton.setIcon(QtGui.QIcon().fromTheme(
            "document-open",
            QtGui.QIcon(str(WOLFFIA_GRAPHICS) + "document-open.png")))

        self.showCheckboxes = dict()

        self.firstUpdate = True
        #print "buildTab init out", QtGui.QWidget.keyboardGrabber ()

        self.cMol = C_MOLECULE_CATALOG

    def _checkFixedShiftModifier_(self, basePin, selected):
        for i in range(self.ui.structManager.rowCount()):
            if self.ui.structManager.cellWidget(i, 1) == basePin:
                row = i
                break

        modifiers = QtGui.QApplication.keyboardModifiers()
        if modifiers == QtCore.Qt.ShiftModifier and self.prevFixed != None:
            if self.prevFixed[1] == selected:
                if row < self.prevFixed[0]:
                    ind = list(range(row + 1, self.prevFixed[0] + 1))
                else:
                    ind = list(range(self.prevFixed[0], row))
                for i in ind:
                    pin = self.ui.structManager.cellWidget(i, 1)
                    #if selected: pin.setFixed(update=False)
                    if self.prevFixed[1]: pin.setFixed(update=False)
                    else: pin.setLoose(update=False)
        self.prevFixed = [row, selected]
        #self.buildPreview.update()

    def _checkShowShiftModifier_(self, baseEye, selected):
        #find row
        for i in range(self.ui.structManager.rowCount()):
            if self.ui.structManager.cellWidget(i, 0) == baseEye:
                row = i
                break

        modifiers = QtGui.QApplication.keyboardModifiers()
        if modifiers == QtCore.Qt.ShiftModifier and self.prevShow != None:
            if self.prevShow[1] == selected:
                if row < self.prevShow[0]:
                    ind = list(range(row, self.prevShow[0]))
                else:
                    ind = list(range(self.prevShow[0] + 1, row))
                for i in ind:
                    pin = self.ui.structManager.cellWidget(i, 0)
                    #if selected: pin.setShown(update=False)
                    if self.prevShow[1]: pin.setShown(update=False)
                    else: pin.setHidden(update=False)
        self.prevShow = [row, selected]
        #self.buildPreview.update()

    #---------------------------------------------------------------
    def on_structManager_cellPressed(self, i, j):
        #print "on_structManager_cellPressed ",  i,j
        mouse_state = QtGui.qApp.mouseButtons()
        if QtGui.qApp.mouseButtons() == QtCore.Qt.LeftButton:
            #print "on_structManager_cellPressed ", QtGui.qApp.mouseButtons()==QtCore.Qt.LeftButton, mouse_state==QtCore.Qt.NoButton
            QtGui.qApp.sendEvent(self.ui.structManager,
                                 QtCore.QEvent(QtCore.QEvent.MouseButtonPress))
            #self.ui.structManager.cellPressed.emit(i,j)

    #activates the Structure Catalog
    def on_molCatalog_itemActivated(self, item):
        #print "on_molCatalog_itemActivated in"
        self.key = str(item.text(0))
        self.parent = item.parent().text(0)

        def moleculeDialog(self, dialog):
            dialog.show()
            dialog.exec_()
            self.addMixture(dialog.getMixture())
            self.buildPreview.update()

        # Polymers
        if self.key == "Polyaniline":
            from interface.PANI.paniEditor import PANIBuilder
            pani = PANIBuilder(self.history.currentState(),
                               self,
                               settings=self.settings)
            moleculeDialog(self, pani)
        elif self.key == "PEDOT":
            from interface.PEDOT.pedotEditor import PEDOTBuilder
            pedot = PEDOTBuilder(self.history.currentState(),
                                 self,
                                 settings=self.settings)
            moleculeDialog(self, pedot)
        elif self.key == "PSS":
            from interface.PSS.pssEditor import PSSBuilder
            pss = PSSBuilder(self.history.currentState(),
                             self,
                             settings=self.settings)
            moleculeDialog(self, pss)
        elif self.key == "Cellulose":
            from interface.celluloseEditor.CelluloseEditor import CelluloseEditor
            c = CelluloseEditor(self.history.currentState(),
                                self,
                                settings=self.settings)
            moleculeDialog(self, c)
        elif self.key == "ssDNA":
            print("ssDNA is not yet implemented!")
        elif self.parent == "Homopolymer":
            from interface.homopolyEditor.HomopolyEditor import HomopolyEditor
            homopol = HomopolyEditor(self.key,
                                     self.history.currentState(),
                                     settings=self.settings)
            moleculeDialog(self, homopol)

        # Carbon Allotropes
        elif self.key == "swCNT":
            from interface.nanotubeEditor.nanotubeEditor import NanotubeBuilder
            cnt = NanotubeBuilder(self, self.settings)
            moleculeDialog(self, cnt)
        elif self.key == "Graphene":
            from interface.grapheneEditor.grapheneEditor import GrapheneBuilder
            graph = GrapheneBuilder(self, self.settings)
            moleculeDialog(self, graph)
        elif self.key == "Diamond":
            from interface.diamondEditor.diamondEditor import DiamondBuilder
            diamond = DiamondBuilder(self, self.settings)
            moleculeDialog(self, diamond)

        # Solvents
        elif self.key == "THF":
            from lib.chemicalGraph.molecule.solvent.THF import THF
            self.addMolecule(THF())
        elif self.key == "DMF":
            from lib.chemicalGraph.molecule.solvent.DMF import DMF
            self.addMolecule(DMF())
        elif self.key == "Water":
            from lib.chemicalGraph.molecule.solvent.WATER import WATER
            self.addMolecule(WATER())
        elif self.key == "Chloroform":
            from lib.chemicalGraph.molecule.solvent.CLF import CLF
            self.addMolecule(CLF())
        elif self.key == "Chloroform (4 atoms)":
            from lib.chemicalGraph.molecule.solvent.CLF4 import CLF4
            self.addMolecule(CLF4())
        elif self.key == "Hydrogen Peroxide":
            from lib.chemicalGraph.molecule.solvent.H2O2 import H2O2
            self.addMolecule(H2O2())
        elif self.key == "Xylene":
            from lib.chemicalGraph.molecule.solvent.Xylene import Xylene
            self.addMolecule(Xylene())
        elif self.key == "AcetoneAllH":
            from lib.chemicalGraph.molecule.solvent.AcetoneAllH import AcetoneAllH
            self.addMolecule(AcetoneAllH())
        elif self.key == "AcetoneNoH":
            from lib.chemicalGraph.molecule.solvent.AcetoneNoH import AcetoneNoH
            self.addMolecule(AcetoneNoH())

        # Surfactants
        elif self.key == "SDS":
            from lib.chemicalGraph.molecule.solvent.SDS import SDS
            self.addMixture(SDS())

        elif self.key == "SDBS":
            from lib.chemicalGraph.molecule.solvent.SDBS import SDBS
            self.addMixture(SDBS())

        elif self.key == "PABA-Tetradecane":
            from lib.chemicalGraph.molecule.solvent.PABA import PABA_Tetradecane
            self.addMolecule(PABA_Tetradecane())

        elif self.key == "PABA-Heptane":
            from lib.chemicalGraph.molecule.solvent.PABA import PABA_Heptane
            self.addMolecule(PABA_Heptane())

        elif self.key == "PABA-Pentane":
            from lib.chemicalGraph.molecule.solvent.PABA import PABA_Pentane
            self.addMolecule(PABA_Pentane().changeResidues("PAB"))

        # Ions
        elif self.key == "Na":
            from lib.chemicalGraph.molecule.solvent.Na import Na
            self.addMolecule(Na())

        else:
            self.addMolecule(
                Element(Element.nameToSymbol(self.key.split(' ')[0])))

        self.update()
        self.buildPreview.update()

    def on_addCustomButton_pressed(self):
        from interface.classifier.Load import Load
        self.history.push()
        loader = Load(self)
        loader.show()
        loader.exec_()

        self.addMixture(loader.getMixture())
        self.buildPreview.update()
        self.update()
        self.buildPreview.update()

    def on_copyButton_pressed(self):
        if not self.ui.copyButton.isFlat():
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()
            else:
                self.copy()
        if not self.ui.removeButton.isFlat():
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()
            else:
                self.copy()

    def on_catalogButton_pressed(self):
        if not self.ui.catalogButton.isFlat():
            selected = self.editor.selectedMolecules()
            #print "SELCTEDDDDDD >>." , selected[0]
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()

            elif selected == []:
                QtGui.QMessageBox.warning(self, "Wolffia's warning",
                                          "Please select a molecule.",
                                          QtGui.QMessageBox.Ok)
                return

            else:
                #print "on_catalogButton_pressed",  self.ui.molCatalog.topLevelItemCount()
                customTreeWidget = self.ui.molCatalog.topLevelItem(
                    self.ui.molCatalog.topLevelItemCount() - 1)
                #print "on_catalogButton_pressed childCount", customTreeWidget.childCount ()

                print("SELCTEDDDDDD >>.", selected)
                mixtureToSave = Mixture()
                print("mixtureToSave >>>>", mixtureToSave)
                molName = ""
                print("molName >>>>", molName)
                for mol in selected:
                    print("mol >>>>", mol)
                    mixtureToSave.add(mol.copy(), True)
                    print("mixtureToSave agregados >>>>", mixtureToSave)
                    if molName == "":
                        molName = mol.molname()
                    else:
                        molName += ("-" + mol.molname())

                print("SELECETEDDDD: ", selected, "mixtureToSave Final",
                      mixtureToSave)
                print(
                    "############################################################"
                )
                #Pregunta el nombre de la molecula que quiere guardar en el catalogo
                nameMolGUI = QtGui.QInputDialog(self)
                nameMolGUI.setTextValue(str(selected[0]))

                nameMol, ok = nameMolGUI.getText(self, "Custom Molecule",
                                                 "Set Molecule Name:", 0,
                                                 str(selected[0]))

                print("value ", nameMol, " ok ", ok)
                if ok:
                    #Guarda archivo en .cMolecule dentro de .wolffia
                    cMixFileName = "/" + nameMol + ".wfm"
                    cMixFileDir = WOLFFIA_DIR + C_MOLECULE_CATALOG + cMixFileName
                    if os.path.exists(cMixFileDir):
                        print("archivo existe", cMixFileDir)
                        nameMol = nameMol + "*"
                        cMixFileName = "/" + nameMol + ".wfm"
                        cMixFileDir = WOLFFIA_DIR + C_MOLECULE_CATALOG + cMixFileName

                    print("cMixFileDir>>>>>", cMixFileDir)
                    #Add a child to Custom Molecule in the Molecular Structure Catalog
                    nameQT = QtGui.QTreeWidgetItem()
                    nameQT.setText(0, nameMol)
                    customTreeWidget.addChild(nameQT)
                    #customTreeWidget.addChild(QtGui.QTreeWidgetItem())
                    print("NAMEMOL1", nameMol)
                    self.history.currentState().getMixture().save(cMixFileDir)

                #Guarda archivo en .cMolecule dentro de .wolffia
                #MixtureToSave are selected
                #cMixtureToSave = Mixture("To save")
                #Nombre del Archivo que se va a guardar es cMolName
                #cMolName = str(nombre.textValue()) + ".wfm"
                #for mol in selected:
                #   print "mol:", mol
                #	cMixtureToSave.add(mol.copy(), False)

                #Directorio en donde se va a guardar es dirCmolName
                #dirCmolName = self.settings.workingFolder + self.cMol

                #try:
                #	print "TRYYYYYYYYYYYYyyyyy"
                #	basename = str(dirCmolName.path() +  "/" + cMolName)
                #	print "basename" , basename
                #	mixtureToSave.writePDB(basename)

                #except:
                #	QtGui.QMessageBox.warning(self, "Wolffia's warning", cMolName + " could not be saved.", QtGui.QMessageBox.Ok)

                #print "cmolName >>>>>>>>>",cMolName, "directorio: >>>>>>", dirCmolName
                #selected.writePDB(cMolName)
                #print "SAVEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE "
                #print ""

    def on_catalogButton_pressed(self):
        if not self.ui.removeButton.isFlat():
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()
            else:
                print("on_catalogButton_pressed",
                      self.ui.molCatalog.topLevelItemCount())
                customTreeWidget = self.ui.molCatalog.topLevelItem(
                    self.ui.molCatalog.topLevelItemCount() - 1)
                print("on_catalogButton_pressed childCount",
                      customTreeWidget.childCount())
                selected = self.editor.selectedMolecules()
                nombre = QtGui.QInputDialog(self)
                nombre.setTextValue(str(selected[0]))
                nombre.exec_()
                customTreeWidget.addChild(
                    QtGui.QTreeWidgetItem([str(nombre.textValue())]))

    def on_duplicateButton_pressed(self):
        if not self.ui.duplicateButton.isFlat():
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()
            else:
                self.history.push()
                self.duplicate()
                self.buildPreview.update()

    def on_removeButton_pressed(self):
        #print "on_removeButton_pressed"
        if not self.ui.removeButton.isFlat():
            if (self.wolffia.simRunning):
                message = QtGui.QMessageBox(
                    1, "Warning", "There's a simulation running right now.")
                message.exec_()
            else:
                progress = QtGui.QProgressDialog(
                    "Removing...", QtCore.QString(), 0, 5, self,
                    QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint)
                progress.setWindowModality(QtCore.Qt.WindowModal)

                progress.setValue(1)
                self.history.push()
                progress.setValue(2)
                self.remove()
                progress.setValue(3)
                self.editor.reset()
                progress.setValue(4)
                self.buildPreview.update()
                #self.buildPreview.setMixture(self.history.currentState().getMixture())
                progress.setValue(5)
                progress.hide()

    #-------------------------------------------------------------------------------
    def on_saveWFMbutton_pressed(self, saveState=True):
        #print "on_saveWFMbutton_pressed "
        if not saveState: return

        else:
            mixFile = self.settings.currentMixtureLocation(
            ) + self.history.currentState().getMixtureName() + ".wfm"
            d = WFileNameDialog(self, 'Save current Mixture',
                                self.settings.currentMixtureLocation(),
                                "Mixture file (*.wfm)")
            if d.isReady():
                filename = d.fullFilename()
                #print "FILENAME = ", filename
                #print "on_saveWFMbutton_pressed >>>>> ","\'"+filename[-4:]+"\'"
                if filename[-4:] != ".wfm" and QtGui.QMessageBox.question(
                        self, "Wolffia's message",
                        "File does not end with .wfm. Add extension?", "Yes",
                        "No") == 0:
                    filename += ".wfm"
                    if os.path.exists(filename) and QtGui.QMessageBox.question(
                            self, "Wolffia's message", "File exists.",
                            "Overwrite", "Cancel") != 0:
                        return
                self.history.currentState().getMixture().save(filename)

                QtGui.QMessageBox.information(self, "Wolffia's message",
                                              filename + " saved.",
                                              QtGui.QMessageBox.Ok)

    def on_saveButton_pressed2(self, saveFiles=True):
        if not saveFiles: return
        mixName = self.history.currentState().getMixtureName()
        d = WDirectoryDialog(
            self, 'Specify directory to save ' + mixName + ".pdb and " +
            mixName + ".psf", self.settings.workingFolder)

        if d.accepted():
            basename = d.path() + "/" + mixName
            import os
            if not (os.path.exists(basename + ".pdb") or os.path.exists(
                    basename + ".psf")) or QtGui.QMessageBox.question(
                        self, "Wolffia's message", "File exists.", "Overwrite",
                        "Cancel") == 0:
                mix = self.history.currentState().getMixture()
                mix.writePDB(basename + ".pdb")
                mix.writePSF(basename + ".psf")

                QtGui.QMessageBox.information(
                    self, "Wolffia's message",
                    mixName + ".pdb and " + mixName + ".psf saved.",
                    QtGui.QMessageBox.Ok)

    def on_saveButton_pressed3(self, saveFiles=True):
        if not saveFiles: return
        selected = self.editor.selectedMolecules()
        #print "on_saveButton_pressed ", selected
        if selected == []:
            QtGui.QMessageBox.warning(
                self, "Wolffia's warning",
                "Could not determine the molecule to be saved.\nPlease select one.",
                QtGui.QMessageBox.Ok)
            return

        mixtureToSave = Mixture("To save")
        molName = ""
        for mol in selected:
            mixtureToSave.add(mol.copy(), False)
            if molName == "":
                molName = mol.molname()
            else:
                molName += ("-" + mol.molname())

        d = WDirectoryDialog(
            self, 'Specify directory to save ' + molName + ".pdb and " +
            molName + ".psf", self.settings.workingFolder)

        try:
            if d.accepted():
                basename = str(d.path() + "/" + molName)
                #import os
                if not (os.path.exists(basename + ".pdb") or os.path.exists(
                        basename + ".psf")) or QtGui.QMessageBox.question(
                            self, "Wolffia's message", "File exists.",
                            "Overwrite", "Cancel") == 0:
                    #mix = self.history.currentState().getMixture()
                    #print "on_saveButton_pressed ", basename
                    mixtureToSave.writePDB(basename + ".pdb")
                    mixtureToSave.writePSF(basename + ".psf")

                    QtGui.QMessageBox.information(
                        self, "Wolffia's message",
                        molName + ".pdb and " + molName + ".psf saved.",
                        QtGui.QMessageBox.Ok)
        except:
            QtGui.QMessageBox.warning(
                self, "Wolffia's warning",
                molName + ".pdb and " + molName + ".psf could not be saved.",
                QtGui.QMessageBox.Ok)

    #------------------------------------------------------------------------------------------

    def on_updateButton_pressed(self):
        #print "on_updateButton_pressed "

        QtGui.QMessageBox.information(
            self, "Wolffia's message",
            "Updates can only be done from coordinate files\nproduced by simulations prepared with Wolffia.\nOther files will produce unexpected results..",
            QtGui.QMessageBox.Ok)

        d = WFileDialog(self,
                        'Specify coordinate file to load.',
                        self.settings.workingFolder,
                        filter="*.pdb *.coor")

        if d.accepted():
            self.history.push()
            try:
                self.history.currentState().mixture.updateCoordinates(
                    str(d.fullFilename()))

                self.buildPreview.update()
                QtGui.QMessageBox.information(self, "Wolffia's message",
                                              "Coordinates updated.",
                                              QtGui.QMessageBox.Ok)
            except:
                QtGui.QMessageBox.warning(self, "Wolffia's warning",
                                          "Coordinates could not be updated.",
                                          QtGui.QMessageBox.Ok)
                self.history.back()

    def on_structManager_itemChanged(self, wi):
        #if isinstance(wi, myTableWidgetItem) and wi.name != "(no name)" and wi.isSelected():
        if wi.column() == 2:
            row = wi.row()
            mol = str(self.ui.structManager.item(row, 4).text())

            if str(wi.text()) == "":
                wi.setText(
                    self.history.currentState().getMixture().getMolecule(
                        mol).molname())
            elif mol[:8] == "SOLVENT(":
                if wi.text() != self.history.currentState().getMixture(
                ).getMolecule(mol).molname():
                    nameLen = len(mol)
                    sepPos = mol.rfind("_")
                    for molecule in self.history.currentState().getMixture():
                        if mol[:sepPos] == molecule[:sepPos]:
                            with warnings.catch_warnings(record=True) as w:
                                #print "on_structManager_itemChanged",molecule,str(wi.text()),str(wi.text())+molecule[sepPos:]
                                self.history.currentState().getMixture(
                                ).renameMolecule(molecule, str(wi.text()))
                            if len(w) > 0:
                                QtGui.QMessageBox.information(
                                    self, "Error", str(w[-1].message))
                    self.update()

            else:
                #print "on_structManager_itemChanged changing molecule with id ", mol
                #print "on_structManager_itemChanged", self.history.currentState().getMixture().getMolecule(mol).molname(), "->", str(wi.text()), " row=", row
                if wi.text() != self.history.currentState().getMixture(
                ).getMolecule(mol).molname():
                    self.history.push()
                    with warnings.catch_warnings(record=True) as w:
                        self.history.currentState().getMixture(
                        ).renameMolecule(mol, str(wi.text()))
                    if len(w) > 0:
                        QtGui.QMessageBox.information(self, "Error",
                                                      str(w[-1].message))
                    self.update()

                    #self.history.currentState().getMixture().getMolecule(mol).rename(str(wi.text()))
                    #print "on_structManager_itemChanged getMixture:",self.history.currentState().getMixture()

    def on_structManager_cellClicked(self, row, col):
        #update editor with selected molecule
        #print "on_structManager_cellClicked",row,col

        molecules = self.history.currentState().getMixture().moleculeIDs()
        molecules.sort()

        #mol = molecules[row]
        mol = str(self.ui.structManager.item(row, 4).text())
        #print "on_structManager_cellClicked",row,col,mol
        if col == 0:
            item = self.ui.structManager.itemAt(row, col)
            #print "detecto"
        elif col == 2:
            #print "on_structManager_cellClicked B"
            #selected = self.editor.setMolecule(self.history.currentState().getMixture().getMolecule(mol), str(mol), True)
            m = self.history.currentState().getMixture().getMolecule(mol)
            #print "on_structManager_cellClicked B2",m,mol
            selected = self.editor.setMolecule(m, str(mol), True)
            #print "on_structManager_cellClicked C", selected

            # if shift key is pressed perform multiple selects
            modifiers = QtGui.QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ShiftModifier and self.prevSelection != None:
                if self.prevSelection[1] == selected:
                    if row < self.prevSelection[0]:
                        ind = list(range(row + 1, self.prevSelection[0]))
                    else:
                        ind = list(range(self.prevSelection[0] + 1, row))
                    for i in ind:
                        mol = str(self.ui.structManager.item(i, 4).text())
                        m = self.history.currentState().getMixture(
                        ).getMolecule(mol)
                        if self.prevSelection[1]:
                            self.editor.removeSelection(m, str(mol))
                        else:
                            self.editor.setMolecule(m,
                                                    str(mol),
                                                    removeIfPresent=False)

            self.prevSelection = [row, selected]
            self.ui.removeButton.setFlat(False)
            self.ui.duplicateButton.setFlat(self.clipboard == None
                                            or len(self.clipboard) == 0)
            self.ui.copyButton.setFlat(False)
            self.ui.catalogButton.setFlat(False)

            self.repaint()
            self.buildPreview.update()
            #print "on_structManager_cellClicked D"

        #self.update()
        #self.buildPreview.update()
        return

    @QtCore.pyqtSlot()
    def on_saveButton_triggered(self, saveFiles=True):
        if not saveFiles: return
        d = WFileNameDialog(self, 'Save Files',
                            self.history.currentState().getBuildDirectory())
        if d.isReady():
            self.history.currentState().setMixtureName(d.mixname())
            self.history.currentState().writeFiles(d.fullFilename())
            mesg = self.history.currentState().getMixtureName(
            ) + '.pdb, ' + self.history.currentState().getMixtureName(
            ) + '.psf and ' + self.history.currentState().getMixtureName(
            ) + '.prm'
            info = QtGui.QErrorMessage(self)
            info.setModal(True)  # blocks Wolffia
            info.showMessage("The files " + mesg +
                             " have been successfully saved in " + d.path())

    def on_showCheckbox(self, on):
        print("on_showCheckbox", end=' ')

    def addMolecule(self, mol, remember=True):
        if mol != None:
            self.editor.reset()
            with warnings.catch_warnings(record=True) as w:
                self.history.currentState().addMolecule(mol)
                self.buildPreview.setMixture(
                    self.history.currentState().getMixture(), True)
                #print "addMolecule len(w)",len(w)
                if len(w) > 0:
                    QtGui.QMessageBox.information(self, "Error",
                                                  str(w[-1].message))
            if remember: self.history.push()

    def addMixture(self, mix, remember=True):
        if mix != None:
            for mol in mix:
                self.addMolecule(mix.getMolecule(mol), False)
                #self.history.currentState().addMixture(mix)
            if remember: self.history.push()

    def chosenMolecules(self):
        count = self.ui.structManager.topLevelItemCount()
        for i in range(count):
            item = self.ui.structManager.itemAt(i, 1)
            #print item.isChecked()

    def copy(self):
        selected = self.editor.selectedMolecules()
        #print "copy ", selected
        if selected == []:
            errorgui = QtGui.QErrorMessage(self)
            errorgui.setModal(True)  # blocks Wolffia
            errorgui.showMessage("Error: no molecule chosen.")
        else:
            self.clipboard = Mixture("Clipboard")
            for mol in selected:
                #print "copy", mol
                #self.clipboard.add(self.history.currentState().getMixture().getMolecule(molname).copy(), False)
                self.clipboard.add(mol.copy(), False)
        #print "copy update<", self.editor.selected()
        self.update()
        #print "copy >", self.editor.selected()

    def duplicate(self):
        from sets import Set
        #print "duplicate ", self.clipboard.molecules()
        currentIDs = Set(self.history.currentState().getMixture().molecules())
        try:
            newMols = self.clipboard.copy()
            newMols.moveBy([
                random.uniform(0., 0.1),
                random.uniform(0., 0.1),
                random.uniform(0., 0.1)
            ])
            self.history.currentState().getMixture().merge(newMols)
        except:
            errorgui = QtGui.QErrorMessage(self)
            errorgui.setModal(True)  # blocks Wolffia
            errorgui.showMessage("Error: could not duplicate molecules.")

        # select pasted molecules
        newMols = Set(
            self.history.currentState().getMixture().molecules()) - currentIDs

        progressMax = len(newMols) - 1
        progressCount = 0
        progress = QtGui.QProgressDialog(
            "Adding...", QtCore.QString(), 0, progressMax, self,
            QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint)
        progress.setWindowModality(QtCore.Qt.WindowModal)

        #print "duplicate ", self.history.currentState().getMixture().molecules(),newMols
        self.editor.reset()
        for mol in newMols:
            self.editor.setMolecule(
                self.history.currentState().getMixture().getMolecule(mol), mol)
            self.history.currentState().shownMolecules.show(mol)
            progressCount += 1
            progress.setValue(progressCount)
        self.insertAllToManager()
        progress.hide()

        self.update()

    def insertAllToManager(self):
        from lib.chemicalGraph.molecule.solvent.Solvent import Solvent
        start = time.clock()
        #print "insertAllToManager ",self.history.currentState().getMixture().molecules()

        self.mixModification = self.history.currentState().getMixture(
        ).getModificationTime()
        #self.ui.structManager.setRowCount(len(self.history.currentState().mixture))
        self.ui.structManager.setRowCount(0)
        row = 0
        solventShown = ShownSolvent()
        shownMolecules = self.history.currentState().shownMolecules
        molecules = self.history.currentState().getMixture().moleculeIDs()
        #print "insertAllToManager ",molecules

        #progress	  = QtGui.QProgressDialog("Storing...", "Abort", 0, len(molecules), self,QtCore.Qt.Dialog|QtCore.Qt.WindowTitleHint)
        #progress.setWindowModality(QtCore.Qt.WindowModal)
        #progress.setAutoClose(True)
        #progress.setMinimumDuration(0)

        self.ui.structManager.blockSignals(True)
        molecules.sort()
        molNum = 0
        for molName in molecules:
            #molName = self.history.currentState().getMixture().getMolecule(mol).molname()
            #print "insertAllToManager ",ShownSolvent.isSolvent(molName),solventShown.isShown(molName)
            if not ShownSolvent.isSolvent(molName) or not solventShown.isShown(
                    molName):
                self.ui.structManager.setRowCount(row + 1)
                #insert checkbox on column 1

                checkBox = PreviewButton(self.history.currentState(),
                                         self.buildPreview,
                                         molname=str(molName),
                                         parent=self,
                                         initState=shownMolecules.isShown(
                                             str(molName)),
                                         editor=self.editor)
                checkBox.setToolTip("Show or hide.")
                self.ui.structManager.setCellWidget(row, 0, checkBox)

                pin = FixedButton(self.history.currentState(),
                                  self.buildPreview,
                                  molname=str(molName),
                                  parent=self,
                                  initState=self.history.currentState().
                                  fixedMolecules.isFixed(str(molName)))
                pin.setToolTip("Fixes position of the molecule.")
                self.ui.structManager.setCellWidget(row, 1, pin)

                #print "insertAllToManager",str(self.history.currentState().mixture.getMolecule(molName)._name) , molecules

                #insert molname on column 2
                baseMolName = str(
                    self.history.currentState().mixture.getMolecule(
                        molName).molname())
                #print "insertAllToManager  creando item para ", baseMolName

                #if isinstance(self.history.currentState().mixture.getMolecule(molName), Solvent):
                #	baseMolName += "(solvent)"
                newitem = QtGui.QTableWidgetItem(baseMolName)
                newitem.setFlags(QtCore.Qt.ItemIsEditable
                                 | QtCore.Qt.ItemIsEnabled)
                newitem.setToolTip(
                    "Click to select or double click to edit the name.")
                self.ui.structManager.setItem(row, 2, newitem)

                #print "insertAllToManager",self.editor.getId(),molName
                if molName in self.editor.selectedNames():
                    newitem.setBackgroundColor(QtCore.Qt.green)

                #insert atom count on column 3
                newitem = QtGui.QTableWidgetItem(
                    str(self.history.currentState().mixture.getMolecule(
                        molName).order()))
                newitem.setFlags(QtCore.Qt.ItemIsEnabled)
                self.ui.structManager.setItem(row, 3, newitem)

                #insert id on column 4
                newitem = QtGui.QTableWidgetItem(str(molName))
                newitem.setFlags(QtCore.Qt.ItemIsEnabled)
                self.ui.structManager.setItem(row, 4, newitem)

                row += 1
                solventShown.setAsShown(molName)
                #print "insertAllToManager solventShown.setAsShown(molName) ", solventShown.isShown(molName)
            elif not ShownSolvent.isSolvent(molName):
                self.history.currentState().shownMolecules.show(molName)

            molNum += 1
            #progress.setValue(molNum)

        #self.buildPreview.setMixture(self.history.currentState().getMixture())
        #self.chosenMolecules()

        self.ui.structManager.blockSignals(False)
        self.ui.removeButton.setFlat(len(self.editor) == 0)
        #self.ui.duplicateButton.setFlat(self.editor.ident == None)
        self.ui.copyButton.setFlat(len(self.editor) == 0)
        self.ui.catalogButton.setFlat(len(self.editor) == 0)
        self.ui.duplicateButton.setFlat(self.clipboard == None
                                        or len(self.clipboard) == 0)

        #self.ui.removeButton.setFlat(molNum == 0)
        #self.ui.duplicateButton.setFlat(molNum == 0)

        #progress.hide()
        stop = time.clock()
        #print "insertAllToManager time",stop-start

    def showEvent(self, e):
        #print "buildTab showEvent"
        #start = time.clock()
        #if self.firstUpdate:
        #	self.update()
        #	self.firstUpdate = False

        self.update()
        super(BuildTab, self).showEvent(e)
        #print "buildTab showEvent time",time.clock()-start

    def remove(self):
        #print "remove"
        self.copy()
        selected = self.editor.selectedNames()
        #print "BuildTab.remove ", selected

        try:
            self.history.currentState().removeMoleculesFrom(selected)
            '''
			for molname in selected:
				self.history.currentState().removeMolecule(molname)
			'''

            #print "BuildTab.remove ", selected, " removed "
        except:
            #errorgui = QtGui.QErrorMessage(self)
            #errorgui.setModal(True) # blocks Wolffia
            #errorgui.showMessage("Error: could not delete molecule "
            #	+ molname + "." )
            logging.getLogger(self.__class__.__name__).warning(
                "Could not delete molecules " + selected + ".")
        self.editor.reset()
        self.update()

    def repaint(self):
        selected = self.editor.selectedNames()
        for row in range(self.ui.structManager.rowCount()):
            #print "repaint ", self.ui.structManager.item(row,4).text()
            if self.ui.structManager.item(row, 4).text() in selected:
                self.ui.structManager.item(row, 2).setBackgroundColor(
                    QtCore.Qt.green)
            else:
                self.ui.structManager.item(row, 2).setBackgroundColor(
                    QtCore.Qt.white)

    def reset(self):
        #print "buildTab reset in"
        self.buildPreview.reset()
        self.editor.reset()
        self.prevSelection = None
        self.prevShow = None
        self.prevFixed = None
        #print "buildTab reset out"

    def update(self):
        #start = time.clock()

        #print "updating buldTab, mixture=", self.history.currentState().getMixture()
        self.insertAllToManager()
        #print "buildTab update insertAllToManager",time.clock()-start
        #self.buildPreview.setMixture(self.history.currentState().getMixture())
        self.mixModification = time.clock()

        self.ui.structManager.resizeColumnToContents(0)
        self.ui.structManager.resizeColumnToContents(1)
        self.ui.structManager.resizeColumnToContents(2)
        self.ui.structManager.resizeColumnToContents(3)

        self.editor.update()
        #self.buildPreview.update()
        #self.wolffia.update()
        #print "buildTab update time",time.clock()-start
        self.repaint()

    '''
Ejemplo n.º 28
0
    def __init__(self, m, n, q):

        diamondMix = Mixture()
        diamondMix.loadWFM(WOLFFIA_WFY_DIR + "/diamond.wfm")
        diamondCell = diamondMix.getMolecule('Diamond_1')

        sal = Element("NA")
        sal.moveBy([-1, -1, -1])  # put it out of the way

        #'Crece' el diamante
        tempMixture = Mixture()
        for dm in range(m):
            for dn in range(n):
                for dq in range(q):
                    newCell = diamondCell.copy()
                    newCell.moveby([dm * 5.43, dn * 5.43, dq * 5.43])
                    tempMixture.add(newCell)

        tempMixture.add(sal)

        G = tempMixture.copy()
        H = tempMixture.copy()
        Coord = []
        overlapAtoms = []
        atomNeighbors = []
        toEliminate = []

        #Hace que las moleculas se conecten al atomo de Na y hace de la mezcla una molecula
        for p, mol in enumerate(G):
            molecule = G.getMolecule(mol)
            for idx, atom1 in enumerate(molecule):
                if molecule.getAttributes(
                        atom1).getInfo().getElement() == "NA":
                    molSal = mol
                    numMolecule = p
                    atomSal = molecule.atom(idx)

        for p, mol in enumerate(G):
            molecule = G.getMolecule(mol)
            if p != numMolecule:
                molC = mol
                atomC = molecule.atom(1)
                H.addBond([molSal, atomSal], [molC, atomC])

        #Pone las coordenadas de la mezcla en una lista
        for p, mol in enumerate(H):
            molecule = H.getMolecule(mol)
            for atom in molecule:
                coordinates = molecule.getAttributes(atom).getCoord()
                Coord.append(coordinates)

        #Te da los atomos que estan en la misma posicion
        for a, coord1 in enumerate(Coord):
            #print a,coord1
            for x, coord2 in enumerate(Coord):
                if a < x and math.fabs(
                        coord1[0] - coord2[0]) < TOLERANCE and math.fabs(
                            coord1[1] - coord2[1]) < TOLERANCE and math.fabs(
                                coord1[2] - coord2[2]) < TOLERANCE:
                    overlapAtoms.append(a)
                    overlapAtoms.append(x)
                    toEliminate.append(x)

        #Te dice los vecinos de los atomos
        for mol in H:
            molecule = H.getMolecule(mol)
            for i in range(len(overlapAtoms) / 2):
                vecinos = molecule.neighbors(overlapAtoms[2 * i + 1] + 1)
                #atomNeighbors.append(overlapAtoms[2*i+1]+1)
                atomNeighbors.append(vecinos)

        G = H.copy()

        for p, mol in enumerate(G):
            molecule = G.getMolecule(mol)
            for i, j in enumerate(atomNeighbors):
                #print i, len(j), j[0]

                mol1 = mol
                atom1 = molecule.atom(overlapAtoms[2 * i])
                #print atom1, "atomo 1", i
                if len(j) == 1:
                    atom2 = molecule.atom(j[0] - 1)
                    #print j[0]
                    #print atom2, atom1
                    H.addBond([mol1, atom1], [mol1, atom2])
                elif len(j) == 2:
                    atom2A = molecule.atom(j[0] - 1)
                    atom2B = molecule.atom(j[1] - 1)
                    H.addBond([mol1, atom1], [mol1, atom2A])
                    H.addBond([mol1, atom1], [mol1, atom2B])

        #toEliminate.sort()
        G = H.copy()
        #print "a Eliminarse", toEliminate

        toEliminate = sorted(set(toEliminate))

        #Busca el indice del atomo Na
        for p, mol in enumerate(G):
            molecule = G.getMolecule(mol)
            for idx, atom1 in enumerate(molecule):
                if molecule.getAttributes(
                        atom1).getInfo().getElement() == "NA":
                    idxNa = idx + 1

        #Elimina los atomos 'repetidos' y el atomo de Na
        for p, mol in enumerate(G):
            molecule = G.getMolecule(mol)
            for i in reversed(toEliminate):
                #print i+1
                molecule.removeAtom(i + 1)
            molecule.removeAtom(idxNa)

        Molecule.__init__(self, "Diamond", next(G.moleculeGenerator()))

        # Fix atom types
        for atom in self:
            N = len(self.neighbors(atom))
            if N == 4:
                self.getAtomAttributes(atom).getInfo().setType("C")
            if N == 1:
                self.getAtomAttributes(atom).getInfo().setType("C2")
            if N == 2:
                self.getAtomAttributes(atom).getInfo().setType("C3")

        self.getForceField().setBond(('C', 'C'), 222., NonBond._EPSILON)
        self.getForceField().setBond(('C', 'C'), 1.512, NonBond._SIGMA)
Ejemplo n.º 29
0
class PropertyEditor(QtWidgets.QWidget):
    def __init__(self, viewer, history):
        super(PropertyEditor, self).__init__()

        # set class fields
        self.viewer = viewer
        self.history = history

        #widgets import
        self.ui = Ui_propertyEditor()
        self.ui.setupUi(self)
        
        self.tree = self.ui.propertyTree
        self.tree.  setColumnWidth(0, 100)
        self.tree.  setColumnWidth(1, 140)        

        #initializes widgets on tree
        self.xRotate = QtWidgets.QDoubleSpinBox(self.tree)
        self.xRotate.  setSingleStep (10.)
        self.xRotate.  setRange (-360., 360.)
        xRotateAt    = self.tree.topLevelItem(1).child(0)
        
        self.yRotate = QtWidgets.QDoubleSpinBox(self.tree)
        self.yRotate.  setSingleStep (10.)
        self.yRotate.  setRange (-360., 360.)
        yRotateAt    = self.tree.topLevelItem(1).child(1)
        
        self.zRotate = QtWidgets.QDoubleSpinBox(self.tree)
        self.zRotate.  setSingleStep (10.)
        self.zRotate.  setRange (-360., 360.)
        zRotateAt    = self.tree.topLevelItem(1).child(2)

        self.xMoveBy = QtWidgets.QDoubleSpinBox(self.tree)
        self.xMoveBy.  setSingleStep (0.5)
        self.xMoveBy.  setRange (-1000., 1000.)
        xMoveByAt    = self.tree.topLevelItem(2).child(0)
        
        self.yMoveBy = QtWidgets.QDoubleSpinBox(self.tree)
        self.yMoveBy.  setSingleStep (0.5)
        self.yMoveBy.  setRange (-1000., 1000.)
        yMoveByAt    = self.tree.topLevelItem(2).child(1)
        
        self.zMoveBy = QtWidgets.QDoubleSpinBox(self.tree)
        self.zMoveBy.  setSingleStep (0.5)
        self.zMoveBy.  setRange (-1000., 1000.)
        zMoveByAt    = self.tree.topLevelItem(2).child(2)
        
        #adds widgets to tree 
        self.tree.setItemWidget(xRotateAt, 1, self.xRotate)  
        self.tree.setItemWidget(yRotateAt, 1, self.yRotate)                
        self.tree.setItemWidget(zRotateAt, 1, self.zRotate)   

        self.tree.setItemWidget(xMoveByAt, 1, self.xMoveBy)  
        self.tree.setItemWidget(yMoveByAt, 1, self.yMoveBy)                
        self.tree.setItemWidget(zMoveByAt, 1, self.zMoveBy)
         
        #manages widget events
        self.xRotate.valueChanged.connect(self.Rotate)
        self.yRotate.valueChanged.connect(self.Rotate)
        self.zRotate.valueChanged.connect(self.Rotate)

        self.xMoveBy.valueChanged.connect(self.MoveBy)
        self.yMoveBy.valueChanged.connect(self.MoveBy)
        self.zMoveBy.valueChanged.connect(self.MoveBy)

        self.tree.resizeColumnToContents(0)
        self.tree.resizeColumnToContents(1)

        #initialize tree window
        self.reset()

    def reset(self):
        #print "PropertyEditor reset "
        self.mixture  = Mixture(None)
        self.registry = dict()
        #self.ident    = None
        
        self.resetBoxes()
        self.setToolTip("Select molecules to activate.")
        self.setEnabled(False)
        self.update()

    def update(self):
        # update resistry
        presentMolecules = self.history.currentState().getMixture().molecules()
        #print "PropertyEditor update  ",presentMolecules, self.registry
        regKeys = list(self.registry.keys())
        for regKey in regKeys:
            if not regKey in presentMolecules:
                if self.mixture.hasMoleculeID(regKey): self.mixture.remove(regKey)
                self.registry.pop(regKey)

        self.resetBoxes()
        QtWidgets.QWidget.update(self)

    def resetBoxes(self):
        if len(self) == 0:
            self.tree.topLevelItem(0).setText(1, "")
        else:
            self.tree.topLevelItem(0).setText(1, str(self))
        self.dx = 0.
        self.dy = 0.
        self.dz = 0.
        self.anglex = 0.
        self.angley = 0.
        self.anglez = 0.
        
        self.xRotate.setValue(0.)
        self.yRotate.setValue(0.)
        self.zRotate.setValue(0.)

        self.xMoveBy.setValue(0.)
        self.yMoveBy.setValue(0.)
        self.zMoveBy.setValue(0.)

    #show molecule name in the editor
    def setMolecule(self, molecule, ident, removeIfPresent=False):
        '''
        Returns True if the molecule ends up selected, False otherwise..
        '''
        from .BuildTab import ShownSolvent
        #print "PropertyEditor setMolecule new", ident,  self.registry
        if ident not in self.registry:
            if ShownSolvent.isSolvent(ident):
                mixture = self.history.currentState().getMixture()
                mixtureNames = mixture.molecules()
                #print "PropertyEditor setMolecule SOLVENT(",mixtureNames
                pos = ident.find(')')+1
                for mol in mixtureNames:
                    if mol[:pos] == ident[:pos]:
                        self.registry[mol] = self.mixture.add(mixture.getMolecule(mol), False)
                        self.registry[mol] = mixture.getMolecule(mol)
            else:
                #print "PropertyEditor setMolecule adding", ident
                self.registry[ident] = molecule
                #print "PropertyEditor setMolecule adding to mixture", ident, self.mixture.molecules()
                self.mixture.add(molecule, False)
            
            #self.ident = ident
            #self.ident = self.getId()
            self.setToolTip("Manage molecules' positions.")
            self.setEnabled(True)
            return False
            self.resetBoxes()
        else:
            #print "PropertyEditor setMolecule duplicate",ident,  self.registry
            if removeIfPresent:
                if ShownSolvent.isSolvent(ident):
                    mixture = self.history.currentState().getMixture()
                    mixtureNames = mixture.molecules()
                    pos = ident.find(')')+1
                    for mol in mixtureNames:
                        #print "PropertyEditor removing ",ident[:pos], mol[:pos]
                        if mol[:pos] == ident[:pos]:
                            #print "PropertyEditor OK "
                            self.removeSelection(mixture.getMolecule(mol), mol)
                else:
                    self.removeSelection(molecule, ident)
                return True
        #print "PropertyEditor setMolecule reseting"
        #print "PropertyEditor setMolecule finished"


    def removeSelection(self, molecule, ident):
        if ident in self.registry:
            self.mixture.remove(self.mixture.getMoleculeID(molecule))
            self.registry.pop(ident)
            #print "PropertyEditor removeSelection removed:",ident
            if len(self.registry) == 0:
                self.reset()
            #print "PropertyEditor setMolecule reseting"
            self.resetBoxes()
    
    def hasSelections(self): return len(self.registry) > 0

    def selectedMolecules(self):
        #print "selectedMolecules ", self.registry
        return list(self.registry.values())

    def selectedNames(self):
        #print "selectedMolecules ",self.registry
        return list(self.registry.keys())

    def __str__(self):
        return str(list(self.registry.keys()))

    def __len__(self):
        return len(self.registry)
    
    #show rotation values in the editor     
    def Rotate(self):        
        if self.mixture.order() > 0:
            x = self.xRotate.value()
            y = self.yRotate.value()
            z = self.zRotate.value()
            value = str(x) + " x " + str(y) + " x " + str(z)
            self.tree.topLevelItem(1).setText(1, value)
            center = self.mixture.center()
            self.mixture.moveBy([-xx for xx in center])
            #print "Rotate ", x-self.anglex,y-self.angley,z-self.anglez
            self.mixture.rotateDeg(x-self.anglex,y-self.angley,z-self.anglez)
            self.mixture.moveBy(center)
            self.anglex = x
            self.angley = y
            self.anglez = z

            self.history.currentState().getMixture().setChanged()
            self.viewer.update()
        else:
            self.tree.topLevelItem(1).setText(1, "0 x 0 x 0")

    def MoveBy(self):
        x = self.xMoveBy.value()
        y = self.yMoveBy.value()
        z = self.zMoveBy.value()

        value = str(x) + " x " + str(y) + " x " + str(z)
        self.tree.topLevelItem(2).setText(1, value)  
        self.mixture.moveBy([x-self.dx,y-self.dy,z-self.dz])
        self.dx = x
        self.dy = y
        self.dz = z
        self.history.currentState().getMixture().setChanged()
        self.viewer.update()

    def getId(self):
        return str(self.mixture.moleculeNames())
Ejemplo n.º 30
0
class CoordinateFile:
	def __init__(self, mixtureFile, fileType=None, psfFile=None, mixtureName=None):
		'''
		Prepares file for reading molecules.
		
		Raises MixtureError or whichever exception that pybel raises.
		'''
		if fileType == None:
			fileType = os.path.splitext(mixtureFile)[1][1:].strip()  # get filename extension
		if mixtureName == None:
			mixtureName = os.path.basename(mixtureFile)
			
		self.fileType = fileType
		self.fileName = mixtureFile
		self.mixtureName = mixtureName
		print("CoordinateFile ", fileType)

		if psfFile == None: self.psf = None
		else: self.psf = PSF(psfFile)
		
		self.__iter__()
		
	def __iter__(self):
		if self.fileType == "cc1":
			from . import cc1
			self.molIterator = cc1.readfile(self.fileName)
		else:
			self.molIterator = pybel.readfile(self.fileType, self.fileName)
		self.currentMolecule = None 
		self.firstMolecule = True
		return self


	def _processFirstFrame(self):
		"""
		Gets the first pybel Molecule and puts its Wolffia equivalent Mixture in self.currentMolecule.
		Returns the first frame.
		Raises whichever exception that pybel throws (probably StopIteration).
		"""
		
		mol = next(self.molIterator)
		chemicalGraphMixed = ChemicalGraph()
		etable			 = openbabel.OBElementTable()

		
		n = 0
		for atom in mol.atoms:
			atomType = atom.OBAtom.GetResidue().GetAtomID(atom.OBAtom)
			symbol = etable.GetSymbol(atom.atomicnum)
			coords = list(atom.coords)
			name	 = etable.GetName(atom.atomicnum) 
			residue = atom.OBAtom.GetResidue().GetName()
			psfType = atom.OBAtom.GetResidue().GetAtomID(atom.OBAtom).strip()
			#print "_processFirstFrame: '" + psfType + "'"
			charge = atom.partialcharge
			mass	 = atom.atomicmass	
			if self.psf != None:
				psfType = self.psf.getType(n)
				charge = self.psf.getCharge(n)
				mass	 = self.psf.getMass(n)
				print("CoordinateFile _processFirstFrame charge  ", charge)
		
		
			ai  = AtomInfo(atomType, symbol, psfType, charge, mass, 1, 1, 1, name, residue)
			atr = AtomAttributes(ai, coords, [])
			chemicalGraphMixed.add_node(n + 1, attrs=[atr])
			n += 1
		
		# add edges
		print('_processFirstFrame add edges')
		if self.psf != None:
			for b in self.psf.bonds:
				try:  # avoids adding an edge twice
					chemicalGraphMixed.add_edge(b)
				except AdditionError:
					pass			
			if len(mol.atoms) != len(self.psf.atoms):
				raise MixtureError("Amount of atoms in " + self.fileName + " and psf File files are different (" + str(len(self.atoms)) + " vs " + str(len(self.psf.atoms)) + ").")
		else:			
			for bond in openbabel.OBMolBondIter(mol.OBMol):   
				chemicalGraphMixed.add_edge([bond.GetBeginAtom().GetIdx(), bond.GetEndAtom().GetIdx()])	   
					
		molecules = list(chemicalGraphMixed.connectedComponents())
		self.currentMolecule = Mixture()
		
		#print '_processFirstFrame Añadir'+  str(list(molecules)) + ' moléculas a mezcla:  ', 
		if len(molecules) == 1:
			self.currentMolecule.add(Molecule(self.mixtureName, molecule=molecules[0]))
		else:
			n = 0
			for m in molecules:
				self.currentMolecule.add(
							Molecule(self.mixtureName + "(" + str(n) + ")", molecule=m),
							checkForInconsistentNames=False)
				n += 1

		return self.currentMolecule
	
	
	def _processNextFrame(self):
		"""
		Gets next pybel Molecule and puts its Wolffia equivalent Mixture in self.currentMolecule.
		Returns the next frame.
		Assumes that _processFirstFrame() has been called earlier.
		Raises whichever exception that pybel throws (probably StopIteration).
		"""
		self.currentMolecule = Mixture(self.currentMolecule)  # copy mixture
		mol = next(self.molIterator)
		print("_processNextFrame", mol)
		coordinates = []
		for atom in mol.atoms:
			coordinates.append(atom.coords)
		self.currentMolecule.updateCoordinatesFromArray(coordinates)
		return self.currentMolecule

		
	def __next__(self):
		"""
		Returns next frame if present.
		Raises whichever exception that pybel throws (probably StopIteration).
		"""
		if self.firstMolecule:
			self.firstMolecule = False
			return self._processFirstFrame()
		else: return self._processNextFrame()