All files / src/parsers PDB.ts

66.66% Statements 18/27
77.77% Branches 7/9
100% Functions 1/1
72% Lines 18/25

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                                3x 3x 3x 3x 3x 3x 5x 5x 5x 5x   5x 2x   3x                         3x 3x     3x 1x       3x    
// parse pdb file from str and create atoms
// if computeStruct is true will always perform secondary structure
// analysis,
// otherwise only do analysis of SHEET/HELIX comments are missing
 
import { getSinglePDB } from "./utils/getSinglePDB";
 
/**
 * @param {string} str
 * @param {ParserOptionsSpec} options - keepH (do not strip hydrogens), noSecondaryStructure,
 *            assignbonds (default true, calculate implicit bonds)
 *            (do not compute ss), altLoc (which alternate location to select, if present; '*' to load all)
 * @category Parsers
 * 
 */
export function PDB(str, options) {
  options = options || {};
  var atoms: any[] & Record<string, any> = []; //a separate list for each model
  var sslookup = {}; //stores SHEET and HELIX info, which is shared across models
  atoms.modelData = [];
  var lines = str.split(/\r?\n|\r/);
  while (lines.length > 0) {
    var pdbinfo = getSinglePDB(lines, options, sslookup);
    var modelatoms = pdbinfo[0];
    var modelData = pdbinfo[1];
    lines = pdbinfo[2];
 
    if (modelatoms.length == 0) {
      continue; //happens when there are blank lines
    }
    Iif (options.multimodel && options.onemol && atoms.length > 0) {
      //merge into existing atoms
      var inc = atoms[0].length;
      for (var i = 0; i < modelatoms.length; i++) {
        //renumber
        var atom = modelatoms[i];
        atom.index = i;
        for (var b = 0; b < atom.bonds.length; b++) {
          atom.bonds[b] += inc;
        }
        atoms[0].push(atom);
      }
    } else {
      atoms.modelData.push(modelData);
      atoms.push(modelatoms);
    }
 
    if (!options.multimodel) {
      break;
    }
  }
 
  return atoms;
}