From 5c1a7da674c986da53f427a63b582ac418e6b62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1na=20Kurillov=C3=A1?= Date: Tue, 13 Apr 2021 16:16:12 +0200 Subject: [PATCH] #594 Electron Density - Settings read file --- js/components/nglView/generatingObjects.js | 38 ++++++++-- js/components/nglView/renderingObjects.js | 41 ++++++----- .../preview/molecule/redux/actions.js | 7 +- .../preview/molecule/redux/constants.js | 3 +- .../preview/molecule/redux/dispatchActions.js | 73 +++++++++++++++---- .../preview/molecule/redux/reducer.js | 22 +++++- 6 files changed, 141 insertions(+), 43 deletions(-) diff --git a/js/components/nglView/generatingObjects.js b/js/components/nglView/generatingObjects.js index 1b019ff0b..f1b2df121 100644 --- a/js/components/nglView/generatingObjects.js +++ b/js/components/nglView/generatingObjects.js @@ -154,7 +154,12 @@ export const generateSurfaceObject = (data, colourToggle, base_url, datasetID) = // Density export const generateDensityObject = (data, colourToggle, base_url, isWireframeStyle) => { + const proteinData = data && data.proteinData; + let prot_url; + let sigmaa_url; + let diff_url; + let event_url; if (data && data.molecule_protein) { prot_url = base_url + data.molecule_protein; @@ -166,16 +171,39 @@ export const generateDensityObject = (data, colourToggle, base_url, isWireframeS } } + if (proteinData && proteinData.event_info) { + if (location.protocol === 'https:') { + event_url = proteinData.event_info.replace('http://', 'https://'); + } else { + event_url = proteinData.event_info; + } + } + + if (proteinData && proteinData.sigmaa_info) { + if (location.protocol === 'https:') { + sigmaa_url = proteinData.sigmaa_info.replace('http://', 'https://'); + } else { + sigmaa_url = proteinData.sigmaa_info; + } + } + + if (proteinData && proteinData.diff_info) { + if (location.protocol === 'https:') { + diff_url = proteinData.diff_info.replace('http://', 'https://'); + } else { + diff_url = proteinData.diff_info; + } + } + return { name: `${data.protein_code || data.name}_${OBJECT_TYPE.DENSITY}`, OBJECT_TYPE: OBJECT_TYPE.DENSITY, sdf_info: data.sdf_info, - map_info: data.map_info, - event_info: data.event_info, - sigmaa_info: data.sigmaa_info, - diff_info: data.diff_info, - colour: colourToggle, + event_url, + sigmaa_url, + diff_url, prot_url, + colour: colourToggle, moleculeId: data.id, wireframe: isWireframeStyle, selectionType: SELECTION_TYPE.DENSITY diff --git a/js/components/nglView/renderingObjects.js b/js/components/nglView/renderingObjects.js index 7b4fe50ec..54139deb4 100644 --- a/js/components/nglView/renderingObjects.js +++ b/js/components/nglView/renderingObjects.js @@ -387,7 +387,7 @@ const showHotspot = ({ stage, input_dict, object_name, representations }) => { } }; -const showDensity = ({ stage, input_dict, object_name, representations }) => { +const showDensity = ({ stage, input_dict, object_name, representations, dispatch }) => { let densityParams = { color: input_dict.coluor, isolevel: input_dict.isoLevel || 3, @@ -398,24 +398,29 @@ const showDensity = ({ stage, input_dict, object_name, representations }) => { opacity: input_dict.opacity || 1, opaqueBack: false }; - return Promise.all([ - stage.loadFile(input_dict.sigmaa_info, { name: object_name, ext: 'map' }).then(comp => { - const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); - const reprArray = representations || createRepresentationsArray([repr]); - return assignRepresentationArrayToComp(reprArray, comp); - }), - stage.loadFile(input_dict.diff_info, { name: object_name, ext: 'map' }).then(comp => { - const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); - const reprArray = representations || createRepresentationsArray([repr]); - return assignRepresentationArrayToComp(reprArray, comp); - }), - stage.loadFile(input_dict.event_info, { name: object_name, ext: 'ccp4' }).then(comp => { - const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); - const reprArray = representations || createRepresentationsArray([repr]); - return assignRepresentationArrayToComp(reprArray, comp); - }) - ]).then(values => [...values]); + input_dict.sigmaa_url && + stage.loadFile(input_dict.sigmaa_url, { ext: 'map' }).then(comp => { + const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); + const reprArray = representations || createRepresentationsArray([repr]); + return assignRepresentationArrayToComp(reprArray, comp); + }), + input_dict.diff_url && + stage.loadFile(input_dict.diff_url, { name: object_name, ext: 'map' }).then(comp => { + const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); + const reprArray = representations || createRepresentationsArray([repr]); + return assignRepresentationArrayToComp(reprArray, comp); + }), + + input_dict.event_url && + stage.loadFile(input_dict.event_url, { name: object_name, ext: 'ccp4' }).then(comp => { + const repr = createRepresentationStructure(MOL_REPRESENTATION.surface, densityParams); + const reprArray = representations || createRepresentationsArray([repr]); + return assignRepresentationArrayToComp(reprArray, comp); + }) + ]).then(values => { + let val = [...values]; + }); }; // Refactor this out into a utils directory diff --git a/js/components/preview/molecule/redux/actions.js b/js/components/preview/molecule/redux/actions.js index 0415ce91a..912c0598f 100644 --- a/js/components/preview/molecule/redux/actions.js +++ b/js/components/preview/molecule/redux/actions.js @@ -12,5 +12,10 @@ export const reloadMoleculeReducer = newState => ({ export const addImageToCache = (molId, image) => ({ type: constants.ADD_IMAGE_TO_CACHE, - payload: {molId: molId, image: image} + payload: { molId: molId, image: image } +}); + +export const addProteindDataToCache = (molId, proteinData) => ({ + type: constants.ADD_PROTEIN_DATA_TO_CACHE, + payload: { molId: molId, image: proteinData } }); diff --git a/js/components/preview/molecule/redux/constants.js b/js/components/preview/molecule/redux/constants.js index 62f9fac26..bb1ca6131 100644 --- a/js/components/preview/molecule/redux/constants.js +++ b/js/components/preview/molecule/redux/constants.js @@ -3,7 +3,8 @@ const prefix = 'PREVIEW_MOLECULE_'; export const constants = { SET_SORT_DIALOG_OPEN: prefix + 'SET_SORT_DIALOG_OPEN', RELOAD_REDUCER: prefix + 'RELOAD_REDUCER', - ADD_IMAGE_TO_CACHE: prefix + 'ADD_IMAGE_TO_CACHE' + ADD_IMAGE_TO_CACHE: prefix + 'ADD_IMAGE_TO_CACHE', + ADD_PROTEIN_DATA_TO_CACHE: prefix + 'ADD_PROTEIN_DATA_TO_CACHE' }; export const MOL_ATTR = { diff --git a/js/components/preview/molecule/redux/dispatchActions.js b/js/components/preview/molecule/redux/dispatchActions.js index 237f56ff9..e41118899 100644 --- a/js/components/preview/molecule/redux/dispatchActions.js +++ b/js/components/preview/molecule/redux/dispatchActions.js @@ -292,21 +292,28 @@ export const addDensity = ( skipTracking = false, representations = undefined ) => dispatch => { - dispatch( - loadObject({ - target: Object.assign( - { display_div: VIEWS.MAJOR_VIEW }, - generateDensityObject(data, colourToggle, base_url, isWireframeStyle) - ), - stage, - previousRepresentations: representations, - orientationMatrix: null - }) - ).finally(() => { - const currentOrientation = stage.viewerControls.getOrientation(); - dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation)); + dispatch(getProteinData(data)).then(i => { + if (i && i.length > 0) { + data.protein_data = i[0]; + + dispatch( + loadObject({ + target: Object.assign( + { display_div: VIEWS.MAJOR_VIEW }, + generateDensityObject(data, colourToggle, base_url, isWireframeStyle) + ), + stage, + previousRepresentations: representations, + orientationMatrix: null + }) + ).finally(() => { + const currentOrientation = stage.viewerControls.getOrientation(); + dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation)); + }); + } + + dispatch(appendDensityList(generateMoleculeId(data), skipTracking)); }); - dispatch(appendDensityList(generateMoleculeId(data), skipTracking)); }; export const addDensityCustomView = ( @@ -773,6 +780,44 @@ export const getQualityInformation = (data, molType, width, height) => (dispatch } }; +export const getProteinData = molecule => (dispatch, getState) => { + const state = getState(); + + const proteindDataCache = state.previewReducers.molecule.proteinDataCache; + + const code = molecule.protein_code; + const molId = molecule.id; + const molIdStr = molId.toString(); + if (proteindDataCache.hasOwnProperty(molIdStr)) { + return new Promise((resolve, reject) => { + resolve(proteindDataCache[molIdStr]); + }); + } else { + return loadProteinData(code).then(i => { + if (!proteindDataCache.hasOwnProperty(molIdStr)) { + dispatch(addImageToCache(molId.toString(), i)); + } + return i; + }); + } +}; + +const loadProteinData = code => { + if (code) { + let url = new URL(`${base_url}/api/proteins/?code=${code}`); + let onCancel = () => {}; + return api({ + url, + onCancel + }).then(response => { + return response.data.results; + }); + } else { + console.error('Trying to load protein data for unknown molecule protein code.'); + return Promise.resolve(); + } +}; + export const getMolImage = (molId, molType, width, height) => (dispatch, getState) => { const state = getState(); diff --git a/js/components/preview/molecule/redux/reducer.js b/js/components/preview/molecule/redux/reducer.js index 81348038d..5c1627b8a 100644 --- a/js/components/preview/molecule/redux/reducer.js +++ b/js/components/preview/molecule/redux/reducer.js @@ -2,7 +2,8 @@ import { constants } from './constants'; export const INITIAL_STATE = { sortDialogOpen: false, - imageCache: {} + imageCache: {}, + proteinDataCache: {} }; export const molecule = (state = INITIAL_STATE, action = {}) => { @@ -16,9 +17,22 @@ export const molecule = (state = INITIAL_STATE, action = {}) => { return Object.assign({}, state, { ...action.payload }); case constants.ADD_IMAGE_TO_CACHE: - return {...state, imageCache: { - ...state.imageCache, [action.payload.molId]: action.payload.image - }}; + return { + ...state, + imageCache: { + ...state.imageCache, + [action.payload.molId]: action.payload.image + } + }; + + case constants.ADD_PROTEIN_DATA_TO_CACHE: + return { + ...state, + proteinDataCache: { + ...state.proteinDataCache, + [action.payload.molId]: action.payload.proteinData + } + }; default: return state;