Skip to content

Commit

Permalink
Updated Parser Util Types
Browse files Browse the repository at this point in the history
Signed-off-by: Adithya Krishna <[email protected]>
  • Loading branch information
Adithya Krishna committed Jul 12, 2023
1 parent 6357419 commit 2a5c276
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/parsers/utils/assignBackboneHBonds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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: string | any[], hbondCutoff: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/utils/assignBonds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { areConnected } from "./areConnected";
* @param {AtomSpec[]} atoms
*/
export function assignBonds(atoms: string | any[]) {
// assign bonds - yuck, can't count on connect records
// 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
Expand Down
8 changes: 4 additions & 4 deletions src/parsers/utils/assignPDBBonds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 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";
Expand All @@ -13,7 +13,7 @@ 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;
Expand All @@ -32,7 +32,7 @@ export function assignPDBBonds(atomsarray: string | any[]) {
// 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];
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/utils/atomNameToElem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bondTable } from "./bondLength";

//attempts to infer atomic element from an atom name
// 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') {
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/utils/computeSecondaryStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export function computeSecondaryStructure(atomsarray: string | any[], hbondCutof

// 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++) {
Expand Down
96 changes: 48 additions & 48 deletions src/parsers/utils/getSinglePDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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: any[], options: ParserOptionsSpec, sslookup: { [x: string]: { [x: string]: any; }; hasOwnProperty?: any; }) {
// 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;
Expand All @@ -19,18 +19,18 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, 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<string, any> = { 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<any, any> = {}; //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 recordName = line.substring(0, 6);
var startChain: string, startResi: number, endChain: any, endResi: number;

if (recordName.indexOf("END") == 0) {
remainingLines = lines.slice(i + 1);
Expand All @@ -45,25 +45,25 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
}
break;
} else if (recordName == "ATOM " || recordName == "HETATM") {
var resn, chain, resi, icode, x, y, z, hetflag, elem, serial, altLoc, b;
altLoc = line.substr(16, 1);
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.substring(16, 1);
if (altLoc != " " && altLoc != selAltLoc && selAltLoc != "*") continue;
serial = parseInt(line.substr(6, 5));
atom = line.substr(12, 4).replace(/ /g, "");
resn = line.substr(17, 3).replace(/ /g, "");
chain = line.substr(21, 1);
resi = parseInt(line.substr(22, 4));
icode = line.substr(26, 1);
x = parseFloat(line.substr(30, 8));
y = parseFloat(line.substr(38, 8));
z = parseFloat(line.substr(46, 8));
b = parseFloat(line.substr(60, 8));
elem = line.substr(76, 2).replace(/ /g, "");
serial = parseInt(line.substring(6, 5));
atom = line.substring(12, 4).replace(/ /g, "");
resn = line.substring(17, 3).replace(/ /g, "");
chain = line.substring(21, 1);
resi = parseInt(line.substring(22, 4));
icode = line.substring(26, 1);
x = parseFloat(line.substring(30, 8));
y = parseFloat(line.substring(38, 8));
z = parseFloat(line.substring(46, 8));
b = parseFloat(line.substring(60, 8));
elem = line.substring(76, 2).replace(/ /g, "");
if (elem === "" || typeof bondTable[elem] === "undefined") {
// for some incorrect PDB files
elem = atomNameToElem(line.substr(12, 2), line[0] == "A");
elem = atomNameToElem(line.substring(12, 2), line[0] == "A");
} else {
elem = elem[0].toUpperCase() + elem.substr(1).toLowerCase();
elem = elem[0].toUpperCase() + elem.substring(1).toLowerCase();
}

if (elem == "H" && noH) continue;
Expand Down Expand Up @@ -96,10 +96,10 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
});
} else if (recordName == "SHEET ") {
hasStruct = true;
startChain = line.substr(21, 1);
startResi = parseInt(line.substr(22, 4));
endChain = line.substr(32, 1);
endResi = parseInt(line.substr(33, 4));
startChain = line.substring(21, 1);
startResi = parseInt(line.substring(22, 4));
endChain = line.substring(32, 1);
endResi = parseInt(line.substring(33, 4));
if (!(startChain in sslookup)) {
sslookup[startChain] = {};
}
Expand All @@ -113,12 +113,12 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
// MEMO: We don't have to parse SSBOND, LINK because both are
// also
// described in CONECT. But what about 2JYT???
var from = parseInt(line.substr(6, 5));
var from = parseInt(line.substring(6, 5));
var fromindex = serialToIndex[from];
var fromAtom = atoms[fromindex];
var coffsets = [11, 16, 21, 26];
for (let j = 0; j < 4; j++) {
var to = parseInt(line.substr(coffsets[j], 5));
var to = parseInt(line.substring(coffsets[j], 5));
var toindex = serialToIndex[to];
let from_to = fromindex+":"+toindex;
var toAtom = atoms[toindex];
Expand Down Expand Up @@ -153,10 +153,10 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
}
} else if (recordName == "HELIX ") {
hasStruct = true;
startChain = line.substr(19, 1);
startResi = parseInt(line.substr(21, 4));
endChain = line.substr(31, 1);
endResi = parseInt(line.substr(33, 4));
startChain = line.substring(19, 1);
startResi = parseInt(line.substring(21, 4));
endChain = line.substring(31, 1);
endResi = parseInt(line.substring(33, 4));
if (!(startChain in sslookup)) {
sslookup[startChain] = {};
}
Expand All @@ -168,25 +168,25 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
} else if (
!noAssembly &&
recordName == "REMARK" &&
line.substr(13, 5) == "BIOMT"
line.substring(13, 5) == "BIOMT"
) {
var n;
var n: number;
var matrix = new Matrix4();
for (n = 1; n <= 3; n++) {
line = lines[i].replace(/^\s*/, "");
if (parseInt(line.substr(18, 1)) == n) {
if (parseInt(line.substring(18, 1)) == n) {
// check for all
// three lines
// by matching #
// @ end of
// "BIOMT" to n
matrix.elements[n - 1] = parseFloat(line.substr(23, 10));
matrix.elements[n - 1 + 4] = parseFloat(line.substr(33, 10));
matrix.elements[n - 1 + 8] = parseFloat(line.substr(43, 10));
matrix.elements[n - 1 + 12] = parseFloat(line.substr(53));
matrix.elements[n - 1] = parseFloat(line.substring(23, 10));
matrix.elements[n - 1 + 4] = parseFloat(line.substring(33, 10));
matrix.elements[n - 1 + 8] = parseFloat(line.substring(43, 10));
matrix.elements[n - 1 + 12] = parseFloat(line.substring(53));
i++;
} else {
while (line.substr(13, 5) == "BIOMT") {
while (line.substring(13, 5) == "BIOMT") {
i++;
line = lines[i].replace(/^\s*/, "");
}
Expand All @@ -199,13 +199,13 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
modelData.symmetries.push(matrix);
i--; // set i back
} else if (recordName == "CRYST1") {
let a, b, c, alpha, beta, gamma;
a = parseFloat(line.substr(7, 8));
b = parseFloat(line.substr(16, 8));
c = parseFloat(line.substr(25, 8));
alpha = parseFloat(line.substr(34, 6));
beta = parseFloat(line.substr(41, 6));
gamma = parseFloat(line.substr(48, 6));
let a: number, b: number, c: number, alpha: number, beta: number, gamma: number;
a = parseFloat(line.substring(7, 8));
b = parseFloat(line.substring(16, 8));
c = parseFloat(line.substring(25, 8));
alpha = parseFloat(line.substring(34, 6));
beta = parseFloat(line.substring(41, 6));
gamma = parseFloat(line.substring(48, 6));
modelData.cryst = {
a: a,
b: b,
Expand All @@ -215,11 +215,11 @@ export function getSinglePDB(lines: any[], options: ParserOptionsSpec, sslookup:
gamma: gamma,
};
} else if (recordName == "ANISOU") {
let serial = parseInt(line.substr(6, 5));
let serial = parseInt(line.substring(6, 5));
var anisouAtomIndex = serialToIndex[serial];
var anisouAtom = atoms[anisouAtomIndex];
if (anisouAtom) {
var vals = line.substr(30).trim().split(/\s+/);
var vals = line.substring(30).trim().split(/\s+/);
var uMat = {
u11: parseInt(vals[0]),
u22: parseInt(vals[1]),
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/utils/isEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function isEmpty(obj: { [x: string]: { [x: string]: any; }; hasOwnProperty?: any; }) {
var name;
var name: string;
for (name in obj) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/utils/processSymmetries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ 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: string | any[], atoms: any[], options: ParserOptionsSpec, cryst: { a: any; b: number; c: number; alpha: number; beta: number; gamma: number; }) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/utils/standardResidues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const standardResidues = new Set([
export const standardResidues: Set<string> = new Set([
"ABU",
"ACD",
"ALA",
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/utils/validateBonds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//make sure bonds are actually two way
export function validateBonds (atomsarray: string | any[], serialToIndex: number[]) {
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++) {
Expand Down

0 comments on commit 2a5c276

Please sign in to comment.