def buildChainMenu(self,event=None):
     if not hasattr(self,'chainVar'): self.chainVar={}
     if not hasattr(self,'oldchainVar'): self.oldchainVar={}
     chMols = MoleculeSet([])
     if len(self.molSet):
         chMols=MoleculeSet(filter(lambda x: Chain in x.levels, self.molSet))
     chainIDList = []
     if len(chMols):
         chains=chMols.findType(Chain)
         if chains==None: return
         for i in chains:
             chainIDList.append(i.full_name())
     self.buildMenu(self.chainMB,chainIDList,self.chainVar,self.oldchainVar,self.getChainVal)
Esempio n. 2
0
 def buildChainMenu(self, event=None):
     if not hasattr(self, 'chainVar'): self.chainVar = {}
     if not hasattr(self, 'oldchainVar'): self.oldchainVar = {}
     chMols = MoleculeSet([])
     if len(self.molSet):
         chMols = MoleculeSet(
             filter(lambda x: Chain in x.levels, self.molSet))
     chainIDList = []
     if len(chMols):
         chains = chMols.findType(Chain)
         if chains == None: return
         for i in chains:
             chainIDList.append(i.full_name())
     self.buildMenu(self.chainMB, chainIDList, self.chainVar,
                    self.oldchainVar, self.getChainVal)
    def go(self):
        msgStr = None
        if self.moleculeSet:
            self.molSet = self.getMolecules(self.moleculeSet, self.selList[0])
        else:
            self.molSet = None
            return []
            # return [], msgStr

        # SPLIT here if mol.children==Atoms
        # possibly: self.Mols4levels=filter(lambda x: x.childrenSetClass == ChainSet, self.molSet)
        # then process the others separately....?????????
        # eg self.Mols2levels=filter(lambda x: x.childrenSetClass == AtomSet, self.molSet)
        # self.Mols2levels would get fed to self.getAtoms and two results ???merged???
        if not self.molSet:
            self.chainSet = None
            msgStr = str(self.selList[0]) + " selected no molecules"
            return []
            # return [], msgStr

        noChainMols = MoleculeSet(
            [x for x in self.molSet if Chain not in x.levels])
        haveChainMols = MoleculeSet(
            [x for x in self.molSet if Chain in x.levels])

        # build the residues belonging to molecules w/ no Chains (!WEIRD!)
        ncrs = ResidueSet()
        for item in noChainMols:
            if Residue in item.levels:
                itemRes = item.allAtoms.parent.uniq()
                ncrs = ncrs + itemRes

        if ncrs:
            noChainResSet = self.getResidues(ncrs, self.selList[2])
            if not noChainResSet: noChainResSet = ResidueSet()
        else:
            noChainResSet = ResidueSet()

        if len(haveChainMols):
            self.chainSet = self.getChains(haveChainMols.findType(Chain),
                                           self.selList[1])
        if self.chainSet:
            haveChainResSet = self.getResidues(self.chainSet.findType(Residue),
                                               self.selList[2])
            # also test noChainMols for residues
            if haveChainResSet:
                self.resSet = haveChainResSet + noChainResSet
            else:
                self.resSet = noChainResSet
        else:
            self.resSet = noChainResSet
            ##don't return unless selList[2]!==['']
            if self.selList[1] != ['']:
                msgStr = str(self.selList[1]) + " selected no chains"
                return []
                # return [], msgStr

        # now: if self.selList for Chain and Residue level was empty, get the Atoms from noChains
        if self.selList[1] == [''] and self.selList[2] == ['']:
            tla = AtomSet()
            for item in noChainMols:
                if Residue not in item.levels:
                    tla = tla + item.allAtoms
            twoLevelAtoms = tla
        else:
            twoLevelAtoms = AtomSet()
        if self.resSet:
            resAts = self.resSet.findType(Atom)
            if twoLevelAtoms: resAts = resAts + twoLevelAtoms
            self.atomSet = self.getAtoms(resAts, self.selList[3])
        else:
            if self.selList[2] != ['']:
                msgStr = str(self.selList[2]) + " selected no residues"
                return []
                # return [], msgStr
            else:
                self.atomSet = self.getAtoms(twoLevelAtoms, self.selList[3])

        selNodes = self.atomSet
        # find correct levelType to return
        # need to split atomSet into two parts:
        if self.atomSet:
            haveChainAtoms = AtomSet(
                [x for x in self.atomSet if x.top != x.parent])
            haveNoChainAtoms = self.atomSet - haveChainAtoms
            if self.selList[3] == ['']:
                # change atoms to residues
                if haveChainAtoms:
                    selNodes = haveChainAtoms.parent.uniq()
                else:
                    selNodes = ResidueSet()
                if self.selList[2] == ['']:
                    # change residues to chains
                    if len(selNodes):
                        selNodes = selNodes.parent.uniq()
                    if self.selList[1] == ['']:
                        # change chains to molecules
                        if haveNoChainAtoms:
                            noChainTops = haveNoChainAtoms.top.uniq()
                        else:
                            noChainTops = ProteinSet()
                        if selNodes:
                            selTops = selNodes.top.uniq()
                        else:
                            selTops = ProteinSet()
                        selNodes = selTops + noChainTops
                        if self.selList[0] == ['']:
                            # change molecules to molecules(?)in the case of no strs
                            if selNodes.__class__ != MoleculeSet:
                                selNodes = MoleculeSet(selNodes.top.uniq())
        else:
            msgStr = str(self.selList[3]) + " selected no atoms"
        for item in ['moleculeSet', 'molSet', 'chainSet', 'resSet', 'atomSet']:
            if hasattr(self, item):
                delattr(self, item)
        #                 exec('del self.'+item)
        return selNodes
    def go(self):
        msgStr = None
        if self.moleculeSet: 
            self.molSet = self.getMolecules(self.moleculeSet, self.selList[0])
        else: 
            self.molSet = None
            return []
            #return [], msgStr

        #SPLIT here if mol.children==Atoms
        #possibly: self.Mols4levels=filter(lambda x: x.childrenSetClass == ChainSet, self.molSet)
        #then process the others separately....?????????
        #eg self.Mols2levels=filter(lambda x: x.childrenSetClass == AtomSet, self.molSet)
        #self.Mols2levels would get fed to self.getAtoms and two results ???merged???
        if not self.molSet:
            self.chainSet = None
            msgStr = str(self.selList[0])+ " selected no molecules"
            return []
            #return [], msgStr

        noChainMols=MoleculeSet(filter(lambda x: Chain not in x.levels, self.molSet))
        haveChainMols=MoleculeSet(filter(lambda x: Chain in x.levels, self.molSet))

        #build the residues belonging to molecules w/ no Chains (!WEIRD!)
        ncrs=ResidueSet()
        for item in noChainMols:
            if Residue in item.levels:
                 itemRes=item.allAtoms.parent.uniq()
                 ncrs= ncrs + itemRes

        if ncrs:
            noChainResSet=self.getResidues(ncrs,self.selList[2]) 
            if not noChainResSet: noChainResSet=ResidueSet()
        else:
            noChainResSet=ResidueSet()

        if len(haveChainMols):
            self.chainSet = self.getChains(haveChainMols.findType(Chain), self.selList[1])
        if self.chainSet:
            haveChainResSet=self.getResidues(self.chainSet.findType(Residue), self.selList[2])
            #also test noChainMols for residues
            if haveChainResSet:
                self.resSet=haveChainResSet+noChainResSet
            else:
                self.resSet = noChainResSet
        else: 
            self.resSet = noChainResSet
            ##don't return unless selList[2]!==['']
            if self.selList[1]!=['']:
                msgStr = str(self.selList[1])+ " selected no chains"
                return []
                #return [], msgStr

        #now: if self.selList for Chain and Residue level was empty, get the Atoms from noChains
        if self.selList[1]==[''] and self.selList[2]==['']:
            tla=AtomSet()
            for item in noChainMols:
                if Residue not in item.levels:
                    tla=tla + item.allAtoms
            twoLevelAtoms = tla
        else:
            twoLevelAtoms=AtomSet()
        if self.resSet:
            resAts=self.resSet.findType(Atom)
            if twoLevelAtoms:resAts=resAts+twoLevelAtoms
            self.atomSet = self.getAtoms(resAts, self.selList[3])
        else: 
            if self.selList[2]!=['']:
                msgStr = str(self.selList[2])+ " selected no residues"
                return []
                #return [], msgStr
            else: self.atomSet = self.getAtoms(twoLevelAtoms, self.selList[3])

        selNodes = self.atomSet
        #find correct levelType to return
        #need to split atomSet into two parts:
        if self.atomSet:
            haveChainAtoms = AtomSet(filter(lambda x: x.top!=x.parent,self.atomSet))
            haveNoChainAtoms=self.atomSet-haveChainAtoms
            if self.selList[3]==['']:
                #change atoms to residues
                if haveChainAtoms: selNodes = haveChainAtoms.parent.uniq()
                else: selNodes=ResidueSet()
                if self.selList[2]==['']:
                    #change residues to chains
                    if len(selNodes): 
                        selNodes = selNodes.parent.uniq()
                    if self.selList[1]==['']:
                        #change chains to molecules
                        if haveNoChainAtoms: noChainTops=haveNoChainAtoms.top.uniq()
                        else: noChainTops=ProteinSet()
                        if selNodes: selTops= selNodes.top.uniq()
                        else: selTops=ProteinSet()
                        selNodes = selTops+noChainTops
                        if self.selList[0]==['']:
                            #change molecules to molecules(?)in the case of no strs
                            if selNodes.__class__!=MoleculeSet:
                                selNodes = MoleculeSet(selNodes.top.uniq())
        else:
            msgStr = str(self.selList[3])+ " selected no atoms"
        for item in ['moleculeSet','molSet','chainSet','resSet','atomSet']:
             if hasattr(self, item): 
                 delattr(self, item)
#                 exec('del self.'+item)
        return selNodes