in packages/miew/src/io/parsers/CMLParser.js [104:184]
_extractSGroups(molecule, atoms) {
const moleculeArr = this._extractSGroup(molecule);
const count = atoms.length;
let i;
let j;
for (i = 0; i < count; i++) {
const atomId = atoms[i].id;
for (j = 0; j < moleculeArr.length; j++) {
const firstAtomRef = moleculeArr[j]._atoms.split(' ')[0];
if (firstAtomRef === atomId) {
if (!atoms[i].sgroupRef) {
atoms[i].sgroupRef = [];
}
atoms[i].sgroupRef.push(moleculeArr[j]);
}
}
}
// build sGroups centers
let atomMap = {}; // sgrpmap cache
let mapEntry = null;
const nLimon = 100000000;
const bLow = new THREE.Vector3(nLimon, nLimon, nLimon);
const bHight = new THREE.Vector3(-nLimon, -nLimon, -nLimon);
function cycleFuncInner(e) {
mapEntry = atomMap[e];
if (mapEntry) {
moleculeArr[j]._atoms.push(mapEntry.a);
}
}
function cycleFunc(e) {
mapEntry = atomMap[e];
if (mapEntry) {
bLow.set(Math.min(bLow.x, mapEntry.x), Math.min(bLow.y, mapEntry.y), Math.min(bLow.z, mapEntry.z));
bHight.set(Math.max(bHight.x, mapEntry.x), Math.max(bHight.y, mapEntry.y), Math.max(bHight.z, mapEntry.z));
cycleFuncInner(e);
}
}
for (i = 0; i < atoms.length; i++) {
atomMap[atoms[i].id] = {};
atomMap[atoms[i].id].x = atoms[i].x2;
if (atoms[i].x3) {
atomMap[atoms[i].id].x = atoms[i].x3;
}
atomMap[atoms[i].id].x = parseFloat(atomMap[atoms[i].id].x);
atomMap[atoms[i].id].y = atoms[i].y2;
if (atoms[i].y3) {
atomMap[atoms[i].id].y = atoms[i].y3;
}
atomMap[atoms[i].id].y = parseFloat(atomMap[atoms[i].id].y);
atomMap[atoms[i].id].z = '0.0';
if (atoms[i].z3) {
atomMap[atoms[i].id].z = atoms[i].z3;
}
atomMap[atoms[i].id].z = parseFloat(atomMap[atoms[i].id].z);
atomMap[atoms[i].id].a = atoms[i];
}
let atomsRef;
for (j = 0; j < moleculeArr.length; j++) {
if (moleculeArr[j]._center !== null) {
bLow.set(nLimon, nLimon, nLimon);
bHight.set(-nLimon, -nLimon, -nLimon);
atomsRef = moleculeArr[j]._atoms.split(' ');
moleculeArr[j]._atoms = [];
atomsRef.forEach(cycleFunc);
moleculeArr[j]._center.addVectors(bLow, bHight);
moleculeArr[j]._center.multiplyScalar(0.5);
} else {
atomsRef = moleculeArr[j]._atoms.split(' ');
moleculeArr[j]._atoms = [];
atomsRef.forEach(cycleFuncInner);
}
}
atomMap = null;
}