コード例 #1
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")
コード例 #2
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)
コード例 #3
0
class ShownMoleculesSet(set):
    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

    def show(self, mol):
        #print "ShownMolecules show",mol
        self.add(mol)

    def showAll(self, mixture=None):
        if mixture != None: self.addMolecules(mixture)
        for mol in self.mixture:
            self.add(mol)

    def add(self, mol):
        super(ShownMoleculesSet, self).add(self.mixture.getMolecule(mol))

    def hide(self, mol):
        self.discard(mol)

    def remove(self, mol):
        #print "ShownMoleculesSet remove ",mol
        #try:
        if isinstance(mol, Molecule):
            super(ShownMoleculesSet, self).remove(mol)
        else:
            super(ShownMoleculesSet,
                  self).remove(self.mixture.getMolecule(mol))
        #except:
        #pass

    def discard(self, mol):
        super(ShownMoleculesSet, self).discard(self.mixture.getMolecule(mol))

    '''
    def discardFrom(self, molIDSet):
        molset = set([ self.mixture.getMolecule(m) for m in molIDSet])
        super(ShownMoleculesSet, self).difference(set(molSet))
    '''

    def duplicate(self, mol):
        pass

    def __deepcopy__(self, memo):
        '''
        Blocks deepcopy because it takes too long.  Copy done manually in push()
        '''
        pass

    def isShown(self, mol):
        #print "isShown ", mol, mol in self.keys(), self[mol]
        try:
            return self.mixture.getMolecule(mol) in self
        except:
            return False

    def shownList(self, mixture):
        print("WARNING: ShownMoleculesSet deprecated.")
        return list(self)

    def addMolecules(self, mixture):
        for mol in mixture:
            self.add(mol)

    def addDictionary(self, shDict):
        '''
        Adds information from a ShownMolecules object.
        '''
        for mol in shDict:
            if shDict[mol]: self.add(mol)

    def updateMixture(self, mixture):
        self.intersection_update(
            set([self.mixture.getMolecule(mol) for mol in mixture]))
        self.mixture = mixture

    def names(self):
        return [self.mixture.getMoleculeID(molecule) for molecule in self]
コード例 #4
0
class Load(QtGui.QDialog):
    def __init__(self, parent=None, dropedPdb=None):
        super(Load, self).__init__(parent, modal = 1)
        
        print("Load dropedPdb=", dropedPdb)
        #Dialog settings
        self.uiLoad         = Ui_Load()
        self.uiLoad.setupUi(self)
        self.history = History()
        self.isAdded = False
        self.history.currentState().reset()
        
        #Viewer
        print("Load setting viewer")
        self.previewArea    = MixtureViewer(self.history, self, None)
        self.previewArea.showHelp(False)
        self.uiLoad.moleculeViewerLayout.addWidget(self.previewArea)
        
        #Mixture
        print("Load setting getting mixture")
        self.myMixture      = self.history.currentState().getMixture()
        self.mixAndRows     = list()
        
        #Table Settings
        self.loadTable      = self.uiLoad.tableWidget
        self.loadTableRows  = 0
        self.equalMolecules = []
        self.saveCheckBox   = None
        
        #Information Button Settings
        self.uiLoad.hint.setFlat(True)
        self.uiLoad.hint.setIcon(QtGui.QIcon().fromTheme("dialog-information", QtGui.QIcon(str(NANOCAD_BASE+"\\interface\\graphics\\") +"dialog-information.png")))    
        self.uiLoad.connectDataBaseButton.setFlat(True)
        self.uiLoad.connectDataBaseButton.setIcon(QtGui.QIcon().fromTheme("network-server", QtGui.QIcon(str(NANOCAD_BASE+"\\interface\\graphics\\") +"dialog-information.png")))    

        #PDB droped from MixtureViewer
        print("Load setting pdbDirectory")
        self.pdbDirectory = dropedPdb
        if self.pdbDirectory != None:
            print("Load setting self.pdbDirectory != None")
            self.uiLoad.lineEdit_1.setText(self.pdbDirectory)
            print("Load animateClick")
            self.uiLoad.loadButton.animateClick()
        print("Load end")
        
    def update(self):
        self.previewArea.update()
        return
        mix = Mixture()
        for i in range(self.loadTable.rowCount()):
            #for j in range(3,6):
            ##print "Load update", self.loadTable.item(i,5).text(),self.loadTable.cellWidget(i,1).show
            if self.loadTable.cellWidget(i,1).show:
                mix.add(self.myMixture.getMolecule(str(self.loadTable.item(i,5).text())))
        self.previewArea.setMixture(mix)
