| 1 | # Compute the area of an MSMS surface colored more red than blue
|
|---|
| 2 | # (electrostatic coloring) as a ratio of the total area.
|
|---|
| 3 | #
|
|---|
| 4 | # Example use.
|
|---|
| 5 | #
|
|---|
| 6 | # menu File / Open..., red_area.py, Creates the new redarea command.
|
|---|
| 7 | #
|
|---|
| 8 | # open 1a0m
|
|---|
| 9 | # surface
|
|---|
| 10 | # coulombic -10 red 0 white 10 blue #0
|
|---|
| 11 | # redarea #0
|
|---|
| 12 | #
|
|---|
| 13 | # menu Favorites / Reply Log
|
|---|
| 14 | # -> "Surface MSMS main surface of 1a0m, red area 1400, total area 1888, ratio 0.7414"
|
|---|
| 15 | #
|
|---|
| 16 |
|
|---|
| 17 | def red_area(surface):
|
|---|
| 18 |
|
|---|
| 19 | red_area = tot_area = 0
|
|---|
| 20 | for p in surface.surfacePieces:
|
|---|
| 21 | va, ta = p.geometry # Vertices and triangles
|
|---|
| 22 | rgba = p.vertexColors
|
|---|
| 23 | mask = (rgba[:,0] >= rgba[:,2]) # Red component >= blue
|
|---|
| 24 | import _surface
|
|---|
| 25 | a = _surface.vertex_areas(va, ta)
|
|---|
| 26 | tot_area += a.sum()
|
|---|
| 27 | red_area += (mask*a).sum()
|
|---|
| 28 | return red_area, tot_area
|
|---|
| 29 |
|
|---|
| 30 | def red_area_command(cmd_name, args):
|
|---|
| 31 |
|
|---|
| 32 | from chimera.specifier import evalSpec
|
|---|
| 33 | for s in evalSpec(args).models():
|
|---|
| 34 | import _surface
|
|---|
| 35 | if isinstance(s, _surface.SurfaceModel):
|
|---|
| 36 | r,t = red_area(s)
|
|---|
| 37 | from chimera.replyobj import status, info
|
|---|
| 38 | msg = 'Surface %s, red area %.4g, total area %.4g, ratio %.4g' % (s.name, r, t, r/t)
|
|---|
| 39 | status(msg)
|
|---|
| 40 | info(msg + '\n')
|
|---|
| 41 |
|
|---|
| 42 | from Midas.midas_text import addCommand
|
|---|
| 43 | addCommand('redarea', red_area_command)
|
|---|