Example #1
0
    def index(selection="(all)", quiet=1, _self=cmd):
        '''
DESCRIPTION

    "index" returns a list of tuples corresponding to the
    object name and index of the atoms in the selection.

PYMOL API

    list = cmd.index(string selection="(all)")

NOTE

  Atom indices are fragile and will change as atoms are added
  or deleted.  Whenever possible, use integral atom identifiers
  instead of indices.

        '''
        # preprocess selection
        selection = selector.process(selection)
        #
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.index(_self._COb, "(" + str(selection) + ")",
                           0)  # 0 = default mode
        finally:
            _self.unlock(r, _self)
        if not quiet:
            if is_list(r):
                if len(r):
                    for a in r:
                        print " cmd.index: (%s`%d)" % (a[0], a[1])
        if _raising(r, _self): raise pymol.CmdException
        return r
Example #2
0
    def get_symmetry(selection="(all)",quiet=1,_self=cmd):
        '''
DESCRIPTION

    "get_symmetry" can be used to obtain the crystal
    and spacegroup parameters for a molecule
    (FUTURE - map object - FUTURE)

USAGE

    get_symmetry object-name-or-selection

PYMOL API

    cmd.get_symmetry(string selection)


        '''
        r = DEFAULT_ERROR
        selection = selector.process(selection)
        try:
            _self.lock(_self)
            r = _cmd.get_symmetry(_self._COb,str(selection))
            if not quiet:
                if(is_list(r)):
                    if(len(r)):
                        print " get_symmetry: A     = %7.3f B    = %7.3f C     = %7.3f"%tuple(r[0:3])
                        print " get_symmetry: Alpha = %7.3f Beta = %7.3f Gamma = %7.3f"%tuple(r[3:6])
                        print " get_symmetry: SpaceGroup = %s"%r[6]
                    else:
                        print " get_symmetry: No symmetry defined."
        finally:
            _self.unlock(r,_self)
        if _raising(r,_self): raise pymol.CmdException
        return r
Example #3
0
    def do(commands, log=1, echo=1, flush=0, _self=cmd):
        # WARNING: don't call this routine if you already have the API lock
        # use cmd._do instead
        '''
DESCRIPTION

    "do" makes it possible for python programs to issue simple PyMOL
    commands as if they were entered on the command line.

PYMOL API

    cmd.do( commands )

USAGE (PYTHON)

    from pymol import cmd
    cmd.do("load file.pdb")
        '''
        r = DEFAULT_ERROR
        log = int(log)
        if is_list(commands):
            cmmd_list = commands
        else:
            cmmd_list = [commands]
        n_cmmd = len(cmmd_list)
        if n_cmmd > 1:  # if processing a list of commands, defer updates
            defer = _self.get_setting_legacy("defer_updates")
            _self.set('defer_updates', 1)
        for cmmd in cmmd_list:
            lst = string.split(string.replace(cmmd, chr(13), chr(10)), chr(10))
            if len(lst) < 2:
                for a in lst:
                    if (len(a)):
                        try:
                            _self.lock(_self)
                            r = _cmd.do(_self._COb, a, log, echo)
                        finally:
                            _self.unlock(r, _self)
                    else:
                        r = DEFAULT_SUCCESS
            else:
                try:
                    _self.lock(_self)
                    do_flush = flush or (
                        (thread.get_ident() == _self._pymol.glutThread)
                        and _self.lock_api_allow_flush)
                    for a in lst:
                        if len(a):
                            r = _cmd.do(_self._COb, a, log, echo)
                            if do_flush:
                                _self.unlock(r, _self)  # flushes
                                _self.lock(_self)
                        else:
                            r = DEFAULT_SUCCESS
                finally:
                    _self.unlock(r, _self)
        if n_cmmd > 1:
            _self.set('defer_updates', defer)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Example #4
0
    def index(selection="(all)",quiet=1,_self=cmd):
        '''
DESCRIPTION

    "index" returns a list of tuples corresponding to the
    object name and index of the atoms in the selection.

PYMOL API

    list = cmd.index(string selection="(all)")

NOTE

  Atom indices are fragile and will change as atoms are added
  or deleted.  Whenever possible, use integral atom identifiers
  instead of indices.

        '''
        # preprocess selection
        selection = selector.process(selection)
        #      
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.index(_self._COb,"("+str(selection)+")",0) # 0 = default mode
        finally:
            _self.unlock(r,_self)
        if not quiet:
            if is_list(r):
                if len(r):
                    for a in r:
                        print " cmd.index: (%s`%d)"%(a[0],a[1])
        if _raising(r,_self): raise pymol.CmdException
        return r
Example #5
0
    def do(commands,log=1,echo=1,flush=0,_self=cmd):
        # WARNING: don't call this routine if you already have the API lock
        # use cmd._do instead
        '''
DESCRIPTION

    "do" makes it possible for python programs to issue simple PyMOL
    commands as if they were entered on the command line.

PYMOL API

    cmd.do( commands )

USAGE (PYTHON)

    from pymol import cmd
    cmd.do("load file.pdb")
        '''
        r = DEFAULT_ERROR
        log = int(log)
        if is_list(commands):
            cmmd_list = commands
        else:
            cmmd_list = [ commands ]
        n_cmmd = len(cmmd_list)
        if n_cmmd>1: # if processing a list of commands, defer updates
            defer = _self.get_setting_legacy("defer_updates")
            _self.set('defer_updates',1)
        for cmmd in cmmd_list:
            lst = string.split(string.replace(cmmd,chr(13),chr(10)),chr(10))
            if len(lst)<2:
                for a in lst:
                    if(len(a)):
                        try:
                            _self.lock(_self)
                            r = _cmd.do(_self._COb,a,log,echo)
                        finally:
                            _self.unlock(r,_self)
                    else:
                        r = DEFAULT_SUCCESS
            else:
                try:
                    _self.lock(_self)
                    do_flush = flush or ((thread.get_ident() == _self._pymol.glutThread)
                                         and _self.lock_api_allow_flush)
                    for a in lst:
                        if len(a):
                            r = _cmd.do(_self._COb,a,log,echo)
                            if do_flush:
                                _self.unlock(r,_self) # flushes
                                _self.lock(_self)
                        else:
                            r = DEFAULT_SUCCESS
                finally:
                    _self.unlock(r,_self)
        if n_cmmd>1:
            _self.set('defer_updates',defer)
        if _self._raising(r,_self): raise pymol.CmdException
        return r
Example #6
0
    def pseudoatom(object='', selection='', name='PS1', resn='PSD', resi='1', chain='P',
                   segi='PSDO', elem='PS', vdw=-1.0, hetatm=1, b=0.0, q=0.0, color='',
                   label='', pos=None, state=0, mode='rms', quiet=1,_self=cmd):
        '''
        
DESCRIPTION

    "pseudoatom" adds a pseudoatom to a molecular object, and will
    creating the molecular object if it does not yet exist.
    
USAGE

    pseudoatom object [, selection [, name [, resn [, resi [, chain
        [, segi [, elem [, vdw [, hetatm [, b [, q [, color [, label
        [, pos [, state [, mode [, quiet ]]]]]]]]]]]]]]]]]

NOTES

    "pseudoatom" can be used for a wide variety of random tasks where
    on must place an atom or a label in 3D space.
    
    '''
        
        r = DEFAULT_ERROR      
        # preprocess selection
        if len(color):
            color = _self.get_color_index(str(color))
        else:
            color = -1 # default
        object = str(object)
        if not len(object):
            object = _self.get_unused_name(prefix="pseudo")
        selection = selector.process(selection)
        mode = pseudoatom_mode_dict[pseudoatom_mode_sc.auto_err(str(mode),'pseudoatom mode')]
        
        (name,resn,resi,chain,segi,elem,label) = map(unquote,(name,resn,resi,chain,segi,elem,label))
        #      
        try:
            _self.lock(_self)
            if pos!=None:
                if not (is_list(pos) or is_tuple(pos)):
                    pos = safe_list_eval(pos)
                pos = (float(pos[0]), # tuple-ize
                       float(pos[1]),
                       float(pos[2]))
            if len(selection.split())>1:
                selection = "("+str(selection)+")"
            r = _cmd.pseudoatom(_self._COb,str(object), str(selection),
                                str(name), str(resn), str(resi), str(chain),
                                str(segi), str(elem), float(vdw), int(hetatm),
                                float(b), float(q), str(label), pos, int(color),
                                int(state)-1, int(mode), int(quiet))
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException                                    
        return r
Example #7
0
 def _get_dump_str(obj):
     if is_list(obj):
         list = map(_get_dump_str,obj)
         result = "[ "+string.join(list,",\n")+" ] "
     elif is_dict(obj):
         list = []
         for key in obj.keys():
             list.append( _get_dump_str(key)+" : "+_get_dump_str(obj[key]) )
         result = "{ "+string.join(list,",\n")+" } "
     elif is_tuple(obj):
         list = map(_get_dump_str,obj)
         result = "( "+string.join(list,",\n")+" ) "
     else:
         result = str(obj)
     return result
Example #8
0
 def _get_dump_str(obj):
     if is_list(obj):
         list = map(_get_dump_str,obj)
         result = "[ "+string.join(list,",\n")+" ] "
     elif is_dict(obj):
         list = []
         for key in obj.keys():
             list.append( _get_dump_str(key)+" : "+_get_dump_str(obj[key]) )
         result = "{ "+string.join(list,",\n")+" } "
     elif is_tuple(obj):
         list = map(_get_dump_str,obj)
         result = "( "+string.join(list,",\n")+" ) "
     else:
         result = str(obj)
     return result
Example #9
0
    def get_object_list(selection="(all)", quiet=1, _self=cmd):
        '''
        
DESCRIPTION

    "get_object_list" is an unsupported command that may have
    something to do with querying the objects covered by a selection.
    '''

        r = DEFAULT_ERROR
        selection = selector.process(selection)
        try:
            _self.lock(_self)
            r = _cmd.get_object_list(_self._COb, str(selection))
            if not quiet:
                if (is_list(r)):
                    print " get_object_list: ", str(r)
        finally:
            _self.unlock(r, _self)
        if _raising(r, _self): raise pymol.CmdException
        return r
Example #10
0
    def get_object_list(selection="(all)", quiet=1, _self=cmd):
        '''
        
DESCRIPTION

    "get_object_list" is an unsupported command that may have
    something to do with querying the objects covered by a selection.
    '''
        
        r = DEFAULT_ERROR
        selection = selector.process(selection)
        try:
            _self.lock(_self)
            r = _cmd.get_object_list(_self._COb,str(selection))
            if not quiet:
                if(is_list(r)):
                    print " get_object_list: ",str(r)
        finally:
            _self.unlock(r,_self)
        if _raising(r,_self): raise pymol.CmdException
        return r
Example #11
0
    def volume_color(name, colors, _self=cmd):
        """
DESCRIPTION -- untested do not use
ALSO -- this belongs in a different module
        """
        if not (is_list(colors) or is_tuple(colors)):
            colors = safe_list_eval(colors)
        # tuple of tuples to list of float
        cList = []
        map(lambda x: cList.extend(x), colors)
        cList = map(lambda x: float(x), cList)

        try:
            _self.lock(_self)
            r = _cmd.volume_color(_self._COb, str(name), cList)
        finally:
            _self.unlock(r, _self)

        if _self._raising(r, _self): raise pymol.CmdException

        # unlock and then use this to differentiate our viz
        return r
