TABLE OF CONTENTS


::pwtk::pwi::ATOMIC_POSITIONS_fromXSF

SYNOPSIS

proc ::pwtk::pwi::ATOMIC_POSITIONS_fromXSF {args} {

USAGE

   ::pwtk::pwi::ATOMIC_POSITIONS_fromXSF ?options? xsfFile

OPTIONS

PURPOSE

Load coordinates from XSF file into ATOMIC_POSITIONS card. If the -ifpos options is specified, then the if_pos(:) fields from the current (old) ATOMIC_POSITIONS card will be loaded into new card.

Beware that "alat" in pw.x and XSF2 have slightly different meanings: "alat" in XSF is always the length of A-lattice vector, whereas in pw.x input this is not always the case. To prevent the usage of "alat" coordinates, specify -noalat option and the coordinates will be transformed to Angstrom or Bohr units, depending on the units in which the lattice vectors are specified in the XSF file.

ARGUMENTS

SOURCE

    set options {
        {alat   "do no tranform 'alat' coordinates to Angstroms"}
        {noalat "do not use coordinates in alat unit, tranform them to Angstrom or Bohr units"}
        {ifpos  "copy if_pos(:) fields from current (old) coordinates"}
        {image.arg 1  "which image to use from AXSF file"}
    }
    array set opt [::cmdline::getoptions args $options [list [lindex [info level 0] 0] options:]]

    if { $opt(alat) && $opt(noalat) } {
        pwtk::error "conflicting options -alat and -noalat specified, please use just one of them" 1
    }
    if { [llength $args] > 1 } {
        pwtk::error "wrong usage: should be ::pwtk::pwi::ATOMIC_POSITIONS_fromXSF ?options? xsfFile, but got:\n
::pwtk::pwi::ATOMIC_POSITIONS_fromXSF $args" 1
    }
    
    # parse XSF-file
    set xsfFile [lindex $args 0]
    ::pwtk::fileMustExist $xsfFile XSF
    set unit [::pwtk::xsf::getPrimCoorUnit $xsfFile]
    set coor [::pwtk::atmPosToCoor [::pwtk::purifyCoor [::pwtk::xsf::getPrimCoor $xsfFile $opt(image)]] ]

    # NOTE: -alat is default, hence query $opt(noalat) !
    
    if { $opt(noalat) && $unit == "alat" } {
        # The -noalat option was specified, hence "alat" coordinates
        # will be tranformed to Angstrom or Bohr units, depending on
        # the units in which the lattice vectors are specified in the
        # XSF file.
        #
        # RATIONALE: the unit for PRIMCOORD in XSF file can be only
        # angstrom, whereas XSF2 also supports bohr, crystal, and alat
        # units. However BEWARE that "alat" in XSF is always the
        # length of A-lattice vector, whereas in pw.x input this is
        # not always the case.        

        set unit [::pwtk::xsf::getPrimVecUnit $xsfFile]
        set vecs [::pwtk::purifyVec [::pwtk::xsf::getPrimVec $xsfFile]]

        ::pwtk::infoMsg "from ATOMIC_POSITIONS_fromXSF: in the \"$xsfFile\" file,
the coordinates are specified in alat units, converting them to $unit units"

        set xsf_alat [::pwtk::norm [lrange $vecs 0 2]]
        set coor     [::pwtk::scaleCoor $xsf_alat $coor]        
    }
    
    if { $opt(ifpos) == 1 } {   
        replaceCoor $coor $unit
    } else {
        ATOMIC_POSITIONS $unit $coor
    }

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