Exemplo n.º 1
0
 def getObjects(self, column):
     # return a list of objects associated with this node and possibly
     # other seleted nodes.  For selection we return a list for each type
     # ( i.e. Atom, Residue, etc..)
     # if the node is selected, collect object from all other selected nodes
     resultAtoms = AtomSet([])
     resultResidues = ResidueSet([])
     resultChains = ChainSet([])
     resultMolecules = MoleculeSet([])
     buttonValue = self.chkbtVar[column].get()
     if self.selected:
         for node in self.tree.list_selected:
             node.chkbtVar[column].set(buttonValue)
             result = node.getNodes(column)
             obj = result[0]
             if isinstance(obj, Atom):
                 resultAtoms += result
             elif isinstance(obj, Residue):
                 resultResidues += result
             elif isinstance(obj, Chain):
                 resultChains += result
             elif isinstance(obj, Molecule) or isinstance(obj, Protein):
                 resultMolecules += result
         result = []
         if len(resultAtoms): result.append(resultAtoms)
         if len(resultResidues): result.append(resultResidues)
         if len(resultChains): result.append(resultChains)
         if len(resultMolecules): result.append(resultMolecules)
         return result
     else:
         return [self.getNodes(column)]
Exemplo n.º 2
0
    def doit(self, Klass, KlassSet=None):
        if type(Klass) == types.StringType:
            if Klass in self.levelDict.keys():
                Klass = self.levelDict[Klass]
            else:
                msg = Klass + "string does not map to a valid level"
                self.warningMsg(msg)
                return "ERROR"
        if Klass is Protein:
            Klass = Molecule

        if len(self.vf.selection):
            self.vf.selection = self.vf.selection.findType(Klass).uniq()
        else:
            if Klass == Molecule: self.vf.selection = MoleculeSet([])
            elif Klass == Chain: self.vf.selection = ChainSet([])
            elif Klass == Residue: self.vf.selection = ResidueSet([])
            elif Klass == Atom: self.vf.selection = AtomSet([])

        self.vf.selectionLevel = Klass
        self.vf.ICmdCaller.setLevel(Klass, KlassSet=None)
        if self.vf.hasGui:
            col = self.vf.ICmdCaller.levelColors[Klass.__name__]
            c = (col[0] / 1.5, col[1] / 1.5, col[2] / 1.5)
            self.vf.GUI.pickLabel.configure(background=TkColor(c))
            msg = '%d %s(s)' % (len(
                self.vf.selection), self.vf.selectionLevel.__name__)
            self.vf.GUI.pickLabel.configure(text=msg)
            if hasattr(self.vf, 'select'):
                self.vf.select.updateSelectionIcons()
            self.levelVar.set(self.vf.selectionLevel.__name__)
def buildPdb(map_dict,
             npts,
             name='DlgBuilt',
             ctr=0,
             outputfile='results.pdb',
             scale=1.0):
    if debug: print "in buildPdb: tolerance=", tolerance
    name = 'DlgBuilt'
    mol = Protein(name=name)
    mol.curChain = Chain()
    mol.chains = ChainSet([mol.curChain])
    mol.curRes = Residue()
    mol.curChain.adopt(mol.curRes)
    mol.allAtoms = AtomSet()
    mol.curRes.atoms = mol.allAtoms
    nzpts = nypts = nxpts = npts
    #nxpts, nypts, nzpts = npts
    ctr = 0
    for ADtype, m in map_dict.items():
        if debug:
            print "PROCESSING ", ADtype, " array:", max(m.ravel()), ':', min(
                m.ravel())
        vals = []
        tctr = 0  #for number of each type
        for z in range(nzpts):
            for y in range(nypts):
                for x in range(nxpts):
                    val = scale * abs(m[x, y, z])
                    vals.append(val)
                    #if abs(val)>.005:
                    if val > tolerance * scale:
                        ctr += 1
                        name = ADtype + str(ctr)
                        #version3:
                        #info_lo = (xcen - numxcells*spacing,
                        #    ycen - numycells*spacing,
                        #    zcen - numzcells *spacing)
                        #using lower back pt of cube, i think
                        #xcoord = (x-info_lo[0])/spacing
                        #ycoord = (y-info_lo[1])/spacing
                        #zcoord = (z-info_lo[2])/spacing
                        #version2:
                        xcoord = (x - numxcells) * spacing + xcen
                        ycoord = (y - numycells) * spacing + ycen
                        zcoord = (z - numzcells) * spacing + zcen
                        coords = (xcoord, ycoord, zcoord)
                        tctr += 1
                        #    #print "addAtom: name=",name,"ADtype=", ADtype," val=", val, "coords=", coords,"ctr=", ctr
                        addAtom(mol, name, ADtype, val, coords, ctr)
        print "added ", tctr, '<-', ADtype, " atoms"
        if debug:
            print ADtype, ':', tctr, ' ', ctr
    print "total atoms=", ctr
    writer = PdbWriter()
    writer.write(outputfile, mol.allAtoms, records=['ATOM'])
