m2ms / fragalysis-frontend

The React, Redux frontend built by webpack
Other
1 stars 1 forks source link

Refactoring snapshots #1483

Open boriskovar-m2ms opened 1 month ago

boriskovar-m2ms commented 1 month ago

Based on #1419

If we want to switch current action based snapshots for state based snapshots, this is how it should work.

Saving snapshot:

  1. We create copy of the state and from the copy we remove everything that is "downloadable" i.e. poses, observations, tags and all computed datasets, job definitions
  2. We send the state json to B/E (in current implementation snapshot entity also has free form json field additional_info so theoretically we can use this one so we do not need to change B/E)

Snapshot restoration:

  1. We download the state (or extract it from additional_info from current snapshot object)
  2. Download all the stuff we stripped away from state during saving
  3. All NGL viewer stuff will be restored by multiple useEffect
  4. All more esoteric stuff like scroll to first visible compound will be also implement by useEffect idiom
  5. Incompatibilities between version will be also handled by useEffect or preprocess pipeline if necessary
  6. In project view where you can switch between snapshots it will be handled in a way that we first apply new NGL view orientation matrix and then apply new state so it will first continuously rotate and after that the changes will be applied (or other way around - don't remember what is done first. If rotation or applying the changes)

PROS:

  1. The biggest pro is that after initial implementation the snapshot saving and restoration will require no additional work (currently you need to specify for every small action: the action object, save behavior, restore behavior, redo and undo behavior). This requires that the NGL viewer will be controlled only using useEffects which will monitor changes in the state related to NGL viewer. Currently it's done imperatively after you lets say press L button we change the state and we tell NGL viewer in the same function what to render. The information about ligand is used only by the rest of the frontend. Now we will implement useEffects which will fully control NGL viewer so NGL viewer will only react to changes in global state and we will never directly control it. The only additional work will be with actions like scroll to first visible compound but historically we do not do this very often.
  2. Waaaaay less code needed therefore less code to maintain and need to understand
  3. Easier to understand code (some parts will definitely not be trivial but on aggregate it will be easier to understand)

CONS:

  1. We will most likely lose Undo/Redo functionality. There is a kind of a hope that we will be able to regain some of the ability to undo redo but it will be undo redo on very atomic/low level so no mass actions nor aggregate actions and definitely no NGL viewer only undo/redo (I don't think they fully work even now). So basically if you press button that selects 20 hits then you will need to press undo 20 times to really undo that one action (yes in this specific case it can be done by updating state in one go and not 20 times when pressing the button but in general it not might be possible - specifically when one action is updating multiple different slices of redux store).
  2. No actions timeline

Not quite sure how long it would take me to implement this but we are definitely talking about several weeks but most likely we are not talking about multiple months.

Waztom commented 1 month ago

@boriskovar-m2ms has started to review the time/steps needed for this refcatoring excercise and estimates update next Tuesday.

boriskovar-m2ms commented 1 month ago

SnapshotsRework-Estimations.xlsx My estimations of refactoring.

mwinokan commented 1 month ago

Thanks for the estimate @boriskovar-m2ms.

@Waztom and I discussed the refactor and we think you should go ahead on this.

mwinokan commented 3 weeks ago

@boriskovar-m2ms has been thinking about the approach to the state-based snapshot resolution, and will begin work imminently.

An update on the time estimate: 18 working days would resolve to 6 weeks as Boris is working 3 days per week on Fragalysis.

mwinokan commented 3 weeks ago

@boriskovar-m2ms has completed the state-based rendering of ligands, and is working ligand removal. The rest of the rendering elements are pending. This would round off the NGL changes necessary for the rest of the refactor.

mwinokan commented 2 weeks ago

@boriskovar-m2ms hit a roadblock with rendering densities, that only occurs when rendering locally, but it has been fixed. Once this is done, Boris will move on to the RHS, after which the groundwork for the snapshot refactor itself will complete.

mwinokan commented 1 week ago

Last week @boriskovar-m2ms fixed the electron density and atom quality rendering, and will work on RHS rendering ligands, complexes, surfaces and interactions.

mwinokan commented 4 days ago

@boriskovar-m2ms confirms that state based rendering is complete for the RHS. Now Boris can workshop sending state to the backend