Michael Lerner wrote, On 04/08/11 20:16:
It's not elegant at all, but it's worth knowing that you can use cmd.do("...") as a quick fix for lines that aren't immediately easy to convert.

Even a mostly-working pml2py tool would be a useful addition to the wiki.

mostly-working script attached, have fun!

Cheers,
  Thomas

--
Thomas Holder
MPI for Developmental Biology
Spemannstr. 35
D-72076 Tübingen
'''
http://sourceforge.net/mailarchive/message.php?msg_id=27331786
Subject: [PyMOL] Convert pml script to Pymol Python script
Date: Fri, 8 Apr 2011 18:01:32 +0100
'''

import sys
from pymol import cmd

def pml2py(filename, out=sys.stdout):
	'''
DESCRIPTION

    Convert a pml script to python syntax.

USAGE

    pml2py infile [, outfile]

TODO

    comments, aliases
	'''
	if isinstance(out, basestring):
		out = open(out, 'w')
	print >> out, '''
# automatically converted from '%s'
import pymol
from pymol import *
''' % (filename)
	handle = open(filename)
	for line in handle:
		a = line.split(None, 1)
		try:
			name = a[0]
			name = cmd.kwhash.shortcut.get(name, name)
			assert name in cmd.keyword
			func = cmd.keyword[name][0]
			assert func.func_name != 'python_help'
		except:
			out.write(line)
			continue
		if len(a) > 1:
			args = [i.strip() for i in a[1].split(',')]
		else:
			args = []

		if name == 'python':
			for line in handle:
				if line.split() == ['python', 'end']:
					break
				out.write(line)
			continue

		print >> out, '%s.%s(%s)' % (func.__module__, func.func_name, ', '.join(map(repr, args)))

cmd.extend('pml2py', pml2py)
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to