Skip to content

Commit

Permalink
#97 add automatic dept queuing
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 5, 2020
1 parent afc66ce commit 5f2b2fa
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
20 changes: 16 additions & 4 deletions js/components/nglView/renderingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const showComplex = (stage, input_dict, object_name, representations) => {
]).then(ol => renderComplex(ol, representations));
};

// ligand
const showEvent = (stage, input_dict, object_name, representations) =>
Promise.all(
[
Expand Down Expand Up @@ -146,7 +147,8 @@ const showEvent = (stage, input_dict, object_name, representations) =>
].then(values => [...values])
);

const showCylinder = (stage, input_dict, object_name, representations) => {
// vector
const showCylinder = (stage, input_dict, object_name, representations, orientationMatrix) => {
let colour = input_dict.colour === undefined ? [1, 0, 0] : input_dict.colour;
let radius = input_dict.radius === undefined ? 0.4 : input_dict.radius;
// Handle undefined start and finish
Expand All @@ -157,14 +159,19 @@ const showCylinder = (stage, input_dict, object_name, representations) => {
let shape = new Shape(object_name, { disableImpostor: true });
shape.addCylinder(input_dict.start, input_dict.end, colour, radius);
let comp = stage.addComponentFromObject(shape);
comp.autoView();
if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
comp.autoView();
}
const reprArray =
representations || createRepresentationsArray([createRepresentationStructure(MOL_REPRESENTATION_BUFFER, {})]);

return Promise.resolve(assignRepresentationArrayToComp(reprArray, comp));
};

const showArrow = (stage, input_dict, object_name, representations) => {
// vector
const showArrow = (stage, input_dict, object_name, representations, orientationMatrix) => {
let colour = input_dict.colour === undefined ? [1, 0, 0] : input_dict.colour;
let radius = input_dict.radius === undefined ? 0.3 : input_dict.radius;
// Handle undefined start and finish
Expand All @@ -175,7 +182,12 @@ const showArrow = (stage, input_dict, object_name, representations) => {
let shape = new Shape(object_name, { disableImpostor: true });
shape.addArrow(input_dict.start, input_dict.end, colour, radius);
let comp = stage.addComponentFromObject(shape);
comp.autoView();
if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else {
comp.autoView();
}

const reprArray =
representations || createRepresentationsArray([createRepresentationStructure(MOL_REPRESENTATION_BUFFER, {})]);

Expand Down
7 changes: 6 additions & 1 deletion js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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';

/**
* Convert the JSON into a list of arrow objects
Expand Down Expand Up @@ -76,14 +77,17 @@ 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.id];
var objList = generateObjectList(json['3d'], data);
dispatch(setVectorList(objList));
// loading vector objects
objList.map(item =>
dispatch(
loadObject(
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, getVectorWithColorByCountOfCompounds(item, to_select)),
stage
stage,
undefined,
orientationMatrix
)
)
);
Expand Down Expand Up @@ -152,6 +156,7 @@ export const addLigand = (stage, data, colourToggle) => dispatch => {
).finally(() => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
dispatch(setMoleculeOrientation(data.id, currentOrientation));
});
dispatch(appendFragmentDisplayList(generateMoleculeId(data)));
};
Expand Down
5 changes: 5 additions & 0 deletions js/reducers/ngl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ export const incrementCountOfPendingNglObjects = () => ({
export const decrementCountOfPendingNglObjects = () => ({
type: CONSTANTS.DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS
});

export const setMoleculeOrientation = (moleculeId, orientation) => ({
type: CONSTANTS.SET_MOLECULE_ORIENTATION,
payload: { moleculeId, orientation }
});
4 changes: 3 additions & 1 deletion js/reducers/ngl/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const CONSTANTS = {
SET_COUNT_OF_REMAINING_MOLECULE_GROUPS: prefix + 'SET_COUNT_OF_REMAINING_MOLECULE_GROUPS',
DECREMENT_COUNT_OF_REMAINING_MOLECULE_GROUPS: prefix + 'DECREMENT_COUNT_OF_REMAINING_MOLECULE_GROUPS',
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'
DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS: prefix + 'DECREMENT_COUNT_OF_PENDING_NGL_OBJECTS',

SET_MOLECULE_ORIENTATION: prefix + 'SET_MOLECULE_ORIENTATION'
};

export const SCENES = {
Expand Down
10 changes: 8 additions & 2 deletions js/reducers/ngl/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import { SELECTION_TYPE } from '../../components/nglView/constants';
import { removeFromComplexList, removeFromFragmentDisplayList, removeFromVectorOnList } from '../selection/actions';
import { nglObjectDictionary } from '../../components/nglView/renderingObjects';

export const loadObject = (target, stage, previousRepresentations) => dispatch => {
export const loadObject = (target, stage, previousRepresentations, orientationMatrix) => dispatch => {
if (stage) {
dispatch(incrementCountOfPendingNglObjects());
return nglObjectDictionary[target.OBJECT_TYPE](stage, target, target.name, previousRepresentations)
return nglObjectDictionary[target.OBJECT_TYPE](
stage,
target,
target.name,
previousRepresentations,
orientationMatrix
)
.then(representations => dispatch(loadNglObject(target, representations)))
.catch(error => {
console.error(error);
Expand Down
9 changes: 8 additions & 1 deletion js/reducers/ngl/nglReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const INITIAL_STATE = {
// Helper variables for marking that protein and molecule groups are successful loaded
countOfRemainingMoleculeGroups: null,
proteinsHasLoaded: null,
countOfPendingNglObjects: 0
countOfPendingNglObjects: 0,
moleculeOrientations: {}
};

export default function nglReducers(state = INITIAL_STATE, action = {}) {
Expand Down Expand Up @@ -195,6 +196,12 @@ 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:
const newMoleculeOrientations = state.moleculeOrientations;
newMoleculeOrientations[action.payload.moleculeId] = action.payload.orientation;

return Object.assign({}, state, { moleculeOrientations: newMoleculeOrientations });

default:
return state;
}
Expand Down

0 comments on commit 5f2b2fa

Please sign in to comment.