فهرست منبع

Issue #2: selector-way to identify new chains

Related GitHub issue:
https://github.com/molstar/molstar/issues/504#issuecomment-1209273019
cycle20 2 سال پیش
والد
کامیت
c8ab0239db
1فایلهای تغییر یافته به همراه62 افزوده شده و 38 حذف شده
  1. 62 38
      src/extensions/tmdet/transformation.ts

+ 62 - 38
src/extensions/tmdet/transformation.ts

@@ -4,7 +4,7 @@ import { Mat4, Vec3 } from '../../mol-math/linear-algebra';
 import { PDBTMDescriptor, PDBTMTransformationMatrix, PMS } from './types';
 import { createStructureRepresentationParams } from '../../mol-plugin-state/helpers/structure-representation-params';
 import { StateTransforms } from '../../mol-plugin-state/transforms';
-import { StateObjectRef, StateBuilder } from '../../mol-state';
+import { StateObjectRef, StateBuilder, StateObjectSelector, StateTransformer } from '../../mol-state';
 import { Expression } from '../../mol-script/language/expression';
 import { MembraneOrientation } from './prop';
 import { TmDetColorThemeProvider } from './tmdet-color-theme';
@@ -15,14 +15,16 @@ export async function applyTransformations(plugin: PluginUIContext, pdbtmDescrip
 
     const membraneTransformation = transformationForStateTransform(pdbtmDescriptor.additional_entry_annotations.membrane.transformation_matrix);
 
+    const selectors: StateObjectSelector<any, any>[] = [];
     if (annotations.biomatrix) {
         annotations.biomatrix.matrix_list.forEach(function(mx) {
             mx.apply_to_chain_list.forEach(async function(chainPair) {
                 let id  = chainPair.chain_id;
                 let newId = chainPair.new_chain_id;
                 const mtx = transformationForStateTransform(mx.transformation_matrix);
-                const composedTransformation = Mat4.mul(Mat4(), membraneTransformation, mtx);
-                chainTransformation(plugin, composedTransformation, id, newId);
+                const composedTransformation = mtx; // Mat4.mul(Mat4(), membraneTransformation, mtx);
+                const selector = chainTransformation(plugin, composedTransformation, id, newId);
+                selectors.push(selector);
                 // await plugin.runTask(Task.create(`TMDET: Transform '${id}' into '${newId}'`, async () => {
                 //     chainTransformation(plugin, mx.transformation_matrix, id, newId);
                 // }));
@@ -35,53 +37,22 @@ export async function applyTransformations(plugin: PluginUIContext, pdbtmDescrip
     //          plugin.runTask with "await" also cannot synchronize here.
     //
     // So this function call transforms only already existing components due to a side effect of another issue.
-    transformWholeModel(plugin, pdbtmDescriptor.additional_entry_annotations.membrane.transformation_matrix);
+    transformWholeModel(plugin, pdbtmDescriptor.additional_entry_annotations.membrane.transformation_matrix, selectors);
     // await plugin.runTask(Task.create(`TMDET: Apply membrane transformation`, async () => {
     //     transformWholeModel(plugin, pdbtmDescriptor.additional_entry_annotations.membrane.transformation_matrix);
     // }));
 
 }
 
-export function transformWholeModel(plugin: PluginUIContext, membraneMatrix: PDBTMTransformationMatrix) {
-    //
-    // membrane transformation
-    //
-    const membraneTransformation = transformationForStateTransform(membraneMatrix);
-
-    // transform each component
-    DebugUtil.log("STRUCTURES", getCurrentHierarchy(plugin).structures);
-    getCurrentHierarchy(plugin).structures[0].components.forEach(component => {
-        const structure: StateObjectRef<PMS> = component.cell;
-        const update: StateBuilder.To<any, any> = plugin.build().to(structure);
-
-        const label = component.cell.obj!.label.toUpperCase();
-        DebugUtil.log("memb.transform of", label, component.cell.obj?.id);
-        DebugUtil.log(`${label} component.cell.obj:`, component.cell.obj);
-        // DebugUtil.log(`${label} component:`, component);
-
-        update
-            .apply(StateTransforms.Model.TransformStructureConformation, {
-                "transform": { name: "matrix", params: { data: membraneTransformation, transpose: false } }
-            })
-            .apply(
-                StateTransforms.Representation.StructureRepresentation3D,
-                createStructureRepresentationParams(plugin, structure.obj?.data, {
-                    type: 'cartoon',
-                    color: TmDetColorThemeProvider.name as any //, colorParams: { pdbtmDescriptor }
-                })
-            );
-        update.commit();
-    });
-}
-
 /**
  * Perform transformation on a chain.
  *
  * @param plugin UI context
  * @param transformationMatrix 4x4 matrix describes transformation and translation
  * @param chainId Id of chain to be selected for transformation
+ * @param newId chain Id of transformation result
  */
-export function chainTransformation(plugin: PluginUIContext, transformationMatrix: Mat4, chainId: string, newId: string): void {
+ export function chainTransformation(plugin: PluginUIContext, transformationMatrix: Mat4, chainId: string, newId: string): StateObjectSelector<any, any> {
     const query: Expression = getChainExpression(chainId);
 
 //    const transformation = transformationForStateTransform(transformationMatrix);
@@ -105,7 +76,60 @@ export function chainTransformation(plugin: PluginUIContext, transformationMatri
             })
         );
     update.commit();
-    DebugUtil.log(`${chainId}->${newId} DONE`);
+    DebugUtil.log(`${chainId}->${newId} DONE; selector:`, update.selector);
+    return update.selector;
+}
+
+export function transformWholeModel(plugin: PluginUIContext, membraneMatrix: PDBTMTransformationMatrix, selectors: StateObjectSelector<any, any>[]) {
+    //
+    // membrane transformation
+    //
+    const membraneTransformation = transformationForStateTransform(membraneMatrix);
+
+    // transform each component
+    DebugUtil.log("STRUCTURES", getCurrentHierarchy(plugin).structures);
+    getCurrentHierarchy(plugin).structures[0].components.forEach(component => {
+        const structure: StateObjectRef<PMS> = component.cell;
+        const update: StateBuilder.To<any, any> = plugin.build().to(structure);
+
+        const label = component.cell.obj!.label.toUpperCase();
+        DebugUtil.log("memb.transform of", label, component.cell.obj?.id);
+        DebugUtil.log(`${label} component.cell.obj:`, component.cell.obj);
+        // DebugUtil.log(`${label} component:`, component);
+
+        update
+            .apply(StateTransforms.Model.TransformStructureConformation, {
+                "transform": { name: "matrix", params: { data: membraneTransformation, transpose: false } }
+            })
+            /* .apply(
+                StateTransforms.Representation.StructureRepresentation3D,
+                createStructureRepresentationParams(plugin, structure.obj?.data, {
+                    type: 'cartoon',
+                    color: TmDetColorThemeProvider.name as any //, colorParams: { pdbtmDescriptor }
+                })
+            ) */;
+        update.commit();
+    });
+
+
+    type TSC = typeof StateTransforms.Model.TransformStructureConformation;
+    type SP = StateTransformer.Params<TSC>;
+
+    selectors.forEach(selector => {
+        const update = plugin.build().to(selector);
+        // apply<T extends StateTransformer<A, any, any>>(tr: T, params?: Partial<StateTransformer.Params<T>>, options?: Partial<StateTransform.Options>): To<StateTransformer.To<T>, T> {
+        // update<T extends StateTransformer<any, A, any>>(transformer: T, params: (old: StateTransformer.Params<T>) => Partial<StateTransformer.Params<T>> | void): Root
+        // update(params: Partial<StateTransformer.Params<T>> | ((old: StateTransformer.Params<T>) => Partial<StateTransformer.Params<T>> | void)): Root
+        // update<T extends StateTransformer<any, A, any>>(paramsOrTransformer: T | any, provider?: (old: StateTransformer.Params<T>) => StateTransformer.Params<T>) {
+
+        DebugUtil.log('selector:', selector);
+        update.update(StateTransforms.Model.TransformStructureConformation, (old: SP): SP => {
+            return {
+                "transform": { name: "matrix", params: { data: membraneTransformation, transpose: false } }
+            };
+        });
+        update.commit();
+    });
 }
 
 // function vadd(a: Vec3, b: Vec3): Vec3 {