diff --git a/src/apps/rednatco/api-impl.ts b/src/apps/rednatco/api-impl.ts index 4121bb9e96b85482fda0c8bd1672926ba0433ae9..fa36829f0dd9f3091b37389f0013c2d141db6b54 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 549b8a44885a463c9e4ce8eb44f919b014715307..07d281d5a2d2a82b5a18bf1e5b5915b9fa862fd8 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 de537d688e735662f2cd77ceed309d7515c5202e..f6dda49d199c4f7006086bb396b767ac926d6b84 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 209e78ddc96ed9e767850fe0ddac9e93d5d7e45e..63514a690d29fb8961cb8605060fdbe24299f40e 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;