Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (105 sloc) 2.696 kb
1e73da7 @michaelgrosner Restructured into separate files
authored
1 class Element
2 constructor: (@parent, @name, cc = null) ->
3 @children = []
4 if parent?
5 @parent.addChild @
b208cfc @michaelgrosner Implemented selectors and ability to change info dicts
authored
6
1e73da7 @michaelgrosner Restructured into separate files
authored
7 if cc?
8 @cc = cc
9 else
10 @cc = @parent.cc
11
12 @info = {}
b208cfc @michaelgrosner Implemented selectors and ability to change info dicts
authored
13 @selector = null
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
14
15 constructorName: =>
16 @.constructor.name
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
17
1e73da7 @michaelgrosner Restructured into separate files
authored
18 writeContextInfo: =>
b208cfc @michaelgrosner Implemented selectors and ability to change info dicts
authored
19 if @constructorName() != "Residue"
1e73da7 @michaelgrosner Restructured into separate files
authored
20 # THIS WILL BREAK IE COMPAT.
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
21 child_type_name = @children[0].constructorName()
22 x = "#{@constructorName()}: #{@name} with #{@children.length}\
b208cfc @michaelgrosner Implemented selectors and ability to change info dicts
authored
23 #{child_type_name}s | #{@selector.str}"
1e73da7 @michaelgrosner Restructured into separate files
authored
24 p = (c.writeContextInfo() for c in @children)
25 return "#{x}<br>#{p.join "" }"
26
27 init: ->
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
28 @atoms = @getOfType Atom
1e73da7 @michaelgrosner Restructured into separate files
authored
29
30 addChild: (child) ->
31 @children.push child
32
33 propogateInfo: (info) ->
34 @info = info
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
35 @info.drawColor = if @info.drawColor? then @info.drawColor else randomRGB()
1e73da7 @michaelgrosner Restructured into separate files
authored
36 for c in @children
37 c.propogateInfo info
38
39 getOfType: (type) ->
40 ret = []
41 recursor = (children) ->
42 for c in children
43 if c instanceof type
44 ret.push c
45 else
46 recursor c.children
47 recursor @children
48 return ret
49
50 draw: =>
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
51 if @info.drawMethod not in supported_draw_methods
52 c = supported_draw_methods.join ", "
53 alert "drawMethod #{@info.drawMethod} not supported! Choose: #{c}"
1e73da7 @michaelgrosner Restructured into separate files
authored
54 if @info.drawMethod == "lines"
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
55 @drawPaths()
1e73da7 @michaelgrosner Restructured into separate files
authored
56 else if @info.drawMethod == "points"
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
57 @drawPoints()
1e73da7 @michaelgrosner Restructured into separate files
authored
58 else if @info.drawMethod == "both"
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
59 @drawPaths()
60 @drawPoints()
1e73da7 @michaelgrosner Restructured into separate files
authored
61
62 drawPaths: =>
b208cfc @michaelgrosner Implemented selectors and ability to change info dicts
authored
63 #@atoms.sort sortByZ
64
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
65 isBonded = (a1, a2) ->
66 if a1.parent.typeName() != a2.parent.typeName()
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
67 return false
68
69 # Precompute distance
70 aad = atomAtomDistance(a1, a2)
71
72 if aad < 3 and a1.parent.isProtein()
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
73 true
f5a4c6f @michaelgrosner Syntax fixing, resetting to original condensed
authored
74 else if aad < 10 and a1.parent.isDNA()
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
75 true
76 else
77 false
78
1e73da7 @michaelgrosner Restructured into separate files
authored
79 x = @cc.context
80
81 for i in [2..@atoms.length-1]
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
82 for j in [i+1..i+5] when j < @atoms.length-1
83 x.beginPath()
84 a2 = @atoms[i]
85 a1 = @atoms[j]
86 if isBonded a1, a2
87 x.moveTo(a1.x, a1.y)
88 x.lineTo(a2.x, a2.y)
89 x.strokeStyle = arrayToRGB (c + a1.z for c in @info.drawColor)
90 #x.lineJoin = "round"
91 #x.lineCap = "round"
92 lw = (3*a1.z + 200)/200
93 x.lineWidth = if lw > 0 then lw else lw
94 x.closePath()
95 x.stroke()
1e73da7 @michaelgrosner Restructured into separate files
authored
96
97 drawPoints: =>
98 @atoms.sort sortByZ
99 for a in @atoms
100 a.drawPoint(color = @info.drawColor)
101
102 rotateAboutY: (theta) =>
103 for a in @atoms
104 a.rotateAboutY theta
105
106 rotateAboutX: (theta) =>
107 for a in @atoms
108 a.rotateAboutX theta
109
110 restoreToOriginal: =>
111 for a in @atoms
112 a.restoreToOriginal()
113
114 avgCenter: =>
115 avgs = [0.0, 0.0, 0.0]
116 for a in @atoms
117 avgs[0] += a.x
118 avgs[1] += a.y
119 avgs[2] += a.z
120 (a/@atoms.length for a in avgs)
121
e27790d @michaelgrosner New structures default to (0,0) and some work on info dict
authored
122 translateTo: (center) =>
123 for a in @atoms
124 a.x -= center[0]
125 a.y -= center[1]
126 a.z -= center[2]
127
Something went wrong with that request. Please try again.