Exemple #1
0
    def cache(action='optimize', scenes='', state=-1, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "cache" manages storage of precomputed results, such as
    molecular surfaces.

USAGE

    cache action [, scenes [, state ]]

ARGUMENTS

    action = string: enable, disable, read_only, clear, or optimize

    scenes = string: a space-separated list of scene names (default: '')

    state = integer: state index (default: -1)

EXAMPLES

    cache enable
    cache optimize
    cache optimize, F1 F2 F5

NOTES

    "cache optimize" will iterate through the list of scenes provided
    (or all defined scenes), compute any missing surfaces, and store
    them in the cache for later reuse.
    
PYMOL API

    cmd.cache(string action, string scenes, int state, int quiet)

    '''

        r = DEFAULT_ERROR
        action = cache_action_dict[cache_action_sc.auto_err(
            str(action), 'action')]
        quiet = int(quiet)
        if action == 0:  # enable
            r = _self.set('cache_mode', 2, quiet=quiet)
        elif action == 1:  # disable
            r = _self.set('cache_mode', 0, quiet=quiet)
        elif action == 2:  # read_only
            r = _self.set('cache_mode', 1, quiet=quiet)
        elif action == 3:  # clear
            r = _self._cache_clear(_self=_self)
        elif action == 4:  # optimize
            r = DEFAULT_SUCCESS
            _self._cache_mark(_self=_self)
            cur_scene = _self.get('scene_current_name')
            cache_max = int(_self.get('cache_max'))
            if cache_max > 0:
                # allow double memory for an optimized cache
                _self.set('cache_max', cache_max * 2)
            scenes = str(scenes)
            scene_list = string.split(scenes)
            cache_mode = int(_self.get('cache_mode'))
            _self.set('cache_mode', 2)
            if not len(scene_list):
                scene_list = _self.get_scene_list()
            for scene in scene_list:
                scene = string.strip(scene)
                if not quiet:
                    print " cache: optimizing scene '%s'." % scene
                cmd.scene(scene, animate=0)
                cmd.rebuild()
                cmd.refresh()
            if len(cur_scene):
                cmd.scene(cur_scene, animate=0)
            else:
                scene_list = _self.get_scene_list()
                if len(scene_list):
                    cmd.scene(scene_list[0], animate=0)
                else:
                    if not quiet:
                        print " cache: no scenes defined -- optimizing current display."
                    cmd.rebuild()
                    cmd.refresh()
            usage = _self._cache_purge(-1, _self=_self)
            if cache_mode:
                _self.set('cache_mode', cache_mode)
            else:
                _self.set('cache_mode', 2)  # hmm... could use 1 here instead.
            _self.set('cache_max', cache_max)  # restore previous limits
            if not quiet:
                print " cache: optimization complete (~%0.1f MB)." % (
                    usage * 4 / 1000000.0)
        try:
            _self.lock(_self)
        finally:
            _self.unlock(r, _self)
        if _self._raising(r, _self): raise QuietException
        return r
Exemple #2
0
    def cache(action='optimize', scenes='',state=-1, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "cache" manages storage of precomputed results, such as
    molecular surfaces.

USAGE

    cache action [, scenes [, state ]]

ARGUMENTS

    action = string: enable, disable, read_only, clear, or optimize

    scenes = string: a space-separated list of scene names (default: '')

    state = integer: state index (default: -1)

EXAMPLES

    cache enable
    cache optimize
    cache optimize, F1 F2 F5

NOTES

    "cache optimize" will iterate through the list of scenes provided
    (or all defined scenes), compute any missing surfaces, and store
    them in the cache for later reuse.
    
PYMOL API

    cmd.cache(string action, string scenes, int state, int quiet)

    '''
        
        r = DEFAULT_ERROR
        action = cache_action_dict[cache_action_sc.auto_err(str(action),'action')]
        quiet = int(quiet)
        if action == 0: # enable
            r = _self.set('cache_mode',2,quiet=quiet)
        elif action == 1: # disable
            r =_self.set('cache_mode',0,quiet=quiet)
        elif action == 2: # read_only
            r =_self.set('cache_mode',1,quiet=quiet)
        elif action == 3: # clear
            r =_self._cache_clear(_self=_self)
        elif action == 4: # optimize
            r = DEFAULT_SUCCESS
            _self._cache_mark(_self=_self)
            cur_scene = _self.get('scene_current_name')
            cache_max = int(_self.get('cache_max'))
            if cache_max>0:
                # allow double memory for an optimized cache
                _self.set('cache_max',cache_max*2) 
            scenes = str(scenes)
            scene_list = string.split(scenes)
            cache_mode = int(_self.get('cache_mode'))
            _self.set('cache_mode',2)
            if not len(scene_list):
                scene_list = _self.get_scene_list()
            for scene in scene_list:
                scene = string.strip(scene)
                if not quiet:
                    print " cache: optimizing scene '%s'."%scene
                cmd.scene(scene,animate=0)
                cmd.rebuild()                
                cmd.refresh()
            if len(cur_scene):
                cmd.scene(cur_scene,animate=0)
            else:
                scene_list = _self.get_scene_list()
                if len(scene_list):
                    cmd.scene(scene_list[0],animate=0)
                else:
                    if not quiet:
                        print " cache: no scenes defined -- optimizing current display."
                    cmd.rebuild() 
                    cmd.refresh()
            usage = _self._cache_purge(-1,_self=_self)
            if cache_mode:
                _self.set('cache_mode',cache_mode)
            else:
                _self.set('cache_mode',2) # hmm... could use 1 here instead.
            _self.set('cache_max',cache_max) # restore previous limits
            if not quiet:            
                print " cache: optimization complete (~%0.1f MB)."%(usage*4/1000000.0)
        try:
            _self.lock(_self)
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise QuietException         
        return r
Exemple #3
0
def ss(selection="(name ca and alt '',A)",state=1,_self=cmd):
    pymol=_self._pymol
    cmd=_self # NOT THREAD SAFE

    print ' util.ss: WARNING: This is not a "correct" secondary structure'
    print ' util.ss: assignment algorithm!  Please use only as a last resort.'
    
    cmd.feedback("push")
    cmd.feedback("disable","executive","actions")
    
    ss_pref = "_sss"
    sss1 = ss_pref+"1"
    cnt = cmd.select(sss1,"((byres ("+selection+")) and name ca and not het)")
    print " util.ss: initiating secondary structure assignment on %d residues."%cnt
    cas = cmd.index(sss1)
    if not len(cas):
        return
    # set cartoon mode to auto over the selection
    
    cmd.cartoon("auto",sss1)

    print " util.ss: extracting sequence and relationships..."

    # get CA list
    
    res_list = []
    pymol._ss = pymol.Scratch_Storage()
    pymol._ss.res_list = res_list
    cmd.iterate(sss1,'_ss.res_list.append((model,index))')

    # generate atom-to-residue conversion dictionaries

    ca_dict = {}
    n_dict = {}
    o_dict = {}
    scr_dict = {} # scr = segment,chain,resi 
    pymol._ss.n_dict = n_dict
    pymol._ss.o_dict = o_dict
    pymol._ss.scr_dict = scr_dict
    pymol._ss.ca_dict = ca_dict
    cmd.iterate(sss1,
                    '_ss.scr_dict[(model,index)]=(segi,chain,resi)') # CA's
    cmd.iterate("((byres "+sss1+") and n;n)"
                    ,'_ss.scr_dict[(model,index)]=(segi,chain,resi)') # N's
    cmd.iterate("((byres "+sss1+") and n;o)",
                    '_ss.scr_dict[(model,index)]=(segi,chain,resi)') # O's
    cmd.iterate(sss1,
                    '_ss.ca_dict[(segi,chain,resi)] = (model,index)')
    cmd.iterate("((byres "+sss1+") and n;n)",
                    '_ss.n_dict[(segi,chain,resi)] = (model,index)')
    cmd.iterate("((byres "+sss1+") and n;o)",
                    '_ss.o_dict[(segi,chain,resi)] = (model,index)')

    scr_dict[None]=None
    o_dict[None]=None
    n_dict[None]=None
    ca_dict[None]=None
    
    # create special version of cas with gaps

    gap = [None,None,None,None]  
    # gap large enough to distinguish i+4 interations from gaps
    last = None
    for a in res_list:
        if last!=None:
            if(cmd.count_atoms(
                "((neighbor(neighbor(neighbor (%s`%d)))) and (%s`%d))"%
                (last[0],last[1],a[0],a[1]),quiet=1)==0):
                gap.extend([None,None,None,None])
        gap.append(a)
        last = a
    gap.extend([None,None,None,None])

    print " util.ss: analyzing phi/psi angles (slow)..."

    # generate reverse-lookup for gap indices

    ss = {}

    c = 0
    gap_idx = {}
    for a in gap:
        gap_idx[a] = c
        c = c + 1

    # secondary structure database...
    
    ss = {}
    ss[None]=None
    
    # make decisions based on phi/psi

    for a in cas:
        ss[a] = 'L' # default
    phipsi = cmd.get_phipsi(sss1,state)
    for a in phipsi.keys():
        (phi,psi) = phipsi[a]
#      print scr_dict[a],(phi,psi)
        if (phi!=None) and (psi!=None):
            if ((phi<-45) and (phi>-160) and
                 (psi<-170) or (psi>10)): # beta?
                ss[a] = 's'
            elif ((phi<-45) and (phi>-160) and
                    (psi>-80) and (psi<-25)): # helix?
                ss[a] = 'H'
                
    print " util.ss: finding hydrogen bonds..."
    
    # find all pairwise hydrogen bonds and make note of them in dict

    hb = cmd.find_pairs("((byres "+sss1+") and n;n)",
                              "((byres "+sss1+") and n;o)",mode=1,
                              cutoff=3.7,angle=55,
                              state1=state,state2=state)
    
    hb_dict = {}  # [((N-atom) (O-atom))] = 1
    n_hb_dict = {} # [(N-atom)] = [(O-atom),...]
    o_hb_dict = {} # [(O-atom)] = [(N-atom),...]
    for a in hb:
#      cmd.dist("(%s`%d)"%a[0],"(%s`%d)"%a[1])
        hb_dict[a] = 1
        n = a[0]
        o = a[1]
        if not n_hb_dict.has_key(n): n_hb_dict[n]=[]
        if not o_hb_dict.has_key(o): o_hb_dict[o]=[]
        n_hb_dict[n].append(o)
        o_hb_dict[o].append(n)

    # check to insure that all helical residues have at least an i +/- 4
    # hydrogen bond

    for c in xrange(4,len(gap)-4):
        a = gap[c]
        if ss[a]=='H':
            aN = n_dict[scr_dict[a]]
            aO = o_dict[scr_dict[a]]
            am4O = o_dict[scr_dict[gap[c-4]]]
            ap4N = n_dict[scr_dict[gap[c+4]]]
            if not hb_dict.has_key((aN,am4O)):
                if not hb_dict.has_key((ap4N,aO)):
                    ss[a]='L'

    print " util.ss: verifying beta sheets..."
    
    # check to insure that all beta residues have proper interactions

    rep_dict = {}
    repeat = 1
    while repeat:
        repeat = 0
        c = 4
        cc = len(gap)-4
        while c<cc:
            a1 = gap[c]
            if (ss[a1] in ['s','S']) and not rep_dict.has_key(a1):
                rep_dict[a1] = 1
                valid = 0
                scr_a1 = scr_dict[a1]
                # look for antiparallel 2:2 H-bonds (NH-O=C + C=O-HN) 
                n_a1_atom = n_dict[scr_a1]
                o_a1_atom = o_dict[scr_a1]
                if (n_hb_dict.has_key(n_a1_atom) and 
                     o_hb_dict.has_key(o_a1_atom)):
                    for n_hb_atom in n_hb_dict[n_a1_atom]:
                        for o_hb_atom in o_hb_dict[o_a1_atom]:
                            n_hb_scr = scr_dict[n_hb_atom]
                            o_hb_scr = scr_dict[o_hb_atom]
                            if o_hb_scr == n_hb_scr:
                                b1 = ca_dict[o_hb_scr]
                                if abs(c-gap_idx[b1])>2:
                                    ss[b1] = 'S' 
                                    ss[a1] = 'S' 
                                    valid = 1
                # look for antiparallel offset HB (i,i+2,j,j-2)
                a3 = gap[c+2]
                if (a3!=None):
                    scr_a3 = scr_dict[a3]
                    o_a1_atom = o_dict[scr_a1]
                    n_a3_atom = n_dict[scr_a3]
                    if (n_hb_dict.has_key(n_a3_atom) and
                         o_hb_dict.has_key(o_a1_atom)):               
                        for n_hb_atom in n_hb_dict[n_a3_atom]:
                            for o_hb_atom in o_hb_dict[o_a1_atom]:
                                n_hb_scr = scr_dict[n_hb_atom]
                                o_hb_scr = scr_dict[o_hb_atom]
                                b1 = ca_dict[o_hb_scr]
                                if b1!=None:
                                    b1_i = gap_idx[b1]
                                    if abs(c-b1_i)>2: # no turns!
                                        b3 = gap[b1_i-2]
                                        if b3!=None:
                                            b3_scr = scr_dict[b3]
                                            if b3_scr == n_hb_scr:
                                                a2 = gap[c+1]
                                                b2 = gap[gap_idx[b1]-1]
                                                ss[b1] = 'S'
                                                ss[b3] = 'S'
                                                ss[a1] = 'S'
                                                ss[a3] = 'S'
                                                if ss[a2]=='L': ss[a2] = 's'
                                                if ss[b2]=='L': ss[b2] = 's'
                                                valid = 1
                # look for antiparallel offset HB (i,i-2,j,j+2)
                a3 = gap[c-2]
                if (a3!=None):
                    scr_a3 = scr_dict[a3]
                    n_a1_atom = n_dict[scr_a1]
                    o_a3_atom = o_dict[scr_a3]
                    if (n_hb_dict.has_key(n_a1_atom) and
                         o_hb_dict.has_key(o_a3_atom)):               
                        for n_hb_atom in n_hb_dict[n_a1_atom]:
                            for o_hb_atom in o_hb_dict[o_a3_atom]:
                                n_hb_scr = scr_dict[n_hb_atom]
                                o_hb_scr = scr_dict[o_hb_atom]
                                b1 = ca_dict[o_hb_scr]
                                if b1!=None:
                                    b1_i = gap_idx[b1]
                                    if abs(c-b1_i)>2: # no turns!
                                        b3 = gap[b1_i-2]
                                        if b3!=None:
                                            b3_scr = scr_dict[b3]
                                            if b3_scr == n_hb_scr:
                                                a2 = gap[c-1]
                                                b2 = gap[gap_idx[b1]-1]
                                                ss[b1] = 'S'
                                                ss[b3] = 'S'
                                                ss[a1] = 'S'
                                                ss[a3] = 'S'
                                                if ss[a2]=='L': ss[a2] = 's'
                                                if ss[b2]=='L': ss[b2] = 's'
                                                valid = 1
                # look for parallel 1:3 HB (i,j-1,j+1)
                n_a1_atom = n_dict[scr_a1]
                o_a1_atom = o_dict[scr_a1]
                if (n_hb_dict.has_key(n_a1_atom) and
                     o_hb_dict.has_key(o_a1_atom)):
                    for n_hb_atom in n_hb_dict[n_a1_atom]:
                        for o_hb_atom in o_hb_dict[o_a1_atom]:
                            n_hb_scr = scr_dict[n_hb_atom]
                            o_hb_scr = scr_dict[o_hb_atom]
                            b0 = ca_dict[n_hb_scr]
                            if b0!=None:
                                b2 = gap[gap_idx[b0]+2]
                                if b2!=None:
                                    b2_scr = scr_dict[b2]
                                    if b2_scr == o_hb_scr:
                                        b1 = gap[gap_idx[b0]+1]
                                        ss[a1] = 'S' 
                                        ss[b0] = 'S'
                                        if ss[b1]=='L': ss[b1]='s'
                                        ss[b2] = 'S'
                                        valid = 1
                                        repeat = 1
                if not valid:
                    ss[a1] = 'L'
            c = c + 1

    # automatically fill 1 residue gaps in helices and well-defined sheets
    c = 4
    cc = len(gap)-6
    while c<cc:
        a1 = gap[c]
        a3 = gap[c+2]
        ss_a1 = ss[a1]
        ss_a3 = ss[a3]
        if (ss_a1==ss_a3) and (ss_a1 in ['S','H']):
            a2 = gap[c+1]
            ss[a2] = ss_a1
        c = c + 1

    # remove singleton sheet residues
    c = 4
    cc = len(gap)-4
    while c<cc:
        a0 = gap[c-1]
        a1 = gap[c]
        a2 = gap[c+1]
        if ss[a1] in ['s','S']:
            if ((not ss[a0] in ['s','S']) and
                 (not ss[a2] in ['s','S'])):
                 ss[a1] = 'L'
        c = c + 1

    # remove sheet residues which aren't next to another sheet 
    c = 4
    cc = len(gap)-4
    while c<cc:
        a1 = gap[c]
        if ss[a1]=='S':
            a1 = gap[c]
            scr_a1 = scr_dict[a1]
            # look for hydrogen bonds to another sheet
            n_a1_atom = n_dict[scr_a1]
            o_a1_atom = o_dict[scr_a1]
            certain = 0
            if n_hb_dict.has_key(n_a1_atom):
                for n_hb_atom in n_hb_dict[n_a1_atom]:
                    n_hb_ca_atom=ca_dict[scr_dict[n_hb_atom]]
                    if ss[n_hb_ca_atom]=='S':
                        certain = 1
                        break
            if o_hb_dict.has_key(o_a1_atom):
                for o_hb_atom in o_hb_dict[o_a1_atom]:
                    o_hb_ca_atom=ca_dict[scr_dict[o_hb_atom]]
                    if ss[o_hb_ca_atom]=='S':
                        certain = 1
                        break
            if not certain:
                ss[a1] = 's'
        c = c + 1

    # remove questionable sheet residues
    c = 4
    cc = len(gap)-4
    while c<cc:
        a0 = gap[c-1]
        a1 = gap[c]
        a2 = gap[c+1]
        if ss[a1]=='s':
            if (not ((ss[a0]=='S') and (ss[a2]=='S'))):
                ss[a1] = 'L'
        c = c + 1

    # extend helices if hydrogen bonding requirements are met
    rep_dict = {}
    repeat = 1
    while repeat:
        repeat = 0
        c = 4
        cc = len(gap)-4
        while c<cc:
            a = gap[c]
            if not rep_dict.has_key(a):
                if ss[gap[c+1]]=='H':
                    rep_dict[a] = 1
                    if ss[a]!='H': # N-terminal end
                        aO = o_dict[scr_dict[a]]
                        ap4N = n_dict[scr_dict[gap[c+4]]]
                        ap3N = n_dict[scr_dict[gap[c+3]]]
                        if hb_dict.has_key((ap4N,aO)) or hb_dict.has_key((ap3N,aO)):
                            ss[a]='H'
                            repeat = 1
                            c = c - 5
                            if c<4: c=4
                if ss[gap[c-1]]=='H':
                    a = gap[c]
                    if ss[a]!='H': # C-terminal end
                        rep_dict[a] = 1
                        aN = n_dict[scr_dict[a]]
                        am4O = o_dict[scr_dict[gap[c-4]]]
                        am3O = o_dict[scr_dict[gap[c-3]]]
                        if hb_dict.has_key((aN,am4O)) or hb_dict.has_key((aN,am3O)):
                            ss[a]='H'
                            repeat = 1
                            c = c - 5
                            if c<4: c=4
            c = c + 1

    # remove doubleton helices

    c = 4
    cc = len(gap)-5
    while c<cc:
        a0 = gap[c-1]
        a1 = gap[c]
        a2 = gap[c+1]
        a3 = gap[c+2]
        ss_a0 = ss[gap[c-1]]
        ss_a1 = ss[gap[c]]
        ss_a2 = ss[gap[c+1]]
        ss_a3 = ss[gap[c+2]]
        if ss_a1=='H':
            if (ss_a2==ss_a1) and (ss_a0!=ss_a2) and (ss_a2!=ss_a3):
                ss[a1] = 'L'
                ss[a2] = 'L'
        c = c + 1

    # remove totally unreasonable helix and sheet residues

    c = 4
    cc = len(gap)-5
    while c<cc:
        a1 = gap[c]
        ss_a1 = ss[gap[c]]
        if ss_a1=='H':
            if phipsi.has_key(a1):
                (phi,psi) = phipsi[a1]
                if (phi>0) and (phi<150):
                    ss[a1] = 'L'
                elif((psi<-120) or (psi>140)):
                    ss[a1] = 'L'
        elif ss_a1 in ['S','s']:
            if phipsi.has_key(a1):
                (phi,psi) = phipsi[a1]
                if (phi>45) and (phi<160):
                    ss[a1] = 'L'
#            if (psi<-30) and (psi>-150):
                if (psi<-65) and (psi>-150):
                    ss[a1] = 'L'
            
        c = c + 1


    for x in range(1,3):
        # remove singleton sheet residues
        c = 4
        cc = len(gap)-4
        while c<cc:
            a0 = gap[c-1]
            a1 = gap[c]
            a2 = gap[c+1]
            if ss[a1] in ['s','S']:
                if ((not ss[a0] in ['s','S']) and
                     (not ss[a2] in ['s','S'])):
                     ss[a1] = 'L'
            c = c + 1

        # remove sheet residues which aren't next to another sheet 
        c = 4
        cc = len(gap)-4
        while c<cc:
            a1 = gap[c]
            if ss[a1]=='S':
                a1 = gap[c]
                scr_a1 = scr_dict[a1]
                # look for hydrogen bonds to another sheet
                n_a1_atom = n_dict[scr_a1]
                o_a1_atom = o_dict[scr_a1]
                certain = 0
                if n_hb_dict.has_key(n_a1_atom):
                    for n_hb_atom in n_hb_dict[n_a1_atom]:
                        n_hb_ca_atom=ca_dict[scr_dict[n_hb_atom]]
                        if ss[n_hb_ca_atom]=='S':
                            certain = 1
                            break
                if o_hb_dict.has_key(o_a1_atom):
                    for o_hb_atom in o_hb_dict[o_a1_atom]:
                        o_hb_ca_atom=ca_dict[scr_dict[o_hb_atom]]
                        if ss[o_hb_ca_atom]=='S':
                            certain = 1
                            break
                if not certain:
                    ss[a1] = 's'
            c = c + 1

        # remove questionable sheet residues
        c = 4
        cc = len(gap)-4
        while c<cc:
            a0 = gap[c-1]
            a1 = gap[c]
            a2 = gap[c+1]
            if ss[a1]=='s':
                if (not ((ss[a0]=='S') and (ss[a2]=='S'))):
                    ss[a1] = 'L'
            c = c + 1

#      lst = ss.keys()
#      lst.sort()
#      for a in lst: print scr_dict[a],ss[a]
        
    # assign protein
    for a in cas:
        if ss[a]=='s':
            ss[a]='S'
        
    cmd.alter(sss1,"ss ='L'")
    for a in cas:
        if ss[a]!='L':
            cmd.alter("(%s`%d)"%a,"ss='%s'"%ss[a])

    cmd.feedback("pop")

    del pymol._ss # IMPORTANT
    cmd.delete(sss1)
    cmd.rebuild(selection,'cartoon')
    #
#   print conn_hash.keys()
    print " util.ss: assignment complete."
def ColorByDisplacementCA(objSel1, objSel2, super1='all', super2='all', doColor="True", doAlign="True", AlignedWhite='yes'):
    ### First create backup copies; names starting with __ (underscores) are normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        ### Create temp objects
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
	### Align and make create an object aln which indicates which atoms were paired between the two structures
	### Super is must faster than align http://www.pymolwiki.org/index.php/Super
        cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln)
	### Modify the original matrix of object1 from the alignment
        cmd.matrix_copy(tObj1, objSel1)
    else:
        ### Create temp objects
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
	### Align and make create an object aln which indicates which atoms were paired between the two structures
	### Super is must faster than align http://www.pymolwiki.org/index.php/Super
        cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln)
 
    ### Modify the B-factor columns of the original objects,
    ### in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-0.2")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    ### Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    ###  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    ### Iterate over objects
    if AlignedWhite=='yes':
        cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAres.append(resi)")
	cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBres.append(resi)")
    else:
	cmd.iterate(tObj1 + " and n. CA", "stored.alnAres.append(resi)")
        cmd.iterate(tObj2 + " and n. CA", "stored.alnBres.append(resi)")
 
    ### Change the B-factors for EACH object
    displacementUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    ### Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    ### Iterate over objects and get b
    if AlignedWhite=='yes':
	### Iterate over objects which is not aligned
    	cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAnb.append(b)" )
	cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBnb.append(b)" )
    else:
	### Or Iterate over all objects with CA
    	cmd.iterate(tObj1 + " and n. CA", "stored.alnAnb.append(b)" )
    	cmd.iterate(tObj2 + " and n. CA", "stored.alnBnb.append(b)" )
 
    ### Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    ### Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    ### Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByDisplacementCA completed successfully."
    print "The MAXIMUM Displacement is: "+str(max(stored.allRMSDval)) +" residue "+str(stored.alnAres[int(stored.allRMSDval.index(max(stored.allRMSDval)))])
 
    if strTrue(doColor):
        ### Showcase what we did
        #cmd.orient()
        #cmd.hide("all")
        cmd.show("cartoon", objSel1 + " or " + objSel2)
        ### Select the residues not used for alignment; they still have their B-factors as "-0.2"
        cmd.select("notUsedForAln", "b = -0.2")
        ### White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        ### Select the residues not in both pdb files; they have their B-factors as "-0. 01"
        cmd.select("ResNotInBothPDB", "b = -0.01")
        ### White-wash the residues not used for alignment
        cmd.color("black", "ResNotInBothPDB")
        ### Color the residues used for alignment according to their B-factors (Displacment values)
#        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln+ResNotInBothPDB")
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not (notUsedForAln or ResNotInBothPDB)")
        ### Delete the selection of atoms not used for alignment
        ### If you would like to keep this selection intact,
        ### just comment "cmd.delete" line and
        ### uncomment the "cmd.disable" line abowe.
        cmd.disable("notUsedForAln")
        cmd.delete("notUsedForAln")
        cmd.disable("ResNotInBothPDB")
        cmd.delete("ResNotInBothPDB")
 
        print "\nObjects are now colored by C-alpha displacement deviation."
        print "Blue is minimum and red is maximum..."
        print "White is those residues used in the alignment algorithm. Can be turned off in top of algorithm."
	print "Black is residues that does not exist in both files..."
Exemple #5
0
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
    """
    colorByRMSD -- align two structures and show the structural deviations
                   in color to more easily see variable regions.
 
    PARAMS
 
        objSel1 (valid PyMOL object or selection)
            The first object to align.  
 
        objSel2 (valid PyMOL object or selection)
            The second object to align
 
        doAlign (boolean, either True or False)
            Should this script align your proteins or just leave them as is?
            If doAlign=True then your original proteins are aligned.
            If False, then they are not. Regardless, the B-factors are changed.
            DEFAULT: True
 
        doPretty (boolean, either True or False)
            If doPretty=True then a simple representation is created to
            highlight the differences.  If False, then no changes are made.
            DEFAULT: False
 
    RETURNS
        None.
 
    SIDE-EFFECTS
        Modifies the B-factor columns in your original structures.
 
    """
    # First create backup copies; names starting with __ (underscores) are
    # normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
        cmd.matrix_copy(tObj1, objSel1)
    else:
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
 
    # Modify the B-factor columns of the original objects,
    # in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-10")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    # Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    #  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    #  Get the residue identifiers from the alignment object "aln"
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
    # Change the B-factors for EACH object
    rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    # Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
    # Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    # Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    # Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByRMSD completed successfully."
    print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval))
    print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval))
 
    if doPretty!=None:
        # Showcase what we did
        cmd.orient()
        cmd.hide("all")
        cmd.show_as("cartoon", objSel1 + " or " + objSel2)
        # Select the residues not used for alignment; they still have their B-factors as "-10"
        cmd.select("notUsedForAln", "b < 0")
        # White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        # Color the residues used for alignment according to their B-factors (RMSD values)
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
        # Delete the selection of atoms not used for alignment
        # If you would like to keep this selection intact,
        # just comment "cmd.delete" line and
        # uncomment the "cmd.disable" line below.
        cmd.delete("notUsedForAln")
        # cmd.disable("notUsedForAln") 
 
        print "\nObjects are now colored by C-alpha RMS deviation."
        print "All residues with RMSD values greater than the maximum are colored white..."
Exemple #6
0
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
    """
    colorByRMSD -- align two structures and show the structural deviations
                   in color to more easily see variable regions.
 
    PARAMS
 
        objSel1 (valid PyMOL object or selection)
            The first object to align.  
 
        objSel2 (valid PyMOL object or selection)
            The second object to align
 
        doAlign (boolean, either True or False)
            Should this script align your proteins or just leave them as is?
            If doAlign=True then your original proteins are aligned.
            If False, then they are not. Regardless, the B-factors are changed.
            DEFAULT: True
 
        doPretty (boolean, either True or False)
            If doPretty=True then a simple representation is created to
            highlight the differences.  If False, then no changes are made.
            DEFAULT: False
 
    RETURNS
        None.
 
    SIDE-EFFECTS
        Modifies the B-factor columns in your original structures.
 
    """
    # First create backup copies; names starting with __ (underscores) are
    # normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
        cmd.matrix_copy(tObj1, objSel1)
    else:
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
 
    # Modify the B-factor columns of the original objects,
    # in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-10")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
    # Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    #  Create lists for storage
    stored.alnAres, stored.alnBres = [], []
 
    #  Get the residue identifiers from the alignment object "aln"
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
    # Change the B-factors for EACH object
    rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
    # Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
    # Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    # Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    # Provide some useful information
    stored.allRMSDval = []
    stored.allRMSDval = stored.alnAnb + stored.alnBnb
    print "\nColorByRMSD completed successfully."
    print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval))
    print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval))
 
    if doPretty!=None:
        # Showcase what we did
        cmd.orient()
        cmd.hide("all")
        cmd.show_as("cartoon", objSel1 + " or " + objSel2)
        # Select the residues not used for alignment; they still have their B-factors as "-10"
        cmd.select("notUsedForAln", "b < 0")
        # White-wash the residues not used for alignment
        cmd.color("white", "notUsedForAln")
        # Color the residues used for alignment according to their B-factors (RMSD values)
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
        # Delete the selection of atoms not used for alignment
        # If you would like to keep this selection intact,
        # just comment "cmd.delete" line and
        # uncomment the "cmd.disable" line below.
        cmd.delete("notUsedForAln")
        # cmd.disable("notUsedForAln") 
 
        print "\nObjects are now colored by C-alpha RMS deviation."
        print "All residues with RMSD values greater than the maximum are colored white..."