TABLE OF CONTENTS
::pwtk::nebi::replaceImage
SYNOPSIS
proc ::pwtk::nebi::replaceImage {index imageData} {
PURPOSE
Set the atomic positions & total_charge for the requested image, i.e., replace the corresponding ATOMIC_POSITIONS & TOTAL_CHARGE cards in the neb.x input.
ARGUMENTS
- index -- index of image to set (index can be also "first" and "last"; the 1st image has index of 1)
- imageData -- atomic-positions and optionally total charge for the $index image
Note that the TOTAL_CHARGE specs are optional but ATOMIC_POSITIONS specs are mandatory in 'imageData'. If the current index-th image has TOTAL_CHARGE and TOTAL_CHARGE is not provided in 'imageData', the current value will be maintained. To delete the TOTAL_CHARGE, use the ::pwtk::nebi::deleteImageCharges command.
REMARK
This command is not related to the "num_of_images" variable, but to FIRST_IMAGE, INTERMEDIATE_IMAGE..., LAST_IMAGE specs in the POSITIONS card (aka BEGIN_POSITIONS / END_POSITIONS).
Note that if index != 1 then "atmPos" will be tranformed to "coor" (the difference is that "atmPos" may contain the if_pos(:) fields but "coor" does not).
EXAMPLE
::pwtk::nebi::replaceImage 2 { ATOMIC_POSITIONS symb1 x1 y1 z1 ?if_pos_x1 if_pos_y1 if_pos_z1? symb2 x2 y2 z2 ?if_pos_x2 if_pos_y2 if_pos_z2? ... TOTAL_CHARGE tot_charge } N.B note that the TOTAL_CHARGE card is optional but ATOMIC_POSITIONS is mandatory
SOURCE
# extract atmPos set atmPos [::pwtk::purifyCoor $imageData] if { $atmPos == {} } { ::pwtk::warning "no ATOMIC_POSITIONS found. Skipping ..." return } # extract charge (if supplied) set ind [string first TOTAL_CHARGE $imageData] if { $ind > -1 } { set charge [lindex [string range $imageData $ind end] end] } else { set charge {} } set nimages [getNImages] if { $nimages == 0 } { # no image specified ::pwtk::error "cannot set any image because POSITIONS card is empty" 1 } set index [image_in_range_ $index $nimages] if { $index != 1 } { set atmPos [::pwtk::atmPosToCoor $atmPos] } set iimage 0 set chargeSet 0 set positions {} set skip 0 foreach line [split [::pwtk::input::cardGetContent POSITIONS] \n] { if { [regexp {IMAGE} $line] } { if { $iimage == $index && ! $chargeSet && $charge != {} } { # TOTAL_CHARGE card was missing & charge was not yet written append positions "TOTAL_CHARGE\n$charge\n" } incr iimage set skip 0 } elseif { [regexp {ATOMIC_POSITIONS} $line] } { if { $iimage == $index } { append positions $line\n$atmPos\n set skip 1 continue } else { set skip 0 } } elseif { [regexp {TOTAL_CHARGE} $line] } { if { $iimage == $index && $charge != {} } { append positions $line\n$charge\n set skip 1 set chargeSet 1 continue } else { set skip 0 } } if { ! $skip } { append positions $line\n } } # take care of LAST_IMAGE if TOTAL_CHARGE record is missing if { $iimage == $index && ! $chargeSet && $charge != {} } { # TOTAL_CHARGE card was missing & charge was not yet written append positions "TOTAL_CHARGE\n$charge\n" } POSITIONS $positions return $positions }