Scripts: surfvert.py

File surfvert.py, 1.2 KB (added by goddard, 17 years ago)
Line 
1#
2# Write the surface vertices of a molecular surface together with the chain
3# id and residue number of the closest residue.
4#
5# To use this script, create the molecular surface, select it, and then
6# open the script (File / Open).
7#
8
9# Get selected molecular surface models
10from chimera import selection,MSMSModel
11slist = [m for m in selection.currentGraphs() if isinstance(m, MSMSModel)]
12
13# Collect surface vertex chain id, residue id, and vertex x,y,z coordinates.
14vertices = []
15for s in slist:
16 va, ta = s.surface_piece.geometry # vertex and triangle arrays
17 for i,v in enumerate(va):
18 x,y,z = v
19 atom = s.atomMap[i]
20 r = atom.residue
21 vertices.append((r.id.chainId, r.id.position, x, y, z))
22vertices.sort()
23
24# Create text with one line per vertex.
25lines = ['%3s %3d %10.5f %10.5f %10.5f' % vinfo for vinfo in vertices]
26text = '\n'.join(lines)
27
28# Write text to a file chosen by user.
29def save_text(okayed, dialog, text = text):
30 if okayed:
31 path = dialog.getPaths()[0]
32 f = open(path, 'w')
33 f.write(text)
34 f.close()
35
36# Show dialog to choose file.
37from OpenSave import SaveModeless
38SaveModeless(command=save_text, historyID="main chimera import dialog").enter()