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

added linkLabel helper

parent baafa384
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
import { Unit, StructureElement, StructureProperties as Props } from 'mol-model/structure'; import { Unit, StructureElement, StructureProperties as Props, Link } from 'mol-model/structure';
import { Loci } from 'mol-model/loci'; import { Loci } from 'mol-model/loci';
import { OrderedSet } from 'mol-data/int'; import { OrderedSet } from 'mol-data/int';
...@@ -19,9 +19,6 @@ function setElementLocation(loc: StructureElement, unit: Unit, index: StructureE ...@@ -19,9 +19,6 @@ function setElementLocation(loc: StructureElement, unit: Unit, index: StructureE
} }
export function labelFirst(loci: Loci): string { export function labelFirst(loci: Loci): string {
if (!elementLocA) elementLocA = StructureElement.create()
if (!elementLocB) elementLocB = StructureElement.create()
switch (loci.kind) { switch (loci.kind) {
case 'element-loci': case 'element-loci':
const e = loci.elements[0] const e = loci.elements[0]
...@@ -32,14 +29,8 @@ export function labelFirst(loci: Loci): string { ...@@ -32,14 +29,8 @@ export function labelFirst(loci: Loci): string {
return 'Unknown' return 'Unknown'
} }
case 'link-loci': case 'link-loci':
const bond = loci.links[0] const link = loci.links[0]
if (bond) { return link ? linkLabel(link) : 'Unknown'
setElementLocation(elementLocA, bond.aUnit, bond.aIndex)
setElementLocation(elementLocB, bond.bUnit, bond.bIndex)
return `${elementLabel(elementLocA)} - ${elementLabel(elementLocB)}`
} else {
return 'Unknown'
}
case 'group-loci': case 'group-loci':
const g = loci.groups[0] const g = loci.groups[0]
if (g) { if (g) {
...@@ -54,32 +45,40 @@ export function labelFirst(loci: Loci): string { ...@@ -54,32 +45,40 @@ export function labelFirst(loci: Loci): string {
} }
} }
export function elementLabel(loc: StructureElement) { export function linkLabel(link: Link.Location) {
const model = loc.unit.model.label if (!elementLocA) elementLocA = StructureElement.create()
const instance = loc.unit.conformation.operator.name if (!elementLocB) elementLocB = StructureElement.create()
let element = '' setElementLocation(elementLocA, link.aUnit, link.aIndex)
setElementLocation(elementLocB, link.bUnit, link.bIndex)
return `${elementLabel(elementLocA)} - ${elementLabel(elementLocB)}`
}
export function elementLabel(element: StructureElement) {
const model = element.unit.model.label
const instance = element.unit.conformation.operator.name
let label = ''
if (Unit.isAtomic(loc.unit)) { if (Unit.isAtomic(element.unit)) {
const asym_id = Props.chain.auth_asym_id(loc) const asym_id = Props.chain.auth_asym_id(element)
const seq_id = Props.residue.auth_seq_id(loc) const seq_id = Props.residue.auth_seq_id(element)
const comp_id = Props.residue.auth_comp_id(loc) const comp_id = Props.residue.auth_comp_id(element)
const atom_id = Props.atom.auth_atom_id(loc) const atom_id = Props.atom.auth_atom_id(element)
element = `[${comp_id}]${seq_id}:${asym_id}.${atom_id}` label = `[${comp_id}]${seq_id}:${asym_id}.${atom_id}`
} else if (Unit.isCoarse(loc.unit)) { } else if (Unit.isCoarse(element.unit)) {
const asym_id = Props.coarse.asym_id(loc) const asym_id = Props.coarse.asym_id(element)
const seq_id_begin = Props.coarse.seq_id_begin(loc) const seq_id_begin = Props.coarse.seq_id_begin(element)
const seq_id_end = Props.coarse.seq_id_end(loc) const seq_id_end = Props.coarse.seq_id_end(element)
if (seq_id_begin === seq_id_end) { if (seq_id_begin === seq_id_end) {
const entityKey = Props.coarse.entityKey(loc) const entityKey = Props.coarse.entityKey(element)
const seq = loc.unit.model.sequence.byEntityKey[entityKey] const seq = element.unit.model.sequence.byEntityKey[entityKey]
const comp_id = seq.compId.value(seq_id_begin - 1) // 1-indexed const comp_id = seq.compId.value(seq_id_begin - 1) // 1-indexed
element = `[${comp_id}]${seq_id_begin}:${asym_id}` label = `[${comp_id}]${seq_id_begin}:${asym_id}`
} else { } else {
element = `${seq_id_begin}-${seq_id_end}:${asym_id}` label = `${seq_id_begin}-${seq_id_end}:${asym_id}`
} }
} else { } else {
element = 'unknown' label = 'unknown'
} }
return `${model} ${instance} ${element}` return `${model} ${instance} ${label}`
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment