Dump2CGO: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Overview = Dumps a PyMOL object to a CGO object. = The Code = <source lang="python"> from pymol import cmd from pymol.cgo import * def dump2surfaceCGO(): CGOobj = [] ...") |
m (py3) |
||
(One intermediate revision by one other user not shown) | |||
Line 72: | Line 72: | ||
cgo = dump2surfaceCGO() | cgo = dump2surfaceCGO() | ||
else: | else: | ||
print "Unknown type" | print("Unknown type") | ||
return | return | ||
Line 82: | Line 82: | ||
[[Category:Script_Library]] [[Category:Math_Scripts]] | [[Category:Script_Library]] [[Category:Math_Scripts]] | ||
[[Category:CGO]] |
Latest revision as of 09:05, 26 February 2018
Overview
Dumps a PyMOL object to a CGO object.
The Code
from pymol import cmd
from pymol.cgo import *
def dump2surfaceCGO():
CGOobj = []
dumpedFile = open("dump.tmp").read()
for block in dumpedFile.split('\n\n'):
CGOobj.append(BEGIN)
CGOobj.append(TRIANGLES)
for line in block.split('\n'):
if line == '':
continue
vals = line.split()
CGOobj.append(NORMAL)
CGOobj.append(float(vals[3]))
CGOobj.append(float(vals[4]))
CGOobj.append(float(vals[5]))
CGOobj.append(VERTEX)
CGOobj.append(float(vals[0]))
CGOobj.append(float(vals[1]))
CGOobj.append(float(vals[2]))
CGOobj.append(END)
return CGOobj
def dump2meshCGO():
CGOobj = []
dumpedFile = open("dump.tmp").read()
for block in dumpedFile.split('\n\n'):
CGOobj.append(BEGIN)
CGOobj.append(LINE_STRIP)
for line in block.split('\n'):
if line == '':
continue
CGOobj.append(VERTEX)
vals = line.split()
CGOobj.append(float(vals[0]))
CGOobj.append(float(vals[1]))
CGOobj.append(float(vals[2]))
CGOobj.append(END)
return CGOobj
def getType(objname):
session = cmd.get_session()['names']
for obj in session:
if obj == None:
continue
if obj[0] != objname:
continue
return obj[4]
return -1
def dump2CGO(obj):
cmd.dump("dump.tmp", obj)
type = getType(obj)
cgo = []
if (type == 3): # Mesh
cgo = dump2meshCGO()
elif (type == 7): #Surface
cgo = dump2surfaceCGO()
else:
print("Unknown type")
return
cmd.load_cgo(cgo, "CGO " + obj)
cmd.extend('dump2CGO', dump2CGO)
cmd.auto_arg[0]['dump2CGO'] = [cmd.object_sc, 'object', '']