Skip to content

Commit

Permalink
Merge pull request #329 from m2ms/#977-ngl
Browse files Browse the repository at this point in the history
Fast switching between snapshots
  • Loading branch information
rsanchezgarc authored Nov 14, 2022
2 parents 0530324 + 7b7cbe9 commit 356e625
Show file tree
Hide file tree
Showing 29 changed files with 1,013 additions and 389 deletions.
8 changes: 4 additions & 4 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,10 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
showCrossReferenceModal
previousItemData={index > 0 && array[index - 1]}
nextItemData={index < array?.length && array[index + 1]}
L={ligandList.includes(data.id)}
P={proteinList.includes(data.id)}
C={complexList.includes(data.id)}
S={surfaceList.includes(data.id)}
L={ligandList?.includes(data.id)}
P={proteinList?.includes(data.id)}
C={complexList?.includes(data.id)}
S={surfaceList?.includes(data.id)}
V={false}
moveMolecule={moveMolecule}
isCheckedToBuy={isCheckedToBuy}
Expand Down
37 changes: 26 additions & 11 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const addDatasetHitProtein = (
datasetID,
skipTracking = false,
representations = undefined
) => dispatch => {
) => async dispatch => {
dispatch(appendProteinList(datasetID, generateMoleculeCompoundId(data), skipTracking));
return dispatch(
loadObject({
Expand Down Expand Up @@ -132,7 +132,7 @@ export const addDatasetComplex = (
datasetID,
skipTracking = false,
representations = undefined
) => dispatch => {
) => async dispatch => {
dispatch(appendComplexList(datasetID, generateMoleculeCompoundId(data), skipTracking));
return dispatch(
loadObject({
Expand Down Expand Up @@ -160,7 +160,13 @@ export const removeDatasetComplex = (stage, data, colourToggle, datasetID, skipT
dispatch(removeFromComplexList(datasetID, generateMoleculeCompoundId(data), skipTracking));
};

export const addDatasetSurface = (stage, data, colourToggle, datasetID, representations = undefined) => dispatch => {
export const addDatasetSurface = (
stage,
data,
colourToggle,
datasetID,
representations = undefined
) => async dispatch => {
dispatch(appendSurfaceList(datasetID, generateMoleculeCompoundId(data)));
return dispatch(
loadObject({
Expand Down Expand Up @@ -195,8 +201,9 @@ export const addDatasetLigand = (
datasetID,
skipTracking = false,
representations = undefined
) => dispatch => {
) => async (dispatch, getState) => {
dispatch(appendLigandList(datasetID, generateMoleculeCompoundId(data), skipTracking));
console.count(`Grabbed orientation before loading dataset ligand`);
const currentOrientation = stage.viewerControls.getOrientation();
return dispatch(
loadObject({
Expand All @@ -206,13 +213,21 @@ export const addDatasetLigand = (
markAsRightSideLigand: true
})
).finally(() => {
const ligandOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation));

dispatch(appendMoleculeOrientation(getDatasetMoleculeID(datasetID, data?.id), ligandOrientation));

// keep current orientation of NGL View
stage.viewerControls.orient(currentOrientation);
const state = getState();
const skipOrientation = state.trackingReducers.skipOrientationChange;
if (!skipOrientation) {
const ligandOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation));

dispatch(appendMoleculeOrientation(getDatasetMoleculeID(datasetID, data?.id), ligandOrientation));

// keep current orientation of NGL View
if (!skipOrientation) {
console.count(`Before applying orientation after loading dataset ligand.`);
stage.viewerControls.orient(currentOrientation);
console.count(`After applying orientation after loading dataset ligand.`);
}
}
});
};

Expand Down
16 changes: 10 additions & 6 deletions js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,11 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
allInspirations,
filteredScoreProperties,
selectedDatasetIndex,
tabValue
tabValue,
ligandLists,
proteinLists,
complexLists,
surfaceLists
} = state;

const newState = {
Expand All @@ -530,12 +534,12 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
filteredScoreProperties,
selectedDatasetIndex,
tabValue,
ligandLists: {},
proteinLists: {},
complexLists: {},
surfaceLists: {},
inspirationLists: {},
moleculeAllSelection: {}
moleculeAllSelection: {},
ligandLists,
proteinLists,
complexLists,
surfaceLists
};

Object.keys(moleculeLists).forEach(datasetID => initializeContainerLists(newState, datasetID));
Expand Down
2 changes: 1 addition & 1 deletion js/components/nglView/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const MOL_REPRESENTATION = {
};

export const COMMON_PARAMS = {
warningIcon: true
warningIcon: 'warningIcon'
};

export const MOL_REPRESENTATION_BUFFER = 'buffer';
Expand Down
35 changes: 26 additions & 9 deletions js/components/nglView/renderingHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ const drawStripyBond = (atom_a, atom_b, color_a, color_b, label, size = 0.1, sha
}
};

export function loadQualityFromFile(stage, file, quality, object_name, orientationMatrix, color, qualityType) {
export const loadQualityFromFile = async (
stage,
file,
quality,
object_name,
orientationMatrix,
color,
qualityType,
skipOrientation
) => {
console.count(`loadQualityFromFile started`);
// let goodids =
// qualityType === QUALITY_TYPES.LIGAND
// ? (quality && quality.goodids) || []
Expand All @@ -50,6 +60,7 @@ export function loadQualityFromFile(stage, file, quality, object_name, orientati
let extension = qualityType === QUALITY_TYPES.LIGAND ? 'sdf' : 'pdb';

return stage.loadFile(file, { name: object_name, ext: extension }).then(function(comp) {
console.count(`loadQualityFromFile file loaded`);
let representationStructures = [];
let rgbColor = hexToRgb(color);

Expand Down Expand Up @@ -196,19 +207,25 @@ export function loadQualityFromFile(stage, file, quality, object_name, orientati
}
}

if (orientationMatrix && orientationMatrix.elements) {
const matrix = new Matrix4();
matrix.fromArray(orientationMatrix.elements);

stage.viewerControls.orient(matrix);
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
if (!skipOrientation) {
if (orientationMatrix && orientationMatrix.elements) {
const matrix = new Matrix4();
matrix.fromArray(orientationMatrix.elements);

console.count(`Before applying quality orientation matrix.`);
stage.viewerControls.orient(matrix);
console.count(`After applying quality orientation matrix.`);
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
console.count(`Orientation matrix not found for quality, using autoView instead.`);
}
}

const reprArray = createRepresentationsArray(representationStructures);
console.count(`loadQualityFromFile finnished`);
return assignRepresentationArrayToComp(reprArray, comp);
});
}
};

export const readQualityInformation = (name, text) => (dispatch, getState) => {
const state = getState();
Expand Down
58 changes: 39 additions & 19 deletions js/components/nglView/renderingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ const showSphere = ({ stage, input_dict, object_name, representations }) => {
return Promise.resolve(assignRepresentationArrayToComp(reprArray, comp));
};

const showLigand = ({
const showLigand = async ({
stage,
input_dict,
object_name,
representations,
orientationMatrix,
markAsRightSideLigand,
loadQuality,
quality
quality,
state
}) => {
let stringBlob = new Blob([input_dict.sdf_info], { type: 'text/plain' });
console.count(`showLigand started`);
const skipOrientation = state.trackingReducers.skipOrientationChange;

if (loadQuality && quality && quality.badids?.length > 0) {
return loadQualityFromFile(
Expand All @@ -47,7 +50,8 @@ const showLigand = ({
object_name,
orientationMatrix,
input_dict.colour,
QUALITY_TYPES.LIGAND
QUALITY_TYPES.LIGAND,
skipOrientation
);
} else {
return loadLigandFromFile(
Expand All @@ -57,7 +61,8 @@ const showLigand = ({
representations,
markAsRightSideLigand,
input_dict,
orientationMatrix
orientationMatrix,
skipOrientation
);
}
};
Expand All @@ -69,9 +74,12 @@ const loadLigandFromFile = (
representations,
markAsRightSideLigand,
input_dict,
orientationMatrix
orientationMatrix,
skipOrientation
) => {
console.count(`loadLigandFromFile started`);
return stage.loadFile(stringBlob, { name: object_name, ext: 'sdf' }).then(comp => {
console.count(`loadLigandFromFile file loaded`);
const reprArray =
representations ||
createRepresentationsArray([
Expand All @@ -86,14 +94,19 @@ const loadLigandFromFile = (
)
]);

if (orientationMatrix && orientationMatrix.elements) {
const matrix = new Matrix4();
matrix.fromArray(orientationMatrix.elements);

stage.viewerControls.orient(matrix);
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
if (!skipOrientation) {
if (orientationMatrix && orientationMatrix.elements) {
const matrix = new Matrix4();
matrix.fromArray(orientationMatrix.elements);
console.count(`Before applying orientation matrix - loadLigandFromFile`);
stage.viewerControls.orient(matrix);
console.count(`After applying orientation matrix - loadLigandFromFile`);
} else if (orientationMatrix === undefined) {
comp.autoView('ligand');
console.count(`Orientation matrix not found for loadLigandFromFile, using autoView instead.`);
}
}
console.count(`loadLigandFromFile finished`);
return assignRepresentationArrayToComp(reprArray, comp);
});
};
Expand Down Expand Up @@ -204,7 +217,7 @@ const renderComplex = (ol, representations, orientationMatrix) => {
// stage.viewerControls.orient(orientationMatrix);
// } else if (orientationMatrix === undefined) {
// comp.autoView('ligand');
// //TODO setFocus should be in condition
// //TODO: setFocus should be in condition
// comp.stage.setFocus(focus_let_temp);
// }

Expand Down Expand Up @@ -360,15 +373,22 @@ const showArrow = ({ stage, input_dict, object_name, representations, orientatio
return Promise.resolve(assignRepresentationArrayToComp(reprArray, comp));
};

const showProtein = ({ stage, input_dict, object_name, representations, orientationMatrix }) =>
const showProtein = ({ stage, input_dict, object_name, representations, orientationMatrix, state }) =>
stage.loadFile(input_dict.prot_url, { name: object_name, ext: 'pdb', defaultAssembly: 'BU1' }).then(comp => {
const reprArray =
representations || createRepresentationsArray([createRepresentationStructure(input_dict.nglProtStyle, {})]);

if (orientationMatrix) {
stage.viewerControls.orient(orientationMatrix);
} else if (orientationMatrix === undefined) {
comp.autoView();
const skipOrientation = state.trackingReducers.skipOrientationChange;

if (!skipOrientation) {
if (orientationMatrix) {
console.count(`Before applying orientation matrix - showProtein`);
stage.viewerControls.orient(orientationMatrix);
console.count(`After applying orientation matrix - showProtein`);
} else if (orientationMatrix === undefined) {
comp.autoView();
console.count(`Orientation matrix not found for showProtein, using autoView instead.`);
}
}
return Promise.resolve(assignRepresentationArrayToComp(reprArray, comp));
});
Expand Down Expand Up @@ -431,7 +451,7 @@ const showHotspot = ({ stage, input_dict, object_name, representations }) => {
}
};

const showDensity = ({ stage, input_dict, object_name, representations, dispatch }) => {
const showDensity = ({ stage, input_dict, object_name, representations }) => {
let densityParams_event = {
color: input_dict.color_DENSITY,
isolevel: input_dict.isolevel_DENSITY,
Expand Down
Loading

0 comments on commit 356e625

Please sign in to comment.