mirror of
https://github.com/molstar/molstar.git
synced 2026-06-07 15:14:22 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
131e88080a | ||
|
|
fb78b886c1 | ||
|
|
aed0b87b16 | ||
|
|
1316cc6a40 |
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "molstar",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "molstar",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"description": "A comprehensive macromolecular library.",
|
||||
"homepage": "https://github.com/molstar/molstar#readme",
|
||||
"repository": {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
/** Set canvas size taking `devicePixelRatio` into account */
|
||||
export function setCanvasSize(canvas: HTMLCanvasElement, width: number, height: number) {
|
||||
canvas.width = window.devicePixelRatio * width
|
||||
canvas.height = window.devicePixelRatio * height
|
||||
canvas.width = Math.round(window.devicePixelRatio * width)
|
||||
canvas.height = Math.round(window.devicePixelRatio * height)
|
||||
Object.assign(canvas.style, { width: `${width}px`, height: `${height}px` })
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function _canvasToBlob(canvas: HTMLCanvasElement, callback: BlobCallback, type?:
|
||||
const len = bin.length
|
||||
const len32 = len >> 2
|
||||
const a8 = new Uint8Array(len)
|
||||
const a32 = new Uint32Array( a8.buffer, 0, len32 )
|
||||
const a32 = new Uint32Array(a8.buffer, 0, len32)
|
||||
|
||||
let j = 0
|
||||
for (let i = 0; i < len32; ++i) {
|
||||
|
||||
@@ -64,7 +64,9 @@ export class ImageControls<P, S extends ImageControlsState> extends CollapsableC
|
||||
}
|
||||
setCanvasSize(this.canvas, w, h)
|
||||
const { pixelRatio } = this.plugin.canvas3d.webgl
|
||||
const imageData = this.imagePass.getImageData(w * pixelRatio, h * pixelRatio)
|
||||
const pw = Math.round(w * pixelRatio)
|
||||
const ph = Math.round(h * pixelRatio)
|
||||
const imageData = this.imagePass.getImageData(pw, ph)
|
||||
this.canvasContext.putImageData(imageData, 0, 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ export class StructureSelectionControls<P, S extends StructureSelectionControlsS
|
||||
|
||||
focus = () => {
|
||||
const { extraRadius, minRadius, durationMs } = this.state
|
||||
if (this.plugin.helpers.structureSelectionManager.stats.elementCount === 0) return
|
||||
const { sphere } = this.plugin.helpers.structureSelectionManager.getBoundary();
|
||||
if (sphere.radius === 0) return
|
||||
const radius = Math.max(sphere.radius + extraRadius, minRadius);
|
||||
this.plugin.canvas3d.camera.focus(sphere.center, radius, durationMs);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ function getResidueCount(unit: Unit.Atomic) {
|
||||
return residueAtomSegments.index[elementEnd] - residueAtomSegments.index[elementStart]
|
||||
}
|
||||
|
||||
export function structureElementStatsLabel(stats: StructureElement.Stats, countsOnly = false) {
|
||||
export function structureElementStatsLabel(stats: StructureElement.Stats, countsOnly = false): string {
|
||||
const { unitCount, residueCount, elementCount } = stats
|
||||
|
||||
if (!countsOnly && elementCount === 1 && residueCount === 0 && unitCount === 0) {
|
||||
@@ -74,34 +74,45 @@ export function structureElementStatsLabel(stats: StructureElement.Stats, counts
|
||||
}
|
||||
}
|
||||
|
||||
export function linkLabel(link: Link.Location) {
|
||||
export function linkLabel(link: Link.Location): string {
|
||||
if (!elementLocA) elementLocA = StructureElement.Location.create()
|
||||
if (!elementLocB) elementLocB = StructureElement.Location.create()
|
||||
setElementLocation(elementLocA, link.aUnit, link.aIndex)
|
||||
setElementLocation(elementLocB, link.bUnit, link.bIndex)
|
||||
return `${elementLabel(elementLocA)} - ${elementLabel(elementLocB)}`
|
||||
const labelA = _elementLabel(elementLocA)
|
||||
const labelB = _elementLabel(elementLocB)
|
||||
let offset = 0
|
||||
for (let i = 0, il = Math.min(labelA.length, labelB.length); i < il; ++i) {
|
||||
if (labelA[i] === labelB[i]) offset += 1
|
||||
else break
|
||||
}
|
||||
return `${labelA.join(' | ')} \u2014 ${labelB.slice(offset).join(' | ')}`
|
||||
}
|
||||
|
||||
export type LabelGranularity = 'element' | 'residue' | 'chain' | 'structure'
|
||||
|
||||
export function elementLabel(location: StructureElement.Location, granularity: LabelGranularity = 'element') {
|
||||
export function elementLabel(location: StructureElement.Location, granularity: LabelGranularity = 'element'): string {
|
||||
return _elementLabel(location, granularity).join(' | ')
|
||||
}
|
||||
|
||||
function _elementLabel(location: StructureElement.Location, granularity: LabelGranularity = 'element'): string[] {
|
||||
const entry = location.unit.model.entry
|
||||
const model = `Model ${location.unit.model.modelNum}`
|
||||
const instance = location.unit.conformation.operator.name
|
||||
const label = [entry, model, instance]
|
||||
|
||||
if (Unit.isAtomic(location.unit)) {
|
||||
label.push(atomicElementLabel(location as StructureElement.Location<Unit.Atomic>, granularity))
|
||||
label.push(..._atomicElementLabel(location as StructureElement.Location<Unit.Atomic>, granularity))
|
||||
} else if (Unit.isCoarse(location.unit)) {
|
||||
label.push(coarseElementLabel(location as StructureElement.Location<Unit.Spheres | Unit.Gaussians>, granularity))
|
||||
label.push(..._coarseElementLabel(location as StructureElement.Location<Unit.Spheres | Unit.Gaussians>, granularity))
|
||||
} else {
|
||||
label.push('Unknown')
|
||||
}
|
||||
|
||||
return label.join(' | ')
|
||||
return label
|
||||
}
|
||||
|
||||
export function atomicElementLabel(location: StructureElement.Location<Unit.Atomic>, granularity: LabelGranularity) {
|
||||
function _atomicElementLabel(location: StructureElement.Location<Unit.Atomic>, granularity: LabelGranularity): string[] {
|
||||
const label_asym_id = Props.chain.label_asym_id(location)
|
||||
const auth_asym_id = Props.chain.auth_asym_id(location)
|
||||
const seq_id = location.unit.model.atomicHierarchy.residues.auth_seq_id.isDefined ? Props.residue.auth_seq_id(location) : Props.residue.label_seq_id(location)
|
||||
@@ -126,10 +137,10 @@ export function atomicElementLabel(location: StructureElement.Location<Unit.Atom
|
||||
label.push(`Chain ${label_asym_id}:${auth_asym_id}`)
|
||||
}
|
||||
|
||||
return label.reverse().join(' | ')
|
||||
return label.reverse()
|
||||
}
|
||||
|
||||
export function coarseElementLabel(location: StructureElement.Location<Unit.Spheres | Unit.Gaussians>, granularity: LabelGranularity) {
|
||||
function _coarseElementLabel(location: StructureElement.Location<Unit.Spheres | Unit.Gaussians>, granularity: LabelGranularity): string[] {
|
||||
const asym_id = Props.coarse.asym_id(location)
|
||||
const seq_id_begin = Props.coarse.seq_id_begin(location)
|
||||
const seq_id_end = Props.coarse.seq_id_end(location)
|
||||
@@ -151,5 +162,5 @@ export function coarseElementLabel(location: StructureElement.Location<Unit.Sphe
|
||||
label.push(`Chain ${asym_id}`)
|
||||
}
|
||||
|
||||
return label.reverse().join(' | ')
|
||||
return label.reverse()
|
||||
}
|
||||
Reference in New Issue
Block a user