-
Notifications
You must be signed in to change notification settings - Fork 2
/
getDiastereotopicAtomIDs.js
36 lines (32 loc) · 1.15 KB
/
getDiastereotopicAtomIDs.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
import { getSymmetryRanks } from '../util/getSymmetryRanks';
import { makeRacemic } from '../util/makeRacemic';
import { tagAtom } from '../util/tagAtom';
import { ensureHeterotopicChiralBonds } from './ensureHeterotopicChiralBonds';
/**
* Returns an array of diastereotopic ID (as idCode)
* @param {import('openchemlib').Molecule} molecule
*/
export function getDiastereotopicAtomIDs(molecule) {
const { Molecule } = molecule.getOCL();
ensureHeterotopicChiralBonds(molecule);
const symmetryRanks = getSymmetryRanks(molecule);
const numberAtoms = molecule.getAllAtoms();
const ids = [];
const cache = {};
for (let iAtom = 0; iAtom < numberAtoms; iAtom++) {
const rank = symmetryRanks[iAtom];
if (rank && cache[rank]) {
ids[iAtom] = cache[rank];
continue;
}
const tempMolecule = molecule.getCompactCopy();
tagAtom(tempMolecule, iAtom);
makeRacemic(tempMolecule);
// We need to ensure the helper array in order to get correctly the result of racemisation
ids[iAtom] = tempMolecule.getCanonizedIDCode(
Molecule.CANONIZER_ENCODE_ATOM_CUSTOM_LABELS,
);
cache[rank] = ids[iAtom];
}
return ids;
}