Browse Source

mol-model & formats: added fallback when chem_comp category is missing

David Sehnal 5 years ago
parent
commit
58b1d7e0eb

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

@@ -23,7 +23,7 @@ import { getSecondaryStructure } from './secondary-structure';
 import { getSequence } from './sequence';
 import { sortAtomSite } from './sort';
 import { StructConn } from './bonds/struct_conn';
-import { getMoleculeType, MoleculeType, getEntityType, getEntitySubtype } from '../../../mol-model/structure/model/types';
+import { getMoleculeType, MoleculeType, getEntityType, getEntitySubtype, getDefaultChemicalComponent } from '../../../mol-model/structure/model/types';
 import { ModelFormat } from '../format';
 import { SaccharideComponentMap, SaccharideComponent, SaccharidesSnfgMap, SaccharideCompIdMap, UnknownSaccharideComponent } from '../../../mol-model/structure/structure/carbohydrates/constants';
 import mmCIF_Format = ModelFormat.mmCIF
@@ -127,9 +127,17 @@ function getMissingResidues(format: mmCIF_Format): Model['properties']['missingR
 function getChemicalComponentMap(format: mmCIF_Format): Model['properties']['chemicalComponentMap'] {
     const map = new Map<string, ChemicalComponent>();
     const { chem_comp } = format.data
-    const { id } = chem_comp
-    for (let i = 0, il = id.rowCount; i < il; ++i) {
-        map.set(id.value(i), Table.getRow(chem_comp, i))
+
+    if (chem_comp._rowCount > 0) {
+        const { id } = chem_comp
+        for (let i = 0, il = id.rowCount; i < il; ++i) {
+            map.set(id.value(i), Table.getRow(chem_comp, i))
+        }
+    } else {
+        const uniqueNames = getUniqueComponentNames(format);
+        uniqueNames.forEach(n => {
+            map.set(n, getDefaultChemicalComponent(n));
+        });
     }
     return map
 }

+ 15 - 1
src/mol-model/structure/model/types.ts

@@ -9,7 +9,7 @@ import BitFlags from '../../../mol-util/bit-flags'
 import { SaccharideCompIdMap } from '../structure/carbohydrates/constants';
 import { mmCIF_Schema } from '../../../mol-io/reader/cif/schema/mmcif';
 import { SetUtils } from '../../../mol-util/set';
-import { EntitySubtype } from './properties/common';
+import { EntitySubtype, ChemicalComponent } from './properties/common';
 
 const _esCache = (function () {
     const cache = Object.create(null);
@@ -245,6 +245,20 @@ export function getComponentType(compId: string): mmCIF_Schema['chem_comp']['typ
     }
 }
 
+export function getDefaultChemicalComponent(compId: string): ChemicalComponent {
+    // TODO: this is to make the chem_comp_type property work if chem_comp category is not present.
+    // should we try to set the formula etc better?
+    return {
+        formula: '',
+        formula_weight: 0,
+        id: compId,
+        name: compId,
+        mon_nstd_flag: 'n',
+        pdbx_synonyms: [],
+        type: getComponentType(compId)
+    };
+}
+
 export function getEntityType(compId: string): mmCIF_Schema['entity']['type']['T'] {
     compId = compId.toUpperCase()
     if (WaterNames.has(compId)) {