Example #1
0
def loadBR(pdb, saveName=None, color=None):
    if not saveName:
        saveName = pdb.split('.')[0]
   
    cmd.load(pdb, saveName)

    if color: cmd.color(color, saveName)
    cmd.hide("lines")
    cmd.hide("nonbonded")
#     cmd.show("cartoon")
    cmd.show("ribbon")

    cmd.set("cartoon_transparency", 0.7)
    keyResidues = ["ASPA0085", "ARGA0082", "GLUA0194", "GLUA0204", "LYSA0216", "RET", "ASPA0212"]
    for eachRes in keyResidues:
        # retinal's residue sequence id can vary in different pdbs.
        selection = ""
        if eachRes == "RET":
            selection = "resn ret"
        else:
            selection = parseResidue(eachRes)
        
        selection += " and not name c+o+n"
        cmd.show("sticks", selection)
        util.cbag(selection)
Example #2
0
    def DisplayLigand(self):
        
        try:
            cmd.set("auto_zoom", 0)
            
            cmd.load(self.RefLigand, self.LigDisplay, state=self.State)
            cmd.refresh()
            
            # Display the atoms spheres
            cmd.show('spheres', self.LigDisplay)
            cmd.refresh()

            cmd.alter(self.LigDisplay,'vdw=0.25')
            cmd.rebuild(self.LigDisplay)
            cmd.refresh()

            util.cbag(self.LigDisplay)
            cmd.refresh()

            cmd.translate(self.Translation,self.LigDisplay)
            cmd.refresh()

            cmd.zoom(self.LigDisplay)
            cmd.refresh()
            
        except:
            self.ErrorCode = 1

        cmd.set("auto_zoom", self.auto_zoom)
        
        return self.ErrorCode
Example #3
0
    def RefreshDisplay(self):
        
        try:
            # Display the atoms spheres
            cmd.show('spheres', self.LigDisplay)
            cmd.refresh()

            cmd.alter(self.LigDisplay,'vdw=0.25')
            cmd.rebuild(self.LigDisplay)
            cmd.refresh()

            util.cbag(self.LigDisplay)
            cmd.refresh()
            
            if self.AnchorAtom != -1:
                AtomSel = self.LigDisplay + ' & id ' + str(self.AnchorAtom)
                cmd.color('white',AtomSel)
                cmd.refresh()

                cmd.alter(AtomSel ,'vdw=0.30')
                cmd.rebuild(AtomSel)
                cmd.refresh()
                        
        except:
            self.ErrorCode = 1

        return self.ErrorCode
Example #4
0
    def RefreshDisplay(self):

        try:
            # Display the atoms spheres
            cmd.show('spheres', self.LigDisplay)
            cmd.refresh()

            cmd.alter(self.LigDisplay, 'vdw=0.25')
            cmd.rebuild(self.LigDisplay)
            cmd.refresh()

            util.cbag(self.LigDisplay)
            cmd.refresh()

            if self.AnchorAtom != -1:
                AtomSel = self.LigDisplay + ' & id ' + str(self.AnchorAtom)
                cmd.color('white', AtomSel)
                cmd.refresh()

                cmd.alter(AtomSel, 'vdw=0.30')
                cmd.rebuild(AtomSel)
                cmd.refresh()

        except:
            self.ErrorCode = 1

        return self.ErrorCode
def show_ligand_interactions(recsel="not hetatm", ligsel="hetatm", cutoff=5):
    """
DESCRIPTION

    Visualize interactions between receptor and ligand.

ARGUMENTS

    recsel = string: atom selection of the receptor {default: "not hetatm"}

    ligsel = string: atom selections of the ligand {default: "hetatm"}

    cutoff = float: show as sticks all receptor residues within this distance from the ligand {default: 5.0}
    """
    cmd.select('ligand', ligsel)
    cmd.select('receptor', recsel)
    cmd.bg_color('white')
    cmd.show_as('cartoon')
    cmd.show_as('sticks', 'hetatm')
    cmd.set('cartoon_transparency', 0.2)
    cmd.spectrum(selection=recsel+" or "+ligsel,byres=1)
    util.cbag('not elem C')
    cmd.set('cartoon_fancy_helices', 1);
    cmd.show("sticks", "(hydro)");
    cmd.select("pocket", "byres (receptor within %s of ligand)" % cutoff);
    cmd.show("sticks", "pocket")
    cmd.hide('(h. and (e. c extend 1))')
    cmd.set('h_bond_max_angle', 30)
    cmd.set('h_bond_cutoff_center', 3.6)
    cmd.set('h_bond_cutoff_edge', 3.2)
    cmd.dist('ligand_Hbonds', 'ligand', 'receptor', 3.5, mode=2)
    cmd.set('dash_radius', 0.15)
    # now set the label options
    cmd.set('label_size', 20)
    cmd.set('label_position', [0,0,10])
Example #6
0
 def clear(self):
     self.cmd.unmask("all")
     self.cmd.deprotect("all")
     self.cmd.sculpt_deactivate("all")
     if self.status == HAVE_SELECTIONS:
         util.cbag("(byobj %s)" % cent_sele, _self=self.cmd)
         self.cmd.flag("exclude", "(byobj %s)" % cent_sele, "clear")
     self.status = NO_SELECTIONS
     self.cmd.delete(sele_pre + "*")
     self.cmd.refresh_wizard()
Example #7
0
 def clear(self):
     self.cmd.unmask("all")
     self.cmd.deprotect("all")
     self.cmd.sculpt_deactivate("all")
     if self.status == HAVE_SELECTIONS:
         util.cbag("(byobj %s)"%cent_sele, _self=self.cmd)
         self.cmd.flag("exclude","(byobj %s)"%cent_sele,"clear")
     self.status = NO_SELECTIONS
     self.cmd.delete(sele_pre+"*")
     self.cmd.refresh_wizard()
Example #8
0
def atomcolor():
  """
  atom coloring
  """

  cmd.bg_color( "white" )
  cmd.hide( "ev" )
  cmd.show( "sticks", "not elem H" )
  cmd.show( "lines", "elem H" )
  util.cbag()
  cmd.color( "white", "elem C" )
Example #9
0
def atomcolor():
    """
  atom coloring
  """

    cmd.bg_color("white")
    cmd.hide("ev")
    cmd.show("sticks", "not elem H")
    cmd.show("lines", "elem H")
    util.cbag()
    cmd.color("white", "elem C")
Example #10
0
 def update_selections(self):
     if self.status == HAVE_SELECTIONS:
         if self.mode == 'by_resi':
             self.cmd.select(
                 free_sele, "((byobj %s) and byres ((%s) x; %8.3f))" %
                 (cent_sele, cent_sele, self.radius))
             self.cmd.select(
                 fix_sele,
                 "((byobj %s) and (not %s) and byres ((%s) x; %8.3f))" %
                 (cent_sele, free_sele, cent_sele,
                  self.radius + self.cushion))
             self.cmd.select(
                 excl_sele, "((byobj %s) and (not (%s|%s)))" %
                 (cent_sele, free_sele, fix_sele))
         elif self.mode == 'ligand_rx':
             self.cmd.select(
                 free_sele,
                 "((byobj %s) and byres (%s))" % (cent_sele, cent_sele))
             self.cmd.select(
                 fix_sele,
                 "((byobj %s) and (not %s) and byres ((%s) x; %8.3f))" %
                 (cent_sele, free_sele, free_sele, self.cushion))
             self.cmd.select(
                 excl_sele, "((byobj %s) and (not (%s|%s)))" %
                 (cent_sele, free_sele, fix_sele))
         self.cmd.protect("(byobj %s)" % cent_sele)
         self.cmd.deprotect(free_sele)
         self.cmd.flag('exclude', "(byobj %s)" % cent_sele, "clear")
         self.cmd.flag('exclude', excl_sele, "set")
         self.cmd.color('grey', excl_sele)
         self.cmd.unmask("(byobj %s)" % cent_sele)
         self.cmd.mask(excl_sele)
         self.cmd.mask(fix_sele)
         self.cmd.zoom(free_sele, 3, animate=1)
         util.cbac(fix_sele, _self=self.cmd)
         util.cbag(free_sele, _self=self.cmd)
         self.cmd.disable('indicate')
         self.cmd.disable(cent_sele)
         self.cmd.disable(free_sele)
         self.cmd.disable(fix_sele)
         self.cmd.disable(excl_sele)
         self.cmd.unpick()
         for obj in self.cmd.get_names(selection=cent_sele):
             self.cmd.push_undo(obj)
             self.cmd.sculpt_activate(obj)
Example #11
0
    def DisplayLigand(self):
        
        try:
            cmd.load(self.pdbPath, self.LigDisplay, state=self.State)

            # Display the atoms spheres
            cmd.show('spheres', self.LigDisplay)
            cmd.alter(self.LigDisplay,'vdw=0.25')
            cmd.rebuild(self.LigDisplay)
        
            util.cbag(self.LigDisplay)
            cmd.translate(self.Translation,self.LigDisplay)
            cmd.zoom(self.LigDisplay)

        except:
            return 1

        return 0
