Esempio n. 1
0
def _special(k,x,y,m=0,_self=cmd): # INTERNAL (invoked when special key is pressed)
    pymol=_self._pymol
    # WARNING: internal routine, subject to change
    k=int(k)
    m=int(m)
    my_special = _self.special
    if(m>0) and (m<5):
        my_special = (_self.special,
                      _self.shft_special,
                      _self.ctrl_special,
                      _self.ctsh_special,
                      _self.alt_special)[m]
    if my_special.has_key(k):
        if my_special[k][1]:
            apply(my_special[k][1],my_special[k][2],my_special[k][3])
        else:
            key = my_special[k][0]
            if(m>0) and (m<5):
                key = ('','SHFT-','CTRL-','CTSH-','ALT-')[m] + key
            if pymol._scene_dict.has_key(key): 
                _self.scene(key)
            elif is_string(pymol._scene_dict_sc.interpret(key+"-")):
                _self.scene(pymol._scene_dict_sc[key+"-"])
            elif pymol._view_dict.has_key(key):
                _self.view(key)
            elif is_string(pymol._view_dict_sc.interpret(key+"-")):
                _self.view(pymol._view_dict_sc[key+"-"])
    return None
Esempio n. 2
0
def _special(k,
             x,
             y,
             m=0,
             _self=cmd):  # INTERNAL (invoked when special key is pressed)
    pymol = _self._pymol
    # WARNING: internal routine, subject to change
    k = int(k)
    m = int(m)
    my_special = _self.special
    if (m > 0) and (m < 5):
        my_special = (_self.special, _self.shft_special, _self.ctrl_special,
                      _self.ctsh_special, _self.alt_special)[m]
    if my_special.has_key(k):
        if my_special[k][1]:
            apply(my_special[k][1], my_special[k][2], my_special[k][3])
        else:
            key = my_special[k][0]
            if (m > 0) and (m < 5):
                key = ('', 'SHFT-', 'CTRL-', 'CTSH-', 'ALT-')[m] + key
            if pymol._scene_dict.has_key(key):
                _self.scene(key)
            elif is_string(pymol._scene_dict_sc.interpret(key + "-")):
                _self.scene(pymol._scene_dict_sc[key + "-"])
            elif pymol._view_dict.has_key(key):
                _self.view(key)
            elif is_string(pymol._view_dict_sc.interpret(key + "-")):
                _self.view(pymol._view_dict_sc[key + "-"])
    return None
Esempio n. 3
0
    def edit_mode(active=1,quiet=1,_self=cmd):
        '''
DESCRIPTION

    "edit_mode" switches the mouse into editing mode, if such a mode
    is available in the current mouse ring.
    
    '''
        # legacy function
        if is_string(active):
            active=boolean_dict[boolean_sc.auto_err(active,'active')]
        active = int(active)
        if len(mouse_ring):
            bm = int(_cmd.get_setting(_self._COb,"button_mode"))
            mouse_mode = mouse_ring[bm]
            if active:
                if mouse_mode[0:10]=='two_button':
                    if mouse_mode!='two_button_editing':
                        mouse(action='two_button_editing',quiet=quiet,_self=_self)
                elif mouse_mode[0:12] == 'three_button':
                    if mouse_mode!='three_button_editing':
                        mouse(action='three_button_editing',quiet=quiet,_self=_self)
            else:
                if mouse_mode[0:10]=='two_button':
                    if mouse_mode!='two_button_viewing':               
                        mouse(action='two_button_viewing',quiet=quiet,_self=_self)
                elif mouse_mode[0:12] == 'three_button':
                    if mouse_mode!='three_button_viewing':
                        mouse(action='three_button_viewing',quiet=quiet,_self=_self)
        return DEFAULT_SUCCESS
Esempio n. 4
0
def _interpret_color(_self,color):
    # WARNING: internal routine, subject to change
    _validate_color_sc(_self)
    new_color = _self.color_sc.interpret(color)
    if new_color:
        if is_string(new_color):
            return new_color
        else:
            _self.color_sc.auto_err(color,'color')
    else:
        return color
Esempio n. 5
0
def _interpret_color(_self, color):
    # WARNING: internal routine, subject to change
    _validate_color_sc(_self)
    new_color = _self.color_sc.interpret(color)
    if new_color:
        if is_string(new_color):
            return new_color
        else:
            _self.color_sc.auto_err(color, 'color')
    else:
        return color
