From 2013ed921fe08c3221ae1169c89f660a9a22d05e Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Fri, 1 Mar 2019 22:18:55 +0100 Subject: [PATCH] mol-plugin: StructureElement.Loci.extendToWholeResidues --- src/mol-math/linear-algebra/3d/vec3.ts | 5 ++- src/mol-model/structure/structure/element.ts | 32 +++++++++++++++++++ .../dynamic/volume-streaming/behavior.ts | 4 ++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index c0437fd57..3e8fd5d5e 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -452,14 +452,13 @@ namespace Vec3 { } const rotTemp = zero(); - const flipMatrix = Mat4.fromScaling(Mat4.zero(), create(-1, -1, -1)) + const flipScaling = create(-1, -1, -1); export function makeRotation(mat: Mat4, a: Vec3, b: Vec3): Mat4 { const by = angle(a, b); if (Math.abs(by) < 0.0001) return Mat4.setIdentity(mat); if (Math.abs(by - Math.PI) < EPSILON.Value) { // here, axis can be [0,0,0] but the rotation is a simple flip - Mat4.copy(mat, flipMatrix); - return mat; + return Mat4.fromScaling(mat, flipScaling); } const axis = cross(rotTemp, a, b); return Mat4.fromRotation(mat, by, axis); diff --git a/src/mol-model/structure/structure/element.ts b/src/mol-model/structure/structure/element.ts index 8b39d2215..4e5148225 100644 --- a/src/mol-model/structure/structure/element.ts +++ b/src/mol-model/structure/structure/element.ts @@ -176,6 +176,38 @@ namespace StructureElement { return false; } + + export function extendToWholeResidues(loci: Loci): Loci { + const elements: Loci['elements'][0][] = []; + + for (const lociElement of loci.elements) { + if (lociElement.unit.kind !== Unit.Kind.Atomic) elements[elements.length] = lociElement; + + const unitElements = lociElement.unit.elements; + const h = lociElement.unit.model.atomicHierarchy; + + const { index: residueIndex, offsets: residueOffsets } = h.residueAtomSegments; + + const newIndices: UnitIndex[] = []; + const indices = lociElement.indices, len = OrderedSet.size(indices); + let i = 0; + while (i < len) { + const rI = residueIndex[unitElements[OrderedSet.getAt(indices, i)]]; + while (i < len && residueIndex[unitElements[OrderedSet.getAt(indices, i)]] === rI) { + i++; + } + + for (let j = residueOffsets[rI], _j = residueOffsets[rI + 1]; j < _j; j++) { + const idx = OrderedSet.indexOf(unitElements, j); + if (idx >= 0) newIndices[newIndices.length] = idx as UnitIndex; + } + } + + elements[elements.length] = { unit: lociElement.unit, indices: SortedArray.ofSortedArray(newIndices) }; + } + + return Loci(loci.structure, elements); + } } } diff --git a/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts b/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts index 7990e753d..d2ce4aa51 100644 --- a/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts +++ b/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts @@ -154,9 +154,11 @@ export namespace VolumeStreaming { // TODO: check if it's the related structure + const loci = StructureElement.Loci.extendToWholeResidues(current.loci); + const eR = this.params.view.params.radius; - const sphere = Loci.getBoundingSphere(current.loci)!; + const sphere = Loci.getBoundingSphere(loci)!; const r = Vec3.create(sphere.radius + eR, sphere.radius + eR, sphere.radius + eR); const box = Box3D.create(Vec3.sub(Vec3.zero(), sphere.center, r), Vec3.add(Vec3.zero(), sphere.center, r)); -- GitLab