TABLE OF CONTENTS


::pwtk::pwi::ATOMIC_POSITIONS_fromCRD

SYNOPSIS

proc ::pwtk::pwi::ATOMIC_POSITIONS_fromCRD {crdFile imageIndex} {

USAGE

   ::pwtk::pwi::ATOMIC_POSITIONS_fromCRD crdFile imageIndex

PURPOSE

Load the coordinates of the specified image from the neb.x CRD file into the ATOMIC_POSITIONS card.

Irrespective of the 'imageIndex', the fix-atoms fields are always taken from the first image because only the first image contains them.

The index of the first image is 1.

ARGUMENTS

SOURCE

    ::pwtk::fileMustExist $crdFile "neb.x CRD"

    # read the *.crd file and transform lines into a list
    
    set crdL [split [string trim [::pwtk::readFile $crdFile]] \n]
    
    # get the number of images
    
    set nimages 0
    foreach line $crdL {
        if { [regexp _IMAGE $line] } { incr nimages }
    }
    if { $nimages == 0 } {
        # not a CRD file
        ::pwtk::error "no images find in the '$crdFile' file" 1
    }
    set imageIndex [::pwtk::parseIndex1 $imageIndex $nimages]

    # check image index
    
    if { $imageIndex < 1 } {
        ::pwtk::warning "using the first image because the specified 'imageindex' < 1"        
        set imageIndex 1
    } elseif { $imageIndex > $nimages } {
        ::pwtk::warning "using the last image because the specified 'imageindex' > number-of-images"
        set imageIndex $nimages
    }

    # read images
    
    set ii 0
    set iat 0
    set nat 0
    set lpos 0
    foreach line $crdL {        
        if { [regexp _IMAGE $line] } {
            incr ii
            set lpos 0
        } elseif { [regexp ATOMIC_POSITIONS $line] } {
            set unit($ii) [lindex $line 1]
            set lpos 1
            set iat  0
        } elseif { [regexp TOTAL_CHARGE $line] } {
            set lpos 0
        } elseif { $lpos } {
            # read the atomic positions
            incr iat
            if { $iat > $nat } { set nat $iat }
            lassign $line symb($ii,$iat) x($ii,$iat) y($ii,$iat) z($ii,$iat) ifx($ii,$iat) ify($ii,$iat) ifz($ii,$iat)
        }
    }

    # construct atomic positions and load them into ATOMIC_POSITIONS card

    set pos {}
    set ii $imageIndex
    for {set iat 1} {$iat <= $nat} {incr iat} {
        if { [info exists x($ii,$iat)] && [info exists x(1,$iat)] } {
            append pos [format $::pwtk::fmt_atmPos(7) \
                            $symb($ii,$iat) $x($ii,$iat) $y($ii,$iat) $z($ii,$iat) \
                            $ifx(1,$iat) $ify(1,$iat) $ifz(1,$iat)]
        } else {
            ::pwtk::warning "the CRD file '$crdFile' is inconsistent: number of atoms do not match between the images"
        }
    }    
    ATOMIC_POSITIONS $unit($imageIndex) $pos

    # update the "nat" variable
    ::pwtk::pwi::setNAtoms
}