seperated autoAttach from property params in custom property transform

This commit is contained in:
Alexander Rose
2020-02-13 15:09:35 -08:00
parent 94ef9f4dbe
commit 46cfb42cce
4 changed files with 29 additions and 16 deletions

View File

@@ -63,7 +63,7 @@ class BasicWrapper {
return parsed
.apply(StateTransforms.Model.ModelFromTrajectory, { modelIndex: 0 })
.apply(StateTransforms.Model.CustomModelProperties, { properties: [StripedResidues.propertyProvider.descriptor.name] }, { ref: 'props', state: { isGhost: false } })
.apply(StateTransforms.Model.CustomModelProperties, { autoAttach: [StripedResidues.propertyProvider.descriptor.name], properties: {} }, { ref: 'props', state: { isGhost: false } })
.apply(StateTransforms.Model.StructureAssemblyFromModel, { id: assemblyId || 'deposited' }, { ref: 'asm' });
}

View File

@@ -94,7 +94,7 @@ class MolStarProteopediaWrapper {
const model = this.state.build().to(StateElements.Model);
const s = model
.apply(StateTransforms.Model.CustomModelProperties, { properties: [EvolutionaryConservation.propertyProvider.descriptor.name] }, { ref: StateElements.ModelProps, state: { isGhost: false } })
.apply(StateTransforms.Model.CustomModelProperties, { autoAttach: [EvolutionaryConservation.propertyProvider.descriptor.name], properties: {} }, { ref: StateElements.ModelProps, state: { isGhost: false } })
.apply(StateTransforms.Model.StructureAssemblyFromModel, { id: assemblyId || 'deposited' }, { ref: StateElements.Assembly });
s.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-sequence' }, { ref: StateElements.Sequence });

View File

@@ -41,21 +41,32 @@ namespace CustomProperty {
/** Get params for all applicable property providers */
getParams(data?: Data) {
const params: PD.Params = {}
const propertiesParams: PD.Params = {}
const autoAttachOptions: [string, string][] = []
const autoAttachDefault: string[] = []
if (data) {
const values = this.providers.values();
const values = this.providers.values();
while (true) {
const v = values.next()
if (v.done) break
const provider = v.value
if (!provider.isApplicable(data)) continue
params[provider.descriptor.name] = PD.Group({
autoAttach: PD.Boolean(this.defaultAutoAttachValues.get(provider.descriptor.name)!),
...provider.getParams(data),
}, { label: v.value.label })
autoAttachOptions.push([provider.descriptor.name, provider.label])
if (this.defaultAutoAttachValues.get(provider.descriptor.name)) {
autoAttachDefault.push(provider.descriptor.name)
}
propertiesParams[provider.descriptor.name] = PD.Group({
...provider.getParams(data)
}, { label: provider.label })
}
}
return params
return {
autoAttach: PD.MultiSelect(autoAttachDefault, autoAttachOptions),
properties: PD.Group(propertiesParams, { isFlat: true })
}
}
setDefaultAutoAttach(name: string, value: boolean) {

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -713,12 +713,13 @@ const CustomModelProperties = PluginStateTransform.BuiltIn({
});
}
});
async function attachModelProps(model: Model, ctx: PluginContext, taskCtx: RuntimeContext, params: PD.Values<PD.Params>) {
async function attachModelProps(model: Model, ctx: PluginContext, taskCtx: RuntimeContext, params: ReturnType<CustomModelProperties['createDefaultParams']>) {
const propertyCtx = { runtime: taskCtx, fetch: ctx.fetch }
for (const name of Object.keys(params)) {
const { autoAttach, properties } = params
for (const name of Object.keys(properties)) {
const property = ctx.customModelProperties.get(name)
const props = params[name as keyof typeof params]
if (props.autoAttach) {
if (autoAttach.includes(name)) {
try {
await property.attach(propertyCtx, model, props)
} catch (e) {
@@ -747,12 +748,13 @@ const CustomStructureProperties = PluginStateTransform.BuiltIn({
});
}
});
async function attachStructureProps(structure: Structure, ctx: PluginContext, taskCtx: RuntimeContext, params: PD.Values<PD.Params>) {
async function attachStructureProps(structure: Structure, ctx: PluginContext, taskCtx: RuntimeContext, params: ReturnType<CustomStructureProperties['createDefaultParams']>) {
const propertyCtx = { runtime: taskCtx, fetch: ctx.fetch }
for (const name of Object.keys(params)) {
const { autoAttach, properties } = params
for (const name of Object.keys(properties)) {
const property = ctx.customStructureProperties.get(name)
const props = params[name as keyof typeof params]
if (props.autoAttach) {
if (autoAttach.includes(name)) {
try {
await property.attach(propertyCtx, structure, props)
} catch (e) {