Skip to content
Snippets Groups Projects
Commit 3436d034 authored by Alexander Rose's avatar Alexander Rose
Browse files

add helpers to work with many locis

- StructureElement.Loci.getPrincipalAxesMany
- structureElementLociLabelMany
parent 58df6f3b
No related branches found
No related tags found
No related merge requests found
...@@ -582,6 +582,20 @@ export namespace Loci { ...@@ -582,6 +582,20 @@ export namespace Loci {
return PrincipalAxes.ofPositions(positions); return PrincipalAxes.ofPositions(positions);
} }
export function getPrincipalAxesMany(locis: Loci[]): PrincipalAxes {
let elementCount = 0;
locis.forEach(l => {
elementCount += size(l);
});
const positions = new Float32Array(3 * elementCount);
let offset = 0;
locis.forEach(l => {
toPositionsArray(l, positions, offset);
offset += size(l) * 3;
});
return PrincipalAxes.ofPositions(positions);
}
function sourceIndex(unit: Unit, element: ElementIndex) { function sourceIndex(unit: Unit, element: ElementIndex) {
return Unit.isAtomic(unit) return Unit.isAtomic(unit)
? unit.model.atomicHierarchy.atomSourceIndex.value(element) ? unit.model.atomicHierarchy.atomSourceIndex.value(element)
......
/** /**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
...@@ -22,6 +22,7 @@ import { PluginStateObject as PSO } from '../../objects'; ...@@ -22,6 +22,7 @@ import { PluginStateObject as PSO } from '../../objects';
import { UUID } from '../../../mol-util'; import { UUID } from '../../../mol-util';
import { StructureRef } from './hierarchy-state'; import { StructureRef } from './hierarchy-state';
import { Boundary } from '../../../mol-math/geometry/boundary'; import { Boundary } from '../../../mol-math/geometry/boundary';
import { iterableToArray } from '../../../mol-data/util';
interface StructureSelectionManagerState { interface StructureSelectionManagerState {
entries: Map<string, SelectionEntry>, entries: Map<string, SelectionEntry>,
...@@ -405,14 +406,8 @@ export class StructureSelectionManager extends StatefulPluginComponent<Structure ...@@ -405,14 +406,8 @@ export class StructureSelectionManager extends StatefulPluginComponent<Structure
} }
getPrincipalAxes(): PrincipalAxes { getPrincipalAxes(): PrincipalAxes {
const elementCount = this.elementCount(); const values = iterableToArray(this.entries.values());
const positions = new Float32Array(3 * elementCount); return StructureElement.Loci.getPrincipalAxesMany(values.map(v => v.selection));
let offset = 0;
this.entries.forEach(v => {
StructureElement.Loci.toPositionsArray(v.selection, positions, offset);
offset += StructureElement.Loci.size(v.selection) * 3;
});
return PrincipalAxes.ofPositions(positions);
} }
modify(modifier: StructureSelectionModifier, loci: Loci) { modify(modifier: StructureSelectionModifier, loci: Loci) {
......
...@@ -92,6 +92,14 @@ export function structureElementStatsLabel(stats: StructureElement.Stats, option ...@@ -92,6 +92,14 @@ export function structureElementStatsLabel(stats: StructureElement.Stats, option
return o.htmlStyling ? label : stripTags(label); return o.htmlStyling ? label : stripTags(label);
} }
export function structureElementLociLabelMany(locis: StructureElement.Loci[], options: Partial<LabelOptions> = {}): string {
const stats = StructureElement.Stats.create();
for (const l of locis) {
StructureElement.Stats.add(stats, stats, StructureElement.Stats.ofLoci(l));
}
return structureElementStatsLabel(stats, options);
}
function _structureElementStatsLabel(stats: StructureElement.Stats, countsOnly = false, hidePrefix = false, condensed = false, reverse = false): string { function _structureElementStatsLabel(stats: StructureElement.Stats, countsOnly = false, hidePrefix = false, condensed = false, reverse = false): string {
const { structureCount, chainCount, residueCount, conformationCount, elementCount } = stats; const { structureCount, chainCount, residueCount, conformationCount, elementCount } = stats;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment