Index: utils/developer/tcl/README
===================================================================
--- utils/developer/tcl/README	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
+++ utils/developer/tcl/README	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
@@ -0,0 +1,5 @@
+This folder contains tcl scripts to be used with VMD (copy to vmd/scripts/tcl) 
+for debugging purposes. E.g. to display triangles in tesselation.
+
+As these are developer-only and not meant for the end-user, they are not
+distributed.
Index: utils/developer/tcl/animatesphere.tcl
===================================================================
--- utils/developer/tcl/animatesphere.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
+++ utils/developer/tcl/animatesphere.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
@@ -0,0 +1,127 @@
+#!/usr/bin/tclsh
+#
+# This scripts displays the rolling sphere used in the tesselation procedure
+# to compute the molecular surface via VMD's graphics interface.
+# It is used during debugging and all its parameters are thrown out by an
+# error message in CandidateForTesselation.cpp.
+
+
+proc animate_sphere { molid atomid1 atomid2 atomid3 rad x1 y1 z1 x2 y2 z2 {step 25} } {
+	global SphereRadius
+	global vector1
+	global vector2
+	global CircleCenter
+	global angle
+	global radius
+	global M_PI
+	set SphereRadius $rad
+
+	# avoid some 'animate dup' bug
+	set molid [molinfo $molid get id]
+	# check molid
+	if {[molinfo $molid get numframes] != 1} {
+		error "Can't find $molid or more than 1 frame."
+	}
+	# step must be integer and greater 2
+	if {$step != int($step)} {
+		error "step must be integer."
+	}
+	if {$step < 2} {
+		error "step should be greater than 2."
+	}
+	# make step-1 copies of current frame
+	for {set i 1} {$i <$step} {incr i} {
+		animate dup frame 0 $molid
+	}
+
+	# select both atoms
+	incr atomid1 -1
+	incr atomid2 -1
+	incr atomid3 -1
+	set selid1 [atomselect $molid "index $atomid1" frame 0]
+	set selid2 [atomselect $molid "index $atomid2" frame 0]
+	set selid3 [atomselect $molid "index $atomid3" frame 0]
+
+	# calculate origin of rotation
+	set Atom1 [$selid1 get {x y z}]
+	puts "Atom1 is $Atom1."
+	set Atom2 [$selid2 get {x y z}]
+	puts "Atom2 is $Atom2."
+	set Atom3 [$selid3 get {x y z}]
+	puts "Atom3 is $Atom3."
+	set CircleCenter [vecadd [vecscale 0.5 [expr $Atom1]] [vecscale 0.5 [expr $Atom2]]]
+	set CircleCenter [vecadd [vecscale 0.5 [expr $Atom1]] [vecscale 0.5 [expr $Atom2]]]
+	puts "CircleCenter is at $CircleCenter."
+	
+	# calculate normal
+	set Normaltmp [vecsub [expr $Atom1] [expr $Atom2]]
+	set CirclePlaneNormal [vecnorm $Normaltmp]
+	puts "CirclePlaneNormal is at $CirclePlaneNormal."
+
+	# calculate radius
+	set SphereCenter [vecsub [list $x1 $y1 $z1] $CircleCenter]
+	puts "SphereCenter is at $SphereCenter."
+	set OtherSphereCenter [vecsub [list $x2 $y2 $z2] $CircleCenter]
+	puts "OtherSphereCenter is at $OtherSphereCenter."
+	set radius [veclength $SphereCenter]
+	puts "Radius of circle is $radius."
+	set vector1 [vecnorm $SphereCenter]
+	puts "vector1 is $vector1."
+
+	# calculate other normal vector on plane, pointing out of triangle
+	set vector2 [veccross $CirclePlaneNormal $vector1]
+	set helper [vecsub $CircleCenter [expr $Atom3]]
+	if {[vecdot $helper $vector2] < -1e-10} {
+		puts "vector2 points inwards, rescaling."
+		set vector2 [vecscale -1. $vector2]
+	}
+	puts "vector2 is $vector2."
+
+	# get angle
+	set angle [expr acos([vecdot $SphereCenter $OtherSphereCenter]/[veclength $SphereCenter]/[veclength $OtherSphereCenter])]
+
+	# make angle in right direction (rotating outward in the sense of vector2
+	set SKP [vecdot $OtherSphereCenter $vector2]
+	puts "SKP with SearchDirection is $SKP."
+	if {$SKP < -1e-10} {
+		set angle [expr 2.*$M_PI - $angle]
+	}
+	puts "angle is $angle."
+
+	global vmd_frame
+	trace variable vmd_frame([molinfo top]) w update_current_sphere
+	display update
+	#enumerate_atoms 0
+	return
+}	
+
+proc update_current_sphere {name index op} { 
+	global SphereRadius
+	global radius
+	global angle
+	global vector1
+	global vector2
+	global CircleCenter
+	# draw sphere
+	set CurrentAngle [expr ($angle/[expr [molinfo $index get numframes]-1])*[molinfo $index get frame]]
+	set center [vecadd [vecscale $radius [vecadd [vecscale [expr cos($CurrentAngle)] $vector1] [vecscale [expr sin($CurrentAngle)] $vector2]]] $CircleCenter]
+	#puts "center is now at $center with CurrentAngle is $CurrentAngle and radius $SphereRadius."
+	draw material Transparent
+	draw color silver
+	if {[draw exists 2] != 0} {
+		draw replace 2
+	}
+	draw sphere $center radius [expr $SphereRadius] resolution 30
+	return
+}
+
+proc animate_sphere_off {} {
+	global vmd_frame
+	trace vdelete vmd_frame([molinfo top]) w update_current_sphere
+	draw delete all
+	animate delete beg 1 end 25 skip 0 [molinfo top]
+	return
+}
+
+#enumerate_atoms 0
+#animate_sphere 0 15 6 3. 4.00145 1.4968 1.28282 1.97354 -2.53854 -1.81601
Index: utils/developer/tcl/showsurface.tcl
===================================================================
--- utils/developer/tcl/showsurface.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
+++ utils/developer/tcl/showsurface.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
@@ -0,0 +1,39 @@
+#!/usr/bin/tclsh
+#
+# This scripts parsed a tecplot style file of triangles and displays them via VMD's graphics interface
+
+# fname is the filename of the tecplot .dat file
+proc show_surface { fname } {
+	draw delete all
+	# open file
+	set file [open $fname r]
+	gets $file title
+	gets $file variables
+	gets $file zone
+	# parse nodes
+	set ncount 1
+	gets $file line
+	while { $line != {} } {
+		set nodes($ncount) $line
+		incr ncount
+		gets $file line
+	}
+	set ncount [ expr $ncount -1 ]
+	puts "There are $ncount nodes."
+	# there's a blank line in between
+	# parse triangles
+	set tcount 0
+	gets $file line
+	while { $line != {} } {
+		set triangles [ split $line " "]
+		set first [ lrange $nodes([ lindex $triangles 0 ]) 0 2 ]
+		set second [ lrange $nodes([ lindex $triangles 1 ]) 0 2 ]
+		set third [ lrange $nodes([ lindex $triangles 2 ]) 0 2 ]
+		draw material Transparent
+		draw color blue2
+		draw triangle $first $second $third
+		incr tcount
+		gets $file line
+	}
+	puts "There are $tcount triangles."
+}	
Index: utils/developer/tcl/surfacing.tcl
===================================================================
--- utils/developer/tcl/surfacing.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
+++ utils/developer/tcl/surfacing.tcl	(revision 1d2d01ed7d609f7ea5e51dc8825133772d41911b)
@@ -0,0 +1,97 @@
+#!/usr/bin/tclsh
+#
+# This scripts parsed a tecplot style file of triangles and produces one
+# frame for each found triangle to be used in animation of the tesselation
+# including the rolling sphere via VMD's graphics interface.
+#
+# Use as follows:
+# surfacing <filename>		# to start
+# surfacing_off 		# to end
+
+# fname is the filename of the tecplot .dat file
+proc surfacing { fname } {
+	global nodes
+	global Triangles
+	global tcount
+	# open file
+	set file [open $fname r]
+	gets $file title
+	gets $file variables
+	gets $file zone
+	# parse nodes
+	set ncount 1
+	gets $file line
+	while { $line != {} } {
+		set nodes($ncount) $line
+		incr ncount
+		gets $file line
+	}
+	set ncount [ expr $ncount -1 ]
+	puts "There are $ncount nodes."
+	# there's a blank line in between
+	# parse triangles
+	set tcount 0
+	gets $file line
+	while { $line != {} } {
+		set Triangles($tcount) [ split $line " "]
+		incr tcount
+		gets $file line
+	}
+	puts "There are $tcount triangles."
+	
+
+	# avoid some 'animate dup' bug
+	set molid [molinfo top]
+	if {$tcount < 2} {
+		error "tcount should be greater than 2."
+	}
+	# make tcount-1 copies of current frame
+	for {set i 0} {$i <$tcount} {incr i} {
+		animate dup frame 0 $molid
+	}
+	animate goto 0
+
+	global vmd_frame
+	trace variable vmd_frame([molinfo top]) w update_current_surface
+	display update
+	return
+}	
+
+proc update_current_surface {name index op} { 
+	draw delete all
+	global nodes
+	global Triangles
+	set count 0
+	set frame [molinfo $index get frame]
+	while { [expr $count+1] < $frame } {
+		draw color red
+		draw material Transparent
+		set first [ lrange $nodes([ lindex $Triangles($count) 0 ]) 0 2 ]
+		set second [ lrange $nodes([ lindex $Triangles($count) 1 ]) 0 2 ]
+		set third [ lrange $nodes([ lindex $Triangles($count) 2 ]) 0 2 ]
+		draw triangle $first $second $third
+		incr count
+	}
+	if { [expr $count+1] <= $frame } {
+		draw color green
+		draw material Opaque
+		puts "Last triangle is [lindex $Triangles($count) 0] [lindex $Triangles($count) 1] [lindex $Triangles($count) 2]"
+		set first [ lrange $nodes([ lindex $Triangles($count) 0 ]) 0 2 ]
+		set second [ lrange $nodes([ lindex $Triangles($count) 1 ]) 0 2 ]
+		set third [ lrange $nodes([ lindex $Triangles($count) 2 ]) 0 2 ]
+		draw triangle $first $second $third
+	}
+	#enumerate_atoms 0
+	
+	return
+}
+
+proc surfacing_off {} {
+	global vmd_frame
+	global tcount
+	trace vdelete vmd_frame([molinfo top]) w update_current_surface
+	draw delete all
+	animate delete beg 1 end $tcount skip 0 [molinfo top]
+	return
+}
+
