예제 #1
0
    def testPairFit(self):
        cmd.fragment('trp')
        cmd.fragment('his')

        # 1 atom
        sele = ('trp and guide', 'his and guide')
        pos = list(map(cmd.get_atom_coords, sele))
        vec = cpv.sub(*pos)
        mat_ref = [
            1.0, 0.0, 0.0, -vec[0],
            0.0, 1.0, 0.0, -vec[1],
            0.0, 0.0, 1.0, -vec[2],
            0.0, 0.0, 0.0, 1.0]
        rms = cmd.pair_fit(*sele)
        self.assertEqual(rms, 0.0)
        mat = cmd.get_object_matrix('trp')
        self.assertArrayEqual(mat, mat_ref, 1e-4)

        # 2 atoms
        sele += ('trp & name CB', 'his & name CB')
        rms = cmd.pair_fit(*sele)
        self.assertAlmostEqual(rms, 0.0082, delta=1e-4)

        # 4 atoms
        sele += ('trp & name CG', 'his & name CG',
                 'trp & name CD1', 'his & name CD2')
        rms = cmd.pair_fit(*sele)
        self.assertAlmostEqual(rms, 0.0713, delta=1e-4)
예제 #2
0
def pairfitCys(Cysmolecule, molecule, chain, residue):
    RN = "/" + Cysmolecule + "//" + "/" + "/N"
    PN = "/" + molecule + "//" + chain + "/" + residue + "/N"
    RCA = "/" + Cysmolecule + "//" + "/" + "/CA"
    PCA = "/" + molecule + "//" + chain + "/" + residue + "/CA"
    RC = "/" + Cysmolecule + "//" + "/" + "/C"
    PC = "/" + molecule + "//" + chain + "/" + residue + "/C"
    RCB = "/" + Cysmolecule + "//" + "/" + "/CB"
    PCB = "/" + molecule + "//" + chain + "/" + residue + "/CB"
    cmd.select("CBatom", PCB)
    CBatomNr = cmd.count_atoms("CBatom")
    # If PRO or GLY, then only fit N, CA, C atoms
    if CBatomNr == 0:
        cmd.pair_fit(RN, PN, RCA, PCA, RC, PC)
    else:
        # cmd.pair_fit(RN,PN,RCA,PCA,RC,PC,RCB,PCB)
        cmd.pair_fit(RN, PN, RCA, PCA, RC, PC)
    cmd.delete("CBatom")
예제 #3
0
def pairfitCys(Cysmolecule, molecule, chain, residue):
    RN = "/" + Cysmolecule + "//" + "/" + "/N"
    PN = "/" + molecule + "//" + chain + "/" + residue + "/N"
    RCA = "/" + Cysmolecule + "//" + "/" + "/CA"
    PCA = "/" + molecule + "//" + chain + "/" + residue + "/CA"
    RC = "/" + Cysmolecule + "//" + "/" + "/C"
    PC = "/" + molecule + "//" + chain + "/" + residue + "/C"
    RCB = "/" + Cysmolecule + "//" + "/" + "/CB"
    PCB = "/" + molecule + "//" + chain + "/" + residue + "/CB"
    cmd.select("CBatom", PCB)
    CBatomNr = cmd.count_atoms("CBatom")
    ### If PRO or GLY, then only fit N, CA, C atoms
    if CBatomNr == 0:
        cmd.pair_fit(RN, PN, RCA, PCA, RC, PC)
    else:
        #cmd.pair_fit(RN,PN,RCA,PCA,RC,PC,RCB,PCB)
        cmd.pair_fit(RN, PN, RCA, PCA, RC, PC)
    cmd.delete("CBatom")
예제 #4
0
def show_motif(value):
    cmd.delete("*")
    domain1 = align_pairs[value][0]
    domain2 = align_pairs[value][1]
    residues1 = align_pairs[value][2]
    residues2 = align_pairs[value][3]

    cmd.load("PDBFiles/%s.pdb" % domain1)
    cmd.load("PDBFiles/%s.pdb" % domain2)
    cmd.bg_color("white")

    cmd.hide("all")
    cmd.show("cartoon", "all")
    cmd.select("motif1", "none")
    cmd.select("motif1",
               "motif1 or (%s and n. CA and resi %s)" % (domain1, residues1))
    cmd.select("motif2", "none")
    cmd.select("motif2",
               "motif2 or (%s and n. CA and resi %s)" % (domain2, residues2))
    cmd.select("none")
    cmd.color("gray80", domain1)
    cmd.color("gray60", domain2)
    cmd.color("cyan", "motif1")
    cmd.color("magenta", "motif2")
    #cmd.seqview("on")
    try:
        cmd.pair_fit("motif1", "motif2", object="alignment")
        cmd.center(domain1)
        #cmd.png("PNGsRenumb/%s_%s_PF.png"%(domain1, domain2), dpi = 300)
    except CmdException:
        pass

    try:
        cmd.cealign("motif1", "motif2", object="alignment")
        cmd.center(domain1)
        #cmd.png("PNGsRenumb/%s_%s_CE.png"%(domain1, domain2), dpi = 300)
    except CmdException:
        pass
예제 #5
0
 def fit(self):
     # build up the pair-wise list of selections
     cmd.delete(dist_prefix + "*")
     lst = self.get_sele_list()
     c = 0
     args = []
     while 1:
         if not len(lst): break
         a = lst.pop()
         if not len(lst): break
         b = lst.pop()
         args.append(a)
         args.append(b)
     # do the fit
     if len(args):
         cmd.push_undo(args[0])
         dist = cmd.pair_fit(*args)
         self.message = "RMS over %d pairs = %5.3f" % (self.n_pair, dist)
         cmd.refresh_wizard()
     self.update_dashes()
예제 #6
0
 def fit(self):
     # build up the pair-wise list of selections
     cmd.delete(dist_prefix+"*")
     lst = self.get_sele_list()
     c = 0
     args = []
     while 1:
         if not len(lst): break
         a = lst.pop()
         if not len(lst): break
         b = lst.pop()
         args.append(a)
         args.append(b)
     # do the fit
     if len(args):
         cmd.push_undo(args[0])
         dist = cmd.pair_fit(*args)
         self.message = "RMS over %d pairs = %5.3f"%(self.n_pair,dist)
         cmd.refresh_wizard()
     self.update_dashes()
