示例#1
0
def _load(oname,
          finfo,
          state,
          ftype,
          finish,
          discrete,
          quiet=1,
          multiplex=0,
          zoom=-1,
          mimic=1,
          plugin='',
          object_props=None,
          atom_props=None,
          _self=cmd):
    # WARNING: internal routine, subject to change
    # caller must already hold API lock
    # NOTE: state index assumes 1-based state
    r = DEFAULT_ERROR
    contents = None
    size = 0
    if ftype not in (loadable.model, loadable.brick):
        if True:
            if ftype in _load2str:
                contents = _self.file_read(finfo)
                ftype = _load2str[ftype]
        return _cmd.load(_self._COb, str(oname), str(finfo), contents,
                         int(state) - 1,
                         int(ftype), int(finish), int(discrete), int(quiet),
                         int(multiplex), int(zoom), plugin, object_props,
                         atom_props, int(mimic))
    else:
        try:
            x = chempy.io.pkl.fromFile(finfo)
            if isinstance(x, (list, tuple)):
                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
示例#2
0
def _load(oname,finfo,state,ftype,finish,discrete,
          quiet=1,multiplex=0,zoom=-1,mimic=1,
          plugin='',
          object_props=None,
          atom_props=None, _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 True:
            if ftype in _load2str:
                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), plugin,
                          object_props, atom_props, int(mimic))
    else:
        try:
            x = chempy.io.pkl.fromFile(finfo)
            if isinstance(x, (list, tuple)):
                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
示例#3
0
def _load(oname,finfo,state,ftype,finish,discrete,
          quiet=1,multiplex=0,zoom=-1,mimic=1,
          plugin='',
          object_props=None,
          atom_props=None, _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:
            from . 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 = chempy.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:
                raise pymol.IncentiveOnlyException(".MOE format not supported by this PyMOL build.")

        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 ImportError:
                raise pymol.IncentiveOnlyException(".MAE format not supported by this PyMOL build.")

        else:
            if ftype in _load2str and ('://' in finfo
                    or cmd.gz_ext_re.search(finfo)
                    or any(c > '~' for c in finfo) # ascii check
                    ):
                # 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), plugin, object_props)
    else:
        try:
            x = chempy.io.pkl.fromFile(finfo)
            if isinstance(x, (list, tuple)):
                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
示例#4
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