UNPKG

molstar

Version:

A comprehensive macromolecular library.

713 lines (712 loc) 33.3 kB
/** * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator, __spreadArray } from "tslib"; import { QueryContext, StructureSelection, StructureProperties, StructureElement } from '../../mol-model/structure'; import { NucleicBackboneAtoms, ProteinBackboneAtoms, AminoAcidNamesL, RnaBaseNames, DnaBaseNames, WaterNames, PolymerNames } from '../../mol-model/structure/model/types'; import { MolScriptBuilder as MS } from '../../mol-script/language/builder'; import { compile } from '../../mol-script/runtime/query/compiler'; import { SetUtils } from '../../mol-util/set'; import { StateTransforms } from '../transforms'; import { ElementNames } from '../../mol-model/structure/model/properties/atomic/types'; import { SecondaryStructureProvider } from '../../mol-model-props/computed/secondary-structure'; export var StructureSelectionCategory; (function (StructureSelectionCategory) { StructureSelectionCategory["Type"] = "Type"; StructureSelectionCategory["Structure"] = "Structure Property"; StructureSelectionCategory["Atom"] = "Atom Property"; StructureSelectionCategory["Bond"] = "Bond Property"; StructureSelectionCategory["Residue"] = "Residue Property"; StructureSelectionCategory["AminoAcid"] = "Amino Acid"; StructureSelectionCategory["NucleicBase"] = "Nucleic Base"; StructureSelectionCategory["Manipulate"] = "Manipulate Selection"; StructureSelectionCategory["Validation"] = "Validation"; StructureSelectionCategory["Misc"] = "Miscellaneous"; StructureSelectionCategory["Internal"] = "Internal"; })(StructureSelectionCategory || (StructureSelectionCategory = {})); export { StructureSelectionQuery }; function StructureSelectionQuery(label, expression, props) { var _a; if (props === void 0) { props = {}; } var _query; return { label: label, expression: expression, description: props.description || '', category: (_a = props.category) !== null && _a !== void 0 ? _a : StructureSelectionCategory.Misc, isHidden: !!props.isHidden, priority: props.priority || 0, referencesCurrent: !!props.referencesCurrent, get query() { if (!_query) _query = compile(expression); return _query; }, ensureCustomProperties: props.ensureCustomProperties, getSelection: function (plugin, runtime, structure) { return __awaiter(this, void 0, void 0, function () { var current, currentSelection; return __generator(this, function (_a) { switch (_a.label) { case 0: current = plugin.managers.structure.selection.getStructure(structure); currentSelection = current ? StructureSelection.Sequence(structure, [current]) : StructureSelection.Empty(structure); if (!props.ensureCustomProperties) return [3 /*break*/, 2]; return [4 /*yield*/, props.ensureCustomProperties({ runtime: runtime, assetManager: plugin.managers.asset }, structure)]; case 1: _a.sent(); _a.label = 2; case 2: if (!_query) _query = compile(expression); return [2 /*return*/, _query(new QueryContext(structure, { currentSelection: currentSelection }))]; } }); }); } }; } var all = StructureSelectionQuery('All', MS.struct.generator.all(), { category: '', priority: 1000 }); var current = StructureSelectionQuery('Current Selection', MS.internal.generator.current(), { category: '', referencesCurrent: true }); var polymer = StructureSelectionQuery('Polymer', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.logic.and([ MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), MS.core.str.match([ MS.re('(polypeptide|cyclic-pseudo-peptide|peptide-like|nucleotide|peptide nucleic acid)', 'i'), MS.ammp('entitySubtype') ]) ]) }) ]), { category: StructureSelectionCategory.Type }); var trace = StructureSelectionQuery('Trace', MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), 'chain-test': MS.core.set.has([ MS.set('sphere', 'gaussian'), MS.ammp('objectPrimitive') ]) }) ]), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'atom-test': MS.core.set.has([MS.set('CA', 'P'), MS.ammp('label_atom_id')]) }) ]) ]) ]), { category: StructureSelectionCategory.Structure }); var _proteinEntityTest = MS.core.logic.and([ MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), MS.core.str.match([ MS.re('(polypeptide|cyclic-pseudo-peptide|peptide-like)', 'i'), MS.ammp('entitySubtype') ]) ]); var _nucleiEntityTest = MS.core.logic.and([ MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), MS.core.str.match([ MS.re('(nucleotide|peptide nucleic acid)', 'i'), MS.ammp('entitySubtype') ]) ]); /** * this is to get non-polymer and peptide terminus components in polymer entities, * - non-polymer, e.g. PXZ in 4HIV or generally ACE * - carboxy terminus, e.g. FC0 in 4BP9, or ETA in 6DDE * - amino terminus, e.g. ARF in 3K4V, or 4MM in 3EGV */ var _nonPolymerResidueTest = MS.core.str.match([ MS.re('non-polymer|(amino|carboxy) terminus|peptide-like', 'i'), MS.ammp('chemCompType') ]); // TODO maybe pre-calculate backbone atom properties var backbone = StructureSelectionQuery('Backbone', MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(ProteinBackboneAtoms)), MS.ammp('label_atom_id')]) }) ]), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _nucleiEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(NucleicBackboneAtoms)), MS.ammp('label_atom_id')]) }) ]) ]) ]), { category: StructureSelectionCategory.Structure }); // TODO maybe pre-calculate sidechain atom property var sidechain = StructureSelectionQuery('Sidechain', MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.logic.or([ MS.core.logic.not([ MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(ProteinBackboneAtoms)), MS.ammp('label_atom_id')]) ]) ]) }) ]), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _nucleiEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.logic.or([ MS.core.logic.not([ MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(NucleicBackboneAtoms)), MS.ammp('label_atom_id')]) ]) ]) }) ]) ]) ]), { category: StructureSelectionCategory.Structure }); // TODO maybe pre-calculate sidechain atom property var sidechainWithTrace = StructureSelectionQuery('Sidechain with Trace', MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.logic.or([ MS.core.logic.not([ MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(ProteinBackboneAtoms)), MS.ammp('label_atom_id')]) ]), MS.core.rel.eq([MS.ammp('label_atom_id'), 'CA']), MS.core.logic.and([ MS.core.rel.eq([MS.ammp('auth_comp_id'), 'PRO']), MS.core.rel.eq([MS.ammp('label_atom_id'), 'N']) ]) ]) }) ]), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _nucleiEntityTest, 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([_nonPolymerResidueTest]), 'atom-test': MS.core.logic.or([ MS.core.logic.not([ MS.core.set.has([MS.set.apply(MS, SetUtils.toArray(NucleicBackboneAtoms)), MS.ammp('label_atom_id')]) ]), MS.core.rel.eq([MS.ammp('label_atom_id'), 'P']) ]) }) ]) ]) ]), { category: StructureSelectionCategory.Structure }); var protein = StructureSelectionQuery('Protein', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest }) ]), { category: StructureSelectionCategory.Type }); var nucleic = StructureSelectionQuery('Nucleic', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _nucleiEntityTest }) ]), { category: StructureSelectionCategory.Type }); var helix = StructureSelectionQuery('Helix', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest, 'residue-test': MS.core.flags.hasAny([ MS.ammp('secondaryStructureFlags'), MS.core.type.bitflags([2 /* SecondaryStructureType.Flag.Helix */]) ]) }) ]), { category: StructureSelectionCategory.Structure, ensureCustomProperties: function (ctx, structure) { return SecondaryStructureProvider.attach(ctx, structure); } }); var beta = StructureSelectionQuery('Beta Strand/Sheet', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': _proteinEntityTest, 'residue-test': MS.core.flags.hasAny([ MS.ammp('secondaryStructureFlags'), MS.core.type.bitflags([4 /* SecondaryStructureType.Flag.Beta */]) ]) }) ]), { category: StructureSelectionCategory.Structure, ensureCustomProperties: function (ctx, structure) { return SecondaryStructureProvider.attach(ctx, structure); } }); var water = StructureSelectionQuery('Water', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'water']) }) ]), { category: StructureSelectionCategory.Type }); var ion = StructureSelectionQuery('Ion', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entitySubtype'), 'ion']) }) ]), { category: StructureSelectionCategory.Type }); var lipid = StructureSelectionQuery('Lipid', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entitySubtype'), 'lipid']) }) ]), { category: StructureSelectionCategory.Type }); var branched = StructureSelectionQuery('Carbohydrate', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.logic.or([ MS.core.rel.eq([MS.ammp('entityType'), 'branched']), MS.core.logic.and([ MS.core.rel.eq([MS.ammp('entityType'), 'non-polymer']), MS.core.str.match([ MS.re('oligosaccharide', 'i'), MS.ammp('entitySubtype') ]) ]) ]) }) ]), { category: StructureSelectionCategory.Type }); var branchedPlusConnected = StructureSelectionQuery('Carbohydrate with Connected', MS.struct.modifier.union([ MS.struct.modifier.includeConnected({ 0: branched.expression, 'layer-count': 1, 'as-whole-residues': true }) ]), { category: StructureSelectionCategory.Internal, isHidden: true }); var branchedConnectedOnly = StructureSelectionQuery('Connected to Carbohydrate', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: branchedPlusConnected.expression, by: branched.expression }) ]), { category: StructureSelectionCategory.Internal, isHidden: true }); var ligand = StructureSelectionQuery('Ligand', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.logic.and([ MS.core.logic.or([ MS.core.rel.eq([MS.ammp('entityType'), 'non-polymer']), MS.core.rel.neq([MS.ammp('entityPrdId'), '']) ]), MS.core.logic.not([MS.core.str.match([ MS.re('(oligosaccharide|lipid|ion)', 'i'), MS.ammp('entitySubtype') ])]) ]), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.logic.not([ MS.core.str.match([MS.re('saccharide', 'i'), MS.ammp('chemCompType')]) ]) }) ]), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': _nonPolymerResidueTest }) ]) ]), ]), by: MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.core.set.has([ MS.set.apply(MS, SetUtils.toArray(PolymerNames)), MS.ammp('label_comp_id') ]) }) ]) }) ]), { category: StructureSelectionCategory.Type }); // don't include branched entities as they have their own link representation var ligandPlusConnected = StructureSelectionQuery('Ligand with Connected', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: MS.struct.modifier.union([ MS.struct.modifier.includeConnected({ 0: ligand.expression, 'layer-count': 1, 'as-whole-residues': true, 'bond-test': MS.core.flags.hasAny([ MS.struct.bondProperty.flags(), MS.core.type.bitflags([ 1 /* BondType.Flag.Covalent */ | 2 /* BondType.Flag.MetallicCoordination */ ]) ]) }) ]), by: branched.expression }) ]), { category: StructureSelectionCategory.Internal, isHidden: true }); var ligandConnectedOnly = StructureSelectionQuery('Connected to Ligand', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: ligandPlusConnected.expression, by: ligand.expression }) ]), { category: StructureSelectionCategory.Internal, isHidden: true }); // residues connected to ligands or branched entities var connectedOnly = StructureSelectionQuery('Connected to Ligand or Carbohydrate', MS.struct.modifier.union([ MS.struct.combinator.merge([ branchedConnectedOnly.expression, ligandConnectedOnly.expression ]), ]), { category: StructureSelectionCategory.Internal, isHidden: true }); var disulfideBridges = StructureSelectionQuery('Disulfide Bridges', MS.struct.modifier.union([ MS.struct.combinator.merge([ MS.struct.modifier.union([ MS.struct.modifier.wholeResidues([ MS.struct.filter.isConnectedTo({ 0: MS.struct.generator.atomGroups({ 'residue-test': MS.core.set.has([MS.set('CYS'), MS.ammp('auth_comp_id')]), 'atom-test': MS.core.set.has([MS.set('SG'), MS.ammp('label_atom_id')]) }), target: MS.struct.generator.atomGroups({ 'residue-test': MS.core.set.has([MS.set('CYS'), MS.ammp('auth_comp_id')]), 'atom-test': MS.core.set.has([MS.set('SG'), MS.ammp('label_atom_id')]) }), 'bond-test': true }) ]) ]), MS.struct.modifier.union([ MS.struct.modifier.wholeResidues([ MS.struct.modifier.union([ MS.struct.generator.bondedAtomicPairs({ 0: MS.core.flags.hasAny([ MS.struct.bondProperty.flags(), MS.core.type.bitflags([8 /* BondType.Flag.Disulfide */]) ]) }) ]) ]) ]) ]) ]), { category: StructureSelectionCategory.Bond }); var nosBridges = StructureSelectionQuery('NOS Bridges', MS.struct.modifier.union([ MS.struct.modifier.wholeResidues([ MS.struct.filter.isConnectedTo({ 0: MS.struct.generator.atomGroups({ 'residue-test': MS.core.set.has([MS.set('CSO', 'LYS'), MS.ammp('auth_comp_id')]), 'atom-test': MS.core.set.has([MS.set('OD', 'NZ'), MS.ammp('label_atom_id')]) }), target: MS.struct.generator.atomGroups({ 'residue-test': MS.core.set.has([MS.set('CSO', 'LYS'), MS.ammp('auth_comp_id')]), 'atom-test': MS.core.set.has([MS.set('OD', 'NZ'), MS.ammp('label_atom_id')]) }), 'bond-test': true }) ]) ]), { category: StructureSelectionCategory.Bond }); var nonStandardPolymer = StructureSelectionQuery('Non-standard Residues in Polymers', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']), 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': MS.ammp('isNonStandard') }) ]), { category: StructureSelectionCategory.Residue }); var coarse = StructureSelectionQuery('Coarse Elements', MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'chain-test': MS.core.set.has([ MS.set('sphere', 'gaussian'), MS.ammp('objectPrimitive') ]) }) ]), { category: StructureSelectionCategory.Type }); var ring = StructureSelectionQuery('Rings in Residues', MS.struct.modifier.union([ MS.struct.generator.rings() ]), { category: StructureSelectionCategory.Residue }); var aromaticRing = StructureSelectionQuery('Aromatic Rings in Residues', MS.struct.modifier.union([ MS.struct.generator.rings({ 'only-aromatic': true }) ]), { category: StructureSelectionCategory.Residue }); var surroundings = StructureSelectionQuery('Surrounding Residues (5 \u212B) of Selection', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: MS.struct.modifier.includeSurroundings({ 0: MS.internal.generator.current(), radius: 5, 'as-whole-residues': true }), by: MS.internal.generator.current() }) ]), { description: 'Select residues within 5 \u212B of the current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var surroundingLigands = StructureSelectionQuery('Surrounding Ligands (5 \u212B) of Selection', MS.struct.modifier.union([ MS.struct.modifier.surroundingLigands({ 0: MS.internal.generator.current(), radius: 5, 'include-water': true }) ]), { description: 'Select ligand components within 5 \u212B of the current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var surroundingAtoms = StructureSelectionQuery('Surrounding Atoms (5 \u212B) of Selection', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: MS.struct.modifier.includeSurroundings({ 0: MS.internal.generator.current(), radius: 5, 'as-whole-residues': false }), by: MS.internal.generator.current() }) ]), { description: 'Select atoms within 5 \u212B of the current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var complement = StructureSelectionQuery('Inverse / Complement of Selection', MS.struct.modifier.union([ MS.struct.modifier.exceptBy({ 0: MS.struct.generator.all(), by: MS.internal.generator.current() }) ]), { description: 'Select everything not in the current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var covalentlyBonded = StructureSelectionQuery('Residues Covalently Bonded to Selection', MS.struct.modifier.union([ MS.struct.modifier.includeConnected({ 0: MS.internal.generator.current(), 'layer-count': 1, 'as-whole-residues': true }) ]), { description: 'Select residues covalently bonded to current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var covalentlyBondedComponent = StructureSelectionQuery('Covalently Bonded Component', MS.struct.modifier.union([ MS.struct.modifier.includeConnected({ 0: MS.internal.generator.current(), 'fixed-point': true }) ]), { description: 'Select covalently bonded component based on current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var covalentlyOrMetallicBonded = StructureSelectionQuery('Residues with Cov. or Metallic Bond to Selection', MS.struct.modifier.union([ MS.struct.modifier.includeConnected({ 0: MS.internal.generator.current(), 'layer-count': 1, 'as-whole-residues': true, 'bond-test': MS.core.flags.hasAny([ MS.struct.bondProperty.flags(), MS.core.type.bitflags([ 1 /* BondType.Flag.Covalent */ | 2 /* BondType.Flag.MetallicCoordination */ ]) ]) }) ]), { description: 'Select residues with covalent or metallic bond to current selection.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var wholeResidues = StructureSelectionQuery('Whole Residues of Selection', MS.struct.modifier.union([ MS.struct.modifier.wholeResidues({ 0: MS.internal.generator.current() }) ]), { description: 'Expand current selection to whole residues.', category: StructureSelectionCategory.Manipulate, referencesCurrent: true }); var StandardAminoAcids = [ [['HIS'], 'Histidine'], [['ARG'], 'Arginine'], [['LYS'], 'Lysine'], [['ILE'], 'Isoleucine'], [['PHE'], 'Phenylalanine'], [['LEU'], 'Leucine'], [['TRP'], 'Tryptophan'], [['ALA'], 'Alanine'], [['MET'], 'Methionine'], [['PRO'], 'Proline'], [['CYS'], 'Cysteine'], [['ASN'], 'Asparagine'], [['VAL'], 'Valine'], [['GLY'], 'Glycine'], [['SER'], 'Serine'], [['GLN'], 'Glutamine'], [['TYR'], 'Tyrosine'], [['ASP'], 'Aspartic Acid'], [['GLU'], 'Glutamic Acid'], [['THR'], 'Threonine'], [['SEC'], 'Selenocysteine'], [['PYL'], 'Pyrrolysine'], [['UNK'], 'Unknown'], ].sort(function (a, b) { return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0; }); var StandardNucleicBases = [ [['A', 'DA'], 'Adenosine'], [['C', 'DC'], 'Cytidine'], [['T', 'DT'], 'Thymidine'], [['G', 'DG'], 'Guanosine'], [['I', 'DI'], 'Inosine'], [['U', 'DU'], 'Uridine'], [['N', 'DN'], 'Unknown'], ].sort(function (a, b) { return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0; }); export function ResidueQuery(_a, category, priority) { var names = _a[0], label = _a[1]; if (priority === void 0) { priority = 0; } var description = names.length === 1 && !StandardResidues.has(names[0]) ? "[".concat(names[0], "] ").concat(label) : "".concat(label, " (").concat(names.join(', '), ")"); return StructureSelectionQuery(description, MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'residue-test': MS.core.set.has([MS.set.apply(MS, names), MS.ammp('auth_comp_id')]) }) ]), { category: category, priority: priority, description: description }); } export function ElementSymbolQuery(_a, category, priority) { var names = _a[0], label = _a[1]; var description = "".concat(label, " (").concat(names.join(', '), ")"); return StructureSelectionQuery(description, MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'atom-test': MS.core.set.has([MS.set.apply(MS, names), MS.acp('elementSymbol')]) }) ]), { category: category, priority: priority, description: description }); } export function EntityDescriptionQuery(_a, category, priority) { var names = _a[0], label = _a[1]; var description = "".concat(label); return StructureSelectionQuery("".concat(label), MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'entity-test': MS.core.list.equal([MS.list.apply(MS, names), MS.ammp('entityDescription')]) }) ]), { category: category, priority: priority, description: description }); } var StandardResidues = SetUtils.unionMany(AminoAcidNamesL, RnaBaseNames, DnaBaseNames, WaterNames); export function getElementQueries(structures) { var uniqueElements = new Set(); for (var _i = 0, structures_1 = structures; _i < structures_1.length; _i++) { var structure = structures_1[_i]; structure.uniqueElementSymbols.forEach(function (e) { return uniqueElements.add(e); }); } var queries = []; uniqueElements.forEach(function (e) { var label = ElementNames[e] || e; queries.push(ElementSymbolQuery([[e], label], 'Element Symbol', 0)); }); return queries; } export function getNonStandardResidueQueries(structures) { var residueLabels = new Map(); var uniqueResidues = new Set(); for (var _i = 0, structures_2 = structures; _i < structures_2.length; _i++) { var structure = structures_2[_i]; structure.uniqueResidueNames.forEach(function (r) { return uniqueResidues.add(r); }); var _loop_1 = function (m) { structure.uniqueResidueNames.forEach(function (r) { var comp = m.properties.chemicalComponentMap.get(r); if (comp) residueLabels.set(r, comp.name); }); }; for (var _a = 0, _b = structure.models; _a < _b.length; _a++) { var m = _b[_a]; _loop_1(m); } } var queries = []; SetUtils.difference(uniqueResidues, StandardResidues).forEach(function (r) { var label = residueLabels.get(r) || r; queries.push(ResidueQuery([[r], label], 'Ligand/Non-standard Residue', 200)); }); return queries; } export function getPolymerAndBranchedEntityQueries(structures) { var uniqueEntities = new Map(); var l = StructureElement.Location.create(); for (var _i = 0, structures_3 = structures; _i < structures_3.length; _i++) { var structure = structures_3[_i]; l.structure = structure; for (var _a = 0, _b = structure.unitSymmetryGroups; _a < _b.length; _a++) { var ug = _b[_a]; l.unit = ug.units[0]; l.element = ug.elements[0]; var entityType = StructureProperties.entity.type(l); if (entityType === 'polymer' || entityType === 'branched') { var description = StructureProperties.entity.pdbx_description(l); uniqueEntities.set(description.join(', '), description); } } } var queries = []; uniqueEntities.forEach(function (v, k) { queries.push(EntityDescriptionQuery([v, k], 'Polymer/Carbohydrate Entities', 300)); }); return queries; } export function applyBuiltInSelection(to, query, customTag) { return to.apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: StructureSelectionQueries[query].expression, label: StructureSelectionQueries[query].label }, { tags: customTag ? [query, customTag] : [query] }); } export var StructureSelectionQueries = { all: all, current: current, polymer: polymer, trace: trace, backbone: backbone, sidechain: sidechain, sidechainWithTrace: sidechainWithTrace, protein: protein, nucleic: nucleic, helix: helix, beta: beta, water: water, ion: ion, lipid: lipid, branched: branched, branchedPlusConnected: branchedPlusConnected, branchedConnectedOnly: branchedConnectedOnly, ligand: ligand, ligandPlusConnected: ligandPlusConnected, ligandConnectedOnly: ligandConnectedOnly, connectedOnly: connectedOnly, disulfideBridges: disulfideBridges, nosBridges: nosBridges, nonStandardPolymer: nonStandardPolymer, coarse: coarse, ring: ring, aromaticRing: aromaticRing, surroundings: surroundings, surroundingLigands: surroundingLigands, surroundingAtoms: surroundingAtoms, complement: complement, covalentlyBonded: covalentlyBonded, covalentlyOrMetallicBonded: covalentlyOrMetallicBonded, covalentlyBondedComponent: covalentlyBondedComponent, wholeResidues: wholeResidues, }; var StructureSelectionQueryRegistry = /** @class */ (function () { function StructureSelectionQueryRegistry() { var _a, _b; this.list = []; this.options = []; this.version = 1; // add built-in (_a = this.list).push.apply(_a, __spreadArray(__spreadArray(__spreadArray([], Object.values(StructureSelectionQueries), false), StandardAminoAcids.map(function (v) { return ResidueQuery(v, StructureSelectionCategory.AminoAcid); }), false), StandardNucleicBases.map(function (v) { return ResidueQuery(v, StructureSelectionCategory.NucleicBase); }), false)); (_b = this.options).push.apply(_b, this.list.map(function (q) { return [q, q.label, q.category]; })); } StructureSelectionQueryRegistry.prototype.add = function (q) { this.list.push(q); this.options.push([q, q.label, q.category]); this.version += 1; }; StructureSelectionQueryRegistry.prototype.remove = function (q) { var idx = this.list.indexOf(q); if (idx !== -1) { this.list.splice(idx, 1); this.options.splice(idx, 1); this.version += 1; } }; return StructureSelectionQueryRegistry; }()); export { StructureSelectionQueryRegistry };