Exemplo n.º 4
0
 def test_select_intersect_chains_empty(self):
     """
     test selecting with stringRepr of empty intersected chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols1.chains & self.mols2.chains
     selString = diff_chains.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, ChainSet())
     self.assertEquals(selString, "stringSel:/&/protease:")
Exemplo n.º 5
0
 def getChainRelIndex(self, item, nodes):
     try:
         number = int(item)
     except:
         msgStr = str(item) + " is invalid relative index"
         # self.vf.warningMsg(msgStr)
         return None
     # indices start w/ 1:
     parentNodes = nodes[0].parent.setClass(nodes.parent.uniq())
     l = []
     for item in parentNodes:
         if len(item.children) >= number:
             l.append(item.children[number - 1])
     return ChainSet(l)
Exemplo n.º 6
0
    def select(self,
               nodes,
               selectionString,
               sets=None,
               caseSensitive=True,
               escapeCharacters=False):
        # print "in select with selectionString=", selectionString
        overallresults = None
        overallmsg = ""
        overall_class = None
        # eg: stringSel:A:PRO1:N;stringSel:B:PRO1:CA;
        if len(selectionString) and selectionString[-1] == ';':
            selectionString = selectionString[:-1]
        # eg: stringSel:A:PRO1:N;stringSel:B:PRO1:CA
        ## mol1;mol2;mol3:::
        allSelectionStrings = selectionString.split(';')
        # print "allSelectionStrings=", allSelectionStrings
        all_tops = nodes.top.uniq()
        final_str_repr = ""  # keep track of string to assign at end
        for selString in allSelectionStrings:
            # print "processing selString=", selString
            lambda_index = selString.find('lambda ')
            if lambda_index == -1:
                setsStrings = selString.split(':')
            else:
                # split repair possible splits of lambda expressions
                # ":::lambda x:x.top.name=='ind'"
                # lambda_index = 3
                setsStrings = selString[:lambda_index].split(':')
                # setsStrings = ['','','','']
                # replace the last one with join of split on lambda ':'
                lambda_exp_list = selString[lambda_index:].split(':')
                lambda_exp = lambda_exp_list[0] + ':' + lambda_exp_list[1]
                setsStrings[-1] = lambda_exp
                if len(lambda_exp_list) > 2:
                    # there may be trailing stuff
                    setsStrings.extend(lambda_exp_list[2:])
                # setsStrings = selString.split(':')
            # print "setsStrings=", setsStrings
            len_setsStrings = len(setsStrings)
            results = all_tops
            msg = ''
            for i in range(len_setsStrings):
                # print "setsStrings[",i,"]=", setsStrings[i]
                if i == 0 and len_setsStrings == 1 and setsStrings[i] == '':
                    # special case of empty selection string
                    final_str_repr = ''
                    for m in all_tops:
                        final_str_repr += m.name + ','
                        final_str_repr = final_str_repr[:-1]
                elif setsStrings[i] != '':
                    # print "in elif loop"
                    these_sets = None
                    if sets is not None:
                        these_sets = sets.get(stype=results.__class__)
                    results, msgList = results.get(
                        setsStrings[i],
                        sets=these_sets,
                        caseSensitive=caseSensitive,
                        escapeCharacters=escapeCharacters,
                        returnMsg=True)
                    # print "results=", results, "msgList=", msgList
                    for m in msgList:
                        setsStrings[i].replace(m, '')
                        msg = msg + str(m)
                    if len(results) == 0:
                        # print "no results with ", setsStrings[i]
                        overallresults = None
                        break
                # check whether the rest of the setsStrings are empty, if so
                final_str_repr += setsStrings[i] + ':'
                results.stringRepr = final_str_repr
                if i < len(setsStrings) - 1:
                    results = results.children
            final_str_repr = final_str_repr[:-1]
            results.stringRepr = final_str_repr
            if len(results):
                if overallresults is None:
                    overallresults = results
                    overall_class = results.__class__
                    overallmsg = msg
                else:
                    # levels are the same
                    if overall_class == results.__class__:
                        overallresults = overallresults + results
                        # does this happen automatically?
                        overallmsg = overallmsg + msg
                    else:
                        print("ERROR")
                        print("overall_class->", overall_class)
                        print("results.__class__->", results.__class__)
                        print("results=", results)
                        raise RuntimeError
                if selString != allSelectionStrings[-1]:
                    final_str_repr += ';'
                    final_str_repr.replace("/+/", ';')
                else:
                    overallresults.stringRepr = final_str_repr

        if overallresults is None:
            overallmsg = selectionString
            if len(setsStrings) == 1:
                overallresults = ProteinSet()
            elif len(setsStrings) == 2:
                overallresults = ChainSet()
            elif len(setsStrings) == 3:
                overallresults = ResidueSet()
            else:
                overallresults = AtomSet()

        return overallresults, overallmsg