UNPKG

molstar

Version:

A comprehensive macromolecular library.

68 lines (67 loc) 3.32 kB
/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator } from "tslib"; import { createRangeArray, makeBuckets } from '../../../mol-data/util'; import { Column, Table } from '../../../mol-data/db'; import { arrayIsIdentity } from '../../../mol-util/array'; export function sortAtomSite(ctx, atom_site, start, end) { return __awaiter(this, void 0, void 0, function () { var indices, label_entity_id, label_asym_id, label_seq_id, entityBuckets, ei, _eI, chainBuckets, cI, _cI, aI; return __generator(this, function (_a) { switch (_a.label) { case 0: indices = createRangeArray(start, end - 1); label_entity_id = atom_site.label_entity_id, label_asym_id = atom_site.label_asym_id, label_seq_id = atom_site.label_seq_id; entityBuckets = makeBuckets(indices, label_entity_id.value); if (!ctx.shouldUpdate) return [3 /*break*/, 2]; return [4 /*yield*/, ctx.update()]; case 1: _a.sent(); _a.label = 2; case 2: ei = 0, _eI = entityBuckets.length - 1; _a.label = 3; case 3: if (!(ei < _eI)) return [3 /*break*/, 10]; chainBuckets = makeBuckets(indices, label_asym_id.value, { start: entityBuckets[ei], end: entityBuckets[ei + 1] }); cI = 0, _cI = chainBuckets.length - 1; _a.label = 4; case 4: if (!(cI < _cI)) return [3 /*break*/, 7]; aI = chainBuckets[cI]; // are we in HETATM territory? if (label_seq_id.valueKind(aI) !== 0 /* Column.ValueKind.Present */) return [3 /*break*/, 6]; makeBuckets(indices, label_seq_id.value, { sort: true, start: aI, end: chainBuckets[cI + 1] }); if (!ctx.shouldUpdate) return [3 /*break*/, 6]; return [4 /*yield*/, ctx.update()]; case 5: _a.sent(); _a.label = 6; case 6: cI++; return [3 /*break*/, 4]; case 7: if (!ctx.shouldUpdate) return [3 /*break*/, 9]; return [4 /*yield*/, ctx.update()]; case 8: _a.sent(); _a.label = 9; case 9: ei++; return [3 /*break*/, 3]; case 10: if (arrayIsIdentity(indices) && indices.length === atom_site._rowCount) { return [2 /*return*/, { atom_site: atom_site, sourceIndex: Column.ofIntArray(indices) }]; } return [2 /*return*/, { atom_site: Table.view(atom_site, atom_site._schema, indices), sourceIndex: Column.ofIntArray(indices) }]; } }); }); }