Example #12
0
 def update_selections(self):
     if self.status == HAVE_SELECTIONS:
         if self.mode=='by_resi':
             self.cmd.select(free_sele,"((byobj %s) and byres ((%s) x; %8.3f))"%
                           (cent_sele,cent_sele,self.radius))
             self.cmd.select(fix_sele,"((byobj %s) and (not %s) and byres ((%s) x; %8.3f))"%
                           (cent_sele,free_sele,cent_sele,self.radius+self.cushion))
             self.cmd.select(excl_sele,"((byobj %s) and (not (%s|%s)))"%
                           (cent_sele,free_sele,fix_sele))
         elif self.mode=='ligand_rx':
             self.cmd.select(free_sele,"((byobj %s) and byres (%s))"%
                           (cent_sele,cent_sele))
             self.cmd.select(fix_sele,"((byobj %s) and (not %s) and byres ((%s) x; %8.3f))"%
                           (cent_sele,free_sele,free_sele,self.cushion))
             self.cmd.select(excl_sele,"((byobj %s) and (not (%s|%s)))"%
                           (cent_sele,free_sele,fix_sele))
         self.cmd.protect("(byobj %s)"%cent_sele)
         self.cmd.deprotect(free_sele)
         self.cmd.flag('exclude',"(byobj %s)"%cent_sele,"clear")
         self.cmd.flag('exclude',excl_sele,"set")
         self.cmd.color('grey',excl_sele)
         self.cmd.unmask("(byobj %s)"%cent_sele)
         self.cmd.mask(excl_sele)
         self.cmd.mask(fix_sele)
         self.cmd.zoom(free_sele,3,animate=1)
         util.cbac(fix_sele,_self=self.cmd)
         util.cbag(free_sele,_self=self.cmd)
         self.cmd.disable('indicate')
         self.cmd.disable(cent_sele)            
         self.cmd.disable(free_sele)
         self.cmd.disable(fix_sele)
         self.cmd.disable(excl_sele)
         self.cmd.unpick()
         for obj in self.cmd.get_names(selection=cent_sele):
             self.cmd.push_undo(obj)
             self.cmd.sculpt_activate(obj)
Example #13
0
def showhbnet(hbFile="hb.txt"):
    
    
    g = loadHbNet(hbFile)
            
    cmd.set("sphere_transparency", 0.7)
    cmd.set("line_width", 0.5)
    
    for eachRes in g.nodes():
        # only show the residues in the network that have connection with the key residues.
        if not isShowing(g, eachRes): continue
        resName = eachRes[:3]
        chainId = eachRes[3]
        resSeq = int(eachRes[4:])
        
        # the schiff's base is specail, it's a combination of Lys216 and the retinal.
        if eachRes == "RSBA0216":
            selection = "(r. lys and c. a and i. 216) or (r. ret)"
            cmd.show("lines", selection)
            cmd.label("r. lys and c. a and i. 216 and name ca", '"RSB"')
            util.cbag(selection)
            continue
        
        
        selection = "(r. %s and c. %c and i. %d)" % (resName, chainId, resSeq)
        if resName == "HOH":
            cmd.show("spheres", selection)
            cmd.set("sphere_scale", 0.15)
            cmd.label(selection, "chain+resi")
        else:
            cmd.show("lines", selection)
            cmd.label(selection+" and name ca", "resn+resi")
            util.cbag(selection)
    
    # hide all the hydrogens.        
    cmd.hide("everything", "h.")
Example #14
0
 def on_pdbentry_pressed(self):
     pdb = self.pdbloc.getvalue()
     if self.check_exist(pdb) == Pmw.OK:
         cmd.load(pdb, 'original', format='pdb', quiet=0)
         util.cbag()
         self.pmobj.append('original')
fragments = ['x2910', 'x3080', 'x3303']
for fragment in fragments:
    cmd.load(path + f'Mpro-{fragment}_0A_bound-ligand.mol2',
             f'quinolones-{fragment}-ligand')
    cmd.load(path + f'Mpro-{fragment}_0A_bound-protein.pdb',
             f'quinolones-{fragment}-protein')
util.cbam(f'quinolones-*')

