#Plotting transition electric dipole moment (red arrow) and transition magnetic dipole moment (cyan arrow)
#Generated by Multiwfn
#Usage examples:
#emtran 2: Plotting the 2nd excited state, both two arrows have default length of 5 Angstrom,
#          with default arrow radius of 0.15 Angstrom, which is equivalent to running "emtran 2 5 5 0.15"
#emtran 2 5 5 0.15  0.12 0.05 0.4  -0.1 0.07 -0.4: The same as above, but shift center of the red arrow by (0.05 0.4 0.1),
#          and shift center of the cyan arrow by (-0.1 0.07 -0.4)
proc emtran {iexc {scl1 5} {scl2 5} {rad 0.15} {sft1x 0} {sft1y 0} {sft1z 0} {sft2x 0} {sft2y 0} {sft2z 0}} {
draw delete all
color Name C tan
color change rgb tan 0.7 0.56 0.36
light 3 on
material change specular Opaque 0.3
global etran
global mtran
draw color red
drawarrow all $etran(1,$iexc) $etran(2,$iexc) $etran(3,$iexc) $scl1 $rad $sft1x $sft1y $sft1z
draw color cyan3
drawarrow all $mtran(1,$iexc) $mtran(2,$iexc) $mtran(3,$iexc) $scl2 $rad $sft2x $sft2y $sft2z
}
 
set etran(1,1)   -0.005100
set etran(2,1)   -0.284500
set etran(3,1)    0.000000
set etran(1,2)    0.000000
set etran(2,2)    0.000000
set etran(3,2)    0.180500
set etran(1,3)   -0.833000
set etran(2,3)    2.823000
set etran(3,3)    0.000000
set mtran(1,1)    0.121150
set mtran(2,1)    0.013350
set mtran(3,1)    0.000000
set mtran(1,2)    0.000000
set mtran(2,2)    0.000000
set mtran(3,2)   -0.073750
set mtran(1,3)   -1.991000
set mtran(2,3)    0.017950
set mtran(3,3)    0.000000
 
#atmrange: Selection of atoms, whose geometry center defines arrow center
#vecx/dy/dz: Cartesian component of the vector to be plotted
#scl: Scale factor of normalized vector
#rad: Radius of arrow
#sftx, sfty, sftz: Shift of center in X,Y,Z
proc drawarrow {atmrange vecx vecy vecz {scl 5} {rad 0.15} {sftx 0} {sfty 0} {sftz 0}} {
#Determine arrow center
set sel [atomselect top $atmrange]
set cen [measure center $sel]
set cenx [expr [lindex $cen 0]+$sftx]
set ceny [expr [lindex $cen 1]+$sfty]
set cenz [expr [lindex $cen 2]+$sftz]
#Scale the normalized vector to obtain actual length
set vecnorm [veclength "$vecx $vecy $vecz"]
set vecx [expr $vecx/$vecnorm*$scl]
set vecy [expr $vecy/$vecnorm*$scl]
set vecz [expr $vecz/$vecnorm*$scl]
#Draw arrow
set body 0.75
set begx [expr $cenx-$vecx/2.0]
set begy [expr $ceny-$vecy/2.0]
set begz [expr $cenz-$vecz/2.0]
set endx [expr $cenx+$vecx*$body-$vecx/2.0]
set endy [expr $ceny+$vecy*$body-$vecy/2.0]
set endz [expr $cenz+$vecz*$body-$vecz/2.0]
draw cylinder "$begx $begy $begz" "$endx $endy $endz" radius $rad filled yes resolution 20
set endx2 [expr $cenx+$vecx/2.0]
set endy2 [expr $ceny+$vecy/2.0]
set endz2 [expr $cenz+$vecz/2.0]
draw cone "$endx $endy $endz" "$endx2 $endy2 $endz2" radius [expr $rad*2.5] resolution 20
}
