UNPKG

molstar

Version:

A comprehensive macromolecular library.

114 lines 4.24 kB
/** * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Fred Ludlow <Fred.Ludlow@astx.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { degToRad } from '../../../mol-math/misc'; import { Vec3 } from '../../../mol-math/linear-algebra'; import { eachBondedAtom, typeSymbol } from './util'; export function geometryLabel(geometry) { switch (geometry) { case 0 /* Spherical */: return 'Spherical'; case 1 /* Terminal */: return 'Terminal'; case 2 /* Linear */: return 'Linear'; case 3 /* Trigonal */: return 'Trigonal'; case 4 /* Tetrahedral */: return 'Tetrahedral'; case 5 /* TrigonalBiPyramidal */: return 'Trigonal Bi-Pyramidal'; case 6 /* Octahedral */: return 'Octahedral'; case 7 /* SquarePlanar */: return 'Square Planar'; case 8 /* Unknown */: return 'Unknown'; } } export function assignGeometry(totalCoordination) { switch (totalCoordination) { case 0: return 0 /* Spherical */; case 1: return 1 /* Terminal */; case 2: return 2 /* Linear */; case 3: return 3 /* Trigonal */; case 4: return 4 /* Tetrahedral */; default: return 8 /* Unknown */; } } export var AtomGeometryAngles = new Map([ [2 /* Linear */, degToRad(180)], [3 /* Trigonal */, degToRad(120)], [4 /* Tetrahedral */, degToRad(109.4721)], [6 /* Octahedral */, degToRad(90)] ]); // tmp objects for `calcAngles` and `calcPlaneAngle` var tmpDir1 = Vec3(); var tmpDir2 = Vec3(); var tmpPosA = Vec3(); var tmpPosB = Vec3(); var tmpPosX = Vec3(); /** * Calculate the angles x-a1-a2 for all x where x is a heavy atom (not H) bonded to ap1. */ export function calcAngles(structure, unitA, indexA, unitB, indexB) { var angles = []; unitA.conformation.position(unitA.elements[indexA], tmpPosA); unitB.conformation.position(unitB.elements[indexB], tmpPosB); Vec3.sub(tmpDir1, tmpPosB, tmpPosA); eachBondedAtom(structure, unitA, indexA, function (unitX, indexX) { if (typeSymbol(unitX, indexX) !== "H" /* H */) { unitX.conformation.position(unitX.elements[indexX], tmpPosX); Vec3.sub(tmpDir2, tmpPosX, tmpPosA); angles.push(Vec3.angle(tmpDir1, tmpDir2)); } }); return angles; } /** * Find two neighbours of ap1 to define a plane (if possible) and * measure angle out of plane to ap2 * @param {AtomProxy} ap1 First atom (angle centre) * @param {AtomProxy} ap2 Second atom (out-of-plane) * @return {number} Angle from plane to second atom */ export function calcPlaneAngle(structure, unitA, indexA, unitB, indexB) { unitA.conformation.position(unitA.elements[indexA], tmpPosA); unitB.conformation.position(unitB.elements[indexB], tmpPosB); Vec3.sub(tmpDir1, tmpPosB, tmpPosA); var neighbours = [Vec3(), Vec3()]; var ni = 0; var unitX1; var indexX1; eachBondedAtom(structure, unitA, indexA, function (unitX, indexX) { if (ni > 1) return; if (typeSymbol(unitX, indexX) !== "H" /* H */) { unitX1 = unitX; indexX1 = indexX; unitX.conformation.position(unitX.elements[indexX], tmpPosX); Vec3.sub(neighbours[ni++], tmpPosX, tmpPosA); } }); if (ni === 1 && unitX1 && indexX1) { eachBondedAtom(structure, unitX1, indexX1, function (unitX, indexX) { if (ni > 1) return; if (unitX === unitA && indexX === indexA) return; if (typeSymbol(unitX, indexX) !== "H" /* H */) { unitX.conformation.position(unitX.elements[indexX], tmpPosX); Vec3.sub(neighbours[ni++], tmpPosX, tmpPosA); } }); } if (ni !== 2) { return; } Vec3.cross(tmpDir2, neighbours[0], neighbours[1]); return Math.abs((Math.PI / 2) - Vec3.angle(tmpDir2, tmpDir1)); } //# sourceMappingURL=geometry.js.map