|
@@ -64,6 +64,39 @@ export class StructureBuilder {
|
|
|
return trajectory.selector;
|
|
|
}
|
|
|
|
|
|
+ async parseStructure(params: {
|
|
|
+ data?: StateObjectRef<SO.Data.Binary | SO.Data.String>,
|
|
|
+ dataFormat?: TrajectoryFormat,
|
|
|
+ blob?: StateObjectRef<SO.Data.Blob>
|
|
|
+ blobParams?: StateTransformer.Params<StateTransforms['Data']['ParseBlob']>,
|
|
|
+ model?: StateTransformer.Params<StateTransforms['Model']['ModelFromTrajectory']>,
|
|
|
+ modelProperties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomModelProperties']>,
|
|
|
+ structure?: RootStructureDefinition.Params,
|
|
|
+ structureProperties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomStructureProperties']>
|
|
|
+ }) {
|
|
|
+ const trajectory = params.data
|
|
|
+ ? await this.parseTrajectory(params.data, params.dataFormat! || 'cif')
|
|
|
+ : await this.parseTrajectoryBlob(params.blob!, params.blobParams!);
|
|
|
+
|
|
|
+ const model = await this.createModel(trajectory, params.model);
|
|
|
+ const modelProperties = !!params.modelProperties
|
|
|
+ ? await this.insertModelProperties(model, typeof params?.modelProperties !== 'boolean' ? params?.modelProperties : void 0) : void 0;
|
|
|
+
|
|
|
+ const structure = await this.createStructure(modelProperties || model, params.structure);
|
|
|
+ const structureProperties = !!params.structureProperties
|
|
|
+ ? await this.insertStructureProperties(structure, typeof params?.structureProperties !== 'boolean' ? params?.structureProperties : void 0) : void 0;
|
|
|
+
|
|
|
+ return {
|
|
|
+ trajectory,
|
|
|
+ model: modelProperties || model,
|
|
|
+ modelBase: model,
|
|
|
+ modelProperties,
|
|
|
+ structure: structureProperties || structure,
|
|
|
+ structureBase: structure,
|
|
|
+ structureProperties
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
async parseTrajectory(data: StateObjectRef<SO.Data.Binary | SO.Data.String>, format: TrajectoryFormat): Promise<StateObjectSelector<SO.Molecule.Trajectory>>
|
|
|
async parseTrajectory(blob: StateObjectRef<SO.Data.Blob>, params: StateTransformer.Params<StateTransforms['Data']['ParseBlob']>): Promise<StateObjectSelector<SO.Molecule.Trajectory>>
|
|
|
async parseTrajectory(data: StateObjectRef, params: any) {
|
|
@@ -79,43 +112,57 @@ export class StructureBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async createModel(trajectory: StateObjectRef<SO.Molecule.Trajectory>, params?: {
|
|
|
- model?: StateTransformer.Params<StateTransforms['Model']['ModelFromTrajectory']>,
|
|
|
- properties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomModelProperties']>
|
|
|
- }) {
|
|
|
+ async createModel(trajectory: StateObjectRef<SO.Molecule.Trajectory>, params?: StateTransformer.Params<StateTransforms['Model']['ModelFromTrajectory']>) {
|
|
|
const state = this.dataState;
|
|
|
|
|
|
const model = state.build().to(trajectory)
|
|
|
- .apply(StateTransforms.Model.ModelFromTrajectory, params?.model || void 0, { tags: StructureBuilderTags.Model });
|
|
|
+ .apply(StateTransforms.Model.ModelFromTrajectory, params || { modelIndex: 0 }, { tags: StructureBuilderTags.Model });
|
|
|
|
|
|
- const props = !!params?.properties
|
|
|
- ? model.apply(StateTransforms.Model.CustomModelProperties, typeof params?.properties !== 'boolean' ? params?.properties : void 0, { tags: StructureBuilderTags.ModelProperties, isDecorator: true })
|
|
|
- : void 0;
|
|
|
+ // const props = !!params?.properties
|
|
|
+ // ? model.apply(StateTransforms.Model.CustomModelProperties, typeof params?.properties !== 'boolean' ? params?.properties : void 0, { tags: StructureBuilderTags.ModelProperties, isDecorator: true })
|
|
|
+ // : void 0;
|
|
|
|
|
|
await this.plugin.runTask(this.dataState.updateTree(model, { revertOnError: true }));
|
|
|
|
|
|
- const modelSelector = model.selector, propertiesSelector = props?.selector;
|
|
|
+ return model.selector;
|
|
|
|
|
|
- return { model: propertiesSelector || modelSelector, index: modelSelector, properties: propertiesSelector };
|
|
|
+ // const modelSelector = model.selector, propertiesSelector = props?.selector;
|
|
|
+
|
|
|
+ // return { model: propertiesSelector || modelSelector, index: modelSelector, properties: propertiesSelector };
|
|
|
}
|
|
|
|
|
|
- async createStructure(model: StateObjectRef<SO.Molecule.Model>, params?: {
|
|
|
- structure?: RootStructureDefinition.Params,
|
|
|
- properties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomStructureProperties']>
|
|
|
- }) {
|
|
|
+ async insertModelProperties(model: StateObjectRef<SO.Molecule.Model>, params?: StateTransformer.Params<StateTransforms['Model']['CustomModelProperties']>) {
|
|
|
+ const state = this.dataState;
|
|
|
+ const props = state.build().to(model)
|
|
|
+ .apply(StateTransforms.Model.CustomModelProperties, params, { tags: StructureBuilderTags.ModelProperties, isDecorator: true });
|
|
|
+ await this.plugin.runTask(this.dataState.updateTree(props, { revertOnError: true }));
|
|
|
+ return props.selector;
|
|
|
+ }
|
|
|
+
|
|
|
+ async createStructure(model: StateObjectRef<SO.Molecule.Model>, params?: RootStructureDefinition.Params) {
|
|
|
const state = this.dataState;
|
|
|
const structure = state.build().to(model)
|
|
|
- .apply(StateTransforms.Model.StructureFromModel, { type: params?.structure || { name: 'assembly', params: { } } }, { tags: StructureBuilderTags.Structure });
|
|
|
+ .apply(StateTransforms.Model.StructureFromModel, { type: params || { name: 'assembly', params: { } } }, { tags: StructureBuilderTags.Structure });
|
|
|
|
|
|
- const props = !!params?.properties
|
|
|
- ? structure.apply(StateTransforms.Model.CustomStructureProperties, typeof params?.properties !== 'boolean' ? params?.properties : void 0, { tags: StructureBuilderTags.StructureProperties, isDecorator: true })
|
|
|
- : void 0;
|
|
|
+ // const props = !!params?.properties
|
|
|
+ // ? structure.apply(StateTransforms.Model.CustomStructureProperties, typeof params?.properties !== 'boolean' ? params?.properties : void 0, { tags: StructureBuilderTags.StructureProperties, isDecorator: true })
|
|
|
+ // : void 0;
|
|
|
|
|
|
await this.plugin.runTask(this.dataState.updateTree(structure, { revertOnError: true }));
|
|
|
|
|
|
- const structureSelector = structure.selector, propertiesSelector = props?.selector;
|
|
|
+ return structure.selector;
|
|
|
|
|
|
- return { structure: propertiesSelector || structureSelector, definition: structureSelector, properties: propertiesSelector };
|
|
|
+ // const structureSelector = structure.selector, propertiesSelector = props?.selector;
|
|
|
+
|
|
|
+ // return { structure: propertiesSelector || structureSelector, definition: structureSelector, properties: propertiesSelector };
|
|
|
+ }
|
|
|
+
|
|
|
+ async insertStructureProperties(structure: StateObjectRef<SO.Molecule.Structure>, params?: StateTransformer.Params<StateTransforms['Model']['CustomStructureProperties']>) {
|
|
|
+ const state = this.dataState;
|
|
|
+ const props = state.build().to(structure)
|
|
|
+ .apply(StateTransforms.Model.CustomStructureProperties, params, { tags: StructureBuilderTags.StructureProperties, isDecorator: true });
|
|
|
+ await this.plugin.runTask(this.dataState.updateTree(props, { revertOnError: true }));
|
|
|
+ return props.selector;
|
|
|
}
|
|
|
|
|
|
/** returns undefined if the component is empty/null */
|