예제 #7
0
    def do_library(self):
        cmd=self.cmd
        pymol=cmd._pymol
        if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and
                (cmd.count_atoms("(%s) and name C"%src_sele)==1) and
                (cmd.count_atoms("(%s) and name O"%src_sele)==1)):
            self.clear()
            return 1
        cmd.feedback("push")
        cmd.feedback("disable","selector","everythin")
        cmd.feedback("disable","editor","actions")
        self.prompt = [ 'Loading rotamers...']
        self.bump_scores = []
        state_best = 0

        pymol.stored.name = 'residue'
        cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi')
        self.res_text = pymol.stored.name
        cmd.select("_seeker_hilight",src_sele)

        auto_zoom = cmd.get_setting_text('auto_zoom')
        cmd.set('auto_zoom',"0",quiet=1)
        cmd.frame(0)
        cmd.delete(frag_name)
        if self.auto_center:
            cmd.center(src_sele,animate=-1)

        self.lib_mode = self.mode
        if self.lib_mode=="current":
            pymol.stored.resn=""
            cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn")
            rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn)
            if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'):
                self.lib_mode = rot_type # force fragment-based load
            else:
                cmd.create(frag_name,src_sele,1,1)
                if self.c_cap=='open':
                    cmd.remove("%s and name OXT"%frag_name)

        if self.lib_mode!='current':
            rot_type = self.lib_mode
            frag_type = self.lib_mode
            if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'):
                if not ( cmd.count_atoms(
                    "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"%
                                     (src_sele,src_sele))):
                    # use N-terminal fragment
                    frag_type ="NT_"+frag_type
            if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'):
                if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"%
                                     (src_sele,src_sele))):
                    # use C-terminal fragment
                    frag_type ="CT_"+frag_type
            if rot_type[0:3] in [ 'NT_', 'CT_' ]:
                rot_type = rot_type[3:]
            rot_type = _rot_type_xref.get(rot_type, rot_type)
            cmd.fragment(frag_type.lower(), frag_name, origin=0)
            # trim off hydrogens
            if (self.hyd == 'none'):
                cmd.remove("("+frag_name+" and hydro)")
            elif (self.hyd == 'auto'):
                if cmd.count_atoms("("+src_sele+") and hydro")==0:
                    cmd.remove("("+frag_name+" and hydro)")
            # copy identifying information
            cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space)
            cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space)
            # move the fragment
            if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and
                 (cmd.count_atoms("(%s & name CB)"%src_sele)==1)):
                cmd.pair_fit("(%s & name CA)"%frag_name,
                             "(%s & name CA)"%src_sele,
                             "(%s & name CB)"%frag_name,
                             "(%s & name CB)"%src_sele,
                             "(%s & name C)"%frag_name,
                             "(%s & name C)"%src_sele,
                             "(%s & name N)"%frag_name,
                             "(%s & name N)"%src_sele)
            else:
                cmd.pair_fit("(%s & name CA)"%frag_name,
                             "(%s & name CA)"%src_sele,
                             "(%s & name C)"%frag_name,
                             "(%s & name C)"%src_sele,
                             "(%s & name N)"%frag_name,
                             "(%s & name N)"%src_sele)

            # fix the carbonyl position...
            cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]")
            cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list")
            if cmd.count_atoms("(%s & name OXT)"%src_sele):
                cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]")
                cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list")
            elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists
                angle = cmd.get_dihedral("(%s & name N)"%frag_name,
                                         "(%s & name CA)"%frag_name,
                                         "(%s & name C)"%frag_name,
                                         "(%s & name O)"%frag_name)
                cmd.protect("(%s & name O)"%frag_name)
                cmd.set_dihedral("(%s & name N)"%frag_name,
                                 "(%s & name CA)"%frag_name,
                                 "(%s & name C)"%frag_name,
                                 "(%s & name OXT)"%frag_name,180.0+angle)
                cmd.deprotect(frag_name)


            # fix the hydrogen position (if any)
            if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1:
                if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1:
                    cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele,
                                      "stored.list=[x,y,z]")
                    cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name,
                                    "(x,y,z)=stored.list")
                elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1:
                    # position hydro based on location of the carbonyl
                    angle = cmd.get_dihedral("(%s & name C)"%frag_name,
                                             "(%s & name CA)"%frag_name,
                                             "(%s & name N)"%frag_name,
                                             tmp_sele1)
                    cmd.set_dihedral("(%s & name C)"%frag_name,
                                     "(%s & name CA)"%frag_name,
                                     "(%s & name N)"%frag_name,
                                     "(%s & name H)"%frag_name,180.0+angle)
                    cmd.delete(tmp_sele1)

            # add c-cap (if appropriate)
            if self.c_cap in [ 'amin', 'nmet' ]:
                if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"%
                                       (src_sele,src_sele)):
                    if cmd.count_atoms("name C & (%s)"%(frag_name))==1:
                        if self.c_cap == 'amin':
                            editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh')
                        elif self.c_cap == 'nmet':
                            editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme')
                        if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name):
                            cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name)
                        # trim hydrogens
                        if (self.hyd == 'none'):
                            cmd.remove("("+frag_name+" and hydro)")
                        elif (self.hyd == 'auto'):
                            if cmd.count_atoms("("+src_sele+") and hydro")==0:
                                cmd.remove("("+frag_name+" and hydro)")

            # add n-cap (if appropriate)
            if self.n_cap in [ 'acet' ]:
                if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "%
                                       (src_sele,src_sele)):
                    if cmd.count_atoms("name N & (%s)"%(frag_name))==1:
                        if self.n_cap == 'acet':
                            editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace')
                        if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name):
                            cmd.h_fix("name N & (%s)"%frag_name)
                        # trim hydrogens
                        if (self.hyd == 'none'):
                            cmd.remove("("+frag_name+" and hydro)")
                        elif (self.hyd == 'auto'):
                            if cmd.count_atoms("("+src_sele+") and hydro")==0:
                                cmd.remove("("+frag_name+" and hydro)")




        cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0)
        sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0)

        cmd.delete(obj_name)
        key = rot_type
        lib = None
        if self.dep == 'dep':
            try:
                result = cmd.phi_psi("%s"%src_sele)
                if len(result)==1:
                    (phi,psi) = list(result.values())[0]
                    (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10))))
                    key = (rot_type,phi,psi)
                    if key not in self.dep_library:
                        (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20))))
                        key = (rot_type,phi,psi)
                        if key not in self.dep_library:
                            (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60))))
                            key = (rot_type,phi,psi)
                    lib = self.dep_library.get(key,None)
            except:
                pass
        if lib is None:
            key = rot_type
            lib = self.ind_library.get(key,None)
            if (lib is not None) and self.dep == 'dep':
                print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.')
        if lib is not None:
            state = 1
            for a in lib:
                cmd.create(obj_name,frag_name,1,state)
                if state == 1:
                    cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele))
                if rot_type=='PRO':
                    cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele)
                for b in a.keys():
                    if b!='FREQ':
                        cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]),
                                         "(%s & n;%s)"%(mut_sele,b[1]),
                                         "(%s & n;%s)"%(mut_sele,b[2]),
                                         "(%s & n;%s)"%(mut_sele,b[3]),
                                         a[b],state=state)
                    else:
                        cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100))
                if rot_type=='PRO':
                    cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele)
                state = state + 1
            cmd.delete(frag_name)
            print(" Mutagenesis: %d rotamers loaded."%len(lib))
            if self.bump_check:
                cmd.delete(bump_name)
                cmd.create(bump_name,
                "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"%
                           (src_sele,mut_sele,src_sele,mut_sele),singletons=1)
                cmd.color("gray50",bump_name+" and elem C")
                cmd.set("seq_view",0,bump_name,quiet=1)
                cmd.hide("everything",bump_name)
                if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"%
                                (bump_name,src_sele)) == 1) and
                    (cmd.select(tmp_sele2, "(name C & (%s in %s))"%
                                (bump_name,mut_sele)) == 1)):
                    cmd.bond(tmp_sele1,tmp_sele2)
                if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"%
                                (bump_name,src_sele)) == 1) and
                    (cmd.select(tmp_sele2,"(name N & (%s in %s))"%
                                (bump_name,mut_sele)) == 1)):
                    cmd.bond(tmp_sele1,tmp_sele2)
                cmd.delete(tmp_sele1)
                cmd.delete(tmp_sele2)

                cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"%
                            (bump_name,bump_name,mut_sele))
                cmd.sculpt_activate(bump_name)
                cmd.show("cgo",bump_name)
                # draw the bumps
                cmd.set("sculpt_vdw_vis_mode",1,bump_name)
                state = 1
                score_best = 1e6
                for a in lib:
                    score = cmd.sculpt_iterate(bump_name, state, 1)
                    self.bump_scores.append(score)
                    if score < score_best:
                        state_best = state
                        score_best = score
                    state = state + 1
            cmd.delete(mut_sele)
        else:
            cmd.create(obj_name,frag_name,1,1)
            print(" Mutagenesis: no rotamers found in library.")
        cmd.set("seq_view",0,obj_name,quiet=1)
        pymol.util.cbaw(obj_name)
        cmd.hide("("+obj_name+")")
        cmd.show(self.rep,obj_name)
        cmd.show('lines',obj_name) #neighbor  always show lines
        if cartoon:
            cmd.show("cartoon",obj_name)
        if sticks:
            cmd.show("sticks",obj_name)
        cmd.set('auto_zoom',auto_zoom,quiet=1)
        cmd.delete(frag_name)
        cmd.frame(state_best)
        cmd.unpick()
        cmd.feedback("pop")
