Skip to content

Commit

Permalink
Merge pull request #41 from stan-donarise/master
Browse files Browse the repository at this point in the history
phonons for all atoms
  • Loading branch information
blokhin authored Jul 11, 2024
2 parents 2f547c3 + d2921d9 commit b4c9bb2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
2 changes: 1 addition & 1 deletion phonons/phonons.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
2 changes: 1 addition & 1 deletion phonons/phonons.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace $.$$ {
}

@ $mol_mem
phonon( next?: string ): string {
phonon_str( next?: string ): string {

if( next === '' ) this.unvibrate()

Expand Down
5 changes: 5 additions & 0 deletions player/player.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
-
Expand Down
77 changes: 61 additions & 16 deletions player/player.view.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,42 +485,57 @@ namespace $.$$ {
}

@ $mol_action
vibrate( phonon: number[][] ) {
$mol_wire_sync( this ).unvibrate()
vibration_start( phonon: number[][] ) {
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 )
Expand All @@ -530,6 +545,36 @@ namespace $.$$ {
return
}

@ $mol_mem
vibration_active( next?: boolean ) {
const phonon = this.phonon()
if( next ) {
if( phonon ) this.vibration_start( phonon )
} else {
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.vibration_active( false )
this.vibration_active( true )
}

@ $mol_mem
left_panel(): readonly any[] {

Expand Down

0 comments on commit b4c9bb2

Please sign in to comment.