@@ -60,6 +60,8 @@ export interface ProteinViewerRef {
6060 recordTurntable : ( duration ?: number ) => Promise < Blob > ;
6161 clearMeasurements : ( ) => void ;
6262 visualizeContact : ( chainA : string , resA : number , chainB : string , resB : number ) => void ;
63+ getMeasurements : ( ) => MeasurementData [ ] ;
64+ restoreMeasurements : ( measurements : { atom1 : any , atom2 : any } [ ] ) => void ;
6365}
6466
6567
@@ -827,6 +829,45 @@ export const ProteinViewer = forwardRef<ProteinViewerRef, ProteinViewerProps>(({
827829 }
828830 } ) ;
829831 }
832+ } ,
833+ getMeasurements : ( ) => measurementsRef . current ,
834+ restoreMeasurements : ( list : { atom1 : any , atom2 : any } [ ] ) => {
835+ if ( ! componentRef . current || ! list || list . length === 0 ) return ;
836+ // Clear existing first
837+ measurementsRef . current = [ ] ;
838+
839+ // Helper to find atom index
840+ const findAtom = ( info : any ) => {
841+ let found : any = null ;
842+ if ( ! componentRef . current ) return null ;
843+ // Try precise match first
844+ const sel = new window . NGL . Selection ( `${ info . r } :${ info . c } and .${ info . a } ` ) ;
845+ componentRef . current . structure . eachAtom ( ( atom : any ) => {
846+ found = atom ;
847+ } , sel ) ;
848+ return found ;
849+ } ;
850+
851+ list . forEach ( m => {
852+ const a1 = findAtom ( { c : m . atom1 . chain , r : m . atom1 . resNo , a : m . atom1 . atomName } ) ;
853+ const a2 = findAtom ( { c : m . atom2 . chain , r : m . atom2 . resNo , a : m . atom2 . atomName } ) ;
854+
855+ if ( a1 && a2 ) {
856+ const dx = a1 . x - a2 . x ;
857+ const dy = a1 . y - a2 . y ;
858+ const dz = a1 . z - a2 . z ;
859+ const dist = Math . sqrt ( dx * dx + dy * dy + dz * dz ) ;
860+
861+ const mData : MeasurementData = {
862+ atom1 : { chain : a1 . chainname , resNo : a1 . resno , atomName : a1 . atomname , x : a1 . x , y : a1 . y , z : a1 . z , index : a1 . index } ,
863+ atom2 : { chain : a2 . chainname , resNo : a2 . resno , atomName : a2 . atomname , x : a2 . x , y : a2 . y , z : a2 . z , index : a2 . index } ,
864+ distance : dist ,
865+ shapeId : `measure-${ Date . now ( ) } -${ Math . random ( ) } `
866+ } ;
867+ measurementsRef . current . push ( mData ) ;
868+ drawMeasurement ( mData ) ;
869+ }
870+ } ) ;
830871 }
831872 } ) ) ;
832873
0 commit comments