# $Id: import_cell.tcl 930 2009-12-04 23:14:35Z toby $ #------------------------------------------------- # define info used in addcmds.tcl set description "PowderCell .CEL file" set extensions .cel set procname ReadPowderCellFile #------------------------------------------------- proc ReadPowderCellFile {filename} { set fp [open $filename r] set cell {} set atomlist {} set spg {} set shift {} set sgnum {} set setting {} set warnlist { 3 4 5 6 7 8 10 11 12 13 14 16 17 18 19 20 21 22 23 24 25 27 32 34 35 37 42 43 44 45 47 48 49 50 55 56 58 59 65 66 68 69 70 71 72 } while {[gets $fp line] >= 0} { set token [lindex $line 0] switch [string toupper $token] { CELL { set cell [lrange $line 1 end] } RGNR { set sgnum [lindex $line 1] set setting [lindex $line 2] if {$setting == ""} {set setting 1} # note that RGNR comes at the end of the file; ignore # anything beyond here close $fp global expgui set fp [open [file join $expgui(scriptdir) spacegrp.ref] r] while {[gets $fp line] >= 0} { if {$sgnum == [lindex $line 1] && \ $setting == [lindex $line 2]} { set spg [lindex $line 8] set shift [lindex $line 9] break } } close $fp break } default { set lbl [lindex $line 0] set type [lindex $line 1] # if the type is a number, convert it to an element symbol catch {set type [lindex { dummy-entry H HE LI BE B C N O F NE NA MG AL SI P S CL AR K CA SC TI V CR MN FE CO NI CU ZN GA GE AS SE BR KR RB SR Y ZR NB MO TC RU RH PD AG CD IN SN SB TE I XE CS BA LA CE PR ND PM SM EU GD TB DY HO ER TM YB LU HF TA W RE OS IR PT AU HG TL PB BI PO AT RN FR RA AC TH PA U NP PU AM CM BK CF } $type]} # convert F-, K+ and Al3+ to F, K and Al regsub {[1-9]*\+} $type {} type regsub {[1-9]*-} $type {} type lappend typelist $type lappend lbllist $lbl lappend xyzlist [lrange $line 2 4] } } } # create the atomlist foreach type $typelist lbl $lbllist xyz $xyzlist { if {$shift == ""} { set l "$lbl $xyz $type" } else { set l $lbl foreach x $xyz offset $shift { lappend l [expr $x + $offset] } lappend l $type } lappend atomlist $l } # exact spacegroup was not found if {$spg == ""} { # how did this happen MyMessageBox -parent . -type ok -icon error \ -message "Error: The space group number ($sgnum) and setting ($setting) in file $filename is invalid!" } elseif {$shift != ""} { # don't have the correct setting MyMessageBox -parent . -type ok -icon warning \ -message "Note: an origin shift ($shift) has been added to the coordinates to convert them to the Origin Choice 2 setting (-1 at 000)" } return "[list $spg] [list $cell] [list $atomlist]" }