#-------------------------------------- Methods ------------------------------------
#loadPsfOrNot(): Asks the user if wants to change all the names of the molecules that are the same 

    def loadPsfOrNot(self,filename):
        
        msg = QtGui.QMessageBox.question(self, 'Loading Fi\les...',
         'Would you like to load the psf file associated with: '+filename+'?\n'+'\n NO, will imply to only read the pdb file.', 
         QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        
        return msg == QtGui.QMessageBox.Yes

#-------------------------------------- 
#changeNameOrNotMessage(): Asks the user if wants to change all the names of the molecules that are the same 

    def changeNameOrNotMessage(self):
        
        msg = QtGui.QMessageBox.question(self, 'Change all Names...',
         'Would you like to change all the names of the molecules with that color?', 
         QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        
        return msg == QtGui.QMessageBox.Yes


#--------------------------------------
#getLineEditInfo(): Gets the paths and constructs the Mixture
    def getLineEditInfo(self):
    
        # Gets paths
        path_1 = str(self.uiLoad.lineEdit_1.displayText())
        print("Load getLineEditInfo",path_1)
        self.uiLoad.lineEdit_1.clear()
        path_2 = str(self.uiLoad.lineEdit_2.displayText())
        print("Load getLineEditInfo",path_2)
        self.uiLoad.lineEdit_2.clear()
        print("Load getLineEditInfo loadInfo")
        self.loadInfo(path_1, path_2)
        print("Load getLineEditInfo end")
 
#--------------------------------------
    def loadInfo(self,path_1='',path_2= ''):       
        if path_1 != '' and path_2 == '':
            try:
                self.history.currentState().getMixture().load(path_1)
            except:
                QtGui.QMessageBox.warning(self,"Error 1 !!!","There is a problem loading the file " + path_1 + " in box 1.")
                print(sys.exc_info())
        elif not(path_2 == '') and path_1 == '':
            try:
                self.history.currentState().getMixture().load(path_2)
            except:
                QtGui.QMessageBox.warning(self,"Error 2 !!!","There is a problem loading the file " + path_2 + " in box 2.")
        elif not(path_1 == '') and not(path_2 == ''):
            if (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'pdb' and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'psf':
                try: 
                    self.history.currentState().getMixture().load(path_1,path_2)
                except Exception as e:
                    QtGui.QMessageBox.warning(self,"Error 3 !!!","There is a problem with the file."+str(e))
            elif (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'psf' and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'pdb':
                try:
                    self.history.currentState().getMixture().load(path_2,path_1)
                except Exception as e:
                    QtGui.QMessageBox.warning(self,"Error 4 !!!","There is a problem with the file."+str(e))
            else:QtGui.QMessageBox.warning(self,"Error 5 !!!","There is a problem with the file.")  
            
        elif not(path_1 == '') and (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'pdb':
            filePath = None
            
            #Search if the *.psf file associated with the *.pdb file exists in the same folder
            for f in os.listdir(os.path.dirname(path_1)) :
                path1 = os.path.basename(path_1)
                if f == path1[0:len(path1)-2]+'s'+'f':
                    filePath = os.path.dirname(path_1)+'/'+f
                    #print "filePath",filePath
                    
            if not(filePath == None):
                if self.loadPsfOrNot(f):
                    try:
                        self.history.currentState().getMixture().load(path_1,filePath)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 6 !!!","There is a problem with the file.")
                else:
                    try:
                        self.history.currentState().getMixture().load(path_1,None)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 7 !!!","There is a problem with the file.")
            else:
                try:
                    self.history.currentState().getMixture().load(path_1,None)
                except:
                    QtGui.QMessageBox.warning(self,"Error 8 !!!","There is a problem with the file.")
                
                            
        elif not(path_1 == '') and (path_1[len(path_1)-3]+path_1[len(path_1)-2]+path_1[len(path_1)-1]) == 'psf':
            for f in os.listdir(os.path.dirname(path_1)) :
                path1 = os.path.basename(path_1)
                if f == path1[0:len(path1)-2]+'d'+'b':
                    filePath = os.path.dirname(path_1)+'/'+f
                    try:
                        self.history.currentState().getMixture().load(filePath,path_1)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 9 !!!","There is a problem with the file.")

        elif path_1 == '' and not(path_2 == '') and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'pdb':
            filePath = None
            for f in os.listdir(os.path.dirname(path_2)) :
                path2 = os.path.basename(path_2)
                if f == path2[0:len(path2)-2]+'s'+'f':
                    filePath = os.path.dirname(path_2)+'/'+f
            if not(filePath == None):
                if self.loadPsfOrNot(f):
                    try:
                        self.history.currentState().getMixture().load(path_2,filePath)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 10 !!!","There is a problem with the file.")
                else:
                    try:
                        self.history.currentState().getMixture().load(path_2,None)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 11 !!!","There is a problem with the file.")
            else:
                try:
                        self.history.currentState().getMixture().load(path_2,None)
                except:
                    QtGui.QMessageBox.warning(self,"Error 12 !!!","There is a problem with the file.")                            
                            
        elif path_1 == '' and not(path_2 == '') and (path_2[len(path_2)-3]+path_2[len(path_2)-2]+path_2[len(path_2)-1]) == 'psf':
            for f in os.listdir(os.path.dirname(path_2)) :
                path2 = os.path.basename(path_2)
                if f == path2[0:len(path2)-2]+'d'+'b':
                    filePath = os.path.dirname(path_2)+'/'+f
                    try:
                        self.history.currentState().getMixture().load(filePath,path_2)
                    except:
                        QtGui.QMessageBox.warning(self,"Error 13 !!!","There is a problem with the file.")
                        
        else:QtGui.QMessageBox.warning(self,"Error 14 !!!","There is a problem with the file.**")
           
        #This is how we can obtain the atoms...
        #for m in self.history.currentState().getMixture().nodes():
            #print "@Load:mixture",self.history.currentState().getMixture().getMolecule(m).nodes()
        #print "myMixture",self.myMixture.order()
                
 
#--------------------------------------
#addCheckBox(): Adds a CheckBox into the column's cell to select the molecules that would be loaded


    def addCheckBox(self,row,name):
    
        #---CheckBox---
    
        self.saveCheckBox = CheckBox(self,row,self.loadTable)
        self.saveCheckBox.setObjectName(str(name+str(row)))
        
        self.saveCheckBox.setCheckState(QtCore.Qt.Checked)
        self.saveCheckBox.setFixedSize(25,25)
            
        #---Cell---
        self.loadTable.setCellWidget(row,0,self.saveCheckBox)

#--------------------------------------
#addButtonintoCell(): Adds a button into the column's cell to preview the molecules


    def addButtonintoCell(self,row,name):
        self.viewToolButton = PreviewButton(self.history.currentState(),
                                        self.previewArea,parent=self.loadTable, molname=str(name),
                                        initState=True)
                                        #initState=self.history.currentState().shownMolecules.isShown(str(name)))
        
        self.history.currentState().shownMolecules.show(str(name))
        #QtCore.QObject.connect(self.viewToolButton, QtCore.SIGNAL('clicked()'), self.on_viewToolButton_clicked())
        #self.viewToolButton.clicked.connect(self.on_viewToolButton_clicked)
        self.viewToolButton.setObjectName(str(name))
        self.viewToolButton.setFixedSize(25,25)
        
        #---Cell---
        self.loadTable.setCellWidget(row,1,self.viewToolButton)

    #--------------------------------------
    #showHideAllMessage(): Asks the user if wants to show/hide all the molecules painted with the same color  

    def loadMessage(self):

        msg = QtGui.QMessageBox.information(self, 'Information...',
        'This may take a while. Please be patient ... ', 
        QtGui.QMessageBox.Ok)
    #--------------------------------------
    #showHideAllMessage(): Asks the user if wants to show/hide all the molecules painted with the same color  

    def showHideAllMessage(self):

        msg = QtGui.QMessageBox.question(self, 'Show or Hide...',
        'Would you like to show/hide all the molecules with that color?', 
        QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        
        
        return msg == QtGui.QMessageBox.Yes 
 

#--------------------------------------
#reviewIsomorphisms(): Verify graph's isomorphism between two graphs
    
    def reviewIsomorphisms(self):
        tempList            = []
        theColors           = []
        self.equalMolecules = []
        row                 = -1
        
        for c in range(0,self.myMixture.order()):
            color = createColors()
            theColors.append(color)
        
        
        #Check equal molecules    
        remainingMols      =  list(self.myMixture)
        
        for each in self.myMixture:
            row        = row + 1
            searchList = list(remainingMols)
        
            for theMol in searchList:
                if self.myMixture.getMolecule(each) == self.myMixture.getMolecule(theMol):
                    tempList.append(theMol)
                    remainingMols.remove(theMol)
                
            if len(tempList) > 0:
                self.equalMolecules.append([tempList, None])
            tempList   = []
        
        #creating colors    
        for c in range(0,len(self.equalMolecules)):
            color = createColors()
            self.equalMolecules[c][1] = color
            #for molecule in self.equalMolecules[c][0]:
                #self.myMixture.getMolecule(molecule).rename(molecule + str(c))
        
                

#************************************************
#addSelectAllCheckBox(): Create a checkBox to select all the molecules in the table

    def addSelectAllCheckBox(self):    
        self.selectAllCheckBox = QtGui.QCheckBox()
        self.deSelectAll       = True
        font                   = QtGui.QFont()
        font.setPointSize(9)
        self.selectAllCheckBox.setFont(font)
        self.selectAllCheckBox.setText(QtGui.QApplication.translate("Load", "Select All", None, QtGui.QApplication.UnicodeUTF8))
        self.selectAllCheckBox.setObjectName("selectAllCheckBox")
        self.selectAllCheckBox.setCheckState(QtCore.Qt.Checked)
        self.selectAllCheckBox.setTristate(on = False)
        self.uiLoad.SelectAllLayout.addWidget(self.selectAllCheckBox)
        self.connect(self.selectAllCheckBox, QtCore.SIGNAL('stateChanged(int)'), self.checkBoxState)
  
    def checkBoxState(self, value):
        if self.selectAllCheckBox.checkState() == QtCore.Qt.Checked:
            for row in range(0,self.loadTableRows):
                self.loadTable.cellWidget(row,0).setCheckState(QtCore.Qt.Checked)
        
        elif self.selectAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.deSelectAll == True:
            for row in range(0,self.loadTableRows):
                self.loadTable.cellWidget(row,0).setCheckState(QtCore.Qt.Unchecked)
        elif self.selectAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.deSelectAll == False:
            self.deSelectAll         = True 

#************************************************
#addSelectAllCheckBox(): Create a checkBox to select all the molecules in the table

    def addShowHideAllCheckBox(self):    
        self.showHideAllCheckBox = QtGui.QCheckBox()
        #print "Entre aqui"
        self.showAll       = True
        font                   = QtGui.QFont()
        font.setPointSize(9)
        self.showHideAllCheckBox.setFont(font)
        self.showHideAllCheckBox.setText(QtGui.QApplication.translate("Load", "Show All", None, QtGui.QApplication.UnicodeUTF8))
        self.showHideAllCheckBox.setObjectName("showHideAllCheckBox")
        self.showHideAllCheckBox.setCheckState(QtCore.Qt.Checked)
        self.showHideAllCheckBox.setTristate(on = False)
        self.uiLoad.ShowAllLayout.addWidget(self.showHideAllCheckBox)
        self.connect(self.showHideAllCheckBox, QtCore.SIGNAL('stateChanged(int)'), self.showHideAllState)
  
    def showHideAllState(self, value):
        if self.showHideAllCheckBox.checkState() == QtCore.Qt.Checked:
            for row in range(0,self.loadTableRows):
                self.loadTable.cellWidget(row,1).setShown()
                #self.loadTable.cellWidget(row,1).click()
        elif self.showHideAllCheckBox.checkState() == QtCore.Qt.Unchecked and self.showAll == True:
            for row in range(0,self.loadTableRows):
                self.loadTable.cellWidget(row,1).setHidden()
        elif  self.showHideAllCheckBox.checkState() == QtCore.Qt.Unchecked  and self.showAll == False:
            self.showAll         = True
   
#*************************************************
#setTable(): Creates and show the table

    def setTable(self):
        
        self.reviewIsomorphisms()
        
        #creates rows and columns
        self.loadTable.setColumnCount(6)
        self.loadTableRows = self.myMixture._len()
        self.loadTable.setRowCount(self.loadTableRows)
        
        
        item = QtGui.QTableWidgetItem()
        self.loadTable.setHorizontalHeaderItem(0, item)
        self.loadTable.horizontalHeaderItem(0).setText(QtGui.QApplication.translate("Load", "Save", None, QtGui.QApplication.UnicodeUTF8))
        
        item = QtGui.QTableWidgetItem()
        self.loadTable.setHorizontalHeaderItem(1, item)
        self.loadTable.horizontalHeaderItem(1).setText(QtGui.QApplication.translate("Load", "Prev", None, QtGui.QApplication.UnicodeUTF8))
        
        item = QtGui.QTableWidgetItem()
        self.loadTable.setHorizontalHeaderItem(2, item)
        self.loadTable.horizontalHeaderItem(2).setText(QtGui.QApplication.translate("Load", "Molecule Name", None, QtGui.QApplication.UnicodeUTF8))
        
        item = QtGui.QTableWidgetItem()
        self.loadTable.setHorizontalHeaderItem(3, item)
        self.loadTable.horizontalHeaderItem(3).setText(QtGui.QApplication.translate("Load", "No. of Atoms", None, QtGui.QApplication.UnicodeUTF8))
        
        item = QtGui.QTableWidgetItem()
        item.setTextAlignment(0x0001)
        self.loadTable.setHorizontalHeaderItem(4, item)
        self.loadTable.horizontalHeaderItem(4).setText(QtGui.QApplication.translate("Load", "Atoms Found", None, QtGui.QApplication.UnicodeUTF8))
        
        item = QtGui.QTableWidgetItem()
        self.loadTable.setHorizontalHeaderItem(5, item)
        self.loadTable.horizontalHeaderItem(5).setText(QtGui.QApplication.translate("Load", "Atom_ID", None, QtGui.QApplication.UnicodeUTF8))
        
        row = 0
        temp =[]
        
        #Adding the molecule information into the rows
        for eqCassInd in range(len(self.equalMolecules)):
            for molName in self.equalMolecules[eqCassInd][0]:                               
                for column in range(0,6):
                    item = QtGui.QTableWidgetItem()
                    self.loadTable.setItem(row, column, item)
            
                    if column == 0:
                        self.addCheckBox(row,molName)
                        self.loadTable.resizeColumnToContents(column)
                        
                    elif column == 1:
                        self.addButtonintoCell(row,molName)
                        self.loadTable.resizeColumnToContents(column)
                        temp.append(molName)
                        temp.append(row)
                        self.mixAndRows.append(temp)
                        temp = []
            
                    elif column == 2:
                        newTableWidgetItem = myTableWidgetItem(self, self.myMixture.getMolecule(molName)._name, molName)
                        newTableWidgetItem.setBackgroundColor(self.equalMolecules[eqCassInd][1])
                        self.loadTable.setItem(row,column,newTableWidgetItem)
                        self.loadTable.resizeColumnToContents(column)
            
                    elif column == 3:
                        newitem = myTableWidgetItem(self,str(self.myMixture.getMolecule(molName).order()))
                        newitem.setFlags(QtCore.Qt.ItemIsEnabled)
                        self.loadTable.setItem(row, column, newitem)
                        self.loadTable.resizeColumnToContents(column)
                    
                    elif column == 4:                    
                        molecule = self.myMixture.getMolecule(molName)
                        newitem = myTableWidgetItem(self,str(molecule.getElements()))
                        newitem.setFlags(QtCore.Qt.ItemIsEnabled)
                        self.loadTable.setItem(row, column, newitem)
                        self.loadTable.resizeColumnToContents(column)
                    
                    elif column == 5:                    
                        newitem = QtGui.QTableWidgetItem(str(molName))
                        newitem.setFlags(QtCore.Qt.ItemIsEnabled)
                        self.loadTable.setItem(row, column, newitem)
                        self.loadTable.resizeColumnToContents(column)                                      
                row += 1
        self.update()       

#---------------- Dialog's signals -------------------
    def on_Browse_1_pressed(self):
        d = WFileDialog(self, 'Browse File','','')
        if d.accepted():
            filename = d.fullFilename()
            if not os.path.exists(str(filename)):
                QtGui.QMessageBox.information(self, "Wolffia's message", "Did not find file " + filename + ". File not loaded.", QtGui.QMessageBox.Ok)
                return
            self.uiLoad.lineEdit_1.setText(str(d.fullFilename()))
            
    def on_Browse_2_pressed(self):
        d = WFileDialog(self, 'Browse File','','')
        if d.accepted():
            filename = d.fullFilename()
            if not os.path.exists(str(filename)):
                QtGui.QMessageBox.information(self, "Wolffia's message", "Did not find file " + filename + ". File not loaded.", QtGui.QMessageBox.Ok)
                return
            self.uiLoad.lineEdit_2.setText(str(d.fullFilename()))
            
    def on_hint_pressed(self):
        from .AboutLoad import AboutLoad
        about = AboutLoad(self)
        about.show()
        about.exec_()
            
    def on_connectDataBaseButton_pressed(self):
        #print"on_connectDataBaseButton_pressed"
        
        from .ImportMolecules import ImportMolecules
        
        importMoleculeDialog = ImportMolecules()
        importMoleculeDialog.show()
        importMoleculeDialog.exec_()
        
        #print "PDB \n",importMoleculeDialog.getFileType()
        if importMoleculeDialog.proceed():
            try:
                #print importMoleculeDialog.getMoleculeFile()
                self.history.currentState().getMixture().load(None,None,importMoleculeDialog.getMoleculeFile(),importMoleculeDialog.getFileType(),importMoleculeDialog.inputName())
            except Exception as err:
            	#print "Load on_connectDataBaseButton_pressed: There is a problem with the file ", importMoleculeDialog.getMoleculeFile()
                QtGui.QMessageBox.warning(self,"Error 15 !!!","There is a problem with the file."+ err)
            
            self.loadTable.clear()
            self.loadTableRows = 0
            self.mixAndRows    = []
            self.setTable()
        
            if self.uiLoad.SelectAllLayout.isEmpty() and self.uiLoad.ShowAllLayout.isEmpty():
                self.addSelectAllCheckBox()
                self.addShowHideAllCheckBox()
            
            self.previewArea.setMixture(self.history.currentState().getMixture())    

    def on_cancelButton_pressed(self):
        #print "Load: Cancel Button: history",self.history.currentState()
        self.close()

    def on_loadButton_pressed(self,dropedPdb=None):
    	print("Load on_loadButton_pressed",dropedPdb)
        if dropedPdb == None:
            print("Load on_loadButton_pressed getLineEditInfo")
            self.getLineEditInfo()           
        print("Load on_loadButton_pressed loadTable.clear")
        self.loadTable.clear()
        self.loadTableRows = 0
        self.mixAndRows    = []
        print("Load on_loadButton_pressed setTable")
        self.setTable()
    
        if self.uiLoad.SelectAllLayout.isEmpty():
            self.addSelectAllCheckBox()
            self.addShowHideAllCheckBox()
        print("Load on_loadButton_pressed previewArea.setMixture")
        self.previewArea.setMixture(self.history.currentState().getMixture())    
        print("Load on_loadButton_pressed end")

    def on_okButton_pressed(self):
        if self.myMixture._len() == 0:
            msg = QtGui.QMessageBox.warning(self, 'Warning',
            'No molecule has been loaded!',QtGui.QMessageBox.Ok)
                
        else:
            progressMax   = self.myMixture._len()
            progressCount = 0
            progress      = QtGui.QProgressDialog("Loading mixture...", "Abort", 0, progressMax, self,QtCore.Qt.Dialog|QtCore.Qt.WindowTitleHint)
            progress.setWindowModality(QtCore.Qt.WindowModal)        
               
            for row in range(0,self.myMixture._len()):
                if progress.wasCanceled():
                    progress.hide()
                    self.history.currentState().reset()  
                    self.myMixture      = self.history.currentState().getMixture()           
                    self.update()
                    self.close()
                    return
                else:
                    #Delete unchecked molecules 
                    if (self.loadTable.cellWidget(row,0).checkState()) == QtCore.Qt.Unchecked: 
                        self.myMixture.remove(str(self.loadTable.item(row,5).text()))
                    #Add remaining molecules to the state
                progressCount += 1
                progress.setValue(progressCount)  
            self.isAdded = True
            self.close()

    def closeEvent(self, e):
        if not self.isAdded:
            self.myMixture = Mixture()

                            
    def getMixture(self):  return self.myMixture

#------------- Table's signals ---------
    def on_tableWidget_itemChanged(self, wi):
        
        if isinstance(wi, myTableWidgetItem) and wi.name != "(no name)" and wi.isSelected():
            self.loadTable.setItemSelected (wi, False)
            multipleMolecules = False
            
            for row in range(0,self.loadTable.rowCount()):
                if not(self.loadTable.currentRow() == row) \
                and self.loadTable.item(self.loadTable.currentRow(),2).backgroundColor() == self.loadTable.item(row,2).backgroundColor():
                    multipleMolecules = True
                    break
            if multipleMolecules and self.changeNameOrNotMessage():
                # changes names of all isomorphic molecules
                selColor = wi.backgroundColor()
                for eqClass in range(0,len(self.equalMolecules)):
                    if selColor == self.equalMolecules[eqClass][1]:
                        for mol in self.equalMolecules[eqClass][0]:
                            self.myMixture.getMolecule(mol)._name = str(wi.text())
                self.setTable()                                    
            else:
                mol = self.myMixture.getMolecule(wi.name)
                mol._name = str(wi.text())

    #--------------------------------------
    #on_viewToolButton_clicked(): When a viewToolButton is clicked, the user can show/hide all the molecules painted with the same color  
    def on_viewToolButton_clicked(self):
        #print "_mySignal"
        value = self.viewToolButton.show
        #print "@WWidget _mySignal value",value
        multipleMolecules = False
        #print "self.loaded.rowCount()",self.loadTable.rowCount()
        for row in range(0,self.loadTable.rowCount()):
            if not(self.viewToolButton.row == row) and self.loadTable.item(self.viewToolButton.row,2).backgroundColor() == self.loadTable.item(row,2).backgroundColor():
                multipleMolecules = True
                #print "multipleMolecules = True"
                break
        
        if isinstance(self, PreviewButton) and multipleMolecules and self.showHideAllMessage() :
            selColor = self.loadTable.item(self.viewToolButton.row,2).backgroundColor()

            for row in range(0,self.loadTable.rowCount()):
                if selColor == self.loadTable.item(row,2).backgroundColor():
                    if value == True:
                        self.loadTable.cellWidget(row,1).setShown()
                    else:
                        self.loadTable.cellWidget(row,1).setHidden()
                        self.loadTable.showAll = False
                        self.loadTable.showHideAllCheckBox.setCheckState(QtCore.Qt.Unchecked)
                        
        else:
            if value == False: 
                self.loadTable.showAll = False
                self.loadTable.showHideAllCheckBox.setCheckState(QtCore.Qt.Unchecked)
コード例 #5
0
class NanoCADState(object):
    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)
        #print "NanoCADState__init__", self.forceFieldStorage.keys()

    #-------------------------- methods ------------------------------------
    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()
        #print "NanoCADState reset"

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

    def save(self, filename=None, fileObject=None):

        if fileObject != None:
            f = fileObject
            f.seek(0)
            pickle.dump(self.__dict__, f)
        else:
            if filename == None:
                #filename = WOLFFIA_DEFAULT_MIXTURE_LOCATION + "/" + WOLFFIA_DEFAULT_MIXTURE_NAME + ".wfy"
                filename = self.getBuildDirectory(
                ) + "/" + self.getMixtureName() + ".wfy"

            #print "History.save_ importing cPickle"
            #print "History.save_ imported cPickle, starting to save"
            #print "History.save_ self.getBuildDirectory(), self.getMixtureName() ", self.getBuildDirectory(), self.getMixtureName()
            try:
                f = open(filename, "w")
            except IOError:
                print(filename + ": File does not exist.")
            pickle.dump(self.__dict__, f)
            f.close()

        #print "NanoCADState.save, save sucessful", f.name

    #--------------------------------------------------------------------------------
    def writeFiles(self, filename=None):
        from chemicalGraph.io.PRM import PRMError
        if filename == None:
            filename = self.getBuildDirectory() + "/" + self.getMixtureName()
        #print "NanoCADState writeFiles,", filename

        try:
            self.getMixture().writeFiles(filename,
                                         self.fixedMolecules.fixedList())
        except:
            raise

    #--------------------------------------------------------------------------------
    def packFiles(self, mixBaseFilename, filename, progressSignal=None):
        import zipfile

        if progressSignal != None: progressSignal.emit(0)

        self.writeFiles(filename=mixBaseFilename)
        if progressSignal != None: progressSignal.emit(50)

        self.save(
        )  # .wfy  saved because it may have changed w/r to the one when the MixtureBrowser was created

        # .coor, .vel and .conf files preserve configuration of last run

        #print "NanoCADState packFiles ", mixBaseFilename, filename
        file1 = zipfile.ZipFile(filename, "w")
        if progressSignal != None: progressSignal.emit(60)
        #mixBaseFilename = str(self.settings.currentMixtureLocation()) + "/" + self.history.currentState().getMixtureName()
        #mixBaseFilename = str(self.getBuildDirectory()) + "/" + self.getMixtureName()
        #print "packFiles mixname", mixBaseFilename

        #for name in glob.glob(str(self.settings.currentMixtureLocation()) + "/*"):
        #	file1.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
        extensionsNotPacked = ""
        extensionsToPack = [
            ".prm", ".pdb", ".psf", ".wfy", ".conf", ".coor", ".vel", ".xsc"
        ]
        progress = 60
        for ext in extensionsToPack:
            #if progress.wasCanceled(): break
            confFilename = mixBaseFilename + ext
            if not os.path.isfile(confFilename):
                #print "packFiles confFilename NotPacked",confFilename
                extensionsNotPacked += " " + ext
            else:
                file1.write(confFilename, os.path.basename(confFilename),
                            zipfile.ZIP_DEFLATED)
            progress += 5
            if progressSignal != None: progressSignal.emit(progress)

        file1.close()
        return extensionsNotPacked

    #--------------------------------------------------------------------
    def load(self, filename=None):
        import pickle as pickle  #Tremenda aportación por carlos cortés
        #import inspect
        #print "NanoCADState.load, caller1=",inspect.stack()[1]
        #print "NanoCADState.load, caller2=",inspect.stack()[2]
        #print "NanoCADState.load, caller3=",inspect.stack()[3]
        if filename == None:
            filename = WOLFFIA_DEFAULT_MIXTURE_LOCATION + "/" + WOLFFIA_DEFAULT_MIXTURE_NAME + ".wfy"

        logger = logging.getLogger(self.__class__.__name__)

        if hasattr(filename, 'read'):  # new in v 1.132
            logger.info("Loading state from " + str(filename.name))
            filename.seek(0)
            self.__dict__ = pickle.load(filename)
            f = filename
        else:
            logger.info("Loading state from " + str(filename))
            if not os.path.exists(filename):
                self.reset()
                self.save(filename)
                return
            #print "History.load_ importing cPickle"
            #print "History.load_ imported cPickle, starting to load"

            try:
                f = open(filename, "r")
                self.__dict__ = pickle.load(f)
                f.close()
            except Exception as e:
                import traceback
                traceback.print_exc()
                #print "NanoCADState.load_ Exeption ", e, " when unpickling file."
                from PyQt5 import QtGui
                gui = QtWidgets.QErrorMessage.qtHandler()
                QtWidgets.QErrorMessage.showMessage(
                    gui, "Error: could not open configuration file " +
                    filename + ".")
                logger.warning("Error: could not open configuration file " +
                               filename + ".")

        if not hasattr(self, "fixedMolecules"):  # introduced in v 0.24
            self.fixedMolecules = FixedMolecules()
        if self.wolffiaVerion < "0.24-4":
            self.simTabValues["pmeGridSp"] = 1.0

        logger.info("Loaded mixture from version " + self.wolffiaVerion +
                    ". Current version is " + WOLFFIA_VERSION)

        if self.wolffiaVerion < "0.24-42":
            #if True:
            #print "YES, mixture=",self.getMixture().molecules()
            for mol in self.getMixture():
                #print "load ", self.getMixture().getMolecule(mol).getForceField()._NONBONDED
                molecule = self.getMixture().getMolecule(mol)
                self.getMixture().getMolecule(mol).copyChargesToForceField()
                self.wolffiaVerion = "0.24-42"
                #print "load ", self.getMixture().getMolecule(mol).getForceField()._NONBONDED
        #else: print "NO"

        if self.wolffiaVerion < "0.24-43":
            temp = ShownMoleculesSet(self.getMixture())
            temp.addDictionary(self.shownMolecules)
            del self.shownMolecules
            self.shownMolecules = temp

        if self.wolffiaVerion < "0.24-44":
            #print "History.load_ fixing self bonds"
            for m in self.mixture:  #remove bonds to self
                molecule = self.mixture.getMolecule(m)
                for atom in molecule:
                    if molecule.has_edge(atom, atom):
                        molecule.remove_edge(atom, atom)

            #print "History.load_  self bonds removed"

        # trick for backward compatibility
        for mol in self.getMixture():
            molecule = self.getMixture().getMolecule(mol)
            #print "load inspecting ",molecule.__class__
            if str(molecule.__class__)[-10:] == "Molecule\'>":
                molecule.__class__ = Molecule
                #print "molecule class changed", molecule.__class__

        if self.wolffiaVerion < "1.13":  # until further versions
            # self.mixture.mixName should be the same as
            # self.parent.settings.currentMixtureName.
            print(
                "History.load_ self.mixture.mixName should be the same as self.parent.settings.currentMixtureName"
            )
            try:
                self.mixture.setMixtureName(
                    self.parent.settings.currentMixtureName)
            except:
                pass

        if self.wolffiaVerion < "1.131":  # fix for 1.13 did not work.
            # self.parent.settings.currentMixtureName is being
            # eliminated in this version.
            print(
                "History.load_ self.mixture.mixName should be the same as self.parent.settings.currentMixtureName"
            )
            try:
                self.parent.settings.setMixtureLocation(
                    self.parent.settings.currentMixtureName)
                del self.parent.settings.currentMixtureName
            except:
                pass

        # other fixes ===========================
        if self.shownMolecules == None:
            self.shownMolecules = ShownMoleculesSet(self.getMixture())
        # end other fixes ===========================

        if self.wolffiaVerion < "1.31":
            self.getMixture().upgrade(self.wolffiaVerion)

        #from PyQt5 import QtGui
        if self.wolffiaVerion < WOLFFIA_VERSION:
            #QtGui.QMessageBox.information(self.parent,"Wolffia", "Simulation version updated from "+str(self.wolffiaVerion)+" to "+str(WOLFFIA_VERSION))
            print("NANOCADState.load: Simulation version updated from " +
                  str(self.wolffiaVerion) + " to " + str(WOLFFIA_VERSION))
        self.wolffiaVerion = WOLFFIA_VERSION
        print("NanoCADState.load_ imported cPickle, load sucessful", f.name)
        #print "History.load self.shownMolecules", self.shownMolecules
        #self.shownMolecules.showAll()

    #--------------------------------------------------------------------
    # If progress != None, it is an object that responds to he folowing methods:
    #   .setLabelText("Removing collisions")
    #   .setRange(0,molNum)
    #   .setValue(0)

    def fillBox(self,
                solv,
                molNum,
                checkCollisions=False,
                replaceCollisions=False,
                applyPCBs=True,
                progress=None):
        import math, random
        import numpy as np
        from lib.chemicalGraph.molecule.solvent.Solvent import Solvent

        solventMolecules = Solvent(solv)  #.__class__)

        remaining = -1  # to track removng collissions

        totalDim = self.getDrawer().getBoxDimension()
        boxmin = self.getDrawer().getCellOrigin()
        boxmax = [
            boxmin[0] + totalDim[0], boxmin[1] + totalDim[1],
            boxmin[2] + totalDim[2]
        ]

        #calculate the volume for a single solvent molecule
        center = [0., 0., 0.]
        pos = solv.massCenter()
        solv.moveBy(
            [center[0] - pos[0], center[1] - pos[1], center[2] - pos[2]])
        #solvDiameter = solv.diameter()+ _SEPARATION_BETWEEN_SOLVENTS_
        solvDiameter = math.pow(self.getDrawer().getBoxVolume() / molNum,
                                1. / 3.)
        if solvDiameter == 0: return

        row = math.floor(totalDim[1] / solvDiameter)
        col = math.floor(totalDim[0] / solvDiameter)
        dep = math.floor(totalDim[2] / solvDiameter)

        progressMax = molNum
        progressCount = 0
        if progress != None:
            progress.setLabelText("Adding solvent")
            progress.setRange(0, molNum - 1)
            progress.setValue(0)

        solvRadius = solvDiameter / 2
        newPos = solv.massCenter()
        refCoor = boxmin

        #boxmax[0] -= solvDiameter/2.
        #boxmax[1] -= solvDiameter/2.
        #boxmax[2] -= solvDiameter/2.

        if progress != None:
            progress.setLabelText("Adding solvent")
            progress.setRange(progressCount, progressMax)
            progress.setValue(progressCount)

        # lopps over a sequence of adding solvent and removing collisions
        originalMolecules = self.getMixture().molecules()
        originalCoords = self.getMixture().getAtomsCoordinatesAsArray()
        solvRadius = solvDiameter / 2.0 + 1.5

        #print "anadiendo... ", progressMax-progressCount
        while progressCount < progressMax:  # adds solvent
            #random rotation for solvent atoms
            rx = random.uniform(0, 360)
            ry = random.uniform(0, 360)
            rz = random.uniform(0, 360)

            #random displacement for solvent atoms
            rdx = random.uniform(boxmin[0], boxmax[0])
            rdy = random.uniform(boxmin[1], boxmax[1])
            rdz = random.uniform(boxmin[2], boxmax[2])

            #generate new molecule and assign next position
            mol = solv.copy()
            mol.rotateDeg(rx, ry, rz)
            newPos = np.array([[rdx, rdy, rdz]])

            if checkCollisions:
                atomDistances = euclidean_distances(originalCoords, newPos)
                if np.min(atomDistances) > solvRadius:
                    #print 'fillBox: añadiendo', progressCount, np.min(atomDistances), newPos
                    mol.moveBy(list(newPos)[0])
                    #nodeName = self.addMolecule(mol, checkForInconsistentNames=False)
                    #self.shownMolecules.show(nodeName)
                    solventMolecules.addCoordinates(mol)
                else:
                    #print 'fillBox: colision'
                    if replaceCollisions: progressCount -= 1

            progressCount += 1
            if progress != None: progress.setValue(progressCount)
            del mol

        # add solvent and rename with the given name
        nodeName = self.addMolecule(solventMolecules,
                                    checkForInconsistentNames=True)
        self.shownMolecules.show(nodeName)
        #print "fillBox ", mol.molname(),progressMax
        solv.rename(solventMolecules.molname())
        progressMax -= 1

        #print "tiempo ", time.clock() - start
        #print "Molecules after cleaning: ",mix.order()

    def fillBoxBAK(self,
                   solv,
                   molNum,
                   checkCollisions=False,
                   replaceCollisions=False,
                   applyPCBs=True,
                   progress=None):
        import math, random
        remaining = -1  # to track removng collissions

        totalDim = self.getDrawer().getBoxDimension()
        boxmin = self.getDrawer().getCellOrigin()
        boxmax = [
            boxmin[0] + totalDim[0], boxmin[1] + totalDim[1],
            boxmin[2] + totalDim[2]
        ]

        #calculate the volume for a single solvent molecule
        center = [0., 0., 0.]
        pos = solv.massCenter()
        solv.moveBy(
            [center[0] - pos[0], center[1] - pos[1], center[2] - pos[2]])
        #solvDiameter = solv.diameter()+ _SEPARATION_BETWEEN_SOLVENTS_
        solvDiameter = math.pow(self.getDrawer().getBoxVolume() / molNum,
                                1. / 3.)
        if solvDiameter == 0: return

        row = math.floor(totalDim[1] / solvDiameter)
        col = math.floor(totalDim[0] / solvDiameter)
        dep = math.floor(totalDim[2] / solvDiameter)

        progressMax = molNum
        progressCount = 0
        if progress != None:
            progress.setLabelText("Adding solvent")
            progress.setRange(0, molNum - 1)
            progress.setValue(0)

        solvRadius = solvDiameter / 2
        newPos = solv.massCenter()
        refCoor = boxmin

        boxmax[0] -= solvDiameter / 2.
        boxmax[1] -= solvDiameter / 2.
        boxmax[2] -= solvDiameter / 2.

        # add first molecule and rename solvent with the given name
        mol = solv.copy()
        mol.moveBy([
            random.uniform(boxmin[0], boxmax[0]),
            random.uniform(boxmin[1], boxmax[1]),
            random.uniform(boxmin[2], boxmax[2])
        ])
        nodeName = self.addMolecule(mol, checkForInconsistentNames=True)
        self.shownMolecules.show(nodeName)
        #print "fillBox ", mol.molname(),progressMax
        solv.rename(mol.molname())
        progressMax -= 1

        if progress != None:
            progress.setLabelText("Adding solvent")
            progress.setRange(progressCount, progressMax)
            progress.setValue(progressCount)

        # lopps over a sequence of adding solvent and removing collisions
        while progressCount < progressMax:

            originalMolecules = self.getMixture().molecules()

            #print "anadiendo... ", progressMax-progressCount
            while progressCount < progressMax:  # adds solvent
                #random rotation for solvent atoms
                rx = random.uniform(0, 360)
                ry = random.uniform(0, 360)
                rz = random.uniform(0, 360)

                #random displacement for solvent atoms
                rdx = random.uniform(boxmin[0], boxmax[0])
                rdy = random.uniform(boxmin[1], boxmax[1])
                rdz = random.uniform(boxmin[2], boxmax[2])

                #generate new molecule and assign next position
                mol = solv.copy()
                mol.rotateDeg(rx, ry, rz)
                newPos = [rdx, rdy, rdz]
                mol.moveBy(newPos)
                #mol.rename("SOLVENT("+mol.molname()+")")
                nodeName = self.addMolecule(mol,
                                            checkForInconsistentNames=False)
                self.shownMolecules.show(nodeName)

                progressCount += 1
                if progress != None: progress.setValue(progressCount)

            # remove collisions
            if checkCollisions:
                if progress != None:
                    progress.setLabelText("Removing collisions")

                mix = self.getMixture()
                collisions = mix.overlapingMolecules(originalMolecules,
                                                     pbc=self.getDrawer(),
                                                     applyPBCs=applyPCBs)

                toRemove = set(collisions).difference(set(originalMolecules))
                if remaining < 0: remaining = len(toRemove)
                #print "remaining", remaining
                #print "removiendo... ", len(toRemove)
                #print "faltan... ", remaining-len(toRemove)
                if progress != None:
                    progress.setRange(0, remaining)
                    progress.setValue(remaining - len(toRemove))
                self.removeMoleculesFrom(toRemove)

                if replaceCollisions: progressCount -= len(toRemove)

        #print "tiempo ", time.clock() - start
        #print "Molecules after cleaning: ",mix.order()

    def getMixture(self):
        return self.mixture

    def getDrawer(self):
        return self.drawer

    def name(self):
        return self.mixture.mixName

    def getMixtureName(self):
        return self.mixture.mixName

    def getBuildDirectory(self):
        #return self.buildDir  # no longer used
        try:
            return self.workingDir
        except:
            self.workingDir = WOLFFIA_DEFAULT_MIXTURE_LOCATION + "/"
            return self.workingDir

    def getCurrentDirectory(self):
        return self.getBuildDirectory()

    def getSimTabValues(self):
        return self.simTabValues

    def updateMixture(self, mix):
        #self.setChanged()
        self.mixture = mix
        self.shownMolecules.updateMixture(self.mixture)
        self.fixedMolecules.updateMixture(self.mixture)
        #for mol in self.mixture:
        #    print "mix @t NanoCADState",self.mixture.getMolecule(mol)._name

    def addMixture(self, mix):
        #print "History addMixture",mix
        #self.mixture.merge(mix)
        for mol in mix:
            self.addMolecule(mix.getMolecule(mol))

    def addMolecule(self, mol, checkForInconsistentNames=True):
        print("NanoCADState addMolecule", mol)
        molname = self.mixture.add(mol, checkForInconsistentNames)
        self.shownMolecules.show(molname)
        return molname

    def removeMolecule(self, mol):
        #import inspect
        #print "NanoCADState.removeMolecule, caller=",inspect.stack()[1]
        #self.forceFieldStorage    =    None

        self.shownMolecules.remove(mol)
        self.getMixture().remove(mol)

    def removeMoleculesFrom(self, mols):
        self.getMixture().removeFrom(mols)
        self.updateMixture(self.getMixture())
        #self.getMixture().removeFrom(mols)

    def duplicateMolecule(self, mol):
        newName = self.getMixture().duplicateMolecule(mol)
        self.shownMolecules.show(newName)

    def setMixtureName(self, n):
        self.mixture.mixName = n

    def setDrawer(self, dr):
        self.drawer = dr

    def setBuildDirectory(self, d):
        #print "buildDirectory changed to, " , d
        #self.buildDir = d  # no longer used
        self.workingDir = d

    def setCurrentDirectory(self, d):
        self.workingDir = d

    def setSimTabValues(self, simVals):
        self.simTabValues = simVals.copy()

    def hasBox(self):
        return self.drawer != None and self.drawer.hasCell()