diff --git a/src/apps/chem-comp-bond/create-table.ts b/src/apps/chem-comp-bond/create-table.ts index c30bc04b270c127e4d37eeb58e4e83b80a34d55c..28dc5000fc972af9ced1ef12f1205c068006eaf4 100644 --- a/src/apps/chem-comp-bond/create-table.ts +++ b/src/apps/chem-comp-bond/create-table.ts @@ -19,7 +19,7 @@ import { Database, Table, DatabaseCollection, Column } from 'mol-data/db' import CIF from 'mol-io/reader/cif' import { CifWriter } from 'mol-io/writer/cif' import { CCD_Schema } from 'mol-io/reader/cif/schema/ccd' -import { difference } from 'mol-util/set' +import { SetUtils } from 'mol-util/set' import { DefaultMap } from 'mol-util/map' export async function ensureAvailable(path: string, url: string) { @@ -130,7 +130,7 @@ function checkAddingBondsFromPVCD(pvcd: DatabaseCollection<CCD_Schema>) { for (let i = 0, il = parentIds.length; i < il; ++i) { const entryBonds = addChemCompBondToSet(new Set<string>(), chem_comp_bond) const entryAtoms = addChemCompAtomToSet(new Set<string>(), chem_comp_atom) - const extraBonds = difference(ccbSetByParent.get(parentIds[i])!, entryBonds) + const extraBonds = SetUtils.difference(ccbSetByParent.get(parentIds[i])!, entryBonds) extraBonds.forEach(bk => { const [a1, a2] = bk.split('|') if (entryAtoms.has(a1) && entryAtoms.has(a2)) { diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index 814503272e6f6c3da610e6a438bb32c977a343a6..60b32ca19a5f47b6722835559ebc74ec69a4e151 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -9,7 +9,7 @@ import { now } from 'mol-util/now'; import { Vec3 } from 'mol-math/linear-algebra' import InputObserver from 'mol-util/input/input-observer' -import * as SetUtils from 'mol-util/set' +import { SetUtils } from 'mol-util/set' import Renderer, { RendererStats } from 'mol-gl/renderer' import { RenderObject } from 'mol-gl/render-object' diff --git a/src/mol-model/structure/export/categories/utils.ts b/src/mol-model/structure/export/categories/utils.ts index d0a63367f8a4a3c7e472b6feaed0ff32316a4beb..17869c5f15547791e4fc967ef6aff51877382b17 100644 --- a/src/mol-model/structure/export/categories/utils.ts +++ b/src/mol-model/structure/export/categories/utils.ts @@ -5,7 +5,7 @@ */ import { mmCIF_Database, mmCIF_Schema } from 'mol-io/reader/cif/schema/mmcif'; -import { unionMany } from 'mol-util/set'; +import { SetUtils } from 'mol-util/set'; import { Model } from '../../model'; import { Structure } from '../../structure'; import { EntityIndex } from '../../model/indexing'; @@ -20,7 +20,7 @@ export function getModelMmCifCategory<K extends keyof mmCIF_Schema>(model: Model } export function getUniqueResidueNamesFromStructures(structures: Structure[]) { - return unionMany(structures.map(s => s.uniqueResidueNames)); + return SetUtils.unionMany(structures.map(s => s.uniqueResidueNames)); } export function getUniqueEntityIdsFromStructures(structures: Structure[]): Set<string> { diff --git a/src/mol-model/structure/query/queries/filters.ts b/src/mol-model/structure/query/queries/filters.ts index 94aad107edce7c291256d06d021d5792cb5b16a6..a64cffc38bf15eae0a037b80153a2ac03b8d6fd4 100644 --- a/src/mol-model/structure/query/queries/filters.ts +++ b/src/mol-model/structure/query/queries/filters.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { isSuperset } from 'mol-util/set'; +import { SetUtils } from 'mol-util/set'; import { Unit } from '../../structure'; import { QueryContext, QueryFn, QueryPredicate } from '../context'; import { StructureQuery } from '../query'; @@ -82,7 +82,7 @@ export function withSameAtomProperties(query: StructureQuery, propertySource: St StructureSelection.forEach(sel, (s, i) => { ctx.currentStructure = s; const currentProps = getCurrentStructureProperties(ctx, props, new Set()); - if (isSuperset(currentProps, propSet)) { + if (SetUtils.isSuperset(currentProps, propSet)) { ret.add(s); } diff --git a/src/mol-script/runtime/query/table.ts b/src/mol-script/runtime/query/table.ts index 9782aeb137c4678dd5024e8db8076b34043a6f71..6a4d2be3f2910763ef0ac73bba9fe56d352ee851 100644 --- a/src/mol-script/runtime/query/table.ts +++ b/src/mol-script/runtime/query/table.ts @@ -8,7 +8,7 @@ import { MolScriptSymbolTable as MolScript } from '../../language/symbol-table'; import { DefaultQueryRuntimeTable, QuerySymbolRuntime, QueryRuntimeArguments } from './compiler'; import { Queries, StructureProperties, StructureElement, QueryContext } from 'mol-model/structure'; import { ElementSymbol } from 'mol-model/structure/model/types'; -import { isSuperset } from 'mol-util/set'; +import { SetUtils } from 'mol-util/set'; import toUpperCase from 'mol-util/upper-case'; import { VdwRadius, AtomWeight, AtomNumber } from 'mol-model/structure/model/properties/atomic'; import { cantorPairing } from 'mol-data/util'; @@ -150,7 +150,7 @@ const symbols = [ // ============= SET ================ C(MolScript.core.set.has, (ctx, v) => v[0](ctx).has(v[1](ctx))), - C(MolScript.core.set.isSubset, (ctx, v) => isSuperset(v[1](ctx) as Set<any>, v[0](ctx) as Set<any>)), + C(MolScript.core.set.isSubset, (ctx, v) => SetUtils.isSuperset(v[1](ctx) as Set<any>, v[0](ctx) as Set<any>)), // ============= FLAGS ================ C(MolScript.core.flags.hasAny, (ctx, v) => { diff --git a/src/mol-util/set.ts b/src/mol-util/set.ts index 7bc7e10d46c2d4b3937b2c41669680a30cac7bed..34a79112f02b0d3afd5f86a440fd0ade65fa1709 100644 --- a/src/mol-util/set.ts +++ b/src/mol-util/set.ts @@ -6,52 +6,63 @@ // TODO remove Array.from workaround when targeting ES6 -/** Test if set a contains all elements of set b. */ -export function isSuperset<T>(setA: Set<T>, setB: Set<T>) { - for (const elm of Array.from(setB)) { - if (!setA.has(elm)) return false; +export namespace SetUtils { + /** Test if set a contains all elements of set b. */ + export function isSuperset<T>(setA: Set<T>, setB: Set<T>) { + for (const elm of Array.from(setB)) { + if (!setA.has(elm)) return false; + } + return true; } - return true; -} - -/** Create set containing elements of both set a and set b. */ -export function union<T>(setA: Set<T>, setB: Set<T>): Set<T> { - const union = new Set(setA); - for (const elem of Array.from(setB)) union.add(elem); - return union; -} - -export function unionMany<T>(sets: Set<T>[]) { - if (sets.length === 0) return new Set<T>(); - if (sets.length === 1) return sets[0]; - const union = new Set(sets[0]); - for (let i = 1; i < sets.length; i++) { - for (const elem of Array.from(sets[i])) union.add(elem); + + /** Create set containing elements of both set a and set b. */ + export function union<T>(setA: Set<T>, setB: Set<T>): Set<T> { + const union = new Set(setA); + for (const elem of Array.from(setB)) union.add(elem); + return union; } - return union; -} - -export function unionManyArrays<T>(arrays: T[][]) { - if (arrays.length === 0) return new Set<T>(); - const union = new Set(arrays[0]); - for (let i = 1; i < arrays.length; i++) { - for (const elem of arrays[i]) union.add(elem); + + export function unionMany<T>(sets: Set<T>[]) { + if (sets.length === 0) return new Set<T>(); + if (sets.length === 1) return sets[0]; + const union = new Set(sets[0]); + for (let i = 1; i < sets.length; i++) { + for (const elem of Array.from(sets[i])) union.add(elem); + } + return union; } - return union; -} - -/** Create set containing elements of set a that are also in set b. */ -export function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> { - const intersection = new Set(); - for (const elem of Array.from(setB)) { - if (setA.has(elem)) intersection.add(elem); + + export function unionManyArrays<T>(arrays: T[][]) { + if (arrays.length === 0) return new Set<T>(); + const union = new Set(arrays[0]); + for (let i = 1; i < arrays.length; i++) { + for (const elem of arrays[i]) union.add(elem); + } + return union; + } + + /** Create set containing elements of set a that are also in set b. */ + export function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> { + const intersection = new Set(); + for (const elem of Array.from(setB)) { + if (setA.has(elem)) intersection.add(elem); + } + return intersection; + } + + /** Create set containing elements of set a that are not in set b. */ + export function difference<T>(setA: Set<T>, setB: Set<T>): Set<T> { + const difference = new Set(setA); + for (const elem of Array.from(setB)) difference.delete(elem); + return difference; + } + + /** Test if set a and b contain the same elements. */ + export function areEqual<T>(setA: Set<T>, setB: Set<T>) { + if (setA.size !== setB.size) return false + for (const elm of Array.from(setB)) { + if (!setA.has(elm)) return false; + } + return true; } - return intersection; -} - -/** Create set containing elements of set a that are not in set b. */ -export function difference<T>(setA: Set<T>, setB: Set<T>): Set<T> { - const difference = new Set(setA); - for (const elem of Array.from(setB)) difference.delete(elem); - return difference; } \ No newline at end of file