Changeset 536 for trunk/addcmds.tcl


Ignore:
Timestamp:
Dec 4, 2009 5:07:49 PM (11 years ago)
Author:
toby
Message:

# on 2002/01/22 22:10:48, toby did:
support changes MM phases (where appropriate)
create a atom type validation routine ValidateAtomsBox? & remove from

addatoms and replacephase2

call UpdateAtomLine? to refresh display of selected atoms
fix minor bug, if a phase is replaced & the number of

atoms remains unchanged

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/addcmds.tcl

    • Property rcs:date changed from 2001/12/16 18:08:28 to 2002/01/22 22:10:48
    • Property rcs:lines changed from +2 -2 to +82 -99
    • Property rcs:rev changed from 1.26 to 1.27
    r493 r536  
    11171117}
    11181118
    1119 proc addatom {phase top} {
    1120     global expgui env expmap
    1121     set np $top.canvas.fr
     1119# Validate the atoms in the atoms add/phase replace box
     1120# returns a null string on error or a list of atoms
     1121proc ValidateAtomsBox {np} {
    11221122    set row 0
    11231123    # loop over the defined rows
     
    11491149        BK_247 CF CF_249
    11501150    }
     1151    # loop over the defined rows
    11511152    while {![catch {grid info $np.e[incr row]t}]} {
    11521153        if !{$expgui(UseAtom$row)} continue
     
    11571158        }
    11581159        if {$line == ""} continue
     1160
    11591161        # validate the input
    11601162        if {[set type [string trim [$np.e${row}t get]]] == ""} {
     
    11751177        }
    11761178        lappend atomlist "$type $x $y $z $o $name I $u"
    1177     }   
     1179    }
    11781180    if {$err != ""} {
    11791181        MyMessageBox -icon warning -message "Note Errors:\n$err" -parent $top
    1180         return
     1182        return {}
    11811183    }
    11821184    if {[llength $atomlist] == 0} {
    11831185        MyMessageBox -icon warning -message "No atoms to load!" -parent $top
    1184         return
    1185     }
     1186        return {}
     1187    }
     1188    return $atomlist
     1189}
     1190
     1191proc addatom {phase top} {
     1192    global expgui env expmap
     1193    set np $top.canvas.fr
     1194    # validate the atoms info
     1195    set atomlist [ValidateAtomsBox $top $np]
     1196    if {$atomslist == ""} return
     1197
    11861198    # ok add the atoms!
    11871199    set fp [open exptool.in w]
     
    13201332            -row 6 -column 0 -columnspan 10 -sticky news
    13211333    set w2 [$w.6 getframe]
    1322     grid [label $w2.1 -text "Uiso or Uequiv: "] -row 1 -column 0
    13231334    grid [entry $w2.e -width 10] -column 1 -row 1
    13241335    $w2.e delete 0 end
     
    13291340            ] -row 2 -column 0 -columnspan 10
    13301341    grid [frame $w2.f] -row 3 -column 0 -columnspan 10
    1331     grid [button $w2.f.iso -text "Set Isotropic" \
    1332             -command "XformAtomsU $phase [list $numberList] iso" \
    1333             ] -row 0 -column 0
    1334     grid [button $w2.f.aniso -text "Set Anisotropic" \
    1335             -command "XformAtomsU $phase [list $numberList] aniso" \
    1336             ] -row 0 -column 1
     1342
     1343    if {[lindex $expmap(phasetype) [expr {$p - 1}]] != 4} {
     1344        grid [label $w2.1 -text "Uiso or Uequiv: "] -row 1 -column 0
     1345        grid [button $w2.f.iso -text "Set Isotropic" \
     1346                -command "XformAtomsU $phase [list $numberList] iso" \
     1347                ] -row 0 -column 0
     1348        grid [button $w2.f.aniso -text "Set Anisotropic" \
     1349                -command "XformAtomsU $phase [list $numberList] aniso" \
     1350                ] -row 0 -column 1
     1351    } else {
     1352        grid [label $w2.1 -text "Uiso: "] -row 1 -column 0
     1353    }
    13371354
    13381355    grid rowconfigure $w 5 -minsize 5
    1339     grid [TitleFrame $w.8 -bd 6 -relief groove \
    1340             -text "Erase Atom$suffix"] \
    1341             -row 8 -column 0 -columnspan 10 -sticky news
    1342     set w2 [$w.8 getframe]
    1343     grid [button $w2.do -text "Erase Atom${suffix}" \
    1344             -command "EraseAtoms $phase [list $numberList] $w" \
    1345             ] -row 2 -column 0 -columnspan 10
    1346 
     1356    if {[lindex $expmap(phasetype) [expr {$p - 1}]] != 4} {
     1357        grid [TitleFrame $w.8 -bd 6 -relief groove \
     1358                -text "Erase Atom$suffix"] \
     1359                -row 8 -column 0 -columnspan 10 -sticky news
     1360        set w2 [$w.8 getframe]
     1361        grid [button $w2.do -text "Erase Atom${suffix}" \
     1362                -command "EraseAtoms $phase [list $numberList] $w" \
     1363                ] -row 2 -column 0 -columnspan 10
     1364    }
    13471365
    13481366    grid rowconfigure $w 9 -minsize 5
     
    13661384# transform the coordinates
    13671385proc XformAtomsCoord {phase numberList w1} {
    1368     global expgui
     1386    global expgui expmap
     1387    if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} {
     1388        set cmd mmatominfo
     1389    } else {
     1390        set cmd atominfo
     1391    }
    13691392    # get the matrix
    13701393    foreach v {x y z} {
     
    13761399    foreach atom $numberList {
    13771400        foreach v {x y z} {
    1378             set $v [atominfo $phase $atom $v]
     1401            set $v [$cmd $phase $atom $v]
    13791402        }
    13801403        foreach v {x y z} {
     
    13831406                set new$v [expr [set new$v] + $matrix(${v}${o})*[set $o]]
    13841407            }
    1385             atominfo $phase $atom $v set [set new$v]
     1408            $cmd $phase $atom $v set [set new$v]
    13861409        }
    13871410        incr expgui(changed)
    13881411    }
    1389     DisplayAllAtoms noreset
     1412    UpdateAtomLine $numberList $phase
    13901413}
    13911414
    13921415# set the occupancies to a single value
    13931416proc XformAtomsOcc {phase numberList w2} {
    1394     global expgui
     1417    global expgui expmap
     1418    if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} {
     1419        set cmd mmatominfo
     1420    } else {
     1421        set cmd atominfo
     1422    }
    13951423    # get the value
    13961424    set val [$w2.e get]
    13971425    foreach atom $numberList {
    1398         atominfo $phase $atom frac set $val
     1426        $cmd $phase $atom frac set $val
    13991427        incr expgui(changed)
    14001428    }
    1401     DisplayAllAtoms noreset
     1429    UpdateAtomLine $numberList $phase
    14021430}
    14031431
     
    14231451        set val [$w2.e get]
    14241452        foreach atom $numberList {
    1425             if {[atominfo $phase $atom temptype] == "I"} {
     1453            global expmap
     1454            if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} {
     1455                mmatominfo $phase $atom Uiso set $val
     1456            } elseif {[atominfo $phase $atom temptype] == "I"} {
    14261457                atominfo $phase $atom Uiso set $val
    14271458            } else {
     
    14361467        }
    14371468    }
    1438     DisplayAllAtoms noreset
     1469    UpdateAtomLine $numberList $phase
    14391470}
    14401471
     
    14561487        }
    14571488        mapexp
    1458         DisplayAllAtoms
     1489        DisplayAllAtoms $phase
    14591490        destroy $w2
    14601491    }
     
    15031534    set file [tk_getOpenFile -parent $top -filetypes $typelist]
    15041535    if {![file exists $file]} return
     1536    # disable during read
     1537    catch {
     1538        foreach b "$top.b1 $top.b2 $top.fr.b3" {
     1539            $b config -state disabled
     1540        }
     1541    }
    15051542    # read in the file
    15061543    set input [$expgui(proc_$format) $file]
     
    15181555    # sort the atoms by number, so that empty entries are at the bottom
    15191556    sortAddAtoms $phase $top number
     1557    # reenable
     1558    catch {
     1559        foreach b "$top.b1 $top.b2 $top.fr.b3" {
     1560            $b config -state normal
     1561        }
     1562    }
    15201563}
    15211564
     
    18141857    # validate coordinates
    18151858    set np $top.canvas.fr
    1816     set row 0
    1817     # loop over the defined rows
    1818     set err {}
    1819     set atomlist {}
    1820     set validatmtypes {
    1821         H H-1 H_1 H_2 H_3 HE HE_3 HE_4 LI LI+1 LI_6 LI_7 BE BE+2 B B_10
    1822         B_11 C CV C_12 C_13 N N_14 N_15 O O-1 O_16 O_17 O_18 F F-1 F_19 NE
    1823         NE_20 NE_21 NE_22 NA NA+1 NA_23 MG MG+2 MG_24 MG_25 MG_26 AL AL+3
    1824         AL_27 SI SI+4 SIV SI_28 SI_29 SI_30 P P_31 S S_32 S_33 S_34 CL CL-1
    1825         CL_35 CL_37 AR AR_36 AR_40 K K+1 K_39 K_41 CA CA+2 CA_40 CA_44 SC SC+3
    1826         SC_45 TI TI+2 TI+3 TI+4 TI_46 TI_47 TI_48 TI_49 TI_50 V V+2 V+3 V+5
    1827         V_51 CR CR+2 CR+3 CR_50 CR_52 CR_53 CR_54 MN MN+2 MN+3 MN+4 MN_55 FE
    1828         FE+2 FE+3 FE_54 FE_56 FE_57 FE_58 CO CO+2 CO+3 CO_59 NI NI+2 NI+3
    1829         NI_58 NI_60 NI_61 NI_62 NI_64 CU CU+1 CU+2 CU_63 CU_65 ZN ZN+2 ZN_64
    1830         ZN_66 ZN_67 ZN_68 GA GA+3 GE GE+4 AS AS_75 SE BR BR-1 BR_79 BR_81 KR
    1831         RB RB+1 SR SR+2 Y Y+3 Y_89 ZR ZR+4 NB NB+3 NB+5 NB_93 MO MO+3 MO+5
    1832         MO+6 TC TC_98 RU RU+3 RU+4 RH RH+3 RH+4 RH_103 PD PD+2 PD+4 AG AG+1
    1833         AG+2 CD CD+2 CD_112 CD_113 CD_114 CD_116 IN IN+3 IN_113 IN_115 SN SN+2
    1834         SN+4 SB SB+3 SB+5 TE I I-1 I_127 XE CS CS+1 CS_133 BA BA+2 LA LA+3 CE
    1835         CE+3 CE+4 PR PR+3 PR+4 PR_141 ND ND+3 PM PM+3 PM_147 SM SM+3 SM_152
    1836         SM_154 EU EU+2 EU+3 EU_153 GD GD+3 GD_160 TB TB+3 TB_159 DY DY+3 HO
    1837         HO+3 HO_165 ER ER+3 TM TM+3 TM_169 YB YB+2 YB+3 LU LU+3 HF HF+4 TA
    1838         TA+5 TA_181 W W+6 RE OS OS+4 IR IR+3 IR+4 PT PT+2 PT+4 AU AU+1 AU+3
    1839         AU_197 HG HG+1 HG+2 TL TL+1 TL+3 PB PB+2 PB+4 BI BI+3 BI+5 BI_209 PO
    1840         PO_210 AT AT_210 RN RN_222 FR FR_223 RA RA+2 RA_226 AC AC+3 AC_227 TH
    1841         TH+4 TH_232 PA PA_231 U U+3 U+4 U+6 U_235 U_238 NP NP+3 NP+4 NP+6
    1842         NP_237 PU PU+3 PU+4 PU+6 PU_239 PU_240 PU_242 AM AM_243 CM CM_244 BK
    1843         BK_247 CF CF_249
    1844     }
    1845     while {![catch {grid info $np.e[incr row]t}]} {
    1846         if !{$expgui(UseAtom$row)} continue
    1847         # ignore blank entries
    1848         set line {}
    1849         foreach i {t x y z} {
    1850             append line [string trim [$np.e${row}$i get]]
    1851         }
    1852         if {$line == ""} continue
    1853         # validate the input
    1854         if {[set type [string trim [$np.e${row}t get]]] == ""} {
    1855             append err "  line $row: No atom type specified\n"
    1856         }
    1857         if {[lsearch $validatmtypes [string toupper $type]] == -1} {
    1858             append err "  line $row: Atom type $type is invalid for GSAS\n"
    1859         }
    1860         set name [string trim [$np.e${row}n get]]
    1861         if {$name == "(default)"} {set name "/"}
    1862         if {$name == ""} {set name "/"}
    1863         foreach i {x y z o u} n {x y z Occ Uiso} {
    1864             if {[set $i [string trim [$np.e${row}$i get]]] == ""} {
    1865                 append err "  line $row: No value specified for $n\n"
    1866             } elseif {[catch {expr [set $i]}]} {
    1867                 append err "  line $row: The value for $n is invalid\n"
    1868             }
    1869         }
    1870         lappend atomlist "$type $x $y $z $o $name I $u"
    1871     }   
    1872     if {$err != ""} {
    1873         MyMessageBox -icon warning -message "Note Errors:\n$err" -parent $top
    1874         return
    1875     }
    1876     if {[llength $atomlist] == 0} {
    1877         MyMessageBox -icon warning -message "No atoms to load!" -parent $top
    1878         return
    1879     }
     1859    # validate the atoms info
     1860    set atomlist [ValidateAtomsBox $top $np]
     1861    if {$atomslist == ""} return
    18801862
    18811863    pleasewait "updating phase"
     
    18851867        phaseinfo $phase $var set $val
    18861868    }
     1869    incr expgui(changed)
    18871870    # delete all atoms
    18881871    foreach i $expmap(atomlist_$phase) {
    18891872        EraseAtom $i $phase
    1890     }
    1891     incr expgui(changed) 8
     1873        incr expgui(changed)
     1874    }
    18921875    # write new atoms from table as input to exptool
    18931876    set fp [open exptool.in w]
     
    18981881    foreach atomline $atomlist {
    18991882        puts $fp $atomline
     1883        incr expgui(changed)
    19001884    }
    19011885    close $fp
     
    19221906    } errmsg
    19231907    # load the revised exp file
    1924     set oldatomlist $expmap(atomlist_$phase)
    19251908    loadexp $expgui(expfile)
    19261909    set fp [open exptool.out r]
     
    19281911    close $fp
    19291912    set err 0
    1930     if {[llength $oldatomlist] == [llength $expmap(atomlist_$phase))]} {
     1913    if {[llength $atomlist] != [llength $expmap(atomlist_$phase))]} {
    19311914        set err 1
    19321915    }
Note: See TracChangeset for help on using the changeset viewer.