TABLE OF CONTENTS


::pwtk::xsf::getPrimCoor

SYNOPSIS

proc ::pwtk::xsf::getPrimCoor {xsfFile {image 1}} {

PURPOSE

Return the primitive atomic positions from XSF file (PRIMCOORD section), i.e.:

        AtmSymb1 x1 y1 z1  
        AtmSymb2 x2 y2 z2  
        ...

or

        AtmSymb1 x1 y1 z1  fx1 fy1 fz1
        AtmSymb2 x2 y2 z2  fx2 fy2 fz2
        ...

    Depending on whether forces are present or not.

ARGUMENTS

SOURCE

    #variable coor_unit

    ::pwtk::fileMustExist $xsfFile XSF
    
    set xsfList [split [::pwtk::skipEmptyLines [::pwtk::readFile $xsfFile]] \n]
    set indices [lsearch -all $xsfList *PRIMCOOR*]
    set nimages [llength $indices]
    
    if { $nimages < 1 } {
        ::pwtk::error "$xsfFile is not an XSF file" 1
    }
    
    if { $image < 1 || $image > $nimages } {
        ::pwtk::warning "image index $image, out of range. Must be within \[1,$nimages\]"
        if { $image < 1 } {
            set image 1
        } elseif { $image > $nimages } {
            set image $nimages
        }
    }

    set ind [lindex $indices $image-1]
    set nat [lindex [lindex $xsfList [expr {$ind + 1}]] 0]

    if { [string is integer $ind] && $ind > -1 } {
        set coor [join [lrange $xsfList [expr {$ind + 2}] [expr {$ind + $nat + 1}]] \n]
        
        foreach line [split $coor \n] {
            set atmSymb [string totitle [lindex $line 0]]
            set coor    [lrange $line 1 6]
            append new_coor "$atmSymb   $coor\n"
        }
        return $new_coor
    } else {
        ::pwtk::error "failed to extract image No.$image from the XSF file $xsfFile" 1
    }
    return ""
}