Ver Fonte

nucleotideElements, proteinElements improvements

Alexander Rose há 6 anos atrás
pai
commit
c3aadc6883

+ 4 - 0
src/mol-model/structure/model/types.ts

@@ -240,6 +240,10 @@ export function isNucleic(moleculeType: MoleculeType) {
     return moleculeType === MoleculeType.DNA || moleculeType === MoleculeType.RNA || moleculeType === MoleculeType.PNA
 }
 
+export function isProtein(moleculeType: MoleculeType) {
+    return moleculeType === MoleculeType.protein
+}
+
 /**
  * TODO write script that read CCD and outputs list of ion names
  *

+ 12 - 5
src/mol-model/structure/structure/unit.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -16,8 +16,7 @@ import StructureElement from './element'
 import { ChainIndex, ResidueIndex, ElementIndex } from '../model/indexing';
 import { IntMap, SortedArray } from 'mol-data/int';
 import { hash2, hashFnv32a } from 'mol-data/util';
-import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElements, getCoarseGapElements } from './util/polymer';
-import { getNucleotideElements } from './util/nucleotide';
+import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElements, getCoarseGapElements, getNucleotideElements, getProteinElements } from './util/polymer';
 
 /**
  * A building block of a structure that corresponds to an atomic or
@@ -126,7 +125,7 @@ namespace Unit {
      * together with a tranformation (rotation and translation)
      * that is dynamically applied to the underlying atom set.
      *
-     * An atom set can be referenced by multiple diffrent units which
+     * An atom set can be referenced by multiple different units which
      * makes construction of assemblies and spacegroups very efficient.
      */
     export class Atomic implements Base {
@@ -191,6 +190,12 @@ namespace Unit {
             return this.props.nucleotideElements.ref;
         }
 
+        get proteinElements() {
+            if (this.props.proteinElements.ref) return this.props.proteinElements.ref;
+            this.props.proteinElements.ref = getProteinElements(this);
+            return this.props.proteinElements.ref;
+        }
+
         getResidueIndex(elementIndex: StructureElement.UnitIndex) {
             return this.model.atomicHierarchy.residueAtomSegments.index[this.elements[elementIndex]];
         }
@@ -215,6 +220,7 @@ namespace Unit {
         polymerElements: ValueRef<SortedArray<ElementIndex> | undefined>
         gapElements: ValueRef<SortedArray<ElementIndex> | undefined>
         nucleotideElements: ValueRef<SortedArray<ElementIndex> | undefined>
+        proteinElements: ValueRef<SortedArray<ElementIndex> | undefined>
     }
 
     function AtomicProperties(): AtomicProperties {
@@ -224,7 +230,8 @@ namespace Unit {
             rings: ValueRef.create(void 0),
             polymerElements: ValueRef.create(void 0),
             gapElements: ValueRef.create(void 0),
-            nucleotideElements: ValueRef.create(void 0)
+            nucleotideElements: ValueRef.create(void 0),
+            proteinElements: ValueRef.create(void 0),
         };
     }
 

+ 0 - 31
src/mol-model/structure/structure/util/nucleotide.ts

@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author Alexander Rose <alexander.rose@weirdbyte.de>
- */
-
-import { Unit, ElementIndex } from 'mol-model/structure';
-import { Segmentation, SortedArray } from 'mol-data/int';
-import { isNucleic } from 'mol-model/structure/model/types';
-
-export function getNucleotideElements(unit: Unit.Atomic) {
-    const indices: ElementIndex[] = []
-    const { elements, model } = unit
-    const { chainAtomSegments, residueAtomSegments } = model.atomicHierarchy
-    const { moleculeType, traceElementIndex } = model.atomicHierarchy.derived.residue
-    const chainIt = Segmentation.transientSegments(chainAtomSegments, elements)
-    const residueIt = Segmentation.transientSegments(residueAtomSegments, elements)
-    while (chainIt.hasNext) {
-        residueIt.setSegment(chainIt.move());
-
-        while (residueIt.hasNext) {
-            const { index } = residueIt.move();
-
-            if (isNucleic(moleculeType[index])) {
-                const elementIndex = traceElementIndex[index]
-                indices.push(elementIndex === -1 ? residueAtomSegments.offsets[index] : elementIndex)
-            }
-        }
-    }
-    return SortedArray.ofSortedArray<ElementIndex>(indices)
-}

+ 50 - 1
src/mol-model/structure/structure/util/polymer.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -7,6 +7,7 @@
 import { Unit, ElementIndex } from 'mol-model/structure';
 import { Segmentation, OrderedSet, Interval, SortedArray } from 'mol-data/int';
 import SortedRanges from 'mol-data/int/sorted-ranges';
+import { isNucleic, isProtein } from 'mol-model/structure/model/types';
 
 export function getAtomicPolymerElements(unit: Unit.Atomic) {
     const indices: ElementIndex[] = []
@@ -43,6 +44,8 @@ export function getCoarsePolymerElements(unit: Unit.Spheres | Unit.Gaussians) {
     return SortedArray.ofSortedArray<ElementIndex>(indices)
 }
 
+//
+
 export function getAtomicGapElements(unit: Unit.Atomic) {
     const indices: ElementIndex[] = []
     const { elements, model, residueIndex } = unit
@@ -73,4 +76,50 @@ export function getCoarseGapElements(unit: Unit.Spheres | Unit.Gaussians) {
         indices.push(elements[start], elements[end - 1])
     }
     return SortedArray.ofSortedArray<ElementIndex>(indices)
+}
+
+//
+
+export function getNucleotideElements(unit: Unit.Atomic) {
+    const indices: ElementIndex[] = []
+    const { elements, model } = unit
+    const { chainAtomSegments, residueAtomSegments } = model.atomicHierarchy
+    const { moleculeType, traceElementIndex } = model.atomicHierarchy.derived.residue
+    const chainIt = Segmentation.transientSegments(chainAtomSegments, elements)
+    const residueIt = Segmentation.transientSegments(residueAtomSegments, elements)
+    while (chainIt.hasNext) {
+        residueIt.setSegment(chainIt.move());
+
+        while (residueIt.hasNext) {
+            const { index } = residueIt.move();
+
+            if (isNucleic(moleculeType[index])) {
+                const elementIndex = traceElementIndex[index]
+                indices.push(elementIndex === -1 ? residueAtomSegments.offsets[index] : elementIndex)
+            }
+        }
+    }
+    return SortedArray.ofSortedArray<ElementIndex>(indices)
+}
+
+export function getProteinElements(unit: Unit.Atomic) {
+    const indices: ElementIndex[] = []
+    const { elements, model } = unit
+    const { chainAtomSegments, residueAtomSegments } = model.atomicHierarchy
+    const { moleculeType, traceElementIndex } = model.atomicHierarchy.derived.residue
+    const chainIt = Segmentation.transientSegments(chainAtomSegments, elements)
+    const residueIt = Segmentation.transientSegments(residueAtomSegments, elements)
+    while (chainIt.hasNext) {
+        residueIt.setSegment(chainIt.move());
+
+        while (residueIt.hasNext) {
+            const { index } = residueIt.move();
+
+            if (isProtein(moleculeType[index])) {
+                const elementIndex = traceElementIndex[index]
+                indices.push(elementIndex === -1 ? residueAtomSegments.offsets[index] : elementIndex)
+            }
+        }
+    }
+    return SortedArray.ofSortedArray<ElementIndex>(indices)
 }

+ 1 - 2
src/mol-repr/structure/visual/util/nucleotide.ts

@@ -5,7 +5,6 @@
  */
 
 import { Unit, StructureElement, Structure } from 'mol-model/structure';
-import { getNucleotideElements } from 'mol-model/structure/structure/util/nucleotide';
 import { Loci, EmptyLoci } from 'mol-model/loci';
 import { OrderedSet, Interval } from 'mol-data/int';
 import { LocationIterator } from 'mol-geo/util/location-iterator';
@@ -16,7 +15,7 @@ import { getResidueLoci } from './common';
 export namespace NucleotideLocationIterator {
     export function fromGroup(group: Unit.SymmetryGroup): LocationIterator {
         const u = group.units[0]
-        const nucleotideElementIndices = Unit.isAtomic(u) ? getNucleotideElements(u) : []
+        const nucleotideElementIndices = Unit.isAtomic(u) ? u.nucleotideElements : []
         const groupCount = nucleotideElementIndices.length
         const instanceCount = group.units.length
         const location = StructureElement.create()