Skip to content
Snippets Groups Projects
Commit 8a7ef1c7 authored by Alexander Rose's avatar Alexander Rose
Browse files

added StructureOverpaintHelper.setFromExpression and alpha prop

parent 8731bc13
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
......@@ -7,10 +7,12 @@
import { PluginStateObject } from '../../mol-plugin/state/objects';
import { StateTransforms } from '../../mol-plugin/state/transforms';
import { StateSelection, StateObjectCell, StateTransform, StateBuilder } from '../../mol-state';
import { Structure, StructureElement } from '../../mol-model/structure';
import { Structure, StructureElement, StructureSelection, QueryContext } from '../../mol-model/structure';
import { PluginContext } from '../context';
import { Color } from '../../mol-util/color';
import { Overpaint } from '../../mol-theme/overpaint';
import Expression from '../../mol-script/language/expression';
import { compile } from '../../mol-script/runtime/query/compiler';
type OverpaintEachReprCallback = (update: StateBuilder.Root, repr: StateObjectCell<PluginStateObject.Molecule.Structure.Representation3D, StateTransform<typeof StateTransforms.Representation.StructureRepresentation3D>>, overpaint?: StateObjectCell<any, StateTransform<typeof StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle>>) => void
const OverpaintManagerTag = 'overpaint-controls'
......@@ -29,7 +31,7 @@ export class StructureOverpaintHelper {
await this.plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true }));
}
async set(color: Color | -1, lociGetter: (structure: Structure) => StructureElement.Loci, types?: string[]) {
async set(color: Color | -1, lociGetter: (structure: Structure) => StructureElement.Loci, types?: string[], alpha = 1) {
await this.eachRepr((update, repr, overpaintCell) => {
if (types && !types.includes(repr.params!.values.type.name)) return
......@@ -48,15 +50,23 @@ export class StructureOverpaintHelper {
if (overpaintCell) {
const bundleLayers = [ ...overpaintCell.params!.values.layers, layer ]
const filtered = getFilteredBundle(bundleLayers, structure)
update.to(overpaintCell).update(Overpaint.toBundle(filtered, 1))
update.to(overpaintCell).update(Overpaint.toBundle(filtered, alpha))
} else {
const filtered = getFilteredBundle([ layer ], structure)
update.to(repr.transform.ref)
.apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, Overpaint.toBundle(filtered, 1), { tags: OverpaintManagerTag });
.apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, Overpaint.toBundle(filtered, alpha), { tags: OverpaintManagerTag });
}
})
}
async setFromExpression(color: Color | -1, expression: Expression, types?: string[], alpha = 1) {
return this.set(color, (structure) => {
const compiled = compile<StructureSelection>(expression)
const result = compiled(new QueryContext(structure))
return StructureSelection.toLociWithSourceUnits(result)
}, types, alpha)
}
constructor(private plugin: PluginContext) {
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment