Переглянути джерело

tweak CCD coordinate type handling

Alexander Rose 1 рік тому
батько
коміт
f0e725f65c

+ 6 - 7
src/extensions/wwpdb/ccd/representation.ts

@@ -11,7 +11,7 @@ import { StateTransforms } from '../../../mol-plugin-state/transforms';
 import { StructureRepresentationPresetProvider, presetStaticComponent } from '../../../mol-plugin-state/builder/structure/representation-preset';
 import { PluginContext } from '../../../mol-plugin/context';
 import { Mat4 } from '../../../mol-math/linear-algebra';
-import { Model, Structure } from '../../../mol-model/structure';
+import { Structure } from '../../../mol-model/structure';
 import { CCDFormat } from '../../../mol-model-formats/structure/mmcif';
 import { MinimizeRmsd } from '../../../mol-math/linear-algebra/3d/minimize-rmsd';
 import { SetUtils } from '../../../mol-util/set';
@@ -53,8 +53,7 @@ export const ChemicalCompontentTrajectoryHierarchyPreset = TrajectoryHierarchyPr
 
         // degenerate case where either model or ideal coordinates are missing
         if (tr.frameCount !== 2) {
-            // variables are 1st model but not necessarily ideal coordinates -- consult trajectory index to distinguish ideal/model coordinates
-            const coordinateType = Model.TrajectoryInfo.get(idealModel.obj!.data).index === 0 ? CCDFormat.CoordinateType.Ideal : CCDFormat.CoordinateType.Model;
+            const coordinateType = CCDFormat.CoordinateType.get(idealModel.obj!.data);
             await builder.representation.applyPreset(idealStructureProperties, representationPreset, { ...representationPresetParams, coordinateType });
 
             return { models: [idealModel], structures: [idealStructure] };
@@ -70,7 +69,7 @@ export const ChemicalCompontentTrajectoryHierarchyPreset = TrajectoryHierarchyPr
         if (!params.showOriginalCoordinates) {
             const [a, b] = getPositionTables(idealStructure.obj!.data, modelStructure.obj!.data);
             if (!a) {
-                plugin.log.warn(`Cannot align ligands whose atom sets are disjoint.`);
+                plugin.log.warn(`Cannot align chemical components whose atom sets are disjoint.`);
             } else {
                 const { bTransform, rmsd } = MinimizeRmsd.compute({ a, b });
                 await transform(plugin, modelStructure.cell!, bTransform);
@@ -78,8 +77,8 @@ export const ChemicalCompontentTrajectoryHierarchyPreset = TrajectoryHierarchyPr
             }
         }
 
-        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' });
+        await builder.representation.applyPreset(idealStructureProperties, representationPreset, { ...representationPresetParams, coordinateType: 'ideal', isHidden: params.shownCoordinateType === 'model' });
+        await builder.representation.applyPreset(modelStructureProperties, representationPreset, { ...representationPresetParams, coordinateType: 'model', isHidden: params.shownCoordinateType === 'ideal' });
 
         return { models: [idealModel, modelModel], structures: [idealStructure, modelStructure] };
     }
@@ -135,7 +134,7 @@ export const ChemicalComponentPreset = StructureRepresentationPresetProvider({
     },
     params: () => ({
         ...StructureRepresentationPresetProvider.CommonParams,
-        coordinateType: PD.Select<CCDFormat.CoordinateType>(CCDFormat.CoordinateType.Ideal, PD.arrayToOptions(Object.keys(CCDFormat.CoordinateType) as CCDFormat.CoordinateType[])),
+        coordinateType: PD.Select<CCDFormat.CoordinateType>('ideal', PD.arrayToOptions(['ideal', 'model'])),
         isHidden: PD.Boolean(false)
     }),
     async apply(ref, params, plugin) {

+ 21 - 12
src/mol-model-formats/structure/mmcif.ts

@@ -119,10 +119,18 @@ namespace CCDFormat {
         db: CCD_Database,
         frame: CifFrame
     }
-    export enum CoordinateType {
-        Ideal = 'ideal',
-        Model = 'model'
-    }
+
+    const CoordinateTypeProp = '__CcdCoordinateType__';
+    export type CoordinateType = 'ideal' | 'model'
+    export const CoordinateType = {
+        get(model: Model): CoordinateType | undefined {
+            return model._staticPropertyData[CoordinateTypeProp];
+        },
+        set(model: Model, type: CoordinateType) {
+            return model._staticPropertyData[CoordinateTypeProp] = type;
+        }
+    };
+
     export function is(x?: ModelFormat): x is CCDFormat {
         return x?.kind === 'CCD';
     }
@@ -139,15 +147,15 @@ export function trajectoryFromCCD(frame: CifFrame): Task<Trajectory> {
 }
 
 async function createCcdModels(data: CCD_Database, format: CCDFormat, ctx: RuntimeContext) {
-    const ideal = await createCcdModel(data, format, { coordinateType: CCDFormat.CoordinateType.Ideal, cartn_x: 'pdbx_model_Cartn_x_ideal', cartn_y: 'pdbx_model_Cartn_y_ideal', cartn_z: 'pdbx_model_Cartn_z_ideal' }, ctx);
-    const model = await createCcdModel(data, format, { coordinateType: CCDFormat.CoordinateType.Model, cartn_x: 'model_Cartn_x', cartn_y: 'model_Cartn_y', cartn_z: 'model_Cartn_z' }, ctx);
+    const ideal = await createCcdModel(data, format, { coordinateType: 'ideal', cartn_x: 'pdbx_model_Cartn_x_ideal', cartn_y: 'pdbx_model_Cartn_y_ideal', cartn_z: 'pdbx_model_Cartn_z_ideal' }, ctx);
+    const model = await createCcdModel(data, format, { coordinateType: 'model', cartn_x: 'model_Cartn_x', cartn_y: 'model_Cartn_y', cartn_z: 'model_Cartn_z' }, ctx);
 
     const models = [];
-    if (ideal) models.push(ideal.representative);
-    if (model) models.push(model.representative);
-    // model index tags models as either 'ideal' (index 0) or 'model' (index 1)
-    if (ideal) Model.TrajectoryInfo.set(models[0], { index: 0, size: models.length });
-    if (model) Model.TrajectoryInfo.set(models[models.length - 1], { index: 1, size: models.length });
+    if (ideal) models.push(ideal);
+    if (model) models.push(model);
+    for (let i = 0, il = models.length; i < il; ++i) {
+        Model.TrajectoryInfo.set(models[i], { index: i, size: models.length });
+    }
 
     return new ArrayTrajectory(models);
 }
@@ -229,6 +237,7 @@ async function createCcdModel(data: CCD_Database, format: CCDFormat, props: CCDP
     const first = models.representative;
     const entries = ComponentBond.getEntriesFromChemCompBond(chem_comp_bond);
     ComponentBond.Provider.set(first, { data: chem_comp_bond, entries });
+    CCDFormat.CoordinateType.set(first, coordinateType);
 
-    return models;
+    return models.representative;
 }