ソースを参照

rather heavy-handed tracking of ideal/model coords

Sebastian Bittrich 1 年間 前
コミット
35439f01aa

+ 2 - 0
src/mol-model-formats/structure/mmcif.ts

@@ -146,6 +146,8 @@ async function createCcdModels(data: CCD_Database, format: CCDFormat, ctx: Runti
     if (model) models.push(model.representative);
     for (let i = 0, il = models.length; i < il; i++) {
         Model.TrajectoryInfo.set(models[i], { index: i, size: models.length });
+        // TODO smarter way to 'tag' model as ideal/model
+        Model.CCDCoordinateType.set(models[i], { coordinateType: models[i] === ideal?.representative ? CCDFormat.CoordinateType.Ideal : CCDFormat.CoordinateType.Model });
     }
 
     return new ArrayTrajectory(models);

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

@@ -20,7 +20,7 @@ import { Topology } from '../topology';
 import { Task } from '../../../mol-task';
 import { IndexPairBonds } from '../../../mol-model-formats/structure/property/bonds/index-pair';
 import { createModels } from '../../../mol-model-formats/structure/basic/parser';
-import { MmcifFormat } from '../../../mol-model-formats/structure/mmcif';
+import { CCDFormat, MmcifFormat } from '../../../mol-model-formats/structure/mmcif';
 import { ChainIndex, ElementIndex } from './indexing';
 import { SymmetryOperator } from '../../../mol-math/geometry';
 import { ModelSymmetry } from '../../../mol-model-formats/structure/property/symmetry';
@@ -200,6 +200,17 @@ export namespace Model {
         }
     };
 
+    const CCDCoordinateTypeProp = '__CCDCoordinateType__';
+    export type CCDCoordinateType = { readonly coordinateType: CCDFormat.CoordinateType }
+    export const CCDCoordinateType = {
+        get(model: Model): CCDCoordinateType {
+            return model._dynamicPropertyData[CCDCoordinateTypeProp] || { coordinateType: CCDFormat.CoordinateType.Ideal };
+        },
+        set(model: Model, ccdCoordinateType: CCDCoordinateType) {
+            return model._dynamicPropertyData[CCDCoordinateTypeProp] = ccdCoordinateType;
+        }
+    };
+
     const AsymIdCountProp = '__AsymIdCount__';
     export type AsymIdCount = { readonly auth: number, readonly label: number }
     export const AsymIdCount = {

+ 15 - 6
src/mol-plugin-state/builder/structure/hierarchy-preset.ts

@@ -128,7 +128,7 @@ const allModels = TrajectoryHierarchyPresetProvider({
 const CCDParams = (a: PluginStateObject.Molecule.Trajectory | undefined, plugin: PluginContext) => ({
     representationPresetParams: PD.Optional(PD.Group(StructureRepresentationPresetProvider.CommonParams)),
     showOriginalCoordinates: PD.Optional(PD.Boolean(true, { description: `Show original coordinates for 'model' and 'ideal' structure and do not align them.` })),
-    shownCoordinateType: PD.Select('ideal', PD.arrayToOptions(['ideal', 'model', 'both'] as const), { description: `What coordinate sets are visibile.` }),
+    shownCoordinateType: PD.Select('ideal', PD.arrayToOptions(['ideal', 'model', 'both'] as const), { description: `What coordinate sets are visible.` }),
     ...CommonParams(a, plugin)
 });
 
@@ -139,7 +139,7 @@ const ccd = TrajectoryHierarchyPresetProvider({
         description: 'Shows molecules from the Chemical Component Dictionary.'
     },
     isApplicable: o => {
-        return CCDFormat.is(o.data.representative.sourceData) && o.data.frameCount === 2;
+        return CCDFormat.is(o.data.representative.sourceData);
     },
     params: CCDParams,
     async apply(trajectory, params, plugin) {
@@ -154,6 +154,19 @@ const ccd = TrajectoryHierarchyPresetProvider({
         const idealStructure = await builder.createStructure(idealModelProperties || idealModel, { name: 'model', params: {} });
         const idealStructureProperties = await builder.insertStructureProperties(idealStructure, params.structureProperties);
 
+        const representationPreset = params.representationPreset || PresetStructureRepresentations['chemical-component'].id;
+        const representationPresetParams = params.representationPresetParams || {};
+        if (representationPresetParams.ignoreHydrogens === undefined) representationPresetParams.ignoreHydrogens = true;
+
+        // degenerate case where either model or ideal coordinates are missing
+        if (tr.frameCount !== 2) {
+            // 'ideal' references 1st model but it might actually be 'model'
+            const coordinateType = Model.CCDCoordinateType.get(idealModel.obj?.data!).coordinateType;
+            await builder.representation.applyPreset(idealStructureProperties, representationPreset, { ...representationPresetParams, coordinateType });
+
+            return { models: [idealModel], structures: [idealStructure] };
+        }
+
         const modelModel = await builder.createModel(trajectory, { modelIndex: 1 });
         const modelModelProperties = await builder.insertModelProperties(modelModel, params.modelProperties, { isCollapsed: true });
 
@@ -172,10 +185,6 @@ const ccd = TrajectoryHierarchyPresetProvider({
             }
         }
 
-        const representationPreset = params.representationPreset || PresetStructureRepresentations['chemical-component'].id;
-        const representationPresetParams = params.representationPresetParams || {};
-        if (representationPresetParams.ignoreHydrogens === undefined) representationPresetParams.ignoreHydrogens = true;
-
         await builder.representation.applyPreset(idealStructureProperties, representationPreset, { ...representationPresetParams, coordinateType: CCDFormat.CoordinateType.Ideal, isHidden: params.shownCoordinateType === 'model' });
         await builder.representation.applyPreset(modelStructureProperties, representationPreset, { ...representationPresetParams, coordinateType: CCDFormat.CoordinateType.Model, isHidden: params.shownCoordinateType === 'ideal' });