source: branches/sandbox/export_test.tcl @ 1117

Last change on this file since 1117 was 931, checked in by toby, 16 years ago

include rest of files

File size: 2.9 KB
Line 
1# a sample coordinate export utility for EXPGUI
2#
3# To make this file useful, one will need to modify the lines containing
4# "example" and then rewrite the "section that will need changing" below.
5# Finally save it as file named export_<something>.tcl
6#
7# set local variables that define the proc to execute and the menu label
8set label "export test format"
9set action export_example
10proc export_example {} {
11    global expmap expgui
12    # don't bother if there are no phases to write
13    if {[llength $expmap(phaselist)] == 0} {
14        MyMessageBox -parent . -title "No phases" \
15                -message "Sorry, no phases are present to write" \
16                -icon warning
17        return
18    }
19    MakeExportBox .export "Export coordinates in <example> format" \
20            "MakeWWWHelp expgui.html export"
21    # note, change export in the line above to the name anchor for a
22    # section documenenting the format added to expgui.html, if added
23    #
24    # force the window to stay on top
25    putontop .export
26    # Wait for the Write or Quit button to be pressed
27    tkwait window .export
28    afterputontop
29    # test for Quit
30    if {$expgui(export_phase) == 0} {return}
31
32    # now open the file and write it
33    set phase $expgui(export_phase)
34    if [catch {
35        set filnam [file rootname $expgui(expfile)]_${phase}.example
36        set fp [open $filnam w]
37        # deal with macromolecular phases
38        if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} {
39            set mm 1
40            set cmd mmatominfo
41        } else {
42            set mm 0
43            set cmd atominfo
44        }
45        #==============================================================
46        # v v v v v v v v v v Section that will need changing v v v v v
47        # title info from GSAS title & phase title
48        puts $fp "TITLE: [expinfo title]"
49        puts $fp "phase = [phaseinfo $phase name]"
50        # write out cell parameters
51        foreach p {a b c alpha beta gamma} {
52            puts $fp "$p = [phaseinfo $phase $p]"
53        }
54        # write out GSAS spacegroup
55        puts $fp "Space Group = [phaseinfo $phase spacegroup]"
56        # write a header
57        puts $fp "label \t type \t x       \t y      \t z        \t Uiso     \t frac"
58        # now loop over atoms
59        foreach atom $expmap(atomlist_$phase) {
60            set uiso [$cmd $phase $atom Uiso]
61            # are there anisotropic atoms? If so convert them to Uequiv
62            if {!$mm} {
63                if {[atominfo $phase $atom temptype] == "A"} {
64                    set uiso [expr \
65                            ([atominfo $phase $atom U11] + \
66                            [atominfo $phase $atom U22] + \
67                            [atominfo $phase $atom U33]) / 3.]
68                }
69            }
70            foreach var {x y z frac label type} {
71                set $var [$cmd $phase $atom $var]
72            }
73            #write out the atom, tab delimited
74            puts $fp "$label \t $type \t $x \t $y \t $z \t $uiso \t $frac"
75        }
76        # ^ ^ ^ ^ ^ ^ ^ end of Section that will need changing ^ ^ ^ ^
77        #==============================================================
78        close $fp
79    } errmsg] {
80        MyMessageBox -parent . -title "Export error" \
81                -message "Export error: $errmsg" -icon warning
82    } else {
83        MyMessageBox -parent . -title "Done" \
84                -message "File [file tail $filnam] was written"
85    }
86}
Note: See TracBrowser for help on using the repository browser.