TABLE OF CONTENTS


::pwtk::replaceAtom

SYNOPSIS

proc ::pwtk::replaceAtom {atomIndex atomSpecs atmPos} {

PURPOSE

Replace the atom with index "atomIndex" in "atmPos" with the new atom (i.e. atomic-symbol + coordinates) specified by "atomSpecs".

ARGUMENTS

RETURN VALUE

new "atmPos" with the atom "atomIndex" replaced with new specs

SOURCE

    set nat [getNAtoms $atmPos]
    if { $atomIndex < 1 || $atomIndex > $nat } {
        ::pwtk::error "atom index $atom out of range, should be within \[1, $nat\]" 1
    }
    if { ! ([llength $atomSpecs] == 4 || [llength $atomSpecs] == 7) } {
        ::pwtk::error "wrong atom specs \"$atomSpecs\", must consist of 4 or 7 fields" 1
    }
    
    set newAtmPos ""
    set nl ""
    set ind 1
    foreach atom [split [purifyCoor $atmPos] \n] {
        if { $atomIndex == $ind } {
            set atom $atomSpecs
        }
        append newAtmPos ${nl}$atom
        set nl \n
        incr ind
    }
    return $newAtmPos
}