# Aim 3 : benzotriazoles (green)
fragments = ['x10820', 'x10871', 'x10876']
for fragment in fragments:
    cmd.load(path + f'Mpro-{fragment}_0A_bound-ligand.mol2',
             f'benzotriazoles-{fragment}-ligand')
    cmd.load(path + f'Mpro-{fragment}_0A_bound-protein.pdb',
             f'benzotriazoles-{fragment}-protein')
util.cbag(f'benzotriazoles-*')

# N3 ligand (white)
cmd.load('6lu7.pdb')
cmd.align('(6lu7 and chain A)', 'aminopyridines-x10237-protein')
cmd.select('N3-ligand', '6lu7 and chain C')
cmd.select('N3-protein', '6lu7 and (chain A or chain B)')
util.cbaw('N3-ligand')

# All fragments
show_fragments = False
if show_fragments:
    files = glob(f'{path}/Mpro-x*.mol2')
    for filename in files:
        print(filename)
        match = re.search('Mpro-(?P<fragment>x\d+)_', filename)
Example #16
0
File: m4x.py Project: Almad/pymol
def setup_contexts(context_info):   # Author: Warren DeLano
    (list,dict) = context_info[0:2]
    key_list = [
        'F1','F2','F3','F4','F5','F6','F7','F8','F9','F10', #,'F11','F12',
        'SHFT-F1','SHFT-F2','SHFT-F3','SHFT-F4','SHFT-F5','SHFT-F6','SHFT-F7',
        'SHFT-F8','SHFT-F9','SHFT-F10']# ,'SHFT-F11','SHFT-F12']
    doc_list = ["Keys"]
    zoom_context = 1
    global labels
    labels = 1
    if len(key_list):
        key = key_list.pop(0)
        cmd.set_key(key,toggle_labels)
        doc_list.append(key+": Toggle Dist")        
    if len(key_list):
        key = key_list.pop(0)
        cmd.set_key(key,lambda :(cmd.zoom(),toggle_labels(0)))
        doc_list.append(key+": Zoom All")
    
    for a in list:
        water = a+"_water"
        ligand = a+"_ligand"
        site = a+"_site"
        hbond = a+"_hbond"
        name_list = dict[a]
        zoom_list = []
        if water in name_list:
            cmd.show("nonbonded",water)
            util.cbac(water)
            zoom_list.append(water)
        if ligand in name_list:
            cmd.show("sticks",ligand)
            cmd.hide("cartoon",ligand)
            util.cbag(ligand)
            zoom_list.append(ligand)
        if site in name_list:
            cmd.show("sticks",site)
            util.cbac(site)
            zoom_list.append(site)
            # replace cartoon with explicit atoms for "site" atoms
            cmd.hide("cartoon",site)
            cmd.show("sticks","(byres (neighbor ("+site+" and name c))) and name n+ca")
            cmd.show("sticks","(byres (neighbor ("+site+" and name n))) and name c+ca+o")
        if len(zoom_list):
            if len(key_list):
                key = key_list.pop(0)
                zoom_str = string.join(zoom_list,' or ')
                if zoom_context == 1:
                    zoom_context = zoom_str
                elif zoom_context not in (0,1):
                    zoom_context = 0
                cmd.set_key(key,lambda x=zoom_str:(cmd.zoom(x)))
                mo = re.search("_([^_]+)$",a)
                if mo:
                    cont_name = mo.groups()[0]
                else:
                    cont_name = a
                doc_list.append(key+": Zoom "+cont_name)
                
        if hbond in name_list:
            cmd.show("dashes",hbond)
            cmd.show("labels",hbond)

        
    cmd.wizard("fedora",doc_list)
    if zoom_context not in (0,1):
        cmd.zoom(zoom_context)
    toggle_labels(0)
#    cmd.feedback("enable","python","output")
    cmd.feedback("enable","objectmolecule","results")
    cmd.feedback("disable","selector","actions")
    cmd.feedback("disable","scene","actions")
    cmd.set("internal_feedback",1)
    cmd.set("internal_prompt",0)
