From 884f2fb3e354a16ed81b42f1cdccc3d51310ba3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= <michal.maly@ibt.cas.cz> Date: Fri, 11 Nov 2022 20:52:14 +0100 Subject: [PATCH] ReDNATCO plugin stage 34 --- src/apps/rednatco/api-impl.ts | 2 +- src/apps/rednatco/api.ts | 2 +- src/apps/rednatco/index.tsx | 2 +- src/apps/rednatco/viewer.ts | 40 ++++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/apps/rednatco/api-impl.ts b/src/apps/rednatco/api-impl.ts index 4121bb9e9..fa36829f0 100644 --- a/src/apps/rednatco/api-impl.ts +++ b/src/apps/rednatco/api-impl.ts @@ -34,7 +34,7 @@ export class ReDNATCOMspApiImpl implements ReDNATCOMspApi.Object { return !!this.target; } - loadStructure(coords: { data: string, type: 'cif'|'pdb' }, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6' }|null) { + loadStructure(coords: { data: string, type: 'cif'|'pdb' }, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6'|'ds' }|null) { this.check(); this.target!.loadStructure(coords, densityMap); } diff --git a/src/apps/rednatco/api.ts b/src/apps/rednatco/api.ts index 549b8a448..07d281d5a 100644 --- a/src/apps/rednatco/api.ts +++ b/src/apps/rednatco/api.ts @@ -126,7 +126,7 @@ export namespace ReDNATCOMspApi { event: (evt: Event) => void; init: (elemId: string, onEvent?: (evt: Event) => void) => void; isReady: () => boolean; - loadStructure: (coords: { data: string, type: 'cif'|'pdb'}, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6' }|null) => void; + loadStructure: (coords: { data: string, type: 'cif'|'pdb'}, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6'|'ds' }|null) => void; query: <T extends Queries.Type>(type: T) => ResponseTypes[T]; } } diff --git a/src/apps/rednatco/index.tsx b/src/apps/rednatco/index.tsx index de537d688..f6dda49d1 100644 --- a/src/apps/rednatco/index.tsx +++ b/src/apps/rednatco/index.tsx @@ -226,7 +226,7 @@ export class ReDNATCOMsp extends React.Component<ReDNATCOMsp.Props, State> { } } - loadStructure(coords: { data: string, type: 'pdb'|'cif' }, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6' }|null) { + loadStructure(coords: { data: string, type: 'pdb'|'cif' }, densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6'|'ds' }|null) { if (this.viewer) { this.viewer.loadStructure(coords, densityMap, this.state.display).then(() => { this.presentConformers = this.viewer!.getPresentConformers(); diff --git a/src/apps/rednatco/viewer.ts b/src/apps/rednatco/viewer.ts index 209e78ddc..63514a690 100644 --- a/src/apps/rednatco/viewer.ts +++ b/src/apps/rednatco/viewer.ts @@ -852,7 +852,7 @@ export class ReDNATCOMspViewer { async loadStructure( coords: { data: string, type: 'pdb'|'cif' }, - densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6' }|null, + densityMap: { data: Uint8Array, type: 'ccp4'|'dsn6'|'ds' }|null, display: Display ) { // TODO: Remove the currently loaded structure @@ -942,28 +942,38 @@ export class ReDNATCOMspViewer { // Load density map, if any if (densityMap) { - const [ParseTransform, VolumeTransform] = densityMap.type === 'ccp4' - ? [StateTransforms.Data.ParseCcp4, StateTransforms.Volume.VolumeFromCcp4] - : [StateTransforms.Data.ParseDsn6, StateTransforms.Volume.VolumeFromDsn6]; - const b4 = this.plugin.state.data.build(); - b4.toRoot() - .apply(RawData, { data: densityMap.data }, { ref: IDs.DensityID('data', BaseRef) }) - .apply(ParseTransform) - .apply(VolumeTransform, {}, { ref: IDs.DensityID('volume', BaseRef) }); - - await b4.commit(); // Load the density map now so we can probe the stats; + // This is ridiculous but anything saner breaks type checker + if (densityMap.type === 'ccp4') { + await this.plugin.state.data.build().toRoot() + .apply(RawData, { data: densityMap.data }, { ref: IDs.DensityID('data', BaseRef) }) + .apply(StateTransforms.Data.ParseCcp4) + .apply(StateTransforms.Volume.VolumeFromCcp4, {}, { ref: IDs.DensityID('volume', BaseRef) }) + .commit(); + } else if (densityMap.type === 'dsn6') { + await this.plugin.state.data.build().toRoot() + .apply(RawData, { data: densityMap.data }, { ref: IDs.DensityID('data', BaseRef) }) + .apply(StateTransforms.Data.ParseDsn6) + .apply(StateTransforms.Volume.VolumeFromDsn6, {}, { ref: IDs.DensityID('volume', BaseRef) }) + .commit(); + } else if (densityMap.type === 'ds') { + await this.plugin.state.data.build().toRoot() + .apply(RawData, { data: densityMap.data }, { ref: IDs.DensityID('data', BaseRef) }) + .apply(StateTransforms.Data.ParseCif) + .apply(StateTransforms.Volume.VolumeFromDensityServerCif, {}, { ref: IDs.DensityID('volume', BaseRef) }) + .commit(); + } + const isoRange = this.densityMapIsoRange()!; const bounds = isoBounds(isoRange.min, isoRange.max); const iso = prettyIso(((isoRange.max - isoRange.min) / 2) + isoRange.min, bounds.step); - const b5 = this.plugin.state.data.build().to(IDs.DensityID('volume', BaseRef)) + await this.plugin.state.data.build().to(IDs.DensityID('volume', BaseRef)) .apply( StateTransforms.Representation.VolumeRepresentation3D, this.densityMapVisuals(display.densityMap), { ref: IDs.DensityID('visual', BaseRef) } - ); - - await b5.commit(); + ) + .commit(); display.densityMap.representations = ['wireframe']; display.densityMap.isoValue = iso; -- GitLab