-
Notifications
You must be signed in to change notification settings - Fork 2
/
getDiastereotopicAtomIDsAndH.js
41 lines (36 loc) · 1.11 KB
/
getDiastereotopicAtomIDsAndH.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
import { getDiastereotopicAtomIDs } from './getDiastereotopicAtomIDs';
/**
*
* @param {import('openchemlib').Molecule} molecule
*/
export function getDiastereotopicAtomIDsAndH(molecule) {
const OCL = molecule.getOCL();
molecule = molecule.getCompactCopy();
molecule.addImplicitHydrogens();
molecule.ensureHelperArrays(OCL.Molecule.cHelperNeighbours);
const diaIDs = getDiastereotopicAtomIDs(molecule);
const newDiaIDs = [];
for (let i = 0; i < diaIDs.length; i++) {
const diaID = diaIDs[i];
const newDiaID = {
oclID: diaID,
hydrogenOCLIDs: [],
nbHydrogens: 0,
};
if (molecule.getAtomicNo(i) === 1) {
const atom = molecule.getConnAtom(i, 0);
newDiaID.heavyAtom = diaIDs[atom];
}
for (let j = 0; j < molecule.getAllConnAtoms(i); j++) {
const atom = molecule.getConnAtom(i, j);
if (molecule.getAtomicNo(atom) === 1) {
newDiaID.nbHydrogens++;
if (!newDiaID.hydrogenOCLIDs.includes(diaIDs[atom])) {
newDiaID.hydrogenOCLIDs.push(diaIDs[atom]);
}
}
}
newDiaIDs.push(newDiaID);
}
return newDiaIDs;
}