Browse Source

SecondaryStructure improvements

- use SecondaryStructureProvider in StructureProperties
- renamed mmCIF source to model
Alexander Rose 5 years ago
parent
commit
4525b98288

+ 10 - 8
src/mol-model-props/computed/secondary-structure.ts

@@ -1,10 +1,10 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { CustomPropertyDescriptor, Structure } from '../../mol-model/structure';
+import { Structure } from '../../mol-model/structure';
 import { DSSPComputationParams, DSSPComputationProps, computeUnitDSSP } from './secondary-structure/dssp';
 import { SecondaryStructure } from '../../mol-model/structure/model/properties/seconday-structure';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
@@ -13,9 +13,10 @@ import { CustomStructureProperty } from '../common/custom-structure-property';
 import { CustomProperty } from '../common/custom-property';
 import { ModelSecondaryStructure } from '../../mol-model-formats/structure/property/secondary-structure';
 import { MmcifFormat } from '../../mol-model-formats/structure/mmcif';
+import { CustomPropertyDescriptor } from '../../mol-model/structure/common/custom-property';
 
 function getSecondaryStructureParams(data?: Structure) {
-    let defaultType = 'mmcif' as 'mmcif' | 'dssp'
+    let defaultType = 'model' as 'model' | 'dssp'
     if (data) {
         defaultType = 'dssp'
         for (let i = 0, il = data.models.length; i < il; ++i) {
@@ -27,7 +28,7 @@ function getSecondaryStructureParams(data?: Structure) {
                 ) {
                     // if there is any secondary structure definition given or if there is
                     // an archival model, don't calculate dssp by default
-                    defaultType = 'mmcif'
+                    defaultType = 'model'
                     break
                 }
             }
@@ -35,9 +36,9 @@ function getSecondaryStructureParams(data?: Structure) {
     }
     return {
         type: PD.MappedStatic(defaultType, {
-            'mmcif': PD.EmptyGroup({ label: 'mmCIF' }),
+            'model': PD.EmptyGroup({ label: 'Model' }),
             'dssp': PD.Group(DSSPComputationParams, { label: 'DSSP', isFlat: true })
-        }, { options: [['mmcif', 'mmCIF'], ['dssp', 'DSSP']] })
+        }, { options: [['model', 'Model'], ['dssp', 'DSSP']] })
     }
 }
 
@@ -45,6 +46,7 @@ export const SecondaryStructureParams = getSecondaryStructureParams()
 export type SecondaryStructureParams = typeof SecondaryStructureParams
 export type SecondaryStructureProps = PD.Values<SecondaryStructureParams>
 
+/** Maps `unit.id` to `SecondaryStructure` */
 export type SecondaryStructureValue = Map<number, SecondaryStructure>
 
 export const SecondaryStructureProvider: CustomStructureProperty.Provider<SecondaryStructureParams, SecondaryStructureValue> = CustomStructureProperty.createProvider({
@@ -61,7 +63,7 @@ export const SecondaryStructureProvider: CustomStructureProperty.Provider<Second
         const p = { ...PD.getDefaultValues(SecondaryStructureParams), ...props }
         switch (p.type.name) {
             case 'dssp': return await computeDssp(data, p.type.params)
-            case 'mmcif': return await computeMmcif(data)
+            case 'model': return await computeModel(data)
         }
     }
 })
@@ -80,7 +82,7 @@ async function computeDssp(structure: Structure, props: DSSPComputationProps): P
     return map
 }
 
-async function computeMmcif(structure: Structure): Promise<SecondaryStructureValue> {
+async function computeModel(structure: Structure): Promise<SecondaryStructureValue> {
     const map = new Map<number, SecondaryStructure>()
     for (let i = 0, il = structure.unitSymmetryGroups.length; i < il; ++i) {
         const u = structure.unitSymmetryGroups[i].units[0]

+ 7 - 10
src/mol-model/structure/structure/properties.ts

@@ -1,14 +1,15 @@
 /**
- * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
 import StructureElement from './element'
 import Unit from './unit'
 import { VdwRadius } from '../model/properties/atomic';
-import { ModelSecondaryStructure } from '../../../mol-model-formats/structure/property/secondary-structure';
 import { SecondaryStructureType } from '../model/types';
+import { SecondaryStructureProvider } from '../../../mol-model-props/computed/secondary-structure';
 
 function p<T>(p: StructureElement.Property<T>) { return p; }
 
@@ -99,19 +100,15 @@ const residue = {
     isNonStandard: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.properties.chemicalComponentMap.get(compId(l))!.mon_nstd_flag[0] !== 'y'),
     hasMicroheterogeneity: p(hasMicroheterogeneity),
     microheterogeneityCompIds: p(microheterogeneityCompIds),
-    // TODO implement as symbol in SecondaryStructureProvider (not ModelSecondaryStructure.Provider)
     secondary_structure_type: p(l => {
         if (!Unit.isAtomic(l.unit)) notAtomic()
-        const secondaryStructure = ModelSecondaryStructure.Provider.get(l.unit.model)
-        if (secondaryStructure) return secondaryStructure.type[l.unit.residueIndex[l.element]]
-        else return SecondaryStructureType.Flag.NA
+        const secStruc = SecondaryStructureProvider.get(l.structure).value?.get(l.unit.id)
+        return secStruc?.type[l.unit.residueIndex[l.element]] ?? SecondaryStructureType.Flag.NA
     }),
-    // TODO implement as symbol in SecondaryStructureProvider (not ModelSecondaryStructure.Provider)
     secondary_structure_key: p(l => {
         if (!Unit.isAtomic(l.unit)) notAtomic()
-        const secondaryStructure = ModelSecondaryStructure.Provider.get(l.unit.model)
-        if (secondaryStructure) return secondaryStructure.key[l.unit.residueIndex[l.element]]
-        else return -1
+        const secStruc = SecondaryStructureProvider.get(l.structure).value?.get(l.unit.id)
+        return secStruc?.key[l.unit.residueIndex[l.element]] ?? -1
     }),
     chem_comp_type: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.properties.chemicalComponentMap.get(compId(l))!.type),
 }