Пример #1
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)
        partial = int(partial)

        pse_export_version = round(
            _self.get_setting_float('pse_export_version'), 4)
        legacyscenes = (0 < pse_export_version <
                        1.76) and _self.get_scene_list()

        if sys.version_info[0] > 2:
            legacypickle = (0 < pse_export_version < 1.9)
            if legacypickle:
                print(
                    ' Warning: pse_export_version with Python 3 is experimental'
                )
            cPickle.configure_legacy_dump(legacypickle)

        if legacyscenes:
            _self.pymol._scene_dict = {}

            scene_current_name = _self.get('scene_current_name')
            tempname = '_scene_db96724c3cef00875c3bebb4f348f711'
            _self.scene(tempname, 'store')

            for name in legacyscenes:
                _self.scene(name, 'recall', animate=0)
                wizard = _self.get_wizard()
                message = wizard.message if getattr(wizard, 'from_scene',
                                                    0) else None
                pymol.viewing._legacy_scene(name,
                                            'store',
                                            message,
                                            _self=_self)

            _self.scene(tempname, 'recall', animate=0)
            _self.scene(tempname, 'clear')
            _self.set('scene_current_name', scene_current_name)

        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 is 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(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 legacyscenes:
            del session['moviescenes']
            session['scene_dict'] = _self.pymol._scene_dict
            session['scene_order'] = legacyscenes
            pymol.viewing._legacy_scene('*', 'clear', _self=_self)
            del _self.pymol._scene_dict

        if is_ok(r):
            if pse_export_version > 0.0:
                try:
                    _session_convert_legacy(session, pse_export_version, _self)
                except Exception as e:
                    print(' Warning: failed to backport session:', e)

            if (compress < 0):
                compress = _self.get_setting_boolean('session_compression')
            if (compress):
                import zlib
                session = zlib.compress(cPickle.dumps(session, 1))
            return session
        elif _self._raising(r, _self):
            raise QuietException
        return r
Пример #2
0
    def get_session(names='',
                    partial=0,
                    quiet=1,
                    compress=-1,
                    cache=-1,
                    binary=-1,
                    version=-1,
                    *,
                    _self=cmd):
        '''
        :param names: Names of objects to export, or the empty string to export all objects.
        :param partial: If true, do not store selections, settings, view, movie.
        :param compress: DEPRECATED Pickle the dictionary to a string and
        compress that with zlib {default: session_compression}
        :param cache: ?
        :param binary: Use efficient binary format {default: pse_binary_dump}
        :param version: {default: pse_export_version}
        '''
        session = {}
        cache = int(cache)
        compress = int(compress)
        partial = int(partial)
        quiet = int(quiet)

        if version < 0:
            version = _self.get_setting_float('pse_export_version')

        pse_export_version = round(float(version), 4)
        legacyscenes = (0 < pse_export_version <
                        1.76) and _self.get_scene_list()

        if True:
            legacypickle = (0 < pse_export_version < 1.9)
            if legacypickle:
                print(' Using Python 2 compatible legacy pickler')
            cPickle.configure_legacy_dump(legacypickle)

        if legacyscenes:
            _self.pymol._scene_dict = {}

            scene_current_name = _self.get('scene_current_name')
            tempname = '_scene_db96724c3cef00875c3bebb4f348f711'
            _self.scene(tempname, 'store')

            for name in legacyscenes:
                _self.scene(name, 'recall', animate=0)
                wizard = _self.get_wizard()
                message = wizard.message if getattr(wizard, 'from_scene',
                                                    0) else None
                pymol.viewing._legacy_scene(name,
                                            'store',
                                            message,
                                            _self=_self)

            _self.scene(tempname, 'recall', animate=0)
            _self.scene(tempname, 'clear')
            _self.set('scene_current_name', scene_current_name)

        if cache:
            cache_opt = _self.get_setting_int('session_cache_optimize')
            if cache_opt == 1 or (cache_opt != 0
                                  and _self.get_setting_int('cache_mode')):
                _self.cache('optimize')

        with _self.lockcm:
            _cmd.get_session(_self._COb, session, str(names), int(partial),
                             int(quiet), binary, pse_export_version)

        if True:
            try:
                session['session'] = copy.deepcopy(_self._pymol.session)
                if cache and hasattr(_self._pymol, '_cache'):
                    session['cache'] = _self._pymol._cache
            except:
                colorprinting.print_exc()

        for a in _self._pymol._session_save_tasks:
            assert a is not None
            error = False
            try:
                # TODO _session_restore_tasks use `not <return-value>`
                # instead of `is_error(<return-value>)`
                error = is_error(a(session, _self=_self))
            except:
                if not quiet:
                    colorprinting.print_exc([__file__])
                error = True
            if error:
                msg = f'Warning: session-save-task "{a.__name__}" failed.'
                if not quiet:
                    msg += '\n         The resulting session file may be incomplete.'
                colorprinting.warning(msg)

        if legacyscenes:
            del session['moviescenes']
            session['scene_dict'] = _self.pymol._scene_dict
            session['scene_order'] = legacyscenes
            pymol.viewing._legacy_scene('*', 'clear', _self=_self)
            del _self.pymol._scene_dict

        if True:
            if pse_export_version > 0.0:
                try:
                    _session_convert_legacy(session, pse_export_version, _self)
                except Exception as e:
                    print(' Warning: failed to backport session:', e)

            if (compress < 0):
                compress = _self.get_setting_boolean('session_compression')
            if (compress):
                colorprinting.warning(
                    ' Warning: `session_compression` is deprecated. Save '
                    'to ".pze" or ".pse.gz" files instead, and/or use '
                    '`pse_binary_dump`')
                import zlib
                session = zlib.compress(cPickle.dumps(session, 1))
            return session
Пример #3
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)
        partial = int(partial)

        pse_export_version = round(_self.get_setting_float('pse_export_version'), 4)
        legacyscenes = (0 < pse_export_version < 1.76) and _self.get_scene_list()

        if sys.version_info[0] > 2:
            legacypickle = (0 < pse_export_version < 1.9)
            if legacypickle:
                print(' Warning: pse_export_version with Python 3 is experimental')
            cPickle.configure_legacy_dump(legacypickle)

        if legacyscenes:
            _self.pymol._scene_dict = {}

            scene_current_name = _self.get('scene_current_name')
            tempname = '_scene_db96724c3cef00875c3bebb4f348f711'
            _self.scene(tempname, 'store')

            for name in legacyscenes:
                _self.scene(name, 'recall', animate=0)
                wizard = _self.get_wizard()
                message = wizard.message if getattr(wizard, 'from_scene', 0) else None
                pymol.viewing._legacy_scene(name, 'store', message, _self=_self)

            _self.scene(tempname, 'recall', animate=0)
            _self.scene(tempname, 'clear')
            _self.set('scene_current_name', scene_current_name)

        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(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 legacyscenes:
            del session['moviescenes']
            session['scene_dict'] = _self.pymol._scene_dict
            session['scene_order'] = legacyscenes
            pymol.viewing._legacy_scene('*', 'clear', _self=_self)
            del _self.pymol._scene_dict

        if is_ok(r):
            if pse_export_version > 0.0:
                try:
                    _session_convert_legacy(session, pse_export_version, _self)
                except Exception as e:
                    print(' Warning: failed to backport session:', e)

            if(compress<0):
                compress = _self.get_setting_boolean('session_compression')
            if(compress):
                import zlib
                session = zlib.compress(cPickle.dumps(session, 1))
            return session
        elif _self._raising(r,_self):
            raise QuietException                  
        return r