Переглянути джерело

Overpaints; only selection must be refined

cycle20 5 місяців тому
батько
коміт
c24394f172
1 змінених файлів з 164 додано та 2 видалено
  1. 164 2
      src/Tm3DStandaloneApp/tmdet-viewer/TmViewerStandalone.ts

+ 164 - 2
src/Tm3DStandaloneApp/tmdet-viewer/TmViewerStandalone.ts

@@ -25,6 +25,19 @@ import { Mat4 } from 'molstar/lib/commonjs/mol-math/linear-algebra';
 import { TrajectoryHierarchyPresetProvider } from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
 import { registerRegionDescriptorData } from '../../TmFv3DApp/UniTmpHelper';
 import { TmDetRcsbPreset } from '../TmTrajectoryHierarchyPreset';
+import { Expression } from 'molstar/lib/mol-script/language/expression';
+import { MolScriptBuilder } from 'molstar/lib/mol-script/language/builder';
+import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
+import { Color } from 'molstar/lib/mol-util/color';
+
+import { StructureElement, Structure, StructureSelection, QueryContext } from 'molstar/lib/mol-model/structure';
+import { OrderedSet } from 'molstar/lib/mol-data/int';
+import { setStructureOverpaint } from 'molstar/lib/mol-plugin-state/helpers/structure-overpaint';
+import { Script } from 'molstar/lib/mol-script/script';
+import { compile } from 'molstar/lib/mol-script/runtime/query/base';
+import { Overpaint } from 'molstar/lib/mol-theme/overpaint';
+import { createStructureRepresentationParams } from 'molstar/lib/mol-plugin-state/helpers/structure-representation-params';
+import { ColorNames } from 'molstar/lib/mol-util/color/names';
 
 export class TmViewerStandalone extends Viewer {
 
@@ -59,8 +72,157 @@ export class TmViewerStandalone extends Viewer {
         return super.loadStructureFromUrl(url, format, isBinary, config);
     }
 
-    unselectChains(chains: string[]) {
-        console.log(TmDetColorThemeProvider);
+    async lociGetter(structure: Structure) {
+        // const structure = this.plugin.managers.structure.hierarchy.current.models[0].structures[0].cell;
+        // const unit = structure.obj!.data!.unitMap.get(0)
+        // structure.obj!.data.entityIndices
+        // StructureElement.Loci(structure.obj!.data, [{ unit: unit, indices: Array.from(unit.elements) }]);
+        // console.log(Structure.Loci());
+        let indices = OrderedSet.ofRange(10 as StructureElement.UnitIndex, 100  as StructureElement.UnitIndex);
+        // let indices = OrderedSet.ofSortedArray([ 15 as StructureElement.UnitIndex ]);
+        return StructureElement.Loci(structure, [
+            { unit: structure.unitMap.get(0), indices: indices },
+            { unit: structure.unitMap.get(1), indices: indices },
+            { unit: structure.unitMap.get(2), indices: indices }
+        ]);
+    }
+
+    chainSelection(auth_asym_id: string) {
+        return MolScriptBuilder.struct.generator.atomGroups({
+            'chain-test': MolScriptBuilder.core.rel.eq([MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), auth_asym_id])
+        });
+    }
+
+    async setChainColorOLD(labelAsymId: string) {
+
+        const state = this.plugin.state.data;
+
+        const selected = state.selectQ(q => q.ofTransformer(StateTransforms.Model.StructureFromModel));
+        //const str = this.plugin.managers.structure.hierarchy.current.structures[0];
+        if (selected.length == 0) {
+            console.log('Structure not found');
+            return;
+        }
+        let structure = selected[0];
+        console.log('STRUCT1', structure);
+        structure = this.plugin.managers.structure.hierarchy.current.models[0].structures[0].cell;
+        console.log('STRUCT2', structure);
+
+        // const update = this.plugin.build().to(structure);  //state.build().to(structure);
+        const query: Expression =
+            MolScriptBuilder.struct.generator.atomGroups({
+                'chain-test': MolScriptBuilder.core.rel.eq([labelAsymId, MolScriptBuilder.ammp('label_asym_id')])
+        });
+
+        const s = await this.plugin.build()
+            .to(this.plugin.managers.structure.hierarchy.current.structures[0].cell)
+            .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: query }).commit();
+        // const rangeSel = Script.getStructureSelection(Q => Q.struct.modifier.union([
+        //     Q.struct.generator.atomGroups({
+        //         // I am not sure this test will be enough, or uses the correct property, but something along these lines should do it
+        //         'chain-test': Q.core.rel.eq([Q.struct.atomProperty.macromolecular.label_asym_id(), 'A']),
+        //     })
+        // ]), );
+        const compiledQuery = compile<StructureSelection>(query);
+        const xs = this.plugin.managers.structure.hierarchy.current.structures;
+        const selections = xs.map(s => StructureSelection.toLociWithCurrentUnits(compiledQuery(new QueryContext(s.cell.obj!.data))));
+
+        console.log(selections);
+
+
+        const component = await this.plugin.builders.structure.tryCreateComponentFromExpression(structure, query, 'hello', { label: 'CHAIN-A' });
+        console.log(component);
+        // const update = this.plugin.build().to(component!.cell!);
+        // update //.apply(StateTransforms.Model.StructureSelectionFromExpression, { label: 'CHAIN-A', expression: query })
+        //     .apply(StateTransforms.Representation.StructureRepresentation3D, createStructureRepresentationParams(this.plugin, update.selector.data,
+        //         { type: 'cartoon', typeParams: { alpha: 1 },
+        //         color: 'uniform', colorParams: { value: Color.fromArray([255,0,0], 0) }  }))
+        // const result = await update.commit();
+        // console.log('Result:', result);
+
+        console.log('Component Group:', this.plugin.managers.structure.hierarchy.currentComponentGroups);
+        // await this.plugin.builders.structure.representation.addRepresentation(structure, {
+        //     type: 'cartoon',
+        //     color: 'uniform',
+        //     colorParams: {value: 0xd3d3d3}, // gray80
+        //     typeParams: {detail: 1}
+        // });
+
+        // TODO: const structureData = component!.cell!.obj!.data;
+
+        //setStructureOverpaint(this.plugin, [ structure!.obj!.data ], Color.fromRgb(255, 0, 0), this.lociGetter, undefined);
+        // console.log(component);
+        console.log('component cell', component!.cell!);
+        const structRef = this.plugin.managers.structure.hierarchy.current.refs;
+        let comps: any[] = [];
+
+        // const bundle = StructureElement.Bundle.fromLoci(selections[0]);
+        // await this.plugin.build().to(component!.cell!)
+        //     .apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromScript,
+        //         {
+        //             layers: [{
+        //                 script: query,
+        //                 color: Color.fromRgb(255, 0, 0),
+        //                 clear: false
+        //             }]
+        //         })
+        //     .commit();
+
+
+        this.plugin.managers.structure.component.currentStructures.forEach(val => comps = comps.concat(...val.components));
+setStructureOverpaint(this.plugin, comps, Color.fromRgb(255, 0, 0), this.lociGetter, undefined);
+        console.log('Components', comps);
+        // console.log('component ref', this.plugin.managers.structure.component.;
+    }
+
+    async setChainColor(labelAsymId: string) {
+
+        const state = this.plugin.state.data;
+
+        const selected = state.selectQ(q => q.ofTransformer(StateTransforms.Model.StructureFromModel));
+        //const str = this.plugin.managers.structure.hierarchy.current.structures[0];
+        if (selected.length == 0) {
+            console.log('Structure not found');
+            return;
+        }
+
+        const query: Expression =
+            MolScriptBuilder.struct.generator.atomGroups({
+                'chain-test': MolScriptBuilder.core.rel.eq([labelAsymId, MolScriptBuilder.ammp('label_asym_id')])
+        });
+
+        // const update = this.plugin.build().to(structure)
+        const update = this.plugin.build().to(Array.from(state.cells.values())[13]);
+        update //.apply(StateTransforms.Model.StructureSelectionFromExpression, { label: 'CHAIN-A', expression: query })
+            // .apply(StateTransforms.Representation.StructureRepresentation3D, createStructureRepresentationParams(this.plugin, update.selector.data,
+            //     { type: 'cartoon', typeParams: { alpha: 1 },
+            //     color: 'uniform', colorParams: { value: Color.fromArray([255,0,0], 0) }  }))
+            .apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromScript, {
+                layers: [
+                    {
+                        script:  Script(
+                            `(sel.atom.res (in-range atom.resno 10 100))`,
+                            'mol-script'
+                        ),
+                        color: ColorNames.red,
+                        clear: false
+
+                    }
+                ]
+            });
+        const result = await update.commit();
+        console.log('Result:', result);
+
+        // await this.plugin.build().to(component!.cell!)
+        //     .apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromScript,
+        //         {
+        //             layers: [{
+        //                 script: query,
+        //                 color: Color.fromRgb(255, 0, 0),
+        //                 clear: false
+        //             }]
+        //         })
+        //     .commit();
     }
 
     async loadWithUNITMPMembraneRepresentation(params: any) {