UNPKG

molstar

Version:

A comprehensive macromolecular library.

68 lines (67 loc) 2.4 kB
/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { StructureSelection } from '../selection'; import { none } from './generators'; import { HashSet } from '../../../../mol-data/generic'; import { Structure } from '../../structure'; export function merge(queries) { if (queries.length === 0) { return none; } else if (queries.length === 1) { return queries[0]; } return function (ctx) { var ret = StructureSelection.UniqueBuilder(ctx.inputStructure); var _loop_1 = function (i) { StructureSelection.forEach(queries[i](ctx), function (s, j) { ret.add(s); if (i % 100) ctx.throwIfTimedOut(); }); }; for (var i = 0; i < queries.length; i++) { _loop_1(i); } return ret.getSelection(); }; } export function intersect(queries) { if (queries.length === 0) { return none; } else if (queries.length === 1) { return queries[0]; } return function (ctx) { var selections = []; for (var i = 0; i < queries.length; i++) selections.push(queries[i](ctx)); var pivotIndex = 0, pivotLength = StructureSelection.structureCount(selections[0]); for (var i = 1; i < selections.length; i++) { var len = StructureSelection.structureCount(selections[i]); if (len < pivotLength) { pivotIndex = i; pivotLength = len; } } ctx.throwIfTimedOut(); var pivotSet = HashSet(function (s) { return s.hashCode; }, Structure.areUnitIdsAndIndicesEqual); StructureSelection.forEach(selections[pivotIndex], function (s) { return pivotSet.add(s); }); var ret = StructureSelection.UniqueBuilder(ctx.inputStructure); for (var pI = 0; pI < selections.length; pI++) { if (pI === pivotIndex) continue; StructureSelection.forEach(selections[pI], function (s) { if (pivotSet.has(s)) ret.add(s); }); ctx.throwIfTimedOut(); } return ret.getSelection(); }; } // TODO: distanceCluster