From 621dd5c060f6bc8db27f2812acd068e6b84516d7 Mon Sep 17 00:00:00 2001 From: "stan.donarise" Date: Wed, 10 Jul 2024 16:10:53 +0300 Subject: [PATCH 1/2] phonons for all atoms fix #30, #40 --- phonons/phonons.view.tree | 2 +- phonons/phonons.view.ts | 2 +- player/player.view.tree | 5 +++ player/player.view.web.ts | 77 +++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/phonons/phonons.view.tree b/phonons/phonons.view.tree index 03757b6..4ad01d1 100644 --- a/phonons/phonons.view.tree +++ b/phonons/phonons.view.tree @@ -4,5 +4,5 @@ $optimade_cifplayer_phonons $optimade_cifplayer_app menu_body / <= Body $mol_list sub / <= Switch $mol_switch - value? <=> phonon? \ + value? <=> phonon_str? \ options <= phonon_options * diff --git a/phonons/phonons.view.ts b/phonons/phonons.view.ts index b2069dd..f631919 100644 --- a/phonons/phonons.view.ts +++ b/phonons/phonons.view.ts @@ -9,7 +9,7 @@ namespace $.$$ { } @ $mol_mem - phonon( next?: string ): string { + phonon_str( next?: string ): string { if( next === '' ) this.unvibrate() diff --git a/player/player.view.tree b/player/player.view.tree index 3d79c3c..445a4f3 100644 --- a/player/player.view.tree +++ b/player/player.view.tree @@ -3,8 +3,11 @@ $optimade_cifplayer_player $mol_view externals? null atom_radius_scale 0.6 zoom_scale_step 0.3 + - vibrate? null unvibrate null + phonon? null + - translate_cells / <= translate_a? 1 <= translate_b? 1 @@ -23,6 +26,8 @@ $optimade_cifplayer_player $mol_view <= cell_box null <= axes_box null <= overlay_changed null + <= vibration_active? false + <= vibration_restart null atom_box* null overlay_box* null - diff --git a/player/player.view.web.ts b/player/player.view.web.ts index 6b44b1d..358e819 100644 --- a/player/player.view.web.ts +++ b/player/player.view.web.ts @@ -485,42 +485,57 @@ namespace $.$$ { } @ $mol_action - vibrate( phonon: number[][] ) { - $mol_wire_sync( this ).unvibrate() + vibration_start( phonon: number[][] ) { + this.$.$mol_wire_sync( this ).vibration_end() - const atoms = this.atom_box([0,0,0]).children const labels = this.overlay_box([0,0,0]).children - - if( phonon.length !== atoms.length) { + if( phonon.length !== labels.length) { this.$.$mol_fail( new $mol_data_error(`Phonon length does not match number of atoms`) ) } - atoms.forEach( ( atom: InstanceType< THREE["Object3D"] >, i: number ) => { - const start = atom.position.toArray() + labels.forEach( ( label: InstanceType< THREE["Object3D"] >, i: number ) => { + const start = label.position.toArray() const [ x, y, z ] = phonon[ i ].map( ( v, i ) => start[ i ] + v * phonon_amp ) - this.tweens.add( new TWEEN.Tween( atom.position ).to( { x, y, z }, 750 ) - .easing( TWEEN.Easing.Cubic.InOut ).repeat( Infinity ).yoyo( true ).start() - ) - this.tweens.add( new TWEEN.Tween( labels[ i ].position ).to( { x, y, z }, 750 ) + this.tweens.add( new TWEEN.Tween( label.position ).to( { x, y, z }, 750 ) .easing( TWEEN.Easing.Cubic.InOut ).repeat( Infinity ).yoyo( true ).start() ) } ) + + this.cell_translations().map( t => { + + const atoms = this.atom_box( t ).children + atoms.forEach( ( atom: InstanceType< THREE["Object3D"] >, i: number ) => { + const start = atom.position.toArray() + const [ x, y, z ] = phonon[ i ].map( ( v, i ) => start[ i ] + v * phonon_amp ) + + this.tweens.add( new TWEEN.Tween( atom.position ).to( { x, y, z }, 750 ) + .easing( TWEEN.Easing.Cubic.InOut ).repeat( Infinity ).yoyo( true ).start() + ) + } ) + + } ) } @ $mol_action - unvibrate() { + vibration_end() { if( this.tweens.getAll().length == 0 ) return this.tweens.removeAll() const atom_datas = this.visible_atoms() - const atoms = this.atom_box([0,0,0]).children const labels = this.overlay_box([0,0,0]).children + labels.forEach( ( label: InstanceType< THREE["Object3D"] >, i: number ) => { + this.tweens.add( new TWEEN.Tween( label.position ).to( atom_datas[ i ], 250 ).start() ) + } ) - atoms.forEach( ( atom: InstanceType< THREE["Object3D"] >, i: number ) => { - this.tweens.add( new TWEEN.Tween( atom.position ).to( atom_datas[ i ], 250 ).start() ) - this.tweens.add( new TWEEN.Tween( labels[ i ].position ).to( atom_datas[ i ], 250 ).start() ) + this.cell_translations().map( t => { + const atoms = this.atom_box( t ).children + const atom_datas = this.visible_atoms_translated( t ) + + atoms.forEach( ( atom: InstanceType< THREE["Object3D"] >, i: number ) => { + this.tweens.add( new TWEEN.Tween( atom.position ).to( atom_datas[ i ], 250 ).start() ) + } ) } ) this.$.$mol_wait_timeout( 250 ) @@ -530,6 +545,36 @@ namespace $.$$ { return } + @ $mol_mem + vibration_active( next?: boolean ) { + const phonon = this.phonon() + if( next ) { + if( phonon ) this.$.$mol_wire_sync( this ).vibration_start( phonon ) + } else { + this.$.$mol_wire_sync( this ).vibration_end() + } + return next ?? false + } + + @ $mol_action + vibrate( phonon: number[][] ) { + this.phonon( phonon ) + this.$.$mol_wire_async( this ).vibration_active( true ) + } + + @ $mol_action + unvibrate() { + this.phonon( null ) + this.$.$mol_wire_async( this ).vibration_active( false ) + } + + @ $mol_mem + vibration_restart() { + this.cell_translations() + this.$.$mol_wire_sync( this ).vibration_active( false ) + this.$.$mol_wire_sync( this ).vibration_active( true ) + } + @ $mol_mem left_panel(): readonly any[] { From d2921d9c5df6adaf26006044407c85a2f98aaf27 Mon Sep 17 00:00:00 2001 From: "stan.donarise" Date: Thu, 11 Jul 2024 19:57:03 +0300 Subject: [PATCH 2/2] remove unnecessary syncs --- player/player.view.web.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/player/player.view.web.ts b/player/player.view.web.ts index 358e819..5449a99 100644 --- a/player/player.view.web.ts +++ b/player/player.view.web.ts @@ -486,7 +486,7 @@ namespace $.$$ { @ $mol_action vibration_start( phonon: number[][] ) { - this.$.$mol_wire_sync( this ).vibration_end() + this.vibration_end() const labels = this.overlay_box([0,0,0]).children if( phonon.length !== labels.length) { @@ -549,9 +549,9 @@ namespace $.$$ { vibration_active( next?: boolean ) { const phonon = this.phonon() if( next ) { - if( phonon ) this.$.$mol_wire_sync( this ).vibration_start( phonon ) + if( phonon ) this.vibration_start( phonon ) } else { - this.$.$mol_wire_sync( this ).vibration_end() + this.vibration_end() } return next ?? false } @@ -571,8 +571,8 @@ namespace $.$$ { @ $mol_mem vibration_restart() { this.cell_translations() - this.$.$mol_wire_sync( this ).vibration_active( false ) - this.$.$mol_wire_sync( this ).vibration_active( true ) + this.vibration_active( false ) + this.vibration_active( true ) } @ $mol_mem