示例#1
0
    def resume(filename, _self=cmd):
        '''
        
DESCRIPTION

    "resume" executes a log file and opens it for recording of
    additional commands.

USAGE

    resume filename

SEE ALSO

    log, log_close

    '''
        pymol = _self._pymol
        r = DEFAULT_ERROR
        if os.path.exists(filename):
            if (re.search(r"\.py$|\.PY$|\.pym$|.PYM$", filename)):
                r = _self.do("run %s" % filename)
            else:
                r = _self.do("@%s" % filename)
        if is_ok(r):
            r = _self.do("log_open %s,a" % filename)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
示例#2
0
文件: querying.py 项目: Almad/pymol
    def count_states(selection="(all)", quiet=1, _self=cmd):
        '''
DESCRIPTION

    "count_states" returns the number of states in the selection.

USAGE

    count_states
    
PYMOL API

    cmd.count_states(string selection)

SEE ALSO

    frame
    '''
        # preprocess selection
        selection = selector.process(selection)
        #
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.count_states(_self._COb,selection)
        finally:
            _self.unlock(r,_self)
        if is_ok(r):
            if not quiet:
                print " cmd.count_states: %d states."%r            
        if _raising(r,_self): raise pymol.CmdException
        return r
示例#3
0
    def count_states(selection="(all)", quiet=1, _self=cmd):
        '''
DESCRIPTION

    "count_states" returns the number of states in the selection.

USAGE

    count_states
    
PYMOL API

    cmd.count_states(string selection)

SEE ALSO

    frame
    '''
        # preprocess selection
        selection = selector.process(selection)
        #
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.count_states(_self._COb, selection)
        finally:
            _self.unlock(r, _self)
        if is_ok(r):
            if not quiet:
                print " cmd.count_states: %d states." % r
        if _raising(r, _self): raise pymol.CmdException
        return r
示例#4
0
文件: commanding.py 项目: Almad/pymol
    def resume(filename, _self=cmd):
        '''
        
DESCRIPTION

    "resume" executes a log file and opens it for recording of
    additional commands.

USAGE

    resume filename

SEE ALSO

    log, log_close

    '''
        pymol=_self._pymol        
        r = DEFAULT_ERROR
        if os.path.exists(filename):
            if(re.search(r"\.py$|\.PY$|\.pym$|.PYM$",filename)):
                r = _self.do("run %s"%filename)
            else:
                r = _self.do("@%s"%filename)
        if is_ok(r):
            r = _self.do("log_open %s,a"%filename)
        if _self._raising(r,_self): raise pymol.CmdException
        return r
示例#5
0
 def get_session(names='',
                 partial=0,
                 quiet=1,
                 compress=-1,
                 cache=-1,
                 _self=cmd):
     session = {}
     r = DEFAULT_SUCCESS
     cache = int(cache)
     compress = int(compress)
     if cache:
         cache_opt = int(_self.get('session_cache_optimize'))
         if cache != 0:
             cache_mode = int(_self.get('cache_mode'))
             if ((cache_mode > 0) and (cache_opt != 0)) or (cache_opt == 1):
                 _self.cache('optimize')
     for a in _self._pymol._session_save_tasks:
         if a == None:
             try:
                 _self.lock(_self)
                 r = _cmd.get_session(_self._COb, session, str(names),
                                      int(partial), int(quiet))
             finally:
                 _self.unlock(r, _self)
             try:
                 session['session'] = copy.deepcopy(_self._pymol.session)
                 if cache and hasattr(_self._pymol, '_cache'):
                     session['cache'] = _self._pymol._cache
             except:
                 traceback.print_exc()
         else:
             try:
                 if is_error(apply(a, (session, ), {'_self': _self})):
                     r = DEFAULT_ERROR
             except:
                 traceback.print_exc()
                 print "Error: An error occurred when trying to generate session."
                 print "Error: The resulting session file may be incomplete."
     if is_ok(r):
         if (compress < 0):
             compress = _self.get_setting_boolean('session_compression')
         if (compress):
             import zlib
             session = zlib.compress(io.pkl.toString(session))
         return session
     elif _self._raising(r, _self):
         raise QuietException
     return r
示例#6
0
 def get_session(names='', partial=0, quiet=1, compress=-1, cache=-1, _self=cmd):
     session = {}
     r = DEFAULT_SUCCESS
     cache = int(cache)
     compress = int(compress)
     if cache:
         cache_opt = int(_self.get('session_cache_optimize'))
         if cache != 0:
             cache_mode = int(_self.get('cache_mode'))
             if ((cache_mode > 0) and (cache_opt != 0)) or (cache_opt==1):
                 _self.cache('optimize')
     for a in _self._pymol._session_save_tasks:
         if a==None:
             try:
                 _self.lock(_self)
                 r = _cmd.get_session(_self._COb,session,str(names),
                                      int(partial),int(quiet))
             finally:
                 _self.unlock(r,_self)
             try:
                 session['session'] = copy.deepcopy(_self._pymol.session)
                 if cache and hasattr(_self._pymol,'_cache'):
                     session['cache'] = _self._pymol._cache
             except:
                 traceback.print_exc()
         else:
             try:
                 if is_error(apply(a,(session,),{'_self':_self})):
                     r = DEFAULT_ERROR
             except:
                 traceback.print_exc()
                 print "Error: An error occurred when trying to generate session."
                 print "Error: The resulting session file may be incomplete."
     if is_ok(r):
         if(compress<0):
             compress = _self.get_setting_boolean('session_compression')
         if(compress):
             import zlib
             session = zlib.compress(io.pkl.toString(session))
         return session
     elif _self._raising(r,_self):
         raise QuietException                  
     return r
示例#7
0
    def pop(name, source, enable=-1, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "pop" provides a mechanism of iterating through an atom selection
    atom by atom, where each atom is sequentially assigned to the
    named selection.
    
USAGE

    pop name, source
    
EXAMPLE

    select src, name ca

    python
    while cmd.pop("tmp","src"):
        cmd.zoom("tmp",2, animate=1)
        for a in range(30):
           cmd.refresh()
           time.sleep(0.05)
    python end
    
PYMOL API

    cmd.deselect()
        '''
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            r = _cmd.pop(_self._COb,str(name),str(source),int(quiet))
            if is_ok(r):
                enable = int(enable)
                if enable>0:
                    r = _cmd.onoff(_self._COb,str(name),1,0);
                elif enable == 0:
                    r = _cmd.onoff(_self._COb,str(name),0,0)
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException                  
        return r
示例#8
0
文件: querying.py 项目: Almad/pymol
    def distance(name=None, selection1="(pk1)", selection2="(pk2)", 
		 cutoff=None, mode=None, zoom=0, width=None, length=None,
                 gap=None, label=1, quiet=1, reset=0, state=0, _self=cmd):
	
        '''
DESCRIPTION

    "distance" creates a new distance object between two selections.

USAGE
    
    distance [name [, selection1 [, selection2 [, cutoff [, mode ]]]]]

ARGUMENTS

    name = string: name of the distance object to create

    selection1 = string: first atom selection

    selection2 = string: second atom selection

    cutoff = float: longest distance to show 
    
    mode = 0: all interatomic distances

    mode = 1: only bond distances

    mode = 2: only show polar contact distances

EXAMPLES

    distance mydist, 14/CA, 29/CA

    distance hbonds, all, all, 3.2, mode=2

NOTES

    The distance wizard makes measuring distances easier than using
    the "dist" command for real-time operations.

    "dist" alone will show distances between selections (pk1) and (pk1),
    which can be set using the PkAt mouse action (usually CTRL-middle-click).

PYMOL API

    cmd.distance(string name, string selection1, string selection2,
                 string cutoff, string mode )

    '''
        # handle unnamed distance
        r = DEFAULT_SUCCESS
        if name!=None:
            if len(name):
                if name[0]=='(' or ' ' in name or '/' in name: # we're one argument off...
                    if cutoff!=None:
                        mode = cutoff
                    if selection2!="(pk2)":
                        cutoff = selection2
                    if selection1!="(pk1)":
                        selection2 = selection1
                    selection1=name
                    name = None

        if selection1=="(pk1)":
            if "pk1" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):
                    print "cmd-Error: The 'pk1' selection is undefined."
                r = DEFAULT_ERROR
        if selection2=="(pk2)":
            if "pk2" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):         
                    print "cmd-Error: The 'pk2' selection is undefined."
                r = DEFAULT_ERROR
        if is_ok(r):
            r = DEFAULT_ERROR

            # if unlabeled, then get next name in series

            if name!=None:
                nam=name
            else:
                try:
                    _self.lock(_self)
                    cnt = _cmd.get(_self._COb,"dist_counter") + 1.0
                    r = _cmd.legacy_set(_self._COb,"dist_counter","%1.0f" % cnt)
                    nam = "dist%02.0f" % cnt
                finally:
                    _self.unlock(r,_self)

            # defaults
            if mode == None:
                mode = 0
            if cutoff == None:
                cutoff = -1.0
            # preprocess selections
            selection1 = selector.process(selection1)
            selection2 = selector.process(selection2)
            # now do the deed
            try:
                _self.lock(_self)
                if selection2!="same":
                    selection2 = "("+selection2+")"
                r = _cmd.dist(_self._COb,str(nam),"("+str(selection1)+")",
                              str(selection2),int(mode),float(cutoff),
                              int(label),int(quiet),int(reset),
                              int(state)-1,int(zoom))
                if width!=None:
                    _self.set("dash_width",width,nam)
                if length!=None:
                    _self.set("dash_length",length,nam)
                if gap!=None:
                    _self.set("dash_gap",gap,nam)
            finally:
                _self.unlock(r,_self)
        if (r<0.0) and (not quiet):
            # a negative value is an warning signal from PyMOL...
            r = DEFAULT_ERROR
        if _raising(r,_self): raise pymol.CmdException
        return r
示例#9
0
文件: querying.py 项目: Almad/pymol
    def dihedral(name=None, selection1="(pk1)", selection2="(pk2)",
		 selection3="(pk3)", selection4="(pk4)", mode=None,
		 label=1, reset=0, zoom=0, state=0, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "dihedral" shows dihedral angles formed between any four atoms.

USAGE

    dihedral [ name [, selection1 [, selection2 [, selection3 [, selection4 ]]]]]


NOTES

    "dihedral" alone will show the dihedral angle formed by selections
    (pk1), (pk2), (pk3), and (pk4), which can be set using the "PkAt"
    mouse action (typically, Ctrl-middle-click)

PYMOL API

    cmd.dihedral(string name, string selection1, string selection2,
                 string selection3, string selection4)

SEE ALSO

    distance, angle
    '''
        r = DEFAULT_SUCCESS      
        if selection1=="(pk1)":
            if "pk1" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):
                    print "cmd-Error: The 'pk1' selection is undefined."
                r = DEFAULT_ERROR
        if selection2=="(pk2)":
            if "pk2" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):         
                    print "cmd-Error: The 'pk2' selection is undefined."
                r = DEFAULT_ERROR
        if selection3=="(pk3)":
            if "pk3" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):         
                    print "cmd-Error: The 'pk3' selection is undefined."
                r = DEFAULT_ERROR
        if selection3=="(pk4)":
            if "pk4" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd,fb_mask.errors,_self):         
                    print "cmd-Error: The 'pk4' selection is undefined."
                r = DEFAULT_ERROR
        if is_ok(r):
            r = DEFAULT_ERROR
            # if unlabeled, then get next name in series

            if name!=None:
                nam=name
            else:
                try:
                    _self.lock(_self)
                    cnt = _cmd.get(_self._COb,"dist_counter") + 1.0
                    r = _cmd.legacy_set(_self._COb,"dist_counter","%1.0f" % cnt)
                    nam = "dihedral%02.0f" % cnt
                finally:
                    _self.unlock(r,_self)

            # defaults
            if mode == None:
                mode = 0
            # preprocess selections
            selection1 = selector.process(selection1)
            selection2 = selector.process(selection2)
            selection3 = selector.process(selection3)
            selection4 = selector.process(selection4)
            # now do the deed
            try:
                _self.lock(_self)
                if selection2!="same":
                    selection2 = "("+selection2+")"
                if selection3!="same":
                    selection3 = "("+selection3+")"
                if selection4!="same":
                    selection4 = "("+selection4+")"
                r = _cmd.dihedral(_self._COb,str(nam),"("+str(selection1)+")",
                                  str(selection2),
                                  str(selection3),
                                  str(selection4),
                                  int(mode),int(label),
                                  int(reset),int(zoom),
                                  int(quiet),int(state)-1)
            finally:
                _self.unlock(r,_self)
        if _raising(r,_self): raise pymol.CmdException
        return r
示例#10
0
def _load(oname,
          finfo,
          state,
          ftype,
          finish,
          discrete,
          quiet=1,
          multiplex=0,
          zoom=-1,
          mimic=1,
          _self=cmd):
    # WARNING: internal routine, subject to change
    # caller must already hold API lock
    # NOTE: state index assumes 1-based state
    r = DEFAULT_ERROR
    size = 0
    if ftype not in (loadable.model, loadable.brick):
        if ftype == loadable.r3d:
            import cgo
            obj = cgo.from_r3d(finfo)
            if is_ok(obj):
                r = _cmd.load_object(_self._COb, str(oname), obj,
                                     int(state) - 1, loadable.cgo, int(finish),
                                     int(discrete), int(quiet), int(zoom))
            else:
                print "Load-Error: Unable to open file '%s'." % finfo
        elif ftype == loadable.cc1:  # ChemDraw 3D
            obj = io.cc1.fromFile(finfo)
            if obj:
                r = _cmd.load_object(_self._COb, str(oname), obj,
                                     int(state) - 1, loadable.model,
                                     int(finish), int(discrete), int(quiet),
                                     int(zoom))
        elif ftype == loadable.moe:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import moe
                moe_str = file_read(finfo)
                r = moe.read_moestr(moe_str,
                                    str(oname),
                                    int(state),
                                    int(finish),
                                    int(discrete),
                                    int(quiet),
                                    int(zoom),
                                    _self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ImportError:
                print "Error: .MOE format not supported by this PyMOL build."
                if _self._raising(-1, _self): raise pymol.CmdException

        elif ftype == loadable.mae:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import mae
                mae_str = file_read(finfo)
                r = mae.read_maestr(mae_str,
                                    str(oname),
                                    int(state),
                                    int(finish),
                                    int(discrete),
                                    int(quiet),
                                    int(zoom),
                                    int(multiplex),
                                    int(mimic),
                                    _self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ValueError:
                print "Error: .MAE format not supported by this PyMOL build."
                if _self._raising(-1, _self): raise pymol.CmdException

        else:
            if ftype in _load2str and ('://' in finfo
                                       or cmd.gz_ext_re.search(finfo)):
                # NOTE: we could safely always do this, not only for URLs and
                # compressed files. But I don't want to change the old behavior
                # that regular files are read from the C function.
                finfo = file_read(finfo)
                ftype = _load2str[ftype]
            r = _cmd.load(_self._COb, str(oname), finfo,
                          int(state) - 1, int(ftype), int(finish),
                          int(discrete), int(quiet), int(multiplex), int(zoom))
    else:
        try:
            x = io.pkl.fromFile(finfo)
            if isinstance(x, types.ListType) or isinstance(x, types.TupleType):
                for a in x:
                    r = _cmd.load_object(_self._COb, str(oname), a,
                                         int(state) - 1, int(ftype), 0,
                                         int(discrete), int(quiet), int(zoom))
                    if (state > 0):
                        state = state + 1
                _cmd.finish_object(_self._COb, str(oname))
            else:
                r = _cmd.load_object(_self._COb, str(oname), x,
                                     int(state) - 1, int(ftype), int(finish),
                                     int(discrete), int(quiet), int(zoom))
        except:
            #            traceback.print_exc()
            print "Load-Error: Unable to load file '%s'." % finfo
    return r
示例#11
0
    def select(name, selection="", enable=-1, quiet=1, merge=0, state=0, domain='',_self=cmd): 
        '''
DESCRIPTION

    "select" creates a named atom selection from a
    selection-expression.

USAGE

    select name, selection [, enable [, quiet [, merge [, state [, domain ]]]]]

ARGUMENTS

    name = a unique name for the selection

    selection = a selection-expression

NOTES

    If a selection-expression with explicit surrounding parethenses is
    provided as the first argument, then the default selection name
    is used as the name argument.

EXAMPLES 

    select chA, chain A
    select ( resn his )
    select near142, resi 142 around 5

PYMOL API

    cmd.select(string name, string selection)

SEE ALSO

    delete
        '''
        r = DEFAULT_ERROR
        try:
            _self.lock(_self)
            if selection=="":
                selection = name                    
                if _cmd.get(_self._COb,"auto_number_selections")!=0.0:
                    sel_cnt = _cmd.get(_self._COb,"sel_counter") + 1.0
                    _cmd.legacy_set(_self._COb,"sel_counter","%1.0f" % sel_cnt)
                    name = "sel%02.0f" % sel_cnt
                else:
                    name = "sele"
            if name == None:
                sel_cnt = _cmd.get(_self._COb,"sel_counter") + 1.0
                _cmd.legacy_set(_self._COb,"sel_counter","%1.0f" % sel_cnt)
                name = "sel%02.0f" % sel_cnt
                
            # preprocess selection (note: inside TRY)
            selection = selector.process(selection)
            merge = int(merge)
            if merge==1:
                selection = "("+selection+") or ?"+name # merge if exists
            elif merge==2:
                selection = "("+selection+") or ??"+name # merge if exists and active
            #
            r = _cmd.select(_self._COb,str(name),str(selection),int(quiet),int(state)-1,str(domain))
            enable = int(enable)
            if is_ok(r) and enable>0:
                _cmd.onoff(_self._COb,str(name),1,0);
            elif enable == 0:
                _cmd.onoff(_self._COb,str(name),0,0)
        finally:
            _self.unlock(r,_self)
        if _self._raising(r,_self): raise pymol.CmdException                  
        return r
示例#12
0
文件: internal.py 项目: Almad/pymol
def _load(oname,finfo,state,ftype,finish,discrete,
          quiet=1,multiplex=0,zoom=-1,mimic=1,
          _self=cmd):
    # WARNING: internal routine, subject to change
    # caller must already hold API lock
    # NOTE: state index assumes 1-based state
    r = DEFAULT_ERROR
    size = 0
    if ftype not in (loadable.model,loadable.brick):
        if ftype == loadable.r3d:
            import cgo
            obj = cgo.from_r3d(finfo)
            if is_ok(obj):
                r = _cmd.load_object(_self._COb,str(oname),obj,int(state)-1,loadable.cgo,
                                      int(finish),int(discrete),int(quiet),
                                      int(zoom))
            else:
                print "Load-Error: Unable to open file '%s'."%finfo
        elif ftype == loadable.cc1: # ChemDraw 3D
            obj = io.cc1.fromFile(finfo)
            if obj:
                r = _cmd.load_object(_self._COb,str(oname),obj,int(state)-1,loadable.model,
                                      int(finish),int(discrete),
                                      int(quiet),int(zoom))
        elif ftype == loadable.moe:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import moe
                if (string.find(finfo,":")>1):
                    import urllib
                    moe_file = urllib.urlopen(finfo)
                else:
                    moe_file = open(finfo)
                moe_str = moe_file.read()
                moe_file.close()
                r = moe.read_moestr(moe_str,str(oname),int(state),
                                int(finish),int(discrete),int(quiet),int(zoom),_self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ImportError:
                print "Error: .MOE format not supported by this PyMOL build."
                if _self._raising(-1,_self): raise pymol.CmdException

        elif ftype == loadable.mae:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import mae
                if (string.find(finfo,":")>1):
                    import urllib 
                    mae_file = urllib.urlopen(finfo)
                else:
                    mae_file = open(finfo)
                mae_str = mae_file.read()
                mae_file.close()
                r = mae.read_maestr(mae_str,str(oname),
                                    int(state),
                                    int(finish),int(discrete),
                                    int(quiet),int(zoom),int(multiplex),
                                    int(mimic),
                                    _self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ValueError:
                print "Error: .MAE format not supported by this PyMOL build."
                if _self._raising(-1,_self): raise pymol.CmdException

        else:
            if ftype in _load2str.keys() and (string.find(finfo,":")>1):
                gz = re.search("\.gz$",finfo,re.I)
                try:
                    import urllib
                    tmp_file = urllib.urlopen(finfo)
                except:
                    print "Error: unable to open the URL:\nError:   %s"%finfo
#                    traceback.print_exc()
                    return 0
                finfo = tmp_file.read() 
                if gz:
                    import StringIO
                    fakestream = StringIO.StringIO(finfo)
                    import gzip
                    finfo = gzip.GzipFile(fileobj=fakestream).read()
                ftype = _load2str[ftype]
                tmp_file.close()
            elif ftype in _load2str.keys() and re.search("\.gz$",finfo,re.I):
                import gzip
                finfo = gzip.open(finfo).read()                
                ftype = _load2str[ftype]
            r = _cmd.load(_self._COb,str(oname),finfo,int(state)-1,int(ftype),
                          int(finish),int(discrete),int(quiet),
                          int(multiplex),int(zoom))
    else:
        try:
            x = io.pkl.fromFile(finfo)
            if isinstance(x,types.ListType) or isinstance(x,types.TupleType):
                for a in x:
                    r = _cmd.load_object(_self._COb,str(oname),a,int(state)-1,
                                                int(ftype),0,int(discrete),int(quiet),
                                                int(zoom))
                    if(state>0):
                        state = state + 1
                _cmd.finish_object(_self._COb,str(oname))
            else:
                r = _cmd.load_object(_self._COb,str(oname),x,
                                            int(state)-1,int(ftype),
                                            int(finish),int(discrete),
                                            int(quiet),int(zoom))
        except:
#            traceback.print_exc()
            print "Load-Error: Unable to load file '%s'." % finfo
    return r
示例#13
0
文件: internal.py 项目: evonove/pymol
def _load(oname,finfo,state,ftype,finish,discrete,
          quiet=1,multiplex=0,zoom=-1,mimic=1,
          _self=cmd):
    # WARNING: internal routine, subject to change
    # caller must already hold API lock
    # NOTE: state index assumes 1-based state
    r = DEFAULT_ERROR
    size = 0
    if ftype not in (loadable.model,loadable.brick):
        if ftype == loadable.r3d:
            import cgo
            obj = cgo.from_r3d(finfo)
            if is_ok(obj):
                r = _cmd.load_object(_self._COb,str(oname),obj,int(state)-1,loadable.cgo,
                                      int(finish),int(discrete),int(quiet),
                                      int(zoom))
            else:
                print "Load-Error: Unable to open file '%s'."%finfo
        elif ftype == loadable.cc1: # ChemDraw 3D
            obj = io.cc1.fromFile(finfo)
            if obj:
                r = _cmd.load_object(_self._COb,str(oname),obj,int(state)-1,loadable.model,
                                      int(finish),int(discrete),
                                      int(quiet),int(zoom))
        elif ftype == loadable.moe:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import moe
                moe_str = _self.file_read(finfo)
                r = moe.read_moestr(moe_str,str(oname),int(state),
                                int(finish),int(discrete),int(quiet),int(zoom),_self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ImportError:
                print "Error: .MOE format not supported by this PyMOL build."
                if _self._raising(-1,_self): raise pymol.CmdException

        elif ftype == loadable.mae:
            try:
                # BEGIN PROPRIETARY CODE SEGMENT
                from epymol import mae
                mae_str = _self.file_read(finfo)
                r = mae.read_maestr(mae_str,str(oname),
                                    int(state),
                                    int(finish),int(discrete),
                                    int(quiet),int(zoom),int(multiplex),
                                    int(mimic),
                                    _self=_self)

                # END PROPRIETARY CODE SEGMENT
            except ValueError:
                print "Error: .MAE format not supported by this PyMOL build."
                if _self._raising(-1,_self): raise pymol.CmdException

        else:
            if ftype in _load2str and ('://' in finfo or cmd.gz_ext_re.search(finfo)):
                # NOTE: we could safely always do this, not only for URLs and
                # compressed files. But I don't want to change the old behavior
                # that regular files are read from the C function.
                finfo = _self.file_read(finfo)
                ftype = _load2str[ftype]
            r = _cmd.load(_self._COb,str(oname),finfo,int(state)-1,int(ftype),
                          int(finish),int(discrete),int(quiet),
                          int(multiplex),int(zoom))
    else:
        try:
            x = io.pkl.fromFile(finfo)
            if isinstance(x,types.ListType) or isinstance(x,types.TupleType):
                for a in x:
                    r = _cmd.load_object(_self._COb,str(oname),a,int(state)-1,
                                                int(ftype),0,int(discrete),int(quiet),
                                                int(zoom))
                    if(state>0):
                        state = state + 1
                _cmd.finish_object(_self._COb,str(oname))
            else:
                r = _cmd.load_object(_self._COb,str(oname),x,
                                            int(state)-1,int(ftype),
                                            int(finish),int(discrete),
                                            int(quiet),int(zoom))
        except:
#            traceback.print_exc()
            print "Load-Error: Unable to load file '%s'." % finfo
    return r
示例#14
0
    def distance(name=None,
                 selection1="(pk1)",
                 selection2="(pk2)",
                 cutoff=None,
                 mode=None,
                 zoom=0,
                 width=None,
                 length=None,
                 gap=None,
                 label=1,
                 quiet=1,
                 reset=0,
                 state=0,
                 _self=cmd):
        '''
DESCRIPTION

    "distance" creates a new distance object between two selections.

USAGE
    
    distance [name [, selection1 [, selection2 [, cutoff [, mode ]]]]]

ARGUMENTS

    name = string: name of the distance object to create

    selection1 = string: first atom selection

    selection2 = string: second atom selection

    cutoff = float: longest distance to show 
    
    mode = 0: all interatomic distances

    mode = 1: only bond distances

    mode = 2: only show polar contact distances

EXAMPLES

    distance mydist, 14/CA, 29/CA

    distance hbonds, all, all, 3.2, mode=2

NOTES

    The distance wizard makes measuring distances easier than using
    the "dist" command for real-time operations.

    "dist" alone will show distances between selections (pk1) and (pk1),
    which can be set using the PkAt mouse action (usually CTRL-middle-click).

PYMOL API

    cmd.distance(string name, string selection1, string selection2,
                 string cutoff, string mode )

    '''
        # handle unnamed distance
        r = DEFAULT_SUCCESS
        if name != None:
            if len(name):
                if name[0] == '(' or ' ' in name or '/' in name:  # we're one argument off...
                    if cutoff != None:
                        mode = cutoff
                    if selection2 != "(pk2)":
                        cutoff = selection2
                    if selection1 != "(pk1)":
                        selection2 = selection1
                    selection1 = name
                    name = None

        if selection1 == "(pk1)":
            if "pk1" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk1' selection is undefined."
                r = DEFAULT_ERROR
        if selection2 == "(pk2)":
            if "pk2" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk2' selection is undefined."
                r = DEFAULT_ERROR
        if is_ok(r):
            r = DEFAULT_ERROR

            # if unlabeled, then get next name in series

            if name != None:
                nam = name
            else:
                try:
                    _self.lock(_self)
                    cnt = _cmd.get(_self._COb, "dist_counter") + 1.0
                    r = _cmd.legacy_set(_self._COb, "dist_counter",
                                        "%1.0f" % cnt)
                    nam = "dist%02.0f" % cnt
                finally:
                    _self.unlock(r, _self)

            # defaults
            if mode == None:
                mode = 0
            if cutoff == None:
                cutoff = -1.0
            # preprocess selections
            selection1 = selector.process(selection1)
            selection2 = selector.process(selection2)
            # now do the deed
            try:
                _self.lock(_self)
                if selection2 != "same":
                    selection2 = "(" + selection2 + ")"
                r = _cmd.dist(_self._COb, str(nam),
                              "(" + str(selection1) + ")", str(selection2),
                              int(mode), float(cutoff), int(label), int(quiet),
                              int(reset),
                              int(state) - 1, int(zoom))
                if width != None:
                    _self.set("dash_width", width, nam)
                if length != None:
                    _self.set("dash_length", length, nam)
                if gap != None:
                    _self.set("dash_gap", gap, nam)
            finally:
                _self.unlock(r, _self)
        if (r < 0.0) and (not quiet):
            # a negative value is an warning signal from PyMOL...
            r = DEFAULT_ERROR
        if _raising(r, _self): raise pymol.CmdException
        return r
示例#15
0
    def dihedral(name=None,
                 selection1="(pk1)",
                 selection2="(pk2)",
                 selection3="(pk3)",
                 selection4="(pk4)",
                 mode=None,
                 label=1,
                 reset=0,
                 zoom=0,
                 state=0,
                 quiet=1,
                 _self=cmd):
        '''
DESCRIPTION

    "dihedral" shows dihedral angles formed between any four atoms.

USAGE

    dihedral [ name [, selection1 [, selection2 [, selection3 [, selection4 ]]]]]


NOTES

    "dihedral" alone will show the dihedral angle formed by selections
    (pk1), (pk2), (pk3), and (pk4), which can be set using the "PkAt"
    mouse action (typically, Ctrl-middle-click)

PYMOL API

    cmd.dihedral(string name, string selection1, string selection2,
                 string selection3, string selection4)

SEE ALSO

    distance, angle
    '''
        r = DEFAULT_SUCCESS
        if selection1 == "(pk1)":
            if "pk1" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk1' selection is undefined."
                r = DEFAULT_ERROR
        if selection2 == "(pk2)":
            if "pk2" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk2' selection is undefined."
                r = DEFAULT_ERROR
        if selection3 == "(pk3)":
            if "pk3" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk3' selection is undefined."
                r = DEFAULT_ERROR
        if selection3 == "(pk4)":
            if "pk4" not in _self.get_names('selections'):
                if _feedback(fb_module.cmd, fb_mask.errors, _self):
                    print "cmd-Error: The 'pk4' selection is undefined."
                r = DEFAULT_ERROR
        if is_ok(r):
            r = DEFAULT_ERROR
            # if unlabeled, then get next name in series

            if name != None:
                nam = name
            else:
                try:
                    _self.lock(_self)
                    cnt = _cmd.get(_self._COb, "dist_counter") + 1.0
                    r = _cmd.legacy_set(_self._COb, "dist_counter",
                                        "%1.0f" % cnt)
                    nam = "dihedral%02.0f" % cnt
                finally:
                    _self.unlock(r, _self)

            # defaults
            if mode == None:
                mode = 0
            # preprocess selections
            selection1 = selector.process(selection1)
            selection2 = selector.process(selection2)
            selection3 = selector.process(selection3)
            selection4 = selector.process(selection4)
            # now do the deed
            try:
                _self.lock(_self)
                if selection2 != "same":
                    selection2 = "(" + selection2 + ")"
                if selection3 != "same":
                    selection3 = "(" + selection3 + ")"
                if selection4 != "same":
                    selection4 = "(" + selection4 + ")"
                r = _cmd.dihedral(_self._COb,
                                  str(nam), "(" + str(selection1) + ")",
                                  str(selection2), str(selection3),
                                  str(selection4), int(mode), int(label),
                                  int(reset), int(zoom), int(quiet),
                                  int(state) - 1)
            finally:
                _self.unlock(r, _self)
        if _raising(r, _self): raise pymol.CmdException
        return r