@@ -2,9 +2,14 @@ import "./css/litemol/LiteMol-plugin-blue.css"
2
2
import $ from "jquery"
3
3
import LiteMol from "./js/pdb/LiteMol-plugin"
4
4
5
+ // populated by downloadPDBMeta.success
5
6
const pdbInfo = { }
6
7
7
8
async function loadSmiles ( pdbid ) {
9
+ let chromophore = pdbInfo [ pdbid ] . chromophore
10
+ if ( ! chromophore ) {
11
+ return
12
+ }
8
13
const _id = pdbInfo [ pdbid ] . chromophore . id
9
14
const url = `https://cdn.rcsb.org/images/ccd/unlabeled/${ _id [ 0 ] } /${ _id } .svg`
10
15
$ ( "#smilesDrawing div" ) . html (
@@ -15,19 +20,19 @@ async function loadSmiles(pdbid) {
15
20
}
16
21
17
22
function getPDBbinary ( id ) {
18
- return new Promise ( function ( resolve , reject ) {
23
+ return new Promise ( function ( resolve , reject ) {
19
24
$ . get ( `https://files.rcsb.org/download/${ id } .cif` )
20
- . done ( response => {
25
+ . done ( ( response ) => {
21
26
resolve ( response )
22
27
} )
23
28
. fail ( ( xhr , status , error ) => {
24
29
$ . get (
25
30
`https://www.ebi.ac.uk/pdbe/static/entry/${ id . toLowerCase ( ) } _updated.cif`
26
31
)
27
- . done ( response => {
32
+ . done ( ( response ) => {
28
33
resolve ( response )
29
34
} )
30
- . fail ( _xhr =>
35
+ . fail ( ( _xhr ) =>
31
36
reject (
32
37
new Error ( {
33
38
status : _xhr . status ,
@@ -51,11 +56,15 @@ function loadChemInfo(pdbid) {
51
56
"href" ,
52
57
`https://www.ncbi.nlm.nih.gov/pubmed/${ e . rcsb_primary_citation . pdbx_database_id_PubMed } `
53
58
)
54
- $ ( "#chem-id" ) . html (
55
- `<a target="_blank" rel="noopener" class="text-secondary"
56
- href="https://www.rcsb.org/ligand/${ e . chromophore . id } ">${ e . chromophore . id } </a>`
57
- )
58
- $ ( "#chem-form" ) . html ( e . chromophore . formula )
59
+ if ( e . chromophore !== undefined ) {
60
+ $ ( "#chem-id" ) . html (
61
+ `<a target="_blank" rel="noopener" class="text-secondary"
62
+ href="https://www.rcsb.org/ligand/${ e . chromophore . id } ">${ e . chromophore . id } </a>`
63
+ )
64
+ $ ( "#chem-form" ) . html ( e . chromophore . formula )
65
+ } else {
66
+ $ ( "#chem-id" ) . html ( "" )
67
+ }
59
68
}
60
69
61
70
function initLiteMol ( selection , changer ) {
@@ -88,27 +97,27 @@ function initLiteMol(selection, changer) {
88
97
} )
89
98
90
99
const dataCache = { }
91
- changer . change ( function ( ) {
100
+ changer . change ( function ( ) {
92
101
const id = this . value
93
102
if ( ! Object . prototype . hasOwnProperty . call ( dataCache , "id" ) ) {
94
103
dataCache [ id ] = getPDBbinary ( id )
95
104
}
96
105
plugin . clear ( )
97
106
dataCache [ id ] . then (
98
- data =>
107
+ ( data ) =>
99
108
plugin . loadMolecule ( {
100
109
data,
101
110
id,
102
111
} ) ,
103
- reason => {
112
+ ( reason ) => {
104
113
$ ( selection ) . html (
105
114
'<span class="text-danger muted">failed to retrieve molecular structure</span>'
106
115
)
107
116
}
108
117
)
109
118
} )
110
119
111
- $ ( "body" ) . on ( "click" , function ( e ) {
120
+ $ ( "body" ) . on ( "click" , function ( e ) {
112
121
if ( $ ( ".lm-layout-right" ) . length ) {
113
122
if ( $ ( e . target ) . closest ( "#litemol-viewer" ) . length === 0 ) {
114
123
plugin . setLayoutState ( {
@@ -124,7 +133,7 @@ function initLiteMol(selection, changer) {
124
133
}
125
134
126
135
changer
127
- . change ( function ( ) {
136
+ . change ( function ( ) {
128
137
// var id = this.value
129
138
$ ( "#pdb-out-link" ) . attr (
130
139
"href" ,
@@ -191,35 +200,52 @@ function downloadPDBMeta(pdbIds) {
191
200
}
192
201
}` ,
193
202
} ) ,
194
- success : function ( { data } ) {
195
- data . entries . forEach ( entry => {
203
+ success : function ( { data } ) {
204
+ data . entries . forEach ( ( entry ) => {
196
205
pdbInfo [ entry . entry . id ] = entry
197
- let chromo =
198
- entry . polymer_entities [ 0 ] . chem_comp_nstd_monomers ||
199
- entry . nonpolymer_entities [ 0 ] . nonpolymer_comp
206
+ let chromo = null
207
+
208
+ if ( entry . polymer_entities && entry . polymer_entities . length > 0 ) {
209
+ chromo = entry . polymer_entities [ 0 ] . chem_comp_nstd_monomers
210
+ } else if (
211
+ entry . nonpolymer_entities &&
212
+ entry . nonpolymer_entities . length > 0
213
+ ) {
214
+ chromo = entry . nonpolymer_entities [ 0 ] . nonpolymer_comp
215
+ }
216
+
200
217
if ( Array . isArray ( chromo ) ) {
201
218
chromo = chromo . reduce ( ( a , b ) =>
202
219
a . chem_comp . formula_weight > b . chem_comp . formula_weight ? a : b
203
220
)
204
221
}
205
- pdbInfo [ entry . entry . id ] . chromophore = { ...chromo . chem_comp }
206
- // eslint-disable-next-line prefer-destructuring
207
- pdbInfo [ entry . entry . id ] . resolution =
208
- entry . rcsb_entry_info . resolution_combined [ 0 ]
222
+
223
+ if ( chromo && chromo . chem_comp ) {
224
+ pdbInfo [ entry . entry . id ] . chromophore = { ...chromo . chem_comp }
225
+ }
226
+
227
+ if (
228
+ entry . rcsb_entry_info &&
229
+ entry . rcsb_entry_info . resolution_combined &&
230
+ entry . rcsb_entry_info . resolution_combined . length > 0
231
+ ) {
232
+ pdbInfo [ entry . entry . id ] . resolution =
233
+ entry . rcsb_entry_info . resolution_combined [ 0 ]
234
+ }
209
235
} )
210
236
} ,
211
237
} )
212
238
)
213
239
}
214
240
215
- const getPDBinfo = function ( pdbIds ) {
241
+ const getPDBinfo = function ( pdbIds ) {
216
242
downloadPDBMeta ( `["${ pdbIds . join ( '","' ) } "]` )
217
243
. done ( ( ) => {
218
244
const select = $ ( "#pdb_select" )
219
245
pdbIds . sort ( ( a , b ) =>
220
246
pdbInfo [ a ] . resolution > pdbInfo [ b ] . resolution ? 1 : - 1
221
247
)
222
- pdbIds . forEach ( id => {
248
+ pdbIds . forEach ( ( id ) => {
223
249
select . append (
224
250
$ ( "<option>" , {
225
251
value : id ,
@@ -229,17 +255,15 @@ const getPDBinfo = function(pdbIds) {
229
255
230
256
initLiteMol ( "#litemol-viewer" , select )
231
257
} )
232
- . fail ( function ( ) {
258
+ . fail ( function ( ) {
233
259
let html =
234
260
'<div><p><small class="text-muted">Failed to retrieve metadata from PDB!</small></p>'
235
261
html += "Please look for these IDs at RSCB PDB: "
236
- pdbIds . forEach ( _id => {
262
+ pdbIds . forEach ( ( _id ) => {
237
263
html += `<a href="https://www.rcsb.org/structure/${ _id } ">${ _id } </a>, `
238
264
} )
239
265
html += "</div>"
240
- $ ( "#protein-structure" )
241
- . html ( html )
242
- . removeClass ( "row" )
266
+ $ ( "#protein-structure" ) . html ( html ) . removeClass ( "row" )
243
267
} )
244
268
}
245
269
0 commit comments