-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathchangeMolfileCustomLabelPosition.js
More file actions
44 lines (44 loc) · 1.31 KB
/
changeMolfileCustomLabelPosition.js
File metadata and controls
44 lines (44 loc) · 1.31 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
export function changeMolfileCustomLabelPosition(
molecule,
customLabelPosition,
) {
switch (customLabelPosition) {
case 'superscript':
for (let i = 0; i < molecule.getAllAtoms(); i++) {
const customLabel = molecule.getAtomCustomLabel(i);
if (customLabel && !customLabel.startsWith(']')) {
molecule.setAtomCustomLabel(i, `]${customLabel}`);
}
}
break;
case 'normal':
for (let i = 0; i < molecule.getAllAtoms(); i++) {
const customLabel = molecule.getAtomCustomLabel(i);
if (customLabel?.startsWith(']')) {
molecule.setAtomCustomLabel(i, customLabel.slice(1));
}
}
break;
case 'auto':
for (let i = 0; i < molecule.getAllAtoms(); i++) {
const customLabel = molecule.getAtomCustomLabel(i);
if (customLabel) {
const atomLabel = molecule.getAtomLabel(i);
if (atomLabel === 'C') {
// normal
if (customLabel.startsWith(']')) {
molecule.setAtomCustomLabel(i, customLabel.slice(1));
}
} else if (!customLabel.startsWith(']')) {
molecule.setAtomCustomLabel(i, `]${customLabel}`);
}
}
}
break;
case undefined:
// nothing to do
break;
default:
break;
}
}