예제 #8
0
    def showCorr(self, ar):

        try:
            cmd.reinitialize()
            self.multiListBox1.focus()
            cmd.load(self.ref_Entry.get(), object="obj1")
            self.index = ar[0]
            self.selection_row = self.multiListBox1.get(self.index)
            self.selection_data = self.selection_row[0]
            self.rank = self.selection_data[0]
            self.zincId = self.selection_data[1]

            # Empty box2
            self.multiListBox2.delete(0, END)

            file_type = ".mol2"
            result_Filename = self.rank + "_" + self.zincId + file_type
            log.info("Filename:'%s'" % result_Filename)
            i = 0
            j = 0
            k = 0
            line = ()
            # timestamp_Folder=os.path.join(result_Folder,timestamp_Done)
            file_Mol = os.path.join(self.timestamp_Folder, result_Filename)
            print file_Mol

            self.ref = ()
            self.tar = ()

            try:
                fh = open(file_Mol, "r")  # handle possible exceptions
                cmd.load(file_Mol, object="obj2")
            except IOError:
                tkMessageBox.showinfo("No data found", "The result molecules were not written to the output")
            for block in iter(lambda: fh.readline(), ""):
                if i == 1:
                    if j == 1:
                        if not block == "\n":

                            k = k + 1
                            line = block.split()
                            self.ref = self.ref + (line[1],)
                            self.tar = self.tar + (line[3],)

                            self.multiListBox2.insert(END, *line)
                        else:
                            i = 0
                            j = 0
                if "LiSiCA  RESULTS" in block:
                    i = 1
                if i == 1:
                    if "--------------" in block:
                        j = 1
            log.info("Displayed the atom correspondence of the selected atom")

            if self.dimension.get() == 2:
                cmd.set("grid_mode", value=1)
                cmd.set("grid_slot", value=1, selection="obj1")
                cmd.set("grid_slot", value=2, selection="obj2")
                cmd.align("obj1", "obj2")
            elif self.dimension.get() == 3:
                self.lig1_atoms = "obj1////"
                self.lig2_atoms = "obj2////"
                for item in self.ref:
                    self.lig1_atoms = self.lig1_atoms + item + "+"
                for item in self.tar:
                    self.lig2_atoms = self.lig2_atoms + item + "+"
                self.lig1_atoms = self.lig1_atoms[:-1]
                self.lig2_atoms = self.lig2_atoms[:-1]
                cmd.pair_fit(self.lig1_atoms, self.lig2_atoms)
            else:
                log.error("Dimension value is wrong")

            cmd.orient()

        except:
            pass
예제 #9
0
    def _do_mutation(self):
        '''
        After selection, propose what the fragment will look like where
        applied.
        Exception: _do_mutation should be wrapped in a try-exception block
                   when called
        '''
        cmd = self.cmd

        cmd.delete(FRAG_NAME)
        cmd.refresh_wizard()

        if any(
                cmd.count_atoms("(%s) & name %s" % (SRC_SELE, name)) != 1
                for name in ("C1'", "C2'", "C3'", "C4'", "O4'")):
            self.clear()
            raise pymol.wizarding.WizardError(
                'Improper selection of nucleic acid.')

        frag_type_lower = self._mode_labels[self.mode].lower()
        cmd.fragment(frag_type_lower, FRAG_NAME, origin=0)
        self._update_reps()
        cmd.color("white", "%s & elem C" % FRAG_NAME)
        cmd.iterate(
            "first (%s)" % SRC_SELE,
            'stored.name = model+"/"+segi+"/"+chain+"/"+resn+"`"+resi',
            space=self._space)
        self.res_text = self._space['stored'].name

        cmd.alter(
            "?%s & name C1'" % SRC_SELE,
            "stored.identifiers = (segi, chain, resi, ss, color)",
            space=self._space)
        self._status = Status.MUTAGENIZING
        self.get_prompt()

        cmd.iterate(
            "(%s & name C1')" % SRC_SELE,
            "stored.resn = resn",
            space=self._space)
        src_type_lower = self._space['stored'].resn.lower()
        self._src_O_atom_name, self._src_Cp_atom_name, self._src_N_atom_name, \
        self._src_C_atom_name = self._get_chi_dihedral_atoms(src_type_lower)

        self._frag_O_atom_name, self._frag_Cp_atom_name, self._frag_N_atom_name, \
        self._frag_C_atom_name = self._get_chi_dihedral_atoms(frag_type_lower)

        cmd.pair_fit("(%s & name %s)" % (FRAG_NAME, self._frag_O_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_O_atom_name),
                     "(%s & name %s)" % (FRAG_NAME, self._frag_Cp_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_Cp_atom_name),
                     "(%s & name %s)" % (FRAG_NAME, self._frag_N_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_N_atom_name))

        self._transfer_dihedral()

        for a in self._sugar_phos_atoms:
            cmd.remove("(%s & name %s)" % (FRAG_NAME, a))

        if self._auto_center == "ON":
            cmd.center(FRAG_NAME, animate=1)
예제 #10
0
    def _do_mutation(self):
        '''
        After selection, propose what the fragment will look like where
        applied.
        Exception: _do_mutation should be wrapped in a try-exception block
                   when called
        '''
        cmd = self.cmd

        cmd.delete(FRAG_NAME)
        cmd.refresh_wizard()

        if any(
                cmd.count_atoms("(%s) & name %s" % (SRC_SELE, name)) != 1
                for name in ("C1'", "C2'", "C3'", "C4'", "O4'")):
            self.clear()
            raise pymol.wizarding.WizardError(
                'Improper selection of nucleic acid.')

        frag_type_lower = self._mode_labels[self.mode].lower()
        cmd.fragment(frag_type_lower, FRAG_NAME, origin=0)
        self._update_reps()
        cmd.color("white", "%s & elem C" % FRAG_NAME)
        cmd.iterate(
            "first (%s)" % SRC_SELE,
            'stored.name = model+"/"+segi+"/"+chain+"/"+resn+"`"+resi',
            space=self._space)
        self.res_text = self._space['stored'].name

        cmd.alter(
            "?%s & name C1'" % SRC_SELE,
            "stored.identifiers = (segi, chain, resi, ss, color)",
            space=self._space)
        self._status = Status.MUTAGENIZING
        self.get_prompt()

        cmd.iterate(
            "(%s & name C1')" % SRC_SELE,
            "stored.resn = resn",
            space=self._space)
        src_type_lower = self._space['stored'].resn.lower()
        self._src_O_atom_name, self._src_Cp_atom_name, self._src_N_atom_name, \
        self._src_C_atom_name = self._get_chi_dihedral_atoms(src_type_lower)

        self._frag_O_atom_name, self._frag_Cp_atom_name, self._frag_N_atom_name, \
        self._frag_C_atom_name = self._get_chi_dihedral_atoms(frag_type_lower)

        cmd.pair_fit("(%s & name %s)" % (FRAG_NAME, self._frag_O_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_O_atom_name),
                     "(%s & name %s)" % (FRAG_NAME, self._frag_Cp_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_Cp_atom_name),
                     "(%s & name %s)" % (FRAG_NAME, self._frag_N_atom_name),
                     "(%s & name %s)" % (SRC_SELE, self._src_N_atom_name))

        self._transfer_dihedral()

        for a in self._sugar_phos_atoms:
            cmd.remove("(%s & name %s)" % (FRAG_NAME, a))

        if self._auto_center == "ON":
            cmd.center(FRAG_NAME, animate=1)
