"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/pymol/exporting.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.

exporting.py  (pymol-v1.8.6.0.tar.bz2):exporting.py  (pymol-v2.1.0.tar.bz2)
skipping to change at line 22 skipping to change at line 22
#-* #-*
#Z* ------------------------------------------------------------------- #Z* -------------------------------------------------------------------
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
if __name__=='pymol.exporting': if __name__=='pymol.exporting':
import os import os
import sys import sys
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
import thread import thread
import cPickle
else: else:
import _thread as thread import _thread as thread
import pickle as cPickle
from . import selector from . import selector
import re import re
import copy import copy
import pymol import pymol
cmd = sys.modules["pymol.cmd"] cmd = sys.modules["pymol.cmd"]
from .cmd import _cmd,lock,unlock,Shortcut,QuietException from .cmd import _cmd,lock,unlock,Shortcut,QuietException
from chempy import io from chempy import io
from chempy.pkl import cPickle
from chempy.sdf import SDF,SDFRec from chempy.sdf import SDF,SDFRec
from .cmd import _feedback,fb_module,fb_mask, \ from .cmd import _feedback,fb_module,fb_mask, \
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error, \ DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error, \
is_list, is_dict, is_tuple, loadable is_list, is_dict, is_tuple, loadable
import traceback import traceback
def copy_image(quiet=1,_self=cmd): # incentive feature / proprietary def copy_image(quiet=1,_self=cmd): # incentive feature / proprietary
r = DEFAULT_ERROR r = DEFAULT_ERROR
if thread.get_ident() == pymol.glutThread: if thread.get_ident() == pymol.glutThread:
r = _self._copy_image(_self,int(quiet)) r = _self._copy_image(_self,int(quiet))
else: else:
r = _self.do('cmd._copy_image(quiet=%d,_self=cmd)'%int(quiet)) r = _self.do('cmd._copy_image(quiet=%d)'%int(quiet))
if _self._raising(r,_self): raise QuietException if _self._raising(r,_self): raise QuietException
return r return r
cache_action_dict = { cache_action_dict = {
'enable' : 0, 'enable' : 0,
'disable' : 1, 'disable' : 1,
'read_only' : 2, 'read_only' : 2,
'clear' : 3, 'clear' : 3,
'optimize' : 4, 'optimize' : 4,
} }
skipping to change at line 362 skipping to change at line 361
def get_session(names='', partial=0, quiet=1, compress=-1, cache=-1, _self=c md): def get_session(names='', partial=0, quiet=1, compress=-1, cache=-1, _self=c md):
session = {} session = {}
r = DEFAULT_SUCCESS r = DEFAULT_SUCCESS
cache = int(cache) cache = int(cache)
compress = int(compress) compress = int(compress)
partial = int(partial) partial = int(partial)
pse_export_version = round(_self.get_setting_float('pse_export_version') , 4) pse_export_version = round(_self.get_setting_float('pse_export_version') , 4)
legacyscenes = (0 < pse_export_version < 1.76) and _self.get_scene_list( ) 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 experimenta
l')
cPickle.configure_legacy_dump(legacypickle)
if legacyscenes: if legacyscenes:
_self.pymol._scene_dict = {} _self.pymol._scene_dict = {}
scene_current_name = _self.get('scene_current_name') scene_current_name = _self.get('scene_current_name')
tempname = '_scene_db96724c3cef00875c3bebb4f348f711' tempname = '_scene_db96724c3cef00875c3bebb4f348f711'
_self.scene(tempname, 'store') _self.scene(tempname, 'store')
for name in legacyscenes: for name in legacyscenes:
_self.scene(name, 'recall', animate=0) _self.scene(name, 'recall', animate=0)
wizard = _self.get_wizard() wizard = _self.get_wizard()
skipping to change at line 632 skipping to change at line 637
ref_state = int: state of ref object {default: -1} ref_state = int: state of ref object {default: -1}
multi = int: for multi-entry file formats, 0 = single entry, multi = int: for multi-entry file formats, 0 = single entry,
1 = by object, 2 = by object-state, -1 = format default {default: -1} 1 = by object, 2 = by object-state, -1 = format default {default: -1}
''' '''
with _self.lockcm: with _self.lockcm:
return _cmd.get_str(_self._COb, str(format), str(selection), return _cmd.get_str(_self._COb, str(format), str(selection),
int(state) - 1, str(ref), int(ref_state), int(state) - 1, str(ref), int(ref_state),
int(multi), int(quiet)) int(multi), int(quiet))
def multifilesave(filename, selection='*', state=-1, format='', ref='',
ref_state=-1, quiet=1, _self=cmd):
'''
DESCRIPTION
For a selection that spans multiple molecular objects and/or states,
save each object and/or state to a separate file. Takes a filename
argument with placeholders:
{name} : object name
{state} : state number
{title} : state title
{num} : file number
{} : object name (first) or state (second)
EXAMPLES
multifilesave /tmp/{name}.pdb
multifilesave /tmp/{name}-{state}.cif, state=0
multifilesave /tmp/{}-{}.cif, state=0
multifilesave /tmp/{}-{title}.sdf, state=0
'''
for (fname, osele, ostate) in multifilenamegen(
filename, selection, int(state), _self):
r = _self.save(fname, osele, ostate, format, ref, ref_state, quiet)
return r
def multifilenamegen(filename, selection, state, _self=cmd):
'''Given a filename pattern, atom selection and state argument,
Generate object-state specific filenames and selections.
'''
import string
filename = _self.exp_path(filename)
fmt_keys = [v[1]
for v in string.Formatter().parse(filename)
if v[1] is not None]
nindexed = fmt_keys.count('')
multiobject = nindexed > 0 or 'name' in fmt_keys or 'num' in fmt_keys
multistate = nindexed > 1 or 'state' in fmt_keys or 'title' in fmt_keys
if not (multiobject or multistate):
raise ValueError('need one or more of {name}, {num}, {state}, {title
}')
odata = []
for oname in _self.get_object_list(selection):
osele = '(%s) & ?%s' % (selection, oname)
first = last = state
if multistate:
if state < 0:
first = last = _self.get_object_state(oname)
if first == 0:
first = 1
last = _self.count_states('%' + oname)
for ostate in range(first, last + 1):
odata.append((oname, osele, ostate))
# pad {state} and {num} with zeros
swidth = len(str(max(v[2] for v in odata)))
nwidth = len(str(len(odata)))
filename = filename.replace('{state}', '{state:0%d}' % swidth)
filename = filename.replace('{num}', '{num:0%d}' % nwidth)
for num, (oname, osele, ostate) in enumerate(odata, 1):
fname = filename.format(oname, ostate,
name=oname, state=ostate, num=num,
title=_self.get_title(oname, ostate))
yield fname, osele, ostate
def save(filename, selection='(all)', state=-1, format='', ref='', def save(filename, selection='(all)', state=-1, format='', ref='',
ref_state=-1, quiet=1, partial=0,_self=cmd): ref_state=-1, quiet=1, partial=0,_self=cmd):
''' '''
DESCRIPTION DESCRIPTION
"save" writes content to a file. "save" writes content to a file.
USAGE USAGE
save filename [, selection [, state [, format ]]] save filename [, selection [, state [, format ]]]
skipping to change at line 683 skipping to change at line 762
load, get_model load, get_model
''' '''
quiet = int(quiet) quiet = int(quiet)
# preprocess selection # preprocess selection
selection = selector.process(selection) selection = selector.process(selection)
# #
r = DEFAULT_ERROR r = DEFAULT_ERROR
# analyze filename # analyze filename
from pymol.importing import filename_to_format from pymol.importing import filename_to_format, _eval_func
_, _, format_guessed, zipped = filename_to_format(filename) _, _, format_guessed, zipped = filename_to_format(filename)
filename = _self.exp_path(filename) filename = _self.exp_path(filename)
# file format # file format
if not format: if not format:
if not format_guessed: if not format_guessed:
raise pymol.CmdException('Unrecognized file format') raise pymol.CmdException('Unrecognized file format')
format = format_guessed format = format_guessed
# PyMOL session # PyMOL session
skipping to change at line 712 skipping to change at line 791
'mmod': io.mmd.toFile, 'mmod': io.mmd.toFile,
'pkl': io.pkl.toFile, # binary pickle 'pkl': io.pkl.toFile, # binary pickle
'pkla': lambda model, filename: io.pkl.toFile(model, filename, bin=0 ), # ascii pickle 'pkla': lambda model, filename: io.pkl.toFile(model, filename, bin=0 ), # ascii pickle
} }
contents = None contents = None
if format in savefunctions: if format in savefunctions:
# generic forwarding to format specific save functions # generic forwarding to format specific save functions
func = savefunctions[format] func = savefunctions[format]
func = _eval_func(func)
kw = { kw = {
'filename': filename, 'filename': filename,
'selection': selection, 'selection': selection,
'name': selection, # alt (get_ccp4str) 'name': selection, # alt (get_ccp4str)
'state': state, 'state': state,
'format': format, 'format': format,
'ref': ref, 'ref': ref,
'ref_state': ref_state, 'ref_state': ref_state,
'quiet': quiet, 'quiet': quiet,
'partial': partial, 'partial': partial,
skipping to change at line 817 skipping to change at line 897
return get_str('mae', selection, state, ref, ref_state, -1, quiet, _self ) return get_str('mae', selection, state, ref, ref_state, -1, quiet, _self )
def get_ccp4str(name, state=1, quiet=1, _self=cmd): def get_ccp4str(name, state=1, quiet=1, _self=cmd):
with _self.lockcm: with _self.lockcm:
return _cmd.get_ccp4str(_self._COb, str(name), return _cmd.get_ccp4str(_self._COb, str(name),
int(state) - 1, int(quiet)) int(state) - 1, int(quiet))
def get_psestr(selection, partial, quiet, _self): def get_psestr(selection, partial, quiet, _self):
if '(' in selection: # ignore selections if '(' in selection: # ignore selections
selection = '' selection = ''
return cPickle.dumps(_self.get_session(selection, partial, quiet), 1) session = _self.get_session(selection, partial, quiet)
return cPickle.dumps(session, 1)
def _get_mtl_obj(format, _self): def _get_mtl_obj(format, _self):
# TODO mtl not implemented, always returns empty string # TODO mtl not implemented, always returns empty string
if format == 'mtl':
raise pymol.CmdException('.MTL export not implemented')
i = {'mtl': 0, 'obj': 1}.get(format) i = {'mtl': 0, 'obj': 1}.get(format)
return _self.get_mtl_obj()[i] return _self.get_mtl_obj()[i]
from . import querying
savefunctions = { savefunctions = {
'cif': get_str, # mmCIF 'cif': get_str, # mmCIF
'xyz': get_str, 'xyz': get_str,
'pdb': get_str, 'pdb': get_str,
'pqr': get_str, 'pqr': get_str,
'sdf': get_str, 'sdf': get_str,
'mol2': get_str, 'mol2': get_str,
'mae': get_str, 'mae': get_str,
'mol': get_str, 'mol': get_str,
'mmtf': 'pymol.lazyio:get_mmtfstr',
'pse': get_psestr, 'pse': get_psestr,
'psw': get_psestr, 'psw': get_psestr,
'fasta': get_fastastr, 'fasta': get_fastastr,
'aln': get_alnstr, 'aln': get_alnstr,
'ccp4': get_ccp4str, 'ccp4': get_ccp4str,
'png': png, 'png': png,
# no arguments (some have a "version" argument) # no arguments (some have a "version" argument)
'dae': querying.get_collada, 'dae': 'pymol.querying:get_collada',
'wrl': querying.get_vrml, 'wrl': 'pymol.querying:get_vrml',
'pov': querying.get_povray, 'pov': 'pymol.querying:get_povray',
'idtf': querying.get_idtf, 'idtf': 'pymol.querying:get_idtf',
'mtl': _get_mtl_obj, # TODO not implemented 'mtl': _get_mtl_obj, # TODO not implemented
'obj': _get_mtl_obj, 'obj': _get_mtl_obj,
} }
 End of changes. 13 change blocks. 
11 lines changed or deleted 95 lines changed or added

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