source: trunk/export_xml.tcl @ 914

Last change on this file since 914 was 781, checked in by toby, 16 years ago

# on 2004/04/27 14:09:07, toby did:
remove unused proc
flag origin 2 space groups when in space group table

  • Property rcs:author set to toby
  • Property rcs:date set to 2004/04/27 14:09:07
  • Property rcs:lines set to +25 -41
  • Property rcs:rev set to 1.3
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 3.8 KB
Line 
1# $Id: export_xml.tcl 781 2009-12-04 23:11:55Z toby $
2# set local variables that define the proc to execute and the menu label
3set label "FOX .xml format"
4set action exp2xml
5# write coordinates in an XML for FOX
6proc exp2xml {} {
7    global expmap expgui
8    # don't bother if there are no phases to write
9    if {[llength $expmap(phaselist)] == 0} {
10        MyMessageBox -parent . -title "No phases" \
11                -message "Sorry, no phases are present to write" \
12                -icon warning
13        return
14    }
15    #------------------------------------------------------------------
16    if [catch {
17        set filnam [file rootname $expgui(expfile)].xml
18        set fp [open $filnam w]
19        puts $fp "<ObjCryst Date=\"[clock format [clock seconds] -format "%Y-%m-%dT%T"]\">"
20        foreach phase $expmap(phaselist) phasetype $expmap(phasetype) {
21            set name [file rootname $expgui(expfile)]_phase${phase}
22            set spacegroup [phaseinfo $phase spacegroup]
23            # remove final R from rhombohedral space groups
24            if {[string toupper [string range $spacegroup end end]] == "R"} {
25                set spacegroup [string range $spacegroup 0 \
26                        [expr [string length $spacegroup]-2]] 
27            }
28            # remove spaces from space group
29            regsub -all " " $spacegroup "" spacegroup
30            # scan through the Origin 1/2 spacegroups for a match
31            set origin2 0
32            set sp [string toupper $spacegroup]
33            # treat bar 3 as the same as 3 (Fd3m <==> Fd-3m)
34            regsub -- "-3" $sp "3" sp
35            set fp1 [open [file join $expgui(scriptdir) spacegrp.ref] r]
36            # skip over the first section of file
37            set line 0
38            while {[lindex $line 1] != 230} {
39                if {[gets $fp1 line] < 0} return
40            }
41            while {[gets $fp1 line] >= 0} {
42                set testsg [string toupper [lindex $line 8]]
43                regsub -all " " $testsg "" testsg
44                regsub -- "-3" $testsg "3" testsg
45                if {$sp == $testsg} {
46                    set origin2 1
47                    break
48                }
49            }
50            close $fp1
51            # GSAS always uses origin2 when there is a choice
52            if {$origin2} {set spacegroup ${spacegroup}:2}
53            puts $fp "  <Crystal Name=\"${name}\" SpaceGroup=\"${spacegroup}\">"
54            set min 1
55            set max 100
56            foreach var {a b c alpha beta gamma} {
57                if {$var == "alpha"} {
58                    set min 28.6479
59                    set max 171.887
60                }
61                set value [phaseinfo $phase $var]
62                puts $fp "<Par Refined=\"0\" Limited=\"1\" Min=\"${min}\" Max=\"${max}\" Name=\"${var}\">${value}</Par>"
63            }
64            puts $fp {<Option Name="Use Dynamical Occupancy Correction" Choice="1" ChoiceName="Yes"/>}
65           
66            if {$phasetype == 4} {
67                set cmd mmatominfo
68            } else {
69                set cmd atominfo
70            }
71            set scatblock {     
72    <ScatteringPowerAtom Name="${label}" Symbol="${elem}">
73            <Par Refined="0" Limited="1" Min="0.1" Max="5" Name="Biso">${Biso}</Par>
74            <RGBColour>$color</RGBColour>
75            </ScatteringPowerAtom>}
76
77            set i -1
78            foreach atom $expmap(atomlist_$phase) {
79                # cycle through colors for now
80                set color [lindex {"1 1 1" "1 0 0" "0 1 0" "0 0 1" "1 1 0" "0 1 1" "1 0 1"} [expr [incr i] % 7]]
81                set label [$cmd $phase $atom label]
82                set Biso [expr 8 * 3.14159 * 3.14159 * [$cmd $phase $atom Uiso]]
83                set elem [$cmd $phase $atom type]
84                puts $fp [subst $scatblock]
85            }
86            set scatblock {
87      <Atom Name="${label}" ScattPow="${label}">
88            <Par Refined="1" Limited="0" Min="0" Max="1" Name="x">${x}</Par>
89            <Par Refined="1" Limited="0" Min="0" Max="1" Name="y">${y}</Par>
90            <Par Refined="1" Limited="0" Min="0" Max="1" Name="z">${z}</Par>
91            <Par Refined="0" Limited="1" Min="0.01" Max="1" Name="Occup">${frac}</Par>
92            </Atom>}
93
94            foreach atom $expmap(atomlist_$phase) {
95                set label [$cmd $phase $atom label]
96                foreach var {x y z frac} {
97                    set $var  [$cmd $phase $atom $var]
98                }
99                puts $fp [subst $scatblock]
100            }
101            puts $fp {</Crystal>}
102        }
103        puts $fp {</ObjCryst>}
104        close $fp
105    } errmsg] {
106        MyMessageBox -parent . -title "Export error" \
107                -message "Export error: $errmsg" -icon warning
108    } else {
109        MyMessageBox -parent . -title "Done" \
110                -message "File [file tail $filnam] was written"
111    }
112}
113
Note: See TracBrowser for help on using the repository browser.