Skip to content

Commit

Permalink
#594 Electron Density - Settings read file
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-m2ms committed Apr 13, 2021
1 parent d6750de commit 5c1a7da
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 43 deletions.
38 changes: 33 additions & 5 deletions js/components/nglView/generatingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
41 changes: 23 additions & 18 deletions js/components/nglView/renderingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion js/components/preview/molecule/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
});
3 changes: 2 additions & 1 deletion js/components/preview/molecule/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
73 changes: 59 additions & 14 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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();

Expand Down
22 changes: 18 additions & 4 deletions js/components/preview/molecule/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { constants } from './constants';

export const INITIAL_STATE = {
sortDialogOpen: false,
imageCache: {}
imageCache: {},
proteinDataCache: {}
};

export const molecule = (state = INITIAL_STATE, action = {}) => {
Expand All @@ -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;
Expand Down

0 comments on commit 5c1a7da

Please sign in to comment.