Переглянути джерело

added some precalculated deried properties

Alexander Rose 6 роки тому
батько
коміт
a500e55c38

+ 6 - 1
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 };
 }

+ 10 - 1
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 {

+ 44 - 0
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>,
+        }
+    }
+}