TABLE OF CONTENTS


::pwtk::nebi::path2imageAtmPos

SYNOPSIS

proc ::pwtk::nebi::path2imageAtmPos {args} {

USAGE

   ::pwtk::nebi::path2imageAtmPos ?-k? ?-ifpos? pathFile index

PURPOSE

Get the atomic positions of the index-th image from the neb.x path file.

OPTIONS

ARGUMENTS

SOURCE

    set narg 2
    set usage "pathFile index"
    set options {
        {k     "precede atomic positions with the ATOMIC_POSITIONS keyword"}
        {ifpos "return atmPos (symb x y z ifx ify ifz) instead of Coor (symb x y z)"}
    }
    ::pwtk::parseOpt_
    lassign $args pathFile index

    set pathL [split [::pwtk::readFile $pathFile] \n]
    set ims [lsearch -all $pathL Image:*]

    set nimages [llength $ims]
    set index [::pwtk::nebi::image_in_range_ $index $nimages]    
    
    set i1 [expr [lindex $ims $index-1] + 2]
    if { $index < $nimages } {
        set i2 [expr [lindex $ims $index] - 1]
    } else {
        # for index == nimages, the above recipe does not work for 'i2'
        set i1m [expr [lindex $ims $index-2] + 2]
        set i2m [expr [lindex $ims $index-1] - 1]
        set i2  [expr $i1 + $i2m - $i1m]
    }

    set natp [expr $i2 - $i1 + 1]
    set nati [::pwtk::nebi::getNAtoms]
    
    if { $natp != $nati } {
        ::pwtk::error "the number of input atoms ($nati) differ from the number of atoms in the path file ($natp);
cannot assign atomic symbols to atomic positions from the '$pathFile' path file" 1
    }
    
    set symbols [::pwtk::nebi::getAtmSymbList]
    set coor    [lrange $pathL $i1 $i2]

    if { $opt(k) } {
        set result "ATOMIC_POSITIONS (bohr)\n"
    }
    if { $opt(ifpos) } {
        append result [join [lmap s $symbols xyz $coor {
            format $::pwtk::fmt_atmPos(7) {*}[concat $s [lrange $xyz 0 2] [lrange $xyz 6 8]]
        }] ""]
    } else {
        append result [join [lmap s $symbols xyz $coor {
            format $::pwtk::fmt_atmPos(4) {*}[concat $s [lrange $xyz 0 2]]
        }] ""]
    }

    return $result
}