예제 #11
0
    def do_library(self):
        cmd=self.cmd
        pymol=cmd._pymol
        if not ((cmd.count_atoms("(%s) and name N"%src_sele)==1) and
                (cmd.count_atoms("(%s) and name C"%src_sele)==1) and
                (cmd.count_atoms("(%s) and name O"%src_sele)==1)):
            self.clear()
            return 1
        cmd.feedback("push")
        cmd.feedback("disable","selector","everythin")
        cmd.feedback("disable","editor","actions")
        self.prompt = [ 'Loading rotamers...']
        self.bump_scores = []
        state_best = 0

        pymol.stored.name = 'residue'
        cmd.iterate("first (%s)"%src_sele,'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi')
        self.res_text = pymol.stored.name
        cmd.select("_seeker_hilight",src_sele)
        
        auto_zoom = cmd.get_setting_text('auto_zoom')
        cmd.set('auto_zoom',"0",quiet=1)
        cmd.frame(0)
        cmd.delete(frag_name)
        if self.auto_center:
            cmd.center(src_sele,animate=-1)

        self.lib_mode = self.mode
        if self.lib_mode=="current":
            pymol.stored.resn=""
            cmd.iterate("(%s & name CA)"%src_sele,"stored.resn=resn")
            rot_type = _rot_type_xref.get(pymol.stored.resn,pymol.stored.resn)
            if (self.c_cap!='none') or (self.n_cap!='none') or (self.hyd != 'auto'):
                self.lib_mode = rot_type # force fragment-based load
            else:
                cmd.create(frag_name,src_sele,1,1)
                if self.c_cap=='open':
                    cmd.remove("%s and name OXT"%frag_name)
                    
        if self.lib_mode!='current':
            rot_type = self.lib_mode
            frag_type = self.lib_mode
            if (self.n_cap == 'posi') and (frag_type[0:3]!='NT_'):
                if not ( cmd.count_atoms(
                    "elem C & !(%s) & (bto. (name N & (%s))) &! resn ACE"%
                                     (src_sele,src_sele))):
                    # use N-terminal fragment
                    frag_type ="NT_"+frag_type
            if (self.c_cap == 'nega') and (frag_type[0:3]!='CT_'):
                if not ( cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"%
                                     (src_sele,src_sele))):
                    # use C-terminal fragment
                    frag_type ="CT_"+frag_type
            if rot_type[0:3] in [ 'NT_', 'CT_' ]:
                rot_type = rot_type[3:]
            rot_type = _rot_type_xref.get(rot_type, rot_type)
            cmd.fragment(frag_type.lower(), frag_name, origin=0)
            # trim off hydrogens
            if (self.hyd == 'none'):
                cmd.remove("("+frag_name+" and hydro)")
            elif (self.hyd == 'auto'):
                if cmd.count_atoms("("+src_sele+") and hydro")==0:
                    cmd.remove("("+frag_name+" and hydro)")
            # copy identifying information
            cmd.alter("?%s & name CA" % src_sele, "stored.identifiers = (segi, chain, resi, ss, color)", space=self.space)
            cmd.alter("?%s" % frag_name, "(segi, chain, resi, ss) = stored.identifiers[:4]", space=self.space)
            # move the fragment
            if ((cmd.count_atoms("(%s & name CB)"%frag_name)==1) and
                 (cmd.count_atoms("(%s & name CB)"%src_sele)==1)):
                cmd.pair_fit("(%s & name CA)"%frag_name,
                             "(%s & name CA)"%src_sele,
                             "(%s & name CB)"%frag_name,
                             "(%s & name CB)"%src_sele,
                             "(%s & name C)"%frag_name,
                             "(%s & name C)"%src_sele,
                             "(%s & name N)"%frag_name,
                             "(%s & name N)"%src_sele)
            else:
                cmd.pair_fit("(%s & name CA)"%frag_name,
                             "(%s & name CA)"%src_sele,
                             "(%s & name C)"%frag_name,
                             "(%s & name C)"%src_sele,
                             "(%s & name N)"%frag_name,
                             "(%s & name N)"%src_sele)

            # fix the carbonyl position...
            cmd.iterate_state(1,"(%s & name O)"%src_sele,"stored.list=[x,y,z]")
            cmd.alter_state(1,"(%s & name O)"%frag_name,"(x,y,z)=stored.list")
            if cmd.count_atoms("(%s & name OXT)"%src_sele):
                cmd.iterate_state(1,"(%s & name OXT)"%src_sele,"stored.list=[x,y,z]")
                cmd.alter_state(1,"(%s & name OXT)"%frag_name,"(x,y,z)=stored.list")
            elif cmd.count_atoms("(%s & name OXT)"%frag_name): # place OXT if no template exists
                angle = cmd.get_dihedral("(%s & name N)"%frag_name,
                                         "(%s & name CA)"%frag_name,
                                         "(%s & name C)"%frag_name,
                                         "(%s & name O)"%frag_name)
                cmd.protect("(%s & name O)"%frag_name)
                cmd.set_dihedral("(%s & name N)"%frag_name,
                                 "(%s & name CA)"%frag_name,
                                 "(%s & name C)"%frag_name,
                                 "(%s & name OXT)"%frag_name,180.0+angle)
                cmd.deprotect(frag_name)

                
            # fix the hydrogen position (if any)
            if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%frag_name)==1:
                if cmd.count_atoms("(hydro and bound_to (name N & (%s)))"%src_sele)==1:
                    cmd.iterate_state(1,"(hydro and bound_to (name N & (%s)))"%src_sele,
                                      "stored.list=[x,y,z]")
                    cmd.alter_state(1,"(hydro and bound_to (name N & (%s)))"%frag_name,
                                    "(x,y,z)=stored.list")
                elif cmd.select(tmp_sele1,"(name C & bound_to (%s and elem N))"%src_sele)==1:
                    # position hydro based on location of the carbonyl
                    angle = cmd.get_dihedral("(%s & name C)"%frag_name,
                                             "(%s & name CA)"%frag_name,
                                             "(%s & name N)"%frag_name,
                                             tmp_sele1)
                    cmd.set_dihedral("(%s & name C)"%frag_name,
                                     "(%s & name CA)"%frag_name,
                                     "(%s & name N)"%frag_name,
                                     "(%s & name H)"%frag_name,180.0+angle)
                    cmd.delete(tmp_sele1)

            # add c-cap (if appropriate)
            if self.c_cap in [ 'amin', 'nmet' ]:
                if not cmd.count_atoms("elem N & !(%s) & (bto. (name C & (%s))) & !resn NME+NHH"%
                                       (src_sele,src_sele)):
                    if cmd.count_atoms("name C & (%s)"%(frag_name))==1:
                        if self.c_cap == 'amin':
                            editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nhh')
                        elif self.c_cap == 'nmet':
                            editor.attach_amino_acid("name C & (%s)"%(frag_name), 'nme')
                        if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name):
                            cmd.h_fix("name N & bound_to (name C & (%s))"%frag_name)
                        # trim hydrogens
                        if (self.hyd == 'none'):
                            cmd.remove("("+frag_name+" and hydro)")
                        elif (self.hyd == 'auto'):
                            if cmd.count_atoms("("+src_sele+") and hydro")==0:
                                cmd.remove("("+frag_name+" and hydro)")
                         
            # add n-cap (if appropriate)
            if self.n_cap in [ 'acet' ]:
                if not cmd.count_atoms("elem C & !(%s) & (bto. (name N & (%s))) & !resn ACE "%
                                       (src_sele,src_sele)):
                    if cmd.count_atoms("name N & (%s)"%(frag_name))==1:
                        if self.n_cap == 'acet':
                            editor.attach_amino_acid("name N & (%s)"%(frag_name), 'ace')
                        if cmd.count_atoms("hydro & bound_to (name N & bound_to (name C & (%s)))"%frag_name):
                            cmd.h_fix("name N & (%s)"%frag_name)
                        # trim hydrogens
                        if (self.hyd == 'none'):
                            cmd.remove("("+frag_name+" and hydro)")
                        elif (self.hyd == 'auto'):
                            if cmd.count_atoms("("+src_sele+") and hydro")==0:
                                cmd.remove("("+frag_name+" and hydro)")
 

                    

        cartoon = (cmd.count_atoms("(%s & name CA & rep cartoon)"%src_sele)>0)
        sticks = (cmd.count_atoms("(%s & name CA & rep sticks)"%src_sele)>0)
            
        cmd.delete(obj_name)
        key = rot_type
        lib = None
        if self.dep == 'dep':
            try:
                result = cmd.phi_psi("%s"%src_sele)
                if len(result)==1:
                    (phi,psi) = list(result.values())[0]
                    (phi,psi) = (int(10*round(phi/10)),int(10*(round(psi/10))))
                    key = (rot_type,phi,psi)
                    if key not in self.dep_library:
                        (phi,psi) = (int(20*round(phi/20)),int(20*(round(psi/20))))
                        key = (rot_type,phi,psi)                    
                        if key not in self.dep_library:
                            (phi,psi) = (int(60*round(phi/60)),int(60*(round(psi/60))))
                            key = (rot_type,phi,psi)
                    lib = self.dep_library.get(key,None)
            except:
                pass
        if lib == None:
            key = rot_type
            lib = self.ind_library.get(key,None)
            if (lib!= None) and self.dep == 'dep':
                print(' Mutagenesis: no phi/psi, using backbone-independent rotamers.')
        if lib != None:
            state = 1
            for a in lib:
                cmd.create(obj_name,frag_name,1,state)
                if state == 1:
                    cmd.select(mut_sele,"(byres (%s like %s))"%(obj_name,src_sele)) 
                if rot_type=='PRO':
                    cmd.unbond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele)
                for b in a.keys():
                    if b!='FREQ':
                        cmd.set_dihedral("(%s & n;%s)"%(mut_sele,b[0]),
                                         "(%s & n;%s)"%(mut_sele,b[1]),
                                         "(%s & n;%s)"%(mut_sele,b[2]),
                                         "(%s & n;%s)"%(mut_sele,b[3]),
                                         a[b],state=state)
                    else:
                        cmd.set_title(obj_name,state,"%1.1f%%"%(a[b]*100))
                if rot_type=='PRO':
                    cmd.bond("(%s & name N)"%mut_sele,"(%s & name CD)"%mut_sele)                
                state = state + 1
            cmd.delete(frag_name)
            print(" Mutagenesis: %d rotamers loaded."%len(lib))
            if self.bump_check:
                cmd.delete(bump_name)
                cmd.create(bump_name,
                "(((byobj %s) within 6 of (%s and not name N+C+CA+O+H+HA)) and (not (%s)))|(%s)"%
                           (src_sele,mut_sele,src_sele,mut_sele),singletons=1)
                cmd.color("gray50",bump_name+" and elem C")
                cmd.set("seq_view",0,bump_name,quiet=1)
                cmd.hide("everything",bump_name)
                if ((cmd.select(tmp_sele1, "(name N & (%s in (neighbor %s)))"%
                                (bump_name,src_sele)) == 1) and
                    (cmd.select(tmp_sele2, "(name C & (%s in %s))"%
                                (bump_name,mut_sele)) == 1)):
                    cmd.bond(tmp_sele1,tmp_sele2)
                if ((cmd.select(tmp_sele1,"(name C & (%s in (neighbor %s)))"%
                                (bump_name,src_sele)) == 1) and
                    (cmd.select(tmp_sele2,"(name N & (%s in %s))"%
                                (bump_name,mut_sele)) == 1)):
                    cmd.bond(tmp_sele1,tmp_sele2)
                cmd.delete(tmp_sele1)
                cmd.delete(tmp_sele2)
                
                cmd.protect("%s and not (%s in (%s and not name N+C+CA+O+H+HA))"%
                            (bump_name,bump_name,mut_sele))
                cmd.sculpt_activate(bump_name)
                cmd.show("cgo",bump_name)
                # draw the bumps
                cmd.set("sculpt_vdw_vis_mode",1,bump_name)
                state = 1
                score_best = 1e6
                for a in lib:
                    score = cmd.sculpt_iterate(bump_name, state, 1)
                    self.bump_scores.append(score)
                    if score < score_best:
                        state_best = state
                        score_best = score
                    state = state + 1
            cmd.delete(mut_sele)
        else:
            cmd.create(obj_name,frag_name,1,1)
            print(" Mutagenesis: no rotamers found in library.")
        cmd.set("seq_view",0,obj_name,quiet=1)
        pymol.util.cbaw(obj_name)
        cmd.hide("("+obj_name+")")
        cmd.show(self.rep,obj_name)
        cmd.show('lines',obj_name) #neighbor  always show lines
        if cartoon:
            cmd.show("cartoon",obj_name)
        if sticks:
            cmd.show("sticks",obj_name)
        cmd.set('auto_zoom',auto_zoom,quiet=1)
        cmd.delete(frag_name)
        cmd.frame(state_best)
        cmd.unpick()
        cmd.feedback("pop")
