source: trunk/export_spf.tcl @ 686

Last change on this file since 686 was 603, checked in by toby, 16 years ago

# on 2002/07/03 21:00:19, toby did:
place only 1 TITL line in file (as requested by Lachlan)

  • Property rcs:author set to toby
  • Property rcs:date set to 2002/07/03 21:00:19
  • Property rcs:lines set to +4 -5
  • Property rcs:rev set to 1.2
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 3.1 KB
Line 
1# write coordinates for PLATON --  STANDARD PARAMETER FILE (.SPF) Format
2## $Id: export_spf.tcl 603 2009-12-04 23:08:56Z toby $
3set label "export SPF (PLATON) format"
4set action export_SPF
5proc export_SPF {} {
6    global expmap expgui
7    # don't bother if there are no phases to write
8    if {[llength $expmap(phaselist)] == 0} {
9        MyMessageBox -parent . -title "No phases" \
10                -message "Sorry, no phases are present to write" \
11                -icon warning
12        return
13    }
14    MakeExportBox .export "Export coordinates in SPF (PLATON) format" \
15            "MakeWWWHelp expgui.html ExportSPF"
16    # note, change export in the line above to the name anchor for a
17    # section documenenting the format added to expgui.html, if added
18    #
19    # force the window to stay on top
20    putontop .export
21    # Wait for the Write or Quit button to be pressed
22    tkwait window .export
23    afterputontop
24    # test for Quit
25    if {$expgui(export_phase) == 0} {return}
26
27    # now open the file and write it
28    set phase $expgui(export_phase)
29    if [catch {
30        set filnam [file rootname $expgui(expfile)]_${phase}.spf
31        set fp [open $filnam w]
32        # deal with macromolecular phases
33        if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} {
34            set mm 1
35            set cmd mmatominfo
36        } else {
37            set mm 0
38            set cmd atominfo
39        }
40        #==============================================================
41        # title info from GSAS title & phase title
42        puts $fp "TITL   Phase $phase from $expgui(expfile) named [string trim [phaseinfo $phase name]]"
43        #puts $fp "TITL   history [string trim [lindex [exphistory last] 1]]"
44        #puts $fp "TITL   [expinfo title]"
45        # write out cell parameters
46        set cell {}
47        foreach p {a b c alpha beta gamma} {
48            append cell " [phaseinfo $phase $p]"
49        }
50        puts $fp "CELL $cell"
51        # process & writeout the spacegroup
52        set spacegroup [phaseinfo $phase spacegroup]
53        # remove final R from rhombohedral space groups
54        if {[string toupper [string range $spacegroup end end]] == "R"} {
55            set spacegroup [string range $spacegroup 0 \
56                    [expr [string length $spacegroup]-2]] 
57        }
58        # remove spaces from space group
59        regsub -all " " $spacegroup "" spacegroup
60        puts $fp "SPGR $spacegroup"
61        # now loop over atoms
62        foreach atom $expmap(atomlist_$phase) {
63            foreach var {x y z frac label type} {
64                set $var [$cmd $phase $atom $var]
65            }
66            if {[catch {incr count($type)}]} {set count($type) 1}
67            # create a label, since the GSAS label may not work for platon
68            set lbl [string range $type 0 1]
69            append lbl ($count($type))
70            #write out the atom, tab delimited
71            puts $fp "ATOM  $lbl   $x $y $z $frac"
72            # is this atom anisotropic?
73            if {!$mm && [atominfo $phase $atom temptype] == "A"} {
74                set ulist {}
75                foreach u {U11 U22 U33 U23 U13 U12} {
76                    lappend ulist [atominfo $phase $atom $u]
77                }
78                puts $fp "UIJ   $lbl   $ulist"
79            } else {
80                puts $fp "U     $lbl   [$cmd $phase $atom Uiso]"
81            }
82        }
83        #==============================================================
84        close $fp
85    } errmsg] {
86        MyMessageBox -parent . -title "Export error" \
87                -message "Export error: $errmsg" -icon warning
88    } else {
89        MyMessageBox -parent . -title "Done" \
90                -message "File [file tail $filnam] was written"
91    }
92}
Note: See TracBrowser for help on using the repository browser.