UNPKG

molstar

Version:

A comprehensive macromolecular library.

100 lines (99 loc) 4.57 kB
"use strict"; /** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Michal Malý <michal.maly@ibt.cas.cz> * @author Jiří Černý <jiri.cerny@ibt.cas.cz> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfalPyramidsIterator = void 0; var property_1 = require("./property"); var int_1 = require("../../../mol-data/int"); var structure_1 = require("../../../mol-model/structure"); var EmptyStepIndices = new Array(); function copyResidue(r) { return r ? { index: r.index, start: r.start, end: r.end } : void 0; } function getAtomIndex(loc, residue, names, altId) { for (var eI = residue.start; eI < residue.end; eI++) { loc.element = loc.unit.elements[eI]; var elName = structure_1.StructureProperties.atom.label_atom_id(loc); var elAltId = structure_1.StructureProperties.atom.label_alt_id(loc); if (names.includes(elName) && (elAltId === altId || elAltId.length === 0)) return loc.element; } return -1; } function getPyramid(loc, one, two, altIdOne, altIdTwo, confalScore, stepIdx) { var O3 = getAtomIndex(loc, one, ['O3\'', 'O3*'], altIdOne); var P = getAtomIndex(loc, two, ['P'], altIdTwo); var OP1 = getAtomIndex(loc, two, ['OP1'], altIdTwo); var OP2 = getAtomIndex(loc, two, ['OP2'], altIdTwo); var O5 = getAtomIndex(loc, two, ['O5\'', 'O5*'], altIdTwo); return { O3: O3, P: P, OP1: OP1, OP2: OP2, O5: O5, confalScore: confalScore, stepIdx: stepIdx }; } var ConfalPyramidsIterator = /** @class */ (function () { function ConfalPyramidsIterator(structure, unit) { this.chainIt = int_1.Segmentation.transientSegments(unit.model.atomicHierarchy.chainAtomSegments, unit.elements); this.residueIt = int_1.Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, unit.elements); var prop = property_1.ConfalPyramidsProvider.get(unit.model).value; this.data = prop === null || prop === void 0 ? void 0 : prop.data; if (this.chainIt.hasNext) { this.residueIt.setSegment(this.chainIt.move()); if (this.residueIt.hasNext) this.residueTwo = this.residueIt.move(); } this.loc = structure_1.StructureElement.Location.create(structure, unit, -1); } ConfalPyramidsIterator.prototype.getStepIndices = function (r) { var _a; this.loc.element = this.loc.unit.elements[r.start]; var modelIdx = structure_1.StructureProperties.unit.model_num(this.loc) - 1; var chainId = structure_1.StructureProperties.chain.auth_asym_id(this.loc); var seqId = structure_1.StructureProperties.residue.auth_seq_id(this.loc); var chains = this.data.mapping[modelIdx]; if (!chains) return EmptyStepIndices; var residues = chains.get(chainId); if (!residues) return EmptyStepIndices; return (_a = residues.get(seqId)) !== null && _a !== void 0 ? _a : EmptyStepIndices; }; ConfalPyramidsIterator.prototype.moveStep = function () { this.residueOne = copyResidue(this.residueTwo); this.residueTwo = copyResidue(this.residueIt.move()); return this.toPyramids(this.residueOne, this.residueTwo); }; ConfalPyramidsIterator.prototype.toPyramids = function (one, two) { var indices = this.getStepIndices(one); var points = []; for (var _i = 0, indices_1 = indices; _i < indices_1.length; _i++) { var idx = indices_1[_i]; var step = this.data.steps[idx]; points.push(getPyramid(this.loc, one, two, step.label_alt_id_1, step.label_alt_id_2, step.confal_score, idx)); } return points; }; Object.defineProperty(ConfalPyramidsIterator.prototype, "hasNext", { get: function () { if (!this.data) return false; return this.residueIt.hasNext ? true : this.chainIt.hasNext; }, enumerable: false, configurable: true }); ConfalPyramidsIterator.prototype.move = function () { if (this.residueIt.hasNext) { return this.moveStep(); } else { this.residueIt.setSegment(this.chainIt.move()); return this.moveStep(); } }; return ConfalPyramidsIterator; }()); exports.ConfalPyramidsIterator = ConfalPyramidsIterator;