Ver Fonte

added Model helpers

- .hasCarbohydrate
- .hasProtein
- .hasNucleic
Alexander Rose há 4 anos atrás
pai
commit
86c09ead98

+ 21 - 0
src/mol-model/structure/model/model.ts

@@ -144,6 +144,27 @@ export namespace Model {
 
     //
 
+    export function hasCarbohydrate(model: Model): boolean {
+        return model.properties.saccharideComponentMap.size > 0;
+    }
+
+    export function hasProtein(model: Model): boolean {
+        const { subtype } = model.entities;
+        for (let i = 0, il = subtype.rowCount; i < il; ++i) {
+            if (subtype.value(i).startsWith('polypeptide')) return true;
+        }
+        return false;
+    }
+
+    export function hasNucleic(model: Model): boolean {
+        const { subtype } = model.entities;
+        for (let i = 0, il = subtype.rowCount; i < il; ++i) {
+            const s = subtype.value(i);
+            if (s.endsWith('ribonucleotide hybrid') || s.endsWith('ribonucleotide')) return true;
+        }
+        return false;
+    }
+
     export function isFromPdbArchive(model: Model): boolean {
         if (!MmcifFormat.is(model.sourceData)) return false;
         const { db } = model.sourceData.data;

+ 2 - 2
src/mol-repr/structure/representation/carbohydrate.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Structure } from '../../../mol-model/structure';
+import { Structure, Model } from '../../../mol-model/structure';
 import { Representation, RepresentationContext, RepresentationParamsGetter } from '../../../mol-repr/representation';
 import { ThemeRegistryContext } from '../../../mol-theme/theme';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
@@ -46,6 +46,6 @@ export const CarbohydrateRepresentationProvider = StructureRepresentationProvide
     defaultColorTheme: { name: 'carbohydrate-symbol' },
     defaultSizeTheme: { name: 'uniform' },
     isApplicable: (structure: Structure) => {
-        return structure.models.reduce((a, v) => a + v.properties.saccharideComponentMap.size, 0) > 0;
+        return structure.models.some(m => Model.hasCarbohydrate(m));
     }
 });

+ 2 - 2
src/mol-theme/color/carbohydrate-symbol.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { StructureElement, Bond, ElementIndex, Unit } from '../../mol-model/structure';
+import { StructureElement, Bond, ElementIndex, Unit, Model } from '../../mol-model/structure';
 import { SaccharideColors, MonosaccharidesColorTable } from '../../mol-model/structure/structure/carbohydrates/constants';
 import { Location } from '../../mol-model/location';
 import { ColorTheme, LocationColor } from '../color';
@@ -68,6 +68,6 @@ export const CarbohydrateSymbolColorThemeProvider: ColorTheme.Provider<Carbohydr
     getParams: getCarbohydrateSymbolColorThemeParams,
     defaultValues: PD.getDefaultValues(CarbohydrateSymbolColorThemeParams),
     isApplicable: (ctx: ThemeDataContext) => {
-        return !!ctx.structure && ctx.structure.models.reduce((a, v) => a + v.properties.saccharideComponentMap.size, 0) > 0;
+        return !!ctx.structure && ctx.structure.models.some(m => Model.hasCarbohydrate(m));
     }
 };