Skip to content
Snippets Groups Projects
Commit 5fcf27eb authored by Alexander Rose's avatar Alexander Rose
Browse files

check for carb comps before calculating carbs

parent 48d3c615
Branches
Tags
No related merge requests found
/** /**
* Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { Column, Table } from 'mol-data/db'; import { Column, Table } from 'mol-data/db';
...@@ -112,7 +113,7 @@ function getSaccharideComponentMap(format: mmCIF_Format): SaccharideComponentMap ...@@ -112,7 +113,7 @@ function getSaccharideComponentMap(format: mmCIF_Format): SaccharideComponentMap
const map = new Map<string, SaccharideComponent>(); const map = new Map<string, SaccharideComponent>();
const { pdbx_chem_comp_identifier } = format.data const { pdbx_chem_comp_identifier } = format.data
if (pdbx_chem_comp_identifier._rowCount > 0) { if (pdbx_chem_comp_identifier._rowCount > 0) {
const { type, comp_id, identifier } = pdbx_chem_comp_identifier const { comp_id, type, identifier } = pdbx_chem_comp_identifier
for (let i = 0, il = pdbx_chem_comp_identifier._rowCount; i < il; ++i) { for (let i = 0, il = pdbx_chem_comp_identifier._rowCount; i < il; ++i) {
if (type.value(i) === 'SNFG CARB SYMBOL') { if (type.value(i) === 'SNFG CARB SYMBOL') {
const snfgName = identifier.value(i) const snfgName = identifier.value(i)
...@@ -124,16 +125,20 @@ function getSaccharideComponentMap(format: mmCIF_Format): SaccharideComponentMap ...@@ -124,16 +125,20 @@ function getSaccharideComponentMap(format: mmCIF_Format): SaccharideComponentMap
} }
} }
} }
} else { } else if (format.data.chem_comp._rowCount > 0) {
SaccharideCompIdMap.forEach((v, k) => map.set(k, v))
const { id, type } = format.data.chem_comp const { id, type } = format.data.chem_comp
for (let i = 0, il = id.rowCount; i < il; ++i) { for (let i = 0, il = id.rowCount; i < il; ++i) {
const _id = id.value(i) const _id = id.value(i)
const _type = type.value(i) const _type = type.value(i)
if (!map.has(_id) && getMoleculeType(_type, _id) === MoleculeType.saccharide) { if (SaccharideCompIdMap.has(_id)) {
map.set(_id, SaccharideCompIdMap.get(_id)!)
} else if (!map.has(_id) && getMoleculeType(_type, _id) === MoleculeType.saccharide) {
map.set(_id, UnknownSaccharideComponent) map.set(_id, UnknownSaccharideComponent)
} }
} }
} else {
// TODO check if present in format.data.atom_site.label_comp_id
SaccharideCompIdMap.forEach((v, k) => map.set(k, v))
} }
return map return map
} }
......
...@@ -17,7 +17,7 @@ import { getPositionMatrix } from '../../util'; ...@@ -17,7 +17,7 @@ import { getPositionMatrix } from '../../util';
import StructureElement from '../element'; import StructureElement from '../element';
import Structure from '../structure'; import Structure from '../structure';
import Unit from '../unit'; import Unit from '../unit';
import { CarbohydrateElement, CarbohydrateLink, Carbohydrates, CarbohydrateTerminalLink, PartialCarbohydrateElement } from './data'; import { CarbohydrateElement, CarbohydrateLink, Carbohydrates, CarbohydrateTerminalLink, PartialCarbohydrateElement, EmptyCarbohydrates } from './data';
import { UnitRings, UnitRing } from '../unit/rings'; import { UnitRings, UnitRing } from '../unit/rings';
import { ElementIndex } from '../../model/indexing'; import { ElementIndex } from '../../model/indexing';
...@@ -122,6 +122,10 @@ function getSaccharideComp(compId: string, model: Model) { ...@@ -122,6 +122,10 @@ function getSaccharideComp(compId: string, model: Model) {
} }
export function computeCarbohydrates(structure: Structure): Carbohydrates { export function computeCarbohydrates(structure: Structure): Carbohydrates {
// skip computation if there are no saccharide components in any model
if (structure.models.reduce((a, v) => a + v.properties.saccharideComponentMap.size, 0) === 0)
return EmptyCarbohydrates
const links: CarbohydrateLink[] = [] const links: CarbohydrateLink[] = []
const terminalLinks: CarbohydrateTerminalLink[] = [] const terminalLinks: CarbohydrateTerminalLink[] = []
const elements: CarbohydrateElement[] = [] const elements: CarbohydrateElement[] = []
......
...@@ -51,3 +51,17 @@ export interface Carbohydrates { ...@@ -51,3 +51,17 @@ export interface Carbohydrates {
getTerminalLinkIndices: (unit: Unit, element: ElementIndex) => ReadonlyArray<number> getTerminalLinkIndices: (unit: Unit, element: ElementIndex) => ReadonlyArray<number>
getAnomericCarbon: (unit: Unit, residueIndex: ResidueIndex) => ElementIndex | undefined getAnomericCarbon: (unit: Unit, residueIndex: ResidueIndex) => ElementIndex | undefined
} }
const EmptyArray: ReadonlyArray<any> = []
export const EmptyCarbohydrates: Carbohydrates = {
links: EmptyArray,
terminalLinks: EmptyArray,
elements: EmptyArray,
partialElements: EmptyArray,
getElementIndex: () => undefined,
getLinkIndex: () => undefined,
getLinkIndices: () => EmptyArray,
getTerminalLinkIndex: () => undefined,
getTerminalLinkIndices: () => EmptyArray,
getAnomericCarbon: () => undefined,
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment