source: trunk/import_cell.tcl @ 263

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

# on 2000/08/14 21:09:21, toby did:
Routine to read PowderCell? coordinate files

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