TABLE OF CONTENTS


::pwtk::pwi::coorToAtmPos

SYNOPSIS

proc ::pwtk::pwi::coorToAtmPos {coor} {

PURPOSE

Transform the supplied atomic coordinates (aka Coor) to AtmPos, that is, supplement the supplied 'coor' atomic coordinates (atmSymb x y z) with the if_pos(:) flags from the current pw.x input data.

ARGUMENTS

REMARK

This command keeps the pw.x input data intact.

RETURN VALUE

The "coor" transformed to "atmPos".

SOURCE

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

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

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

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