| 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
|
|---|
| 10 | from chimera import selection,MSMSModel
|
|---|
| 11 | slist = [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.
|
|---|
| 14 | vertices = []
|
|---|
| 15 | for 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))
|
|---|
| 22 | vertices.sort()
|
|---|
| 23 |
|
|---|
| 24 | # Create text with one line per vertex.
|
|---|
| 25 | lines = ['%3s %3d %10.5f %10.5f %10.5f' % vinfo for vinfo in vertices]
|
|---|
| 26 | text = '\n'.join(lines)
|
|---|
| 27 |
|
|---|
| 28 | # Write text to a file chosen by user.
|
|---|
| 29 | def 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.
|
|---|
| 37 | from OpenSave import SaveModeless
|
|---|
| 38 | SaveModeless(command=save_text, historyID="main chimera import dialog").enter()
|
|---|