molstar
Version:
A comprehensive macromolecular library.
68 lines (67 loc) • 4.07 kB
JavaScript
"use strict";
/**
* Copyright (c) 2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Adam Midlik <midlik@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementSet = exports.SelectorAll = exports.SelectorParams = exports.StaticSelectorChoice = void 0;
exports.isSelectorAll = isSelectorAll;
exports.substructureFromSelector = substructureFromSelector;
const int_1 = require("../../../mol-data/int.js");
const structure_1 = require("../../../mol-model/structure.js");
const structure_component_1 = require("../../../mol-plugin-state/helpers/structure-component.js");
const objects_1 = require("../../../mol-plugin-state/objects.js");
const builder_1 = require("../../../mol-script/language/builder.js");
const object_1 = require("../../../mol-util/object.js");
const param_choice_1 = require("../../../mol-util/param-choice.js");
const param_definition_1 = require("../../../mol-util/param-definition.js");
const string_1 = require("../../../mol-util/string.js");
const annotation_structure_component_1 = require("./annotation-structure-component.js");
/** Allowed values for a static selector */
exports.StaticSelectorChoice = new param_choice_1.Choice((0, object_1.mapArrayToObject)(structure_component_1.StaticStructureComponentTypes, t => (0, string_1.capitalize)(t)), 'all');
/** Parameter definition for specifying a part of structure (kinda extension of `StructureComponentParams` from mol-plugin-state/helpers/structure-component) */
exports.SelectorParams = param_definition_1.ParamDefinition.MappedStatic('static', {
static: exports.StaticSelectorChoice.PDSelect(),
expression: param_definition_1.ParamDefinition.Value(builder_1.MolScriptBuilder.struct.generator.all),
bundle: param_definition_1.ParamDefinition.Value(structure_1.StructureElement.Bundle.Empty),
script: param_definition_1.ParamDefinition.Script({ language: 'mol-script', expression: '(sel.atom.all)' }),
annotation: param_definition_1.ParamDefinition.Group((0, object_1.pickObjectKeys)(annotation_structure_component_1.MVSAnnotationStructureComponentParams, ['annotationId', 'fieldName', 'fieldValues'])),
}, { description: 'Define a part of the structure where this layer applies (use Static:all to apply to the whole structure)' });
/** `Selector` for selecting the whole structure */
exports.SelectorAll = { name: 'static', params: 'all' };
/** Decide whether a selector is `SelectorAll` */
function isSelectorAll(props) {
return props.name === 'static' && props.params === 'all';
}
exports.ElementSet = {
/** Create an `ElementSet` from a structure */
fromStructure(structure) {
if (!structure)
return {};
const out = {};
for (const unit of structure.units) {
out[unit.id] = unit.elements;
}
return out;
},
/** Create an `ElementSet` from the substructure of `structure` defined by `selector` */
fromSelector(structure, selector) {
if (!structure)
return {};
const selection = substructureFromSelector(structure, selector); // using `getAtomRangesForRow` might (might not) be faster here
return this.fromStructure(selection);
},
/** Decide if the element set `set` contains structure element location `location` */
has(set, location) {
const array = set[location.unit.id];
return array ? int_1.SortedArray.has(array, location.element) : false;
},
};
/** Return a substructure of `structure` defined by `selector` */
function substructureFromSelector(structure, selector) {
const pso = (selector.name === 'annotation') ?
(0, annotation_structure_component_1.createMVSAnnotationStructureComponent)(structure, { ...selector.params, label: '', nullIfEmpty: false })
: (0, structure_component_1.createStructureComponent)(structure, { type: selector, label: '', nullIfEmpty: false }, { source: structure });
return objects_1.PluginStateObject.Molecule.Structure.is(pso) ? pso.data : structure_1.Structure.Empty;
}