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

imroved sequence widget entity dropdown

parent 0ce2966c
No related branches found
No related tags found
No related merge requests found
...@@ -27,11 +27,18 @@ function opKey(l: StructureElement.Location) { ...@@ -27,11 +27,18 @@ function opKey(l: StructureElement.Location) {
return `${ids.sort().join(',')}|${ncs}|${hkl}|${spgrOp}` return `${ids.sort().join(',')}|${ncs}|${hkl}|${spgrOp}`
} }
function splitModelEntityId(modelEntityId: string) {
const [ modelIdx, entityId ] = modelEntityId.split('|')
return [ parseInt(modelIdx), entityId ]
}
function getSequenceWrapper(state: SequenceViewState, structureSelection: StructureElementSelectionManager): SequenceWrapper.Any | undefined { function getSequenceWrapper(state: SequenceViewState, structureSelection: StructureElementSelectionManager): SequenceWrapper.Any | undefined {
const { structure, entityId, invariantUnitId, operatorKey } = state const { structure, modelEntityId, invariantUnitId, operatorKey } = state
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const [ modelIdx, entityId ] = splitModelEntityId(modelEntityId)
for (const unit of structure.units) { for (const unit of structure.units) {
StructureElement.Location.set(l, unit, unit.elements[0]) StructureElement.Location.set(l, unit, unit.elements[0])
if (structure.getModelIndex(unit.model) !== modelIdx) continue
if (SP.entity.id(l) !== entityId) continue if (SP.entity.id(l) !== entityId) continue
if (unit.invariantId !== invariantUnitId) continue if (unit.invariantId !== invariantUnitId) continue
if (opKey(l) !== operatorKey) continue if (opKey(l) !== operatorKey) continue
...@@ -43,7 +50,7 @@ function getSequenceWrapper(state: SequenceViewState, structureSelection: Struct ...@@ -43,7 +50,7 @@ function getSequenceWrapper(state: SequenceViewState, structureSelection: Struct
} }
} }
function getEntityOptions(structure: Structure) { function getModelEntityOptions(structure: Structure) {
const options: [string, string][] = [] const options: [string, string][] = []
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const seen = new Set<string>() const seen = new Set<string>()
...@@ -51,25 +58,33 @@ function getEntityOptions(structure: Structure) { ...@@ -51,25 +58,33 @@ function getEntityOptions(structure: Structure) {
for (const unit of structure.units) { for (const unit of structure.units) {
StructureElement.Location.set(l, unit, unit.elements[0]) StructureElement.Location.set(l, unit, unit.elements[0])
const id = SP.entity.id(l) const id = SP.entity.id(l)
if (seen.has(id)) continue const modelIdx = structure.getModelIndex(unit.model)
const key = `${modelIdx}|${id}`
if (seen.has(key)) continue
const label = `${id}: ${SP.entity.pdbx_description(l).join(', ')}` let description = SP.entity.pdbx_description(l).join(', ')
options.push([ id, label ]) if (description.startsWith('Polymer ') && structure.models.length > 1) {
seen.add(id) description += ` (${structure.models[modelIdx].entry})`
}
const label = `${id}: ${description}`
options.push([ key, label ])
seen.add(key)
} }
if (options.length === 0) options.push(['', 'No entities']) if (options.length === 0) options.push(['', 'No entities'])
return options return options
} }
function getUnitOptions(structure: Structure, entityId: string) { function getUnitOptions(structure: Structure, modelEntityId: string) {
const options: [number, string][] = [] const options: [number, string][] = []
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const seen = new Set<number>() const seen = new Set<number>()
const water = new Map<string, number>() const water = new Map<string, number>()
const [ modelIdx, entityId ] = splitModelEntityId(modelEntityId)
for (const unit of structure.units) { for (const unit of structure.units) {
StructureElement.Location.set(l, unit, unit.elements[0]) StructureElement.Location.set(l, unit, unit.elements[0])
if (structure.getModelIndex(unit.model) !== modelIdx) continue
if (SP.entity.id(l) !== entityId) continue if (SP.entity.id(l) !== entityId) continue
const id = unit.invariantId const id = unit.invariantId
...@@ -98,13 +113,15 @@ function getUnitOptions(structure: Structure, entityId: string) { ...@@ -98,13 +113,15 @@ function getUnitOptions(structure: Structure, entityId: string) {
return options return options
} }
function getOperatorOptions(structure: Structure, entityId: string, invariantUnitId: number) { function getOperatorOptions(structure: Structure, modelEntityId: string, invariantUnitId: number) {
const options: [string, string][] = [] const options: [string, string][] = []
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const seen = new Set<string>() const seen = new Set<string>()
const [ modelIdx, entityId ] = splitModelEntityId(modelEntityId)
for (const unit of structure.units) { for (const unit of structure.units) {
StructureElement.Location.set(l, unit, unit.elements[0]) StructureElement.Location.set(l, unit, unit.elements[0])
if (structure.getModelIndex(unit.model) !== modelIdx) continue
if (SP.entity.id(l) !== entityId) continue if (SP.entity.id(l) !== entityId) continue
if (unit.invariantId !== invariantUnitId) continue if (unit.invariantId !== invariantUnitId) continue
...@@ -135,13 +152,13 @@ function getStructureOptions(state: State) { ...@@ -135,13 +152,13 @@ function getStructureOptions(state: State) {
type SequenceViewState = { type SequenceViewState = {
structure: Structure, structure: Structure,
structureRef: string, structureRef: string,
entityId: string, modelEntityId: string,
invariantUnitId: number, invariantUnitId: number,
operatorKey: string operatorKey: string
} }
export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
state = { structure: Structure.Empty, structureRef: '', entityId: '', invariantUnitId: -1, operatorKey: '' } state = { structure: Structure.Empty, structureRef: '', modelEntityId: '', invariantUnitId: -1, operatorKey: '' }
componentDidMount() { componentDidMount() {
if (this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure)).length > 0) this.setState(this.getInitialState()) if (this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure)).length > 0) this.setState(this.getInitialState())
...@@ -180,18 +197,18 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { ...@@ -180,18 +197,18 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
// TODO reuse selected values from previous state if applicable // TODO reuse selected values from previous state if applicable
const structureRef = getStructureOptions(this.plugin.state.dataState)[0][0] const structureRef = getStructureOptions(this.plugin.state.dataState)[0][0]
const structure = this.getStructure(structureRef) const structure = this.getStructure(structureRef)
const entityId = getEntityOptions(structure)[0][0] const modelEntityId = getModelEntityOptions(structure)[0][0]
const invariantUnitId = getUnitOptions(structure, entityId)[0][0] const invariantUnitId = getUnitOptions(structure, modelEntityId)[0][0]
const operatorKey = getOperatorOptions(structure, entityId, invariantUnitId)[0][0] const operatorKey = getOperatorOptions(structure, modelEntityId, invariantUnitId)[0][0]
return { structure, structureRef, entityId, invariantUnitId, operatorKey } return { structure, structureRef, modelEntityId, invariantUnitId, operatorKey }
} }
private get params() { private get params() {
const { structure, entityId, invariantUnitId } = this.state const { structure, modelEntityId, invariantUnitId } = this.state
const structureOptions = getStructureOptions(this.plugin.state.dataState) const structureOptions = getStructureOptions(this.plugin.state.dataState)
const entityOptions = getEntityOptions(structure) const entityOptions = getModelEntityOptions(structure)
const unitOptions = getUnitOptions(structure, entityId) const unitOptions = getUnitOptions(structure, modelEntityId)
const operatorOptions = getOperatorOptions(structure, entityId, invariantUnitId) const operatorOptions = getOperatorOptions(structure, modelEntityId, invariantUnitId)
return { return {
structure: PD.Select(structureOptions[0][0], structureOptions, { shortLabel: true }), structure: PD.Select(structureOptions[0][0], structureOptions, { shortLabel: true }),
entity: PD.Select(entityOptions[0][0], entityOptions, { shortLabel: true }), entity: PD.Select(entityOptions[0][0], entityOptions, { shortLabel: true }),
...@@ -203,7 +220,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { ...@@ -203,7 +220,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
private get values(): PD.Values<SequenceView['params']> { private get values(): PD.Values<SequenceView['params']> {
return { return {
structure: this.state.structureRef, structure: this.state.structureRef,
entity: this.state.entityId, entity: this.state.modelEntityId,
unit: this.state.invariantUnitId, unit: this.state.invariantUnitId,
operator: this.state.operatorKey operator: this.state.operatorKey
} }
...@@ -217,18 +234,18 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { ...@@ -217,18 +234,18 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
case 'structure': case 'structure':
state.structureRef = p.value state.structureRef = p.value
state.structure = this.getStructure(p.value) state.structure = this.getStructure(p.value)
state.entityId = getEntityOptions(state.structure)[0][0] state.modelEntityId = getModelEntityOptions(state.structure)[0][0]
state.invariantUnitId = getUnitOptions(state.structure, state.entityId)[0][0] state.invariantUnitId = getUnitOptions(state.structure, state.modelEntityId)[0][0]
state.operatorKey = getOperatorOptions(state.structure, state.entityId, state.invariantUnitId)[0][0] state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.invariantUnitId)[0][0]
break break
case 'entity': case 'entity':
state.entityId = p.value state.modelEntityId = p.value
state.invariantUnitId = getUnitOptions(state.structure, state.entityId)[0][0] state.invariantUnitId = getUnitOptions(state.structure, state.modelEntityId)[0][0]
state.operatorKey = getOperatorOptions(state.structure, state.entityId, state.invariantUnitId)[0][0] state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.invariantUnitId)[0][0]
break break
case 'unit': case 'unit':
state.invariantUnitId = p.value state.invariantUnitId = p.value
state.operatorKey = getOperatorOptions(state.structure, state.entityId, state.invariantUnitId)[0][0] state.operatorKey = getOperatorOptions(state.structure, state.modelEntityId, state.invariantUnitId)[0][0]
break break
case 'operator': case 'operator':
state.operatorKey = p.value state.operatorKey = p.value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment