/usr/share/xcrysden/Tcl/runC95.tcl is in xcrysden-data 1.5.60-1build3.
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 | #############################################################################
# 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/runC95.tcl
# ------ #
# Copyright (c) 1996-2014 by Anton Kokalj #
#############################################################################
proc RunAndGetC95Output {command bg_how input_var} {
global system
set out $system(SCRDIR)/xc_output.$system(PID)
if { ! [RunC95 $command $bg_how $input_var $out ] } {
return 0
}
return [ReadFile $out]
}
proc RunC95 {command bg_how input_var \
{output_file {}} {is_string {}} {dir {}}} {
global system prop runC95
# command ... one of integrals, scf, scfdir, properties
#
# bg_how ... how to handle background execution:
# $bg_how == {} | {message <message_text>} | bg
# {} ... calculation is fast; give no feed-back to the user
# message . calculation can be long; display some message to
# the user
# bg ... calculation is probably very long;
# just submit to the background and forget about it.
# "{}" & "message" works via fileevent, whereas bg submit the
# job to background and forget about it.
#
# input_var ... variable where input is stored
#
# output_file ... name of output file
#
# is_string ... check if $is_string appear in crystal95's output
# this is just in any case
set runC95(output) {}
#
# check if the $command is allowed command
#
set match 0
foreach com [list $system(c95_integrals) $system(c95_scf) \
$system(c95_scfdir) $system(c95_properties)] {
if { $com == $command } { set match 1 }
}
if { ! $match } {
tk_dialog [WidgetName] "ERROR" "ERROR: CRYSTAL-$system(c95_version)'s command \"${command}:\" not found, must be one of: $system(c95_integrals), $system(c95_scf), $system(c95_scfdir), $system(c95_properties)" error 0 OK
return 0
}
#
# if dir is not defined, use default one
#
if { $dir == "" } {
set dir $system(SCRDIR)
}
#
# what is the output file ???
#
if { $output_file == "" } {
set output_file $system(SCRDIR)/xc_output.$system(PID)
}
set runC95(output_file) $output_file
set inp $dir/xc_tmp.$system(PID)
WriteFile $inp $input_var
#
# if the species is EXTERNAL
#
cxxManageExternal
####CD DIR#######
# now go to dir #
cd $dir
xcDebug -stderr "Crystal Input:\n--------------\n$input_var"
xcDebug "PWD = [pwd]"
if { $bg_how != "bg" } {
if { [lindex $bg_how 0] == "message" } {
###################################################################
# calculation can take some time, it's needed to
# give some feed back to the user.
set oldgrab [grab current]
set mw [DisplayUpdateWidget "Calculating" [lindex $bg_how 1]]
catch { grab $mw }
}
#
# change cursor to watch, to indicate that something is going on
#
SetWatchCursor
# ================================
# run CRYSTAL in background mode
# ================================
set runC95(command) $command
set runC95(fileID) [open "| $command < $inp 2> /dev/null" r]
fconfigure $runC95(fileID) -blocking 0
fileevent $runC95(fileID) readable C95FileEvent
tkwait variable runC95(done)
ResetCursor
xcSwapBuffers
if { [lindex $bg_how 0] == "message" } {
destroy $mw
if { $oldgrab != {} } {
catch { grab $oldgrab }
}
}
#
# has an error occured during CRYSTAL execution
#
if { $runC95(error) == 1 } {
#if [catch {exec $command < $inp > $output_file} err]
#C95Error $command $output_file $err
cd $system(SCRDIR)
unset runC95
ResetCursor
return 0
} else {
# if CRYSTAL has exited nicely, it does not mean that an
# error didn't occure; check for ERROR string (here
# CRYSTAL06 and later seems aexception when keyword STOP
# is used)
set is_str 0
set is_err 0
set fileID [open $output_file r]
foreach line [split [read $fileID] \n] {
if { [string match "*ERROR \*\*\*\**" $line] } {
# check for CRYSTAL06 line: "... STOP KEYWORD - EXECUTION STOPS"
if { ($system(c95_version) == "06" || $system(c95_version) == "09" || $system(c95_version) == "14") \
&& [string match "*STOP KEYWORD - EXECUTION STOPS*" $line] } {
# OK, we don't have error
continue
} else {
close $fileID
C95Error
cd $system(SCRDIR)
unset runC95
ResetCursor
return 0
}
}
if { $is_string != "" } {
if [string match "*${is_string}*" $line] {
set is_str 1
}
}
}
if { $is_string != "" && $is_str == 0} {
tk_dialog [WidgetName] "CRYSTAL ERROR" "ERROR: pattern \"$is_string\" not found in CRYSTAL-$system(c95_version)'s output; this may be bug in program - please report to author !!! \nCode: RunC95 -pattern not found-" error 0 OK
close $fileID
cd $system(SCRDIR)
unset runC95
ResetCursor
return 0
}
close $fileID
# t.k: zakaj skopira unit 34 ??????
if { $dir != $system(SCRDIR) } {
# copy ftn34 to $system(SCRDIR)
if [file exists $dir/$prop(file)34] {
file copy -force $dir/$prop(file)34 $system(SCRDIR)/$prop(file)34
}
}
cd $system(SCRDIR)
unset runC95
ResetCursor
xcDebug "end of RunC95"
return 1
}
}
}
proc C95FileEvent {} {
global runC95
if { ! [eof $runC95(fileID)] } {
append runC95(output) [gets $runC95(fileID)]\n
return
} else {
xcDebug "In C95FileEvent"
set runC95(error) 0
if { [catch {close $runC95(fileID)}] } {
xcDebug "In C95FileEvent: error while closing the process"
set runC95(error) 1
}
#
# write $output to runC95(output_file)
#
set fileID [open $runC95(output_file) w]
puts $fileID $runC95(output)
flush $fileID
close $fileID
#
# if we have an error display tk_dialog
#
if { $runC95(error) } {
C95Error
}
set runC95(done) 1
}
}
proc C95Error {} {
global c95error runC95 system
set button [tk_dialog [WidgetName] ERROR \
"ERROR occured while executing CRYSTAL-$system(c95_version) command: $runC95(command)" \
error 0 OK Details]
if { $button == 1} {
set oldgrab [grab current]
set t [xcToplevel [WidgetName] "CRYSTAL ERROR" "ERROR" \
. 100 100 1]
catch { grab $t }
set fileID [open $runC95(output_file) r]
set output [read $fileID]
close $fileID
set text [DispText $t.f $output 80 35]
set fric [lindex [$text yview] 1]
$text yview moveto [expr 1.0 - $fric]
$text config -state disabled
proc C95ErrorCan {} {
global c95error
set c95error(done) 1
}
set f2 [frame $t.f2 -height 10]
pack $f2 -side bottom -before $t.f -fill x
set close [button $f2.cl -text "Close" \
-command C95ErrorCan]
pack $close -side left -expand 1 -ipadx 2 -ipady 2 -pady 10
tkwait variable c95error(done)
unset c95error
catch { grab release $t }
destroy $t
if { $oldgrab != "" } {
catch { grab $oldgrab }
}
}
}
#
# Purpose: driver proc for executing CRYSTAL for Advanced-Geom manipulations
#
proc RunC95_advGeom {input option error_text} {
global system
# cd to SCRATCH dir
cd $system(SCRDIR)
set output xc_output.$system(PID)
cxxManageExternal
if { [catch {exec $system(c95_integrals) < $input > $output} errMsg] } {
# printing the "FORTRAN STOP" to stderr cause the error. Check !!!
if { $errMsg != "FORTRAN STOP" } {
# a real error occurred
ErrorDialog "an error occured for option: $option. Please try Again !!!" $errMsg
# delete last AdvGeom state
xcAdvGeomState delete
ResetCursor
return 0
}
}
# if CRYSTAL has exited nicely, it does not mean that an error
# didn't occure; check for ERROR (here CRYSTAL06 and later seems
# an exception when keyword STOP is used)
set file [ReadFile $output]
foreach line [split $file \n] {
if { [string match "*ERROR \*\*\*\**" $line] } {
# check for CRYSTAL06 line: "... STOP KEYWORD - EXECUTION STOPS"
if { ($system(c95_version) == "06" || $system(c95_version) == "09" || $system(c95_version) == "14") \
&& [string match "*STOP KEYWORD - EXECUTION STOPS*" $line] } {
# OK, we don't have error
continue
} else {
ErrorDialogInfo "$error_text Please try Again !!!" $file
# delete last AdvGeom state
xcAdvGeomState delete
ResetCursor
return 0
}
}
}
return 1
}
|