Difference for vnd/vnd_gui.tcl from version 1.38 to 1.39

version 1.38version 1.39
Line 1
Line 1
 ## ##
 ## VND -- Visual Neuronal Dynamics graphical interface ## VND -- Visual Neuronal Dynamics graphical interface
 ## ##
 ## $Id: vnd_gui.tcl,v 1.38 2025/02/05 23:17:44 barryi Exp $ ## $Id: vnd_gui.tcl,v 1.39 2025/04/18 01:24:35 jasonks2 Exp $
 ## ##
 ## ##
 ## Home Page ## Home Page
Line 167
Line 167
  
         #variables for alignment tool         #variables for alignment tool
         variable princ_moved_mol -1         variable princ_moved_mol -1
          variable princ_moved_mol_list ""
         variable princ_moved_mol_axes -1         variable princ_moved_mol_axes -1
          variable princ_moved_mol_axes_list ""
         variable princ_axes ""          variable princ_axes "" 
         variable princ_axes_scale -1         variable princ_axes_scale -1
         variable princ_axes_com ""         variable princ_axes_com ""
Line 177
Line 179
         variable xin ""         variable xin ""
         variable yin ""         variable yin ""
         variable zin ""         variable zin ""
          #variables for rotations
         variable rot_count 0         variable rot_count 0
         variable mov_count 0         variable mov_count 0
         variable moved -1         variable moved -1
         variable rotated -1         variable rotated -1
         variable m_com_to_orig         variable m_com_to_orig
         variable m_orig_to_com         variable m_orig_to_com
  
             #alignment tool             #alignment tool
         variable aligned_on         variable aligned_on
         variable axis_on         variable axis_on
         variable tool_state         variable tool_state
         variable alignment_mol         variable alignment_mol
         variable principal_axis_mol         variable principal_axis_mol
          variable principal_axis_mol_list ""
         variable alignment_axis_mol         variable alignment_axis_mol
         variable box_mol         variable box_mol
         variable x_array         variable x_array
         variable y_array         variable y_array
         variable z_array         variable z_array
  
          variable x_array_apical
          variable y_array_apical
          variable z_array_apical
  
          variable x_array_no_axon
          variable y_array_no_axon
          variable z_array_no_axon
  
         variable size_array         variable size_array
         variable unaligned_old         variable unaligned_old
         variable aligned_new         variable aligned_new
Line 211
Line 222
         #----         #----
         variable alignment_population         variable alignment_population
         variable alignment_populationID         variable alignment_populationID
          variable alignment_population_list
         #--- gui         #--- gui
         variable w         variable w
         #--- for new query         #--- for new query
Line 221
Line 233
         variable globalNodeID         variable globalNodeID
         variable nsize           variable nsize  
  
          #newest version of alignment
          variable com_list ""
          variable size_list ""
          variable paxis_list ""
          variable spherelist_list ""
          variable nodes ""
          variable main_pa_list ""
          variable exclude_axons 1
          variable com_list_apical
          variable flip_priority_axis 0
          variable vcom_to_pa 
          variable vcom_to_bio 
          variable vdot 
          variable vdot_list ""
     }     }
     initialize     initialize
 } }
