From de093b5472c70e770e08a85fded74064ed23f45d Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Wed, 2 Sep 2020 22:14:44 -0700
Subject: [PATCH] support origin and model as reference for model unitcell
representation
---
.../transforms/representation.ts | 4 ++--
src/mol-repr/shape/model/unitcell.ts | 19 +++++++++++++------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/mol-plugin-state/transforms/representation.ts b/src/mol-plugin-state/transforms/representation.ts
index dd61588bc..eca2ddd82 100644
--- a/src/mol-plugin-state/transforms/representation.ts
+++ b/src/mol-plugin-state/transforms/representation.ts
@@ -702,7 +702,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({
return Task.create('Model Unit Cell', async ctx => {
const symmetry = ModelSymmetry.Provider.get(a.data);
if (!symmetry) return StateObject.Null;
- const data = getUnitcellData(a.data, symmetry);
+ const data = getUnitcellData(a.data, symmetry, params);
const repr = UnitcellRepresentation({ webgl: plugin.canvas3d?.webgl, ...plugin.representation.structure.themes }, () => UnitcellParams);
await repr.createOrUpdate(params, data).runInContext(ctx);
return new SO.Shape.Representation3D({ repr, source: a }, { label: `Unit Cell`, description: symmetry.spacegroup.name });
@@ -713,7 +713,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({
const symmetry = ModelSymmetry.Provider.get(a.data);
if (!symmetry) return StateTransformer.UpdateResult.Null;
const props = { ...b.data.repr.props, ...newParams };
- const data = getUnitcellData(a.data, symmetry);
+ const data = getUnitcellData(a.data, symmetry, props);
await b.data.repr.createOrUpdate(props, data).runInContext(ctx);
b.data.source = a;
return StateTransformer.UpdateResult.Updated;
diff --git a/src/mol-repr/shape/model/unitcell.ts b/src/mol-repr/shape/model/unitcell.ts
index fc28c1c9a..4acdbdd03 100644
--- a/src/mol-repr/shape/model/unitcell.ts
+++ b/src/mol-repr/shape/model/unitcell.ts
@@ -29,10 +29,16 @@ interface UnitcellData {
ref: Vec3
}
+const CellRef = {
+ origin: 'Origin',
+ model: 'Model'
+};
+
const CellParams = {
...Mesh.Params,
cellColor: PD.Color(ColorNames.orange),
- cellScale: PD.Numeric(2, { min: 0.1, max: 5, step: 0.1 })
+ cellScale: PD.Numeric(2, { min: 0.1, max: 5, step: 0.1 }),
+ ref: PD.Select('model', PD.objectToOptions(CellRef), { isEssential: true })
};
type MeshParams = typeof CellParams
@@ -98,11 +104,12 @@ function getUnitcellShape(ctx: RuntimeContext, data: UnitcellData, props: Unitce
//
-export function getUnitcellData(model: Model, symmetry: Symmetry) {
- return {
- symmetry,
- ref: Vec3.transformMat4(Vec3(), Model.getCenter(model), symmetry.spacegroup.cell.toFractional)
- };
+export function getUnitcellData(model: Model, symmetry: Symmetry, props: UnitcellProps) {
+ const ref = Vec3();
+ if (props.ref === 'model') {
+ Vec3.transformMat4(ref, Model.getCenter(model), symmetry.spacegroup.cell.toFractional);
+ }
+ return { symmetry, ref };
}
export type UnitcellRepresentation = Representation<UnitcellData, UnitcellParams>
--
GitLab