UNPKG

molstar

Version:

A comprehensive macromolecular library.

107 lines 4.31 kB
/** * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { Segmentation } from '../../../mol-data/int/segmentation'; import { SortedRanges } from '../../../mol-data/int/sorted-ranges'; import { OrderedSet } from '../../../mol-data/int'; import { Vec3 } from '../../../mol-math/linear-algebra'; /** Usees same definition as GROMACS' helixorient */ export function calcHelixOrientation(model) { var _a = model.atomicConformation, x = _a.x, y = _a.y, z = _a.z; var _b = model.atomicHierarchy.derived.residue, polymerType = _b.polymerType, traceElementIndex = _b.traceElementIndex; var n = polymerType.length; var elements = OrderedSet.ofBounds(0, model.atomicConformation.atomId.rowCount); var polymerIt = SortedRanges.transientSegments(model.atomicRanges.polymerRanges, elements); var residueIt = Segmentation.transientSegments(model.atomicHierarchy.residueAtomSegments, elements); var centers = new Float32Array(n * 3); var axes = new Float32Array(n * 3); var i = 0; var j = -1; var s = -1; var a1 = Vec3(); var a2 = Vec3(); var a3 = Vec3(); var a4 = Vec3(); var r12 = Vec3(); var r23 = Vec3(); var r34 = Vec3(); var v1 = Vec3(); var v2 = Vec3(); var vt = Vec3(); var diff13 = Vec3(); var diff24 = Vec3(); var axis = Vec3(); var prevAxis = Vec3(); while (polymerIt.hasNext) { var ps = polymerIt.move(); residueIt.setSegment(ps); i = -1; s = -1; while (residueIt.hasNext) { i += 1; var index = residueIt.move().index; if (i === 0) s = index; j = (index - 2); var j3 = j * 3; Vec3.copy(a1, a2); Vec3.copy(a2, a3); Vec3.copy(a3, a4); var eI_1 = traceElementIndex[index]; Vec3.set(a4, x[eI_1], y[eI_1], z[eI_1]); if (i < 3) continue; Vec3.sub(r12, a2, a1); Vec3.sub(r23, a3, a2); Vec3.sub(r34, a4, a3); Vec3.sub(diff13, r12, r23); Vec3.sub(diff24, r23, r34); Vec3.cross(axis, diff13, diff24); Vec3.normalize(axis, axis); Vec3.toArray(axis, axes, j3); var tmp = Math.cos(Vec3.angle(diff13, diff24)); var diff13Length = Vec3.magnitude(diff13); var diff24Length = Vec3.magnitude(diff24); var r = (Math.sqrt(diff24Length * diff13Length) / // clamp, to avoid numerical instabilities for when // angle between diff13 and diff24 is close to 0 Math.max(2.0, 2.0 * (1.0 - tmp))); Vec3.scale(v1, diff13, r / diff13Length); Vec3.sub(v1, a2, v1); Vec3.toArray(v1, centers, j3); Vec3.scale(v2, diff24, r / diff24Length); Vec3.sub(v2, a3, v2); Vec3.toArray(v2, centers, j3 + 3); Vec3.copy(prevAxis, axis); } // calc axis as dir of second and third center pos // project first trace atom onto axis to get first center pos var s3 = s * 3; Vec3.fromArray(v1, centers, s3 + 3); Vec3.fromArray(v2, centers, s3 + 6); Vec3.normalize(axis, Vec3.sub(axis, v1, v2)); var sI = traceElementIndex[s]; Vec3.set(a1, x[sI], y[sI], z[sI]); Vec3.copy(vt, a1); Vec3.projectPointOnVector(vt, vt, axis, v1); Vec3.toArray(vt, centers, s3); // calc axis as dir of n-1 and n-2 center pos // project last traceAtom onto axis to get last center pos var e = j + 2; var e3 = e * 3; Vec3.fromArray(v1, centers, e3 - 3); Vec3.fromArray(v2, centers, e3 - 6); Vec3.normalize(axis, Vec3.sub(axis, v1, v2)); var eI = traceElementIndex[e]; Vec3.set(a1, x[eI], y[eI], z[eI]); Vec3.copy(vt, a1); Vec3.projectPointOnVector(vt, vt, axis, v1); Vec3.toArray(vt, centers, e3); } return { centers: centers }; } //# sourceMappingURL=helix-orientation.js.map