diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index 44e3ca0e63fb28239dce764d67538879d633180d..fd349d65ab14e94e4a0a0dd3775625a04d4e9329 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -261,8 +261,8 @@ namespace Canvas3D { if (oldRO) { if (!SetUtils.areEqual(newRO, oldRO)) { - for (const o of Array.from(newRO)) { if (!oldRO.has(o)) scene.add(o) } - for (const o of Array.from(oldRO)) { if (!newRO.has(o)) scene.remove(o) } + newRO.forEach(o => { if (!oldRO.has(o)) scene.add(o) }) + oldRO.forEach(o => { if (!newRO.has(o)) scene.remove(o) }) } } else { repr.renderObjects.forEach(o => scene.add(o)) diff --git a/src/mol-model-props/rcsb/util.ts b/src/mol-model-props/rcsb/util.ts index 695af4b1e46018c25784990a9668fee6acd8d5da..86b5855fd8317750aff6fef4ca91d8a54b4c3093 100644 --- a/src/mol-model-props/rcsb/util.ts +++ b/src/mol-model-props/rcsb/util.ts @@ -13,7 +13,7 @@ export function getAssemblyIds(units: ReadonlyArray<Unit>) { units.forEach(u => { if (u.conformation.operator.assembly) ids.add(u.conformation.operator.assembly.id) }) - return Array.from(ids) + return Array.from(ids.values()) } export function getSymmetrySelectParam(structure?: Structure) { diff --git a/src/mol-model/structure/model/types.ts b/src/mol-model/structure/model/types.ts index d591872740d6488e32cec8555d4be01390b25a69..d9f083413db7634beb079693f418b50d18ebeaa9 100644 --- a/src/mol-model/structure/model/types.ts +++ b/src/mol-model/structure/model/types.ts @@ -410,26 +410,26 @@ export function isProtein(moleculeType: MoleculeType) { * ) AS t1; */ export const IonNames = new Set([ - '118', '119', '1AL', '1CU', '2FK', '2HP', '2OF', '3CO', - '3MT', '3NI', '3OF', '3P8', '4MO', '4PU', '543', '6MO', 'ACT', 'AG', 'AL', - 'ALF', 'AM', 'ATH', 'AU', 'AU3', 'AUC', 'AZI', 'BA', 'BCT', 'BEF', 'BF4', 'BO4', - 'BR', 'BS3', 'BSY', 'CA', 'CAC', 'CD', 'CD1', 'CD3', 'CD5', 'CE', 'CHT', 'CL', - 'CO', 'CO3', 'CO5', 'CON', 'CR', 'CS', 'CSB', 'CU', 'CU1', 'CU3', 'CUA', 'CUZ', - 'CYN', 'DME', 'DMI', 'DSC', 'DTI', 'DY', 'E4N', 'EDR', 'EMC', 'ER3', 'EU', - 'EU3', 'F', 'FE', 'FE2', 'FPO', 'GA', 'GD3', 'GEP', 'HAI', 'HG', 'HGC', 'IN', - 'IOD', 'IR', 'IR3', 'IRI', 'IUM', 'K', 'KO4', 'LA', 'LCO', 'LCP', 'LI', 'LU', - 'MAC', 'MG', 'MH2', 'MH3', 'MLI', 'MLT', 'MMC', 'MN', 'MN3', 'MN5', 'MN6', - 'MO1', 'MO2', 'MO3', 'MO4', 'MO5', 'MO6', 'MOO', 'MOS', 'MOW', 'MW1', 'MW2', - 'MW3', 'NA', 'NA2', 'NA5', 'NA6', 'NAO', 'NAW', 'NCO', 'NET', 'NH4', 'NI', - 'NI1', 'NI2', 'NI3', 'NO2', 'NO3', 'NRU', 'O4M', 'OAA', 'OC1', 'OC2', 'OC3', - 'OC4', 'OC5', 'OC6', 'OC7', 'OC8', 'OCL', 'OCM', 'OCN', 'OCO', 'OF1', 'OF2', - 'OF3', 'OH', 'OS', 'OS4', 'OXL', 'PB', 'PBM', 'PD', 'PDV', 'PER', 'PI', 'PO3', - 'PO4', 'PR', 'PT', 'PT4', 'PTN', 'RB', 'RH3', 'RHD', 'RU', 'SB', 'SCN', 'SE4', - 'SEK', 'SM', 'SMO', 'SO3', 'SO4', 'SR', 'T1A', 'TB', 'TBA', 'TCN', 'TEA', 'TH', - 'THE', 'TL', 'TMA', 'TRA', 'UNX', 'V', 'VN3', 'VO4', 'W', 'WO5', 'Y1', 'YB', - 'YB2', 'YH', 'YT3', 'ZCM', 'ZN', 'ZN2', 'ZN3', 'ZNO', 'ZO3', + '118', '119', '1AL', '1CU', '2FK', '2HP', '2OF', '3CO', + '3MT', '3NI', '3OF', '3P8', '4MO', '4PU', '543', '6MO', 'ACT', 'AG', 'AL', + 'ALF', 'AM', 'ATH', 'AU', 'AU3', 'AUC', 'AZI', 'BA', 'BCT', 'BEF', 'BF4', 'BO4', + 'BR', 'BS3', 'BSY', 'CA', 'CAC', 'CD', 'CD1', 'CD3', 'CD5', 'CE', 'CHT', 'CL', + 'CO', 'CO3', 'CO5', 'CON', 'CR', 'CS', 'CSB', 'CU', 'CU1', 'CU3', 'CUA', 'CUZ', + 'CYN', 'DME', 'DMI', 'DSC', 'DTI', 'DY', 'E4N', 'EDR', 'EMC', 'ER3', 'EU', + 'EU3', 'F', 'FE', 'FE2', 'FPO', 'GA', 'GD3', 'GEP', 'HAI', 'HG', 'HGC', 'IN', + 'IOD', 'IR', 'IR3', 'IRI', 'IUM', 'K', 'KO4', 'LA', 'LCO', 'LCP', 'LI', 'LU', + 'MAC', 'MG', 'MH2', 'MH3', 'MLI', 'MLT', 'MMC', 'MN', 'MN3', 'MN5', 'MN6', + 'MO1', 'MO2', 'MO3', 'MO4', 'MO5', 'MO6', 'MOO', 'MOS', 'MOW', 'MW1', 'MW2', + 'MW3', 'NA', 'NA2', 'NA5', 'NA6', 'NAO', 'NAW', 'NCO', 'NET', 'NH4', 'NI', + 'NI1', 'NI2', 'NI3', 'NO2', 'NO3', 'NRU', 'O4M', 'OAA', 'OC1', 'OC2', 'OC3', + 'OC4', 'OC5', 'OC6', 'OC7', 'OC8', 'OCL', 'OCM', 'OCN', 'OCO', 'OF1', 'OF2', + 'OF3', 'OH', 'OS', 'OS4', 'OXL', 'PB', 'PBM', 'PD', 'PDV', 'PER', 'PI', 'PO3', + 'PO4', 'PR', 'PT', 'PT4', 'PTN', 'RB', 'RH3', 'RHD', 'RU', 'SB', 'SCN', 'SE4', + 'SEK', 'SM', 'SMO', 'SO3', 'SO4', 'SR', 'T1A', 'TB', 'TBA', 'TCN', 'TEA', 'TH', + 'THE', 'TL', 'TMA', 'TRA', 'UNX', 'V', 'VN3', 'VO4', 'W', 'WO5', 'Y1', 'YB', + 'YB2', 'YH', 'YT3', 'ZCM', 'ZN', 'ZN2', 'ZN3', 'ZNO', 'ZO3', // additional ion names - 'OHX' + 'OHX' ]) export type SecondaryStructureType = BitFlags<SecondaryStructureType.Flag> diff --git a/src/mol-plugin/state/actions/data-format.ts b/src/mol-plugin/state/actions/data-format.ts index 1c841267faca1be3c13412398d5607fb00b48100..0eb77a0e7e8baf2099b2e656e27c63fcde7c860c 100644 --- a/src/mol-plugin/state/actions/data-format.ts +++ b/src/mol-plugin/state/actions/data-format.ts @@ -125,7 +125,7 @@ export const OpenFile = StateAction.build({ params: (a, ctx: PluginContext) => { const { extensions, options } = ctx.dataFormat.registry return { - file: PD.File({ accept: Array.from(extensions).map(e => `.${e}`).join(',')}), + file: PD.File({ accept: Array.from(extensions.values()).map(e => `.${e}`).join(',')}), format: PD.Select('auto', options), visuals: PD.Boolean(true, { description: 'Add default visuals' }), } diff --git a/src/mol-plugin/util/structure-selection-helper.ts b/src/mol-plugin/util/structure-selection-helper.ts index 0c8f3916a8e8fd88805e5e57adda3721106eef50..e8b3c455305d0d85a04cb3d7f407d91abae352f2 100644 --- a/src/mol-plugin/util/structure-selection-helper.ts +++ b/src/mol-plugin/util/structure-selection-helper.ts @@ -68,7 +68,7 @@ const backbone = StructureSelectionQuery('Backbone', MS.struct.modifier.union([ ]) ]), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), - 'atom-test': MS.core.set.has([MS.set(...Array.from(ProteinBackboneAtoms)), MS.ammp('label_atom_id')]) + 'atom-test': MS.core.set.has([MS.set(...Array.from(ProteinBackboneAtoms.values())), MS.ammp('label_atom_id')]) }) ]), MS.struct.modifier.union([ @@ -81,7 +81,7 @@ const backbone = StructureSelectionQuery('Backbone', MS.struct.modifier.union([ ]) ]), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), - 'atom-test': MS.core.set.has([MS.set(...Array.from(NucleicBackboneAtoms)), MS.ammp('label_atom_id')]) + 'atom-test': MS.core.set.has([MS.set(...Array.from(NucleicBackboneAtoms.values())), MS.ammp('label_atom_id')]) }) ]) ]) diff --git a/src/mol-plugin/util/viewport-screenshot.ts b/src/mol-plugin/util/viewport-screenshot.ts index be05711c5863eba48dd1b1abd030b8e1e3e2416e..eae9094d3f96790eebc2ba902775bc52355176bd 100644 --- a/src/mol-plugin/util/viewport-screenshot.ts +++ b/src/mol-plugin/util/viewport-screenshot.ts @@ -102,7 +102,7 @@ class ViewportScreenshotHelper { const models = this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Model)).map(s => s.obj!.data) const uniqueIds = new Set<string>() models.forEach(m => uniqueIds.add(m.entryId.toUpperCase())) - const idString = Array.from(uniqueIds).join('-') + const idString = Array.from(uniqueIds.values()).join('-') return `${idString || 'molstar-image'}.png` } diff --git a/src/mol-theme/color/operator-hkl.ts b/src/mol-theme/color/operator-hkl.ts index 1a531fa8a5bad1876b7d16aa9b13ca0203517dc3..2469356eaa12799c0496bf2f27cad96a04184311 100644 --- a/src/mol-theme/color/operator-hkl.ts +++ b/src/mol-theme/color/operator-hkl.ts @@ -63,7 +63,7 @@ function getOperatorHklSerialMap(structure: Structure) { const k = hklKey(structure.units[i].conformation.operator.hkl) set.add(k) } - const arr = Array.from(set).sort() + const arr = Array.from(set.values()).sort() arr.forEach(k => map.set(k, map.size)) const min = hklKeySplit(arr[0]) const max = hklKeySplit(arr[arr.length - 1]) diff --git a/src/mol-util/polyfill.ts b/src/mol-util/polyfill.ts index 85b2831888894850342755c33344879e80817141..403cf6b4763c6c08161dc966f6320f5c946fd828 100644 --- a/src/mol-util/polyfill.ts +++ b/src/mol-util/polyfill.ts @@ -592,4 +592,104 @@ if (!Array.prototype.fill) { return O; } }); +} + +if (!Array.prototype.copyWithin) { + Object.defineProperty(Array.prototype, 'copyWithin', { + value: function(target: any, start: any/* , end*/) { + // Steps 1-2. + if (this == null) { + throw new TypeError('this is null or not defined'); + } + + let O = Object(this); + + // Steps 3-5. + let len = O.length >>> 0; + + // Steps 6-8. + let relativeTarget = target >> 0; + + let to = relativeTarget < 0 ? + Math.max(len + relativeTarget, 0) : + Math.min(relativeTarget, len); + + // Steps 9-11. + let relativeStart = start >> 0; + + let from = relativeStart < 0 ? + Math.max(len + relativeStart, 0) : + Math.min(relativeStart, len); + + // Steps 12-14. + let end = arguments[2]; + let relativeEnd = end === undefined ? len : end >> 0; + + let final = relativeEnd < 0 ? + Math.max(len + relativeEnd, 0) : + Math.min(relativeEnd, len); + + // Step 15. + let count = Math.min(final - from, len - to); + + // Steps 16-17. + let direction = 1; + + if (from < to && to < (from + count)) { + direction = -1; + from += count - 1; + to += count - 1; + } + + // Step 18. + while (count > 0) { + if (from in O) { + O[to] = O[from]; + } else { + delete O[to]; + } + + from += direction; + to += direction; + count--; + } + + // Step 19. + return O; + }, + configurable: true, + writable: true + }); +} + +if (!Int8Array.prototype.copyWithin) { + Object.defineProperty(Int8Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Int16Array.prototype.copyWithin) { + Object.defineProperty(Int16Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Int32Array.prototype.copyWithin) { + Object.defineProperty(Int32Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Uint8Array.prototype.copyWithin) { + Object.defineProperty(Uint8Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Uint16Array.prototype.copyWithin) { + Object.defineProperty(Uint16Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Uint32Array.prototype.copyWithin) { + Object.defineProperty(Uint32Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Float32Array.prototype.copyWithin) { + Object.defineProperty(Float32Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) +} + +if (!Float64Array.prototype.copyWithin) { + Object.defineProperty(Float64Array.prototype, 'copyWithin', { value: Array.prototype.copyWithin }) } \ No newline at end of file diff --git a/src/mol-util/set.ts b/src/mol-util/set.ts index bc5de1879a0ebf7006cd962dc16fe06dd017c2b1..25114f787f1df08d836f969726272cc95d4f13e0 100644 --- a/src/mol-util/set.ts +++ b/src/mol-util/set.ts @@ -1,24 +1,25 @@ /** - * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -// TODO remove Array.from workaround when targeting ES6 +// TODO use set@@iterator when targeting es6 export namespace SetUtils { /** Test if set a contains all elements of set b. */ export function isSuperset<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>) { - for (const elm of Array.from(setB)) { - if (!setA.has(elm)) return false; - } - return true; + let flag = true + setB.forEach(elem => { + if (!setA.has(elem)) flag = false; + }) + return flag } /** Add all elements from `sets` to `out` */ export function add<T>(out: Set<T>, ...sets: ReadonlySet<T>[]): Set<T> { for (let i = 0; i < sets.length; i++) { - for (const elem of Array.from(sets[i])) out.add(elem); + sets[i].forEach(elem => out.add(elem)) } return out; } @@ -26,7 +27,7 @@ export namespace SetUtils { /** Create set containing elements of both set a and set b. */ export function union<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): Set<T> { const union = new Set(setA); - for (const elem of Array.from(setB)) union.add(elem); + setB.forEach(elem => union.add(elem)) return union; } @@ -34,8 +35,8 @@ export namespace SetUtils { if (sets.length === 0) return new Set<T>(); if (sets.length === 1) new Set(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); + for (let i = 1, il = sets.length; i < il; i++) { + sets[i].forEach(elem => union.add(elem)) } return union; } @@ -52,32 +53,34 @@ export namespace SetUtils { /** Create set containing elements of set a that are also in set b. */ export function intersection<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): Set<T> { const intersection = new Set<T>(); - for (const elem of Array.from(setB)) { + setB.forEach(elem => { if (setA.has(elem)) intersection.add(elem); - } + }) return intersection; } export function areIntersecting<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): boolean { - for (const elem of Array.from(setB)) { - if (setA.has(elem)) return true; - } - return false; + let flag = false + setB.forEach(elem => { + if (setA.has(elem)) flag = true; + }) + return flag; } /** Create set containing elements of set a that are not in set b. */ export function difference<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): Set<T> { const difference = new Set(setA); - for (const elem of Array.from(setB)) difference.delete(elem); + setB.forEach(elem => difference.delete(elem)) return difference; } /** Test if set a and b contain the same elements. */ export function areEqual<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>) { if (setA.size !== setB.size) return false - for (const elm of Array.from(setB)) { - if (!setA.has(elm)) return false; - } - return true; + let flag = true + setB.forEach(elem => { + if (!setA.has(elem)) flag = false; + }) + return flag; } } \ No newline at end of file