function _addPointsForLoneResidue()

in packages/miew/src/gfx/modes/groups/CartoonHelper.js [44:94]


function _addPointsForLoneResidue(centerPoints, topPoints, idx, residue) {
  const nucleic = (residue._type.flags & ResidueType.Flags.NUCLEIC) !== 0;
  const nameFrom = nucleic ? 'C5\'' : 'N';
  const nameTo = nucleic ? 'C3\'' : 'C';

  let posFrom;
  let posTo;
  residue.forEachAtom((atom) => {
    const name = atom.getVisualName();
    if (!posFrom && name === nameFrom) {
      posFrom = atom.position;
    } else if (!posTo && name === nameTo) {
      posTo = atom.position;
    }
  });

  // provide a fallback for unknown residues
  if (!(posFrom && posTo)) {
    posFrom = residue._firstAtom.position;
    posTo = residue._lastAtom.position;
  }

  if (posFrom && posTo) {
    const shift = posTo.clone().sub(posFrom);

    const wing = residue._wingVector;
    const cp = residue._controlPoint;
    const tp = cp.clone().add(wing);

    const cpPrev = cp.clone().sub(shift);
    const tpPrev = cpPrev.clone().add(wing);
    centerPoints[idx] = [cpPrev.x, cpPrev.y, cpPrev.z];
    topPoints[idx] = [tpPrev.x, tpPrev.y, tpPrev.z];
    ++idx;
    centerPoints[idx] = [cpPrev.x, cpPrev.y, cpPrev.z];
    topPoints[idx] = [tpPrev.x, tpPrev.y, tpPrev.z];
    ++idx;

    centerPoints[idx] = [cp.x, cp.y, cp.z];
    topPoints[idx] = [tp.x, tp.y, tp.z];
    ++idx;

    const cpNext = cp.clone().add(shift);
    const tpNext = cpNext.clone().add(wing);
    centerPoints[idx] = [cpNext.x, cpNext.y, cpNext.z];
    topPoints[idx] = [tpNext.x, tpNext.y, tpNext.z];
    ++idx;
    centerPoints[idx] = [cpNext.x, cpNext.y, cpNext.z];
    topPoints[idx] = [tpNext.x, tpNext.y, tpNext.z];
  }
}