# All files / src/parsers/utils assignPDBBonds.ts

100% Statements 38/38
92.85% Branches 13/14
100% Functions 2/2
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69

    11x
    11x

    11x
    8380x
    8380x
    8380x
    8374x

    11x

    11x
    8367x
    8364x

    11x
    11x

    11x
    8374x

    8374x
    841x
    841x

    841x

    8374x

    8374x
    144618x
    144618x
    144573x

    8131x
    136442x
    8486x

    3692x
    3692x
    3692x
    3692x

    8486x

     // this is optimized for proteins where it is assumed connected
    // atoms are on the same or next residue

    import { areConnected } from "./areConnected";
    import { assignBonds } from "./assignBonds";
    import { standardResidues } from "./standardResidues";

    /*
     * @param {AtomSpec[]}
     *            atomsarray
     */
    export function assignPDBBonds(atomsarray) {
      // assign bonds - yuck, can't count on connect records
      var protatoms: any[] = [];
      var hetatoms: any[] = [];
      var i, n;
      for (i = 0, n = atomsarray.length; i < n; i++) {
        var atom: any = atomsarray[i];
        atom.index = i;
        if (atom.hetflag || !standardResidues.has(atom.resn)) hetatoms.push(atom);
        else protatoms.push(atom);
      }

      assignBonds(hetatoms);

      // sort by resid
      protatoms.sort(function (a: any, b: any) {
        if (a.chain != b.chain) return a.chain < b.chain ? -1 : 1;
        return a.resi - b.resi;
      });

      // for identifying connected residues
      var currentResi = -1;
      var reschain = -1;
      var lastResConnected;

      for (i = 0, n = protatoms.length; i < n; i++) {
        var ai = protatoms[i];

        if (ai.resi !== currentResi) {
          currentResi = ai.resi;
          if (!lastResConnected) reschain++;

          lastResConnected = false;
        }

        ai.reschain = reschain;

        for (var j = i + 1; j < protatoms.length; j++) {
          var aj = protatoms[j];
          if (aj.chain != ai.chain) break;
          if (aj.resi - ai.resi > 1)
            // can't be connected
            break;
          if (areConnected(ai, aj)) {
            if (ai.bonds.indexOf(aj.index) === -1) {
              // only add if not already there
              ai.bonds.push(aj.index);
              ai.bondOrder.push(1);
              aj.bonds.push(ai.index);
              aj.bondOrder.push(1);
            }

            if (ai.resi !== aj.resi) lastResConnected = true;
          }
        }
      }
    }