Browse Source

Coordinate system changes
- remove StructureCoordinateSystem transform
* TransformStructureConformation should be enough
- update Structure.coordinateSystem
- update Structure.transform to keep parent's parent

David Sehnal 5 years ago
parent
commit
a0d38e6b10

+ 10 - 9
src/mol-model/structure/structure/structure.ts

@@ -204,14 +204,15 @@ class Structure {
         return this._props.parent;
     }
 
-    get coordinateSystem() {
-        // TODO: do not use SymmetryOperator for this?
-        // TODO: figure out a good way to compose this
-        return this.parent?.coordinateSystem || this._props.coordinateSystem;
-    }
-
-    set coordinateSystem(op: SymmetryOperator) {
-        this._props.coordinateSystem = op;
+    /**
+     * Conformation transformation that was applied to every unit of this structure.
+     *
+     * Coordinate system applies to the *current* structure only.
+     * A parent structure can have a different coordinate system and thefore it has to be composed "manualy"
+     * by the consumer.
+     */
+    get coordinateSystem(): SymmetryOperator {
+        return this._props.coordinateSystem;
     }
 
     get label() {
@@ -787,7 +788,7 @@ namespace Structure {
 
         const cs = s.coordinateSystem;
         const newCS = SymmetryOperator.compose(SymmetryOperator.create(cs.name, transform, cs), cs);
-        return new Structure(units, { parent: s, coordinateSystem: newCS });
+        return new Structure(units, { parent: s.parent, coordinateSystem: newCS });
     }
 
     export class StructureBuilder {

+ 47 - 48
src/mol-plugin-state/transforms/model.ts

@@ -9,7 +9,6 @@ import { parse3DG } from '../../mol-io/reader/3dg/parser';
 import { parseDcd } from '../../mol-io/reader/dcd/parser';
 import { parseGRO } from '../../mol-io/reader/gro/parser';
 import { parsePDB } from '../../mol-io/reader/pdb/parser';
-import { SymmetryOperator } from '../../mol-math/geometry';
 import { Mat4, Vec3 } from '../../mol-math/linear-algebra';
 import { shapeFromPly } from '../../mol-model-formats/shape/ply';
 import { trajectoryFrom3DG } from '../../mol-model-formats/structure/3dg';
@@ -49,7 +48,6 @@ export { TrajectoryFrom3DG };
 export { ModelFromTrajectory };
 export { StructureFromTrajectory };
 export { StructureFromModel };
-export { StructureCoordinateSystem };
 export { TransformStructureConformation };
 export { StructureSelectionFromExpression };
 export { MultiStructureSelectionFromExpression };
@@ -350,52 +348,52 @@ const StructureFromModel = PluginStateTransform.BuiltIn({
 
 const _translation = Vec3(), _m = Mat4(), _n = Mat4();
 
-type StructureCoordinateSystem = typeof StructureCoordinateSystem
-const StructureCoordinateSystem = PluginStateTransform.BuiltIn({
-    name: 'structure-coordinate-system',
-    display: { name: 'Coordinate System' },
-    isDecorator: true,
-    from: SO.Molecule.Structure,
-    to: SO.Molecule.Structure,
-    params: {
-        transform: PD.MappedStatic('components', {
-            components: PD.Group({
-                axis: PD.Vec3(Vec3.create(1, 0, 0)),
-                angle: PD.Numeric(0, { min: -180, max: 180, step: 0.1 }),
-                translation: PD.Vec3(Vec3.create(0, 0, 0)),
-            }, { isFlat: true }),
-            matrix: PD.Group({
-                data: PD.Mat4(Mat4.identity()),
-                transpose: PD.Boolean(false)
-            }, { isFlat: true })
-        }, { label: 'Kind' })
-    }
-})({
-    canAutoUpdate({ newParams }) {
-        return newParams.transform.name === 'components';
-    },
-    apply({ a, params }) {
-        // TODO: optimze
-
-        const transform = Mat4();
-
-        if (params.transform.name === 'components') {
-            const { axis, angle, translation } = params.transform.params;
-            const center = a.data.boundary.sphere.center;
-            Mat4.fromTranslation(_m, Vec3.negate(_translation, center));
-            Mat4.fromTranslation(_n, Vec3.add(_translation, center, translation));
-            const rot = Mat4.fromRotation(Mat4(), Math.PI / 180 * angle, Vec3.normalize(Vec3(), axis));
-            Mat4.mul3(transform, _n, rot, _m);
-        } else if (params.transform.name === 'matrix') {
-            Mat4.copy(transform, params.transform.params.data);
-            if (params.transform.params.transpose) Mat4.transpose(transform, transform);
-        }
-
-        // TODO: compose with parent's coordinate system
-        a.data.coordinateSystem = SymmetryOperator.create('CS', transform);
-        return new SO.Molecule.Structure(a.data, { label: a.label, description: `${a.description} [Transformed]` });
-    }
-});
+// type StructureCoordinateSystem = typeof StructureCoordinateSystem
+// const StructureCoordinateSystem = PluginStateTransform.BuiltIn({
+//     name: 'structure-coordinate-system',
+//     display: { name: 'Coordinate System' },
+//     isDecorator: true,
+//     from: SO.Molecule.Structure,
+//     to: SO.Molecule.Structure,
+//     params: {
+//         transform: PD.MappedStatic('components', {
+//             components: PD.Group({
+//                 axis: PD.Vec3(Vec3.create(1, 0, 0)),
+//                 angle: PD.Numeric(0, { min: -180, max: 180, step: 0.1 }),
+//                 translation: PD.Vec3(Vec3.create(0, 0, 0)),
+//             }, { isFlat: true }),
+//             matrix: PD.Group({
+//                 data: PD.Mat4(Mat4.identity()),
+//                 transpose: PD.Boolean(false)
+//             }, { isFlat: true })
+//         }, { label: 'Kind' })
+//     }
+// })({
+//     canAutoUpdate({ newParams }) {
+//         return newParams.transform.name === 'components';
+//     },
+//     apply({ a, params }) {
+//         // TODO: optimze
+
+//         const transform = Mat4();
+
+//         if (params.transform.name === 'components') {
+//             const { axis, angle, translation } = params.transform.params;
+//             const center = a.data.boundary.sphere.center;
+//             Mat4.fromTranslation(_m, Vec3.negate(_translation, center));
+//             Mat4.fromTranslation(_n, Vec3.add(_translation, center, translation));
+//             const rot = Mat4.fromRotation(Mat4(), Math.PI / 180 * angle, Vec3.normalize(Vec3(), axis));
+//             Mat4.mul3(transform, _n, rot, _m);
+//         } else if (params.transform.name === 'matrix') {
+//             Mat4.copy(transform, params.transform.params.data);
+//             if (params.transform.params.transpose) Mat4.transpose(transform, transform);
+//         }
+
+//         // TODO: compose with parent's coordinate system
+//         a.data.coordinateSystem = SymmetryOperator.create('CS', transform);
+//         return new SO.Molecule.Structure(a.data, { label: a.label, description: `${a.description} [Transformed]` });
+//     }
+// });
 
 type TransformStructureConformation = typeof TransformStructureConformation
 const TransformStructureConformation = PluginStateTransform.BuiltIn({
@@ -423,6 +421,7 @@ const TransformStructureConformation = PluginStateTransform.BuiltIn({
     },
     apply({ a, params }) {
         // TODO: optimze
+        // TODO: think of ways how to fast-track changes to this for animations
 
         const transform = Mat4();
 

+ 10 - 10
src/mol-plugin-state/transforms/representation.ts

@@ -128,11 +128,11 @@ const StructureRepresentation3D = PluginStateTransform.BuiltIn({
             await Theme.ensureDependencies(propertyCtx, plugin.representation.structure.themes, { structure: a.data }, params);
             repr.setTheme(Theme.create(plugin.representation.structure.themes, { structure: a.data }, params));
 
-            // TODO: build this into representation?
-            if (!a.data.coordinateSystem.isIdentity) {
-                (cache as any)['transform'] = a.data.coordinateSystem;
-                repr.setState({ transform: a.data.coordinateSystem.matrix });
-            }
+            // // TODO: build this into representation?
+            // if (!a.data.coordinateSystem.isIdentity) {
+            //     (cache as any)['transform'] = a.data.coordinateSystem;
+            //     repr.setState({ transform: a.data.coordinateSystem.matrix });
+            // }
 
             // TODO set initial state, repr.setState({})
             await repr.createOrUpdate(props, a.data).runInContext(ctx);
@@ -154,11 +154,11 @@ const StructureRepresentation3D = PluginStateTransform.BuiltIn({
             await Theme.ensureDependencies(propertyCtx, plugin.representation.structure.themes, { structure: a.data }, newParams);
             b.data.repr.setTheme(Theme.create(plugin.representation.structure.themes, { structure: a.data }, newParams));
 
-            // TODO: build this into representation?
-            if ((cache as any)['transform'] !== a.data.coordinateSystem) {
-                (cache as any)['transform'] = a.data.coordinateSystem;
-                b.data.repr.setState({ transform: a.data.coordinateSystem.matrix });
-            }
+            // // TODO: build this into representation?
+            // if ((cache as any)['transform'] !== a.data.coordinateSystem) {
+            //     (cache as any)['transform'] = a.data.coordinateSystem;
+            //     b.data.repr.setState({ transform: a.data.coordinateSystem.matrix });
+            // }
 
             await b.data.repr.createOrUpdate(props, a.data).runInContext(ctx);
             b.data.source = a;

+ 0 - 1
src/mol-plugin/index.ts

@@ -42,7 +42,6 @@ export const DefaultPluginSpec: PluginSpec = {
         PluginSpec.Action(StateTransforms.Model.TrajectoryFromCifCore),
         PluginSpec.Action(StateTransforms.Model.TrajectoryFromPDB),
         PluginSpec.Action(StateTransforms.Model.TransformStructureConformation),
-        PluginSpec.Action(StateTransforms.Model.StructureCoordinateSystem),
         PluginSpec.Action(StateTransforms.Model.StructureFromModel),
         PluginSpec.Action(StateTransforms.Model.StructureFromTrajectory),
         PluginSpec.Action(StateTransforms.Model.ModelFromTrajectory),