| 1 | # ----------------------------------------------------------------------------
|
|---|
| 2 | # Save images of orthographically projected surface silhouettes for several
|
|---|
| 3 | # orientations.
|
|---|
| 4 | #
|
|---|
| 5 | # Create surfaces then open this script in Chimera (File / Open) to create
|
|---|
| 6 | # the images. Tested in Chimera 1.4 daily build September 2, 2009.
|
|---|
| 7 | #
|
|---|
| 8 | def surface_silhouette_images(directory = '~/Desktop/silhouettes',
|
|---|
| 9 | filename = 'sil_%04d.png',
|
|---|
| 10 | axis = 'y', angle_step = 10, count = 36,
|
|---|
| 11 | multilayer = False):
|
|---|
| 12 |
|
|---|
| 13 | # Find all surface models
|
|---|
| 14 | from chimera import openModels as om, runCommand as run, replyobj
|
|---|
| 15 | from _surface import SurfaceModel
|
|---|
| 16 | surfs = om.list(modelTypes = [SurfaceModel])
|
|---|
| 17 | if len(surfs) == 0:
|
|---|
| 18 | replyobj.warning('surfsilhouette.py: No surfaces')
|
|---|
| 19 | return
|
|---|
| 20 |
|
|---|
| 21 | # Turn off lighting for surfaces
|
|---|
| 22 | for s in surfs:
|
|---|
| 23 | for p in s.surfacePieces:
|
|---|
| 24 | p.useLighting = False
|
|---|
| 25 |
|
|---|
| 26 | # Color surfaces white, or transparent gray for multilayer.
|
|---|
| 27 | if multilayer:
|
|---|
| 28 | for s in surfs:
|
|---|
| 29 | s.oneTransparentLayer = False
|
|---|
| 30 | for p in s.surfacePieces:
|
|---|
| 31 | p.vertexColors = None
|
|---|
| 32 | p.color = (.1,.1,.1,0)
|
|---|
| 33 | p.tranparencyBlendMode = p.SRC_1_DST_1_MINUS_ALPHA # Add
|
|---|
| 34 | else:
|
|---|
| 35 | for s in surfs:
|
|---|
| 36 | for p in s.surfacePieces:
|
|---|
| 37 | p.vertexColors = None
|
|---|
| 38 | p.color = (1,1,1,1)
|
|---|
| 39 |
|
|---|
| 40 | # Turn off depth cueing.
|
|---|
| 41 | run('~set depth_cue')
|
|---|
| 42 |
|
|---|
| 43 | # Set orthographic projection
|
|---|
| 44 | run('set projection orthographic')
|
|---|
| 45 |
|
|---|
| 46 | # Turn off glossy lighting
|
|---|
| 47 | run('set light_quality normal')
|
|---|
| 48 |
|
|---|
| 49 | # Expand ~ to user's home directory.
|
|---|
| 50 | from OpenSave import tildeExpand
|
|---|
| 51 | directory = tildeExpand(directory)
|
|---|
| 52 |
|
|---|
| 53 | # Make directory if it doesn't exist.
|
|---|
| 54 | import os, os.path
|
|---|
| 55 | if not os.path.isdir(directory):
|
|---|
| 56 | os.mkdir(directory)
|
|---|
| 57 |
|
|---|
| 58 | # Save images.
|
|---|
| 59 | for i in range(count):
|
|---|
| 60 | path = os.path.join(directory, filename % i)
|
|---|
| 61 | run('copy file %s' % path)
|
|---|
| 62 | run('turn %s %f' % (axis, angle_step))
|
|---|
| 63 |
|
|---|
| 64 | # ----------------------------------------------------------------------------
|
|---|
| 65 | #
|
|---|
| 66 | surface_silhouette_images()
|
|---|
| 67 | #surface_silhouette_images(multilayer = True)
|
|---|