diff --git a/src/mol-model/structure/model/formats/mmcif/atomic.ts b/src/mol-model/structure/model/formats/mmcif/atomic.ts index 20bef52965e7057bb0b99f6a3490c577064b0857..5b7335376caae94227ad990eff71c1637c18277b 100644 --- a/src/mol-model/structure/model/formats/mmcif/atomic.ts +++ b/src/mol-model/structure/model/formats/mmcif/atomic.ts @@ -19,6 +19,7 @@ import { Entities } from '../../properties/common'; import mmCIF_Format = Format.mmCIF import { getAtomicRanges } from '../../properties/utils/atomic-ranges'; import { FormatData } from '../mmcif'; +import { getAtomicDerivedData } from '../../properties/utils/atomic-derived'; type AtomSite = mmCIF_Database['atom_site'] @@ -99,7 +100,11 @@ export function getAtomicHierarchyAndConformation(format: mmCIF_Format, atom_sit } const index = getAtomicIndex(hierarchyData, entities, hierarchySegments); + console.time('derived') + const derived = getAtomicDerivedData(hierarchyData, index, formatData.chemicalComponentMap); + console.timeEnd('derived') + console.log(derived) const hierarchyRanges = getAtomicRanges(hierarchyData, hierarchySegments, conformation, formatData.chemicalComponentMap); - const hierarchy: AtomicHierarchy = { ...hierarchyData, ...hierarchySegments, ...hierarchyRanges, index }; + const hierarchy: AtomicHierarchy = { ...hierarchyData, ...hierarchySegments, ...hierarchyRanges, index, derived }; return { sameAsPrevious: false, hierarchy, conformation }; } \ No newline at end of file diff --git a/src/mol-model/structure/model/properties/atomic/hierarchy.ts b/src/mol-model/structure/model/properties/atomic/hierarchy.ts index 62c7d7ca6531ef0fd5efaaabe8bc99ecf0534176..0b0d3c1e0d68660f718a42ec5f9d4b3846ea5d39 100644 --- a/src/mol-model/structure/model/properties/atomic/hierarchy.ts +++ b/src/mol-model/structure/model/properties/atomic/hierarchy.ts @@ -8,7 +8,7 @@ import { Column, Table } from 'mol-data/db' import { Segmentation } from 'mol-data/int' import { mmCIF_Schema as mmCIF } from 'mol-io/reader/cif/schema/mmcif' -import { ElementSymbol } from '../../types' +import { ElementSymbol, MoleculeType } from '../../types' import { ChainIndex, EntityIndex, ResidueIndex, ElementIndex } from '../../indexing'; import SortedRanges from 'mol-data/int/sorted-ranges'; @@ -103,6 +103,14 @@ export interface AtomicData { chains: Chains } +export interface AtomicDerivedData { + readonly residue: { + readonly traceElementIndex: ArrayLike<ElementIndex> + readonly directionElementIndex: ArrayLike<ElementIndex> + readonly moleculeType: ArrayLike<MoleculeType> + } +} + export interface AtomicSegments { /** Maps residueIndex to a range of atoms [segments[rI], segments[rI + 1]) */ residueAtomSegments: Segmentation<ElementIndex, ResidueIndex>, @@ -204,6 +212,7 @@ export interface AtomicRanges { type _Hierarchy = AtomicData & AtomicSegments & AtomicRanges export interface AtomicHierarchy extends _Hierarchy { index: AtomicIndex + derived: AtomicDerivedData } export namespace AtomicHierarchy { diff --git a/src/mol-model/structure/model/properties/utils/atomic-derived.ts b/src/mol-model/structure/model/properties/utils/atomic-derived.ts new file mode 100644 index 0000000000000000000000000000000000000000..c998a2513010e4ea9315d3202f148d33b982dfce --- /dev/null +++ b/src/mol-model/structure/model/properties/utils/atomic-derived.ts @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import { AtomicData } from '../atomic'; +import { ChemicalComponentMap } from '../chemical-component'; +import { AtomicIndex, AtomicDerivedData } from '../atomic/hierarchy'; +import { ElementIndex, ResidueIndex } from '../../indexing'; +import { MoleculeType } from '../../types'; +import { getAtomIdForAtomRole } from 'mol-model/structure/util'; + +export function getAtomicDerivedData(data: AtomicData, index: AtomicIndex, chemicalComponentMap: ChemicalComponentMap): AtomicDerivedData { + + const { label_comp_id, _rowCount: n } = data.residues + + const traceElementIndex = new Uint32Array(n) + const directionElementIndex = new Uint32Array(n) + const moleculeType = new Uint8Array(n) + + for (let i = 0; i < n; ++i) { + const compId = label_comp_id.value(i) + const chemCompMap = chemicalComponentMap + const cc = chemCompMap.get(compId) + const molType = cc ? cc.moleculeType : MoleculeType.unknown + moleculeType[i] = molType + + const traceAtomId = getAtomIdForAtomRole(molType, 'trace') + traceElementIndex[i] = index.findAtomOnResidue(i as ResidueIndex, traceAtomId) + + const directionAtomId = getAtomIdForAtomRole(molType, 'direction') + directionElementIndex[i] = index.findAtomOnResidue(i as ResidueIndex, directionAtomId) + } + + + return { + residue: { + traceElementIndex: traceElementIndex as unknown as ArrayLike<ElementIndex>, + directionElementIndex: directionElementIndex as unknown as ArrayLike<ElementIndex>, + moleculeType: moleculeType as unknown as ArrayLike<MoleculeType>, + } + } +} \ No newline at end of file