diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index c0437fd5770afa42a9e867d8369494f819c8444f..3e8fd5d5ee7765fcb88215a1455655b75357b10e 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 8b39d221530230aa05717c0db078191c3a34360a..4e5148225bd4749fc6ca83e8a8dd2efeb037e318 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 7990e753dcdbaa98dbb98ba40a34e52e03460a30..d2ce4aa511aec14e17335e51a105e1a037263c9e 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));