diff --git a/src/mol-model-formats/structure/mmcif/parser.ts b/src/mol-model-formats/structure/mmcif/parser.ts index 97d6c72c2e0444d9f81cb9aa9627138b12131106..29a3c2e3ad5b573d009157cdd73bfcb2474db535 100644 --- a/src/mol-model-formats/structure/mmcif/parser.ts +++ b/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 } diff --git a/src/mol-model/structure/model/types.ts b/src/mol-model/structure/model/types.ts index 58b63f4cf515596089de11646a591c61ea3ac2d8..64863fcf0610b7ac75f9a7456e65db462bcc0a8d 100644 --- a/src/mol-model/structure/model/types.ts +++ b/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)) {