| 1 | # Calculate the volume of each connected surface component and then delete
|
|---|
| 2 | # all but the largest component.
|
|---|
| 3 |
|
|---|
| 4 | # Find all surface models
|
|---|
| 5 | from chimera import openModels
|
|---|
| 6 | from _surface import SurfaceModel
|
|---|
| 7 | surfs = openModels.list(modelTypes = [SurfaceModel])
|
|---|
| 8 |
|
|---|
| 9 | # Divide surface into connected pieces, report volumes, delete all but largest.
|
|---|
| 10 | from Surface import actions
|
|---|
| 11 | from MeasureVolume import enclosed_volume
|
|---|
| 12 | for s in surfs:
|
|---|
| 13 | pieces = []
|
|---|
| 14 | for p in s.surfacePieces:
|
|---|
| 15 | # Split surface piece into connected components.
|
|---|
| 16 | cplist = actions.split_surface_piece(p)
|
|---|
| 17 | for cp in cplist:
|
|---|
| 18 | # Calculate volume.
|
|---|
| 19 | varray, tarray = cp.geometry
|
|---|
| 20 | v, holes = enclosed_volume(varray, tarray)
|
|---|
| 21 | if holes == 0:
|
|---|
| 22 | pieces.append((v, cp))
|
|---|
| 23 | if pieces:
|
|---|
| 24 | # Print volumes.
|
|---|
| 25 | pieces.sort()
|
|---|
| 26 | pieces.reverse()
|
|---|
| 27 | volumes = ', '.join(['%.3g' % v for v,p in pieces])
|
|---|
| 28 | print 'Volumes ', volumes
|
|---|
| 29 | # Delete all but largest volume piece.
|
|---|
| 30 | v0, p0 = pieces[0]
|
|---|
| 31 | for p in s.surfacePieces:
|
|---|
| 32 | if p != p0:
|
|---|
| 33 | s.removePiece(p)
|
|---|