"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/pymol/__init__.py" between
pymol-v1.8.6.0.tar.bz2 and pymol-v2.1.0.tar.bz2

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

__init__.py  (pymol-v1.8.6.0.tar.bz2):__init__.py  (pymol-v2.1.0.tar.bz2)
skipping to change at line 70 skipping to change at line 70
# from a terminal where the user could set pymol_argv # from a terminal where the user could set pymol_argv
args = getattr(__main__, "pymol_argv", None) args = getattr(__main__, "pymol_argv", None)
# standard launch (consume main thread) # standard launch (consume main thread)
import pymol import pymol
pymol.launch(args) pymol.launch(args)
# this should never be reached because PyMOL will exit the process # this should never be reached because PyMOL will exit the process
raise SystemExit raise SystemExit
if sys.version_info[0] > 2: IS_PY2 = sys.version_info[0] == 2
IS_PY3 = sys.version_info[0] == 3
IS_WINDOWS = sys.platform.startswith('win')
IS_MACOS = sys.platform.startswith('darwin')
IS_LINUX = sys.platform.startswith('linux')
if IS_PY3:
# legacy string API, still used by Pmw for example # legacy string API, still used by Pmw for example
import string import string
for attr in ['capitalize', 'count', 'find', 'index', 'lower', for attr in ['capitalize', 'count', 'find', 'index', 'lower',
'replace', 'rstrip', 'split', 'strip', 'upper', 'zfill']: 'replace', 'rstrip', 'split', 'strip', 'upper', 'zfill']:
setattr(string, attr, getattr(str, attr)) setattr(string, attr, getattr(str, attr))
string.letters = string.ascii_letters string.letters = string.ascii_letters
string.lowercase = string.ascii_lowercase string.lowercase = string.ascii_lowercase
string.join = lambda words, sep=' ': sep.join(words) string.join = lambda words, sep=' ': sep.join(words)
string.atoi = int string.atoi = int
skipping to change at line 191 skipping to change at line 197
Guess PYMOL_PATH from typical locations and return it as string. Guess PYMOL_PATH from typical locations and return it as string.
''' '''
init_file = os.path.abspath(__file__) init_file = os.path.abspath(__file__)
pymol_path_candidates = [ pymol_path_candidates = [
# $PYMOL_PATH == <site-packages>/pymol/pymol_path # $PYMOL_PATH == <site-packages>/pymol/pymol_path
os.path.join(os.path.dirname(init_file), 'pymol_path'), os.path.join(os.path.dirname(init_file), 'pymol_path'),
# $PYMOL_PATH/modules/pymol/__init__.py # $PYMOL_PATH/modules/pymol/__init__.py
re.sub(r"[\/\\]modules[\/\\]pymol[\/\\]__init__\.py[c]*$", "", init_file ), re.sub(r"[\/\\]modules[\/\\]pymol[\/\\]__init__\.py[c]*$", "", init_file ),
# /usr/share/pymol
os.path.join(sys.prefix, 'share', 'pymol'),
] ]
for pymol_path in pymol_path_candidates: for pymol_path in pymol_path_candidates:
if os.path.isdir(pymol_path): if os.path.isdir(pymol_path):
return pymol_path return pymol_path
return '.' return '.'
def setup_environ(): def setup_environ():
# guess PYMOL_PATH if unset # guess PYMOL_PATH if unset
skipping to change at line 254 skipping to change at line 263
def exec_deferred(self): def exec_deferred(self):
''' '''
Execute the stuff from invocations.options.deferred Execute the stuff from invocations.options.deferred
''' '''
try: try:
from socket import error as socket_error from socket import error as socket_error
except ImportError: except ImportError:
socket_error = None socket_error = None
print('import socket failed') print('import socket failed')
import pymol as _pymol
cmd = self.cmd cmd = self.cmd
_pymol = cmd._pymol
# read from stdin (-p) # read from stdin (-p)
if self.invocation.options.read_stdin and not _pymol._stdin_reader_thread: if self.invocation.options.read_stdin and not _pymol._stdin_reader_thread:
try: try:
t = _pymol._stdin_reader_thread = \ t = _pymol._stdin_reader_thread = \
threading.Thread(target=cmd._parser.stdin_reader) threading.Thread(target=cmd._parser.stdin_reader)
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
except: except:
traceback.print_exc() traceback.print_exc()
skipping to change at line 315 skipping to change at line 323
elif vendor.startswith('Mesa'): elif vendor.startswith('Mesa'):
if renderer[0:18]=='Mesa GLX Indirect': if renderer[0:18]=='Mesa GLX Indirect':
pass pass
elif vendor.startswith('ATI'): elif vendor.startswith('ATI'):
if renderer[0:17] == 'FireGL2 / FireGL3': # obsolete ? if renderer[0:17] == 'FireGL2 / FireGL3': # obsolete ?
if invocation.options.show_splash: if invocation.options.show_splash:
print(" Adapting to FireGL hardware.") print(" Adapting to FireGL hardware.")
cmd.set('line_width', 2, quiet=1) cmd.set('line_width', 2, quiet=1)
if sys.platform.startswith('win'): if IS_WINDOWS:
if sys.getwindowsversion()[0] > 5: if sys.getwindowsversion()[0] > 5:
# prevent color corruption by calling glFlush etc. # prevent color corruption by calling glFlush etc.
cmd.set('ati_bugs', 1) cmd.set('ati_bugs', 1)
if 'Radeon HD' in renderer: if 'Radeon HD' in renderer:
if invocation.options.show_splash: if invocation.options.show_splash:
print(" Adjusting settings to improve performance for ATI cards. ") print(" Adjusting settings to improve performance for ATI cards. ")
if cmd.get_setting_int("use_shaders")==0: if cmd.get_setting_int("use_shaders")==0:
# limit frame rate to 30 fps to avoid ATI "jello" # limit frame rate to 30 fps to avoid ATI "jello"
skipping to change at line 368 skipping to change at line 376
except: except:
pass pass
# store our adapted state as default # store our adapted state as default
cmd.reinitialize("store") cmd.reinitialize("store")
def launch_gui(self): def launch_gui(self):
''' '''
Launch if requested: Launch if requested:
- external GUI - external GUI
- RPC server
''' '''
pymol_path = os.getenv('PYMOL_PATH', '') pymol_path = os.getenv('PYMOL_PATH', '')
try: try:
poll = (sys.platform == 'darwin') poll = IS_MACOS
if self.invocation.options.external_gui == 3: if self.invocation.options.external_gui == 3:
if 'DISPLAY' not in os.environ: if 'DISPLAY' not in os.environ:
os.environ['DISPLAY'] = ':0.0' os.environ['DISPLAY'] = ':0.0'
if self.invocation.options.external_gui in (1, 3): if self.invocation.options.external_gui in (1, 3):
__import__(self.invocation.options.gui) __import__(self.invocation.options.gui)
sys.modules[self.invocation.options.gui].__init__(self, poll, sys.modules[self.invocation.options.gui].__init__(self, poll,
skin = self.invocation.options.skin) skin = self.invocation.options.skin)
# import plugin system # import plugin system
import pymol.plugins import pymol.plugins
# -- Greg Landrum's RPC stuff
if self.invocation.options.rpcServer:
from pymol import rpc
rpc.launch_XMLRPC()
# --
except: except:
traceback.print_exc() traceback.print_exc()
def prime_pymol(): def prime_pymol():
''' '''
Set the current thread as the glutThread Set the current thread as the glutThread
Launch X11 on OSX (legacy)
''' '''
global glutThread global glutThread
if not glutThread: if not glutThread:
glutThread = thread.get_ident() glutThread = thread.get_ident()
# legacy X11 launching on OSX def _launch_no_gui():
if sys.platform == 'darwin' and invocation.options.external_gui == 1: import pymol2
xdpyinfo = "/opt/X11/bin/xdpyinfo"
if not os.path.exists(xdpyinfo) or \ p = pymol2.SingletonPyMOL()
os.system(xdpyinfo + " >/dev/null 2>&1"): p.start()
# launch X11 (if needed)
os.system("/usr/bin/open -a X11") # TODO sufficient?
while (p.idle() or p.getRedisplay() or
invocation.options.keep_thread_alive or
cmd.get_modal_draw() or
cmd.get_setting_int('keep_alive') or
cmd._pymol._stdin_reader_thread is not None):
p.draw()
# TODO needed?
cmd.sync()
p.stop()
def launch(args=None, block_input_hook=0): def launch(args=None, block_input_hook=0):
''' '''
Run PyMOL with args Run PyMOL with args
Only returns if we are running pretend GLUT. Only returns if we are running pretend GLUT.
''' '''
if args is None: if args is None:
args = sys.argv args = sys.argv
invocation.parse_args(args) invocation.parse_args(args)
if invocation.options.gui == 'pmg_qt':
if invocation.options.no_gui:
return _launch_no_gui()
try:
from pmg_qt import pymol_qt_gui
sys.exit(pymol_qt_gui.execapp())
except ImportError:
print('Qt not available, using GLUT/Tk interface')
invocation.options.gui = 'pmg_tk'
prime_pymol() prime_pymol()
_cmd.runpymol(_cmd._get_global_C_object(), block_input_hook) _cmd.runpymol(_cmd._get_global_C_object(), block_input_hook)
def finish_launching(args=None): def finish_launching(args=None):
''' '''
Start the PyMOL process in a thread Start the PyMOL process in a thread
''' '''
global glutThreadObject global glutThreadObject
if cmd._COb is not None: if cmd._COb is not None:
skipping to change at line 480 skipping to change at line 502
if label: if label:
self.label = label self.label = label
def __str__(self): def __str__(self):
return " %s: %s" % (self.label, self.message) return " %s: %s" % (self.label, self.message)
class IncentiveOnlyException(CmdException): class IncentiveOnlyException(CmdException):
''' '''
Exception type for features that are not available in Open-Source PyMOL Exception type for features that are not available in Open-Source PyMOL
''' '''
label = "Incentive-Only-Error" label = "Incentive-Only-Error"
def __init__(self, *args, **kwargs): def __init__(self, message=''):
super(IncentiveOnlyException, self).__init__(*args, **kwargs) if not message:
if not self.message:
try: try:
funcname = sys._getframe(1).f_code.co_name funcname = sys._getframe(1).f_code.co_name
self.message = '"%s" is not available in Open-Source PyMOL' % (f uncname,) message = '"%s" is not available in Open-Source PyMOL' % (funcna me,)
except: except:
self.message = 'Not available in Open-Source PyMOL' message = 'Not available in Open-Source PyMOL'
self.message += '\n\n' \ message += '\n\n' \
' Please visit http://pymol.org if you are interested in the\n' \ ' Please visit http://pymol.org if you are interested in the\n' \
' full featured "Incentive PyMOL" version.\n' ' full featured "Incentive PyMOL" version.\n'
super(IncentiveOnlyException, self).__init__(message)
class Scratch_Storage: class Scratch_Storage:
''' '''
Generic namespace Generic namespace
''' '''
def __reduce__(self):
# for loading Python 3 (new-style class) pickle with Python 2
return (self.__class__, (), self.__dict__)
def get_unused_name(self, prefix='tmp'): def get_unused_name(self, prefix='tmp'):
''' '''
Get an unused name from this namespace Get an unused name from this namespace
''' '''
i = 1 i = 1
while True: while True:
name = prefix + str(i) name = prefix + str(i)
if not hasattr(self, name): if not hasattr(self, name):
setattr(self, name, None) setattr(self, name, None)
return name return name
i += 1 i += 1
class Session_Storage: class Session_Storage:
''' '''
Generic namespace Generic namespace
''' '''
pass def __reduce__(self):
# for loading Python 3 (new-style class) pickle with Python 2
return (self.__class__, (), self.__dict__)
def _colortype(cmd):
# backwards compatible color index type for iterate, which used
# to expose colors as RGB tuples
get_color_tuple = cmd.get_color_tuple
class Color(int):
def __getitem__(self, i):
return get_color_tuple(self)[i]
def __len__(self):
return 3
return Color
######### VARIABLES ############################ ######### VARIABLES ############################
glutThread = 0 glutThread = 0
######### ENVIRONMENT ########################## ######### ENVIRONMENT ##########################
setup_environ() setup_environ()
# initialize instance-specific module/object internals # initialize instance-specific module/object internals
skipping to change at line 562 skipping to change at line 602
# The following causes an import error for "import cmd": # The following causes an import error for "import cmd":
class _NoCmdFinder: class _NoCmdFinder:
def find_spec(self, fullname, path=None, target=None): def find_spec(self, fullname, path=None, target=None):
if path is None and fullname == 'cmd': if path is None and fullname == 'cmd':
msg = 'use "from pymol import cmd" instead of "import cmd"' msg = 'use "from pymol import cmd" instead of "import cmd"'
raise CmdException(msg) raise CmdException(msg)
return None return None
find_module = find_spec find_module = find_spec
sys.meta_path.insert(0, _NoCmdFinder())
########## LEGACY PRINT STATEMENT FOR PYMOL COMMAND LINE ################### ########## LEGACY PRINT STATEMENT FOR PYMOL COMMAND LINE ###################
if sys.version_info[0] > 2: if IS_PY3:
def _print_statement(*args, **_): def _print_statement(*args, **_):
'''Legacy Python-2-like print statement for the PyMOL command line''' '''Legacy Python-2-like print statement for the PyMOL command line'''
kw = {} kw = {}
if args and args[0].startswith('>>'): if args and args[0].startswith('>>'):
kw['file'] = eval(args[0][2:]) kw['file'] = eval(args[0][2:])
args = args[1:] args = args[1:]
if args and not args[-1]: if args and not args[-1]:
kw['end'] = ' ' kw['end'] = ' '
args = args[:-1] args = args[:-1]
args = [eval(a) for a in args] args = [eval(a) for a in args]
 End of changes. 19 change blocks. 
28 lines changed or deleted 70 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)