Skip to content

Commit ff812f1

Browse files
- #441 - nearly finished implementation
1 parent 452b8ce commit ff812f1

File tree

11 files changed

+203
-62
lines changed

11 files changed

+203
-62
lines changed

js/components/datasets/datasetMoleculeView.js

+28-13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { isString } from 'lodash';
4343
import { SvgTooltip } from '../common';
4444
import { getMolImage } from '../preview/molecule/redux/dispatchActions';
4545
import { MOL_TYPE } from '../preview/molecule/redux/constants';
46+
import { deselectVectorCompound, isCompoundFromVectorSelector, showHideLigand } from '../preview/compounds/redux/dispatchActions';
4647

4748
const useStyles = makeStyles(theme => ({
4849
container: {
@@ -264,10 +265,12 @@ export const DatasetMoleculeView = memo(
264265
P,
265266
C,
266267
S,
267-
V
268+
V,
269+
fromSelectedCompounds = false
268270
}) => {
269271
const selectedAll = useRef(false);
270-
const currentID = (data && data.id) || undefined;
272+
const currentID = (data && data.id) || (data && data.smiles) || undefined;
273+
const isFromVectorSelector = isCompoundFromVectorSelector(data);
271274
const classes = useStyles();
272275
const ref = useRef(null);
273276
const dispatch = useDispatch();
@@ -299,7 +302,11 @@ export const DatasetMoleculeView = memo(
299302
const hasAllValuesOn = isLigandOn && isProteinOn && isComplexOn;
300303
const hasSomeValuesOn = !hasAllValuesOn && (isLigandOn || isProteinOn || isComplexOn || isSurfaceOn);
301304

302-
const areArrowsVisible = isLigandOn || isProteinOn || isComplexOn || isSurfaceOn;
305+
let areArrowsVisible = isLigandOn || isProteinOn || isComplexOn || isSurfaceOn;
306+
307+
if (fromSelectedCompounds) {
308+
areArrowsVisible = false;
309+
}
303310

304311
// const disableUserInteraction = useDisableUserInteraction();
305312

@@ -359,10 +366,14 @@ export const DatasetMoleculeView = memo(
359366
} else if (calledFromSelectAll && selectedAll.current === false) {
360367
removeSelectedLigand(calledFromSelectAll);
361368
} else if (!calledFromSelectAll) {
362-
if (isLigandOn === false) {
363-
addNewLigand();
369+
if (isFromVectorSelector) {
370+
dispatch(showHideLigand(data, stage));
364371
} else {
365-
removeSelectedLigand();
372+
if (isLigandOn === false) {
373+
addNewLigand();
374+
} else {
375+
removeSelectedLigand();
376+
}
366377
}
367378
}
368379
};
@@ -558,6 +569,7 @@ export const DatasetMoleculeView = memo(
558569
dispatch(appendMoleculeToCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
559570
} else {
560571
dispatch(removeMoleculeFromCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
572+
dispatch(deselectVectorCompound(data));
561573
}
562574
}}
563575
/>
@@ -646,7 +658,7 @@ export const DatasetMoleculeView = memo(
646658
onProtein(true);
647659
onComplex(true);
648660
}}
649-
disabled={false}
661+
disabled={isFromVectorSelector}
650662
>
651663
A
652664
</Button>
@@ -674,7 +686,7 @@ export const DatasetMoleculeView = memo(
674686
[classes.contColButtonSelected]: isProteinOn
675687
})}
676688
onClick={() => onProtein()}
677-
disabled={false}
689+
disabled={isFromVectorSelector}
678690
>
679691
P
680692
</Button>
@@ -689,7 +701,7 @@ export const DatasetMoleculeView = memo(
689701
[classes.contColButtonSelected]: isComplexOn
690702
})}
691703
onClick={() => onComplex()}
692-
disabled={false}
704+
disabled={isFromVectorSelector}
693705
>
694706
C
695707
</Button>
@@ -703,7 +715,7 @@ export const DatasetMoleculeView = memo(
703715
[classes.contColButtonSelected]: isSurfaceOn
704716
})}
705717
onClick={() => onSurface()}
706-
disabled={false}
718+
disabled={isFromVectorSelector}
707719
>
708720
S
709721
</Button>
@@ -729,7 +741,7 @@ export const DatasetMoleculeView = memo(
729741
setRef(ref.current);
730742
}
731743
}}
732-
disabled={false}
744+
disabled={isFromVectorSelector}
733745
>
734746
F
735747
</Button>
@@ -751,7 +763,7 @@ export const DatasetMoleculeView = memo(
751763
setRef(ref.current);
752764
}
753765
}}
754-
disabled={false}
766+
disabled={isFromVectorSelector}
755767
>
756768
X
757769
</Button>
@@ -776,7 +788,10 @@ export const DatasetMoleculeView = memo(
776788
filteredScoreProperties[datasetID] &&
777789
filteredScoreProperties[datasetID].map(score => {
778790
//const item = scoreCompoundMap && scoreCompoundMap[data?.compound]?.find(o => o.score.id === score.id);
779-
const value = allScores[score.name];
791+
let value = allScores[score.name];
792+
if (!value) {
793+
value = data[score.name];
794+
}
780795
return (
781796
<Tooltip title={`${score.name} - ${score.description} : ${value}`} key={score.name}>
782797
{(value && (

js/components/datasets/redux/reducer.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,16 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
275275
return Object.assign({}, state, { scoreCompoundMap: {} });
276276

277277
case constants.UPDATE_FILTER_SHOWED_SCORE_PROPERTIES:
278-
return {
279-
...state,
280-
filteredScoreProperties: {
281-
...state.filteredScoreProperties,
282-
[action.payload.datasetID]: action.payload.scoreList
283-
}
278+
if (state.filteredScoreProperties[action.payload.datasetID]) {
279+
return {...state};
280+
} else {
281+
return {
282+
...state,
283+
filteredScoreProperties: {
284+
...state.filteredScoreProperties,
285+
[action.payload.datasetID]: action.payload.scoreList
286+
}
287+
};
284288
};
285289

286290
case constants.REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES:

js/components/datasets/redux/selectors.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const densityList = state => state.selectionReducers.densityList;
1818
const vectorOnList = state => state.selectionReducers.vectorOnList;
1919
const filteredScoreProperties = state => state.datasetsReducers.filteredScoreProperties;
2020

21+
const selectedVectorCompounds = state => state.previewReducers.compounds.allSelectedCompounds;
22+
2123
export const getInitialDatasetFilterSettings = createSelector(
2224
(_, datasetID) => datasetID,
2325
scoreDatasetMap,
@@ -259,7 +261,7 @@ export const getFilteredDatasetMoleculeList = createSelector(
259261
const defaultFilterProperties = getInitialDatasetFilterProperties(state, datasetID);
260262

261263
let sortedAttributes = filterSettings.priorityOrder
262-
.filter(attr => defaultFilterProperties[attr]?.order != 0 || false)
264+
.filter(attr => defaultFilterProperties[attr]?.order !== 0 || false)
263265
.map(attr => attr);
264266

265267
return filteredMolecules.sort((a, b) => {
@@ -304,7 +306,8 @@ export const getFilteredDatasetMoleculeList = createSelector(
304306
export const getMoleculesObjectIDListOfCompoundsToBuy = createSelector(
305307
compoundsToBuyDatasetMap,
306308
moleculeLists,
307-
(compoundsToBuyDatasetMap, moleculeLists) => {
309+
selectedVectorCompounds,
310+
(compoundsToBuyDatasetMap, moleculeLists, selectedVectorCompounds) => {
308311
let moleculeList = [];
309312
Object.keys(compoundsToBuyDatasetMap).forEach(datasetID => {
310313
compoundsToBuyDatasetMap[datasetID] &&
@@ -314,6 +317,9 @@ export const getMoleculesObjectIDListOfCompoundsToBuy = createSelector(
314317
if (foundedMolecule) {
315318
moleculeList.push({ molecule: foundedMolecule, datasetID });
316319
}
320+
} else if (selectedVectorCompounds[moleculeID]) {
321+
const cmp = selectedVectorCompounds[moleculeID];
322+
moleculeList.push({ molecule: {...cmp, name: cmp.smiles}, datasetID });
317323
}
318324
});
319325
});

js/components/datasets/selectedCompoundsList.js

+36-20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { NglContext } from '../nglView/nglProvider';
2727
import { VIEWS } from '../../constants/constants';
2828
import FileSaver from 'file-saver';
2929
import JSZip from 'jszip';
30+
import { isCompoundFromVectorSelector } from '../preview/compounds/redux/dispatchActions';
31+
3032

3133
const useStyles = makeStyles(theme => ({
3234
container: {
@@ -86,6 +88,8 @@ export const SelectedCompoundList = memo(({ height }) => {
8688
const complexListAllDatasets = useSelector(state => state.datasetsReducers.complexLists);
8789
const surfaceListAllDatasets = useSelector(state => state.datasetsReducers.surfaceLists);
8890

91+
const showedCompoundList = useSelector(state => state.previewReducers.compounds.showedCompoundList);
92+
8993
const removeOfAllSelectedTypes = () => {
9094
Object.keys(ligandListAllDatasets).forEach(datasetKey => {
9195
ligandListAllDatasets[datasetKey]?.forEach(moleculeID => {
@@ -236,26 +240,38 @@ export const SelectedCompoundList = memo(({ height }) => {
236240
}
237241
useWindow={false}
238242
>
239-
{currentMolecules.map((data, index, array) => (
240-
<DatasetMoleculeView
241-
key={index}
242-
index={index}
243-
imageHeight={imgHeight}
244-
imageWidth={imgWidth}
245-
data={data.molecule}
246-
datasetID={data.datasetID}
247-
setRef={setSelectedMoleculeRef}
248-
showCrossReferenceModal
249-
previousItemData={index > 0 && array[index - 1]}
250-
nextItemData={index < array?.length && array[index + 1]}
251-
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
252-
L={ligandList.includes(data.molecule.id)}
253-
P={proteinList.includes(data.molecule.id)}
254-
C={complexList.includes(data.molecule.id)}
255-
S={surfaceList.includes(data.molecule.id)}
256-
V={false}
257-
/>
258-
))}
243+
{currentMolecules.map((data, index, array) => {
244+
const isFromVectorSelector = isCompoundFromVectorSelector(data.molecule);
245+
let isLigandOn = false;
246+
if (isFromVectorSelector) {
247+
if (showedCompoundList.find(item => item === data.molecule.smiles) !== undefined) {
248+
isLigandOn = true;
249+
}
250+
} else {
251+
isLigandOn = ligandList.includes(data.molecule.id);
252+
}
253+
return (
254+
<DatasetMoleculeView
255+
key={index}
256+
index={index}
257+
imageHeight={imgHeight}
258+
imageWidth={imgWidth}
259+
data={data.molecule}
260+
datasetID={data.datasetID}
261+
setRef={setSelectedMoleculeRef}
262+
showCrossReferenceModal
263+
previousItemData={index > 0 && array[index - 1]}
264+
nextItemData={index < array?.length && array[index + 1]}
265+
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
266+
L={isLigandOn}
267+
P={proteinList.includes(data.molecule.id)}
268+
C={complexList.includes(data.molecule.id)}
269+
S={surfaceList.includes(data.molecule.id)}
270+
V={false}
271+
fromSelectedCompounds={true}
272+
/>
273+
)
274+
})}
259275
</InfiniteScroll>
260276
</Grid>
261277
)}

js/components/preview/compounds/compoundView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const CompoundView = memo(({ height, width, data, index }) => {
5454
const currentCompoundIds = data.compound_ids;
5555

5656
let current_style = Object.assign({}, not_selected_style);
57-
if (showedCompoundList.find(item => item === index) !== undefined) {
57+
if (showedCompoundList.find(item => item === data.smiles) !== undefined) {
5858
current_style = Object.assign(current_style, showedStyle);
5959
}
6060

js/components/preview/compounds/redux/actions.js

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ export const resetCurrentCompoundsSettings = (withCompoundClasses = false) => as
2020
}
2121
};
2222

23+
export const resetCurrentCompoundSettingsWithoutSelection = (withCompoundClasses = false) => async dispatch => {
24+
await dispatch({
25+
type: constants.RESET_CURRENT_COMPOUNDS_SETTINGS_WITHOUT_SELECTION
26+
});
27+
28+
if (withCompoundClasses === true) {
29+
dispatch(resetCompoundClasses());
30+
}
31+
}
32+
2333
export const updateCurrentCompound = ({ id, key, value }) => ({
2434
type: constants.UPDATE_COMPOUND,
2535
payload: {
@@ -92,3 +102,8 @@ export const reloadCompoundsReducer = newState => ({
92102
type: constants.RELOAD_REDUCER,
93103
payload: newState
94104
});
105+
106+
export const setSelectedCompounds = selectedCompounds => ({
107+
type: constants.SET_SELECTED_COMPOUNDS,
108+
payload: selectedCompounds
109+
});

js/components/preview/compounds/redux/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const constants = {
44
SET_CURRENT_COMPOUNDS: prefix + 'SET_CURRENT_COMPOUNDS',
55
SET_CURRENT_PAGE: prefix + 'SET_CURRENT_PAGE',
66
RESET_CURRENT_COMPOUNDS_SETTINGS: prefix + 'RESET_CURRENT_COMPOUNDS_SETTINGS',
7+
RESET_CURRENT_COMPOUNDS_SETTINGS_WITHOUT_SELECTION: prefix + 'RESET_CURRENT_COMPOUNDS_SETTINGS_WITHOUT_SELECTION',
78
UPDATE_COMPOUND: prefix + 'UPDATE_COMPOUND',
89
SET_CURRENT_COMPOUND_CLASS: prefix + 'SET_CURRENT_COMPOUND_CLASS',
910
SET_COMPOUND_CLASSES: prefix + 'SET_COMPOUND_CLASSES',
@@ -19,6 +20,8 @@ export const constants = {
1920
REMOVE_SELECTED_COMPOUND_CLASS: prefix + 'REMOVE_SELECTED_COMPOUND_CLASS',
2021
RESET_SELECTED_COMPOUND_CLASS: prefix + 'RESET_SELECTED_COMPOUND_CLASS',
2122

23+
SET_SELECTED_COMPOUNDS: prefix + 'SET_SELECTED_COMPOUNDS',
24+
2225
RELOAD_REDUCER: prefix + 'RELOAD_REDUCER'
2326
};
2427

0 commit comments

Comments
 (0)