Skip to content

Commit

Permalink
Merge pull request #151 from m2ms/#209
Browse files Browse the repository at this point in the history
  • Loading branch information
reskyner authored Mar 30, 2020
2 parents a51314b + 03a4a58 commit fd1e600
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 25 deletions.
1 change: 1 addition & 0 deletions js/components/nglView/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const toggleMoleculeGroup = (molGroupId, summaryViewStage, majorViewStage
dispatch(
clearAfterDeselectingMoleculeGroup({
molGroupId,
currentMolGroup,
majorViewStage
})
);
Expand Down
16 changes: 8 additions & 8 deletions js/components/nglView/renderingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const showMol = (stage, input_dict, object_name, representations, orientationMat

if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
}
return assignRepresentationArrayToComp(reprArray, comp);
Expand Down Expand Up @@ -72,11 +72,11 @@ const renderComplex = (ol, representations, orientationMatrix) => {
const reprArray = representations || createRepresentationsArray([repr2, repr3]);
if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
//TODO setFocus should be in condition
comp.stage.setFocus(focus_let_temp);
}
//TODO setFocus should be in condition
comp.stage.setFocus(focus_let_temp);

return assignRepresentationArrayToComp(reprArray, comp);
};
Expand Down Expand Up @@ -124,7 +124,7 @@ const showEvent = (stage, input_dict, object_name, representations, orientationM

if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView('LIG');
}

Expand Down Expand Up @@ -173,7 +173,7 @@ const showCylinder = (stage, input_dict, object_name, representations, orientati
let comp = stage.addComponentFromObject(shape);
if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView();
}
const reprArray =
Expand All @@ -196,7 +196,7 @@ const showArrow = (stage, input_dict, object_name, representations, orientationM
let comp = stage.addComponentFromObject(shape);
if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView();
}

Expand All @@ -213,7 +213,7 @@ const showProtein = (stage, input_dict, object_name, representations, orientatio

if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
} else if (orientationMatrix === undefined) {
comp.autoView();
}
return Promise.resolve(assignRepresentationArrayToComp(reprArray, comp));
Expand Down
17 changes: 7 additions & 10 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { VIEWS } from '../../../../constants/constants';
import { api } from '../../../../utils/api';
import { selectVectorAndResetCompounds } from '../../../../reducers/selection/dispatchActions';
import { colourList } from '../moleculeView';
import { setMoleculeOrientation } from '../../../../reducers/ngl/actions';
import { appendMoleculeOrientation } from '../../../../reducers/ngl/actions';
import { setCompoundImage } from '../../summary/redux/actions';
import { noCompoundImage } from '../../summary/redux/reducer';

Expand Down Expand Up @@ -79,7 +79,6 @@ const getViewUrl = (get_view, data) => {
const handleVector = (json, stage, data) => (dispatch, getState) => {
const state = getState();
const to_select = state.selectionReducers.to_select;
const orientationMatrix = state.nglReducers.moleculeOrientations[data.site];
var objList = generateObjectList(json['3d'], data);
dispatch(setVectorList(objList));
// loading vector objects
Expand All @@ -89,7 +88,7 @@ const handleVector = (json, stage, data) => (dispatch, getState) => {
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, getVectorWithColorByCountOfCompounds(item, to_select)),
stage,
undefined,
orientationMatrix
null
)
)
);
Expand Down Expand Up @@ -129,15 +128,13 @@ export const removeVector = (stage, data) => (dispatch, getState) => {
dispatch(removeFromVectorOnList(generateMoleculeId(data)));
};

export const addComplex = (stage, data, colourToggle) => (dispatch, getState) => {
const state = getState();
const orientationMatrix = state.nglReducers.moleculeOrientations[data.site];
export const addComplex = (stage, data, colourToggle) => dispatch => {
dispatch(
loadObject(
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateComplexObject(data, colourToggle, base_url)),
stage,
undefined,
orientationMatrix
null
)
).finally(() => {
const currentOrientation = stage.viewerControls.getOrientation();
Expand All @@ -164,13 +161,13 @@ export const addLigand = (stage, data, colourToggle) => (dispatch, getState) =>
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateMoleculeObject(data, colourToggle)),
stage,
undefined,
orientationMatrix
orientationMatrix !== undefined ? null : undefined
)
).finally(() => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));

dispatch(setMoleculeOrientation(data.site, currentOrientation));
dispatch(appendMoleculeOrientation(data.site, currentOrientation));
});
dispatch(appendFragmentDisplayList(generateMoleculeId(data)));
};
Expand All @@ -180,7 +177,7 @@ export const removeLigand = (stage, data) => dispatch => {
dispatch(removeFromFragmentDisplayList(generateMoleculeId(data)));
};

export const selectFirstMolecule = (majorView, moleculeList) => (dispatch, getState) => {
export const selectFirstMolecule = (majorView, moleculeList) => dispatch => {
if (moleculeList) {
const firstMolecule = moleculeList[0];
dispatch(addLigand(majorView, firstMolecule, colourList[0]));
Expand Down
25 changes: 23 additions & 2 deletions js/components/preview/moleculeGroups/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
} from '../../../../reducers/ngl/dispatchActions';
import { getJoinedMoleculeList } from '../../molecule/redux/selectors';
import {
removeFromComplexList,
removeFromFragmentDisplayList,
removeFromVectorOnList,
resetSelectionState,
setComplexList,
setFilterSettings,
Expand All @@ -17,15 +20,18 @@ import {
setVectorList,
setVectorOnList
} from '../../../../reducers/selection/actions';
import { setCountOfRemainingMoleculeGroups } from '../../../../reducers/ngl/actions';
import { removeMoleculeOrientation, setCountOfRemainingMoleculeGroups } from '../../../../reducers/ngl/actions';
import { setMolGroupList, setMolGroupOn } from '../../../../reducers/api/actions';
import { getUrl, loadFromServer } from '../../../../utils/genericList';
import { OBJECT_TYPE } from '../../../nglView/constants';
import { SCENES } from '../../../../reducers/ngl/constants';
import { setSortDialogOpen } from '../../molecule/redux/actions';
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';

export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, majorViewStage }) => (dispatch, getState) => {
export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup, majorViewStage }) => (
dispatch,
getState
) => {
dispatch(setObjectSelection([molGroupId]));

let site;
Expand Down Expand Up @@ -63,6 +69,20 @@ export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, majorViewStage
});

dispatch(setObjectSelection(undefined));

// remove molecule orientation for given site
dispatch(removeMoleculeOrientation(site));

// remove all selected ALCV of given site
currentMolGroup.mol_id.forEach(moleculeID => {
// remove Ligand, Complex, Vectors from selection
//Ligand
dispatch(removeFromFragmentDisplayList({ id: moleculeID }));
// Complex
dispatch(removeFromComplexList({ id: moleculeID }));
// Vectors
dispatch(removeFromVectorOnList({ id: moleculeID }));
});
};

export const saveMoleculeGroupsToNglView = (molGroupList, stage) => dispatch => {
Expand Down Expand Up @@ -200,6 +220,7 @@ export const onSelectMoleculeGroup = ({ moleculeGroup, stageSummaryView, majorVi
dispatch(
clearAfterDeselectingMoleculeGroup({
molGroupId: moleculeGroup.id,
currentMolGroup,
majorViewStage
})
);
Expand Down
14 changes: 12 additions & 2 deletions js/reducers/ngl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ export const decrementCountOfPendingNglObjects = () => ({
type: CONSTANTS.DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS
});

export const setMoleculeOrientation = (moleculeGroupID, orientation) => ({
type: CONSTANTS.SET_MOLECULE_ORIENTATION,
export const appendMoleculeOrientation = (moleculeGroupID, orientation) => ({
type: CONSTANTS.APPEND_MOLECULE_ORIENTATION,
payload: { moleculeGroupID, orientation }
});

export const setMoleculeOrientations = moleculeOrientations => ({
type: CONSTANTS.SET_MOLECULE_ORIENTATIONS,
payload: moleculeOrientations
});

export const removeMoleculeOrientation = moleculeGroupID => ({
type: CONSTANTS.REMOVE_MOLECULE_ORIENTATION,
payload: moleculeGroupID
});
4 changes: 3 additions & 1 deletion js/reducers/ngl/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export const CONSTANTS = {
INCREMENT_COUNT_OF_PENDING_NGL_OBJECTS: prefix + 'INCREMENT_COUNT_OF_PENDING_NGL_OBJECTS',
DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS: prefix + 'DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS',

SET_MOLECULE_ORIENTATION: prefix + 'SET_MOLECULE_ORIENTATION'
SET_MOLECULE_ORIENTATIONS: prefix + 'SET_MOLECULE_ORIENTATIONS',
APPEND_MOLECULE_ORIENTATION: prefix + 'SET_MOLECULE_ORIENTATION',
REMOVE_MOLECULE_ORIENTATION: prefix + 'REMOVE_MOLECULE_ORIENTATION'
};

export const SCENES = {
Expand Down
6 changes: 6 additions & 0 deletions js/reducers/ngl/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
resetStateToDefaultScene,
resetStateToSessionScene,
saveCurrentStateAsDefaultScene,
setMoleculeOrientations,
setNglOrientation,
setNglViewParams,
setProteinLoadingState
Expand Down Expand Up @@ -141,5 +142,10 @@ export const reloadNglViewFromScene = (stage, display_div, scene, sessionData) =
if (newOrientation) {
stage.viewerControls.orient(newOrientation.elements);
}

// set molecule orientations
if (currentScene.moleculeOrientations) {
dispatch(setMoleculeOrientations(currentScene.moleculeOrientations));
}
});
};
12 changes: 11 additions & 1 deletion js/reducers/ngl/nglReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,24 @@ export default function nglReducers(state = INITIAL_STATE, action = {}) {
case CONSTANTS.INCREMENT_COUNT_OF_PENDING_NGL_OBJECTS:
return Object.assign({}, state, { countOfPendingNglObjects: state.countOfPendingNglObjects + 1 });

case CONSTANTS.SET_MOLECULE_ORIENTATION:
case CONSTANTS.SET_MOLECULE_ORIENTATIONS:
return Object.assign({}, state, { moleculeOrientations: action.payload });

case CONSTANTS.APPEND_MOLECULE_ORIENTATION:
const newMoleculeOrientations = state.moleculeOrientations;

if (newMoleculeOrientations[action.payload.moleculeGroupID] === undefined) {
newMoleculeOrientations[action.payload.moleculeGroupID] = action.payload.orientation;
}
return Object.assign({}, state, { moleculeOrientations: newMoleculeOrientations });

case CONSTANTS.REMOVE_MOLECULE_ORIENTATION:
const diminishedMoleculeOrientations = state.moleculeOrientations;
if (diminishedMoleculeOrientations[action.payload] !== undefined) {
delete diminishedMoleculeOrientations[action.payload];
}
return Object.assign({}, state, { moleculeOrientations: diminishedMoleculeOrientations });

default:
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragalysis-frontend",
"version": "0.4.0",
"version": "0.4.2",
"description": "Frontend for fragalysis",
"main": "webpack.config.js",
"scripts": {
Expand Down

0 comments on commit fd1e600

Please sign in to comment.