예제 #12
0
pymol.finish_launching()

if '-h' in args:
    print("help")
else:
    if ('-r' in args) and ('-i' in args) and ('-o' in args) and (
            '-n' in args) and (len(args) == 9):
        prot_a = args[args.index('-r') + 1]
        prot_b = args[args.index('-i') + 1]
        outfile = args[args.index('-o') + 1]
        pos = int(args[args.index('-n') + 1])

        cmd.load(protein)
        cmd.load(loop)
        a_name = os.path.basename(prot_a).split('.')[0]
        b_name = os.path.basename(prot_b).split('.')[0]
        cmd.select("a_s1", "/%s///%d/N" % (a_name, pos))
        cmd.select("a_s2", "/%s///%d/CA" % (a_name, pos))
        cmd.select("a_s3", "/%s///%d/C" % (a_name, pos))
        cmd.select("a_s4", "/%s///%d/CB" % (a_name, pos))
        cmd.select("a_s1", "/%s///%d/N" % (b_name, pos))
        cmd.select("a_s2", "/%s///%d/CA" % (b_name, pos))
        cmd.select("a_s3", "/%s///%d/C" % (b_name, pos))
        cmd.select("a_s4", "/%s///%d/CB" % (b_name, pos))
        out_loop = cmd.select("out_prot", "/%s////" % (b_name))
        cmd.pair_fit("b_s1", "a_s1", "b_s2", "a_s2", "b_s3", "a_s3", "b_s4",
                     "a_s4")
        cmd.save(outfile, "out_prot")
    else:
        print("help")
예제 #13
0
        cmd.select("p_s3", "/%s//%s/%d/C" % (p_name, chain, ini - 2))
        cmd.select("p_s4", "/%s//%s/%d/N" % (p_name, chain, ini - 1))
        cmd.select("p_s5", "/%s//%s/%d/CA" % (p_name, chain, ini - 1))
        cmd.select("p_s6", "/%s//%s/%d/C" % (p_name, chain, ini - 1))
        cmd.select("p_e1", "/%s//%s/%d/N" % (p_name, chain, end + 1))
        cmd.select("p_e2", "/%s//%s/%d/CA" % (p_name, chain, end + 1))
        cmd.select("p_e3", "/%s//%s/%d/C" % (p_name, chain, end + 1))
        cmd.select("p_e4", "/%s//%s/%d/N" % (p_name, chain, end + 2))
        cmd.select("p_e5", "/%s//%s/%d/CA" % (p_name, chain, end + 2))
        cmd.select("p_e6", "/%s//%s/%d/C" % (p_name, chain, end + 2))
        cmd.select("l_s1", "/%s///%d/N" % (l_name, ini - 2))
        cmd.select("l_s2", "/%s///%d/CA" % (l_name, ini - 2))
        cmd.select("l_s3", "/%s///%d/C" % (l_name, ini - 2))
        cmd.select("l_s4", "/%s///%d/N" % (l_name, ini - 1))
        cmd.select("l_s5", "/%s///%d/CA" % (l_name, ini - 1))
        cmd.select("l_s6", "/%s///%d/C" % (l_name, ini - 1))
        cmd.select("l_e1", "/%s///%d/N" % (l_name, end + 1))
        cmd.select("l_e2", "/%s///%d/CA" % (l_name, end + 1))
        cmd.select("l_e3", "/%s///%d/C" % (l_name, end + 1))
        cmd.select("l_e4", "/%s///%d/N" % (l_name, end + 2))
        cmd.select("l_e5", "/%s///%d/CA" % (l_name, end + 2))
        cmd.select("l_e6", "/%s///%d/C" % (l_name, end + 2))
        out_loop = cmd.select("out_loop", "/%s////" % (l_name))
        cmd.pair_fit("l_s1", "p_s1", "l_s2", "p_s2", "l_s3", "p_s3", "l_s4",
                     "p_s4", "l_s5", "p_s5", "l_s6", "p_s6", "l_e1", "p_e1",
                     "l_e2", "p_e2", "l_e3", "p_e3", "l_e4", "p_e4", "l_e5",
                     "p_e5", "l_e6", "p_e6")
        cmd.save(outfile, "out_loop")
    else:
        print("help")
