source: trunk/import_cell.tcl @ 309

Last change on this file since 309 was 266, checked in by toby, 14 years ago

# on 2000/08/17 23:46:23, toby did:
perform origin shifts for Origin 1 settings

  • Property rcs:author set to toby
  • Property rcs:date set to 2000/08/17 23:46:23
  • Property rcs:lines set to +24 -14
  • Property rcs:rev set to 1.2
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 2.6 KB
Line 
1# $Id: import_cell.tcl 266 2009-12-04 23:03:11Z toby $
2
3#-------------------------------------------------
4# define info used in addcmds.tcl
5set description "PowderCell .CEL file"
6set extensions .cel
7set procname ReadPowderCellFile
8#-------------------------------------------------
9
10proc ReadPowderCellFile {filename} {
11    set fp [open $filename r]
12    set cell {}
13    set atomlist {}
14    set spg {}
15    set shift {}
16    set sgnum {}
17    set setting {}
18    set warnlist {
19        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
20        37 42 43 44 45 47 48 49 50 55 56 58 59 65 66 68 69 70 71 72
21    }
22
23    while {[gets $fp line] >= 0} {
24        set token [lindex $line 0] 
25        switch [string toupper $token] {
26            CELL {
27                set cell [lrange $line 1 end]
28            }
29            RGNR {
30                set sgnum [lindex $line 1]
31                set setting [lindex $line 2]
32                if {$setting == ""} {set setting 1}
33                close $fp
34                global expgui
35                set fp [open [file join $expgui(scriptdir) spacegrp.ref] r]
36                while {[gets $fp line] >= 0} {
37                    if {$sgnum == [lindex $line 1] && \
38                            $setting == [lindex $line 2]} {
39                        set spg [lindex $line 8]
40                        set shift [lindex $line 9]
41                        close $fp
42                        break
43                    }
44                }
45                break
46            }
47            default {
48                set lbl [lindex $line 0]
49                set type [lindex $line 1]
50                # if the type is a number, convert it to an element symbol
51                catch {set type [lindex {
52                    dummy-entry
53                    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
54                    NI CU ZN GA GE AS SE BR KR RB SR Y ZR NB MO TC RU RH PD AG CD IN SN SB
55                    TE I XE CS BA LA CE PR ND PM SM EU GD TB DY HO ER TM YB LU HF TA W RE
56                    OS IR PT AU HG TL PB BI PO AT RN FR RA AC TH PA U NP PU AM CM BK CF
57                } $type]}
58                # convert  F-, K+ and  Al3+ to F, K and Al
59                regsub {[1-9]*\+} $type {} type   
60                regsub {[1-9]*-} $type {} type   
61                lappend typelist $type
62                lappend lbllist $lbl
63                lappend xyzlist [lrange $line 2 4]
64            }
65        }
66    }
67    # create the atomlist
68    foreach type $typelist lbl $lbllist xyz $xyzlist {
69        if {$shift == ""} {
70            set l "$lbl $xyz $type"
71        } else {
72            set l $lbl
73            foreach x $xyz offset $shift {
74                lappend l [expr $x + $offset]
75            }
76            lappend l $type
77        }
78        lappend atomlist $l
79    }
80    # exact spacegroup was not found
81    if {$spg == ""} {
82        # how did this happen
83        MyMessageBox -parent . -type ok -icon error \
84                -message "Error: The space group number ($sgnum) and setting ($setting) in file $filename is invalid!"
85    } elseif {$shift != ""} {
86        # don't have the correct setting
87        MyMessageBox -parent . -type ok -icon warning \
88                -message "Note: an origin shift ($shift) has been added to the coordinates to convert them to the Origin Choice 2 setting (-1 at 000)"
89    }
90    return "[list $spg] [list $cell] [list $atomlist]"
91}
Note: See TracBrowser for help on using the repository browser.