From 7f98d2e255ed641fe2d6a606211d084e4effc722 Mon Sep 17 00:00:00 2001 From: Prajwal Kulkarni Date: Fri, 26 Jan 2024 17:02:26 +0530 Subject: [PATCH 1/2] Refactor remaining files in parser/utils --- src/parsers/utils/assignBonds.ts | 13 +- src/parsers/utils/assignPDBBonds.ts | 41 +++--- src/parsers/utils/getSinglePDB.ts | 167 ++++++++++++++----------- src/parsers/utils/isEmpty.ts | 8 +- src/parsers/utils/processSymmetries.ts | 65 +++++----- src/parsers/utils/validateBonds.ts | 30 ++--- src/specs.ts | 40 +++--- 7 files changed, 206 insertions(+), 158 deletions(-) diff --git a/src/parsers/utils/assignBonds.ts b/src/parsers/utils/assignBonds.ts index 40a0488a1..197a0bf2c 100644 --- a/src/parsers/utils/assignBonds.ts +++ b/src/parsers/utils/assignBonds.ts @@ -21,7 +21,7 @@ const OFFSETS = [ ]; const MAX_BOND_LENGTH = 4.95; // (largest bond length, Cs) 2.25 * 2 * 1.1 (fudge factor) -export function assignBonds(atoms: string | any[]) { +export function assignBonds(atoms: AtomSpec[]) { // Assign bonds - yuck, can't count on connect records for (let i = 0, n = atoms.length; i < n; i++) { @@ -29,7 +29,14 @@ export function assignBonds(atoms: string | any[]) { if (!atoms[i].index) atoms[i].index = i; } - const grid = {}; + let grid: { + x: { + y: { + z: AtomSpec[]; + }; + }; + }; + for (let index = 0; index < atoms.length; index++) { const atom = atoms[index]; const x = Math.floor(atom.x / MAX_BOND_LENGTH); @@ -76,7 +83,7 @@ export function assignBonds(atoms: string | any[]) { } } } - }; + } for (let xg in grid) { const x = parseInt(xg); diff --git a/src/parsers/utils/assignPDBBonds.ts b/src/parsers/utils/assignPDBBonds.ts index 4205741f1..f8f2bc649 100644 --- a/src/parsers/utils/assignPDBBonds.ts +++ b/src/parsers/utils/assignPDBBonds.ts @@ -1,22 +1,21 @@ // This is optimized for proteins where it is assumed connected atoms are on the same or next residue +import { AtomSpec } from "specs"; import { areConnected } from "./areConnected"; import { assignBonds } from "./assignBonds"; import { standardResidues } from "./standardResidues"; - -/** +/** * @param {AtomSpec[]} * atomsarray -*/ + */ -export function assignPDBBonds(atomsarray: string | any[]) { +export function assignPDBBonds(atomsarray: AtomSpec[]) { // assign bonds - yuck, can't count on connect records - var protatoms: any[] = []; - var hetatoms: any[] = []; - var i: number, n: number; - for (i = 0, n = atomsarray.length; i < n; i++) { - var atom: any = atomsarray[i]; + const protatoms: Array = []; + const hetatoms: Array = []; + for (let i = 0, n = atomsarray.length; i < n; i++) { + const atom = atomsarray[i]; atom.index = i; if (atom.hetflag || !standardResidues.has(atom.resn)) hetatoms.push(atom); else protatoms.push(atom); @@ -25,18 +24,18 @@ export function assignPDBBonds(atomsarray: string | any[]) { assignBonds(hetatoms); // sort by resid - protatoms.sort(function (a: any, b: any) { - if (a.chain != b.chain) return a.chain < b.chain ? -1 : 1; + protatoms.sort(function (a, b) { + 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: boolean; + let currentResi = -1; + let reschain = -1; + let lastResConnected: boolean; - for (i = 0, n = protatoms.length; i < n; i++) { - var ai = protatoms[i]; + for (let i = 0, n = protatoms.length; i < n; i++) { + const ai = protatoms[i]; if (ai.resi !== currentResi) { currentResi = ai.resi; @@ -47,12 +46,10 @@ export function assignPDBBonds(atomsarray: string | any[]) { 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; + for (let j = i + 1; j < protatoms.length; j++) { + const aj = protatoms[j]; + if (aj.chain !== ai.chain || aj.resi - ai.resi > 1) break; + if (areConnected(ai, aj)) { if (ai.bonds.indexOf(aj.index) === -1) { // only add if not already there diff --git a/src/parsers/utils/getSinglePDB.ts b/src/parsers/utils/getSinglePDB.ts index cab1607e4..6fb5b5fbf 100644 --- a/src/parsers/utils/getSinglePDB.ts +++ b/src/parsers/utils/getSinglePDB.ts @@ -7,47 +7,63 @@ import { processSymmetries } from "./processSymmetries"; import { assignPDBBonds } from "./assignPDBBonds"; import { validateBonds } from "./validateBonds"; import { ParserOptionsSpec } from "../ParserOptionsSpec"; - +import { AtomSpec, Cryst } from "specs"; // 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 = +export function getSinglePDB( + lines: string[], + options: ParserOptionsSpec, + sslookup: { [x: string]: { [x: string]: string }; hasOwnProperty?: any } +): [AtomSpec[], { symmetries: Matrix4[]; cryst: Cryst }, string[]]{ + const atoms: AtomSpec[] = []; + const assignbonds = options.assignBonds === undefined ? true : options.assignBonds; - var noH = !options.keepH; // suppress hydrogens by default - var ignoreStruct = !!options.noSecondaryStructure; - var computeStruct = !options.noComputeSecondaryStructure; - 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: any; - var remainingLines = []; + const noH = !options.keepH; // suppress hydrogens by default + const ignoreStruct = !!options.noSecondaryStructure; + const computeStruct = !options.noComputeSecondaryStructure; + const noAssembly = !options.doAssembly; // don't assemble by default + const selAltLoc = options.altLoc ? options.altLoc : "A"; //default alternate location to select if present + let modelData: { symmetries: Matrix4[]; cryst: Cryst }; + //atom name + let atom: string; + let remainingLines = []; - var serialToIndex: number[] = []; // map from pdb serial to index in atoms - var line: string | string[]; - var seenbonds: Record = {}; //sometimes connect records are duplicated as an unofficial means of relaying bond orders + const serialToIndex: number[] = []; // map from pdb serial to index in atoms + let line: string | string[]; + const 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.substring(0, 6); + const recordName = line.substring(0, 6); - var startChain: string, startResi: number, endResi: number; + let startChain: string, startResi: number, endResi: number; - if (recordName.indexOf("END") == 0) { + if (recordName.indexOf("END") === 0) { remainingLines = lines.slice(i + 1); - if (recordName == "END") { + if (recordName === "END") { //as opposed to ENDMDL //reset secondary structure - for (var prop in sslookup) { + for (const prop in sslookup) { if (sslookup.hasOwnProperty(prop)) { delete sslookup[prop]; } } } break; - } else if (recordName == "ATOM " || recordName == "HETATM") { - 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; + } else if (recordName === "ATOM " || recordName === "HETATM") { + let resn: string, + 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.substring(16, 17); - if (altLoc != " " && altLoc != selAltLoc && selAltLoc != "*") continue; + if (altLoc !== " " && altLoc !== selAltLoc && selAltLoc !== "*") continue; serial = parseInt(line.substring(6, 11)); atom = line.substring(12, 16).replace(/ /g, ""); resn = line.substring(17, 20).replace(/ /g, ""); @@ -59,42 +75,42 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook z = parseFloat(line.substring(46, 54)); b = parseFloat(line.substring(60, 68)); elem = line.substring(76, 78).replace(/ /g, ""); - if (elem === "" || typeof bondTable[elem] === "undefined") { + if (elem === "" || bondTable[elem] === undefined) { // for some incorrect PDB files elem = atomNameToElem(line.substring(12, 14), line[0] == "A"); } else { elem = elem[0].toUpperCase() + elem.substring(1).toLowerCase(); } - if (elem == "H" && noH) continue; + if (elem === "H" && noH) continue; if (recordName[0] == "H") hetflag = true; else hetflag = false; serialToIndex[serial] = atoms.length; atoms.push({ - resn: resn, - x: x, - y: y, - z: z, - elem: elem, - hetflag: hetflag, - altLoc: altLoc, - chain: chain, - resi: resi, + resn, + x, + y, + z, + elem, + hetflag, + altLoc, + chain, + resi, icode: icode, - rescode: resi + (icode != " " ? "^" + icode : ""), // combo + rescode: resi + (icode !== " " ? "^" + icode : ""), // combo // resi // and // icode - serial: serial, - atom: atom, + serial, + atom, bonds: [], ss: "c", bondOrder: [], properties: {}, - b: b, + b, pdbline: line, }); - } else if (recordName == "SHEET ") { + } else if (recordName === "SHEET ") { startChain = line.substring(21, 22); startResi = parseInt(line.substring(22, 26)); endResi = parseInt(line.substring(33, 37)); @@ -103,30 +119,30 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook } //mark start and end with additional character sslookup[startChain][startResi] = "s1"; - for (var res = startResi + 1; res < endResi; res++) { + for (let res = startResi + 1; res < endResi; res++) { sslookup[startChain][res] = "s"; } sslookup[startChain][endResi] = "s2"; - } else if (recordName == "CONECT") { + } else if (recordName === "CONECT") { // MEMO: We don't have to parse SSBOND, LINK because both are // also // described in CONECT. But what about 2JYT??? - var from = parseInt(line.substring(6, 11)); - var fromindex = serialToIndex[from]; - var fromAtom = atoms[fromindex]; - var coffsets = [11, 16, 21, 26]; + const from = parseInt(line.substring(6, 11)); + const fromindex = serialToIndex[from]; + const fromAtom = atoms[fromindex]; + const coffsets = [11, 16, 21, 26]; for (let j = 0; j < 4; j++) { - var to = parseInt(line.substring(coffsets[j], coffsets[j]+5)); - var toindex = serialToIndex[to]; - let from_to = fromindex+":"+toindex; - var toAtom = atoms[toindex]; + const to = parseInt(line.substring(coffsets[j], coffsets[j] + 5)); + const toindex = serialToIndex[to]; + let from_to = fromindex + ":" + toindex; + const toAtom = atoms[toindex]; if (fromAtom !== undefined && toAtom !== undefined) { // duplicated conect records indicate bond order if (!seenbonds[from_to]) { seenbonds[from_to] = 1; if ( fromAtom.bonds.length == 0 || - fromAtom.bonds[fromAtom.bonds.length - 1] != toindex + fromAtom.bonds[fromAtom.bonds.length - 1] !== toindex ) { fromAtom.bonds.push(toindex); fromAtom.bondOrder.push(1); @@ -137,7 +153,7 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook for (let bi = 0; bi < fromAtom.bonds.length; bi++) { if (fromAtom.bonds[bi] == toindex) { - var newbo = seenbonds[from_to]; + const newbo = seenbonds[from_to]; if (newbo >= 4) { //aromatic fromAtom.bondOrder[bi] = 1; @@ -149,7 +165,7 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook } } } - } else if (recordName == "HELIX ") { + } else if (recordName === "HELIX ") { startChain = line.substring(19, 20); startResi = parseInt(line.substring(21, 25)); endResi = parseInt(line.substring(33, 37)); @@ -163,11 +179,11 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook sslookup[startChain][endResi] = "h2"; } else if ( !noAssembly && - recordName == "REMARK" && - line.substring(13, 18) == "BIOMT" + recordName === "REMARK" && + line.substring(13, 18) === "BIOMT" ) { - var n: number; - var matrix = new Matrix4(); + let n: number; + let matrix = new Matrix4(); for (n = 1; n <= 3; n++) { line = lines[i].replace(/^\s*/, ""); if (parseInt(line.substring(18, 19)) == n) { @@ -182,7 +198,7 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook matrix.elements[n - 1 + 12] = parseFloat(line.substring(53)); i++; } else { - while (line.substring(13, 18) == "BIOMT") { + while (line.substring(13, 18) === "BIOMT") { i++; line = lines[i].replace(/^\s*/, ""); } @@ -194,8 +210,13 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook matrix.elements[15] = 1; modelData.symmetries.push(matrix); i--; // set i back - } else if (recordName == "CRYST1") { - let a: number, b: number, c: number, alpha: number, beta: number, gamma: number; + } else if (recordName === "CRYST1") { + let a: number, + b: number, + c: number, + alpha: number, + beta: number, + gamma: number; a = parseFloat(line.substring(7, 15)); b = parseFloat(line.substring(16, 24)); c = parseFloat(line.substring(25, 33)); @@ -203,20 +224,20 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook beta = parseFloat(line.substring(41, 47)); gamma = parseFloat(line.substring(48, 54)); modelData.cryst = { - a: a, - b: b, - c: c, - alpha: alpha, - beta: beta, - gamma: gamma, + a, + b, + c, + alpha, + beta, + gamma, }; - } else if (recordName == "ANISOU") { - let serial = parseInt(line.substring(6, 11)); - var anisouAtomIndex = serialToIndex[serial]; - var anisouAtom = atoms[anisouAtomIndex]; + } else if (recordName === "ANISOU") { + const serial = parseInt(line.substring(6, 11)); + const anisouAtomIndex = serialToIndex[serial]; + const anisouAtom = atoms[anisouAtomIndex]; if (anisouAtom) { - var vals = line.substring(30).trim().split(/\s+/); - var uMat = { + const vals = line.substring(30).trim().split(/\s+/); + const uMat = { u11: parseInt(vals[0]), u22: parseInt(vals[1]), u33: parseInt(vals[2]), @@ -245,10 +266,10 @@ export function getSinglePDB(lines: string[], options: ParserOptionsSpec, sslook // Assign secondary structures from pdb file if (!isEmpty(sslookup)) { for (let i = 0; i < atoms.length; i++) { - atom = atoms[i]; + const atom = atoms[i]; if (atom === undefined) continue; if (atom.chain in sslookup && atom.resi in sslookup[atom.chain]) { - var code = sslookup[atom.chain][atom.resi]; + const code = sslookup[atom.chain][atom.resi]; atom.ss = code[0]; if (code.length > 1) { if (code[1] == "1") atom.ssbegin = true; diff --git a/src/parsers/utils/isEmpty.ts b/src/parsers/utils/isEmpty.ts index 281039cc8..1317f0950 100644 --- a/src/parsers/utils/isEmpty.ts +++ b/src/parsers/utils/isEmpty.ts @@ -1,6 +1,8 @@ -export function isEmpty(obj: { [x: string]: { [x: string]: any; }; hasOwnProperty?: any; }) { - var name: string; - for (name in obj) { +export function isEmpty(obj: { + [x: string]: { [x: string]: unknown }; + hasOwnProperty?: any; +}) { + for (const _ in obj) { return false; } return true; diff --git a/src/parsers/utils/processSymmetries.ts b/src/parsers/utils/processSymmetries.ts index 8bbb53f50..041465781 100644 --- a/src/parsers/utils/processSymmetries.ts +++ b/src/parsers/utils/processSymmetries.ts @@ -1,12 +1,18 @@ -import { ParserOptionsSpec } from 'parsers/ParserOptionsSpec'; -import { Matrix3, conversionMatrix3, Vector3 } from '../../WebGL'; +import { ParserOptionsSpec } from "parsers/ParserOptionsSpec"; +import { Matrix3, conversionMatrix3, Vector3 } from "../../WebGL"; +import { AtomSpec, Cryst } from "specs"; // 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: any, l: number, n: number; // Used in for loops + +export function processSymmetries( + copyMatrices: string[] | any[], + atoms: AtomSpec[], + options: ParserOptionsSpec, + cryst: Cryst +) { + const dontDuplicate = !options.duplicateAssemblyAtoms; + const end = atoms.length; + let offset = end; let modifiedIdentity = -1; if (options.normalizeAssembly && cryst) { @@ -15,7 +21,7 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], //compute the centroid, calculate any adjustment needed to get it in [0,1], //convert the adjustment to a cartesian translation, and then add it to //the symmetry matrix - let conversionMatrix = conversionMatrix3( + const conversionMatrix = conversionMatrix3( cryst.a, cryst.b, cryst.c, @@ -23,14 +29,14 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], cryst.beta, cryst.gamma ); - let toFrac = new Matrix3(); + const toFrac = new Matrix3(); toFrac.getInverse3(conversionMatrix); - for (t = 0; t < copyMatrices.length; t++) { + for (let t = 0; t < copyMatrices.length; t++) { //transform with the symmetry, and then back to fractional coordinates - let center = new Vector3(0, 0, 0); - for (n = 0; n < end; n++) { - let xyz = new Vector3(atoms[n].x, atoms[n].y, atoms[n].z); + const center = new Vector3(0, 0, 0); + for (let n = 0; n < end; n++) { + const xyz = new Vector3(atoms[n].x, atoms[n].y, atoms[n].z); xyz.applyMatrix4(copyMatrices[t]); xyz.applyMatrix3(toFrac); //figure out @@ -38,7 +44,7 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], } center.divideScalar(end); const centerCoord = [center.x, center.y, center.z]; - let adjustment = [0.0, 0.0, 0.0]; + const adjustment = [0.0, 0.0, 0.0]; for (let i = 0; i < 3; i++) { while (centerCoord[i] < -0.001) { centerCoord[i] += 1.0; @@ -57,7 +63,10 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], ); adjustmentVec.applyMatrix3(conversionMatrix); //modify symmetry matrix to include translation - if (copyMatrices[t].isNearlyIdentity() && adjustmentVec.lengthSq() > 0.001) { + if ( + copyMatrices[t].isNearlyIdentity() && + adjustmentVec.lengthSq() > 0.001 + ) { modifiedIdentity = t; //keep track of which matrix was identity } copyMatrices[t].translate(adjustmentVec); @@ -65,22 +74,22 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], } if (!dontDuplicate) { // do full assembly - for (n = 0; n < end; n++) { + for (let n = 0; n < end; n++) { atoms[n].sym = -1; //if identity matrix is present, original labeled -1 } - for (t = 0; t < copyMatrices.length; t++) { + for (let t = 0; t < copyMatrices.length; t++) { if (!copyMatrices[t].isNearlyIdentity() && modifiedIdentity != t) { - let xyz = new Vector3(); - for (n = 0; n < end; n++) { - var bondsArr: any[] = []; - for (l = 0; l < atoms[n].bonds.length; l++) { + const xyz = new Vector3(); + for (let n = 0; n < end; n++) { + const bondsArr: number[] = []; + for (let l = 0; l < atoms[n].bonds.length; l++) { bondsArr.push(atoms[n].bonds[l] + offset); } xyz.set(atoms[n].x, atoms[n].y, atoms[n].z); xyz.applyMatrix4(copyMatrices[t]); - var newAtom: Record = {}; - for (var i in atoms[n]) { + const newAtom: Record = {}; + for (const i in atoms[n]) { newAtom[i] = atoms[n][i]; } newAtom.x = xyz.x; @@ -93,15 +102,15 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], } offset = atoms.length; } else { - for (n = 0; n < end; n++) { + for (let n = 0; n < end; n++) { atoms[n].sym = t; } } } if (modifiedIdentity >= 0) { //after applying the other transformations, apply this one in place - let xyz = new Vector3(); - for (n = 0; n < end; n++) { + const xyz = new Vector3(); + for (let n = 0; n < end; n++) { xyz.set(atoms[n].x, atoms[n].y, atoms[n].z); xyz.applyMatrix4(copyMatrices[modifiedIdentity]); atoms[n].x = xyz.x; @@ -112,9 +121,9 @@ export function processSymmetries(copyMatrices: string[] | any[], atoms: any[], //we have explicitly duplicated the atoms, remove model symmetry information (copyMatrices as any).length = 0; } else if (copyMatrices.length > 1) { - for (t = 0; t < atoms.length; t++) { + for (let t = 0; t < atoms.length; t++) { var symmetries: Vector3[] = []; - for (l = 0; l < copyMatrices.length; l++) { + for (let l = 0; l < copyMatrices.length; l++) { if (!copyMatrices[l].isNearlyIdentity()) { var newXYZ = new Vector3(); newXYZ.set(atoms[t].x, atoms[t].y, atoms[t].z); diff --git a/src/parsers/utils/validateBonds.ts b/src/parsers/utils/validateBonds.ts index 17b176255..346f938df 100644 --- a/src/parsers/utils/validateBonds.ts +++ b/src/parsers/utils/validateBonds.ts @@ -1,18 +1,20 @@ +import { AtomSpec } from "specs"; + // Make sure bonds are actually two way -export function validateBonds (atomsarray: string[] | any[], serialToIndex: number[]) { +export function validateBonds(atomsarray: AtomSpec[], serialToIndex: number[]) { for (let i = 0, n = atomsarray.length; i < n; i++) { - const atom = atomsarray[i]; - for(let b = 0; b < atom.bonds.length; b++) { - const a2i = atom.bonds[b]; - const atom2 = atomsarray[a2i]; - const atomi = serialToIndex[atom.serial]; - if(atom2 && atomi) { - const a1i = atom2.bonds.indexOf(atomi); - if(a1i < 0) { - atom2.bonds.push(atomi); - atom2.bondOrder.push(atom.bondOrder[b]); - } - } + const atom = atomsarray[i]; + for (let b = 0; b < atom.bonds.length; b++) { + const a2i = atom.bonds[b]; + const atom2 = atomsarray[a2i]; + const atomi = serialToIndex[atom.serial]; + if (atom2 && atomi) { + const a1i = atom2.bonds.indexOf(atomi); + if (a1i < 0) { + atom2.bonds.push(atomi); + atom2.bondOrder.push(atom.bondOrder[b]); + } } + } } -}; \ No newline at end of file +} diff --git a/src/specs.ts b/src/specs.ts index f8b3cdb29..3b6587b7f 100644 --- a/src/specs.ts +++ b/src/specs.ts @@ -1,16 +1,15 @@ // Specifications for various object types used in 3Dmol.js // This is primarily for documentation +import { Vector3 } from "WebGL"; import { AtomStyleSpec, BondStyle, GLModel } from "./GLModel"; import { GLViewer } from "./GLViewer"; import { ColorSpec } from "./colors"; - - /** * Atom representation. Depending on the input file format, not all fields may be defined. */ -export interface AtomSpec { +export interface AtomSpec { /** Parent residue name */ resn?: string; /** Atom's x coordinate */ @@ -31,8 +30,8 @@ export interface AtomSpec { chain?: string; /** Residue number */ resi?: number; - icode?: number; - rescode?: number; + icode?: string; + rescode?: string; /** Atom's serial id number */ serial?: number; /** Index of atom in molecule */ @@ -78,7 +77,11 @@ export interface AtomSpec { hbondDistanceSq?: number; hbondOther?: any; altLoc?: string; -}; + reschain?: number; + uMat?: Record; + symmetries?: Vector3[]; + sym?: any; +} /** * Atom selection object. Used to specify what atoms should be selected. Can include @@ -96,9 +99,10 @@ export interface AtomSpec { * viewer.render(); * }); */ -export interface AtomSelectionSpec extends Omit { +export interface AtomSelectionSpec + extends Omit { /** a single model or list of models from which atoms should be selected. Can also specify by numerical creation order. Reverse indexing is allowed (-1 specifies last added model). */ - model?: GLModel | number | GLModel[] | number[]; + model?: GLModel | number | GLModel[] | number[]; /** frame index of individual frame to style; will apply to all frames if not set */ frame?: number; /** index of the atom or atoms to select */ @@ -114,19 +118,17 @@ export interface AtomSelectionSpec extends Omit Date: Fri, 26 Jan 2024 17:29:49 +0530 Subject: [PATCH 2/2] Assign initial value to grid and modelData --- src/parsers/utils/assignBonds.ts | 8 +++++++- src/parsers/utils/getSinglePDB.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parsers/utils/assignBonds.ts b/src/parsers/utils/assignBonds.ts index 197a0bf2c..7d84d0eb1 100644 --- a/src/parsers/utils/assignBonds.ts +++ b/src/parsers/utils/assignBonds.ts @@ -29,12 +29,18 @@ export function assignBonds(atoms: AtomSpec[]) { if (!atoms[i].index) atoms[i].index = i; } - let grid: { + const grid: { x: { y: { z: AtomSpec[]; }; }; + } = { + x: { + y: { + z: [], + }, + }, }; for (let index = 0; index < atoms.length; index++) { diff --git a/src/parsers/utils/getSinglePDB.ts b/src/parsers/utils/getSinglePDB.ts index 6fb5b5fbf..0405b29fa 100644 --- a/src/parsers/utils/getSinglePDB.ts +++ b/src/parsers/utils/getSinglePDB.ts @@ -22,7 +22,7 @@ export function getSinglePDB( const computeStruct = !options.noComputeSecondaryStructure; const noAssembly = !options.doAssembly; // don't assemble by default const selAltLoc = options.altLoc ? options.altLoc : "A"; //default alternate location to select if present - let modelData: { symmetries: Matrix4[]; cryst: Cryst }; + const modelData: { symmetries: Matrix4[]; cryst: Cryst } = {symmetries:[], cryst: undefined}; //atom name let atom: string; let remainingLines = [];