Skip to content

Commit

Permalink
#593 Electron Density - D button behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-m2ms committed Mar 26, 2021
1 parent fb0e78e commit 760cd0e
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 57 deletions.
2 changes: 2 additions & 0 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export const DatasetMoleculeList = memo(
const fragmentDisplayListMolecule = useSelector(state => state.selectionReducers.fragmentDisplayList);
const surfaceListMolecule = useSelector(state => state.selectionReducers.surfaceList);
const densityListMolecule = useSelector(state => state.selectionReducers.densityList);
const densityListCustomMolecule = useSelector(state => state.selectionReducers.densityListCustom);
const vectorOnListMolecule = useSelector(state => state.selectionReducers.vectorOnList);

const ligandList = useSelector(state => state.datasetsReducers.ligandLists[datasetID]);
Expand Down Expand Up @@ -317,6 +318,7 @@ export const DatasetMoleculeList = memo(
complexListMolecule,
surfaceListMolecule,
densityListMolecule,
densityListCustomMolecule,
vectorOnListMolecule,
skipTracking
)
Expand Down
43 changes: 2 additions & 41 deletions js/components/datasets/inspirationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
removeLigand,
removeHitProtein,
removeSurface,
removeDensity,
removeVector
removeAllSelectedMolTypes
} from '../preview/molecule/redux/dispatchActions';
import MoleculeView from '../preview/molecule/moleculeView';
import { moleculeProperty } from '../preview/molecule/helperConstants';
Expand Down Expand Up @@ -210,45 +209,7 @@ export const InspirationDialog = memo(
const selectMoleculeSite = moleculeGroupSite => {};

const removeOfAllSelectedTypes = (skipTracking = false) => {
proteinList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);

dispatch(
removeHitProtein(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
complexList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);
dispatch(
removeComplex(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
ligandList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);
dispatch(removeLigand(stage, foundedMolecule, skipTracking));
});
surfaceList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);
dispatch(
removeSurface(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
densityList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);
dispatch(
removeDensity(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
vectorOnList?.forEach(moleculeID => {
let foundedMolecule = moleculeList?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: true }, foundedMolecule);
dispatch(removeVector(stage, foundedMolecule, skipTracking));
});
dispatch(removeAllSelectedMolTypes(stage, moleculeList, skipTracking, true));
};