Example #12
0
    def volume_color(name, colors, _self=cmd):
        """
DESCRIPTION -- untested do not use
ALSO -- this belongs in a different module
        """
        if not (is_list(colors) or is_tuple(colors)):
            colors = safe_list_eval(colors)
        # tuple of tuples to list of float
        cList = []
        map(lambda x: cList.extend(x), colors)
        cList = map(lambda x: float(x), cList)

        try:
            _self.lock(_self)
            r = _cmd.volume_color(_self._COb, str(name), cList)
        finally:
            _self.unlock(r,_self)
        
        if _self._raising(r,_self): raise pymol.CmdException

        # unlock and then use this to differentiate our viz
        return r        
Example #13
0
    def identify(selection="(all)", mode=0, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "identify" returns a list of atom IDs corresponding to the ID code
    of atoms in the selection.

PYMOL API

    list = cmd.identify(string selection="(all)",int mode=0)

NOTES

    mode 0: only return a list of identifiers (default)
    mode 1: return a list of tuples of the object name and the identifier

        '''
        # preprocess selection
        selection = selector.process(selection)
        #
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.identify(_self._COb, "(" + str(selection) + ")",
                              int(mode))  # 0 = default mode
        finally:
            _self.unlock(r, _self)
        if is_list(r):
            if len(r):
                if not quiet:
                    if mode:
                        for a in r:
                            print " cmd.identify: (%s and id %d)" % (a[0],
                                                                     a[1])
                    else:
                        for a in r:
                            print " cmd.identify: (id %d)" % a
        if _raising(r, _self): raise pymol.CmdException
        return r
Example #14
0
    def identify(selection="(all)",mode=0,quiet=1,_self=cmd):
        '''
DESCRIPTION

    "identify" returns a list of atom IDs corresponding to the ID code
    of atoms in the selection.

PYMOL API

    list = cmd.identify(string selection="(all)",int mode=0)

NOTES

    mode 0: only return a list of identifiers (default)
    mode 1: return a list of tuples of the object name and the identifier

        '''
        # preprocess selection
        selection = selector.process(selection)
        #
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.identify(_self._COb,"("+str(selection)+")",int(mode)) # 0 = default mode
        finally:
            _self.unlock(r,_self)
        if is_list(r):
            if len(r):
                if not quiet:
                    if mode:
                        for a in r:
                            print " cmd.identify: (%s and id %d)"%(a[0],a[1])
                    else:
                        for a in r:
                            print " cmd.identify: (id %d)"%a
        if _raising(r,_self): raise pymol.CmdException
        return r
Example #15
0
    def get_symmetry(selection="(all)", state=-1, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "get_symmetry" can be used to obtain the crystal
    and spacegroup parameters for a molecule or map.

USAGE

    get_symmetry object-name-or-selection

PYMOL API

    cmd.get_symmetry(string selection, int state, int quiet)


        '''
        r = DEFAULT_ERROR
        selection = selector.process(selection)
        try:
            _self.lock(_self)
            r = _cmd.get_symmetry(_self._COb, str(selection), int(state))
            if not quiet:
                if (is_list(r)):
                    if (len(r)):
                        print " get_symmetry: A     = %7.3f B    = %7.3f C     = %7.3f" % tuple(
                            r[0:3])
                        print " get_symmetry: Alpha = %7.3f Beta = %7.3f Gamma = %7.3f" % tuple(
                            r[3:6])
                        print " get_symmetry: SpaceGroup = %s" % r[6]
                    else:
                        print " get_symmetry: No symmetry defined."
        finally:
            _self.unlock(r, _self)
        if _raising(r, _self): raise pymol.CmdException
        return r
Example #16
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
Example #17
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
Example #18
0
    def map_new(name, type='gaussian', grid=None, selection="(all)",
                buffer=None, box=None, state=0, quiet=1, zoom=0,
                normalize=-1, clamp=[1.0,-1.0], resolution=0.0, _self=cmd):

        '''

DESCRIPTION

    "map_new" creates a map object using one of the built-in map
    generation routines.  This command not yet fully supported.

USAGE

    map_new name [, type [, grid [, selection [, buffer [, box [, state ]]]]]]

ARGUMENTS

    name = string: name of the map object to create or modify
	
    type = vdw, gaussian, gaussian_max, coulomb, coulomb_neutral, coulomb_local

    grid = float: grid spacing

    selection = string: atoms about which to generate the map

    buffer = float: cutoff 
    
    state > 0: use the indicated state
    
    state = 0: use all states independently with independent extents
    
    state = -1: use current global state
    
    state = -2: use effective object state(s)
    
    state = -3: use all states in one map
    
    state = -4: use all states independent states by with a unified extent

NOTES

    This command can be used to create low-resolution surfaces of
    protein structures.
    
    '''
        # preprocess selection
        r = DEFAULT_ERROR
        selection = selector.process(selection)
        if box!=None: # box should be [[x1,y1,z1],[x2,y2,z2]]
            if _self.is_string(box):
                box = safe_list_eval(box)
            box = (float(box[0][0]),
                   float(box[0][1]),
                   float(box[0][2]),
                   float(box[1][0]),
                   float(box[1][1]),
                   float(box[1][2]))
            box_flag = 1
        else:
            box = (0.0,0.0,0.0,1.0,1.0,1.0)
            box_flag = 0
        if grid==None:
            grid = _self.get_setting_legacy('gaussian_resolution')/3.0
        if buffer==None:
            buffer = _self.get_setting_legacy('gaussian_resolution')
        grid = float(grid) # for now, uniform xyz; later (x,y,z)

        if not is_list(clamp):
            clamp = safe_list_eval(str(clamp))
        if len(clamp)<2:
            clamp = [1.0,-1.0]
        type = map_type_dict[map_type_sc.auto_err(str(type),'map type')]
        try:
            _self.lock(_self)
            r = _cmd.map_new(_self._COb,str(name),int(type),grid,str(selection),
                             float(buffer),box,int(state)-1,
                             int(box_flag),int(quiet),int(zoom),int(normalize),
                             float(clamp[0]),float(clamp[1]),float(resolution))
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException         
        return r
Example #19
0
 def __init__(self, self_cmd, sele, state=-1, message=None):
     self.cmd = self_cmd
     if message == '':
         message = None
     if state < 1:
         state = self_cmd.get_state()
     # this code will moved elsewhere
     ok = 1
     try:
         from freemol import mengine
     except:
         ok = 0
         print "Error: unable to import freemol.mengine module."
         print "This PyMOL build appears not to include full modeling capabilities."
     if ok:
         if not mengine.validate():
             ok = 0
             print "Error: Unable to validate freemol.mengine"
     if ok:
         if self_cmd.count_atoms(sele) > 999:
             ok = 0
             print "Error: Sorry, clean is currently limited to 999 atoms"
     if not ok:
         pass
         # we can't call warn because this is the not the tcl-tk gui thread
         # warn("Please be sure that FreeMOL is correctly installed.")
     else:
         if message != None:
             self.cmd.do("_ cmd.wizard('message','''%s''')" % message)
         obj_list = self_cmd.get_object_list("bymol (" + sele + ")")
         ok = 0
         result = None
         if is_list(obj_list) and (len(obj_list) == 1):
             obj_name = obj_list[0]
             self_cmd.sculpt_deactivate(obj_name)
             # eliminate all sculpting information for object
             self.cmd.sculpt_purge()
             self.cmd.set("sculpting", 0)
             state = self_cmd.get_state()
             if self_cmd.count_atoms(
                     obj_name + " and flag 2"):  # any atoms restrained?
                 self_cmd.reference(
                     "validate", obj_name,
                     state)  # then we have reference coordinates
             input_model = self_cmd.get_model(obj_name, state=state)
             (fit_flag, sdf_list) = model_to_sdf_list(self_cmd, input_model)
             input_sdf = string.join(sdf_list, '')
             #                print input_sdf
             result = mengine.run(input_sdf)
             if result != None:
                 if len(result):
                     clean_sdf = result[0]
                     clean_rec = clean_sdf.split("$$$$")[0]
                     energy = get_energy_from_rec(clean_rec)
                     if len(clean_rec) and int(energy) != 9999:
                         clean_name = "builder_clean_tmp"
                         self_cmd.set("suspend_updates")
                         try:
                             self_cmd.read_molstr(clean_rec,
                                                  clean_name,
                                                  zoom=0)
                             # need to insert some error checking here
                             if clean_name in self_cmd.get_names("objects"):
                                 self_cmd.set("retain_order", "1",
                                              clean_name)
                                 if fit_flag:
                                     self_cmd.fit(clean_name,
                                                  obj_name,
                                                  matchmaker=4,
                                                  mobile_state=1,
                                                  target_state=state)
                                 self_cmd.push_undo(obj_name)
                                 self_cmd.update(obj_name,
                                                 clean_name,
                                                 matchmaker=0,
                                                 source_state=1,
                                                 target_state=state)
                                 self_cmd.sculpt_activate(obj_name)
                                 self_cmd.sculpt_deactivate(obj_name)
                                 ok = 1
                         finally:
                             self_cmd.delete(clean_name)
                             self_cmd.unset("suspend_updates")
         if not ok:
             # we can't call warn because this is the not the tcl-tk gui thread
             if result != None:
                 if len(result) > 1:
                     print "\n=== mengine errors below === "
                     print result[1].replace("\n\n", "\n"),
                     print "=== mengine errors above ===\n"
             failed_file = "cleanup_failed.sdf"
             print "Clean-Error: Structure cleanup failed.  Invalid input or software malfuction?"
             aromatic = 0
             for bond in input_model.bond:
                 if bond.order == 4:
                     aromatic = 1
             try:
                 open(failed_file, 'wb').write(input_sdf)
                 print "Clean-Error: Wrote SD file '%s' into the directory:" % failed_file
                 print "Clean-Error: '%s'." % os.getcwd()
                 print "Clean-Error: If you believe PyMOL should be able to handle this structure"
                 print "Clean-Error: then please email that SD file to [email protected]. Thank you!"
             except IOError:
                 print "Unabled to write '%s" % failed_file
             if aromatic:
                 print "Clean-Warning: Please eliminate aromatic bonds and then try again."
     if message != None:
         self_cmd.do("_ wizard")
Example #20
0
    def map_new(name,
                type='gaussian',
                grid=None,
                selection="(all)",
                buffer=None,
                box=None,
                state=0,
                quiet=1,
                zoom=0,
                normalize=-1,
                clamp=[1.0, -1.0],
                resolution=0.0,
                _self=cmd):
        '''

DESCRIPTION

    "map_new" creates a map object using one of the built-in map
    generation routines.  This command not yet fully supported.

USAGE

    map_new name [, type [, grid [, selection [, buffer [, box [, state ]]]]]]

ARGUMENTS

    name = string: name of the map object to create or modify
	
    type = vdw, gaussian, gaussian_max, coulomb, coulomb_neutral, coulomb_local

    grid = float: grid spacing

    selection = string: atoms about which to generate the map

    buffer = float: cutoff 
    
    state > 0: use the indicated state
    
    state = 0: use all states independently with independent extents
    
    state = -1: use current global state
    
    state = -2: use effective object state(s)
    
    state = -3: use all states in one map
    
    state = -4: use all states independent states by with a unified extent

NOTES

    This command can be used to create low-resolution surfaces of
    protein structures.
    
    '''
        # preprocess selection
        r = DEFAULT_ERROR
        selection = selector.process(selection)
        if box != None:  # box should be [[x1,y1,z1],[x2,y2,z2]]
            if _self.is_string(box):
                box = safe_list_eval(box)
            box = (float(box[0][0]), float(box[0][1]), float(box[0][2]),
                   float(box[1][0]), float(box[1][1]), float(box[1][2]))
            box_flag = 1
        else:
            box = (0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
            box_flag = 0
        if grid == None:
            grid = _self.get_setting_legacy('gaussian_resolution') / 3.0
        if buffer == None:
            buffer = _self.get_setting_legacy('gaussian_resolution')
        grid = float(grid)  # for now, uniform xyz; later (x,y,z)

        if not is_list(clamp):
            clamp = safe_list_eval(str(clamp))
        if len(clamp) < 2:
            clamp = [1.0, -1.0]
        type = map_type_dict[map_type_sc.auto_err(str(type), 'map type')]
        try:
            _self.lock(_self)
            r = _cmd.map_new(_self._COb, str(name), int(type), grid,
                             str(selection), float(buffer), box,
                             int(state) - 1, int(box_flag), int(quiet),
                             int(zoom), int(normalize), float(clamp[0]),
                             float(clamp[1]), float(resolution))
        finally:
            _self.unlock(r, _self)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Example #21
0
    def __init__(self,self_cmd,sele,state=-1,message=None):
        self.cmd = self_cmd
        if message == '':
            message = None
        if state<1:
            state = self_cmd.get_state()
        # this code will moved elsewhere
        ok = 1
        try:
            from freemol import mengine
        except:
            ok = 0
            print "Error: unable to import freemol.mengine module."
            print "This PyMOL build appears not to include full modeling capabilities."
        if ok:
            if not mengine.validate():
                ok = 0
                print "Error: Unable to validate freemol.mengine"
        if ok:
            if self_cmd.count_atoms(sele) > 999:
                ok = 0
                print "Error: Sorry, clean is currently limited to 999 atoms"
        if not ok:
            pass
            # we can't call warn because this is the not the tcl-tk gui thread
            # warn("Please be sure that FreeMOL is correctly installed.")
        else:
            if message != None:
                self.cmd.do("_ cmd.wizard('message','''%s''')"%message)
            obj_list = self_cmd.get_object_list("bymol ("+sele+")")
            ok = 0
            result = None
            if is_list(obj_list) and (len(obj_list)==1):
                obj_name = obj_list[0]
                self_cmd.sculpt_deactivate(obj_name) 
                # eliminate all sculpting information for object
                self.cmd.sculpt_purge()
                self.cmd.set("sculpting",0)
                state = self_cmd.get_state()
                if self_cmd.count_atoms(obj_name+" and flag 2"): # any atoms restrained?
                    self_cmd.reference("validate",obj_name,state) # then we have reference coordinates
                input_model = self_cmd.get_model(obj_name,state=state)
                (fit_flag, sdf_list) = model_to_sdf_list(self_cmd,input_model)
                input_sdf = string.join(sdf_list,'')
#                print input_sdf
                result = mengine.run(input_sdf)
                if result != None:
                    if len(result):
                        clean_sdf = result[0]
                        clean_rec = clean_sdf.split("$$$$")[0]
                        energy = get_energy_from_rec(clean_rec)
                        if len(clean_rec) and int(energy) != 9999:
                            clean_name = "builder_clean_tmp"
                            self_cmd.set("suspend_updates")
                            try:
                                self_cmd.read_molstr(clean_rec, clean_name, zoom=0)
                                # need to insert some error checking here
                                if clean_name in self_cmd.get_names("objects"):
                                    self_cmd.set("retain_order","1",clean_name)
                                    if fit_flag:
                                        self_cmd.fit(clean_name, obj_name, matchmaker=4,
                                                     mobile_state=1, target_state=state)
                                    self_cmd.push_undo(obj_name)
                                    self_cmd.update(obj_name, clean_name, matchmaker=0,
                                                    source_state=1, target_state=state)
                                    self_cmd.sculpt_activate(obj_name) 
                                    self_cmd.sculpt_deactivate(obj_name)
                                    ok = 1
                            finally:
                                self_cmd.delete(clean_name)
                                self_cmd.unset("suspend_updates")
            if not ok:
                # we can't call warn because this is the not the tcl-tk gui thread
                if result != None:
                    if len(result)>1:
                        print "\n=== mengine errors below === "
                        print result[1].replace("\n\n","\n"),
                        print "=== mengine errors above ===\n"
                failed_file = "cleanup_failed.sdf"
                print "Clean-Error: Structure cleanup failed.  Invalid input or software malfuction?"
                aromatic = 0
                for bond in input_model.bond:
                    if bond.order == 4:
                        aromatic = 1
                try:
                    open(failed_file,'wb').write(input_sdf)
                    print "Clean-Error: Wrote SD file '%s' into the directory:"%failed_file
                    print "Clean-Error: '%s'."%os.getcwd()
                    print "Clean-Error: If you believe PyMOL should be able to handle this structure"
                    print "Clean-Error: then please email that SD file to [email protected]. Thank you!"
                except IOError:
                    print "Unabled to write '%s"%failed_file
                if aromatic:
                    print "Clean-Warning: Please eliminate aromatic bonds and then try again."                    
        if message!=None:
            self_cmd.do("_ wizard")
Example #22
0
    def pseudoatom(object='',
                   selection='',
                   name='PS1',
                   resn='PSD',
                   resi='1',
                   chain='P',
                   segi='PSDO',
                   elem='PS',
                   vdw=-1.0,
                   hetatm=1,
                   b=0.0,
                   q=0.0,
                   color='',
                   label='',
                   pos=None,
                   state=0,
                   mode='rms',
                   quiet=1,
                   _self=cmd):
        '''
        
DESCRIPTION

    "pseudoatom" adds a pseudoatom to a molecular object, and will
    creating the molecular object if it does not yet exist.
    
USAGE

    pseudoatom object [, selection [, name [, resn [, resi [, chain
        [, segi [, elem [, vdw [, hetatm [, b [, q [, color [, label
        [, pos [, state [, mode [, quiet ]]]]]]]]]]]]]]]]]

NOTES

    "pseudoatom" can be used for a wide variety of random tasks where
    on must place an atom or a label in 3D space.
    
    '''

        r = DEFAULT_ERROR
        # preprocess selection
        if len(color):
            color = _self.get_color_index(str(color))
        else:
            color = -1  # default
        object = str(object)
        if not len(object):
            object = _self.get_unused_name(prefix="pseudo")
        selection = selector.process(selection)
        mode = pseudoatom_mode_dict[pseudoatom_mode_sc.auto_err(
            str(mode), 'pseudoatom mode')]

        (name, resn, resi, chain, segi, elem,
         label) = map(unquote, (name, resn, resi, chain, segi, elem, label))
        #
        try:
            _self.lock(_self)
            if pos != None:
                if not (is_list(pos) or is_tuple(pos)):
                    pos = safe_list_eval(pos)
                pos = (
                    float(pos[0]),  # tuple-ize
                    float(pos[1]),
                    float(pos[2]))
            if len(selection.split()) > 1:
                selection = "(" + str(selection) + ")"
            r = _cmd.pseudoatom(_self._COb, str(object), str(selection),
                                str(name), str(resn), str(resi), str(chain),
                                str(segi), str(elem), float(vdw), int(hetatm),
                                float(b), float(q), str(label), pos,
                                int(color),
                                int(state) - 1, int(mode), int(quiet))
        finally:
            _self.unlock(r, _self)
        if _self._raising(r, _self): raise pymol.CmdException
        return r