123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author Alexander Rose <alexander.rose@weirdbyte.de>
- */
- import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
- import { StateSelection } from '../../mol-state';
- import { PluginStateObject } from '../state/objects';
- import { QueryContext, StructureSelection } from '../../mol-model/structure';
- import { compile } from '../../mol-script/runtime/query/compiler';
- import { Loci } from '../../mol-model/loci';
- import { PluginContext } from '../context';
- import Expression from '../../mol-script/language/expression';
- const all = MS.struct.generator.all()
- const polymers = MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer'])
- })
- ])
- const backboneTrace = MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'atom-test': MS.core.logic.or([
- MS.core.rel.eq([MS.ammp('label_atom_id'), 'CA']),
- MS.core.rel.eq([MS.ammp('label_atom_id'), 'P'])
- ])
- })
- ])
- const water = MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'water'])
- })
- ])
- const branched = 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'), 'branched'])
- })
- ]),
- MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'non-polymer']),
- 'residue-test': MS.core.str.match([MS.re('saccharide', 'i'), MS.ammp('chemCompType')])
- })
- ])
- ])
- ])
- const branchedPlusConnected = MS.struct.modifier.union([
- MS.struct.modifier.includeConnected({
- 0: branched, 'layer-count': 1, 'as-whole-residues': true
- })
- ])
- const branchedConnectedOnly = MS.struct.modifier.union([
- MS.struct.modifier.exceptBy({
- 0: branchedPlusConnected,
- by: branched
- })
- ])
- const ligands = MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'entity-test': MS.core.logic.and([
- MS.core.rel.neq([MS.ammp('entityType'), 'branched']),
- MS.core.rel.eq([MS.ammp('entityType'), 'non-polymer'])
- ]),
- 'residue-test': MS.core.logic.not([
- MS.core.str.match([MS.re('saccharide', 'i'), MS.ammp('chemCompType')])
- ])
- })
- ])
- const ligandsPlusConnected = MS.struct.modifier.union([
- MS.struct.modifier.includeConnected({
- 0: ligands, 'layer-count': 1, 'as-whole-residues': true
- })
- ])
- const coarse = MS.struct.modifier.union([
- MS.struct.generator.atomGroups({
- 'chain-test': MS.core.set.has([
- MS.set('sphere', 'gaussian'), MS.ammp('objectPrimitive')
- ])
- })
- ])
- export const StructureSelectionQueries = {
- all,
- polymers,
- backboneTrace,
- water,
- branched,
- branchedPlusConnected,
- branchedConnectedOnly,
- ligands,
- ligandsPlusConnected,
- coarse,
- }
- //
- type SelectionModifier = 'add' | 'remove' | 'only'
- export class StructureSelectionHelper {
- private get structures() {
- const state = this.plugin.state.dataState
- return state.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure))
- }
- private _set(modifier: SelectionModifier, loci: Loci) {
- switch (modifier) {
- case 'add':
- this.plugin.interactivity.lociSelections.add({ loci })
- break
- case 'remove':
- this.plugin.interactivity.lociSelections.remove({ loci })
- break
- case 'only':
- this.plugin.interactivity.lociSelections.only({ loci })
- break
- }
- }
- set(modifier: SelectionModifier, query: Expression) {
- const compiled = compile<StructureSelection>(query)
- for (const so of this.structures) {
- const s = so.obj!.data
- const result = compiled(new QueryContext(s))
- const loci = StructureSelection.toLoci2(result)
- this._set(modifier, loci)
- }
- }
- constructor(private plugin: PluginContext) {
- }
- }
|