const removeSelectedType = (type, skipTracking = false) => {
Expand Down
45 changes: 42 additions & 3 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ import {
addComplex,
addSurface,
addLigand,
addDensity
addDensity,
addDensityCustomView
} from '../../preview/molecule/redux/dispatchActions';
import { OBJECT_TYPE } from '../../nglView/constants';
import { getRepresentationsByType } from '../../nglView/generatingObjects';
Expand Down Expand Up @@ -724,6 +725,7 @@ export const moveMoleculeInspirationsSettings = (
complexListMolecule,
surfaceListMolecule,
densityListMolecule,
densityCustomListMolecule,
vectorOnListMolecule,
skipTracking
) => (dispatch, getState) => {
Expand All @@ -735,6 +737,10 @@ export const moveMoleculeInspirationsSettings = (
let isAnyInspirationComplexOn = isAnyInspirationTurnedOnByType(computed_inspirations, complexListMolecule);
let isAnyInspirationSurfaceOn = isAnyInspirationTurnedOnByType(computed_inspirations, surfaceListMolecule);
let isAnyInspirationDensityOn = isAnyInspirationTurnedOnByType(computed_inspirations, densityListMolecule);
let isAnyInspirationDensityOnCustom = isAnyInspirationTurnedOnByType(
computed_inspirations,
densityCustomListMolecule
);
let isAnyInspirationVectorOn = isAnyInspirationTurnedOnByType(computed_inspirations, vectorOnListMolecule);

if (
Expand All @@ -743,9 +749,9 @@ export const moveMoleculeInspirationsSettings = (
isAnyInspirationComplexOn ||
isAnyInspirationSurfaceOn ||
isAnyInspirationDensityOn ||
isAnyInspirationDensityOnCustom ||
isAnyInspirationVectorOn
) {
// dispatch(loadInspirationMoleculesDataList(newItemData.computed_inspirations)).then(() => {
dispatch(
moveInspirations(
stage,
Expand All @@ -755,11 +761,11 @@ export const moveMoleculeInspirationsSettings = (
isAnyInspirationComplexOn,
isAnyInspirationSurfaceOn,
isAnyInspirationDensityOn,
isAnyInspirationDensityOnCustom,
isAnyInspirationVectorOn,
skipTracking
)
);
// });
}
}
};
Expand All @@ -772,6 +778,7 @@ const moveInspirations = (
isAnyInspirationComplexOn,
isAnyInspirationSurfaceOn,
isAnyInspirationDensityOn,
isAnyInspirationDensityOnCustom,
isAnyInspirationVectorOn,
skipTracking
) => (dispatch, getState) => {
Expand Down Expand Up @@ -817,6 +824,18 @@ const moveInspirations = (
addDensity(stage, molecule, colourList[molecule.id % colourList.length], skipTracking, representations)
);
}
if (isAnyInspirationDensityOnCustom) {
let representations = getRepresentationsByType(objectsInView, molecule, OBJECT_TYPE.DENSITY);
dispatch(
addDensityCustomView(
stage,
molecule,
colourList[molecule.id % colourList.length],
skipTracking,
representations
)
);
}
if (isAnyInspirationVectorOn) {
dispatch(addVector(stage, molecule, colourList[molecule.id % colourList.length], skipTracking));
}
Expand All @@ -832,6 +851,8 @@ export const moveSelectedInspirations = (
proteinListMolecule,
complexListMolecule,
surfaceListMolecule,
densityListMolecule,
densityListCustomMolecule,
vectorOnListMolecule,
skipTracking
) => (dispatch, getState) => {
Expand Down Expand Up @@ -871,6 +892,24 @@ export const moveSelectedInspirations = (
addSurface(stage, molecule, colourList[molecule.id % colourList.length], skipTracking, representations)
);
}
if (densityListMolecule.includes(molecule.id)) {
let representations = getRepresentationsByType(objectsInView, molecule, OBJECT_TYPE.DENSITY);
dispatch(
addDensity(stage, molecule, colourList[molecule.id % colourList.length], skipTracking, representations)
);
}
if (densityListCustomMolecule.includes(molecule.id)) {
let representations = getRepresentationsByType(objectsInView, molecule, OBJECT_TYPE.DENSITY);
dispatch(
addDensityCustomView(
stage,
molecule,
colourList[molecule.id % colourList.length],
skipTracking,
representations
)
);
}
if (vectorOnListMolecule.includes(molecule.id)) {
dispatch(addVector(stage, molecule, colourList[molecule.id % colourList.length], skipTracking));
}
Expand Down
2 changes: 1 addition & 1 deletion js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei

const removeOfAllSelectedTypes = (skipTracking = false) => {
let molecules = [...getJoinedMoleculeList, ...allInspirationMoleculeDataList];
dispatch(removeAllSelectedMolTypes(majorViewStage, molecules, skipTracking));
dispatch(removeAllSelectedMolTypes(majorViewStage, molecules, skipTracking, false));
};

const selectMoleculeSite = moleculeGroupSite => {
Expand Down
81 changes: 73 additions & 8 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ export const addDensityCustomView = (
skipTracking = false,
representations = undefined
) => dispatch => {
// delete object at first (removeDensity)
// load other object

//dispatch(
// loadObject({
// target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateDensityObject(data, colourToggle, base_url)),
Expand All @@ -322,7 +325,7 @@ export const addDensityCustomView = (
};

export const removeDensity = (stage, data, colourToggle, skipTracking = false) => dispatch => {
////dispatch(
//dispatch(
// deleteObject(
// Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateDensityObject(data, colourToggle, base_url)),
// stage
Expand Down Expand Up @@ -390,12 +393,16 @@ export const hideAllSelectedMolecules = (stage, currentMolecules, isHideAll, ski
const vectorOnList = state.selectionReducers.vectorOnList;
const surfaceList = state.selectionReducers.surfaceList;
const proteinList = state.selectionReducers.proteinList;
const densityList = state.selectionReducers.densityList;
const densityListCustom = state.selectionReducers.densityListCustom;

let ligandDataList = [];
let complexDataList = [];
let vectorOnDataList = [];
let surfaceDataList = [];
let proteinDataList = [];
let densityDataList = [];
let densityDataListCustom = [];

fragmentDisplayList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
Expand All @@ -418,6 +425,13 @@ export const hideAllSelectedMolecules = (stage, currentMolecules, isHideAll, ski
dispatch(removeVector(stage, data, skipTracking));
}
});
surfaceList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
surfaceDataList.push(data);
dispatch(removeSurface(stage, data, colourList[0], skipTracking));
}
});

// remove Surface
surfaceList.forEach(moleculeId => {
Expand All @@ -437,6 +451,22 @@ export const hideAllSelectedMolecules = (stage, currentMolecules, isHideAll, ski
}
});

densityList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
densityDataList.push(data);
dispatch(removeDensity(stage, data, colourList[0], skipTracking));
}
});

densityListCustom.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
densityDataListCustom.push(data);
dispatch(removeDensity(stage, data, colourList[0], skipTracking));
}
});

// vector_list
dispatch(setVectorList([]));
dispatch(resetCompoundsOfVectors());
Expand All @@ -448,7 +478,9 @@ export const hideAllSelectedMolecules = (stage, currentMolecules, isHideAll, ski
proteinList: proteinDataList,
complexList: complexDataList,
surfaceList: surfaceDataList,
vectorOnList: vectorOnDataList
vectorOnList: vectorOnDataList,
densityList: densityDataList,
densityListCustom: densityDataListCustom
};

if (isHideAll === true) {
Expand All @@ -474,6 +506,14 @@ export const moveSelectedMolSettings = (stage, item, newItem, data, skipTracking
let representations = getRepresentationsByType(data.objectsInView, item, OBJECT_TYPE.SURFACE);
dispatch(addSurface(stage, newItem, data.colourToggle, skipTracking, representations));
}
if (data.isDensityOn) {
let representations = getRepresentationsByType(data.objectsInView, item, OBJECT_TYPE.DENSITY);
dispatch(addDensity(stage, newItem, data.colourToggle, skipTracking, representations));
}
if (data.isDensityCustomOn) {
let representations = getRepresentationsByType(data.objectsInView, item, OBJECT_TYPE.DENSITY);
dispatch(addDensityCustomView(stage, newItem, data.colourToggle, skipTracking, representations));
}
if (data.isVectorOn) {
dispatch(addVector(stage, newItem, skipTracking)).catch(error => {
throw new Error(error);
Expand All @@ -482,17 +522,24 @@ export const moveSelectedMolSettings = (stage, item, newItem, data, skipTracking
}
};

export const removeAllSelectedMolTypes = (majorViewStage, molecules, skipTracking = false) => (dispatch, getState) => {
export const removeAllSelectedMolTypes = (majorViewStage, molecules, skipTracking, isInspiration) => (
dispatch,
getState
) => {
const state = getState();
const fragmentDisplayList = state.selectionReducers.fragmentDisplayList;
const complexList = state.selectionReducers.complexList;
const vectorOnList = state.selectionReducers.vectorOnList;
const surfaceList = state.selectionReducers.surfaceList;
const proteinList = state.selectionReducers.proteinList;
const densityList = state.selectionReducers.densityList;
const densityListCustom = state.selectionReducers.densityListCustom;
let joinedMoleculeLists = molecules;

proteinList?.forEach(moleculeID => {
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);

dispatch(
removeHitProtein(
majorViewStage,
Expand All @@ -503,23 +550,41 @@ export const removeAllSelectedMolTypes = (majorViewStage, molecules, skipTrackin
);
});
complexList?.forEach(moleculeID => {
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(
removeComplex(majorViewStage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
fragmentDisplayList?.forEach(moleculeID => {
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(removeLigand(majorViewStage, foundedMolecule, skipTracking));
});
surfaceList?.forEach(moleculeID => {
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(
removeSurface(majorViewStage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
densityList?.forEach(moleculeID => {
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(
removeDensity(majorViewStage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
densityListCustom?.forEach(moleculeID => {
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(
removeDensity(majorViewStage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], skipTracking)
);
});
vectorOnList?.forEach(moleculeID => {
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
let foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
foundedMolecule = foundedMolecule && Object.assign({ isInspiration: isInspiration }, foundedMolecule);
dispatch(removeVector(majorViewStage, foundedMolecule, skipTracking));
});
};
Expand Down
Loading

0 comments on commit 760cd0e

Please sign in to comment.