Example #17
0
    def update_plot_multiple(self, source=0, to_display=set(), canvas=None):
        """ Check for updated selections data in all plots simultaneously"""
        start_time = time.time()
        if source == 1:
            # Check mulltiple selection by dragging rectangle
            if self.scale == "Model":
                logging.info("Display models sent by OnDrag: ")
                logging.info(to_display)
                self.models_to_display = to_display.intersection(
                    self.all_models)
                logging.info(self.models_to_display)
                #if self.correlate.get():
                for m in self.all_models:
                    if m in self.models_to_display:
                        logging.debug("Color: %04d" % m)
                        #cmd.select('sele', '%04d' % s[5][1])
                        #cmd.show('cartoon', 'name CA and %04d' % s[5][1])
                        cmd.show('line', '%04d' % m)
                        #cmd.disable('sele')
                    elif m in self.models_shown:
                        cmd.hide('line', '%04d' % m)

                self.models_shown = self.models_to_display
            #     elif s[5][1] not in self.models_to_display and s[5][1] in self.models_shown:
            #                 canvas.itemconfig(k, fill='grey')
            #                 cpt=0
            #                 for it in canvas.ids_ext[k]:
            #                     if self.canvas[cpt] != canvas:
            #                         self.canvas[cpt].itemconfig(it, fill='grey')
            #                     else:
            #                         cpt+=1
            #                         self.canvas[cpt].itemconfig(it, fill='grey')
            #                     cpt+=1
            #                 logging.debug("Hide: %04d" % s[5][1])
            #                 #cmd.select('sele', '%04d' % s[5][1])
            #                 cmd.hide('everything', '%04d' % s[5][1])
            #                 #cmd.disable('sele')
            #         self.models_shown = self.models_to_display
            #     else:
            #         for k,s in canvas.shapes.iteritems():
            #             if s[5][1] in canvas.selected:
            #                 canvas.itemconfig(k, fill=self.color_selection[self.canvas.index(canvas)])
            #             elif s[5][1] not in self.models_to_display:
            #                 canvas.itemconfig(k, fill='grey')
            #         show = canvas.selected
            #         tmp = []
            #         for canv in self.canvas:
            #             if len(canv.selected) > 0 and canv != canvas:
            #                 tmp = [val for val in show if val in canv.selected]
            #                 show = tmp
            #         for model in self.models_shown:
            #             if model in show:
            #                 cmd.show('line', '%04d' % model)
            #             else:
            #                 cmd.hide('everything', '%04d' % model)
            #         self.models_shown = show
            #
            # elif self.scale == "Residue":
            #     logging.info("Display residues sent by OnDrag: ")
            #     logging.info(to_display)
            #     self.residues_to_display = to_display.intersection(self.all_residues)
            #     logging.info(self.residues_to_display)
            #     for k,s in canvas.shapes.iteritems():
            #         if s[5][1] in self.residues_to_display and s[5][1] not in self.residues_shown:
            #             canvas.itemconfig(k, fill='blue')
            #             cpt = 0
            #             for it in canvas.ids_ext[k]:
            #                 if self.canvas[cpt] != canvas:
            #                     self.canvas[cpt].itemconfig(it, fill='blue')
            #                 else:
            #                     cpt+=1
            #                     self.canvas[cpt].itemconfig(it, fill='blue')
            #                 cpt+=1
            #             logging.debug("Stick: %04d" % s[5][1])
            #             #cmd.select('sele', '%04d' % s[5][1])
            #             #cmd.show('cartoon', 'name CA and %04d' % s[5][1])
            #             cmd.show('sticks', 'resid %d and model %04d' % (s[5][1], self.model_selected))
            #             #cmd.disable('sele')
            #         elif s[5][1] not in self.residues_to_display and s[5][1] in self.residues_shown:
            #             canvas.itemconfig(k, fill='grey')
            #             cpt=0
            #             for it in canvas.ids_ext[k]:
            #                 if self.canvas[cpt] != canvas:
            #                     self.canvas[cpt].itemconfig(it, fill='grey')
            #                 else:
            #                     cpt+=1
            #                     self.canvas[cpt].itemconfig(it, fill='grey')
            #                 cpt+=1
            #             logging.debug("Line: %04d" % s[5][1])
            #             #cmd.select('sele', '%04d' % s[5][1])
            #             cmd.hide('sticks', 'resid %d and model %04d' % (s[5][1], self.model_selected))
            #             # cmd.show('line', 'resid %d and model %04d' % (s[5][1], self.model_selected))
            #             #cmd.disable('sele')
            #     self.residues_shown = self.residues_to_display

        elif source == 0:
            # Check single picking items
            for canv in self.canvas:
                if canv.picked != 0 and canv.picked != canv.previous:
                    logging.info("Something has been picked")
                    canv.itemconfig(canv.picked, fill='blue')
                    cpt = 0
                    for it in canv.ids_ext[canv.picked]:
                        if self.canvas[cpt] != canv:
                            self.canvas[cpt].itemconfig(it, fill='blue')
                        else:
                            cpt += 1
                            self.canvas[cpt].itemconfig(it, fill='blue')
                        cpt += 1
                    if self.scale == "Model":
                        cmd.show(
                            'cartoon', 'name CA and %04d' %
                            canv.shapes[canv.picked][5][1])
                        cmd.show('lines',
                                 '%04d' % canv.shapes[canv.picked][5][1])
                        logging.info(
                            "You selected item %d corresponding to model %d" %
                            (canv.picked, canv.shapes[canv.picked][5][1]))
                    elif self.scale == "Residue":
                        cmd.show(
                            'sticks', 'resid %d and model %04d' %
                            (canv.shapes[canv.picked][5][1],
                             self.model_selected))
                        logging.info(
                            "You selected item %d corresponding to model %d" %
                            (canv.picked, canv.shapes[canv.picked][5][1]))
                    if canv.previous != 0:
                        canv.itemconfig(canv.previous, fill='grey')
                        cpt = 0
                        for it in canv.ids_ext[canv.previous]:
                            if self.canvas[cpt] != canv:
                                self.canvas[cpt].itemconfig(it, fill='grey')
                            else:
                                cpt += 1
                                self.canvas[cpt].itemconfig(it, fill='grey')
                            cpt += 1
                        if self.scale == "Model":
                            cmd.hide('everything',
                                     '%04d' % canv.shapes[canv.previous][5][1])
                        elif self.scale == "Residue":
                            cmd.hide(
                                'sticks', 'resid %d and model %04d' %
                                (canv.shapes[canv.previous][5][1],
                                 self.model_selected))
                    canv.previous = canv.picked
                    break  # We can pick only one item among all canvas
            # Check selection from PyMol viewer
            try:
                items = self.queue.get_nowait()
                logging.info("Items from user selection in the viewer: " +
                             str(items))
                logging.info("Current state: %s / Scale: %s" %
                             (self.current_state, self.scale))

                # Automatic checking of model selection by the user
                if self.current_state == "default" and self.scale == "Model":
                    self.models_to_display = items.intersection(
                        self.all_models)
                    if len(self.models_to_display) > 0:
                        for k, s in canvas.shapes.iteritems():
                            if s[5][1] in self.models_to_display:
                                logging.info("Color red -> %04d" % s[5][1])
                                canvas.itemconfig(k, fill='blue')
                                cpt = 0
                                for it in canvas.ids_ext[k]:
                                    if self.canvas[cpt] != canvas:
                                        self.canvas[cpt].itemconfig(
                                            it, fill='blue')
                                    else:
                                        cpt += 1
                                        self.canvas[cpt].itemconfig(
                                            it, fill='blue')
                                    cpt += 1
                                cmd.color('red', '%04d' % s[5][1])
                            else:
                                logging.info("Color default -> %04d" % s[5][1])
                                canvas.itemconfig(k, fill='grey')
                                cpt = 0
                                for it in canvas.ids_ext[k]:
                                    if self.canvas[cpt] != canvas:
                                        self.canvas[cpt].itemconfig(
                                            it, fill='grey')
                                    else:
                                        cpt += 1
                                        self.canvas[cpt].itemconfig(
                                            it, fill='grey')
                                    cpt += 1
                                util.cbag('%04d' % s[5][1])
                                # cmd.select('sele', '%04d' % s[5][1])
                                # cmd.hide('line', '(sele)')
                        cmd.disable('lb')
                # We wait for user selection to trigger next steps
                elif self.current_state == "selection":
                    # Model selection
                    if int(cmd.get("mouse_selection_mode")) == 5:
                        try:
                            logging.info("Model selected for analyses: %d " %
                                         list(items)[0])
                            self.model_selected = list(items)[0]
                            cmd.hide('everything', 'all')
                            cmd.show('cartoon', '%04d' % self.model_selected)
                            cmd.show('lines', '%04d' % self.model_selected)
                            color_by_residue.color_by_restype()
                            for k, s in canvas.shapes.iteritems():
                                if s[5][1] == self.model_selected:
                                    canvas.itemconfig(k, fill='blue')
                                    cpt = 0
                                    for it in canvas.ids_ext[k]:
                                        if self.canvas[cpt] != canvas:
                                            self.canvas[cpt].itemconfig(
                                                it, fill='blue')
                                        else:
                                            cpt += 1
                                            self.canvas[cpt].itemconfig(
                                                it, fill='blue')
                                        cpt += 1
                                else:
                                    logging.info("Color default -> %04d" %
                                                 s[5][1])
                                    canvas.itemconfig(k, fill='grey')
                                    cpt = 0
                                    for it in canvas.ids_ext[k]:
                                        if self.canvas[cpt] != canvas:
                                            self.canvas[cpt].itemconfig(
                                                it, fill='grey')
                                        else:
                                            cpt += 1
                                            self.canvas[cpt].itemconfig(
                                                it, fill='grey')
                                        cpt += 1
                                    # cmd.select('sele', '%04d' % s[5][1])

                            #cmd.disable('lb')
                            self.current_state = "default"
                            self.on_model_selected(evt=None)
                            items = set()
                        except IndexError:
                            logging.info("No model selected in the viewer")
                            pass
                    # Residue selection
                    elif int(cmd.get("mouse_selection_mode")) == 1:
                        try:
                            logging.info(
                                "Residue selection for analyses: %d " %
                                list(items)[0])
                            self.item_selected = list(items)[0]
                            items = set()
                            self.current_state = "default"
                            self.on_reference_selected_for_distance(evt=None)
                        except IndexError:
                            logging.info("No residue selected in the viewer")
                            pass

            except Queue.Empty:
                pass
        # Reset plot and viewer
        elif source == 2:
            logging.info("RESET")
            for canv in self.canvas:
                for k, s in canv.shapes.iteritems():
                    canv.itemconfig(k, fill='grey')
                    cpt = 0
                    for it in canvas.ids_ext[k]:
                        if self.canvas[cpt] != canvas:
                            self.canvas[cpt].itemconfig(it, fill='grey')
                        else:
                            cpt += 1
                            self.canvas[cpt].itemconfig(it, fill='grey')
                        cpt += 1
                    self.models_to_display.clear()
                    self.models_shown.clear()
                canv.previous = 0
                canv.picked = 0
            cmd.hide('everything', 'all')

        # "Selection mode"
        elif source == 3:
            logging.info("SELECTION MODE")
            for canv in self.canvas:
                for k, s in canv.shapes.iteritems():
                    canv.itemconfig(k, fill='grey')
                    cpt = 0
                    for it in canv.ids_ext[k]:
                        if self.canvas[cpt] != canv:
                            self.canvas[cpt].itemconfig(it, fill='grey')
                        else:
                            cpt += 1
                            self.canvas[cpt].itemconfig(it, fill='grey')
                        cpt += 1
                    self.models_to_display.add(s[5][1])
                    self.models_shown.add(s[5][1])
            cmd.show('cartoon', 'name CA')
            cmd.show('lines', 'all')

        logging.debug("---- %s seconds ----" % str(time.time() - start_time))
        print time.time()
        try:
            self.rootframe.after(500, self.update_plot_multiple)
        except:
            pass
