-
Notifications
You must be signed in to change notification settings - Fork 2
/
getAtomFeatures.js
59 lines (53 loc) · 1.55 KB
/
getAtomFeatures.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
import { makeRacemic } from '../util/makeRacemic';
export function getAtomFeatures(originalMolecule, options = {}) {
const OCL = originalMolecule.getOCL();
const { sphere = 1 } = options;
const fragment = new OCL.Molecule(0, 0);
const results = [];
for (
let rootAtom = 0;
rootAtom < originalMolecule.getAllAtoms();
rootAtom++
) {
let min = 0;
let max = 0;
const atomMask = new Array(originalMolecule.getAtoms());
const atomList = new Array(originalMolecule.getAtoms());
const molecule = originalMolecule.getCompactCopy();
for (let currentSphere = 0; currentSphere <= sphere; currentSphere++) {
if (max === 0) {
atomList[max] = rootAtom;
atomMask[rootAtom] = true;
max++;
} else {
let newMax = max;
for (let i = min; i < max; i++) {
const atom = atomList[i];
for (let j = 0; j < molecule.getAllConnAtoms(atom); j++) {
const connAtom = molecule.getConnAtom(atom, j);
if (!atomMask[connAtom]) {
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
}
}
}
min = max;
max = newMax;
}
molecule.copyMoleculeByAtoms(fragment, atomMask, true, null);
if (currentSphere === sphere) {
makeRacemic(fragment);
results.push(fragment.getCanonizedIDCode());
}
}
}
const atoms = {};
for (const result of results) {
if (!atoms[result]) {
atoms[result] = 1;
} else {
atoms[result]++;
}
}
return atoms;
}