-
Notifications
You must be signed in to change notification settings - Fork 2
/
ensureHeterotopicChiralBonds.js
34 lines (31 loc) · 1.5 KB
/
ensureHeterotopicChiralBonds.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
import { getChiralOrHeterotopicCarbons } from './getChiralOrHeterotopicCarbons.js';
/**
* This function will add missing chiral bonds on carbons ensure that all enantiotopic
* or diastereotopic atoms can be identified uniquely
* @param {import('openchemlib').Molecule} molecule
* @param {object} [options={}]
* @param {number} [options.esrType=Molecule.cESRTypeAnd]
* @param {boolean} [options.atLeastThreeAtoms=true] - if true, only carbons with at least three atoms will be considered
*/
export function ensureHeterotopicChiralBonds(molecule, options = {}) {
const { Molecule } = molecule.getOCL();
const { esrType = Molecule.cESRTypeAnd, atLeastThreeAtoms = true } = options;
molecule.ensureHelperArrays(Molecule.cHelperBitNeighbours);
const heterotopicCarbons = getChiralOrHeterotopicCarbons(molecule);
for (const i of heterotopicCarbons) {
if (atLeastThreeAtoms && molecule.getAllConnAtoms(i) < 3) continue;
if (molecule.getStereoBond(i) === -1) {
const stereoBond = molecule.getAtomPreferredStereoBond(i);
if (stereoBond !== -1) {
molecule.setBondType(stereoBond, Molecule.cBondTypeUp);
if (molecule.getBondAtom(1, stereoBond) === i) {
const connAtom = molecule.getBondAtom(0, stereoBond);
molecule.setBondAtom(0, stereoBond, i);
molecule.setBondAtom(1, stereoBond, connAtom);
}
// To me it seems that we have to add all stereo centers into AND group 0. TLS 9.Nov.2015
molecule.setAtomESR(i, esrType, 0);
}
}
}
}