-
Notifications
You must be signed in to change notification settings - Fork 167
/
ribbon-representation.js
165 lines (132 loc) · 3.94 KB
/
ribbon-representation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* @file Ribbon Representation
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { RepresentationRegistry } from '../globals'
import { defaults } from '../utils'
import Spline from '../geometry/spline.js'
import StructureRepresentation from './structure-representation.js'
import RibbonBuffer from '../buffer/ribbon-buffer.js'
/**
* Ribbon Representation
*/
class RibbonRepresentation extends StructureRepresentation {
constructor (structure, viewer, params) {
super(structure, viewer, params)
this.type = 'ribbon'
this.parameters = Object.assign({
subdiv: {
type: 'integer', max: 50, min: 1, rebuild: true
},
tension: {
type: 'number', precision: 1, max: 1.0, min: 0.1
},
smoothSheet: {
type: 'boolean', rebuild: true
}
}, this.parameters, {
side: null,
wireframe: null,
linewidth: null
})
this.init(params)
}
init (params) {
var p = params || {}
p.colorScheme = defaults(p.colorScheme, 'chainname')
p.colorScale = defaults(p.colorScale, 'RdYlBu')
p.radiusType = defaults(p.radiusType, 'sstruc')
p.radiusScale = defaults(p.radiusScale, 4.0)
if (p.quality === 'low') {
this.subdiv = 3
} else if (p.quality === 'medium') {
this.subdiv = 6
} else if (p.quality === 'high') {
this.subdiv = 12
} else {
this.subdiv = defaults(p.subdiv, 6)
}
this.tension = defaults(p.tension, NaN)
this.smoothSheet = defaults(p.smoothSheet, false)
super.init(p)
}
getSplineParams (params) {
return Object.assign({
subdiv: this.subdiv,
tension: this.tension,
directional: true,
smoothSheet: this.smoothSheet
}, params)
}
getAtomRadius (atom) {
return atom.isTrace() ? super.getAtomRadius(atom) : 0
}
createData (sview) {
var bufferList = []
var polymerList = []
this.structure.eachPolymer(polymer => {
if (polymer.residueCount < 4) return
polymerList.push(polymer)
var spline = new Spline(polymer, this.getSplineParams())
var subPos = spline.getSubdividedPosition()
var subOri = spline.getSubdividedOrientation()
var subCol = spline.getSubdividedColor(this.getColorParams())
var subPick = spline.getSubdividedPicking()
var subSize = spline.getSubdividedSize(this.getRadiusParams())
bufferList.push(
new RibbonBuffer(
{
position: subPos.position,
normal: subOri.binormal,
dir: subOri.normal,
color: subCol.color,
size: subSize.size,
picking: subPick.picking
},
this.getBufferParams()
)
)
}, sview.getSelection())
return {
bufferList: bufferList,
polymerList: polymerList
}
}
updateData (what, data) {
what = what || {}
var i = 0
var n = data.polymerList.length
for (i = 0; i < n; ++i) {
var bufferData = {}
var spline = new Spline(data.polymerList[ i ], this.getSplineParams())
if (what.position) {
var subPos = spline.getSubdividedPosition()
var subOri = spline.getSubdividedOrientation()
bufferData.position = subPos.position
bufferData.normal = subOri.binormal
bufferData.dir = subOri.normal
}
if (what.radius || what.scale) {
var subSize = spline.getSubdividedSize(this.getRadiusParams())
bufferData.size = subSize.size
}
if (what.color) {
var subCol = spline.getSubdividedColor(this.getColorParams())
bufferData.color = subCol.color
}
data.bufferList[ i ].setAttributes(bufferData)
}
}
setParameters (params) {
var rebuild = false
var what = {}
if (params && params.tension) {
what.position = true
}
super.setParameters(params, what, rebuild)
return this
}
}
RepresentationRegistry.add('ribbon', RibbonRepresentation)
export default RibbonRepresentation