Beispiel #1
0
    def quit(code=0, _self=cmd):
        '''
DESCRIPTION

    "quit" terminates the program. 

USAGE

    quit

PYMOL API

    cmd.quit()
        '''
        code = int(code)
        if thread.get_ident() == pymol.glutThread:
            _self._quit(code, _self)
        else:
            try:
                _self.lock(_self)
                _cmd.do(_self._COb,
                        "_ time.sleep(0.100);cmd._quit(%d)" % (code), 0, 0)
                # allow time for a graceful exit from the calling thread
                try:
                    thread.exit()
                except SystemExit:
                    pass
            finally:
                _self.unlock(-1, _self=_self)
        return None
Beispiel #2
0
    def quit(_self=cmd):
        '''
DESCRIPTION

    "quit" terminates the program. 

USAGE

    quit

PYMOL API

    cmd.quit()
        '''
        if thread.get_ident() == pymol.glutThread:
            _self._quit(_self)
        else:
            try:
                _self.lock(_self)
                _cmd.do(_self._COb,"_ time.sleep(0.100);cmd._quit()",0,0)
                # allow time for a graceful exit from the calling thread
                try:
                    thread.exit()
                except SystemExit:
                    pass
            finally:
                _self.unlock(-1,_self=_self)
        return None
Beispiel #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
Beispiel #4
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