Line 309
Line 334
     $w.main.def.nb add $w.main.def.nb.page2 -text "Keywords" -padding 2 -sticky news     $w.main.def.nb add $w.main.def.nb.page2 -text "Keywords" -padding 2 -sticky news
  
     grid [label $w.main.def.nb.page1.colorlbl -text "Coloring Method" -anchor c] -row 0 -column 0     grid [label $w.main.def.nb.page1.colorlbl -text "Coloring Method" -anchor c] -row 0 -column 0
  
     grid [ttk::combobox $w.main.def.nb.page1.colorcb -width 15 -values {"Type" "CompartmentType" "Color"} -textvariable ::NeuronVND::colorRep -state readonly] -row 1 -column 0     grid [ttk::combobox $w.main.def.nb.page1.colorcb -width 15 -values {"Type" "CompartmentType" "Color"} -textvariable ::NeuronVND::colorRep -state readonly] -row 1 -column 0
     # button option for color not being used     # button option for color not being used
     button $w.main.def.nb.page1.colorid -background white -width 1 -command {     button $w.main.def.nb.page1.colorid -background white -width 1 -command {
Line 1332
Line 1358
    $w.menubar.display.menu.background add radiobutton -label "Tan" -variable bgsolid -value tan -command { display backgroundgradient off; color Display Background tan}    $w.menubar.display.menu.background add radiobutton -label "Tan" -variable bgsolid -value tan -command { display backgroundgradient off; color Display Background tan}
    $w.menubar.display.menu.background add radiobutton -label "Ice Blue" -variable bgsolid -value iceblue -command { display backgroundgradient off; color Display Background iceblue}    $w.menubar.display.menu.background add radiobutton -label "Ice Blue" -variable bgsolid -value iceblue -command { display backgroundgradient off; color Display Background iceblue}
    $w.menubar.display.menu.background add radiobutton -label "Gradient" -variable bgsolid -value bggradient -command { display backgroundgradient on }    $w.menubar.display.menu.background add radiobutton -label "Gradient" -variable bgsolid -value bggradient -command { display backgroundgradient on }
  
    $w.menubar.display.menu add separator    $w.menubar.display.menu add separator
    menu $w.menubar.display.menu.rendermode -tearoff no -title "Render Mode"    menu $w.menubar.display.menu.rendermode -tearoff no -title "Render Mode"
    $w.menubar.display.menu add cascade -label "Render Mode" -menu $w.menubar.display.menu.rendermode    $w.menubar.display.menu add cascade -label "Render Mode" -menu $w.menubar.display.menu.rendermode
Line 1728
Line 1755
         set showRep true         set showRep true
         set materialRep Opaque         set materialRep Opaque
         set repselected 0         set repselected 0
         #too soon to set numberRep  
          #too soon to set number rep
         #set numberRep $listmodels(0,neurons)         #set numberRep $listmodels(0,neurons)
  
         # limit crowding in the default preview         # limit crowding in the default preview
Line 1859
Line 1887
     foreach r [.neuron.fp.systems.rep.main.table.tb get 0 end] {     foreach r [.neuron.fp.systems.rep.main.table.tb get 0 end] {
         lappend listOfRepsForConnect [lindex $r 3]         lappend listOfRepsForConnect [lindex $r 3]
     }     }
  
  
      #define new variable $listOfSelectionStrings
      foreach r [.neuron.fp.systems.rep.main.table.tb get 0 end] {
          lappend listOfSelectionStrings [lindex $r 3]
      }
  
      #foreach selection run the query, run the principal axes code2
  
     .neuron.fp.connect.main.lbl1.cb configure -values $::NeuronVND::listOfRepsForConnect     .neuron.fp.connect.main.lbl1.cb configure -values $::NeuronVND::listOfRepsForConnect
     .neuron.fp.connect.main.lbl2.cb configure -values $::NeuronVND::listOfRepsForConnect     .neuron.fp.connect.main.lbl2.cb configure -values $::NeuronVND::listOfRepsForConnect
     # same for activity     # same for activity
Line 1983
Line 2020
     ::NeuronVND::statusBarChanges ready     ::NeuronVND::statusBarChanges ready
 } }
  
 proc ::NeuronVND::movePcaGraphs {dim sign} { proc ::NeuronVND::moveGraphs {dim sign} {
   variable objList   variable objList
   variable objIndex   variable objIndex
   variable movex   variable movex
   variable movey   variable movey
   variable movez   variable movez
   variable aggoffset   variable aggoffset
   variable aggrot 
   variable princ_moved_mol 
   variable princ_moved_mol_axes 
   variable princ_axes 
   variable princ_axes_scale 
   variable princ_axes_com 
   variable princ_axes_spherelist 
   variable princ_axes_spherelist_moved 
   variable xin 
   variable yin 
   variable zin 
   variable draw_go 
   variable scale1 
   variable scale2 
   variable scale3 
   variable m_rot_around_orig 
   variable m_com_to_orig 
   variable m_orig_to_com 
   variable m_rot_around_orig_then_offset 
   variable moved 
   variable rotated 
   variable rot_count 
   variable mov_count 
   variable scale1_temp 
   variable scale2_temp 
   variable scale3_temp 
  
   puts "is it rotated?? ->> $rotated" 
  
   set objid [lindex $objIndex 0]   set objid [lindex $objIndex 0]
    set aggoffset [transidentity]
   if {$objid == ""} {return}   if {$objid == ""} {return}
  
   if {$princ_moved_mol == -1} { 
     set princ_moved_mol [mol new] 
     mol rename $princ_moved_mol "Aligned neuron" 
   } 
  
   if {$princ_moved_mol_axes == -1} { 
     set princ_moved_mol_axes [mol new] 
     mol rename $princ_moved_mol "Aligned neuron axes" 
   } 
  
   set numG [llength [graphics $objid list]]   set numG [llength [graphics $objid list]]
   switch $dim {   switch $dim {
     "x" {      "x" { 
Line 2051
Line 2049
     }     }
     "default" {puts "error: dimension must be either x, y or z"}     "default" {puts "error: dimension must be either x, y or z"}
   }   }
     set a1 [lindex $princ_axes 0] 
     set a2 [lindex $princ_axes 1] 
     set a3 [lindex $princ_axes 2] 
  
     #4x4 
     set offset_matrix [transoffset $offset]  
     set aggoffset [transmult $aggoffset $offset_matrix] 
     #4x4 
     #might be backwards transmult 
  
     if {$rot_count == 0} { 
         #set m_orig_to_com [transoffset $princ_axes_com] 
         #set m_com_to_orig [transoffset [vecscale -1 $princ_axes_com]] 
         set m_rot_around_orig_then_offset $aggoffset 
     } elseif {$rot_count != 0} { 
         set m_rot_around_orig_then_offset [transmult $aggoffset $m_orig_to_com $aggrot $m_com_to_orig] 
     } elseif {$mov_count != 0} { 
         set m_rot_around_orig_then_offset $aggoffset 
     } 
     set a1_moved [coordtrans $aggoffset $a1] 
     set a2_moved [coordtrans $aggoffset $a2] 
     set a3_moved [coordtrans $aggoffset $a3] 
  
     if {$rot_count == 0} { 
         puts "int the tempscale" 
         set scale1 $scale1_temp 
         set scale2 $scale2_temp 
         set scale3 $scale3_temp 
     } else { 
         puts "now we should see this in the else statement" 
         set a1_moved [coordtrans $aggrot $a1] 
         set a2_moved [coordtrans $aggrot $a2] 
         set a3_moved [coordtrans $aggrot $a3] 
  
         set scale1 [vecscale $princ_axes_scale $a1_moved] 
         set scale2 [vecscale $princ_axes_scale $a2_moved] 
         set scale3 [vecscale $princ_axes_scale $a3_moved] 
     } 
     graphics $princ_moved_mol_axes delete all 
     graphics $princ_moved_mol_axes color 9 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale1 
     graphics $princ_moved_mol_axes color 15 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale2 
     graphics $princ_moved_mol_axes color 12 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale3 
  
     draw color 22   display update off
     puts "a1 = $a1, a2 = $a2, a3 = $a3"   for {set i 1} {$i < $numG} {incr i} {
     graphics $princ_moved_mol delete all      lassign [graphics $objid info $i] t v1 v2 v3
     foreach s $princ_axes_spherelist {     # offset v1 v2 v3
         set ts [coordtrans $m_rot_around_orig_then_offset $s]     set newv1 [vecadd $v1 $offset]
         lappend princ_axes_spherelist_moved $ts     set newv2 [vecadd $v2 $offset]
         graphics $princ_moved_mol sphere $ts radius 1     set newv3 [vecadd $v3 $offset]
      # redraw graphics i
      graphics $objid replace $i
      graphics $objid triangle $newv1 $newv2 $newv3
     }     }
  
     set princ_axes_sphere_list $princ_axes_spherelist_moved 
     set princ_axes_spherelist_moved "" 
  
     display update on     display update on
  
     if {$mov_count == 0} { 
         display resetview 
     } 
  
    # for {set i 1} {$i < [llength $princ_axes_spherelist]} {incr i} { 
       #  lassign [graphics $princ_moved_mol info $i] t v1 radius r resolution res 
      #   lappend princ_axes_spherelist_moved [list $v1] 
         #graphics $objid replace $i 
         #graphics $objid $t [list $newv1 $newv2] radii [list [lindex $r 0] [lindex $r 1]] drawtubes $on 
     #} 
     set moved 1 
     incr mov_count 
     puts "moved this many times $mov_count" 
 } 
  
 proc ::NeuronVND::redraw_align {} { 
   #call redraw in button 
   variable aggoffset 
   variable aggrot 
   variable princ_moved_mol 
   variable princ_moved_mol_axes 
   variable princ_axes 
   variable princ_axes_scale 
   variable princ_axes_com 
   variable princ_axes_spherelist 
   variable princ_axes_spherelist_moved 
    
  
   variable scale1 
   variable scale2 
   variable scale3 
   variable m_rot_around_orig 
   variable m_rot_around_orig_then_offset 
  
   variable rot_count 
   variable mov_count 
  
   set a1_moved [coordtrans $aggoffset $a1] 
   set a2_moved [coordtrans $aggoffset $a2] 
   set a3_moved [coordtrans $aggoffset $a3] 
  
     graphics $princ_moved_mol_axes delete all 
     graphics $princ_moved_mol_axes color 9 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale1 
     graphics $princ_moved_mol_axes color 15 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale2 
     graphics $princ_moved_mol_axes color 12 
     vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale3 
  
     draw color 22 
     puts "a1 = $a1, a2 = $a2, a3 = $a3" 
     graphics $princ_moved_mol delete all 
      
     foreach s $princ_axes_spherelist { 
         set ts [coordtrans $aggoffset $s] 
         lappend princ_axes_spherelist_moved $ts 
         graphics $princ_moved_mol sphere $ts radius 1 
 } 
 } }
  
 proc ::NeuronVND::rotPcaGraphs {axis sign} { proc ::NeuronVND::rotGraphs {axis sign} {
   variable objList   variable objList
   variable objIndex   variable objIndex
   variable rotarx   variable rotarx
   variable rotary   variable rotary
   variable rotarz   variable rotarz
   variable aggrot   variable aggrot
   variable aggoffset 
   variable princ_moved_mol 
   variable princ_moved_mol_axes 
   variable princ_axes 
   variable princ_axes_scale 
   variable princ_axes_com 
   variable princ_axes_spherelist 
   variable princ_axes_spherelist_moved 
   variable m_rot_around_orig 
   variable m_rot_around_orig_then_offset  
   variable xin 
   variable yin 
   variable zin 
   variable draw_go 
   variable initial_state 
   variable scale1 
   variable scale2 
   variable scale3 
   variable m_com_to_orig 
   variable m_orig_to_com 
  
   variable moved 
   variable rotated 
  
   variable rot_count 
   variable mov_count 
  
   set objid [lindex $objIndex 0]   set objid [lindex $objIndex 0]
   if {$objid == ""} {return}   if {$objid == ""} {return}
  
   if {$princ_moved_mol == -1} { 
     set princ_moved_mol [mol new] 
     mol rename $princ_moved_mol "Aligned neuron" 
   } 
  
   if {$princ_moved_mol_axes == -1} { 
     set princ_moved_mol_axes [mol new] 
     mol rename $princ_moved_mol "Aligned neuron axes" 
   } 
   set numG [llength [graphics $objid list]]   set numG [llength [graphics $objid list]]
   if {$axis != "x" && $axis != "y" && $axis != "z"} {   if {$axis != "x" && $axis != "y" && $axis != "z"} {
     puts "error: axis must be either x, y or z"     puts "error: axis must be either x, y or z"
Line 2229
Line 2085
   }   }
   if {$sign == "neg"} {set val [expr -1*$val]}   if {$sign == "neg"} {set val [expr -1*$val]}
  
   #retrieves vectors of principal axes   # update aggrot 
   set a1 [lindex $princ_axes 0]   set aggrot [transmult $aggrot [transaxis $axis $val]]
   set a2 [lindex $princ_axes 1] 
   set a3 [lindex $princ_axes 2] 
   puts "a1 = $a1, a2 = $a2, a3 = $a3" 
  
    display update off
    for {set i 1} {$i < $numG} {incr i} {
      lassign [graphics $objid info $i] t v1 v2 v3
      # offset v1 v2 v3
      set newv1 [vectrans [transaxis $axis $val] $v1]
      set newv2 [vectrans [transaxis $axis $val] $v2]
      set newv3 [vectrans [transaxis $axis $val] $v3]
      # redraw graphics i
      graphics $objid replace $i
      graphics $objid triangle $newv1 $newv2 $newv3
    }
    display update on
  }
  
   set princ_axes_com_offset [coordtrans $aggoffset $princ_axes_com] 
  
   #For rotations, move the entire center of mass to the origin and then apply the rotations proc ::NeuronVND::revealVars {repdetails} {
   set m_orig_to_com_offset [transoffset $princ_axes_com_offset] 
   set m_com_to_orig_offset [transoffset [vecscale -1 $princ_axes_com_offset]] 
  
   set m_orig_to_com [transoffset $princ_axes_com]     set show [lindex $repdetails 1] 
   set m_com_to_orig [transoffset [vecscale -1 $princ_axes_com]]     set style [lindex $repdetails 3]
      set color [lindex $repdetails 4]
      set material [lindex $repdetails 5]
      set selection [lindex $repdetails 6]
      set num_neurons [lindex $repdetails 8]
      set scale [lindex $repdetails 10] 
      set resolution [lindex $repdetails 11]
  
   #apply the axis rotation incrementally and then apply it to the aggregate rotation matrix     set result "show $show style $style color $color material $material neurons $num_neurons selection {$selection}";#scale $scale resolution $resolution"
   set init_state $aggrot 
   set aggrot [transmult $aggrot [transaxis $axis $val]] 
   puts "aggrot = $aggrot" 
   #m_to_user is specifically for the morphology included with translations to origin and back to COM 
   set m_rot_around_orig_then_offset [transmult $aggoffset $m_orig_to_com $aggrot $m_com_to_orig] 
  
   # update aggrot  
   set a1_moved [coordtrans $aggrot $a1] 
   set a2_moved [coordtrans $aggrot $a2] 
   set a3_moved [coordtrans $aggrot $a3] 
  
   set scale1 [vecscale $princ_axes_scale $a1_moved] 
   set scale2 [vecscale $princ_axes_scale $a2_moved] 
   set scale3 [vecscale $princ_axes_scale $a3_moved] 
  
   puts "yeeeeeee -> $scale1 , $scale2. $scale3" 
  
   graphics $princ_moved_mol_axes delete all 
  
   graphics $princ_moved_mol_axes color 9 
   vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale1 
  
   graphics $princ_moved_mol_axes color 15 
   vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale2 
  
   graphics $princ_moved_mol_axes color 12 
   vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale3 
   draw color 22 
  
   #SPHERE TUBES ARE BROKEN! 
   #graphics $princ_moved_mol spheretube "$princ_axes_spherelist" radii 1 drawtubes 0 
    
   #coordstrans takes a 4x4 and applies a transformation to each point in the entire sphere_list   
  
   graphics $princ_moved_mol delete all 
  
   foreach s $princ_axes_spherelist { 
         set ts [coordtrans $m_rot_around_orig_then_offset $s] 
         lappend princ_axes_spherelist_moved $ts 
         graphics $princ_moved_mol sphere $ts radius 1 
     } 
  
  
     display update on 
  
   if {$rot_count == 0} { 
     display resetview 
   } 
     #set princ_axes_spherelist_moved "" 
     #for {set i 1} {$i < [llength $princ_axes_spherelist]} {incr i} { 
      #   lassign [graphics $princ_moved_mol info $i] t v1 radius r resolution res 
     #    lappend princ_axes_spherelist_moved [list $v1] 
         #graphics $objid replace $i 
         #graphics $objid $t [list $newv1 $newv2] radii [list [lindex $r 0] [lindex $r 1]] drawtubes $on 
    # } 
     set rotated 1 
     incr rot_count 
     puts "rotated this many times --> $rot_count" 
     } 
 proc ::NeuronVND::moveGraphs {dim sign} { 
   variable objList 
   variable objIndex 
   variable movex 
   variable movey 
   variable movez 
   variable aggoffset 
   set objid [lindex $objIndex 0] 
   set aggoffset [transidentity] 
   if {$objid == ""} {return} 
   set numG [llength [graphics $objid list]] 
   switch $dim { 
     "x" {  
         set val $movex 
         if {$sign == "neg"} {set val [expr -1*$val]} 
         set offset [list $val 0.0 0.0]  
     } 
     "y" {  
         set val $movey 
         if {$sign == "neg"} {set val [expr -1*$val]} 
         set offset [list 0.0 $val 0.0]  
     } 
     "z" {  
         set val $movez 
         if {$sign == "neg"} {set val [expr -1*$val]} 
         set offset [list 0.0 0.0 $val]  
     } 
     "default" {puts "error: dimension must be either x, y or z"} 
   } 
  
   display update off 
   for {set i 1} {$i < $numG} {incr i} { 
     lassign [graphics $objid info $i] t v1 v2 v3 
     # offset v1 v2 v3 
     set newv1 [vecadd $v1 $offset] 
     set newv2 [vecadd $v2 $offset] 
     set newv3 [vecadd $v3 $offset] 
     # redraw graphics i 
     graphics $objid replace $i 
     graphics $objid triangle $newv1 $newv2 $newv3 
   } 
   display update on 
 } 
  
 proc ::NeuronVND::rotGraphs {axis sign} { 
   variable objList 
   variable objIndex 
   variable rotarx 
   variable rotary 
   variable rotarz 
   variable aggrot 
   set objid [lindex $objIndex 0] 
   if {$objid == ""} {return} 
   set numG [llength [graphics $objid list]] 
   if {$axis != "x" && $axis != "y" && $axis != "z"} { 
     puts "error: axis must be either x, y or z" 
     return 
   } 
   switch $axis { 
     "x" { set val $rotarx } 
     "y" { set val $rotary } 
     "z" { set val $rotarz } 
   } 
   if {$sign == "neg"} {set val [expr -1*$val]} 
  
   # update aggrot  
   set aggrot [transmult $aggrot [transaxis $axis $val]] 
  
   display update off 
   for {set i 1} {$i < $numG} {incr i} { 
     lassign [graphics $objid info $i] t v1 v2 v3 
     # offset v1 v2 v3 
     set newv1 [vectrans [transaxis $axis $val] $v1] 
     set newv2 [vectrans [transaxis $axis $val] $v2] 
     set newv3 [vectrans [transaxis $axis $val] $v3] 
     # redraw graphics i 
     graphics $objid replace $i 
     graphics $objid triangle $newv1 $newv2 $newv3 
   } 
   display update on 
 } 
  
  
 proc ::NeuronVND::revealVars {repdetails} { 
  
     set show [lindex $repdetails 1]  
     set style [lindex $repdetails 3] 
     set color [lindex $repdetails 4] 
     set material [lindex $repdetails 5] 
     set selection [lindex $repdetails 6] 
     set num_neurons [lindex $repdetails 8] 
     set scale [lindex $repdetails 10]  
     set resolution [lindex $repdetails 11] 
  
     set result "show $show style $style color $color material $material neurons $num_neurons selection {$selection}";#scale $scale resolution $resolution" 
  
     return $result     return $result
 } }
