From 8a6a5115bb98789bbcf2d024eeaeff85243b87d7 Mon Sep 17 00:00:00 2001 From: boriskovar-m2ms Date: Mon, 27 Jan 2025 11:55:43 +0100 Subject: [PATCH 1/3] -checkpoint --- js/components/userFeedback/browserApi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/components/userFeedback/browserApi.js b/js/components/userFeedback/browserApi.js index afa59899f..721e090f8 100644 --- a/js/components/userFeedback/browserApi.js +++ b/js/components/userFeedback/browserApi.js @@ -83,7 +83,7 @@ export const captureScreen = () => async dispatch => { }; export const captureScreenOfSnapshot = () => async dispatch => { - html2canvas(document.body).then(canvas => { - // dispatch(setTrackingImageSource(canvas.toDataURL())); - }); + // html2canvas(document.body).then(canvas => { + // // dispatch(setTrackingImageSource(canvas.toDataURL())); + // }); }; From 36a569bbba3f8a75055ae45f937ce7eff7b50f93 Mon Sep 17 00:00:00 2001 From: boriskovar-m2ms Date: Wed, 5 Feb 2025 12:42:27 +0100 Subject: [PATCH 2/3] - fixing the centering of the ligands --- js/components/nglView/renderingObjects.js | 37 +++++++++++-------- .../snapshot/redux/dispatchActions.js | 5 +++ js/reducers/ngl/dispatchActions.js | 22 ++++++----- js/reducers/ngl/useDisplayLigandLHS.js | 34 ++++++++++------- 4 files changed, 60 insertions(+), 38 deletions(-) diff --git a/js/components/nglView/renderingObjects.js b/js/components/nglView/renderingObjects.js index 179aa3a92..a4f5a6779 100644 --- a/js/components/nglView/renderingObjects.js +++ b/js/components/nglView/renderingObjects.js @@ -36,7 +36,8 @@ const showLigand = async ({ markAsRightSideLigand, loadQuality, quality, - state + state, + center }) => { let stringBlob = new Blob([input_dict.sdf_info], { type: 'text/plain' }); console.count(`showLigand started`); @@ -62,7 +63,8 @@ const showLigand = async ({ markAsRightSideLigand, input_dict, orientationMatrix, - skipOrientation + skipOrientation, + center ); } }; @@ -75,7 +77,8 @@ const loadLigandFromFile = ( markAsRightSideLigand, input_dict, orientationMatrix, - skipOrientation + skipOrientation, + center ) => { console.count(`loadLigandFromFile started`); return stage.loadFile(stringBlob, { name: object_name, ext: 'sdf' }).then(comp => { @@ -93,19 +96,23 @@ const loadLigandFromFile = ( } ) ]); - - 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.`); - } + if (center) { + comp.autoView('ligand'); + // const ligandOrientation = stage.viewerControls.getOrientation(); + // dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation)); } + // 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`); const returnVal = assignRepresentationArrayToComp(reprArray, comp); return returnVal; diff --git a/js/components/snapshot/redux/dispatchActions.js b/js/components/snapshot/redux/dispatchActions.js index b2ee8a807..5a79cf79d 100644 --- a/js/components/snapshot/redux/dispatchActions.js +++ b/js/components/snapshot/redux/dispatchActions.js @@ -623,6 +623,11 @@ export const getCleanStateForSnapshot = () => (dispatch, getState) => { snapshotData = deepMergeWithPriority({ ...snapshotData }, notToBeCopiedClone); snapshotData = deepMergeWithPriority({ ...snapshotData }, SNAPSHOT_VALUES_TO_BE_DELETED); snapshotData.nglReducers.snapshotNglOrientation = { ...snapshotData.nglReducers.nglOrientations }; + //this is because we don't want the first ligand to be centered but we always want to apply snapshot orientation + snapshotData.selectionReducers.toBeDisplayedList = snapshotData.selectionReducers.toBeDisplayedList.map(obj => ({ + ...obj, + center: false + })); return snapshotData; }; diff --git a/js/reducers/ngl/dispatchActions.js b/js/reducers/ngl/dispatchActions.js index ada75f6b4..d958c016f 100644 --- a/js/reducers/ngl/dispatchActions.js +++ b/js/reducers/ngl/dispatchActions.js @@ -23,7 +23,7 @@ import { setColorAction } from './actions'; import { isEmpty, isEqual } from 'lodash'; -import { createRepresentationsArray } from '../../components/nglView/generatingObjects'; +import { createRepresentationsArray, generateMoleculeObject } from '../../components/nglView/generatingObjects'; import { COMMON_PARAMS, DENSITY_MAPS, OBJECT_TYPE, SELECTION_TYPE } from '../../components/nglView/constants'; import { removeFromComplexList, @@ -39,6 +39,7 @@ import { nglObjectDictionary } from '../../components/nglView/renderingObjects'; import { createInitialSnapshot } from '../../components/snapshot/redux/dispatchActions'; import { VIEWS } from '../../constants/constants'; import { NGL_PARAMS } from '../../components/nglView/constants/index'; +import { getRandomColor } from '../../components/preview/molecule/utils/color'; export const loadObject = ({ target, @@ -48,7 +49,8 @@ export const loadObject = ({ markAsRightSideLigand, loadQuality, quality, - preserveColour = false + preserveColour = false, + center }) => async (dispatch, getState) => { console.log('loadObject - entry'); if (stage) { @@ -88,7 +90,8 @@ export const loadObject = ({ loadQuality, quality, dispatch, - state + state, + center }) .then(representations => { console.count(`Object loaded`); @@ -210,12 +213,13 @@ export const setOrientationByInteraction = (div_id, orientation) => (dispatch, g export const centerOnLigandByMoleculeID = (stage, moleculeID) => (dispatch, getState) => { if (moleculeID && stage) { const state = getState(); - const skipOrientation = false; //state.trackingReducers.skipOrientationChange; - if (!skipOrientation) { - const storedOrientation = state.nglReducers.moleculeOrientations[moleculeID]; - console.count(`Before applying orientation centerOnLigandByMoleculeID`); - stage.viewerControls.orient(storedOrientation); - console.count(`After applying orientation centerOnLigandByMoleculeID`); + const all_mol_lists = state.apiReducers.all_mol_lists; + const observation = all_mol_lists.find(mol => mol.id === moleculeID); + if (observation) { + const colourToggle = getRandomColor(observation); + let obsObject = generateMoleculeObject(observation, colourToggle); + const component = stage.getComponentsByName(obsObject.name).first; + component?.autoView(); } } }; diff --git a/js/reducers/ngl/useDisplayLigandLHS.js b/js/reducers/ngl/useDisplayLigandLHS.js index d9f74742b..d401525df 100644 --- a/js/reducers/ngl/useDisplayLigandLHS.js +++ b/js/reducers/ngl/useDisplayLigandLHS.js @@ -58,22 +58,28 @@ export const useDisplayLigandLHS = () => { stage, previousRepresentations: ligandData.representations, loadQuality: hasAdditionalInformation, - quality: qualityInformation + quality: qualityInformation, + center: ligandData.center }) ).then(() => { - const skipOrientation = skipOrientationChange; - if (!skipOrientation /* || isLoadingCurrentSnapshot*/) { - const ligandOrientation = stage.viewerControls.getOrientation(); - dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation)); - - dispatch(appendMoleculeOrientation(data?.id, ligandOrientation)); - if (!ligandData.center) { - // keep current orientation of NGL View - console.count(`Before applying orientation matrix after loading ligand.`); - stage.viewerControls.orient(currentOrientation); - console.count(`After applying orientation matrix after loading ligand.`); - } - } + // const ligandOrientation = stage.viewerControls.getOrientation(); + // dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation)); + // const skipOrientation = skipOrientationChange; + // if (!skipOrientation /* || isLoadingCurrentSnapshot*/) { + // const ligandOrientation = stage.viewerControls.getOrientation(); + // dispatch(setOrientation(VIEWS.MAJOR_VIEW, ligandOrientation)); + // dispatch(appendMoleculeOrientation(data?.id, ligandOrientation)); + // if (!ligandData.center) { + // // keep current orientation of NGL View + // console.count(`Before applying orientation matrix after loading ligand.`); + // stage.viewerControls.orient(currentOrientation); + // console.count(`After applying orientation matrix after loading ligand.`); + // } + // } + // if (ligandData.center) { + // const component = stage.getComponentsByName(ligandData.name).first; + // component?.autoView('ligand'); + // } // dispatch(setNglViewFromSnapshotRendered(false)); }); }, From 43960150b09deb90ba53a0423ec232c874ad59af Mon Sep 17 00:00:00 2001 From: boriskovar-m2ms Date: Wed, 5 Feb 2025 14:35:49 +0100 Subject: [PATCH 3/3] - checkpoint --- js/reducers/ngl/dispatchActions.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/js/reducers/ngl/dispatchActions.js b/js/reducers/ngl/dispatchActions.js index d958c016f..105b3e686 100644 --- a/js/reducers/ngl/dispatchActions.js +++ b/js/reducers/ngl/dispatchActions.js @@ -210,14 +210,25 @@ export const setOrientationByInteraction = (div_id, orientation) => (dispatch, g } }; -export const centerOnLigandByMoleculeID = (stage, moleculeID) => (dispatch, getState) => { +export const centerOnLigandByMoleculeID = (stage, moleculeID, datasetId = null) => (dispatch, getState) => { if (moleculeID && stage) { const state = getState(); - const all_mol_lists = state.apiReducers.all_mol_lists; - const observation = all_mol_lists.find(mol => mol.id === moleculeID); + let observation = null; + if (!datasetId) { + const all_mol_lists = state.apiReducers.all_mol_lists; + observation = all_mol_lists.find(mol => mol.id === moleculeID); + } else { + const datasetCompounds = state.datasetsReducers.moleculeLists[datasetId] || []; + observation = datasetCompounds.find(mol => mol.id === moleculeID); + } if (observation) { const colourToggle = getRandomColor(observation); - let obsObject = generateMoleculeObject(observation, colourToggle); + let obsObject = null; + if (!datasetId) { + obsObject = generateMoleculeObject(observation, colourToggle); + } else { + obsObject = generateMoleculeObject(observation, colourToggle, datasetId); + } const component = stage.getComponentsByName(obsObject.name).first; component?.autoView(); }