/usr/share/xcrysden/Tcl/scriptingFilter.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 | #############################################################################
# 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/scriptingFilter.tcl
# ------ #
# Copyright (c) 1996-2003 by Anton Kokalj #
#############################################################################
# ------------------------------------------------------------------------
#****c* Scripting/scripting::filter
#
# NAME
# scripting::filter
#
# PURPOSE
# This namespace provide the filter functions for loading crystal
# (molecular) structures from various formats. The filter functions
# are similar to "scripting::open --format file.format". However for
# some formats using the latter form will query interactively some
# parameters, for instance, atomic numbers are usually not known in
# I/O files of pseudopotential-codes and are therefore
# queried. Instead by using the filter functions, the necessary
# information is supplied in function call, thus avoiding interactive
# querying. This makes the filter functions suitable for use in
# scripts. For example, if one wants to make 100 figures, the 100
# interactive queries would be very cumbersome, therefore one can use
# the filter functions instead.
#
# COMMANDS
#
# scripting::filter::g98cube -- loads the Gaussian98 CUBE file
# scripting::filter::crystalInput -- loads the CRYSTAL input file
# scripting::filter::pwscfInput -- loads the PWSCF input file
# scripting::filter::pwscfOutput -- loads the PWSCF output file
# scripting::filter::fhiInpini -- loads the FHI98MD inp.ini file
# scripting::filter::fhiCoord -- loads the FHI98MD coord.out file
#
#****
# ------------------------------------------------------------------------
namespace eval scripting::filter {}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::g98cube
#
# NAME
# scripting::filter::g98cube
#
# USAGE
# scripting::filter::g98cube cube_file mo_index
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display a particular
# molecular orbital (MO) from Gaussian cube-file by specifying the
# "mo_index", which is the ID of the MO as specified in the Gaussian
# cube-file. Using instead the "scripting::open --g98_cube cube_file"
# proc will result in querying the mo_index. Hence this proc differs
# from "scripting::open --g98_cube cube_file" in that the mo_index is
# already specified explicitly and is therefore not queried.
#
# ARGUMENTS
# cube_file -- name of Gaussian cube file.
# mo_index -- which Molecular Orbital to display
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::g98cube molecular_orbitals.cube 11
#****
# ------------------------------------------------------------------------
proc scripting::filter::g98cube {cube_file mo_index} {
global g98
set cube_file [_init $cube_file]
set files [g98Cube:cube2xsf $cube_file]
set mo_file mo-[format %3.3d $mo_index].xsf
set ind [lsearch $files $mo_file]
if { $ind == -1 } {
ErrorDialog "molecular orbital with index $mo_index does not exists in cube file: $cube_file"
exit
}
set mo_file [lindex $files $ind]
xsfOpen $g98(cube_dir)/$mo_file .mesa
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::crystalInput
#
# NAME
# scripting::filter::crystalInput
#
# USAGE
# scripting::filter::crystalInput crystalInput_file
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display a the structure
# from the CRYSTAL input file. Using instead the "scripting::open
# --crystal_inp file" call will result in interactive query of some
# action. Instead this proc immediately displays the structure and the
# interactive query is turned off.
#
# ARGUMENTS
# crystalInput_file -- name of CRYSTAL input file.
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::crystalInput urea.c98
#****
# ------------------------------------------------------------------------
proc scripting::filter::crystalInput {crystalInput_file} {
global crystalInput
set crystalInput_file [_init $crystalInput_file]
OpenFile $crystalInput_file
if { [xcIsActive c95] } {
CalStru
foreach t $crystalInput(two_toplevels) {
destroy $t
}
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::pwscfInput
#
# NAME
# scripting::filter::pwscfInput -- Filter for PWscf-Input files
#
# USAGE
# scripting::filter::pwscfInput pwscfInput_file reduce ?itypNatList?
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display crystal structure
# from PWSCF input file. It is similar to "scripting::open --pw_inp
# file" call. The latter call will result in querying the atomic
# numbers for PWscf version < 1.3, while this information is supplied
# in the function call by itypNatList argument. One can also specify a
# possible reduction of the structure dimensionality. For example, if
# the structure is a molecule, then one can get rid of 3D unit cell,
# by reducing the dimensionality to 0D.
#
# ARGUMENTS
# pwscfInput_file -- name of PWSCF input file.
# reduce -- reduce dimenionality to "reduce"-D.
# itypNatList -- used for PWSCF < 1.2 only.
# PWSCF's ityp --> atomic-number (i.e. nat) mapping list.
# The format of the list is the following:
# {ityp1 nat1 ityp2 nat2 ...}
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::pwscfInput water.inp 0 {1 8 2 1} ; # for PWSCF < 1.2
# scripting::filter::pwscfInput water.inp 0 ; # for PWSCF >= 1.2
#****
# ------------------------------------------------------------------------
proc scripting::filter::pwscfInput {pwscfInput_file reduce {itypNatList {}}} {
global system xcMisc
# the structure of itypNatList is the following:
# ----------------------------------------------
# set itypNatList [list ityp1 nat1 ityp2 nat2]
# standard PWSCF pre-setting
set pwscfInput_file [_absoluteFilename $pwscfInput_file]
_pwscfInputCheckItypNatList $pwscfInput_file $itypNatList
_pwscf scripting::filter::pwscfInput $pwscfInput_file $reduce $itypNatList
# load the structure
openExtStruct 3 crystal external \
[list sh $system(TOPDIR)/scripts/pwi2xsf.sh] \
$system(SCRDIR)/pwi2xsf.xsf_out \
{PWSCF Input File} \
ANGS \
-file $pwscfInput_file
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::pwscfOutput
#
# NAME
# scripting::filter::pwscfOutput -- Filter for PWscf-Output files
#
# USAGE
# scripting::filter::pwscfOutput option pwscfOutput_file reduce ?itypNatList?
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display crystal structure
# from PWSCF output file. It is similar to "scripting::open --pw_out
# file" call. The latter call will result in querying the atomic
# numbers, ... Contrary, this information is supplied in the function
# call by itypNatList argument (used only for PWSCF outputs <
# 1.2). One can also specify possible reduction of the structure
# dimensionality. For example, if the structure is a molecule, then
# one can get rid of 3D unit cell, by reducing the dimensionality to
# 0D. Since PWSCF output file may contains several structures, one
# should specify which one to display using the option argument.
#
# ARGUMENTS
# option -- which structure to render. Possibilities:
# --initcoor or -ic ... render initial structure
# --latestcoor or -lc ... latest structure in the file
# --optcoor or -oc ... optimized structure
# --animxsf or -a ... extract all structure (animation)
# pwscfOutput_file -- name of PWSCF output file
# reduce -- reduce dimenionality to "reduce"-D
# itypNatList -- used for PWSCF < 1.2 only.
# PWSCF's ityp --> atomic-number (i.e. nat) mapping list.
# The format of the list is the following:
# {ityp1 nat1 ityp2 nat2 ...}
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::pwscfOutput --optcoor water.out 0 {1 8 2 1} ; # for PWSCF < 1.2
# scripting::filter::pwscfOutput --optcoor water.out 0 ; # for PWSCF >= 1.2
#
#****
# ------------------------------------------------------------------------
proc scripting::filter::pwscfOutput {option pwscfOutput_file reduce {itypNatList {}}} {
global system xcMisc pw
# the structure of itypNatList is the following:
# set itypNatList [list ityp1 nat1 ityp2 nat2]
# standard PWSCF pre-setting
set pwscfOutput_file [_absoluteFilename $pwscfOutput_file]
_pwscfOutputCheckItypNatList $pwscfOutput_file $itypNatList
_pwscf scripting::filter::pwscfOutput $pwscfOutput_file $reduce $itypNatList
# load the structure
switch -exact -- $option {
--inicoor - -ic -
--optcoor - -oc -
--latestcoor - -lc -
--animxsf - -a {
set pw(output_flag) $option
}
default {
ErrorDialog "wrong option $option, must be one of --initcor, --latestcoor, --optcoor, or --animxsf"
exit
}
}
pwOutputPresetWhat dummy $pwscfOutput_file
set xsf [ReadFile $system(SCRDIR)/pwo2xsf.xsf]
puts stderr "XSF = \n$xsf"
xsfOpen $system(SCRDIR)/pwo2xsf.xsf .mesa
}
proc scripting::filter::_pwscf {procname file reduce itypNatList} {
global system
# the structure of itypNatList is the following:
# set itypNatList [list ityp1 nat1 ityp2 nat2]
set len [_pp_common $procname $file $reduce $itypNatList]
if { $itypNatList != "" } {
# write the nuclei.charges file
set out "[expr $len / 2]\n"
foreach {ityp nat} $itypNatList {
append out "$ityp $nat\n"
}
} else {
# workaround for PWscf version 1.2
set out 0
}
evalInScratch {WriteFile nuclei.charges $out w}
}
# ------------------------------------------------------------------------
# scripting::filter::_pwscfInputCheckItypNatList --
#
# Check the PWscf Input-file if the itypNatList argument is
# necessary !!!
# ------------------------------------------------------------------------
proc scripting::filter::_pwscfInputCheckItypNatList {file itypNatList} {
set ntyp 0
set is_new_input 0
set is_old_input 0
foreach line [split [ReadFile $file] \n] {
foreach field [split $line ,] {
if { [string match -nocase *ntyp* $field] } {
set ntyp [lindex [split $field =] 1]
break
}
}
if { [string match -nocase *&input* $line] } {
set is_old_input 1
}
if { [string match -nocase *&system* $line] } {
set is_new_input 1
}
}
puts stderr "File = file"
if { $ntyp == 0 || (!$is_new_input && !$is_old_input) } {
# the file is not PW-input file
ErrorDialog "file \"$file\" is not a PWSCF Input file !!!\n\nTrace:\nntyp=$ntyp\nis_new_input=$is_new_input\nis_old_input=$is_old_input\n\nApplication will Exit."
exit 1
}
if { $is_old_input && $itypNatList == "" } {
ErrorDialog "please specify itypNatList argument for PWscf Input file < 1.3 !!!\n\nApplication will Exit."
exit 1
}
}
# ------------------------------------------------------------------------
# scripting::filter::_pwscfOutputCheckItypNatList --
#
# Check the PWscf Output-file if the itypNatList argument is
# necessary !!!
# ------------------------------------------------------------------------
proc scripting::filter::_pwscfOutputCheckItypNatList {file itypNatList} {
set version 0.0
set fid [open $file r]
while { ! [eof $fid] } {
gets $fid line
if { [string match "* Program PWSCF *" $line] } {
#
# get the PWscf version of the output
#
set ver [split [string trimleft [lindex $line 2] {v.}] .]
set version [lindex $ver 0].[lindex $ver 1]
if { [llength $ver] == 3 } {
append version [lindex $ver 2]
}
break
}
}
close $fid
if { $version < 1.2 && $itypNatList == "" } {
ErrorDialog "please specify itypNatList argument for PWscf Output file < 1.3 !!!\n\nApplication will Exit."
exit 1
}
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::fhiInpini
#
# NAME
# scripting::filter::fhiInpini
#
# USAGE
# scripting::filter::fhiInpini fhiInpini_file reduce itypNatList
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display crystal structure
# from FHI98MD inp.ini file. It is similar to "scripting::open
# --fhi_inpini file" call. The latter call will result in querying the
# atomic numbers. Contrary, this information is supplied in function
# call of the scripting::filter::fhiInpini. Also one can specify
# possible reduction of the structure dimensionality. For example, if
# the structure is a molecule, then one can get rid of 3D unit cell,
# by reducing the dimensionality to 0D.
#
# ARGUMENTS
# fhiInpini_file -- name of FHI98MD input file.
# reduce -- reduce dimenionality to "reduce"-D
# itypNatList -- FHI98MD's atomic-name --> atomic-number (i.e. nat)
# mapping list. The format of the list is the following:
# {name1 nat1 name2 nat2 ...}
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::fhiInpini inp.ini 0 {oxygen 8 hydrogen 1}
#****
# ------------------------------------------------------------------------
proc scripting::filter::fhiInpini {fhiInpini_file reduce nameNatList} {
global system
# the structure of nameNatList is the following:
# set nameNatList [list name1 nat1 name2 nat2]
set fhiInpini_file [_absoluteFilename $fhiInpini_file]
_fhi scripting::filter::fhiInpini $fhiInpini_file $reduce $nameNatList
openExtStruct 3 crystal external34 \
$system(BINDIR)/fhi_inpini2ftn34 \
$system(ftn_name).34 {FHI98MD "ini.inp"} \
BOHR \
-file $fhiInpini_file
}
# ------------------------------------------------------------------------
#****f* Scripting/scripting::filter::fhiCoord
#
# NAME
# scripting::filter::fhiCoord
#
# USAGE
# scripting::filter::fhiCoord fhiCoord_file reduce itypNatList
#
# PURPOSE
# This proc is used in XCRYSDEN scripts to display crystal structure
# from FHI98MD coord.out file. It is similar to "scripting::open
# --fhi_coord file" call. The latter call will result in querying the
# atomic numbers. Contrary, this information is supplied in function
# call of the scripting::filter::fhiCoord. Also one can specify
# possible reduction of the structure dimensionality. For example, if
# the structure is a molecule, then one can get rid of 3D unit cell,
# by reducing the dimensionality to 0D.
#
# ARGUMENTS
# fhiCoord_file -- name of FHI98MD input file.
# reduce -- reduce dimenionality to "reduce"-D
# itypNatList -- FHI98MD's atomic-name --> atomic-number (i.e. nat)
# mapping list. The format of the list is the following:
# {name1 nat1 name2 nat2 ...}
#
# RETURN VALUE
# Undefined.
#
# EXAMPLE
# scripting::filter::fhiCoord coord.out 0 {oxygen 8 hydrogen 1}
#****
# ------------------------------------------------------------------------
proc scripting::filter::fhiCoord {fhiCoord_file reduce nameNatList} {
global system
# the structure of nameNatList is the following:
# set nameNatList [list name1 nat1 name2 nat2]
set fhiCoord_file [_absoluteFilename $fhiCoord_file]
_fhi scripting::filter::fhiCoord $fhiCoord_file $reduce $nameNatList
openExtStruct 3 crystal external \
$system(BINDIR)/fhi_coord2xcr \
fhi_coord.xcr {FHI98MD "coord.out"} \
BOHR \
-file $fhiCoord_file
}
proc scripting::filter::_fhi {procname file reduce nameNatList} {
global system xcMisc
# the structure of nameNatList is the following:
# set nameNatList [list name1 nat1 name2 nat2]
set len [_pp_common $procname $file $reduce $nameNatList]
# get the list of atom names
if { [namespace tail $procname] == "fhiInpini" } {
xcCatchExecReturn $system(BINDIR)/fhi_inpini2ftn34 $file getlist
#if { [catch {exec $system(BINDIR)/fhi_inpini2ftn34 $file getlist}] } {
# ErrorDialog "error while executing \"fhi_inpini2ftn34 $file getlist\" program"
# return 0
#}
} else {
# type == fhiCoord
xcCatchExecReturn $system(BINDIR)/fhi_coord2xcr $file getlist
#if { [catch {exec $system(BINDIR)/fhi_coord2xcr $file getlist}] } {
# ErrorDialog "error while executing \"fhi_coord2xcr $file getlist\" program"
# return 0
#}
}
# get the atom names
set atomNames [lrange [ReadFile $system(SCRDIR)/fhi_species_name.list] 1 end]
# write the nuclei.charges file
set out "[expr $len / 2]\n"
foreach {name nat} $nameNatList {
set Nat($name) $nat
}
# the order in nameNatList and atomNames might be different, the
# atomNames order is the right one
foreach name $atomNames {
append out $Nat($name)\n
}
# ------------------------------------------------------------------------
# cd to SCRATCH directory and write the file
cd $system(SCRDIR)
WriteFile fhi_species_nat.list $out w
# ------------------------------------------------------------------------
}
# pp_common == pseudo-potential common
proc scripting::filter::_pp_common {procname file reduce atomMappingList} {
global xcMisc
set file [_init $file]
# REDUCE factor is used for reducing the periodic structure to
# lower dimensions
if { ! [string is digit $reduce] } {
ErrorIn $procname "reduce-factor must be an integer, but got $reduce"
} else {
if { $reduce > -1 && $reduce < 4 } {
set xcMisc(reduce_to) $reduce
}
}
# check the length itypNatList
set len [llength $atomMappingList]
if { $len % 2 } {
ErrorIn $procname "odd number of elements in atomMappingList list"
exit
}
return $len
}
proc scripting::filter::_init {file} {
# pop-up the Viewer
ViewMol .
# destroy the welcome window
destroyWelcomeWindow
set file [_absoluteFilename $file]
if { ! [file exists $file] } {
ErrorDialog "File $file does not exists"
exit
}
return $file
}
proc scripting::filter::_absoluteFilename {file} {
if { [file pathtype $file] != "absolute" } {
global system
evalInPWD {
set file [file join [pwd] $file]
}
}
return $file
}
|