Line 2563
Line 2278
 } }
  
 proc ::NeuronVND::makeMovie { type } { proc ::NeuronVND::makeMovie { type } {
  
     cd $::NeuronVND::renderWorkDir     cd $::NeuronVND::renderWorkDir
     # render all frames     # render all frames
     #::neuro::compart_animate_selection_render_ranged $::NeuronVND::compartSel $::NeuronVND::renderMovTimeFrom $::NeuronVND::renderMovTimeTo  \     #::neuro::compart_animate_selection_render_ranged $::NeuronVND::compartSel $::NeuronVND::renderMovTimeFrom $::NeuronVND::renderMovTimeTo  \
Line 2820
Line 2534
     grid [ttk::combobox $w.main.label1.dropdown -width 50 -values $::NeuronVND::listOfRepsForConnect -state readonly -textvariable ::NeuronVND::alignment_population] -row 0 -column 1 -columnspan 2 -padx 2 -pady 1     grid [ttk::combobox $w.main.label1.dropdown -width 50 -values $::NeuronVND::listOfRepsForConnect -state readonly -textvariable ::NeuronVND::alignment_population] -row 0 -column 1 -columnspan 2 -padx 2 -pady 1
     bind $w.main.label1.dropdown <<ComboboxSelected>> {     bind $w.main.label1.dropdown <<ComboboxSelected>> {
         set text [%W get]         set text [%W get]
         get_population_ID $text         ::NeuronVND::get_population_ID $text
         #::NeuronVND::draw_box         #::NeuronVND::draw_box
         %W selection clear         %W selection clear
     }         }    
Line 2830
Line 2544
     #grid [entry $w.main.label1.textentry -textvariable ::Alignment::alignment_populationID] -row 1 -column 1 -sticky news -padx 2 -pady 1     #grid [entry $w.main.label1.textentry -textvariable ::Alignment::alignment_populationID] -row 1 -column 1 -sticky news -padx 2 -pady 1
     grid [labelframe $w.main.label3 -text "Axes and Alignment Vector" -labelanchor nw ] -row $gr -column 0 -sticky news -padx 2 -pady 1         grid [labelframe $w.main.label3 -text "Axes and Alignment Vector" -labelanchor nw ] -row $gr -column 0 -sticky news -padx 2 -pady 1    
     incr gr     incr gr
     grid [button $w.main.label3.but1 -text "Calculate & Draw Axes" -command {::NeuronVND::draw_axis}] -row $gr -column 0 -sticky news -padx 4 -pady 1     grid [button $w.main.label3.but1 -text "Calculate & Draw Axes" -command {::NeuronVND::draw_axis $::NeuronVND::alignment_population}] -row $gr -column 0 -sticky news -padx 4 -pady 1
     grid [button $w.main.label3.but2 -text "Delete All" -command {::NeuronVND::delete_axes}] -row $gr -column 1 -sticky news -padx 4 -pady 1     grid [button $w.main.label3.but2 -text "Delete All" -command {::NeuronVND::delete_axes}] -row $gr -column 1 -sticky news -padx 4 -pady 1
      grid [radiobutton $w.main.label3.but8 -text "Include Axons" -variable ::NeuronVND::exclude_axons -value 0 -command {puts "including the axons"}] -row $gr -column 2
  
     incr gr     incr gr
      grid [radiobutton $w.main.label3.but9 -text "Exclude Axons" -variable ::NeuronVND::exclude_axons -value 1 -command {puts "exlcuding the axons now"}] -row $gr -column 2
  
     grid [label $w.main.label3.textlabel2 -text "input x"] -row $gr -column 0 -padx 1 -pady 1     grid [label $w.main.label3.textlabel2 -text "input x"] -row $gr -column 0 -padx 1 -pady 1
     grid [entry $w.main.label3.textentry2 -textvariable ::NeuronVND::xin] -row $gr -column 1 -padx 1 -pady 1     grid [entry $w.main.label3.textentry2 -textvariable ::NeuronVND::xin] -row $gr -column 1 -padx 1 -pady 1
     incr gr     incr gr
Line 2843
Line 2561
     grid [entry $w.main.label3.textentry4 -textvariable ::NeuronVND::zin] -row $gr -column 1 -padx 1 -pady 1     grid [entry $w.main.label3.textentry4 -textvariable ::NeuronVND::zin] -row $gr -column 1 -padx 1 -pady 1
     #grid [button $w.main.but2 -text "Remove Axes" -command {::NeuronVND::hide_axis}] -row $gr -column 0 -sticky news -padx 2 -pady 1     #grid [button $w.main.but2 -text "Remove Axes" -command {::NeuronVND::hide_axis}] -row $gr -column 0 -sticky news -padx 2 -pady 1
     incr gr      incr gr 
     grid [button $w.main.label3.but3 -text "Align to x, y, z" -command {::NeuronVND::jump}] -row $gr -column 0 -sticky news -padx 4 -pady 1     grid [button $w.main.label3.but4 -text "Align to x, y, z" -command {::NeuronVND::jump_mult_node}] -row $gr -column 0 -sticky news -padx 4 -pady 1
     grid [button $w.main.label3.but4 -text "Reset position" -command {::NeuronVND::resetpos}] -row $gr -column 1 -sticky news -padx 4 -pady 1     grid [button $w.main.label3.but5 -text "Reset position" -command {::NeuronVND::resetpos}] -row $gr -column 1 -sticky news -padx 4 -pady 1
     incr gr     incr gr
     grid [labelframe $w.main.label2 -text "Navigation Controls" -labelanchor nw ] -row $gr -column 0 -sticky news -padx 2 -pady 1     grid [labelframe $w.main.label2 -text "Navigation Controls" -labelanchor nw ] -row $gr -column 0 -sticky news -padx 2 -pady 1
     incr gr     incr gr
     grid [label $w.main.label2.sel -text "Select:"] -row $gr -column 0 -sticky news     grid [label $w.main.label2.sel -text "Select Object:"] -row $gr -column 0 -sticky news
     grid [ttk::combobox $w.main.label2.cb -width 30 -values "" -textvariable ::NeuronVND::objIndex -state readonly] -row $gr -column 1 -columnspan 4     grid [ttk::combobox $w.main.label2.cb -width 30 -values "" -textvariable ::NeuronVND::objIndex -state readonly] -row $gr -column 1 -columnspan 4
     bind $w.main.label2.cb <<ComboboxSelected>> {     bind $w.main.label2.cb <<ComboboxSelected>> {
         set ::NeuronVND::objIndex [%W get]         set ::NeuronVND::objIndex [%W get]
Line 2905
Line 2623
         ::NeuronVND::delete_all         ::NeuronVND::delete_all
     }     }
  
 #this draws the principal axis (3 in total) 
     proc ::NeuronVND::draw_axis {} { 
  
  #this draws the principal axis (3 in total)
  proc ::NeuronVND::draw_axis {selection_string} {
     variable sel_string     variable sel_string
     variable x_array     variable x_array
     variable y_array     variable y_array
Line 2915
Line 2633
     variable size_array     variable size_array
     variable state     variable state
     variable rot_count     variable rot_count
      variable flip
      set flip 0
      #find out how many neurons are in selection
      set header [::neuro::cmd_query morpho_details -no_coords "$selection_string && has_morpho = True"]
      set size [llength $header]
      ::NeuronVND::statusBarChanges loading
      ::NeuronVND::draw_mult_axes $selection_string
      ::NeuronVND::statusBarChanges ready
  
  }
          
  
  
  #function for multiple nodes in 1 selection -> see draw_axis
  proc ::NeuronVND::draw_mult_axes {selection_string} {
      variable sel_string
      variable x_array
      variable y_array
      variable z_array
      variable x_array_apical ""
      variable y_array_apical ""
      variable z_array_apical ""
      variable x_array_no_axon
      variable y_array_no_axon
      variable z_array_no_axon
      variable size_array
      variable state
      variable rot_count
      variable principal_axis_mol_list
      variable com_list
      variable size_list
      variable paxis_list
      variable spherelist_list
      variable nodes
      variable main_pa_list
      variable morph_spherelist_combo_axon_exlusion
      variable morph_spherelist_combo_apical
      variable com_list_apical
     set ::NeuronVND::objList ""     set ::NeuronVND::objList ""
     set ::NeuronVND::objIndex ""     set ::NeuronVND::objIndex ""
      set spherelist_list ""
      set com_list ""
      set paxis_list ""
      set size_list ""
      variable priority_axis
      variable vdot
      variable vcom_to_pa
      variable vcom_to_bio
      variable vdot_list
      variable flip_priority_axis 0
     variable principal_axis_mol     variable principal_axis_mol
      set counter 0
      set flipped_list ""
      set sel_string $selection_string
  
      #perform for all reps
     if ![catch {molinfo $principal_axis_mol get name}] {return} 
     set principal_axis_mol [mol new]     set principal_axis_mol [mol new]
      lappend principal_axis_mol_list $principal_axis_mol
     set name [mol rename $principal_axis_mol "Principal Axes"]     set name [mol rename $principal_axis_mol "Principal Axes Number: $sel_string"]
     set name2 [molinfo $principal_axis_mol get name]     set name2 [molinfo $principal_axis_mol get name]
      set ID [::NeuronVND::get_population_ID $sel_string]
     set sel_string $::NeuronVND::alignment_population 
  
     set ID $::NeuronVND::alignment_populationID 
  
     #if soma is drawn use standard node_list_attrib_query, else use the morpho_details query since a morphology is drawn     #if soma is drawn use standard node_list_attrib_query, else use the morpho_details query since a morphology is drawn
     if {[lindex [lindex ::neuro::nrepList $ID] 3] == "soma"} {     if {[lindex [lindex ::neuro::nrepList $ID] 3] == "soma"} {
         set x_array [::neuro::cmd_query node_list_attrib_values x [::neuro::parse_full_selection_string $sel_string node]]         set x_array [::neuro::cmd_query node_list_attrib_values x [::neuro::parse_full_selection_string $sel_string node]]
         set y_array [::neuro::cmd_query node_list_attrib_values y [::neuro::parse_full_selection_string $sel_string node]]         set y_array [::neuro::cmd_query node_list_attrib_values y [::neuro::parse_full_selection_string $sel_string node]]
         set z_array [::neuro::cmd_query node_list_attrib_values z [::neuro::parse_full_selection_string $sel_string node]]         set z_array [::neuro::cmd_query node_list_attrib_values z [::neuro::parse_full_selection_string $sel_string node]]
  
         set size_array [llength $x_array]         set size_array [llength $x_array]
  
         #calculate mass. Initiliaze mass array of each neuron.         #calculate mass. Initiliaze mass array of each neuron.
         ::Orient::sel_mass $size_array         ::Orient::sel_mass $size_array
  
         #actually draw the principal access          #actually draw the principal access 
         vmd_draw_principalaxes $x_array $y_array $z_array $principal_axis_mol         vmd_draw_principalaxes $x_array $y_array $z_array $principal_axis_mol
     } else {     } else {
         set output_header [::neuro::cmd_query morpho_details -no_coords "$sel_string && has_morpho == True"]         set nodes [::neuro::parse_full_selection_string "$sel_string && (has_morpho == True)"]
          set output_header [::neuro::cmd_query morpho_details -no_coords "$sel_string && (has_morpho == True)"]
          #number of neurons in selection
         set nsize [llength $output_header]         set nsize [llength $output_header]
         set output [::neuro::cmd_query morpho_details -moved_coords "$sel_string && has_morpho == True"] 
         puts "nsize is $nsize" 
          
  
         set globalNodeID [lindex [lindex $output 0] 0] 
  
         set x_array "" 
         set y_array "" 
         set z_array "" 
  
         #copying the data from ::neuro:: to ::Orient:: vars 
         set morph_spherelist_combo ""         set morph_spherelist_combo ""
  
         for {set i 0} {$i < $nsize} {incr i} {         for {set i 0} {$i < $nsize} {incr i} {
             foreach coord [lindex [lindex $output $i] 3] {             set morph_spherelist_combo ""
                 lappend morph_spherelist_combo $coord             set morph_spherelist_combo_apical ""
                 foreach {x y z} $coord {             set morph_spherelist_combo_axon_exlusion ""
              set morpho_details_of_one_node [::neuro::cmd_query morpho_details -moved_coords_compart_types "global_node_id == [lindex $nodes $i]"]
                      
              set principal_axis_mol [mol new]
              lappend principal_axis_mol_list $principal_axis_mol
              set name [mol rename $principal_axis_mol "Principal Axes Number: $sel_string"]
              set name2 [molinfo $principal_axis_mol get name] 
              foreach coord [lindex [lindex $morpho_details_of_one_node 0] 3] {                                            
                  lappend morph_spherelist_combo [lindex $coord 1]
                  foreach {x y z} [lindex $coord 1] {
                     lappend x_array $x                     lappend x_array $x
                     lappend y_array $y                     lappend y_array $y
                     lappend z_array $z                     lappend z_array $z
                     }                     }
             }              } 
              foreach coord [lindex [lindex $morpho_details_of_one_node 0] 3] {
                  if {[lindex $coord 0] != 2} {
                      lappend morph_spherelist_combo_axon_exlusion [lindex $coord 1]
                      foreach {x y z} [lindex $coord 1] {
                          lappend x_array_no_axon $x
                          lappend y_array_no_axon $y
                          lappend z_array_no_axon $z
                      }
         }         }
                 #share spheres for rotGraphs preview             }
              #copy the apical nodes for calculations
              foreach coord [lindex [lindex $morpho_details_of_one_node 0] 3] {  
                  if {[lindex $coord 0] == 4} {                                         
                      lappend morph_spherelist_combo_apical [lindex $coord 1]
                      foreach {x y z} [lindex $coord 1] {
                          lappend x_array_apical $x
                          lappend y_array_apical $y
                          lappend z_array_apical $z
                      }
                  }
              }
              if {$::NeuronVND::exclude_axons == 1} {
                  set ::NeuronVND::princ_axes_spherelist $morph_spherelist_combo_axon_exlusion
                  lappend spherelist_list $::NeuronVND::princ_axes_spherelist
                  set size_array [llength $x_array_no_axon]
                  ::Orient::sel_mass $size_array
                  ::Orient::sel_com $x_array_no_axon $y_array_no_axon $z_array_no_axon
                  #after running sel_mass/sel_com. Some data has been generated, let's copy the variables to our large list
                  set paxis [vmd_draw_principalaxes $x_array_no_axon $y_array_no_axon $z_array_no_axon [lindex $principal_axis_mol_list $i] $flip_priority_axis]
                  lappend paxis_list $paxis
  
                  lappend com_list $::Orient::center_of_mass
                  lappend size_list $::Orient::assigned_weights
                  lappend main_pa_list $priority_axis
                  #vecsub of the priority axis (using type 1,4,3) from COM to get a vector
                  set vcom_to_pa [vecsub [lindex $main_pa_list $i] [lindex $com_list $i]]
  
                  if {[llength $x_array_apical]} {
                      set size_array [llength $x_array_apical]
                      ::Orient::sel_mass $size_array
                      ::Orient::sel_com $x_array_apical $y_array_apical $z_array_apical
                      lappend com_list_apical $::Orient::center_of_mass
                      #vector of the soma com to bio_com (apical region)
                      set vcom_to_bio [vecsub [lindex $com_list_apical $i] [lindex $com_list $i]]
                      #dot product between initial vector and bio vector (apical)
                      set vdot [vecdot $vcom_to_pa $vcom_to_bio]
                      lappend vdot_list $vdot
                      if {$vdot < 0} {
                          graphics [lindex $principal_axis_mol_list $i] delete all
                          set flip_priority_axis 1
                          set size_array_2 [llength $x_array_no_axon]
                          ::Orient::sel_mass $size_array_2
                          ::Orient::sel_com $x_array_no_axon $y_array_no_axon $z_array_no_axon
                          set paxis [vmd_draw_principalaxes $x_array_no_axon $y_array_no_axon $z_array_no_axon [lindex $principal_axis_mol_list $i] $flip_priority_axis]
                          #lappend paxis_list $paxis
                          incr counter
                          lappend flipped_list [lindex $nodes $i]
                      }
                  }
                  puts "now excluding"
              } elseif {$::NeuronVND::exclude_axons == 0} {
                  graphics [lindex $principal_axis_mol_list $i] delete all
  
                 set ::NeuronVND::princ_axes_spherelist $morph_spherelist_combo                 set ::NeuronVND::princ_axes_spherelist $morph_spherelist_combo
                  lappend spherelist_list $::NeuronVND::princ_axes_spherelist
                 set size_array [llength $x_array]                 set size_array [llength $x_array]
  
                 puts "length of x_array [llength $x_array]" 
                 puts "length of size_array [llength $size_array]" 
                 ::Orient::sel_mass $size_array                 ::Orient::sel_mass $size_array
                 vmd_draw_principalaxes $x_array $y_array $z_array $principal_axis_mol                 ::Orient::sel_com $x_array $y_array $z_array
                  #after running sel_mass/sel_com. Some data has been generated, let's copy the variables to our large list
                  
                  #see here we use a different list x_array (this list contains mutually exhaustive structural points)
                  #set paxis [vmd_draw_principalaxes $x_array_no_axon $y_array_no_axon $z_array_no_axon [lindex $principal_axis_mol_list $i] $flip_priority_axis]
                  set paxis [vmd_draw_principalaxes $x_array $y_array $z_array [lindex $principal_axis_mol_list $i] $flip_priority_axis]
                  lappend paxis_list $paxis
                  lappend com_list $::Orient::center_of_mass
                  lappend size_list $::Orient::assigned_weights
                  lappend main_pa_list $priority_axis
                  #vecsub of the priority axis (using type 1,4,3) from COM to get a vector
                  set vcom_to_pa [vecsub [lindex $main_pa_list $i] [lindex $com_list $i]]
                 display resetview                 display resetview
                  puts "now including"
              }
              set x_array_apical ""
              set y_array_apical ""
              set z_array_apical ""
              set x_array_no_axon ""                
              set y_array_no_axon ""
              set z_array_no_axon ""
              set x_array ""
              set y_array ""
              set z_array "" 
     }     }
          puts "list -> $vdot_list"
          puts "-------------THERE HAS BEEN $counter AXIS FLIPPED-------------"
          puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
          puts "Flipped Nodes: $flipped_list\n"
          set total [llength $nodes]
  
          if {$counter == 0} {
              set percent 0
          } else {
              set percent [expr [expr double($counter)/$total] * 100]
          }
          puts "The percent flipped = $percent%"
          
      }
  
     #fill Mariano's objlist #haky way     #fill Mariano's objlist #haky way
     lappend ::NeuronVND::objList [list $principal_axis_mol $name2]     lappend ::NeuronVND::objList [list $principal_axis_mol $name2]
     set ::NeuronVND::objIndex [lindex $::NeuronVND::objList 0]     set ::NeuronVND::objIndex [lindex $::NeuronVND::objList 0]
     set_scale     set_scale
     set rot_count 0     set rot_count 0
     }     }
     #helper utility function 
  #function used for aligning to input vector
  proc ::NeuronVND::jump_mult_node {} {
      variable objList
      variable objIndex
      variable rotarx
      variable rotary
      variable rotarz
      variable aggrot
      variable aggoffset
      variable princ_moved_mol
      variable princ_moved_mol_axes
      variable princ_axes
      variable princ_axes_scale
      variable princ_axes_com
      variable princ_axes_spherelist
      variable xin
      variable yin
      variable zin
      variable draw_go
      variable priority
      variable priority_axis
      variable m_com_to_orig
      variable m_orig_to_com
      variable m_rot_around_orig_then_offset
      variable com_list
      variable size_list
      variable paxis_list
      variable princ_moved_mol_axes_list
      variable princ_moved_mol_list
      variable spherelist_list
      variable nodes 
      variable main_pa_list
      set aggoffset [transidentity]
      set aggrot [transidentity]
  
      set objid [lindex $objIndex 0]
      if {$objid == ""} {return}
  
      #in Layman's terms, each neuron in the selection gets aligned to input vector
      for {set i 0} {$i < [expr [llength $nodes]]} {incr i} {
          set princ_moved_mol [mol new]
          mol rename $princ_moved_mol "Aligned molecule"
          lappend princ_moved_mol_list $princ_moved_mol
  
          set princ_moved_mol_axes [mol new]
          mol rename $princ_moved_mol_axes "Aligned molecule axes" 
          lappend princ_moved_mol_axes_list $princ_moved_mol_axes
  
          set a1 [lindex $paxis_list $i 0]
          set a2 [lindex $paxis_list $i 1]
          set a3 [lindex $paxis_list $i 2]
  
          puts "IN THE LOOP a1 = $a1, a2 = $a2, a3 = $a3"
          #constant 
          set user_target [list $xin $yin $zin] 
          set m1 [transvecinv [lindex $main_pa_list $i]]
          set m2 [transvec $user_target]
          set m_orig_to_com [transoffset [lindex $com_list $i]]
          set m_com_to_orig [transoffset [vecscale -1 [lindex $com_list $i]]]
          #m_to_user is specifically for the morphology included with translations to origin and back to COM
          set m_to_user [transmult $m_orig_to_com $m2 $m1 $m_com_to_orig]
          set aggrot [transmult $m2 $m1] 
          set a1_moved [coordtrans $aggrot $a1]
          set a2_moved [coordtrans $aggrot $a2]
          set a3_moved [coordtrans $aggrot $a3]
  
          if {$::NeuronVND::exclude_axons == 1} {
              set a3_moved [vecscale -1 $a3_moved]
          }
  
          graphics $princ_moved_mol delete all
          graphics $princ_moved_mol_axes delete all
  
          #draw numbers here and set principal axis
          graphics [lindex $princ_moved_mol_axes_list $i] color 9
          vmd_draw_vector [lindex $princ_moved_mol_axes_list $i] [lindex $com_list $i] [vecscale $princ_axes_scale $a1_moved]
          graphics [lindex $princ_moved_mol_axes_list $i] color 12
          vmd_draw_vector [lindex $princ_moved_mol_axes_list $i] [lindex $com_list $i] [vecscale $princ_axes_scale $a2_moved]
          graphics [lindex $princ_moved_mol_axes_list $i] color 15
          vmd_draw_vector [lindex $princ_moved_mol_axes_list $i] [lindex $com_list $i] [vecscale $princ_axes_scale $a3_moved]
                                                         
          foreach sphere [lindex $spherelist_list $i] {
              set ts [coordtrans $m_to_user $sphere]
              draw color 32
              graphics [lindex $princ_moved_mol_list $i] sphere $ts radius 1   
          }
      } 
      display update on
  }
  
  #utility function to set principal axis scale
     proc ::NeuronVND::set_scale {} {     proc ::NeuronVND::set_scale {} {
         variable princ_axes_scale         variable princ_axes_scale
         variable princ_axes         variable princ_axes
         variable scale1_temp         variable scale1_temp
         variable scale2_temp         variable scale2_temp
         variable scale3_temp         variable scale3_temp
  
         set a1 [lindex $princ_axes 0]         set a1 [lindex $princ_axes 0]
         set a2 [lindex $princ_axes 1]         set a2 [lindex $princ_axes 1]
         set a3 [lindex $princ_axes 2]         set a3 [lindex $princ_axes 2]
          
         set aggrot [transidentity]         set aggrot [transidentity]
         set aggrot [transmult $aggrot [transaxis x 0]]         set aggrot [transmult $aggrot [transaxis x 0]]
  
Line 3009
Line 2953
         set scale2_temp [vecscale $princ_axes_scale $a2_moved]         set scale2_temp [vecscale $princ_axes_scale $a2_moved]
         set scale3_temp [vecscale $princ_axes_scale $a3_moved]         set scale3_temp [vecscale $princ_axes_scale $a3_moved]
     }     }
     #toggles axes on and off 
  #free the lists from memory
     proc ::NeuronVND::delete_axes {} {     proc ::NeuronVND::delete_axes {} {
     variable principal_axis_mol     variable principal_axis_mol
     variable princ_moved_mol_axes     variable princ_moved_mol_axes
Line 3018
Line 2963
     variable rot_count 0     variable rot_count 0
     variable princ_moved_mol_axes     variable princ_moved_mol_axes
     variable princ_moved_mol      variable princ_moved_mol 
      variable paxis_list
      variable princ_moved_mol_axes_list
      variable princ_moved_mol_list
  
      variable principal_axis_mol_list
      variable com_list_apical
  
     mol delete $principal_axis_mol     mol delete $principal_axis_mol
     mol delete $princ_moved_mol_axes     mol delete $princ_moved_mol_axes
     mol delete $princ_moved_mol     mol delete $princ_moved_mol
          
      foreach x $paxis_list {
          mol delete $x
      }
      foreach y $principal_axis_mol_list {
          mol delete $y
      }
  
      foreach z $princ_moved_mol_list {
          mol delete $z
      }
  
      foreach a $princ_moved_mol_axes_list {
          mol delete $a
      }
      set ::NeuronVND::x_array_apical ""
      set ::NeuronVND::y_array_apical ""
      set ::NeuronVND::z_array_apical ""
      set ::NeuronVND::x_array_no_axon ""                
      set ::NeuronVND::y_array_no_axon ""
      set ::NeuronVND::z_array_no_axon ""
      set ::NeuronVND::x_array ""
      set ::NeuronVND::y_array ""
      set ::NeuronVND::z_array "" 
      set princ_moved_mol_list ""
      set princ_moved_mol_axes_list ""
     set mov_count 0     set mov_count 0
     set rot_count 0     set rot_count 0
     set princ_moved_mol_axes -1     set princ_moved_mol_axes -1
     set princ_moved_mol -1     set princ_moved_mol -1
      set principal_axis_mol_list ""
      set ::NeuronVND::morph_spherelist_combo_axon_exlusion ""
      set ::NeuronVND::morph_spherelist_combo_apical ""
      set ::NeuronVND::com_list ""
      set ::NeuronVND::size_list ""
      set ::NeuronVND::main_pa_list ""
      set ::NeuronVND::paxis_list ""
      set ::NeuronVND::spherelist_list ""
      set ::NeuronVND::com_list_apical ""
     }     }
  
     proc ::NeuronVND::delete_all {} {     proc ::NeuronVND::delete_all {} {
         variable principal_axis_mol         variable principal_axis_mol
         variable princ_moved_mol         variable princ_moved_mol
Line 3044
Line 3030
     }     }
 } }
  
 #used to jump a aggrot matrix to another aligned matrix 
 proc ::NeuronVND::jump {} { #todo: merge these two functions into 1
  #incrementally translate a neuron
  proc ::NeuronVND::movePcaGraphs {dim sign} {
    variable objList
    variable objIndex
    variable movex
    variable movey
    variable movez
    variable aggoffset
    variable aggrot
    variable princ_moved_mol
    variable princ_moved_mol_axes
    variable princ_axes
    variable princ_axes_scale
    variable princ_axes_com
    variable princ_axes_spherelist
    variable princ_axes_spherelist_moved
    variable xin
    variable yin
    variable zin
    variable draw_go
    variable scale1
    variable scale2
    variable scale3
    variable m_rot_around_orig
    variable m_com_to_orig
    variable m_orig_to_com
    variable m_rot_around_orig_then_offset
    variable moved
    variable rotated
    variable rot_count
    variable mov_count
    variable scale1_temp
    variable scale2_temp
    variable scale3_temp
    variable princ_moved_mol_axes_list
    variable nodes
    variable princ_moved_mol_list
    variable princ_moved_mol_axes_list
    variable paxis_list
    variable com_list
    variable spherelist_list
  
    #princ_moved_mol_list
      #princ_moved_mol_axes_list
     #  set a3 [lindex $paxis_list $i 2]
  
    set objid [lindex $objIndex 0]
    if {$objid == ""} {return}
  
    if {$princ_moved_mol == -1} {
      set princ_moved_mol [mol new]
      mol rename $princ_moved_mol "Aligned neuron"
    }
  
    if {$princ_moved_mol_axes == -1} {
      set princ_moved_mol_axes [mol new]
      lappend princ_moved_mol_axes_list $princ_moved_mol_axes
      mol rename $princ_moved_mol "Aligned neuron axes"
    }
  
    set numG [llength [graphics $objid list]]
    switch $dim {
      "x" { 
          set val $movex
          if {$sign == "neg"} {set val [expr -1*$val]}
          set offset [list $val 0.0 0.0] 
      }
      "y" { 
          set val $movey
          if {$sign == "neg"} {set val [expr -1*$val]}
          set offset [list 0.0 $val 0.0] 
      }
      "z" { 
          set val $movez
          if {$sign == "neg"} {set val [expr -1*$val]}
          set offset [list 0.0 0.0 $val] 
      }
      "default" {puts "error: dimension must be either x, y or z"}
    }
      set a1 [lindex $princ_axes 0]
      set a2 [lindex $princ_axes 1]
      set a3 [lindex $princ_axes 2]
  
      #4x4
      set offset_matrix [transoffset $offset] 
      set aggoffset [transmult $aggoffset $offset_matrix]
  
      if {$rot_count == 0} {
          #set m_orig_to_com [transoffset $princ_axes_com]
          #set m_com_to_orig [transoffset [vecscale -1 $princ_axes_com]]
          set m_rot_around_orig_then_offset $aggoffset
      } elseif {$rot_count != 0} {
          set m_rot_around_orig_then_offset [transmult $aggoffset $m_orig_to_com $aggrot $m_com_to_orig]
      } elseif {$mov_count != 0} {
          set m_rot_around_orig_then_offset $aggoffset
      }
      set a1_moved [coordtrans $aggoffset $a1]
      set a2_moved [coordtrans $aggoffset $a2]
      set a3_moved [coordtrans $aggoffset $a3]
  
      if {$rot_count == 0} {
          set scale1 $scale1_temp
          set scale2 $scale2_temp
          set scale3 $scale3_temp
  
      } else {
          set a1_moved [coordtrans $aggrot $a1]
          set a2_moved [coordtrans $aggrot $a2]
          set a3_moved [coordtrans $aggrot $a3]
  
          set scale1 [vecscale $princ_axes_scale $a1_moved]
          set scale2 [vecscale $princ_axes_scale $a2_moved]
          set scale3 [vecscale $princ_axes_scale $a3_moved]
      }
  
      graphics $princ_moved_mol_axes delete all
      graphics $princ_moved_mol_axes color 9
      vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale1
      graphics $princ_moved_mol_axes color 12
      vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale2
      graphics $princ_moved_mol_axes color 15
      vmd_draw_vector $princ_moved_mol_axes [coordtrans $aggoffset $princ_axes_com] $scale3
  
      draw color 22
      puts "a1 = $a1, a2 = $a2, a3 = $a3"
      graphics $princ_moved_mol delete all 
      foreach s $princ_axes_spherelist {
          set ts [coordtrans $m_rot_around_orig_then_offset $s]
          lappend princ_axes_spherelist_moved $ts
          graphics $princ_moved_mol sphere $ts radius 1
      }
  
      set princ_axes_sphere_list $princ_axes_spherelist_moved
      set princ_axes_spherelist_moved ""
  
      display update on
  
      if {$mov_count == 0} {
          display resetview
      }
      set moved 1
      incr mov_count
  }
  
  #incrementally rotate a neuron (don't edit)
  proc ::NeuronVND::rotPcaGraphs {axis sign} {
     variable objList     variable objList
     variable objIndex     variable objIndex
     variable rotarx     variable rotarx
Line 3059
Line 3191
     variable princ_axes_scale     variable princ_axes_scale
     variable princ_axes_com     variable princ_axes_com
     variable princ_axes_spherelist     variable princ_axes_spherelist
    variable princ_axes_spherelist_moved
    variable m_rot_around_orig
    variable m_rot_around_orig_then_offset 
     variable xin     variable xin
     variable yin     variable yin
     variable zin     variable zin
     variable draw_go     variable draw_go
     variable priority   variable initial_state
     variable priority_axis   variable scale1
    variable scale2
    variable scale3
     variable m_com_to_orig     variable m_com_to_orig
     variable m_orig_to_com     variable m_orig_to_com
    variable moved
     set aggoffset [transidentity]   variable rotated
     set aggrot [transidentity]   variable rot_count
    variable mov_count
  
     set objid [lindex $objIndex 0]     set objid [lindex $objIndex 0]
     if {$objid == ""} {return}     if {$objid == ""} {return}
  
     if {$princ_moved_mol == -1} {     if {$princ_moved_mol == -1} {
         set princ_moved_mol [mol new]         set princ_moved_mol [mol new]
         mol rename $princ_moved_mol "Aligned molecule"     mol rename $princ_moved_mol "Aligned neuron"
     }     }
  
         if {$princ_moved_mol_axes == -1} {         if {$princ_moved_mol_axes == -1} {
         set princ_moved_mol_axes [mol new]         set princ_moved_mol_axes [mol new]
         mol rename $princ_moved_mol_axes "Aligned molecule axes"     lappend princ_moved_mol_axes_list $princ_moved_mol_axes
      mol rename $princ_moved_mol "Aligned neuron axes"
     }     }
  
     set numG [llength [graphics $objid list]]     set numG [llength [graphics $objid list]]
    if {$axis != "x" && $axis != "y" && $axis != "z"} {
      puts "error: axis must be either x, y or z"
      return
    }
    switch $axis {
      "x" { set val $rotarx }
      "y" { set val $rotary }
      "z" { set val $rotarz }
    }
    if {$sign == "neg"} {set val [expr -1*$val]}
  
    #retrieves vectors of principal axes
    #really it's a list here
     set a1 [lindex $princ_axes 0]     set a1 [lindex $princ_axes 0]
     set a2 [lindex $princ_axes 1]     set a2 [lindex $princ_axes 1]
     set a3 [lindex $princ_axes 2]     set a3 [lindex $princ_axes 2]
     puts "a1 = $a1, a2 = $a2, a3 = $a3"     puts "a1 = $a1, a2 = $a2, a3 = $a3"
       #note that orient.tcl calculates what axis has the largest variance 
       set user_target [list $xin $yin $zin] 
       puts "priority is $priority_axis"   set princ_axes_com_offset [coordtrans $aggoffset $princ_axes_com]
       set m1 [transvecinv $priority_axis] 
       set m2 [transvec $user_target]   #For rotations, move the entire center of mass to the origin and then apply the rotations
    set m_orig_to_com_offset [transoffset $princ_axes_com_offset]
    set m_com_to_orig_offset [transoffset [vecscale -1 $princ_axes_com_offset]]
  
       set m_orig_to_com [transoffset $princ_axes_com]       set m_orig_to_com [transoffset $princ_axes_com]
       set m_com_to_orig [transoffset [vecscale -1 $princ_axes_com]]       set m_com_to_orig [transoffset [vecscale -1 $princ_axes_com]]
  
    #apply the axis rotation incrementally and then apply it to the aggregate rotation matrix
    set init_state $aggrot
    set aggrot [transmult $aggrot [transaxis $axis $val]]
    puts "aggrot = $aggrot"
       #m_to_user is specifically for the morphology included with translations to origin and back to COM       #m_to_user is specifically for the morphology included with translations to origin and back to COM
       set m_to_user [transmult $m_orig_to_com $m2 $m1 $m_com_to_orig]   set m_rot_around_orig_then_offset [transmult $aggoffset $m_orig_to_com $aggrot $m_com_to_orig]
       set aggrot [transmult $m2 $m1] 
  
    # update aggrot 
       set a1_moved [coordtrans $aggrot $a1]       set a1_moved [coordtrans $aggrot $a1]
       set a2_moved [coordtrans $aggrot $a2]       set a2_moved [coordtrans $aggrot $a2]
       set a3_moved [coordtrans $aggrot $a3]       set a3_moved [coordtrans $aggrot $a3]
  
    set scale1 [vecscale $princ_axes_scale $a1_moved]
    set scale2 [vecscale $princ_axes_scale $a2_moved]
    set scale3 [vecscale $princ_axes_scale $a3_moved]
  
    puts "yeeeeeee -> $scale1 , $scale2. $scale3"
  
       graphics $princ_moved_mol_axes delete all       graphics $princ_moved_mol_axes delete all
       graphics $princ_moved_mol delete all 
  
       graphics $princ_moved_mol_axes color 9       graphics $princ_moved_mol_axes color 9
       vmd_draw_vector $princ_moved_mol_axes $princ_axes_com [vecscale $princ_axes_scale $a1_moved]   vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale1
       graphics $princ_moved_mol_axes color 15 
       vmd_draw_vector $princ_moved_mol_axes $princ_axes_com [vecscale $princ_axes_scale $a2_moved] 
       graphics $princ_moved_mol_axes color 12       graphics $princ_moved_mol_axes color 12
       vmd_draw_vector $princ_moved_mol_axes $princ_axes_com [vecscale $princ_axes_scale $a3_moved]   vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale2
  
    graphics $princ_moved_mol_axes color 15
    vmd_draw_vector $princ_moved_mol_axes $princ_axes_com_offset $scale3
       draw color 22       draw color 22
  
    #SPHERE TUBES ARE BROKEN!
    #graphics $princ_moved_mol spheretube "$princ_axes_spherelist" radii 1 drawtubes 0
    
    #coordstrans takes a 4x4 and applies a transformation to each point in the entire sphere_list  
  
    graphics $princ_moved_mol delete all
  
       foreach s $princ_axes_spherelist {       foreach s $princ_axes_spherelist {
       set ts [coordtrans $m_to_user $s]         set ts [coordtrans $m_rot_around_orig_then_offset $s]
          lappend princ_axes_spherelist_moved $ts
       graphics $princ_moved_mol sphere $ts radius 1       graphics $princ_moved_mol sphere $ts radius 1
       }       }
  
  
   display update on   display update on
  
    if {$rot_count == 0} {
   display resetview   display resetview
 } }
      #set princ_axes_spherelist_moved ""
      #for {set i 1} {$i < [llength $princ_axes_spherelist]} {incr i} {
       #   lassign [graphics $princ_moved_mol info $i] t v1 radius r resolution res
      #    lappend princ_axes_spherelist_moved [list $v1]
          #graphics $objid replace $i
          #graphics $objid $t [list $newv1 $newv2] radii [list [lindex $r 0] [lindex $r 1]] drawtubes $on
     # }
      set rotated 1
      incr rot_count
      puts "rotated this many times --> $rot_count"
  }
  
 #utility to reset to the initial position  #utility to reset to the initial position 
 proc ::NeuronVND::resetpos {} { proc ::NeuronVND::resetpos {} {
Line 3138
Line 3324
     graphics $princ_moved_mol delete all     graphics $princ_moved_mol delete all
     graphics $princ_moved_mol_axes delete all     graphics $princ_moved_mol_axes delete all
  
      foreach id $::NeuronVND::princ_moved_mol_list {
          graphics $id delete all
      }
  
      foreach molid $::NeuronVND::princ_moved_mol_axes_list {
          graphics $molid delete all
      }
  
  
     set moved -1     set moved -1
     set rotated -1     set rotated -1
  
Line 3152
Line 3347
 } }
  
 #utility function to get the ID of a neuronal selection #utility function to get the ID of a neuronal selection
 proc get_population_ID {population} { proc ::NeuronVND::get_population_ID {population} {
     if {$population == ""} {     if {$population == ""} {
         puts "population error"         puts "population error"
         set ::NeuronVND::alignment_populationID "null"         set ::NeuronVND::alignment_populationID "null"
Line 3288
Line 3483
     .neuron.fp.systems.rep.main.table.tb delete 0 end     .neuron.fp.systems.rep.main.table.tb delete 0 end
  
     foreach m [molinfo list] {mol delete $m}     foreach m [molinfo list] {mol delete $m}
  
 } }
  
 proc ::NeuronVND::exit {} { proc ::NeuronVND::exit {} {


Legend:
Removed in v.1.38 
changed lines
 Added in v.1.39



Made by using version 1.65 of cvs2html