-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathradius-factory.ts
95 lines (78 loc) · 1.94 KB
/
radius-factory.ts
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
/**
* @file Radius Factory
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { defaults } from '../utils'
import { NucleicBackboneAtoms } from '../structure/structure-constants'
import AtomProxy from '../proxy/atom-proxy'
export const RadiusFactoryTypes = {
'': '',
'vdw': 'by vdW radius',
'covalent': 'by covalent radius',
'sstruc': 'by secondary structure',
'bfactor': 'by bfactor',
'size': 'size',
'data': 'data'
}
export type RadiusType = keyof typeof RadiusFactoryTypes
export interface RadiusParams {
type?: RadiusType
scale?: number
size?: number
data?: { [k: number]: number }
}
class RadiusFactory {
max = 10
static types = RadiusFactoryTypes
readonly type: RadiusType
readonly scale: number
readonly size: number
readonly data: { [k: number]: number }
constructor (params: RadiusParams = {}) {
this.type = defaults(params.type, 'size')
this.scale = defaults(params.scale, 1)
this.size = defaults(params.size, 1)
this.data = defaults(params.data, {})
}
atomRadius (a: AtomProxy) {
let r
switch (this.type) {
case 'vdw':
r = a.vdw
break
case 'covalent':
r = a.covalent
break
case 'bfactor':
r = a.bfactor || 1.0
break
case 'sstruc':
const sstruc = a.sstruc
if (sstruc === 'h') {
r = 0.25
} else if (sstruc === 'g') {
r = 0.25
} else if (sstruc === 'i') {
r = 0.25
} else if (sstruc === 'e') {
r = 0.25
} else if (sstruc === 'b') {
r = 0.25
} else if (NucleicBackboneAtoms.includes(a.atomname)) {
r = 0.4
} else {
r = 0.1
}
break
case 'data':
r = defaults(this.data[ a.index ], 1.0)
break
default:
r = this.size
break
}
return Math.min(r * this.scale, this.max)
}
}
export default RadiusFactory