Bladeren bron

added Model.TrajectoryInfo

- replaces model.trajectoryInfo
Alexander Rose 4 jaren geleden
bovenliggende
commit
d500393501

+ 7 - 7
src/extensions/cellpack/color/generate.ts

@@ -10,7 +10,7 @@ import { Color } from '../../../mol-util/color';
 import { getPalette } from '../../../mol-util/color/palette';
 import { ColorTheme, LocationColor } from '../../../mol-theme/color';
 import { ScaleLegend, TableLegend } from '../../../mol-util/legend';
-import { StructureElement, Bond } from '../../../mol-model/structure';
+import { StructureElement, Bond, Model } from '../../../mol-model/structure';
 import { Location } from '../../../mol-model/location';
 import { CellPackInfoProvider } from '../property';
 import { distinctColors } from '../../../mol-util/color/distinct';
@@ -40,7 +40,7 @@ export function CellPackGenerateColorTheme(ctx: ThemeDataContext, props: PD.Valu
         const { models } = ctx.structure.root;
 
         let size = 0;
-        for (const m of models) size = Math.max(size, m.trajectoryInfo.size);
+        for (const m of models) size = Math.max(size, Model.TrajectoryInfo.get(m).size);
 
         const palette = getPalette(size, { palette: {
             name: 'generate',
@@ -53,15 +53,15 @@ export function CellPackGenerateColorTheme(ctx: ThemeDataContext, props: PD.Valu
         legend = palette.legend;
         const modelColor = new Map<number, Color>();
         for (let i = 0, il = models.length; i < il; ++i) {
-            const idx = models[i].trajectoryInfo.index;
-            modelColor.set(models[i].trajectoryInfo.index, palette.color(idx));
+            const idx = Model.TrajectoryInfo.get(models[i]).index;
+            modelColor.set(Model.TrajectoryInfo.get(models[i]).index, palette.color(idx));
         }
 
         color = (location: Location): Color => {
             if (StructureElement.Location.is(location)) {
-                return modelColor.get(location.unit.model.trajectoryInfo.index)!;
+                return modelColor.get(Model.TrajectoryInfo.get(location.unit.model).index)!;
             } else if (Bond.isLocation(location)) {
-                return modelColor.get(location.aUnit.model.trajectoryInfo.index)!;
+                return modelColor.get(Model.TrajectoryInfo.get(location.aUnit.model).index)!;
             }
             return DefaultColor;
         };
@@ -89,7 +89,7 @@ export const CellPackGenerateColorThemeProvider: ColorTheme.Provider<CellPackGen
     isApplicable: (ctx: ThemeDataContext) => {
         return (
             !!ctx.structure && ctx.structure.elementCount > 0 &&
-            ctx.structure.models[0].trajectoryInfo.size > 1 &&
+            Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1 &&
             !!CellPackInfoProvider.get(ctx.structure).value
         );
     }

+ 5 - 5
src/extensions/cellpack/color/provided.ts

@@ -9,7 +9,7 @@ import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 import { Color } from '../../../mol-util/color';
 import { ColorTheme, LocationColor } from '../../../mol-theme/color';
 import { ScaleLegend, TableLegend } from '../../../mol-util/legend';
-import { StructureElement } from '../../../mol-model/structure';
+import { StructureElement, Model } from '../../../mol-model/structure';
 import { Location } from '../../../mol-model/location';
 import { CellPackInfoProvider } from '../property';
 
@@ -32,13 +32,13 @@ export function CellPackProvidedColorTheme(ctx: ThemeDataContext, props: PD.Valu
         const { models } = ctx.structure.root;
         const modelColor = new Map<number, Color>();
         for (let i = 0, il = models.length; i < il; ++i) {
-            const idx = models[i].trajectoryInfo.index;
-            modelColor.set(models[i].trajectoryInfo.index, info.colors[idx]);
+            const idx = Model.TrajectoryInfo.get(models[i]).index;
+            modelColor.set(Model.TrajectoryInfo.get(models[i]).index, info.colors[idx]);
         }
 
         color = (location: Location): Color => {
             return StructureElement.Location.is(location)
-                ? modelColor.get(location.unit.model.trajectoryInfo.index)!
+                ? modelColor.get(Model.TrajectoryInfo.get(location.unit.model).index)!
                 : DefaultColor;
         };
     } else {
@@ -65,7 +65,7 @@ export const CellPackProvidedColorThemeProvider: ColorTheme.Provider<CellPackPro
     isApplicable: (ctx: ThemeDataContext) => {
         return (
             !!ctx.structure && ctx.structure.elementCount > 0 &&
-            ctx.structure.models[0].trajectoryInfo.size > 1 &&
+            Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1 &&
             !!CellPackInfoProvider.get(ctx.structure).value?.colors
         );
     }

+ 1 - 3
src/extensions/cellpack/model.ts

@@ -412,9 +412,7 @@ export function createStructureFromCellPack(plugin: PluginContext, packing: Cell
         if (ctx.shouldUpdate) await ctx.update(`${name} - structure`);
         const structure = builder.getStructure();
         for( let i = 0, il = structure.models.length; i < il; ++i) {
-            const { trajectoryInfo } = structure.models[i];
-            trajectoryInfo.size = il;
-            trajectoryInfo.index = i;
+            Model.TrajectoryInfo.set(structure.models[i], { size: il, index: i });
         }
         return { structure, assets, colors: skipColors ? undefined : colors };
     });

+ 2 - 56
src/extensions/cellpack/state.ts

@@ -13,7 +13,7 @@ import { IngredientFiles } from './util';
 import { Asset } from '../../mol-util/assets';
 import { PluginContext } from '../../mol-plugin/context';
 import { CellPackInfoProvider } from './property';
-import { Structure, StructureSymmetry, Unit } from '../../mol-model/structure';
+import { Structure, StructureSymmetry, Unit, Model } from '../../mol-model/structure';
 import { ModelSymmetry } from '../../mol-model-formats/structure/property/symmetry';
 
 export const DefaultCellPackBaseUrl = 'https://mesoscope.scripps.edu/data/cellPACK_data/cellPACK_database_1.1.0/';
@@ -138,9 +138,7 @@ const StructureFromAssemblies = PluginStateTransform.BuiltIn({
                 }
                 structure = builder.getStructure();
                 for( let i = 0, il = structure.models.length; i < il; ++i) {
-                    const { trajectoryInfo } = structure.models[i];
-                    trajectoryInfo.size = il;
-                    trajectoryInfo.index = i;
+                    Model.TrajectoryInfo.set(structure.models[i], { size: il, index: i });
                 }
             }
             return new PSO.Molecule.Structure(structure, { label: a.label, description: `${a.description}` });
@@ -150,55 +148,3 @@ const StructureFromAssemblies = PluginStateTransform.BuiltIn({
         b?.data.customPropertyDescriptors.dispose();
     }
 });
-
-// export { GetAllAssamblyinOneStructure };
-// type GetAllAssamblyinOneStructure = typeof GetAllAssamblyinOneStructure
-// const GetAllAssamblyinOneStructure = PluginStateTransform.BuiltIn({
-//     name: 'get assambly from structure',
-//     display: { name: 'get assambly from structure' },
-//     isDecorator: true,
-//     from: PSO.Molecule.Structure,
-//     to: PSO.Molecule.Structure,
-//     params(a) {
-//         return { };
-//     }
-// })({
-//     apply({ a, params }) {
-//         return Task.create('Build Structure Assemblies', async ctx => {
-//             // TODO: optimze
-//             // TODO: think of ways how to fast-track changes to this for animations
-//             const initial_structure = a.data;
-//             const structures: Structure[] = [];
-//             let structure: Structure = initial_structure;
-//             // the list of asambly *?
-//             const symmetry = ModelSymmetry.Provider.get(initial_structure.model);
-//             if (symmetry){
-//                 if (symmetry.assemblies.length !== 0) {
-//                     for (const a of symmetry.assemblies) {
-//                         const s = await StructureSymmetry.buildAssembly(initial_structure, a.id!).runInContext(ctx);
-//                         structures.push(s);
-//                     }
-//                     const builder = Structure.Builder({ label: name });
-//                     let offsetInvariantId = 0;
-//                     for (const s of structures) {
-//                         let maxInvariantId = 0;
-//                         for (const u of s.units) {
-//                             const invariantId = u.invariantId + offsetInvariantId;
-//                             if (u.invariantId > maxInvariantId) maxInvariantId = u.invariantId;
-//                             builder.addUnit(u.kind, u.model, u.conformation.operator, u.elements, Unit.Trait.None, invariantId);
-//                         }
-//                         offsetInvariantId += maxInvariantId + 1;
-//                     }
-//                     structure = builder.getStructure();
-//                     for( let i = 0, il = structure.models.length; i < il; ++i) {
-//                         const { trajectoryInfo } = structure.models[i];
-//                         trajectoryInfo.size = il;
-//                         trajectoryInfo.index = i;
-//                     }
-//                 }
-//             }
-//             return new PSO.Molecule.Structure(structure, { label: a.label, description: `${a.description}` });
-//         });
-//     }
-// });
-

+ 1 - 4
src/mol-model-formats/structure/basic/parser.ts

@@ -29,8 +29,7 @@ export async function createModels(data: BasicData, format: ModelFormat, ctx: Ru
         : await readStandard(ctx, data, properties, format);
 
     for (let i = 0; i < models.length; i++) {
-        models[i].trajectoryInfo.index = i;
-        models[i].trajectoryInfo.size = models.length;
+        Model.TrajectoryInfo.set(models[i], { index: i, size: models.length });
     }
 
     return models;
@@ -69,7 +68,6 @@ function createStandardModel(data: BasicData, atom_site: AtomSite, sourceIndex:
         entry,
         sourceData: format,
         modelNum,
-        trajectoryInfo: { index: 0, size: 1 },
         entities,
         sequence,
         atomicHierarchy: atomic.hierarchy,
@@ -108,7 +106,6 @@ function createIntegrativeModel(data: BasicData, ihm: CoarseData, properties: Mo
         entry,
         sourceData: format,
         modelNum: ihm.model_id,
-        trajectoryInfo: { index: 0, size: 1 },
         entities: ihm.entities,
         sequence,
         atomicHierarchy: atomic.hierarchy,

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

@@ -48,14 +48,6 @@ export interface Model extends Readonly<{
      */
     modelNum: number,
 
-    /**
-     * This is a hack to allow "model-index coloring"
-     */
-    trajectoryInfo: {
-        index: number,
-        size: number
-    },
-
     sourceData: ModelFormat,
 
     entities: Entities,
@@ -127,8 +119,7 @@ export namespace Model {
             let index = 0;
             for (const m of trajectory) {
                 IndexPairBonds.Provider.set(m, indexPairBonds);
-                m.trajectoryInfo.index = index++;
-                m.trajectoryInfo.size = trajectory.length;
+                TrajectoryInfo.set(m, { index: index++, size: trajectory.length });
             }
             return trajectory;
         });
@@ -142,6 +133,17 @@ export namespace Model {
         return center;
     }
 
+    const TrajectoryInfoProp = '__TrajectoryInfo__';
+    export type TrajectoryInfo = { readonly index: number, readonly size: number }
+    export const TrajectoryInfo = {
+        get(model: Model): TrajectoryInfo {
+            return model._staticPropertyData[TrajectoryInfoProp] || { index: 0, size: 1 };
+        },
+        set(model: Model, trajectoryInfo: TrajectoryInfo) {
+            return model._staticPropertyData[TrajectoryInfoProp] = trajectoryInfo;
+        }
+    };
+
     //
 
     export function hasCarbohydrate(model: Model): boolean {

+ 8 - 7
src/mol-plugin-ui/structure/source.tsx

@@ -17,6 +17,7 @@ import { UpdateTransformControl } from '../state/update-transform';
 import { StructureSelectionStatsControls } from './selection';
 import { StateSelection } from '../../mol-state';
 import { MoleculeSvg, BookmarksOutlinedSvg } from '../controls/icons';
+import { Model } from '../../mol-model/structure';
 
 interface StructureSourceControlState extends CollapsableState {
     isBusy: boolean,
@@ -47,15 +48,15 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
         switch (ref.kind) {
             case 'model': {
                 const model = ref.cell.obj?.data;
-                if (model?.trajectoryInfo.size! > 1) {
-                    label = `${ref.cell.obj?.data.entryId} | Model ${model?.trajectoryInfo.index! + 1} of ${model?.trajectoryInfo.size}`;
+                if (model && Model.TrajectoryInfo.get(model).size > 1) {
+                    label = `${ref.cell.obj?.data.entryId} | Model ${Model.TrajectoryInfo.get(model).index + 1} of ${Model.TrajectoryInfo.get(model).size}`;
                 }
                 label = `${ref.cell.obj?.data.entryId} | ${ref.cell.obj?.label}`; break;
             }
             case 'structure': {
                 const model = ref.cell.obj?.data.models[0];
-                if (model && model.trajectoryInfo.size! > 1) {
-                    label = `${model.entryId} | ${ref.cell.obj?.label} (Model ${model?.trajectoryInfo.index! + 1} of ${model?.trajectoryInfo.size})`; break;
+                if (model && Model.TrajectoryInfo.get(model).size! > 1) {
+                    label = `${model.entryId} | ${ref.cell.obj?.label} (Model ${Model.TrajectoryInfo.get(model).index + 1} of ${Model.TrajectoryInfo.get(model).size})`; break;
                 } else if (model) {
                     label = `${model.entryId} | ${ref.cell.obj?.label}`; break;
                 } else {
@@ -148,8 +149,8 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
 
             if (models.length === 1) {
                 const model = models[0].cell.obj?.data;
-                if (model?.trajectoryInfo.size! > 1) {
-                    return `${t?.cell.obj?.label} | Model ${model?.trajectoryInfo.index! + 1} of ${model?.trajectoryInfo.size}`;
+                if (model && Model.TrajectoryInfo.get(model).size > 1) {
+                    return `${t?.cell.obj?.label} | Model ${Model.TrajectoryInfo.get(model).index + 1} of ${Model.TrajectoryInfo.get(model).size}`;
                 } else {
                     return `${t?.cell.obj?.label} | Model`;
                 }
@@ -225,7 +226,7 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
         if (selection.structures.length !== 1) return null;
         const m = selection.structures[0].model;
         if (!m || m.cell.transform.transformer !== StateTransforms.Model.ModelFromTrajectory) return null;
-        if (m.cell.obj?.data.trajectoryInfo.size! <= 1) return null;
+        if (!m.cell.obj || Model.TrajectoryInfo.get(m.cell.obj.data).size <= 1) return null;
 
         const params = m.cell.params?.definition;
         if (!params) return null;

+ 7 - 7
src/mol-theme/color/model-index.ts

@@ -6,7 +6,7 @@
 
 import { Color } from '../../mol-util/color';
 import { Location } from '../../mol-model/location';
-import { StructureElement, Bond } from '../../mol-model/structure';
+import { StructureElement, Bond, Model } from '../../mol-model/structure';
 import { ColorTheme, LocationColor } from '../color';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../../mol-theme/theme';
@@ -32,21 +32,21 @@ export function ModelIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<Mod
         const { models } = ctx.structure.root;
 
         let size = 0;
-        for (const m of models) size = Math.max(size, m.trajectoryInfo.size);
+        for (const m of models) size = Math.max(size, Model.TrajectoryInfo.get(m)?.size || 0);
 
         const palette = getPalette(size, props);
         legend = palette.legend;
         const modelColor = new Map<number, Color>();
         for (let i = 0, il = models.length; i < il; ++i) {
-            const idx = models[i].trajectoryInfo.index;
-            modelColor.set(models[i].trajectoryInfo.index, palette.color(idx));
+            const idx = Model.TrajectoryInfo.get(models[i])?.index || 0;
+            modelColor.set(idx, palette.color(idx));
         }
 
         color = (location: Location): Color => {
             if (StructureElement.Location.is(location)) {
-                return modelColor.get(location.unit.model.trajectoryInfo.index)!;
+                return modelColor.get(Model.TrajectoryInfo.get(location.unit.model).index)!;
             } else if (Bond.isLocation(location)) {
-                return modelColor.get(location.aUnit.model.trajectoryInfo.index)!;
+                return modelColor.get(Model.TrajectoryInfo.get(location.aUnit.model).index)!;
             }
             return DefaultColor;
         };
@@ -71,5 +71,5 @@ export const ModelIndexColorThemeProvider: ColorTheme.Provider<ModelIndexColorTh
     factory: ModelIndexColorTheme,
     getParams: getModelIndexColorThemeParams,
     defaultValues: PD.getDefaultValues(ModelIndexColorThemeParams),
-    isApplicable: (ctx: ThemeDataContext) => !!ctx.structure && ctx.structure.elementCount > 0 && ctx.structure.models[0].trajectoryInfo.size > 1
+    isApplicable: (ctx: ThemeDataContext) => !!ctx.structure && ctx.structure.elementCount > 0 && Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1
 };