Esempio n. 6
0
    def order(names, sort=0, location='current', _self=cmd):
        '''
DESCRIPTION

    "order" changes the ordering of names in the control panel.

USAGE

    order names, sort, location

ARGUMENTS

    names = string: a space-separated list of names

    sort = yes or no {default: no}

    location = top, current, or bottom {default: current}

EXAMPLES

    order 1dn2 1fgh 1rnd       # sets the order of these three objects
    order *,yes                # sorts all names
    order 1dn2_*, yes          # sorts all names beginning with 1dn2_
    order 1frg, location=top   # puts 1frg at the top of the list

PYMOL API

    cmd.order(string names, string sort, string location)

NOTES

    "order" can also be used to reorder objects within a group.
    
SEE ALSO

    set_name, group
        '''

        r = DEFAULT_ERROR
        location = location_code[location_sc.auto_err(location, 'location')]
        if is_string(sort):
            sort = boolean_dict[boolean_sc.auto_err(sort, 'sort option')]
        try:
            _self.lock(_self)
            r = _cmd.order(_self._COb, str(names), int(sort), int(location))
        finally:
            _self.unlock(r, _self)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Esempio n. 7
0
    def order(names,sort=0,location='current',_self=cmd):
        '''
DESCRIPTION

    "order" changes the ordering of names in the control panel.

USAGE

    order names, sort, location

ARGUMENTS

    names = string: a space-separated list of names

    sort = yes or no {default: no}

    location = top, current, or bottom {default: current}

EXAMPLES

    order 1dn2 1fgh 1rnd       # sets the order of these three objects
    order *,yes                # sorts all names
    order 1dn2_*, yes          # sorts all names beginning with 1dn2_
    order 1frg, location=top   # puts 1frg at the top of the list

PYMOL API

    cmd.order(string names, string sort, string location)

NOTES

    "order" can also be used to reorder objects within a group.
    
SEE ALSO

    set_name, group
        '''

        r = DEFAULT_ERROR
        location=location_code[location_sc.auto_err(location,'location')]
        if is_string(sort):
            sort=boolean_dict[boolean_sc.auto_err(sort,'sort option')]
        try:
            _self.lock(_self)
            r = _cmd.order(_self._COb,str(names),int(sort),int(location))
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException         
        return r
Esempio n. 8
0
    def log_open(filename='log.pml', mode='w', _self=cmd):
        '''
DESCRIPTION

    "log_open" opens a log file for writing.

USAGE

    log_open filename

SEE ALSO

    log, log_close
    
        '''
        pymol = _self._pymol
        if not is_string(filename):  # we're logging to Queue, not a file.
            pymol._log_file = QueueFile(filename)
            _self.set("logging", 1, quiet=1)
        else:
            try:
                try:
                    if hasattr(pymol, "_log_file"):
                        if pymol._log_file != None:
                            pymol._log_file.close()
                            del pymol._log_file
                except:
                    pass
                pymol._log_file = open(filename, mode)
                if _self._feedback(fb_module.cmd,
                                   fb_mask.details):  # redundant
                    if mode != 'a':
                        print " Cmd: logging to '%s'." % filename
                    else:
                        print " Cmd: appending to '%s'." % filename
                if mode == 'a':
                    pymol._log_file.write("\n")  # always start on a new line
                if (re.search(r"\.py$|\.PY$|\.pym$|\.PYM$", filename)):
                    _self.set("logging", 2, quiet=1)
                else:
                    _self.set("logging", 1, quiet=1)
            except:
                print "Error: unable to open log file '%s'" % filename
                pymol._log_file = None
                _self.set("logging", 0, quiet=1)
                traceback.print_exc()
                raise QuietException
Esempio n. 9
0
    def log_open(filename='log.pml', mode='w', _self=cmd):
        '''
DESCRIPTION

    "log_open" opens a log file for writing.

USAGE

    log_open filename

SEE ALSO

    log, log_close
    
        '''
        pymol=_self._pymol
        if not is_string(filename): # we're logging to Queue, not a file.
            pymol._log_file = QueueFile(filename)
            _self.set("logging",1,quiet=1)
        else:
            try:
                try:
                    if hasattr(pymol,"_log_file"):
                        if pymol._log_file!=None:
                            pymol._log_file.close()
                            del pymol._log_file
                except:
                    pass
                pymol._log_file = open(filename,mode)
                if _self._feedback(fb_module.cmd,fb_mask.details): # redundant
                    if mode!='a':
                        print " Cmd: logging to '%s'."%filename
                    else:
                        print " Cmd: appending to '%s'."%filename            
                if mode=='a':
                    pymol._log_file.write("\n") # always start on a new line
                if(re.search(r"\.py$|\.PY$|\.pym$|\.PYM$",filename)):
                    _self.set("logging",2,quiet=1)
                else:
                    _self.set("logging",1,quiet=1)
            except:
                print"Error: unable to open log file '%s'"%filename
                pymol._log_file = None
                _self.set("logging",0,quiet=1)
                traceback.print_exc()
                raise QuietException
Esempio n. 10
0
        def alignto(target=None,method="cealign",quiet=1,_self=cmd, **kwargs):
                """
DESCRIPTION

        "alignto" aligns all other loaded objects to the target
        using the specified alignment algorithm.

USAGE

        alignto target [, method [, quiet ]]

NOTES

        Available alignment methods are "align", "super" and "cealign".

EXAMPLE

        # fetch some calmodulins
        fetch 1cll 1sra 1ggz 1k95, async=0

        # align them to 1cll using cealign
        alignto 1cll, method=cealign
        alignto 1cll, object=all_to_1cll

SEE ALSO

        align, super, cealign, fit, rms, rms_cur, intra_fit
                """
                if cmd.is_string(method):
                    if method in cmd.keyword:
                        method = cmd.keyword[method][0]
                    else:
                        raise CmdException('Unknown method: ' + method)
                names = cmd.get_names("public_objects", 1)
                if not target:
                    target = names[0]
                for x in names:
                        if x == target:
                            continue
                        if not quiet:
                                print "Aligning %s to %s" % (x, target)
                        method(mobile=x, target=target, **kwargs)
Esempio n. 11
0
    def alignto(target=None, method="cealign", quiet=1, _self=cmd, **kwargs):
        """
DESCRIPTION

        "alignto" aligns all other loaded objects to the target
        using the specified alignment algorithm.

USAGE

        alignto target [, method [, quiet ]]

NOTES

        Available alignment methods are "align", "super" and "cealign".

EXAMPLE

        # fetch some calmodulins
        fetch 1cll 1sra 1ggz 1k95, async=0

        # align them to 1cll using cealign
        alignto 1cll, method=cealign
        alignto 1cll, object=all_to_1cll

SEE ALSO

        align, super, cealign, fit, rms, rms_cur, intra_fit
                """
        if cmd.is_string(method):
            if method in cmd.keyword:
                method = cmd.keyword[method][0]
            else:
                raise CmdException('Unknown method: ' + method)
        names = cmd.get_names("public_objects", 1)
        if not target:
            target = names[0]
        for x in names:
            if x == target:
                continue
            if not quiet:
                print "Aligning %s to %s" % (x, target)
            method(mobile=x, target=target, **kwargs)
Esempio n. 12
0
    def edit_mode(active=1, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "edit_mode" switches the mouse into editing mode, if such a mode
    is available in the current mouse ring.
    
    '''
        # legacy function
        if is_string(active):
            active = boolean_dict[boolean_sc.auto_err(active, 'active')]
        active = int(active)
        bm = _self.get_setting_int("button_mode")
        if 0 <= bm < len(mouse_ring):
            mouse_mode = mouse_ring[bm]
            if active:
                if mouse_mode[0:10] == 'two_button':
                    if mouse_mode != 'two_button_editing':
                        mouse(action='two_button_editing',
                              quiet=quiet,
                              _self=_self)
                elif mouse_mode[0:12] == 'three_button':
                    if mouse_mode != 'three_button_editing':
                        mouse(action='three_button_editing',
                              quiet=quiet,
                              _self=_self)
            else:
                if mouse_mode[0:10] == 'two_button':
                    if mouse_mode != 'two_button_viewing':
                        mouse(action='two_button_viewing',
                              quiet=quiet,
                              _self=_self)
                elif mouse_mode[0:12] == 'three_button':
                    if mouse_mode != 'three_button_viewing':
                        mouse(action='three_button_viewing',
                              quiet=quiet,
                              _self=_self)
        return DEFAULT_SUCCESS
Esempio n. 13
0
    def ramp_new(name,
                 map_name,
                 range=[-1.0, 0.0, 1.0],
                 color=['red', [1.0, 1.0, 1.0], 'blue'],
                 state=1,
                 selection='',
                 beyond=2.0,
                 within=6.0,
                 sigma=2.0,
                 zero=1,
                 quiet=1,
                 _self=cmd):
        '''
DESCRIPTION

    "ramp_new" creates a color ramp based on a map potential value or
    based on proximity to a molecular object.
    
USAGE

    ramp_new name, map_name [, range [, color [, state [, selection [,
        beyond [, within [, sigma [, zero ]]]]]]]]

ARGUMENTS

    name = string: name of the ramp object

    map_name = string: name of the map (for potential) or molecular
    object (for proximity)
    
    range = list: values corresponding to slots in the ramp

    color = list: colors corresponding to slots in the ramp

    state = integer: state identifier

    selection = selection: for automatic ranging
    
    beyond = number: with automatic ranging, are we excluding
    values beyond a certain distance from the selection?

    within = number: with automatic ranging, are we only including
    valuess within a certain distance from the selection?

    sigma = number: with automatic ranging, how many standard
    deviations from the mean do we go?

    zero = integer: with automatic ranging, do we force the central
    value to be zero?

EXAMPLES

    ramp_new e_pot_color, e_pot_map, [-10,0,10], [red,white,blue]

NOTES

    Color ramps are extremely powerful but complicated to use.

    In the simplest case, they can be used to color representations
    based on the potential values found in a map object at the
    corresponding positions in space.

    In another simple case, representations can be colored based on
    proximity to a target.  Note that since ramp targets must
    themselves be real objects (not merely selections), the "create"
    command may be needed in order to generate an appropriate target.
    
    In more complicated cases, they can be used to color
    representations on one object based atoms found in another.

    Ramps can operate recursively.  In other words, the output color
    from one ramp can be used as the input color for another.  For
    example, you could color by map potential within a certain
    distance of the target object, beyond which, a uniform color is applied.
    
    
PYMOL API

    def ramp_new(string name, string map_name, list range, list color,
                 int state, string selection, float beyond, float
                 within, float sigma, int zero, int quiet)

SEE ALSO

    load, color, create, slice, gradient
    
    '''
        r = DEFAULT_ERROR
        safe_color = string.strip(str(color))
        if (safe_color[0:1] == "["):  # looks like a list
            color = safe_alpha_list_eval(str(safe_color))
        else:  # looks like a literal
            color = str(color)
        new_color = []
        # preprocess selection
        if selection != '':
            selection = selector.process(selection)
        # coerce range
        try:
            if isinstance(range, str):
                range = safe_list_eval(range)
            range = map(float, range)
        except:
            raise pymol.CmdException('invalid range')
        if is_list(color):
            for a in color:
                if not is_list(a):
                    new_color.append(list(_self.get_color_tuple(
                        a, 4)))  # incl negative RGB special colors
                else:
                    new_color.append(a)
        elif is_string(color):
            new_color = ramp_spectrum_dict[ramp_spectrum_sc.auto_err(
                str(color), 'ramp color spectrum')]
        else:
            new_color = int(color)
        try:
            _self.lock(_self)
            r = _cmd.ramp_new(_self._COb, str(name), str(map_name), range,
                              new_color,
                              int(state) - 1, str(selection), float(beyond),
                              float(within), float(sigma), int(zero),
                              int(quiet))
        finally:
            _self.unlock(r, _self)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Esempio n. 14
0
def _fab(input,name,mode,resi,chain,segi,state,dir,hydro,ss,quiet,_self=cmd):
    r = DEFAULT_ERROR
    code = _fab_codes.get(mode,None)
    quiet = int(quiet)
    resi = int(resi)
    state = int(state)
    dir = int(dir)
    hydro = int(hydro)

    if hydro < 0:
        hydro = not _self.get_setting_boolean("auto_remove_hydrogens")
    
    seq_len = 0
    if (mode == 'peptide') and is_string(input):
        # '123/ ADC B/234/ AFCD' to [ '123/','A','D','C','B/234/','F','C','D' ]
        frags = input.split()
        input = []
        for frag in frags:
            if '/' in frag:
                input.append(frag)
            else:
                seq_len = seq_len + len(frag)
                input.extend(list(frag))
                input.append("/") # breaks chain
    if name == None:
        name = _self.get_unused_name("obj")
#    if mode in [ 'smiles' ]: # small molecule (FUTURE)
#        from chempy.champ import Champ
#        ch = Champ()
#        ch.insert_pattern_string(input)
    if mode in [ 'peptide' ]:  # polymers
        if (seq_len>99) and not quiet:
            print " Generating a %d residue peptide from sequence..."%seq_len
        input.reverse()
        sequence = input
        if code != None:
            while len(sequence):
                while len(sequence) and '/' in sequence[-1]:
                    part = sequence.pop().split('/')
                    if len(part)>1:
                        if len(part[-2]):
                            resi = int(part[-2])
                    if len(part)>2:
                        chain = part[-3]
                    if len(part)>3:
                        segi = part[-4]
                if len(sequence) and not _self.count_atoms("?pk1"): # new polymer segment
                    tmp_obj = _self.get_unused_name()
                    first = sequence.pop()
                    _self.fragment(code[first], tmp_obj)
                    if not hydro:
                        cmd.remove(tmp_obj + ' and hydro')
                    _self.alter(tmp_obj,'resi="""%s""";chain="""%s""";segi="""%s"""'%(resi,chain,segi))
                    _self.create(name,tmp_obj+" or ?"+name,1,state,zoom=0)
                    tmp_sel = _self.get_unused_name()
                    if mode == 'peptide':
                        if dir>0:
                            _self.select(tmp_sel,"name c and "+tmp_obj)
                            resi = resi + 1
                        else:
                            _self.select(tmp_sel,"name n and "+tmp_obj)
                            resi = resi - 1
                    _self.edit(name+" in "+tmp_sel) # set the editor's pk1 selection
                    _self.delete(tmp_sel+" "+tmp_obj)
                if mode == 'peptide':
                    while len(sequence):
                        if '/' in sequence[-1]:
                            _self.unpick() # break chain at this point
                            break
                        if not _self.count_atoms("?pk1"):
                            break
                        else:
                            attach_amino_acid("pk1",code[sequence.pop()],animate=0,ss=ss,hydro=hydro,_self=_self)
                            if dir>0:
                                resi = resi + 1
                            else:
                                resi = resi - 1
    if not len(sequence):
        r = DEFAULT_SUCCESS
Esempio n. 15
0
def feedback(action="?", module="?", mask="?", _self=cmd):
    '''
DESCRIPTION

    "feedback" changes the amount of information output by pymol.

USAGE

    feedback action, module, mask

ARGUMENTS

    action = set, enable, or disable

    module = string: a space-separated list of modules or simply "all"

    mask = string: a space-separated list of output categories or simply "everything"

NOTES

    "feedback" alone will print a list of the available module choices

PYMOL API

    cmd.feedback(string action,string module,string mask)

EXAMPLES

    feedback enable, all , debugging
    feedback disable, selector, warnings actions
    feedback enable, main, blather

    '''
    
    r = None

    # validate action
    if not hasattr(_self,'_fb_dict'):
        _self._fb_dict = copy.deepcopy(_fb_dict)
    if action=="?":
        print " feedback: possible actions: \nset, enable, disable"
        act_int = 0
    else:
        act_kee = fb_action_sc.interpret(action)
        if act_kee == None:
            print "Error: invalid feedback action '%s'."%action
            if _raising(_self=_self):
                raise QuietException
            else:
                return None
        elif not is_string(act_kee):
            print "Error: ambiguous feedback action '%s'."%action
            print action_amb
            if _raising(_self=_self):
                raise QuietException
            else:
                return None
        act_int = int(getattr(fb_action,act_kee))

    if (act_int<3) and ("?" in [action,module,mask]):
        if module=="?":
            print " feedback: Please specify module names:"
            lst = fb_module.__dict__.keys()
            lst.sort()
            for a in lst:
                if a[0]!='_':
                    print "   ",a
        if mask=="?":
            print " feedback: Please specify masks:"
            lst = fb_mask.__dict__.keys()
            lst.sort()
            for a in lst:
                if a[0]!='_':
                    print "   ",a
    else:
        if (act_int>=3):
            module='all'
            mask='everything'

        # validate and combine masks

        mask_int = 0
        mask_lst = string.split(mask)
        for mask in mask_lst:
            mask_kee = fb_mask_sc.interpret(mask)
            if mask_kee == None:
                print "Error: invalid feedback mask '%s'."%mask
                if _raising(_self=_self): raise QuietException
                else: return None
            elif not is_string(mask_kee):
                print "Error: ambiguous feedback mask '%s'."%mask
                if _raising(_self=_self): raise QuietException
                else: return None
            mask_int = int(getattr(fb_mask,mask_kee))

        # validate and iterate modules

        mod_lst = string.split(module)
        for module in mod_lst:
            mod_kee = fb_module_sc.interpret(module)
            if mod_kee == None:
                print "Error: invalid feedback module '%s'."%module
                if _raising(_self=_self): raise QuietException
                else: return None
            elif not is_string(mod_kee):
                print "Error: ambiguous feedback module '%s'."%module
                if _raising(_self=_self): raise QuietException
                else: return None
            mod_int = int(getattr(fb_module,mod_kee))
            if mod_int>=0:
                try:
                    _self.lock(_self)
                    r = _cmd.set_feedback(_self._COb,act_int,mod_int,mask_int)
                finally:
                    _self.unlock(r,_self)
            if mod_int<=0:
                if mod_int:
                    if act_int==0:
                        _self._fb_dict[mod_int] = mask_int
                    elif act_int==1:
                        _self._fb_dict[mod_int] = _self._fb_dict[mod_int] | mask_int
                    elif act_int==2:
                        _self._fb_dict[mod_int] = _self._fb_dict[mod_int] & ( 0xFF - mask_int )
                else:
                    for mod_int in _self._fb_dict.keys():
                        if act_int==0:
                            _self._fb_dict[mod_int] = mask_int
                        elif act_int==1:
                            _self._fb_dict[mod_int] = _self._fb_dict[mod_int] | mask_int
                        elif act_int==2:
                            _self._fb_dict[mod_int] = _self._fb_dict[mod_int] & ( 0xFF - mask_int )
                if _feedback(fb_module.feedback,fb_mask.debugging,_self):
                     sys.stderr.write(" feedback: mode %d on %d mask %d\n"%(
                         act_int,mod_int,mask_int))
    return r
Esempio n. 16
0
def feedback(action="?", module="?", mask="?", _self=cmd):
    '''
DESCRIPTION

    "feedback" changes the amount of information output by pymol.

USAGE

    feedback action, module, mask

ARGUMENTS

    action = set, enable, or disable

    module = string: a space-separated list of modules or simply "all"

    mask = string: a space-separated list of output categories or simply "everything"

NOTES

    "feedback" alone will print a list of the available module choices

PYMOL API

    cmd.feedback(string action,string module,string mask)

EXAMPLES

    feedback enable, all , debugging
    feedback disable, selector, warnings actions
    feedback enable, main, blather

    '''
    
    r = None

    # validate action
    if not hasattr(_self,'_fb_dict'):
        _self._fb_dict = copy.deepcopy(_fb_dict)
    if action=="?":
        print " feedback: possible actions: \nset, enable, disable"
        act_int = 0
    else:
        act_kee = fb_action_sc.interpret(action)
        if act_kee == None:
            print "Error: invalid feedback action '%s'."%action
            if _raising(_self=_self):
                raise QuietException
            else:
                return None
        elif not is_string(act_kee):
            print "Error: ambiguous feedback action '%s'."%action
            print action_amb
            if _raising(_self=_self):
                raise QuietException
            else:
                return None
        act_int = int(getattr(fb_action,act_kee))

    if (act_int<3) and ("?" in [action,module,mask]):
        if module=="?":
            print " feedback: Please specify module names:"
            lst = fb_module.__dict__.keys()
            lst.sort()
            for a in lst:
                if a[0]!='_':
                    print "   ",a
        if mask=="?":
            print " feedback: Please specify masks:"
            lst = fb_mask.__dict__.keys()
            lst.sort()
            for a in lst:
                if a[0]!='_':
                    print "   ",a
    else:
        if (act_int>=3):
            module='all'
            mask='everything'

        # validate and combine masks

        mask_int = 0
        mask_lst = string.split(mask)
        for mask in mask_lst:
            mask_kee = fb_mask_sc.interpret(mask)
            if mask_kee == None:
                print "Error: invalid feedback mask '%s'."%mask
                if _raising(_self=_self): raise QuietException
                else: return None
            elif not is_string(mask_kee):
                print "Error: ambiguous feedback mask '%s'."%mask
                if _raising(_self=_self): raise QuietException
                else: return None
            mask_int |= int(getattr(fb_mask,mask_kee))

        # validate and iterate modules

        mod_lst = string.split(module)
        for module in mod_lst:
            mod_kee = fb_module_sc.interpret(module)
            if mod_kee == None:
                print "Error: invalid feedback module '%s'."%module
                if _raising(_self=_self): raise QuietException
                else: return None
            elif not is_string(mod_kee):
                print "Error: ambiguous feedback module '%s'."%module
                if _raising(_self=_self): raise QuietException
                else: return None
            mod_int = int(getattr(fb_module,mod_kee))
            if mod_int>=0:
                try:
                    _self.lock(_self)
                    r = _cmd.set_feedback(_self._COb,act_int,mod_int,mask_int)
                finally:
                    _self.unlock(r,_self)
            if mod_int<=0:
                if mod_int:
                    if act_int==0:
                        _self._fb_dict[mod_int] = mask_int
                    elif act_int==1:
                        _self._fb_dict[mod_int] = _self._fb_dict[mod_int] | mask_int
                    elif act_int==2:
                        _self._fb_dict[mod_int] = _self._fb_dict[mod_int] & ( 0xFF - mask_int )
                else:
                    for mod_int in _self._fb_dict.keys():
                        if act_int==0:
                            _self._fb_dict[mod_int] = mask_int
                        elif act_int==1:
                            _self._fb_dict[mod_int] = _self._fb_dict[mod_int] | mask_int
                        elif act_int==2:
                            _self._fb_dict[mod_int] = _self._fb_dict[mod_int] & ( 0xFF - mask_int )
                if _feedback(fb_module.feedback,fb_mask.debugging,_self):
                     sys.stderr.write(" feedback: mode %d on %d mask %d\n"%(
                         act_int,mod_int,mask_int))
    return r
Esempio n. 17
0
def _fab(input,name,mode,resi,chain,segi,state,dir,hydro,ss,quiet,_self=cmd):
    r = DEFAULT_ERROR
    code = _fab_codes.get(mode,None)
    quiet = int(quiet)
    resi = int(resi)
    state = int(state)
    dir = int(dir)
    hydro = int(hydro)

    if hydro < 0:
        hydro = not _self.get_setting_boolean("auto_remove_hydrogens")
    
    seq_len = 0
    if (mode == 'peptide') and is_string(input):
        # '123/ ADC B/234/ AFCD' to [ '123/','A','D','C','B/234/','F','C','D' ]
        frags = input.split()
        input = []
        for frag in frags:
            if '/' in frag:
                input.append(frag)
            else:
                seq_len = seq_len + len(frag)
                input.extend(list(frag))
                input.append("/") # breaks chain
    if name == None:
        name = _self.get_unused_name("obj")
#    if mode in [ 'smiles' ]: # small molecule (FUTURE)
#        from chempy.champ import Champ
#        ch = Champ()
#        ch.insert_pattern_string(input)
    if mode in [ 'peptide' ]:  # polymers
        if (seq_len>99) and not quiet:
            print " Generating a %d residue peptide from sequence..."%seq_len
        input.reverse()
        sequence = input
        if code != None:
            while len(sequence):
                while len(sequence) and '/' in sequence[-1]:
                    part = sequence.pop().split('/')
                    if len(part)>1:
                        if len(part[-2]):
                            resi = int(part[-2])
                    if len(part)>2:
                        chain = part[-3]
                    if len(part)>3:
                        segi = part[-4]
                if len(sequence) and not _self.count_atoms("?pk1"): # new polymer segment
                    tmp_obj = _self.get_unused_name()
                    first = sequence.pop()
                    _self.fragment(code[first], tmp_obj)
                    if not hydro:
                        cmd.remove(tmp_obj + ' and hydro')
                    _self.alter(tmp_obj,'resi="""%s""";chain="""%s""";segi="""%s"""'%(resi,chain,segi))
                    _self.create(name,tmp_obj+" or ?"+name,1,1,zoom=0)
                    tmp_sel = _self.get_unused_name()
                    if mode == 'peptide':
                        if dir>0:
                            _self.select(tmp_sel,"name c and "+tmp_obj)
                            resi = resi + 1
                        else:
                            _self.select(tmp_sel,"name n and "+tmp_obj)
                            resi = resi - 1
                    _self.edit(name+" in "+tmp_sel) # set the editor's pk1 selection
                    _self.delete(tmp_sel+" "+tmp_obj)
                if mode == 'peptide':
                    while len(sequence):
                        if '/' in sequence[-1]:
                            _self.unpick() # break chain at this point
                            break
                        if not _self.count_atoms("?pk1"):
                            break
                        else:
                            attach_amino_acid("pk1",code[sequence.pop()],animate=0,ss=ss,hydro=hydro,_self=_self)
                            if dir>0:
                                resi = resi + 1
                            else:
                                resi = resi - 1
    if not len(sequence):
        r = DEFAULT_SUCCESS
Esempio n. 18
0
    def ramp_new(name, map_name, range=[-1.0,0.0,1.0],
                 color=['red',[1.0,1.0,1.0],'blue'], state=1,
                 selection='', beyond=2.0, within=6.0, sigma=2.0,
                 zero=1, quiet=1, _self=cmd):

        '''
DESCRIPTION

    "ramp_new" creates a color ramp based on a map potential value or
    based on proximity to a molecular object.
    
USAGE

    ramp_new name, map_name [, range [, color [, state [, selection [,
        beyond [, within [, sigma [, zero ]]]]]]]]

ARGUMENTS

    name = string: name of the ramp object

    map_name = string: name of the map (for potential) or molecular
    object (for proximity)
    
    range = list: values corresponding to slots in the ramp

    color = list: colors corresponding to slots in the ramp

    state = integer: state identifier

    selection = selection: for automatic ranging
    
    beyond = number: with automatic ranging, are we excluding
    values beyond a certain distance from the selection?

    within = number: with automatic ranging, are we only including
    valuess within a certain distance from the selection?

    sigma = number: with automatic ranging, how many standard
    deviations from the mean do we go?

    zero = integer: with automatic ranging, do we force the central
    value to be zero?

EXAMPLES

    ramp_new e_pot_color, e_pot_map, [-10,0,10], [red,white,blue]

NOTES

    Color ramps are extremely powerful but complicated to use.

    In the simplest case, they can be used to color representations
    based on the potential values found in a map object at the
    corresponding positions in space.

    In another simple case, representations can be colored based on
    proximity to a target.  Note that since ramp targets must
    themselves be real objects (not merely selections), the "create"
    command may be needed in order to generate an appropriate target.
    
    In more complicated cases, they can be used to color
    representations on one object based atoms found in another.

    Ramps can operate recursively.  In other words, the output color
    from one ramp can be used as the input color for another.  For
    example, you could color by map potential within a certain
    distance of the target object, beyond which, a uniform color is applied.
    
    
PYMOL API

    def ramp_new(string name, string map_name, list range, list color,
                 int state, string selection, float beyond, float
                 within, float sigma, int zero, int quiet)

SEE ALSO

    load, color, create, slice, gradient
    
    '''
        r = DEFAULT_ERROR
        safe_color = string.strip(str(color))
        if(safe_color[0:1]=="["): # looks like a list
            color = safe_alpha_list_eval(str(safe_color))
        else: # looks like a literal
            color = str(color)
        new_color = []
        # preprocess selection
        if selection!='':
            selection = selector.process(selection)
        # coerce range
        try:
            if isinstance(range, str):
                range = safe_list_eval(range)
            range = map(float, range)
        except:
            raise pymol.CmdException('invalid range')
        if is_list(color):
            for a in color:
                if not is_list(a):
                    new_color.append(list(_self.get_color_tuple(a,4))) # incl negative RGB special colors
                else:
                    new_color.append(a)
        elif is_string(color):
            new_color = ramp_spectrum_dict[ramp_spectrum_sc.auto_err(str(color),'ramp color spectrum')]
        else:
            new_color=int(color)
        try:
            _self.lock(_self)
            r = _cmd.ramp_new(_self._COb,str(name),str(map_name),range,new_color,
                                    int(state)-1,str(selection),float(beyond),float(within),
                                    float(sigma),int(zero),int(quiet))
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException         
        return r