예제 #14
0
def scanFactor( nucleosome, probe, cutoff=2, clashKeep=1, writeModels=False ):
  """
USAGE

  scanFactor nucleosome object,
             probe object,
             probe DNA chain ID,
             distance in Ångstrom below which atoms are considered clashing,
             keep models with fewer than the specified number of residue clashes

  """

  results=[]
  if writeModels:
    dirName =  None
    dirName = ("%s_%s_models" % (nucleosome, probe) )
    if not os.path.exists(dirName):
      os.mkdir("%s" % (dirName) )


  if not cmd.select("polymer.nucleic and %s" % (nucleosome) ) :
    print("\nThe nucleosome object \'%s\' must contain contain DNA – are you sure this is a nucleosome model?\n" % (nucleosome) )
    return

  if not cmd.select("polymer.nucleic and %s" % (probe) ) :
    print("\nThe probe object \'%s\' must contain at least two DNA bases for superposition, the first two of which should correspond\nto the position of the central two bases of the factor's recognition sequence when bound to DNA\n" % (probe) )
    return
      

  # Determine probe DNA chain ID
  cmd.select("probeDNA","polymer.nucleic and %s" % (probe) )
  probeDNAChain = cmd.get_model("probeDNA").atom[0].chain

  # Renumber probe DNA chain to start from 1
  firstBase = []
  firstBase = int(cmd.get_model("%s and chain %s" % (probe, probeDNAChain)).atom[0].resi)
  secondBase = firstBase+1
  offset = firstBase-1

  print ("Renumbering %s chain %s to start at residue 1\n" % (probe, probeDNAChain) )
  cmd.alter("%s and chain %s" % (probe, probeDNAChain), "resi=str(int(resi)-%d)" % (offset) )

  # Remove hydrogens
  print ("\nRemoving hydrogens\n")
  cmd.remove("hydrogens")
  
  # Determine nucleosomal DNA chain IDs
  chains = []
  chains = cmd.get_chains("polymer.nucleic and %s" % (nucleosome) )

  # Loop over nuclesomal DNA
  for chain in chains:

     firstBase = int(cmd.get_model("%s and chain %s" % (nucleosome, chain)).atom[0].resi)
     chainLength = (len(cmd.get_model("polymer and %s and chain %s" % (nucleosome, chain)).get_residues()))
     
     for i in range(firstBase, (firstBase + chainLength) ):

        j=(i+1)
        
        # Handle lack of 5' phosphates (such as on the first base)
        if not cmd.select("%s and chain %s and resi %d and name P" % (nucleosome, chain, i) ) :
           cmd.select("moving", "%s and chain %s and resi 2 and backbone and not (n. P or n. OP1 or n. OP2)" % (probe, probeDNAChain) )
           cmd.select("target", "%s and chain %s and resi %d and backbone and not (n. P or n. OP1 or n. OP2)" % (nucleosome, chain, j) )
        # Handle overhanging superposition for final base
        elif i == (firstBase + chainLength - 1):
           cmd.select("moving", "%s and chain %s and resi 1 and backbone" % (probe, probeDNAChain) )
           cmd.select("target", "%s and chain %s and resi %d and backbone" % (nucleosome, chain, i) )
        else:
           cmd.select("moving", "%s and chain %s and resi 1-2 and backbone" % (probe, probeDNAChain) )
           cmd.select("target", "%s and chain %s and resi %d-%d and backbone" % (nucleosome, chain, i, j) )

        #numAtomMoving=(cmd.count_atoms("moving"))
        #print ("Number of moving atoms: %d" % (numAtomMoving) )
        #numAtomTarget=(cmd.count_atoms("target"))
        #print ("Number of target atoms: %d" % (numAtomTarget) ) 

        alignResult=[]
        alignResult = cmd.pair_fit("moving", "target")
        
        if alignResult:
        
          # alignResult = cmd.super("moving", "target")
          # print ("RMSD after refinement %.4f with %d atoms in alignhment after %d refinement cycles" % (alignResult[0],alignResult[1],alignResult[2]) )
          # print(" ".join('%s' % x for x in alignResult))

          clashes=("clashes")
          # Calculate clashes excluding DNA portion of probe
          cmd.select("%s" % (clashes), "(%s and not chain %s) within %f of %s" % (probe, probeDNAChain, float(cutoff), nucleosome) )
          scoreAtoms = (cmd.count_atoms("%s" % (clashes) ))
          cmd.select("%s" % (clashes), "clashes byres clashes")
          scoreRes = (cmd.count_atoms("%s" % (clashes) + " and name CA"))

          # Write out models (nuclesome + current superimposed probe) for Rosetta scoring
          if  writeModels :
            modelName = None
            modelName = ("%s_probe_%s_%d-%d" % (nucleosome, chain, i, j) )

            editing.copy_to("%s" % (modelName), "(%s or %s)" % (nucleosome, probe) )
            cmd.save("%s/%s.pdb" % (dirName,modelName), "(%s)" % (modelName) )
            cmd.delete("%s" % (modelName) )

         # Retain models with no. residue clashes less than or equal to 'clashKeep'
          if scoreRes < (int(clashKeep)+1):
             editing.copy_to("probe_%s_%d-%d" % (chain, i, j), "%s" % (probe) )
             cmd.group("ClashKeep %s)" % (clashKeep),"nonclashing + probe_%s_%d-%d" % (chain, i, j) )
             cmd.order("probe_*", "yes")

          print ("DNA chain %s bases %d - %d : %s clashes with %d non-hydrogen atoms in %d residues" % (chain, i, j, probe, scoreAtoms, scoreRes) )
          clashes=("%s,%d,%d,%d,%d" % (chain, i, j, scoreAtoms, scoreRes) )
          results.append((clashes))
        # Catch superpostion failures
        else:
            
          print ("DNA chain %s bases %d - %d : %s superpositon failed and clashes were not calculated – check for missing atoms, alternate conformations, or unsual bases at these positions" % (chain, i, j, probe) )
          clashes=("%s,%d,%d,-,-" % (chain, i, j) )
          results.append((clashes))


  with open('%s_scanFactor.csv' % (nucleosome), 'w') as output:
    output.write("DNAchain,start,end,atomClashes,residueClashes\n")
    for i in results:
      output.write("%s\n" % i)
  print ("\nOutput saved to %s_scanFactor.csv\n" % (nucleosome) )