Example #18
0
def setup_contexts(context_info):  # Author: Warren DeLano
    (list, dict) = context_info[0:2]
    key_list = [
        'F1',
        'F2',
        'F3',
        'F4',
        'F5',
        'F6',
        'F7',
        'F8',
        'F9',
        'F10',  #,'F11','F12',
        'SHFT-F1',
        'SHFT-F2',
        'SHFT-F3',
        'SHFT-F4',
        'SHFT-F5',
        'SHFT-F6',
        'SHFT-F7',
        'SHFT-F8',
        'SHFT-F9',
        'SHFT-F10'
    ]  # ,'SHFT-F11','SHFT-F12']
    doc_list = ["Keys"]
    zoom_context = 1
    global labels
    labels = 1
    if len(key_list):
        key = key_list.pop(0)
        cmd.set_key(key, toggle_labels)
        doc_list.append(key + ": Toggle Dist")
    if len(key_list):
        key = key_list.pop(0)
        cmd.set_key(key, lambda: (cmd.zoom(), toggle_labels(0)))
        doc_list.append(key + ": Zoom All")

    for a in list:
        water = a + "_water"
        ligand = a + "_ligand"
        site = a + "_site"
        hbond = a + "_hbond"
        name_list = dict[a]
        zoom_list = []
        if water in name_list:
            cmd.show("nonbonded", water)
            util.cbac(water)
            zoom_list.append(water)
        if ligand in name_list:
            cmd.show("sticks", ligand)
            cmd.hide("cartoon", ligand)
            util.cbag(ligand)
            zoom_list.append(ligand)
        if site in name_list:
            cmd.show("sticks", site)
            util.cbac(site)
            zoom_list.append(site)
            # replace cartoon with explicit atoms for "site" atoms
            cmd.hide("cartoon", site)
            cmd.show(
                "sticks",
                "(byres (neighbor (" + site + " and name C))) and name N+CA")
            cmd.show(
                "sticks",
                "(byres (neighbor (" + site + " and name N))) and name C+CA+O")
        if len(zoom_list):
            if len(key_list):
                key = key_list.pop(0)
                zoom_str = ' or '.join(zoom_list)
                if zoom_context == 1:
                    zoom_context = zoom_str
                elif zoom_context not in (0, 1):
                    zoom_context = 0
                cmd.set_key(key, lambda x=zoom_str: (cmd.zoom(x)))
                mo = re.search("_([^_]+)$", a)
                if mo:
                    cont_name = mo.groups()[0]
                else:
                    cont_name = a
                doc_list.append(key + ": Zoom " + cont_name)

        if hbond in name_list:
            cmd.show("dashes", hbond)
            cmd.show("labels", hbond)

    cmd.wizard("fedora", doc_list)
    if zoom_context not in (0, 1):
        cmd.zoom(zoom_context)
    toggle_labels(0)
    #    cmd.feedback("enable","python","output")
    cmd.feedback("enable", "objectmolecule", "results")
    cmd.feedback("disable", "selector", "actions")
    cmd.feedback("disable", "scene", "actions")
    cmd.set("internal_feedback", 1)
    cmd.set("internal_prompt", 0)
Example #19
0
    def on_execute_button_clicked(self):
        if not _HAS_LIB:
            tkMessageBox.showerror(
                'ERROR',
                'Please install EMDY before launch the plugin',
                parent=self.parent)
            return

        if self.notebook.getcurselection() == 'Preparation':
            if self.mod is None or self.top is None or self.prm is None:
                failed = self.load_input()
                if failed:
                    return
            try:
                self.mod = add_atoms(self.mod, self.top, self.prm)
            except Exception:
                tkMessageBox.showerror(
                    'ERROR',
                    'Failed',
                    parent=self.parent)
            else:
                tkMessageBox.showinfo(
                    'INFO',
                    'Successfully completed',
                    parent=self.parent)

        elif self.notebook.getcurselection() == 'Solvation':
            if self.mod is None or self.top is None or self.prm is None:
                failed = self.load_input()
                if failed:
                    return
            try:
                self.mod = add_solvents(self.mod, self.watmod.getvalue(),
                                        self.watseg.getvalue(),
                                        self.boxshape.get(),
                                        float(self.pad.getvalue()),
                                        float(self.cut.getvalue()))
            except Exception:
                tkMessageBox.showerror(
                    'ERROR',
                    'Failed',
                    parent=self.parent)
            else:
                tkMessageBox.showinfo(
                    'INFO',
                    'Successfully completed',
                    parent=self.parent)

        elif self.notebook.getcurselection() == 'Ionization':
            if self.mod is None or self.top is None or self.prm is None:
                failed = self.load_input()
                if failed:
                    return

            if self.do_neutral.get():
                catnum = aninum = 0
            else:
                catnum = int(self.catnum.getvalue())
                aninum = int(self.aninum.getvalue())
                if catnum == aninum == 0:
                    return

            catmod = IONS[self.catmod.getvalue()]
            animod = IONS[self.animod.getvalue()]

            try:
                self.mod = add_ions(self.mod, catmod, catnum, animod, aninum,
                                    float(self.salcon.getvalue()),
                                    float(self.ionsol.getvalue()),
                                    float(self.ionion.getvalue()), None,
                                    self.ionseg.getvalue(), self.ionmeth.get())
            except Exception:
                tkMessageBox.showerror(
                    'ERROR',
                    'Failed',
                    parent=self.parent)
            else:
                tkMessageBox.showinfo(
                    'INFO',
                    'Successfully completed',
                    parent=self.parent)

        else:
            if self.mod is None or self.top is None or self.prm is None:
                self.load_input()
            return

        # generate a tmp file for view
        objname = {'Preparation': 'modified', 'Solvation': 'solvated',
                   'Ionization': 'ionized'}[self.notebook.getcurselection()]
        tmpfp = StringIO()
        with PdbFile(tmpfp, 'w') as f:
            f.write(self.mod)
            for obj in self.pmobj:
                cmd.delete(obj)
            cmd.read_pdbstr(tmpfp.getvalue(), objname)
            util.cbag()
            self.pmobj = [objname]
            if self.notebook.getcurselection() == 'Ionization':
                cmd.show('spheres', 'segi %s'%self.ionseg.getvalue())