TABLE OF CONTENTS


::pwtk::pwi::coorToAtmPos

SYNOPSIS

proc ::pwtk::pwi::coorToAtmPos {coorLines} {

PURPOSE

Transform Coor to AtmPos, that is, supplement the coordinate-lines (AtmSy x y z) with the if_pos(:) flags from the current pw.x input data.

SOURCE

    set calculation [::pwtk::input::namelistGetVarValue CONTROL calculation 1]
    if { $calculation == "neb" || $calculation == "smd" } {
        set allow_path 1
    } else {
        set allow_path 0
    }
    set coorLines [::pwtk::purifyCoor $coorLines]
    set old_coor  [::pwtk::pwi::getAtmPos $allow_path]
    
    if { [string match -nocase {*first_image*} [lindex $old_coor 0]] } {        
        # we have a path calculation, get rid of first_image line       
        set old_coor [join [lrange [split $old_coor \n] 1 end] \n]
    }
    
    set atmPos ""
    foreach old_line [split $old_coor \n] line [split $coorLines \n] {  
        if { [regexp intermediate_image $old_line] || [regexp last_image $old_line] } {
            # we have done it
            break
        }

        # keep only the AtmSym x y z fields from $coorLines
        set len [llength $line]
        if { $len != 4 && $len != 7 } {
            ::pwtk::error "wrong number of fields in coorLine, $len, must be 4 or 7"
        }
        set line [lrange $line 0 3]
        
        if { [llength $old_line] == 7 } {
            # if_pos(:) are present on the current old_line --> add
            # them to line          
            
            set line [concat $line [lrange $old_line 4 6]]
        }

        append atmPos "${line}\n"
    }
    
    # if atmPos is empty, just use the input $coorLines
    if { $atmPos == "" } {
        set atmPos $coorLines
    }

    return [::pwtk::purifyCoor $atmPos]
}