in packages/miew/src/io/parsers/CMLParser.js [263:357]
function prepareComponentCompound(data) {
let atoms = [];
if (data.molecule && data.molecule.atomArray && data.molecule.atomArray.atom) {
if (!Array.isArray(data.molecule.atomArray.atom)) {
atoms.push(data.molecule.atomArray.atom);
} else {
atoms = data.molecule.atomArray.atom;
}
} else if (!data.molecule) {
const ret = {};
ret.atomLabels = null;
ret.labelsCount = 1;
return ret;
}
if (data.molecule.molecule) {
self._extractSGroups(data.molecule.molecule, atoms);
}
let atom;
let count = atoms.length;
for (let i = 0; i < count; i++) {
atom = atoms[i];
atom.edges = [];
}
let localBond = [];
if (data.molecule.bondArray && data.molecule.bondArray.bond) {
if (!Array.isArray(data.molecule.bondArray.bond)) {
localBond.push(data.molecule.bondArray.bond);
} else {
localBond = data.molecule.bondArray.bond;
}
}
let bond;
count = localBond.length;
self._rebuidBondIndexes(atoms, localBond);
function addCurrBond(index) {
bond = localBond[index];
atom = atoms[bond.start];
if (!atom) {
return false;
}
atom.edges.push(bond.end);
atom = atoms[bond.end];
if (!atom) {
return false;
}
atom.edges.push(bond.start);
return true;
}
for (let i = 0; i < count; i++) {
if (!addCurrBond(i)) {
// ignore invalid bond
continue;
}
const orderAttr = bond.xmlNode.getAttribute('order');
const tc = parseInt(orderAttr, 10);
// the default bond order is unknown
localBond[i].order = 0;
localBond[i].type = Bond.BondType.UNKNOWN;
if (tc > 1) {
localBond[i].order = tc;
} else {
// another option - bond order is a string
const order = cOrderCharCodes[orderAttr];
if (order !== undefined) {
localBond[i].order = order;
if (orderAttr === 'A') {
localBond[i].type = Bond.BondType.AROMATIC;
}
}
}
}
count = atoms.length;
for (let i = 0; i < count; i++) {
atom = atoms[i];
atom.edges.sort();
}
const labels = self._breadWidthSearch(atoms, 0); // for now
const retStruct = {};
retStruct.atoms = atoms;
retStruct.bonds = localBond;
retStruct.labels = labels.atomLabels;
retStruct.count = Math.min(1, labels.labelsCount); // for now
retStruct.curr = -1;
retStruct.originalCML = doc;
return retStruct;
}