/usr/share/xcrysden/Tcl/scripting.tcl is in xcrysden-data 1.5.60-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 | #############################################################################
# Author: #
# ------ #
# Anton Kokalj Email: Tone.Kokalj@ijs.si #
# Department of Physical and Organic Chemistry Phone: x 386 1 477 3523 #
# Jozef Stefan Institute Fax: x 386 1 477 3811 #
# Jamova 39, SI-1000 Ljubljana #
# SLOVENIA #
# #
# Source: $XCRYSDEN_TOPDIR/Tcl/scripting.tcl
# ------ #
# Copyright (c) 1996-2003 by Anton Kokalj #
#############################################################################
# ------------------------------------------------------------------------
#****h* XCRYSDEN/Scripting ***
#
# NAME
# scripting -- Scripting facility (v0.1) of XCRYSDEN
#
# COPYRIGHT
# Anton Kokalj (C) 2003
#
# FUNCTION
#
# Often a mechanism for automating a particular job is desirable. For
# example, one might want to produce several plots of molecular
# orbitals of a given molecule. It would be desirable that the display
# parameters are exactly the same for all plots. By using the
# XCRYSDEN's GUI one would need to open each file and repeat all the
# operations for each molecular orbital, and this is largely
# redundant. Once the display parameters for one plot are determined
# one could produce the others using script which automates the task.
# This is the purpose of the "Scripting" class of functions, namely,
# to provide an XCRYSDEN shell-script mechanism for achieving such
# jobs.
#
# AUTHOR
# Anton Kokalj
#
# CREATION DATE
# Sometime in February 2003
#
# NOTES
#
# At this stage the API of Scripting is not yet completely fixed and
# is used for testing the "scripting" possibility, that is, loading
# the tasks from a Tcl script.
#
#****
# ------------------------------------------------------------------------
namespace eval scripting {
variable scripting
set scripting(verbosity) 1
}
# ------------------------------------------------------------------------
#****if* Scripting/scripting::source
#
# NAME
# scripting::source
#
# USAGE
# scripting::source scriptfile
#
# PURPOSE
# This proc is used to source the an XCRYSDEN script. The proc is for
# internal use only, namely, the XCRYSDEN uses this proc to sources
# the scriptFile.
#
# ARGUMENTS
# scriptfile -- name of scripting file
#
# RETURN VALUE
# Undefined.
#****
# ------------------------------------------------------------------------
proc scripting::source {scriptfile} {
global scriptFile
set scriptFile $scriptfile
# execute script in global level --
uplevel \#0 {
cd $system(PWD)
SetWatchCursor
source [gunzipFile $scriptFile]
ResetCursor
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::open
#
# NAME
# scripting::open
#
# USAGE
# scripting::open option file ?option file? ...
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to open structure files. The
# usage is very similar to that of xcrysden command, that is, instead
# of "xcrysden option file" one calls "scripting::open option file".
#
# ARGUMENTS
# args -- the command line arguments (those of xcrysden program)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::open --xsf file.xsf
#****
# ------------------------------------------------------------------------
proc scripting::open {args} {
parseComLinArg $args
update
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::save
#
# NAME
# scripting::save
#
# USAGE
# scripting::save ?format? file
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to save the structure
# information of the current structure. So far only the XSF format is
# supported.
#
# ARGUMENTS
# format -- the format to be used for saved [OPTIONAL]
# filename -- the name of the file to save into
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::save --xsf file.xsf
#****
# ------------------------------------------------------------------------
proc scripting::save {args} {
set len [llength $args]
if { $len < 1 || $len > 2 } {
ErrorDialog "wrong number of arguments, $len. Must be ::scripting::save ?format? filename"
return
}
set fmt xsf
if { $len == 2 } {
set fmt [lindex $args 0]
switch $fmt {
xsf { DummyProc }
default {
ErrorDialog "wrong format in ::scripting::save, $fmt. Must be \"xsf\"."
return
}
}
}
set filename [lindex $args end]
SaveStruct $filename
return 1
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::exec
#
# NAME
# scripting::exec
#
# USAGE
# scripting::exec option file ?option file? ...
#
# PURPOSE
# This proc is used inside majorScript of scripting::multiScript.
# Instead of calling "xcrysden option file" one calls "scripting::exec
# option file".
#
# ARGUMENTS
# args -- the command line arguments (those of xcrysden program)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::exec --xsf file.xsf
#****
# ------------------------------------------------------------------------
proc scripting::exec {args} {
global env system
variable scripting
# support the following: cd $dir; scripting::exec ***
set system(PWD) [pwd]
set script "namespace eval ::scripting \{\n"
if { [regexp -- {^--} [lindex $args 0]] } {
# we have an option, i.e., --option file
append script "scripting::open $args\n"
} else {
# we have a filter-routine, i.e., scripting::filter file
append script $args\n
}
if { [info exists scripting(minorScript)] } {
append script $scripting(minorScript)
}
append script "\n\}\n"
# write a script file
set script_file [file join $system(PWD) xc_script.tcl.$system(PID)]
WriteFile $script_file $script w
switch -- [string tolower $scripting(verbosity)] {
1 - yes - on {
puts stderr "From scripting::exec executing a minor-script::"
puts stderr "-----------------------------------------------\n$script"
}
}
# load a script file
#catch {::exec sh $env(XCRYSDEN_TOPDIR)/xcrysden --script $script_file >& $system(SCRDIR)/log}
xcCatchExec sh $env(XCRYSDEN_TOPDIR)/xcrysden --script $script_file >& $system(SCRDIR)/log
# check for a Tcl-error
set log [ReadFile $system(SCRDIR)/log]
if { [string match {*Error in startup script:*} $log] } {
puts stderr $log
exit 1
}
# delete the script file
if { [file exists $script_file] } {
file delete $script_file
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::multiScript
#
# NAME
# scripting::multiScript
#
# USAGE
# scripting::multiScript majorScript minorScript
#
# PURPOSE
# This proc is for multiple-task jobs. For example, one might want to
# produce several plots of molecular orbitals of a given molecule. It
# would be desirable that the display parameters are exactly the same
# for all plots. This proc is provided to facilitate such jobs. In
# majorScript one specifies how many times to run XCRYSDEN and what
# files to load, and in minorScript one specify what to do with this
# files. For example the instruction in minorScript would be how to
# render molecular orbitals for each provided file in majorScript (see
# example).
#
# ARGUMENTS
# majorScript -- a major script
# minorScript -- a minor script
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::multiScript {
# # ------------------------------------------------------------------------
# # This is the MAJOR script
# #
# # Lets open a structures from several files (one at a time), and
# # print them.
# # ------------------------------------------------------------------------
#
# foreach file {file1.xsf file2.xsf} {
# scripting::exec --xsf $file
# file rename -force print.png $file.png
# } {
# } {
# # ------------------------------------------------------------------------
# # This is the MINOR script
# #
# # It renders and print a structure
# # ------------------------------------------------------------------------
#
# scripting::lighting On
# scripting::displayMode3D BallStick
# scripting::zoom +0.5
# scripting::rotate x -90
# scripting::rotate y -30
# scripting::printToFile print.png windowdump
# }
#
#****
# ------------------------------------------------------------------------
proc scripting::multiScript {majorScript minorScript} {
variable scripting
global system
if { [winfo exists .title] } {
destroy .title
update
}
set scripting(majorScript) $majorScript
set scripting(minorScript) $minorScript
#puts stderr "DEBUG> multiScript::"
#puts stderr "$scripting(majorScript)"
#puts stderr ""
cd $system(PWD)
eval $scripting(majorScript)
exit 0
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::lighting
#
# NAME
# scripting::lighting
#
# USAGE
# scripting::lighting On|Off
#
# PURPOSE
# This proc toggles the lighing Off/On display mode.
#
# ARGUMENTS
# mode -- the lighting mode (must be On or Off)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::lighting On
#****
# ------------------------------------------------------------------------
proc scripting::lighting {mode} {
global light
switch -glob [string totitle $mode] {
"On" { set light On; Lighting On }
"Off" { set light Off; Lighting Off }
default {
ErrorDialog "wrong lighting-mode $mode, should one On or Off"
return
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::display
#
# NAME
# scripting::display
#
# USAGE
# scripting::display on|off coordinate-system|atomic-labels|crystal-cells|
# unicolor-bonds|wigner-seitz-cell|molecular-surface
# or
# scripting::display on|off perspective ?near-factor? ?far-factor?
# or
# scripting::display as ball|spacefill covalent|vad-der-waals
# or
# scripting::display as crystal-cells rods|lines
# or
# scripting::display as cell-mode primitive|convetional
# or
# scripting::display as cell-unit cell|asymm
#
# PURPOSE
# This proc is used to set the display property of various objects,
# such as coordinate system, atomic symbols, perspective projection
# etc. The "scripting::display on|off" command will display or
# not-display a requested object, while "scripting::display as" will
# display particular object as requested.
#
# ARGUMENTS
# mode -- the mode of command, must be one of on|off|as
# what -- what object to display
# args -- the rest of arguments (as requested by particular object)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::display on coordinate-system
# or
# scripting::display as cell-mode primitive
#****
# ------------------------------------------------------------------------
proc scripting::display {mode what args} {
global check radio
switch $mode {
yes - on - 1 { set mode 1 }
no - off - 0 { set mode 0 }
as { ; }
default {
ErrorDialog "wrong scripting::display mode $mode, should be on or off"
return
}
}
if { $mode == "1" || $mode == "0" } {
# ------------------------------------------------------------------------
# scripting::display on|off ...
# ------------------------------------------------------------------------
switch -glob [string tolower $what] {
"coor*" {
set check(crds) $mode;
CrdSist
}
"atom*" - "label*" {
set check(labels) $mode
AtomLabels
}
"cryst*" - "cell*" {
set check(frames) $mode
CrysFrames
}
"unicol*" - "unibon*" {
set check(unibond) $mode
Unibond
}
"force*" - {
set check(forces) $mode
forceVectors .mesa
}
"wigner*" - {
set check(wigner) $mode
WignerSeitz
}
"molec*" - "molsurf*" {
set check(pseudoDens) $mode
PseudoDensity
}
"persp*" {
set check(perspective) $mode
if { $args != "" } {
# args1 = near-factor; args2 = far-factor
set i 0
foreach var $args {
set var($i) [lindex $args $i]
if { ! [string is double $var($i)] } {
ErrorDialog "expected double, but got $var($i), while executing scripting::display $mode $what $args"
}
if { $i == 0 } {
xc_newvalue .mesa $mody(L_PERSPECTIVEFOVY) $var($i)
} else {
xc_newvalue .mesa $mody(L_PERSPECTIVEBACK) $var($i)
}
incr i
}
}
Perspective
}
}
} elseif { $mode == "as" } {
# ------------------------------------------------------------------------
# scripting::display as ...
# ------------------------------------------------------------------------
switch -glob [string tolower $what] {
"ball*" {
switch -glob [string tolower $args] {
"cova*" {
set radio(ball) "Balls based on covalent radii"
xc_newvalue .mesa $mody(L_BALL_COV)
}
"van*" {
set radio(ball) "Balls based on Van der Waals radii"
xc_newvalue .mesa $mody(L_BALL_VDW)
}
}
}
"spacefill*" {
switch -glob [string tolower $args] {
"cova*" {
set radio(space) "SpaceFill based on covalent radii"
xc_newvalue .mesa $mody(L_SPACE_COV)
}
"van*" {
set radio(space) "SpaceFill based on Van der Waals radii"
xc_newvalue .mesa $mody(L_SPACE_VDW)
}
}
}
"crystal-c" - "crystal-f" - "frame*" {
switch -glob [string tolower $args] {
"rod*" {
set radio(frames) rods
DispFramesAs
}
"line*" {
set radio(frames) lines
DispFramesAs
}
}
}
"cell-s*" - "cell-m*" {
switch -glob [string tolower $args] {
"prim*" {
set radio(cellmode) prim
CellMode 1
}
"conv*" {
set radio(cellmode) conv
CellMode 1
}
}
}
"cell-u*" - "unit of rep*" {
switch -glob [string tolower $args] {
"cell*" {
set radio(unitrep) cell
CellMode 1
}
"asym*" {
set radio(unitrep) asym
CellMode 1
}
}
}
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::displayMode3D
#
# NAME
# scripting::displayMode3D
#
# USAGE
# scripting::lighting sticks|pipe&ball|ballstick|spacefill
#
# PURPOSE
# Switch to requested 3D (i.e. Lighting-On) display mode
#
# ARGUMENTS
# mode -- one of allowed 3D display modes
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::displayMode3D ballstick
#****
# ------------------------------------------------------------------------
proc scripting::displayMode3D {mode} {
switch -glob [string tolower $mode] {
"stick*" { DisplayOver3D S }
"pipe&ball*" { DisplayOver3D PB }
"ballstick*" { DisplayOver3D BS }
"spacefill*" { DisplayOver3D SF }
default {
ErrorDialog "wrong 3D display-mode $mode, should one of Stick, Pipe&Ball, BallStick, or SpaceFill"
return
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::displayMode2D
#
# NAME
# scripting::displayMode2D
#
# USAGE
# scripting::lighting wireframe|pointline|pipe&ball|ballstick-1|ballstick-2|spacefill
#
# PURPOSE
# Switch to requested 2D (i.e. Lighting-Off) display mode
#
# ARGUMENTS
# mode -- one of allowed 2D display modes
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::displayMode2D ballstick
#****
# ------------------------------------------------------------------------
proc scripting::displayMode2D {mode} {
switch -glob [string tolower $mode] {
"wireframe*" { Display2D WF }
"pointline*" { Display2D PL }
"pipe&ball*" { Display2D PB }
"ballstick-1" { Display2D BS1 }
"ballstick*" { Display2D BS2 }
"spacefill*" { Display2D SF }
default {
ErrorDialog "wrong 2D display-mode $mode, should one of WireFrame, PointLine, Pipe&Ball, BallStick-1, BallStick-2, or SpaceFill"
return
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::mainWindow
#
# NAME
# scripting::mainWindow
#
# USAGE
# scripting::mainWindow maximize
# or
# scripting::mainWindow resize width height
#
# PURPOSE
# Resize the XCRYSDEN main window.
#
# ARGUMENTS
# action -- mode od resizing (maximize or resize)
# args -- width and height for resize mode
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::mainWindow resize 500 500
#****
# ------------------------------------------------------------------------
proc scripting::mainWindow {action args} {
switch -exact -- $action {
maximize {
global maingeom
set maingeom Maxi
MainGeom
}
resize {
set len [llength $args]
if { $len != 2 } {
ErrorDialog "wrong number of arguments $len, should be \"scripting::mainWindow resize width height"
return
}
set w [lindex $args 0]
set h [lindex $args 0]
foreach num $args {
if { ! [string is integer $num] } {
ErrorDialog "expected integer but got $num, while executing w scripting::mainWindow $action $w $h"
}
}
PlaceGlobWin 1 $w $h
}
default {
ErrorDialog "wrong subcommand $action, should be maximize or resize, while executing scripting::mainWindow ..."
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::displayWindow
#
# NAME
# scripting::displayWindow
#
# USAGE
# scripting::displayWindow fullscreen
# or
# scripting::displayWindow resize width height
#
# PURPOSE
# Resize the XCRYSDEN display window of XCRYSDEN's main window.
#
# ARGUMENTS
# action -- mode od resizing (fullscren or resize)
# args -- width and height for resize mode
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::displayWindow resize 500 500
#****
# ------------------------------------------------------------------------
proc scripting::displayWindow {action args} {
switch -exact -- $action {
maximize - fullscreen {
maximizeDisplay
}
resize {
set len [llength $args]
if { $len != 2 } {
ErrorDialog "wrong number of arguments $len, should be \"scripting::displayWindow resize width height"
return
}
set w [lindex $args 0]
set h [lindex $args 1]
foreach num $args {
if { ! [string is integer $num] } {
ErrorDialog "expected integer but got $num, while executing scripting::displayWindow $action $w $h"
}
}
PlaceGlobWin display_resize $w $h
}
default {
ErrorDialog "wrong subcommand $action, should be maximize or resize, while executing scripting::displayWindow ..."
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::zoom
#
# NAME
# scripting::zoom
#
# USAGE
# scripting::zoom step ?nsteps?
#
# PURPOSE
# This proc zooms the displayed structure. The optional argument
# nsteps determines the number of zooming steps. If it is omitted only
# one zooming is performed. The unit of step is fractional, unless %
# sign is appended to the step number. In this case the step is in
# percentage unit.
#
# ARGUMENTS
# step -- the zooming step (typical values between 0 and 1)
# nstep -- number of zooming step (default=1)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::zoom 0.05
# scripting::zoom 5%
#
#****
# ------------------------------------------------------------------------
proc scripting::zoom {step {ntimes 1}} {
if { ! [string is integer $ntimes] } {
ErrorDialog "wanted integer, but got $ntimes, while executing scripting::zoom $step $ntimes"
return
}
if { [string range $step end end] == "%" } {
set step [string trim $step %]
if { ! [string is double $step] } {
ErrorDialog "wanted double, but got $step, while executing scripting::zoom $step $ntimes"
}
set step [expr {$step / 100.0}]
} elseif { ! [string is double $step] } {
ErrorDialog "wanted double, but got $step, while executing scripting::zoom $step $ntimes"
}
for {set i 0} {$i < $ntimes} {incr i} {
.mesa xc_translate +z $step
update
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::rotate
#
# NAME
# scripting::rotate
#
# USAGE
# scripting::rotate x|y|z rotationstep ?nsteps?
# or
# scripting::rotate xy|xz|yz rotstep_dir1 rotstep_dir2 ?nsteps?
#
# PURPOSE
# This proc rotates the displayed objects, either around x, y, or z
# axes (x|y|z modes), or around x-and-y, x-and-z, y-and-z axes
# (xy|xz|yz modes). In the latter case the rotste_dir1 is the rotation
# step for the first axis, while rotstep_dir2 is the rotation step for
# second axis. The optional argument nsteps determines the number of
# rotation steps. If it is omitted only one rotation is performed.
#
# ARGUMENTS
# dir -- direction of rotation (must be one one x, y, z, xy, xz, or yz)
# args -- the rest of arguments as requested by particular mode
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::rotate x 5
# or
# scripting::rotate x 5 10
# or
# scripting::rotate xy 5 5
# or
# scripting::rotate xy 5 5 10
#****
# ------------------------------------------------------------------------
proc scripting::rotate {dir args} {
switch -- $dir {
xy - xz - yz {
set argc [llength $args]
if { $argc < 2 && $argc > 4 } {
ErrorDialog "wrong number of scripting::rotate ++ arguments"
return
}
set step1 [lindex $args 0]
set step2 [lindex $args 1]
set n_step [lindex $args 2]
if { $n_step == "" } {
set n_step 1
}
if { ! [string is integer $n_step] } {
ErrorDialog "wanted integer, but got $ntimes, while executing scripting::rotate $dir $args"
return
}
for {set i 0} {$i < $n_step} {incr i} {
.mesa xc_rotate ++$dir $step1 $step2
update
}
}
x - y - z {
set argc [llength $args]
if { $argc < 1 && $argc > 2 } {
ErrorDialog "wrong number of scripting::rotate arguments"
return
}
set step [lindex $args 0]
set n_step [lindex $args 1]
if { $n_step == "" } {
set n_step 1
}
if { ! [string is integer $n_step] } {
ErrorDialog "wanted integer, but got $ntimes, while executing scripting::rotate $dir $args"
return
}
for {set i 0} {$i < $n_step} {incr i} {
.mesa xc_rotate +$dir $step
update
}
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::printToFile
#
# NAME
# scripting::printToFile
#
# USAGE
# scripting::printToFile ?filename? ?windowdump? ?togl?
#
# PURPOSE
# This proc prints to a file the content of the display window. If
# windowdump is specified, the display window is dumped to a file.In
# the windowdump case make sure that no other window obscures the
# display window, as it will appear on the dump. If togl option is
# omitted the XCRYSDEN main display window is assumed.
#
# ARGUMENTS
# filename -- the name of the file to print to (if not specified or
# void, the filename will be queried)
# windowdump -- if non-void, the a display window dump is performed
# togl -- the pathName of the display window
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::printToFile print.png
#****
# ------------------------------------------------------------------------
proc scripting::printToFile {{filename {}} {windowdump {}} {togl .mesa}} {
global xcMisc system printSetup light toglEPS
#
# check if we have converting program
#
if { $filename == "" } {
set filename [printTogl_queryFilename]
if { $filename == "" } {
return
}
}
cd $system(PWD)
set ext [file extension [file tail $filename]]
set EXT [string toupper $ext]
SetWatchCursor
if { $windowdump != "" } {
dumpWindow $togl $filename
return
}
if { $EXT == ".EPS" || $EXT == ".PS" } {
if { $light == "On" } {
#
# ligting-ON mode
#
set colorEPS 1
$togl xc_dump2eps $filename $colorEPS
} else {
#
# ligting-OFF mode
#
if { ! [info exists toglEPS(pointsize)] } {
set toglEPS(pointsize) 2.0
}
if { ! [info exists toglEPS(linewidth)] } {
set toglEPS(linewidth) 2.0
}
$togl cry_gl2psPrintTogl GL2PS_EPS GL2PS_NO_SORT GL2PS_NONE \
$toglEPS(pointsize) $toglEPS(linewidth) $filename
}
} else {
printTogl_Antialias begin
if { $EXT == ".PPM" } {
$togl cry_dump2ppm $filename 1 1 1
} elseif { $EXT == ".PGM" } {
$togl cry_dump2ppm $filename 2
} else {
if { ! [info exists xcMisc(ImageMagick.convert)] } {
ErrorDialog "cannot print to [file tail $filename], the variable xcMisc(ImageMagick.convert) is not defined in \$HOME/.xcrysden/custom-definition file."
return
}
$togl cry_dump2ppm $system(SCRDIR)/tmp.ppm 1
scripting::_printToFile_imageConvert $system(SCRDIR)/tmp.ppm $filename
}
printTogl_Antialias end
}
ResetCursor
}
# ------------------------------------------------------------------------
#****if* Scripting/scripting::_printToFile_imageConvert
#
# NAME
# scripting::_printToFile_imageConvert
#
# USAGE
# scripting::printToFile infile outfile
#
# PURPOSE
# This proc performs the PPM to PNG/GIF/JPEG image conversion. It is used
# internally by printToFile proc.
#
# ARGUMENTS
# infile -- name of PPM file to convert (input)
# outfile -- name of converted file (output)
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::_printToFile_imageConvert tmp.ppm print.png
#****
# ------------------------------------------------------------------------
proc scripting::_printToFile_imageConvert {infile outfile} {
global printSetup xcMisc
if { ! [info exists printSetup(useOptions) ] } {
# see the printSetup proc
set printSetup(useOptions) 0
}
if { ! [info exists xcMisc(ImageMagick.convertOptions)] } {
set xcMisc(ImageMagick.convertOptions) ""
}
if { $printSetup(useOptions) } {
eval xcCatchExecReturn $xcMisc(ImageMagick.convert) $xcMisc(ImageMagick.convertOptions) $infile $outfile
} else {
eval xcCatchExecReturn $xcMisc(ImageMagick.convert) $infile $outfile
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::load_myParam
#
# NAME
# scripting::load_myParam
#
# USAGE
# scripting::load_myParam
#
# PURPOSE
# This proc loads the myParam values defined in the script.
#
# ARGUMENTS
# None.
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# set myParam(TESSELLATION) 50.0
# set myParam(ATRAD_SCALE) 1.00
# scripting::load_myParam
#
#****
# ------------------------------------------------------------------------
proc scripting::load_myParam {} {
::load_myParam
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::buildCrystal
#
# NAME
# scripting::buildCrystal
#
# USAGE
# scripting::buildCrystal nx ?ny? ?nz?
#
# PURPOSE
# This proc builds (i.e. generate) a crystal, that is, nx-cells in 1st
# direction, ny-cells in second direction, and nz-cells in 3rd
# direction.
#
# ARGUMENTS
# nx -- number of cells in 1st crystallographic direction
# ny -- number of cells in 2nd crystallographic direction
# nz -- number of cells in 3rd crystallographic direction
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::buildCrystal 3 3 3
#
#****
# ------------------------------------------------------------------------
proc scripting::buildCrystal {nx {ny 0} {nz 0}} {
global periodic nxdir nydir nzdir
foreach num [list $nx $ny $nz] {
if { ! [string is integer $num] } {
ErrorDialog "expected integer but got $num, while executing scripting::buildCrystal $nx $ny $nz"
return
}
if { $num < 0 } {
ErrorDialog "expected positive integer but got $num, while executing scripting::buildCrystal $nx $ny $nz"
return
}
}
if { $periodic(dim) == 0 } { return }
if { $periodic(dim) < 2 } { set ny 0 }
if { $periodic(dim) < 3 } { set nz 0 }
set nxdir $nx
set nydir $ny
set nzdir $nz
GenGeomDisplay 1
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::chdir
#
# NAME
# scripting::chdir -- an enhanced version of cd
#
# USAGE
# scripting::chdir newdir
#
# PURPOSE
# This proc is an enhancement of standard "cd" routine. It changes the
# directory to $newdir and updates system(PWD) variable.
#
# ARGUMENTS
# newdir -- new directory to chdir into
#
# RETURN VALUE
# The absolute path of $newdir.
#
# EXAMPLE
# scripting::chdir ../
#
#****
# ------------------------------------------------------------------------
proc scripting::chdir {newdir} {
global system
cd $newdir
set system(PWD) [pwd]
return $system(PWD)
}
|