diff --git a/src/parsers/CDJSON.ts b/src/parsers/CDJSON.ts index d1358e341..22d901036 100644 --- a/src/parsers/CDJSON.ts +++ b/src/parsers/CDJSON.ts @@ -1,3 +1,5 @@ +import { ParserOptionsSpec } from "./ParserOptionsSpec"; + /** * This parses the ChemDoodle json file format. Although this is registered * for the json file extension, other chemical json file formats exist that @@ -7,14 +9,15 @@ * @param {string} str * @param {ParserOptionsSpec} options * @category Parsers - */ -export function CDJSON(str, options) { +*/ + +export function CDJSON(str: string, options: ParserOptionsSpec) { var atoms: any[][] & Record = [[]]; if (typeof str === "string") { // Str is usually automatically parsed by JQuery str = JSON.parse(str); } - var molecules = str.m; + var molecules = (str as any).m; var atomsInFile = molecules[0].a; // Assumes there is at least one var bondsInFile = molecules[0].b; // molecule and ignores any more // Ignores any shapes diff --git a/src/parsers/CIF.ts b/src/parsers/CIF.ts index 6d85ac6cc..d6942da52 100644 --- a/src/parsers/CIF.ts +++ b/src/parsers/CIF.ts @@ -1,17 +1,18 @@ import { ParserOptionsSpec } from './ParserOptionsSpec'; -// puts atoms specified in mmCIF fromat in str into atoms import { assignBonds } from "./utils/assignBonds"; import { computeSecondaryStructure } from "./utils/computeSecondaryStructure"; import { processSymmetries } from "./utils/processSymmetries"; -import { conversionMatrix3, Matrix4, Vector3, } from "../WebGL" +import { conversionMatrix3, Matrix3, Matrix4, Vector3, } from "../WebGL" /** + * Puts atoms specified in mmCIF fromat in str into atoms + * * @param {string} str * @param {ParserOptionsSpec} options * @category Parsers +*/ - */ export function CIF(str: string, options: ParserOptionsSpec = {}) { var atoms: any[] & Record = []; var noAssembly = !options.doAssembly; // don't assemble by default @@ -20,12 +21,12 @@ export function CIF(str: string, options: ParserOptionsSpec = {}) { options.assignBonds === undefined ? true : options.assignBonds; //coordinate conversion - var fractionalToCartesian = function (cmat, x, y, z) { + var fractionalToCartesian = function (cmat: Matrix3, x: number, y: number, z: number) { return new Vector3(x, y, z).applyMatrix3(cmat); }; // Used to handle quotes correctly - function splitRespectingQuotes(string, separator) { + function splitRespectingQuotes(string: string, separator: string | any[]) { var sections: any[] = []; var sectionStart = 0; var sectionEnd = 0; @@ -318,7 +319,7 @@ export function CIF(str: string, options: ParserOptionsSpec = {}) { modelData[modelData.length - 1].symmetries.push(matrix); } } - var parseTerm = function (term) { + var parseTerm = function (term: string) { var negative = term.match("-"); term = term.replace(/[-xyz]/g, ""); var fractionParts = term.split("/"); @@ -342,7 +343,7 @@ export function CIF(str: string, options: ParserOptionsSpec = {}) { /["' ]/g, "" ); - var componentStrings = transform.split(",").map(function (val) { + var componentStrings = transform.split(",").map(function (val: string) { return val.replace(/-/g, "+-"); }); let matrix = new Matrix4( diff --git a/src/parsers/CUBE.ts b/src/parsers/CUBE.ts index 8184880f8..67ddc4d89 100644 --- a/src/parsers/CUBE.ts +++ b/src/parsers/CUBE.ts @@ -1,16 +1,16 @@ import { Vector3, Matrix4 } from "../WebGL"; import { assignBonds } from "./utils/assignBonds"; import { anumToSymbol } from "./utils/anumToSymbol"; +import { ParserOptionsSpec } from "./ParserOptionsSpec"; /** - * @param {string} - * str - * @param {ParserOptionsSpec} - * options + * @param {string} + * str + * @param {ParserOptionsSpec} + * options * @category Parsers - */ -export function CUBE(str, options) { +export function CUBE(str: string, options: ParserOptionsSpec) { options = options || {}; var atoms: any[][] & Record = [[]]; var lines = str.split(/\r?\n/); @@ -37,22 +37,22 @@ export function CUBE(str, options) { // always assume bohr: openbabel source code // always assume angstrom: http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/cubeplugin.html // we are going to go with n<0 means angstrom - note this is just the first n - var convFactor = (lineArr[0] > 0) ? 0.529177 : 1; + var convFactor = ((lineArr[0] as any) > 0) ? 0.529177 : 1; origin.multiplyScalar(convFactor); - var nX = Math.abs(lineArr[0]); + var nX = Math.abs((lineArr[0] as any)); var xVec = new Vector3(parseFloat(lineArr[1]), parseFloat(lineArr[2]), parseFloat(lineArr[3])) .multiplyScalar(convFactor); lineArr = lines[4].replace(/^\s+/, "").replace(/\s+/g, " ").split(" "); - var nY = Math.abs(lineArr[0]); + var nY = Math.abs((lineArr[0] as any)); var yVec = new Vector3(parseFloat(lineArr[1]), parseFloat(lineArr[2]), parseFloat(lineArr[3])) .multiplyScalar(convFactor); lineArr = lines[5].replace(/^\s+/, "").replace(/\s+/g, " ").split(" "); - var nZ = Math.abs(lineArr[0]); + var nZ = Math.abs((lineArr[0] as any)); var zVec = new Vector3(parseFloat(lineArr[1]), parseFloat(lineArr[2]), parseFloat(lineArr[3])) .multiplyScalar(convFactor); diff --git a/src/parsers/GRO.ts b/src/parsers/GRO.ts index 8fc8a10e5..8c3ddfe87 100644 --- a/src/parsers/GRO.ts +++ b/src/parsers/GRO.ts @@ -3,15 +3,15 @@ import { atomNameToElem } from "./utils/atomNameToElem"; /** * Parse a gro file from str and create atoms - * - * @param {string} - * str - * @param {ParserOptionsSpec} - * options* - * @category Parsers + * + * @param {string} + * str + * @param {ParserOptionsSpec} + * options* + * @category Parsers +*/ - */ -export function GRO(str /*, options*/) { +export function GRO(str: string /*, options*/) { var allatoms: any[][] & Record = []; var lines = str.split(/\r?\n|\r/); while (lines.length > 0) { @@ -53,7 +53,7 @@ export function GRO(str /*, options*/) { var box = last.trim().split(/\s+/); if (box.length == 3) { for (var b = 0; b < 3; b++) { - box[b] = parseFloat(box[b]) * 10.0; + (box[b] as any) = parseFloat(box[b]) * 10.0; } allatoms.box = box; } diff --git a/src/parsers/LAMMPSTRJ.ts b/src/parsers/LAMMPSTRJ.ts index f61141254..269d1edd5 100644 --- a/src/parsers/LAMMPSTRJ.ts +++ b/src/parsers/LAMMPSTRJ.ts @@ -1,13 +1,15 @@ +import { ParserOptionsSpec } from "./ParserOptionsSpec"; import { assignBonds } from "./utils/assignBonds"; /** * Parse a lammps trajectory file from str and create atoms + * * @category Parsers +*/ - */ -export function LAMMPSTRJ(str, options) { +export function LAMMPSTRJ(str: string, options: ParserOptionsSpec) { var atoms: any[] = []; - var dic = { + var dic:any = { id: "serial", type: "atom", element: "elem", @@ -43,7 +45,7 @@ export function LAMMPSTRJ(str, options) { atoms.push([]); for (let j = offset; j < offset + atomCount; j++) { var atom: Record = {}; - var properties = {}; + var properties: any = {}; var tokens = lines[j].split(" "); for (var k = 0; k < tokens.length; k++) { var prop = dic[types[k]]; diff --git a/src/parsers/MMTF.ts b/src/parsers/MMTF.ts index 216c8cfc2..74ff227e5 100644 --- a/src/parsers/MMTF.ts +++ b/src/parsers/MMTF.ts @@ -1,5 +1,6 @@ import { base64ToArray } from "../utilities"; import { Matrix4 } from "../WebGL"; +import { ParserOptionsSpec } from "./ParserOptionsSpec"; import { computeSecondaryStructure } from "./utils/computeSecondaryStructure"; import { processSymmetries } from "./utils/processSymmetries"; @@ -8,12 +9,12 @@ interface MMTFobj { } declare var MMTF: MMTFobj; -var fromCharCode = function (charCodeArray) { +var fromCharCode = function (charCodeArray: any) { return String.fromCharCode.apply(null, charCodeArray).replace(/\0/g, ''); }; -var convertSS = function (val) { - //convert mmtf code to 3dmol code +var convertSS = function (val: number | boolean) { + // Convert mmtf code to 3dmol code /* 0: pi helix 1: bend @@ -41,11 +42,13 @@ let mmtfHETATMtypes = new Set([ "PEPTIDE-LIKE", "SACCHARIDE"]); -/** @param bindata - binary UInt8Array buffer or a base64 encoded string - * @param ParserOptionsSpec - * @category Parsers +/** + * @param bindata - binary UInt8Array buffer or a base64 encoded string + * @param ParserOptionsSpec + * @category Parsers */ -export function MMTFparser(bindata, options) { + +export function MMTFparser(bindata: any, options: ParserOptionsSpec) { var noH = !options.keepH; // suppress hydrogens by default var selAltLoc = options.altLoc ? options.altLoc : 'A'; //default alternate location to select if present @@ -108,7 +111,7 @@ export function MMTFparser(bindata, options) { } let chainIsPolymer: boolean[] = []; - mmtfData.entityList.forEach(entity => { + mmtfData.entityList.forEach((entity: { chainIndexList: any[]; type: string; }) => { entity.chainIndexList.forEach(ch => { chainIsPolymer[ch] = entity.type == "polymer"; }); diff --git a/src/parsers/MOL2.ts b/src/parsers/MOL2.ts index c3d7cee8c..012bdae4b 100644 --- a/src/parsers/MOL2.ts +++ b/src/parsers/MOL2.ts @@ -1,5 +1,6 @@ +import { ParserOptionsSpec } from "./ParserOptionsSpec"; -let SYBYLtoElem = { +let SYBYLtoElem:any = { 'C.1': 'C', 'C1': 'C', 'C.2': 'C', @@ -50,16 +51,17 @@ let SYBYLtoElem = { 'So2':'S' }; -// parse SYBYL mol2 file from string - assumed to only contain one molecule -// tag +// Parse SYBYL mol2 file from string - assumed to only contain one molecule tag + /** * @param {string} * str * @param {ParserOptionsSpec} * options * @category Parsers - */ -export function MOL2(str, options) { +*/ + +export function MOL2(str: string, options: ParserOptionsSpec) { var atoms: any[][] & Record = [[]]; var noH = false; if (typeof options.keepH !== "undefined") noH = !options.keepH; diff --git a/src/parsers/PDB.ts b/src/parsers/PDB.ts index f2917a6a9..a319752fd 100644 --- a/src/parsers/PDB.ts +++ b/src/parsers/PDB.ts @@ -1,24 +1,24 @@ -// 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 { ParserOptionsSpec } from "./ParserOptionsSpec"; import { getSinglePDB } from "./utils/getSinglePDB"; /** + * 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 + * * @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) { +*/ + +export function PDB(str: string, options: ParserOptionsSpec) { options = options || {}; var atoms: any[] & Record = []; //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/); + var lines: any = str.split(/\r?\n|\r/); while (lines.length > 0) { var pdbinfo = getSinglePDB(lines, options, sslookup); var modelatoms = pdbinfo[0]; diff --git a/src/parsers/PQR.ts b/src/parsers/PQR.ts index 746b7e311..4c42b6b88 100644 --- a/src/parsers/PQR.ts +++ b/src/parsers/PQR.ts @@ -1,18 +1,19 @@ +import { ParserOptionsSpec } from "./ParserOptionsSpec"; import { assignPDBBonds } from "./utils/assignPDBBonds"; import { computeSecondaryStructure } from "./utils/computeSecondaryStructure"; - /** - * Parse a pqr file from str and create atoms. A pqr file is assumed to be a - * whitespace delimited PDB with charge and radius fields. - * - * @param {string} - * str - * @param {ParserOptionsSpec} - * options - noSecondaryStructure (do not compute ss) - * @category Parsers - */ -export function PQR(str, options) { +/** + * Parse a pqr file from str and create atoms. A pqr file is assumed to be a whitespace delimited PDB with charge and radius fields. + * + * @param {string} + * str + * @param {ParserOptionsSpec} + * options - noSecondaryStructure (do not compute ss) + * @category Parsers +*/ + +export function PQR(str: string, options: ParserOptionsSpec) { var atoms: any[][] & Record = [[]]; var computeStruct = !options.noSecondaryStructure; atoms.modelData = [{symmetries:[]}]; diff --git a/src/parsers/PRMTOP.ts b/src/parsers/PRMTOP.ts index b5d040714..ba5abf26a 100644 --- a/src/parsers/PRMTOP.ts +++ b/src/parsers/PRMTOP.ts @@ -1,16 +1,16 @@ // @ts-nocheck + /** * Parse a prmtop file from str and create atoms * - * @param {string} - * str - * @param {ParserOptionsSpec} - * options - noSecondaryStructure (do not compute ss) - * + * @param {string} + * str + * @param {ParserOptionsSpec} + * options - noSecondaryStructure (do not compute ss) * @category Parsers +*/ - */ -export function PRMTOP(str /*, options*/) { +export function PRMTOP(str: string /*, options*/) { var atoms = []; var atomIndex; var count = 0; diff --git a/src/parsers/SDF.ts b/src/parsers/SDF.ts index 26078a57f..36ab2ab75 100644 --- a/src/parsers/SDF.ts +++ b/src/parsers/SDF.ts @@ -1,10 +1,7 @@ -/* - * @param {!Array.} lines - * @param {ParserOptionsSpec} options - * @returns {!Array.>} - */ -var parseV2000 = function (lines, options) { - var atoms: any[][] & Record = [[]]; +import { ParserOptionsSpec } from "./ParserOptionsSpec"; + +var parseV2000 = function (lines: any, options: ParserOptionsSpec) { + var atoms: any & Record = [[]]; var noH = false; if (typeof options.keepH !== "undefined") noH = !options.keepH; @@ -16,11 +13,11 @@ var parseV2000 = function (lines, options) { var offset = 4; if (lines.length < 4 + atomCount + bondCount) break; - // serial is atom's index in file; index is atoms index in 'atoms' + // Serial is atom's index in file; index is atoms index in 'atoms' var serialToIndex: number[] = []; var start = atoms[atoms.length - 1].length; var end = start + atomCount; - var i, line; + var i: number, line: string; for (i = start; i < end; i++, offset++) { line = lines[offset]; var atom: Record = {}; @@ -66,12 +63,13 @@ var parseV2000 = function (lines, options) { return atoms; }; -/* +/** * @param {!Array.} lines * @param {ParserOptionsSpec} options * @returns {!Array.>} - */ -var parseV3000 = function (lines, options) { +*/ + +var parseV3000 = function (lines: any, options: ParserOptionsSpec) { var atoms: any[][] & Record = [[]]; var noH = false; if (typeof options.keepH !== "undefined") noH = !options.keepH; @@ -99,22 +97,22 @@ var parseV3000 = function (lines, options) { var serialToIndex: number[] = []; var start = atoms[atoms.length - 1].length; var end = start + atomCount; - var i, line; + var i: number, line: string; for (i = start; i < end; i++, offset++) { line = lines[offset]; var atomParts = line.substr(6).match(/\S+/g); - if (atomParts.length > 4) { + if (atomParts!.length > 4) { var atom: Record = {}; - var elem = atomParts[1].replace(/ /g, ""); + var elem = atomParts![1].replace(/ /g, ""); atom.atom = atom.elem = elem[0].toUpperCase() + elem.substr(1).toLowerCase(); if (atom.elem !== "H" || !noH) { atom.serial = i; serialToIndex[i] = atoms[atoms.length - 1].length; - atom.x = parseFloat(atomParts[2]); - atom.y = parseFloat(atomParts[3]); - atom.z = parseFloat(atomParts[4]); + atom.x = parseFloat(atomParts![2]); + atom.y = parseFloat(atomParts![3]); + atom.z = parseFloat(atomParts![4]); atom.hetflag = true; atom.bonds = []; atom.bondOrder = []; @@ -134,10 +132,10 @@ var parseV3000 = function (lines, options) { for (i = 0; i < bondCount; i++, offset++) { line = lines[offset]; var bondParts = line.substr(6).match(/\S+/g); - if (bondParts.length > 3) { - var from = serialToIndex[parseInt(bondParts[2]) - 1 + start]; - var to = serialToIndex[parseInt(bondParts[3]) - 1 + start]; - var order = parseFloat(bondParts[1]); + if (bondParts!.length > 3) { + var from = serialToIndex[parseInt(bondParts![2]) - 1 + start]; + var to = serialToIndex[parseInt(bondParts![3]) - 1 + start]; + var order = parseFloat(bondParts![1]); if (typeof from != "undefined" && typeof to != "undefined") { atoms[atoms.length - 1][from].bonds.push(to); atoms[atoms.length - 1][from].bondOrder.push(order); @@ -161,16 +159,15 @@ var parseV3000 = function (lines, options) { return atoms; }; - /** * @param {string} * str * @param {ParserOptionsSpec} * options * @category Parsers +*/ - */ -export function SDF(str, options) { +export function SDF(str: string, options: ParserOptionsSpec) { var molformat = "V2000"; var lines = str.split(/\r?\n|\r/); if (lines.length > 3 && lines[3].length > 38) { @@ -181,5 +178,5 @@ export function SDF(str, options) { } else if (molformat === "V3000") { return parseV3000(lines, options); } - return [[]]; + return [['']]; } diff --git a/src/parsers/VASP.ts b/src/parsers/VASP.ts index 23c14c8c9..a017c2d84 100644 --- a/src/parsers/VASP.ts +++ b/src/parsers/VASP.ts @@ -6,8 +6,9 @@ import { Matrix3 } from "../WebGL"; * @param {ParserOptionsSpec} * options * @category Parsers - */ -export function VASP(str /*,options*/) { +*/ + +export function VASP(str: string /*,options*/) { var atoms: any[][] & Record = [[]]; var lattice: Record = {}; @@ -33,9 +34,9 @@ export function VASP(str /*,options*/) { return atoms; } - lattice.xVec = new Float32Array(lines[2].replace(/^\s+/, "").split(/\s+/)); - lattice.yVec = new Float32Array(lines[3].replace(/^\s+/, "").split(/\s+/)); - lattice.zVec = new Float32Array(lines[4].replace(/^\s+/, "").split(/\s+/)); + lattice.xVec = new Float32Array((lines[2] as any).replace(/^\s+/, "").split(/\s+/)); + lattice.yVec = new Float32Array((lines[3] as any).replace(/^\s+/, "").split(/\s+/)); + lattice.zVec = new Float32Array((lines[4] as any).replace(/^\s+/, "").split(/\s+/)); var matrix = new Matrix3( lattice.xVec[0], @@ -56,7 +57,7 @@ export function VASP(str /*,options*/) { .replace(/\s+$/, "") .split(/\s+/); var atomSpeciesNumber = new Int16Array( - lines[6].replace(/^\s+/, "").split(/\s+/) + (lines[6] as any).replace(/^\s+/, "").split(/\s+/) ); var vaspMode = lines[7].replace(/\s+/, ""); @@ -86,11 +87,11 @@ export function VASP(str /*,options*/) { var atomSymbol = atomSymbols[i]; for (var j = 0, atomLen = atomSpeciesNumber[i]; j < atomLen; j++) { var coords = new Float32Array( - lines[atomCounter + j].replace(/^\s+/, "").split(/\s+/) + (lines[atomCounter + j] as any).replace(/^\s+/, "").split(/\s+/) ); var atom: Record = {}; - atom.elem = atomSymbol; + (atom.elem as any) = atomSymbol; if (vaspMode == "cartesian") { atom.x = lattice.length * coords[0]; atom.y = lattice.length * coords[1]; diff --git a/src/parsers/XYZ.ts b/src/parsers/XYZ.ts index 66b4f9d5d..a4ec23a9c 100644 --- a/src/parsers/XYZ.ts +++ b/src/parsers/XYZ.ts @@ -1,14 +1,16 @@ import { ParserOptionsSpec } from './ParserOptionsSpec'; -// read an XYZ file from str and return result import { Matrix3 } from "../WebGL"; import { assignBonds } from "./utils/assignBonds"; /** + * Read an XYZ file from str and return result + * * @param {string} str * @param {ParserOptionsSpec} options * @category Parsers - */ +*/ + export function XYZ(str: string, options: ParserOptionsSpec) { options = options || {}; var atoms: any[][] & Record = [[]]; diff --git a/src/parsers/utils/anumToSymbol.ts b/src/parsers/utils/anumToSymbol.ts index 6f91c6d5a..62334469b 100644 --- a/src/parsers/utils/anumToSymbol.ts +++ b/src/parsers/utils/anumToSymbol.ts @@ -1,4 +1,4 @@ -export const anumToSymbol = { +export const anumToSymbol:any = { 1: 'H', 2: 'He', 3:'Li',4:'Be', 5: 'B', 6: 'C', 7:'N', 8:'O', 9:'F', 10: 'Ne', 11: 'Na',12:'Mg', 13: 'Al',14:'Si',15:'P',16:'S',17:'Cl',18:'Ar', diff --git a/src/parsers/utils/areConnected.ts b/src/parsers/utils/areConnected.ts index 1afd36ed2..923c3cd5e 100644 --- a/src/parsers/utils/areConnected.ts +++ b/src/parsers/utils/areConnected.ts @@ -1,9 +1,10 @@ import { bondLength } from "./bondLength"; /* - * return true if atom1 and atom2 are probably bonded to each other based on distance alone - */ -export function areConnected(atom1, atom2) { + * Return true if atom1 and atom2 are probably bonded to each other based on distance alone +*/ + +export function areConnected(atom1: { elem: any; x: number; y: number; z: number; altLoc: string; }, atom2: { elem: any; x: number; y: number; z: number; altLoc: string; }) { var maxsq = bondLength(atom1.elem) + bondLength(atom2.elem); maxsq += 0.25; // fudge factor, especially important for md frames, also see 1i3d maxsq *= maxsq; diff --git a/src/parsers/utils/assignBackboneHBonds.ts b/src/parsers/utils/assignBackboneHBonds.ts index 5994a061d..7531e96e8 100644 --- a/src/parsers/utils/assignBackboneHBonds.ts +++ b/src/parsers/utils/assignBackboneHBonds.ts @@ -1,7 +1,7 @@ -// this will identify all hydrogen bonds between backbone +// This will identify all hydrogen bonds between backbone // atoms; assume atom names are correct, only identifies // single closest hbond -export function assignBackboneHBonds(atomsarray, hbondCutoff) { +export function assignBackboneHBonds(atomsarray: string | any[], hbondCutoff: number) { let maxlength = hbondCutoff || 3.2; let maxlengthSq = maxlength*maxlength; let atoms = []; diff --git a/src/parsers/utils/assignBonds.ts b/src/parsers/utils/assignBonds.ts index cc63d8f3d..9485202dd 100644 --- a/src/parsers/utils/assignBonds.ts +++ b/src/parsers/utils/assignBonds.ts @@ -1,10 +1,11 @@ import { areConnected } from "./areConnected"; -/* +/** * @param {AtomSpec[]} atoms - */ -export function assignBonds(atoms) { - // assign bonds - yuck, can't count on connect records +*/ + +export function assignBonds(atoms: string | any[]) { + // Assign bonds - yuck, can't count on connect records for (var i = 0, n = atoms.length; i < n; i++) { // Don't reindex if atoms are already indexed @@ -32,7 +33,7 @@ export function assignBonds(atoms) { grid[x][y][z].push(atom); } - var findConnections = function (points, otherPoints) { + var findConnections = function (points: string | any[], otherPoints: string | any[]) { for (var i = 0; i < points.length; i++) { var atom1 = points[i]; for (var j = 0; j < otherPoints.length; j++) { diff --git a/src/parsers/utils/assignPDBBonds.ts b/src/parsers/utils/assignPDBBonds.ts index 7e96509d4..4205741f1 100644 --- a/src/parsers/utils/assignPDBBonds.ts +++ b/src/parsers/utils/assignPDBBonds.ts @@ -1,19 +1,20 @@ -// this is optimized for proteins where it is assumed connected -// atoms are on the same or next residue +// 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) { +*/ + +export function assignPDBBonds(atomsarray: string | any[]) { // assign bonds - yuck, can't count on connect records var protatoms: any[] = []; var hetatoms: any[] = []; - var i, n; + var i: number, n: number; for (i = 0, n = atomsarray.length; i < n; i++) { var atom: any = atomsarray[i]; atom.index = i; @@ -32,7 +33,7 @@ export function assignPDBBonds(atomsarray) { // for identifying connected residues var currentResi = -1; var reschain = -1; - var lastResConnected; + var lastResConnected: boolean; for (i = 0, n = protatoms.length; i < n; i++) { var ai = protatoms[i]; diff --git a/src/parsers/utils/atomNameToElem.ts b/src/parsers/utils/atomNameToElem.ts index 4971849ed..d5baacc42 100644 --- a/src/parsers/utils/atomNameToElem.ts +++ b/src/parsers/utils/atomNameToElem.ts @@ -1,7 +1,7 @@ import { bondTable } from "./bondLength"; -//attempts to infer atomic element from an atom name -export function atomNameToElem(name, nothetero) { +// Attempts to infer atomic element from an atom name +export function atomNameToElem(name: string, nothetero: boolean) { var elem = name.replace(/ /g, ""); if(elem.length > 0 && elem[0] == 'H' && elem != 'Hg' && elem != 'He' && elem != 'Hf' && elem != 'Hs' && elem != 'Ho') { elem = 'H'; //workaround weird hydrogen names from MD, note mercury must use lowercase diff --git a/src/parsers/utils/bondLength.ts b/src/parsers/utils/bondLength.ts index 5b6424918..f324966b2 100644 --- a/src/parsers/utils/bondLength.ts +++ b/src/parsers/utils/bondLength.ts @@ -1,7 +1,6 @@ -/* Covalent radii lookup table used to identify bonds in assignBonds - */ -export let bondTable = { +// Covalent radii lookup table used to identify bonds in assignBonds +export let bondTable:any = { H :0.37, He:0.32, Li:1.34,Be:0.90, B :0.82,C :0.77,N :0.75,O :0.73,F :0.71,Ne:0.69, Na:1.54,Mg:1.30, Al:1.18,Si:1.11,P :1.06,S :1.02,Cl:0.99,Ar:0.97, @@ -13,16 +12,12 @@ export let bondTable = { }; -/** Get the length used for bond identification for the specified element. - * - */ -export function bondLength(elem) { +// Get the length used for bond identification for the specified element. +export function bondLength(elem: string | number) { return bondTable[elem] || 1.6; }; -/** Set the length used for bond identification for the specified element. - * - */ +// Set the length used for bond identification for the specified element. export function setBondLength(elem:string, radius:number) { if(radius < 0) radius = 0; bondTable[elem] = radius; diff --git a/src/parsers/utils/computeSecondaryStructure.ts b/src/parsers/utils/computeSecondaryStructure.ts index dd005dafe..759280ae4 100644 --- a/src/parsers/utils/computeSecondaryStructure.ts +++ b/src/parsers/utils/computeSecondaryStructure.ts @@ -1,12 +1,12 @@ import { assignBackboneHBonds } from "./assignBackboneHBonds"; -export function computeSecondaryStructure(atomsarray, hbondCutoff) { - assignBackboneHBonds(atomsarray, hbondCutoff); +export function computeSecondaryStructure(atomsarray: string | any[], hbondCutoff: number | undefined) { + assignBackboneHBonds(atomsarray, hbondCutoff!); // compute, per residue, what the secondary structure is var chres = {}; // lookup by chain and resid - var i, il, c, r; // i: used in for loop, il: length of atomsarray - var atom, val; + var i: number, il: number, c: string | number, r: number; // i: used in for loop, il: length of atomsarray + var atom: { chain: string | number; hbondDistanceSq: number; hbondOther: any; resi: number; ss: string; ssbegin: boolean; ssend: boolean; }, val: string; //identify helices first for (i = 0, il = atomsarray.length; i < il; i++) { diff --git a/src/parsers/utils/getSinglePDB.ts b/src/parsers/utils/getSinglePDB.ts index 61a809936..82073d4b9 100644 --- a/src/parsers/utils/getSinglePDB.ts +++ b/src/parsers/utils/getSinglePDB.ts @@ -6,9 +6,10 @@ import { isEmpty } from "./isEmpty"; import { processSymmetries } from "./processSymmetries"; import { assignPDBBonds } from "./assignPDBBonds"; import { validateBonds } from "./validateBonds"; +import { ParserOptionsSpec } from "parsers/ParserOptionsSpec"; -//return one model worth of pdb, returns atoms, modelData, and remaining lines -export function getSinglePDB(lines, options, sslookup) { +// Return one model worth of pdb, returns atoms, modelData, and remaining lines +export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslookup: { [x: string]: { [x: string]: any; }; hasOwnProperty?: any; }) { var atoms: any[] = []; var assignbonds = options.assignBonds === undefined ? true : options.assignBonds; @@ -18,18 +19,18 @@ export function getSinglePDB(lines, options, sslookup) { var noAssembly = !options.doAssembly; // don't assemble by default var selAltLoc = options.altLoc ? options.altLoc : "A"; //default alternate location to select if present var modelData: Record = { symmetries: [] }; - var atom; + var atom: any; var remainingLines = []; var hasStruct = false; var serialToIndex: number[] = []; // map from pdb serial to index in atoms - var line; + var line: string | string[]; var seenbonds: Record = {}; //sometimes connect records are duplicated as an unofficial means of relaying bond orders for (let i = 0; i < lines.length; i++) { line = lines[i].replace(/^\s*/, ""); // remove indent var recordName = line.substr(0, 6); - var startChain, startResi, endChain, endResi; + var startChain: string, startResi: number, endChain: any, endResi: number; if (recordName.indexOf("END") == 0) { remainingLines = lines.slice(i + 1); @@ -44,7 +45,7 @@ export function getSinglePDB(lines, options, sslookup) { } break; } else if (recordName == "ATOM " || recordName == "HETATM") { - var resn, chain, resi, icode, x, y, z, hetflag, elem, serial, altLoc, b; + var resn: any, chain: any, resi: string | number, icode: string, x: number, y: number, z: number, hetflag: boolean, elem: string | string[], serial: number, altLoc: string, b: number; altLoc = line.substr(16, 1); if (altLoc != " " && altLoc != selAltLoc && selAltLoc != "*") continue; serial = parseInt(line.substr(6, 5)); @@ -169,7 +170,7 @@ export function getSinglePDB(lines, options, sslookup) { recordName == "REMARK" && line.substr(13, 5) == "BIOMT" ) { - var n; + var n: number; var matrix = new Matrix4(); for (n = 1; n <= 3; n++) { line = lines[i].replace(/^\s*/, ""); @@ -198,7 +199,7 @@ export function getSinglePDB(lines, options, sslookup) { modelData.symmetries.push(matrix); i--; // set i back } else if (recordName == "CRYST1") { - let a, b, c, alpha, beta, gamma; + let a: number, b: number, c: number, alpha: number, beta: number, gamma: number; a = parseFloat(line.substr(7, 8)); b = parseFloat(line.substr(16, 8)); c = parseFloat(line.substr(25, 8)); diff --git a/src/parsers/utils/isEmpty.ts b/src/parsers/utils/isEmpty.ts index 1a3ef7890..281039cc8 100644 --- a/src/parsers/utils/isEmpty.ts +++ b/src/parsers/utils/isEmpty.ts @@ -1,5 +1,5 @@ -export function isEmpty(obj) { - var name; +export function isEmpty(obj: { [x: string]: { [x: string]: any; }; hasOwnProperty?: any; }) { + var name: string; for (name in obj) { return false; } diff --git a/src/parsers/utils/processSymmetries.ts b/src/parsers/utils/processSymmetries.ts index a343756c5..8bbb53f50 100644 --- a/src/parsers/utils/processSymmetries.ts +++ b/src/parsers/utils/processSymmetries.ts @@ -1,11 +1,12 @@ +import { ParserOptionsSpec } from 'parsers/ParserOptionsSpec'; import { Matrix3, conversionMatrix3, Vector3 } from '../../WebGL'; -//adds symmetry info to either duplicate and rotate/translate biological unit later or add extra atoms now -//matrices may be modified if normalization is requested -export function processSymmetries(copyMatrices, atoms, options, cryst) { +// Adds symmetry info to either duplicate and rotate/translate biological unit later or add extra atoms now +// matrices may be modified if normalization is requested +export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], options: ParserOptionsSpec, cryst: { a: any; b: number; c: number; alpha: number; beta: number; gamma: number; }) { var dontDuplicate = !options.duplicateAssemblyAtoms; var end = atoms.length; var offset = end; - var t, l, n; // Used in for loops + var t: any, l: number, n: number; // Used in for loops let modifiedIdentity = -1; if (options.normalizeAssembly && cryst) { @@ -109,7 +110,7 @@ export function processSymmetries(copyMatrices, atoms, options, cryst) { } } //we have explicitly duplicated the atoms, remove model symmetry information - copyMatrices.length = 0; + (copyMatrices as any).length = 0; } else if (copyMatrices.length > 1) { for (t = 0; t < atoms.length; t++) { var symmetries: Vector3[] = []; diff --git a/src/parsers/utils/standardResidues.ts b/src/parsers/utils/standardResidues.ts index ccd11de4c..f3f7b7276 100644 --- a/src/parsers/utils/standardResidues.ts +++ b/src/parsers/utils/standardResidues.ts @@ -1,4 +1,4 @@ -export const standardResidues = new Set([ +export const standardResidues: Set = new Set([ "ABU", "ACD", "ALA", diff --git a/src/parsers/utils/validateBonds.ts b/src/parsers/utils/validateBonds.ts index fce4d1b5e..888cb9af2 100644 --- a/src/parsers/utils/validateBonds.ts +++ b/src/parsers/utils/validateBonds.ts @@ -1,5 +1,5 @@ -//make sure bonds are actually two way -export function validateBonds (atomsarray, serialToIndex) { +// Make sure bonds are actually two way +export function validateBonds (atomsarray: string[] | any[], serialToIndex: number[]) { for (var i = 0, n = atomsarray.length; i < n; i++) { var atom = atomsarray[i]; for(var b = 0; b < atom.bonds.length; b++) {