-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPubChem.js
More file actions
73 lines (69 loc) · 1.85 KB
/
PubChem.js
File metadata and controls
73 lines (69 loc) · 1.85 KB
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
import ui from 'src/util/ui';
const pubchemURL = 'https://octochemdb.cheminfo.org/compounds/v1/fromMF?';
async function getMolecules(mf) {
const searchParams = new URLSearchParams();
searchParams.set('mf', mf);
searchParams.set('fields', 'data.iupac,data.ocl');
searchParams.set('limit', '50000');
let response = await fetch(`${pubchemURL}${searchParams.toString()}`);
let results = await response.json();
return results.data;
}
module.exports = {
choose(mf) {
let promise = getMolecules(mf);
return ui
.choose([{ promise }], {
autoSelect: false,
asynchronous: true,
noConfirmation: true,
returnRow: false,
dialog: {
width: 1000,
height: 800,
},
columns: [
{
id: 'iupac',
name: 'Name',
jpath: [],
rendererOptions: {
forceType: 'object',
twig: `
{{data.iupac}}
`,
},
},
{
id: 'structure',
name: 'Structure',
jpath: ['data', 'ocl', 'idCode'],
rendererOptions: {
forceType: 'oclID',
},
maxWidth: 500,
},
{
id: 'url',
name: 'Pubchem',
jpath: [],
rendererOptions: {
forceType: 'object',
twig: `
<a href="https://pubchem.ncbi.nlm.nih.gov/compound/{{_id}}" onclick="event.stopPropagation()" target="_blank">⬈</a>
`,
},
maxWidth: 70,
},
],
idField: 'id',
slick: {
rowHeight: 140,
},
})
.catch((e) => {
console.error(e); // eslint-disable-line no-console
ui.showNotification('search failed', 'error');
});
},
};