예제 #15
0
    def do_library(self):
        cmd = self.cmd
        pymol = cmd._pymol
        if not (
            (cmd.count_atoms("(%s) and name n" % src_sele) == 1)
            and (cmd.count_atoms("(%s) and name c" % src_sele) == 1)
            and (cmd.count_atoms("(%s) and name o" % src_sele) == 1)
        ):
            self.clear()
            return 1
        cmd.feedback("push")
        cmd.feedback("disable", "selector", "everythin")
        cmd.feedback("disable", "editor", "actions")
        self.prompt = ["Loading rotamers..."]

        pymol.stored.name = "residue"
        cmd.iterate("first (%s)" % src_sele, 'stored.name=model+"/"+segi+"/"+chain+"/"+resn+"`"+resi')
        self.res_text = pymol.stored.name
        cmd.select("_seeker_hilight", src_sele)

        auto_zoom = cmd.get_setting_text("auto_zoom")
        cmd.set("auto_zoom", "0", quiet=1)
        cmd.frame(0)
        cmd.delete(frag_name)
        if self.auto_center:
            cmd.center(src_sele, animate=-1)

        self.lib_mode = self.mode
        if self.lib_mode == "current":
            pymol.stored.resn = ""
            cmd.iterate("(%s and n;ca)" % src_sele, "stored.resn=resn")
            rot_type = _rot_type_xref.get(pymol.stored.resn, pymol.stored.resn)
            if (self.c_cap != "none") or (self.n_cap != "none") or (self.hyd != "auto"):
                self.lib_mode = rot_type  # force fragment-based load
            else:
                cmd.create(frag_name, src_sele, 1, 1)
                if self.c_cap == "open":
                    cmd.remove("%s and name OXT" % frag_name)

        if self.lib_mode != "current":
            rot_type = self.lib_mode
            frag_type = self.lib_mode
            if (self.n_cap == "posi") and (frag_type[0:3] != "NT_"):
                if not (cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) &! r. ace" % (src_sele, src_sele))):
                    # use N-terminal fragment
                    frag_type = "NT_" + frag_type
            if (self.c_cap == "nega") and (frag_type[0:3] != "CT_"):
                if not (cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele))):
                    # use C-terminal fragment
                    frag_type = "CT_" + frag_type
            if rot_type[0:3] in ["NT_", "CT_"]:
                rot_type = rot_type[3:]
            rot_type = _rot_type_xref.get(rot_type, rot_type)
            cmd.fragment(string.lower(frag_type), frag_name)
            # trim off hydrogens
            if self.hyd == "none":
                cmd.remove("(" + frag_name + " and hydro)")
            elif self.hyd == "auto":
                if cmd.count_atoms("(" + src_sele + ") and hydro") == 0:
                    cmd.remove("(" + frag_name + " and hydro)")
            # copy identifying information
            cmd.iterate("(%s and n;ca)" % src_sele, "stored.chain=chain")
            cmd.alter("(%s)" % frag_name, "chain=stored.chain")
            cmd.iterate("(%s and n;ca)" % src_sele, "stored.resi=resi")
            cmd.alter("(%s)" % frag_name, "resi=stored.resi")
            cmd.iterate("(%s and n;ca)" % src_sele, "stored.segi=segi")
            cmd.alter("(%s)" % frag_name, "segi=stored.segi")
            cmd.iterate("(%s and n;ca)" % src_sele, "stored.ss=ss")
            cmd.alter("(%s)" % frag_name, "ss=stored.ss")
            # move the fragment
            if (cmd.count_atoms("(%s and n;cb)" % frag_name) == 1) and (
                cmd.count_atoms("(%s and n;cb)" % src_sele) == 1
            ):
                cmd.pair_fit(
                    "(%s and n;ca)" % frag_name,
                    "(%s and n;ca)" % src_sele,
                    "(%s and n;cb)" % frag_name,
                    "(%s and n;cb)" % src_sele,
                    "(%s and n;c)" % frag_name,
                    "(%s and n;c)" % src_sele,
                    "(%s and n;n)" % frag_name,
                    "(%s and n;n)" % src_sele,
                )
            else:
                cmd.pair_fit(
                    "(%s and n;ca)" % frag_name,
                    "(%s and n;ca)" % src_sele,
                    "(%s and n;c)" % frag_name,
                    "(%s and n;c)" % src_sele,
                    "(%s and n;n)" % frag_name,
                    "(%s and n;n)" % src_sele,
                )

            # fix the carbonyl position...
            cmd.iterate_state(1, "(%s and n;o)" % src_sele, "stored.list=[x,y,z]")
            cmd.alter_state(1, "(%s and n;o)" % frag_name, "(x,y,z)=stored.list")
            if cmd.count_atoms("(%s and n;oxt)" % src_sele):
                cmd.iterate_state(1, "(%s and n;oxt)" % src_sele, "stored.list=[x,y,z]")
                cmd.alter_state(1, "(%s and n;oxt)" % frag_name, "(x,y,z)=stored.list")
            elif cmd.count_atoms("(%s and n;oxt)" % frag_name):  # place OXT if no template exists
                angle = cmd.get_dihedral(
                    "(%s and n;n)" % frag_name,
                    "(%s and n;ca)" % frag_name,
                    "(%s and n;c)" % frag_name,
                    "(%s and n;o)" % frag_name,
                )
                cmd.protect("(%s and n;o)" % frag_name)
                cmd.set_dihedral(
                    "(%s and n;n)" % frag_name,
                    "(%s and n;ca)" % frag_name,
                    "(%s and n;c)" % frag_name,
                    "(%s and n;oxt)" % frag_name,
                    180.0 + angle,
                )
                cmd.deprotect(frag_name)

            # fix the hydrogen position (if any)
            if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % frag_name) == 1:
                if cmd.count_atoms("(elem h and bound_to (n;n and (%s)))" % src_sele) == 1:
                    cmd.iterate_state(1, "(elem h and bound_to (n;n and (%s)))" % src_sele, "stored.list=[x,y,z]")
                    cmd.alter_state(1, "(elem h and bound_to (n;n and (%s)))" % frag_name, "(x,y,z)=stored.list")
                elif cmd.select(tmp_sele1, "(n;c and bound_to (%s and e;n))" % src_sele) == 1:
                    # position hydro based on location of the carbonyl
                    angle = cmd.get_dihedral(
                        "(%s and n;c)" % frag_name, "(%s and n;ca)" % frag_name, "(%s and n;n)" % frag_name, tmp_sele1
                    )
                    cmd.set_dihedral(
                        "(%s and n;c)" % frag_name,
                        "(%s and n;ca)" % frag_name,
                        "(%s and n;n)" % frag_name,
                        "(%s and n;h)" % frag_name,
                        180.0 + angle,
                    )
                    cmd.delete(tmp_sele1)

            # add c-cap (if appropriate)
            if self.c_cap in ["amin", "nmet"]:
                if not cmd.count_atoms("elem n & !(%s) & (bto. (n;c & (%s))) & !r. nme+nhh" % (src_sele, src_sele)):
                    if cmd.count_atoms("n;c & (%s)" % (frag_name)) == 1:
                        if self.c_cap == "amin":
                            editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nhh")
                        elif self.c_cap == "nmet":
                            editor.attach_amino_acid("n;c & (%s)" % (frag_name), "nme")
                        if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name):
                            cmd.h_fix("n;n & bound_to (n;c & (%s))" % frag_name)
                        # trim hydrogens
                        if self.hyd == "none":
                            cmd.remove("(" + frag_name + " and hydro)")
                        elif self.hyd == "auto":
                            if cmd.count_atoms("(" + src_sele + ") and hydro") == 0:
                                cmd.remove("(" + frag_name + " and hydro)")

            # add n-cap (if appropriate)
            if self.n_cap in ["acet"]:
                if not cmd.count_atoms("elem c & !(%s) & (bto. (n;n & (%s))) & !r. ace " % (src_sele, src_sele)):
                    if cmd.count_atoms("n;n & (%s)" % (frag_name)) == 1:
                        if self.n_cap == "acet":
                            editor.attach_amino_acid("n;n & (%s)" % (frag_name), "ace")
                        if cmd.count_atoms("hydro & bound_to (n;n & bound_to (n;c & (%s)))" % frag_name):
                            cmd.h_fix("n;n & (%s)" % frag_name)
                        # trim hydrogens
                        if self.hyd == "none":
                            cmd.remove("(" + frag_name + " and hydro)")
                        elif self.hyd == "auto":
                            if cmd.count_atoms("(" + src_sele + ") and hydro") == 0:
                                cmd.remove("(" + frag_name + " and hydro)")

        cartoon = cmd.count_atoms("(%s and n;ca and rep cartoon)" % src_sele) > 0
        sticks = cmd.count_atoms("(%s and n;ca and rep sticks)" % src_sele) > 0

        cmd.delete(obj_name)
        key = rot_type
        lib = None
        if self.dep == "dep":
            try:
                result = cmd.phi_psi("%s" % src_sele)
                if len(result) == 1:
                    (phi, psi) = result[result.keys()[0]]
                    (phi, psi) = (int(10 * round(phi / 10)), int(10 * (round(psi / 10))))
                    key = (rot_type, phi, psi)
                    if not self.dep_library.has_key(key):
                        (phi, psi) = (int(20 * round(phi / 20)), int(20 * (round(psi / 20))))
                        key = (rot_type, phi, psi)
                        if not self.dep_library.has_key(key):
                            (phi, psi) = (int(60 * round(phi / 60)), int(60 * (round(psi / 60))))
                            key = (rot_type, phi, psi)
                    lib = self.dep_library.get(key, None)
            except:
                pass
        if lib == None:
            key = rot_type
            lib = self.ind_library.get(key, None)
            if (lib != None) and self.dep == "dep":
                print " Mutagenesis: no phi/psi, using backbone-independent rotamers."
        if lib != None:
            state = 1
            for a in lib:
                cmd.create(obj_name, frag_name, 1, state)
                if state == 1:
                    cmd.select(mut_sele, "(byres (%s like %s))" % (obj_name, src_sele))
                if rot_type == "PRO":
                    cmd.unbond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele)
                for b in a.keys():
                    if b != "FREQ":
                        cmd.set_dihedral(
                            "(%s & n;%s)" % (mut_sele, b[0]),
                            "(%s & n;%s)" % (mut_sele, b[1]),
                            "(%s & n;%s)" % (mut_sele, b[2]),
                            "(%s & n;%s)" % (mut_sele, b[3]),
                            a[b],
                            state=state,
                        )
                    else:
                        cmd.set_title(obj_name, state, "%1.1f%%" % (a[b] * 100))
                if rot_type == "PRO":
                    cmd.bond("(%s & name N)" % mut_sele, "(%s & name CD)" % mut_sele)
                state = state + 1
            cmd.delete(frag_name)
            print " Mutagenesis: %d rotamers loaded." % len(lib)
            if self.bump_check:
                cmd.delete(bump_name)
                cmd.create(
                    bump_name,
                    "(((byobj %s) within 6 of (%s and not name n+c+ca+o+h+ha)) and (not (%s)))|(%s)"
                    % (src_sele, mut_sele, src_sele, mut_sele),
                    singletons=1,
                )
                cmd.color("gray50", bump_name + " and elem c")
                cmd.set("seq_view", 0, bump_name, quiet=1)
                cmd.hide("everything", bump_name)
                if (cmd.select(tmp_sele1, "(n;N and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and (
                    cmd.select(tmp_sele2, "(n;C and (%s in %s))" % (bump_name, mut_sele)) == 1
                ):
                    cmd.bond(tmp_sele1, tmp_sele2)
                if (cmd.select(tmp_sele1, "(n;C and (%s in (neighbor %s)))" % (bump_name, src_sele)) == 1) and (
                    cmd.select(tmp_sele2, "(n;N and (%s in %s))" % (bump_name, mut_sele)) == 1
                ):
                    cmd.bond(tmp_sele1, tmp_sele2)
                cmd.delete(tmp_sele1)
                cmd.delete(tmp_sele2)

                cmd.protect("%s and not (%s in (%s and not name n+c+ca+o+h+ha))" % (bump_name, bump_name, mut_sele))
                cmd.sculpt_activate(bump_name)
                cmd.show("cgo", bump_name)
                # draw the bumps
                cmd.set("sculpt_vdw_vis_mode", 1, bump_name)
                state = 1
                for a in lib:
                    cmd.sculpt_iterate(bump_name, state=state)
                    state = state + 1
            cmd.delete(mut_sele)
        else:
            cmd.create(obj_name, frag_name, 1, 1)
            print " Mutagenesis: no rotamers found in library."
        cmd.set("seq_view", 0, obj_name, quiet=1)
        pymol.util.cbaw(obj_name)
        cmd.hide("(" + obj_name + ")")
        cmd.show(self.rep, obj_name)
        cmd.show("lines", obj_name)  # neighbor  always show lines
        if cartoon:
            cmd.show("cartoon", obj_name)
        if sticks:
            cmd.show("sticks", obj_name)
        cmd.set("auto_zoom", auto_zoom, quiet=1)
        cmd.delete(frag_name)
        cmd.frame(0)
        cmd.unpick()
        cmd.feedback("pop")
예제 #16
0
cmd.split_states(target, prefix="Molecule_Name_")
#cmd.split_states(target)
cmd.delete(target)
counter = 0
#target_atom1=''
#target_atom2=''
#target_atom3=''
#target_atom4=''
for object in cmd.get_object_list('(all)'):
    cmd.alter(object, 'resn="' + three_letter_code + '"')
    counter += 1
    if counter == 1:
        target_object = object
        target_atom1 = target_object + ' and name ' + atoms_to_align[0]
        target_atom2 = target_object + ' and name ' + atoms_to_align[1]
        target_atom3 = target_object + ' and name ' + atoms_to_align[2]
    if counter > 1:
        mobile_atom1 = object + ' and name ' + atoms_to_align[0]
        mobile_atom2 = object + ' and name ' + atoms_to_align[1]
        mobile_atom3 = object + ' and name ' + atoms_to_align[2]
        print(target_atom1)
        print(mobile_atom1)
        cmd.pair_fit(mobile_atom1, target_atom1, mobile_atom2, target_atom2,
                     mobile_atom3, target_atom3)
    for element in delete_atoms:
        print("got here")
        cmd.remove('{object} and name {element}'.format(object=object,
                                                        element=element))
cmd.join_states(three_letter_code + '.rotlib', '*')
7
예제 #17
0
def scanDamage(nucleosome, uvddb, cutoff=2, clashKeep=1, writeModels=False):
    """
USAGE

  scanDamage nucleosome object (DNA in chains I and J),
             UVDDB probe object (containing appropriately positioned 2 bp ssDNA in chain Z as residues 1-2 for superpositioning),
             distance in Ångstrom closer than which atoms are considered clashing,
             keep models with fewer than the specified number of clashes,
             write all models (for scoring externally for instance) 

  """

    chains = ['I', 'J']
    results = []
    if writeModels:
        dirName = None
        dirName = ("%s_%s_models" % (nucleosome, uvddb))
        if not os.path.exists(dirName):
            os.mkdir("%s" % (dirName))

    for chain in chains:

        chainLength = (len(
            cmd.get_model("polymer and %s and chain %s" %
                          (nucleosome, chain)).get_residues()))

        for i in range(0, chainLength + 1):
            #        for i in range(130, 146):
            j = (i + 1)

            if chain == 'I':
                comnplementaryChain = 'J'
            elif chain == 'J':
                matchedChain = 'I'

            # Handle lack of 5' phosphate on first nucleotide
            if i == 0:
                cmd.select(
                    "moving",
                    "%s and chain Z and resi 2 and backbone and not (n. P or n. OP1 or n. OP2)"
                    % (uvddb))
                cmd.select(
                    "target",
                    "%s and chain %s and resi %d and backbone and not (n. P or n. OP1 or n. OP2)"
                    % (nucleosome, chain, j))
            elif i == 1:
                cmd.select(
                    "moving",
                    "%s and chain Z and resi 1-2 and backbone and not (n. P or n. OP1 or n. OP2)"
                    % (uvddb))
                cmd.select(
                    "target",
                    "%s and chain %s and resi %d-%d and backbone and not (n. P or n. OP1 or n. OP2)"
                    % (nucleosome, chain, i, j))
            # Handle final base
            elif i == chainLength:
                cmd.select("moving",
                           "%s and chain Z and resi 1 and backbone" % (uvddb))
                cmd.select(
                    "target", "%s and chain %s and resi %d and backbone" %
                    (nucleosome, chain, i))
            else:
                cmd.select(
                    "moving",
                    "%s and chain Z and resi 1-2 and backbone" % (uvddb))
                cmd.select(
                    "target", "%s and chain %s and resi %d-%d and backbone" %
                    (nucleosome, chain, i, j))

            #numAtomMoving=(cmd.count_atoms("moving"))
            #print ("\nNumber of moving atoms: %d" % (numAtomMoving) )
            #numAtomTarget=(cmd.count_atoms("target"))
            #print ("Number of target atoms: %d" % (numAtomTarget) )

            alignResult = []

            alignResult = cmd.pair_fit("moving", "target")
            # alignResult = cmd.super("moving", "target")

            # print ("RMSD after refinement %.4f with %d atoms in alignhment after %d refinement cycles" % (alignResult[0],alignResult[1],alignResult[2]) )
            # print(" ".join('%s' % x for x in alignResult))

            clashes = ("clashes")
            # Calculate clashes excluding DNA portion (chain Z resi 1-2) of UV-DDB probe
            cmd.select(
                "%s" % (clashes), "(%s and not chain Z) within %d of %s" %
                (uvddb, float(cutoff), nucleosome))
            scoreAtoms = (cmd.count_atoms("%s" % (clashes)))
            cmd.select("%s" % (clashes), "clashes byres clashes")
            scoreRes = (cmd.count_atoms("%s" % (clashes) + " and name CA"))

            # Write out models (nucleosome + current superimposed UV-DDB probe) for Rosetta scoring
            if writeModels:
                modelName = None
                modelName = ("%s_uvddb_%s_%d-%d" % (nucleosome, chain, i, j))

                editing.copy_to("%s" % (modelName),
                                "(%s or %s)" % (nucleosome, uvddb))
                cmd.save("%s/%s.pdb" % (dirName, modelName),
                         "(%s)" % (modelName))
                cmd.delete("%s" % (modelName))

            # Retain models with no. residue clashes less than or equal to 'clashKeep'
            if scoreRes < (int(clashKeep) + 1):
                editing.copy_to("uvddb_%s_%d-%d" % (chain, i, j),
                                "%s" % (uvddb))
                cmd.group("ClashKeep %s)" % (clashKeep),
                          "nonclashing + uvddb_%s_%d-%d" % (chain, i, j))
                cmd.order("uvddb_*", "yes")

            print(
                "DNA chain %s bases %d - %d :  UV-DDB clashes atoms %d residues %d "
                % (chain, i, j, scoreAtoms, scoreRes))
            clashes = ("%s,%d,%d,%d,%d" % (chain, i, j, scoreAtoms, scoreRes))
            results.append((clashes))

    with open('%s_scanDamage.csv' % (nucleosome), 'w') as output:
        output.write("DNAchain,start,end,atomClashes,residueClashes\n")
        for i in results:
            output.write("%s\n" % i)
    print("\nOutput saved to %s_scanDamage.csv\n" % (nucleosome))