<commit_before>

import * as THREE from 'three';
import {Smooth} from 'Smooth';
import gfxutils from '../../gfxutils';
var calcMatrix = gfxutils.calcChunkMatrix;

function _buildStructureInterpolator(points, tension) {
  var path = Smooth(points, {
    method: Smooth.METHOD_CUBIC,
    clip: Smooth.CLIP_CLAMP,
    cubicTension: tension,
    scaleTo: 1
  });

  return function(t, argTrans) {
    var transformT = argTrans;
    if (transformT === null) {
      // map our range to the [second .. last but one]
      transformT = function(tt) {
        return (tt * ((points.length - 1) - 2) + 1) / (points.length - 1);
      };
    }
    var newt = transformT(t);
    var ans = path(newt);
    return new THREE.Vector3(ans[0], ans[1], ans[2]);
  };
}

function _addPoints(centerPoints, topPoints, idx, residue) {
  if (!residue._isValid) {
    centerPoints[idx] = centerPoints[idx - 1];
    topPoints[idx] = topPoints[idx - 1];
    return;
  }
  var cp = residue._controlPoint;
  centerPoints[idx] = [cp.x, cp.y, cp.z];
  var tp = cp.clone().add(residue._wingVector);
  topPoints[idx] = [tp.x, tp.y, tp.z];
}

function _addPointsForLoneResidue(centerPoints, topPoints, idx, residue) {
  let posN, posC;
  residue.forEachAtom((atom) => {
    const name = atom.getVisualName();
    if (!posN && name === 'N') {
      posN = atom._position;
    } else if (!posC && name === 'C') {
      posC = atom._position;
    }
  });
  if (posN && posC) {
    const shift = posC.clone().sub(posN);

    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];
  }
}

function _calcPoints(residues, firstIdx, lastIdx, boundaries) {
  var left = boundaries.start;
  var right = boundaries.end;
  function _prevIdx(idx) {
    return idx > left && residues[idx - 1]._isValid ? idx - 1 : idx;
  }
  function _nextIdx(idx) {
    return idx < right && residues[idx + 1]._isValid ? idx + 1 : idx;
  }

  var topPoints = new Array(lastIdx - firstIdx + 5);
  var centerPoints = new Array(lastIdx - firstIdx + 5);
  var arrIdx = 0;
  function _extrapolate2(currIdx, otherIdx) {
    var cp = residues[currIdx]._controlPoint.clone().lerp(residues[otherIdx]._controlPoint, -0.25);<commit_msg>Fix a crash for non-protein lone residue<commit_after>

import * as THREE from 'three';
import {Smooth} from 'Smooth';
import gfxutils from '../../gfxutils';
var calcMatrix = gfxutils.calcChunkMatrix;

function _buildStructureInterpolator(points, tension) {
  var path = Smooth(points, {
    method: Smooth.METHOD_CUBIC,
    clip: Smooth.CLIP_CLAMP,
    cubicTension: tension,
    scaleTo: 1
  });

  return function(t, argTrans) {
    var transformT = argTrans;
    if (transformT === null) {
      // map our range to the [second .. last but one]
      transformT = function(tt) {
        return (tt * ((points.length - 1) - 2) + 1) / (points.length - 1);
      };
    }
    var newt = transformT(t);
    var ans = path(newt);
    return new THREE.Vector3(ans[0], ans[1], ans[2]);
  };
}

function _addPoints(centerPoints, topPoints, idx, residue) {
  if (!residue._isValid) {
    centerPoints[idx] = centerPoints[idx - 1];
    topPoints[idx] = topPoints[idx - 1];
    return;
  }
  var cp = residue._controlPoint;
  centerPoints[idx] = [cp.x, cp.y, cp.z];
  var tp = cp.clone().add(residue._wingVector);
  topPoints[idx] = [tp.x, tp.y, tp.z];
}

function _addPointsForLoneResidue(centerPoints, topPoints, idx, residue) {
  let posFrom, posTo;
  residue.forEachAtom((atom) => {
    const name = atom.getVisualName();
    if (!posFrom && name === 'N') {
      posFrom = atom._position;
    } else if (!posTo && name === 'C') {
      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];
  }
}

function _calcPoints(residues, firstIdx, lastIdx, boundaries) {
  var left = boundaries.start;
  var right = boundaries.end;
  function _prevIdx(idx) {
    return idx > left && residues[idx - 1]._isValid ? idx - 1 : idx;
  }
  function _nextIdx(idx) {
    return idx < right && residues[idx + 1]._isValid ? idx + 1 : idx;
  }

  var topPoints = []; // new Array(lastIdx - firstIdx + 5);
  var centerPoints = []; // new Array(lastIdx - firstIdx + 5);
  var arrIdx = 0;
  function _extrapolate2(currIdx, otherIdx) {
    var cp = residues[currIdx]._controlPoint.clone().lerp(residues[otherIdx]._controlPoint, -0.25);
{'fraction_non_alphanumeric': 0.16254071661237784, 'fraction_numerical': 0.0071661237785016286, 'mean_word_length': 3.152129817444219, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6255266', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2260, 'n_words': 512}