source: trunk/export_spf.tcl @ 529

Last change on this file since 529 was 529, checked in by toby, 11 years ago

# on 2002/01/22 21:45:59, toby did:
export coordinates in PLATON "Simple Parameter File" format

  • Property rcs:author set to toby
  • Property rcs:date set to 2002/01/22 21:45:59
  • Property rcs:rev set to 1.1
  • 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 529 2009-12-04 23:07:42Z 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)"
43        puts $fp "TITL   history [string trim [lindex [exphistory last] 1]]"
44        puts $fp "TITL   phase title [phaseinfo $phase name]"
45        puts $fp "TITL   [expinfo title]"
46        # write out cell parameters
47        set cell {}
48        foreach p {a b c alpha beta gamma} {
49            append cell " [phaseinfo $phase $p]"
50        }
51        puts $fp "CELL $cell"
52        # process & writeout the spacegroup
53        set spacegroup [phaseinfo $phase spacegroup]
54        # remove final R from rhombohedral space groups
55        if {[string toupper [string range $spacegroup end end]] == "R"} {
56            set spacegroup [string range $spacegroup 0 \
57                    [expr [string length $spacegroup]-2]] 
58        }
59        # remove spaces from space group
60        regsub -all " " $spacegroup "" spacegroup
61        puts $fp "SPGR $spacegroup"
62        # now loop over atoms
63        foreach atom $expmap(atomlist_$phase) {
64            foreach var {x y z frac label type} {
65                set $var [$cmd $phase $atom $var]
66            }
67            if {[catch {incr count($type)}]} {set count($type) 1}
68            # create a label, since the GSAS label may not work for platon
69            set lbl [string range $type 0 1]
70            append lbl ($count($type))
71            #write out the atom, tab delimited
72            puts $fp "ATOM  $lbl   $x $y $z $frac"
73            # is this atom anisotropic?
74            if {!$mm && [atominfo $phase $atom temptype] == "A"} {
75                set ulist {}
76                foreach u {U11 U22 U33 U23 U13 U12} {
77                    lappend ulist [atominfo $phase $atom $u]
78                }
79                puts $fp "UIJ   $lbl   $ulist"
80            } else {
81                puts $fp "U     $lbl   [$cmd $phase $atom Uiso]"
82            }
83        }
84        #==============================================================
85        close $fp
86    } errmsg] {
87        MyMessageBox -parent . -title "Export error" \
88                -message "Export error: $errmsg" -icon warning
89    } else {
90        MyMessageBox -parent . -title "Done" \
91                -message "File [file tail $filnam] was written"
92    }
93}
Note: See TracBrowser for help on using the repository browser.