Changeset 1795 for branches


Ignore:
Timestamp:
Jul 8, 2010 2:09:35 PM (14 years ago)
Author:
gah
Message:
 
Location:
branches/blt4/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/analyzer.tcl

    r1710 r1795  
    7171    protected method _simOutput {message}
    7272    protected method _resultTooltip {}
     73    protected method _isPdbTrajectory {data}
     74    protected method _isLammpsTrajectory {data}
     75    protected method _pdbToSequence {xmlobj path id child data}
     76    protected method _lammpsToSequence {xmlobj path id child data}
     77    protected method _trajToSequence {xmlobj {path ""}}
    7378
    7479    private variable _tool ""          ;# belongs to this tool
     
    523528
    524529    lappend _runs $xmlobj
     530
     531    # detect molecule elements that contain trajectory data and convert
     532    # to sequences.
     533    _trajToSequence $xmlobj output
    525534
    526535    # go through the analysis and find all result sets
     
    11321141itcl::body Rappture::Analyzer::_fixNotebook {} {
    11331142    switch -- $itk_option(-notebookpage) {
    1134         about {
    1135             $itk_component(notebook) current about
    1136         }
    1137         simulate {
    1138             $itk_component(notebook) current simulate
    1139         }
    1140         analyze {
    1141             $itk_component(notebook) current analyze
    1142         }
    1143         default {
    1144             error "bad value \"$itk_option(-notebookpage)\": should be about, simulate, analyze"
    1145         }
     1143        about {
     1144            $itk_component(notebook) current about
     1145        }
     1146        simulate {
     1147            $itk_component(notebook) current simulate
     1148        }
     1149        analyze {
     1150            $itk_component(notebook) current analyze
     1151        }
     1152        default {
     1153            error "bad value \"$itk_option(-notebookpage)\": should be about, simulate, analyze"
     1154        }
     1155    }
     1156}
     1157
     1158# ----------------------------------------------------------------------
     1159# USAGE: _isPdbTrajectory <data>
     1160#
     1161# Used internally to determine whether pdb or lammps data represents a
     1162# trajectory rather than a single frame
     1163# ----------------------------------------------------------------------
     1164itcl::body Rappture::Analyzer::_isPdbTrajectory {data} {
     1165    if { [llength $data]  == 0 } {
     1166        return 0
     1167    }
     1168    set nModels 0
     1169    foreach line $data {
     1170        if { [string match "MODEL*" $line] }  {
     1171            incr nModels
     1172            if { $nModels > 1 } {
     1173                # Stop if more than one model found.  No need to count them
     1174                # all.
     1175                return 1
     1176            }
     1177        }
     1178    }
     1179    return 0
     1180}
     1181
     1182# ----------------------------------------------------------------------
     1183# USAGE: _isLammpsTrajectory <data>
     1184#
     1185# Used internally to determine whether pdb or lammps data represents a
     1186# trajectory rather than a single frame
     1187# ----------------------------------------------------------------------
     1188itcl::body Rappture::Analyzer::_isLammpsTrajectory { data } {
     1189    if { [llength $data]  == 0 } {
     1190        return 0
     1191    }
     1192    set nModels 0
     1193    foreach line $data {
     1194        if { [regexp {^[\t ]*ITEM:[ \t]+TIMESTEP} $line] } {
     1195            incr nModels
     1196            if { $nModels > 1 } {
     1197                # Stop if more than one model found.  No need to count them
     1198                # all.
     1199                return 1
     1200            }
     1201        }
     1202    }
     1203    return 0
     1204}
     1205
     1206# ----------------------------------------------------------------------
     1207# USAGE: _trajtosequence <xmlobj> ?<path>?
     1208#
     1209    # If the molecule element is a trajectory, delete the original
     1210    # and create a sequence of individual molecules.
     1211# Used internally to detect any molecule output elements that contain
     1212# trajectory data.  Trajectories will be converted into sequences of
     1213# individual molecules.  All other elements will be unaffected. Scans
     1214# the entire xml tree if a starting path is not specified.
     1215# ----------------------------------------------------------------------
     1216itcl::body Rappture::Analyzer::_pdbToSequence {xmlobj path id child data} {
     1217
     1218    set seqLabel [$xmlobj get ${child}.about.label]
     1219    set descr    [$xmlobj get ${child}.about.description]
     1220    set formula  [$xmlobj get ${child}.components.molecule.formula]
     1221    $xmlobj remove $child
     1222
     1223    set seqPath  $path.sequence($id)
     1224    $xmlobj put ${seqPath}.about.label $seqLabel
     1225    $xmlobj put ${seqPath}.about.description $descr
     1226    $xmlobj put ${seqPath}.index.label "Frame"
     1227
     1228    set frameNum 0
     1229    set frameContents ""
     1230    set inModel 0
     1231    foreach line $data {
     1232        set line [string trim $line]
     1233        if { $line == "" } {
     1234            continue;                   # Skip blank lines
     1235        }
     1236        if { [string match "MODEL*" $line] } {
     1237            if { $inModel && $frameContents != "" } {
     1238                # Dump the current contents into the last model
     1239
     1240                set framePath ${seqPath}.element($frameNum)
     1241                $xmlobj put ${framePath}.index $frameNum
     1242               
     1243                set molPath ${framePath}.structure.components.molecule
     1244                $xmlobj put ${molPath}.pdb $frameContents
     1245                $xmlobj put ${molPath}.formula $formula
     1246               
     1247                incr frameNum
     1248                set frameContents ""
     1249            }
     1250            set inModel 1
     1251        } elseif {[string match "ATOM*" $line] } {
     1252            if { !$inModel } {
     1253                puts stderr "found \"$line\" without previous MODEL line"
     1254                set inModel 1
     1255            }
     1256            append frameContents $line\n
     1257        }
     1258    }
     1259    if { $frameContents != "" } {
     1260        # Dump the current contents into the last model
     1261
     1262        set framePath ${seqPath}.element($frameNum)
     1263        $xmlobj put ${framePath}.index $frameNum
     1264       
     1265        set molPath ${framePath}.structure.components.molecule
     1266        $xmlobj put ${molPath}.pdb $frameContents
     1267        $xmlobj put ${molPath}.formula $formula
     1268    }
     1269}
     1270
     1271itcl::body Rappture::Analyzer::_lammpsToSequence {xmlobj path id child data} {
     1272
     1273    set seqLabel [$xmlobj get ${child}.about.label]
     1274    set descr    [$xmlobj get ${child}.about.description]
     1275    set typemap  [$xmlobj get ${child}.components.molecule.lammpstypemap]
     1276    $xmlobj remove $child
     1277
     1278    set seqPath ${path}.sequence($id)
     1279    $xmlobj put ${seqPath}.about.label $seqLabel
     1280    $xmlobj put ${seqPath}.about.description $descr
     1281    $xmlobj put ${seqPath}.index.label "Frame"
     1282
     1283    set frameNum 0
     1284    set frameContents ""
     1285    set inModel 0
     1286    foreach line $data {
     1287        set line [string trim $line]
     1288        if { $line == "" } {
     1289            continue;                   # Skip blank lines
     1290        }
     1291        if {[regexp {^[\t ]*ITEM:[ \t]+ATOMS} $line] } {
     1292            if { $inModel && $frameContents != "" } {
     1293                set framePath ${seqPath}.element($frameNum)
     1294                $xmlobj put ${framePath}.index $frameNum
     1295               
     1296                set molPath ${framePath}.structure.components.molecule
     1297                $xmlobj put ${molPath}.lammps $frameContents
     1298                $xmlobj put ${molPath}.lammpstypemap $typemap
     1299               
     1300                incr frameNum
     1301                set frameContents ""
     1302            }
     1303            set inModel 1
     1304        } elseif { [scan $line "%d %d %f %f %f" a b c d e] == 5 } {
     1305            if { !$inModel } {
     1306                puts stderr "found \"$line\" without previous \"ITEM: ATOMS\""
     1307                set inModel 1
     1308            }
     1309            append frameContents $line\n
     1310        }
     1311    }
     1312    if { $frameContents != "" } {
     1313        set framePath ${seqPath}.element($frameNum)
     1314        $xmlobj put ${framePath}.index $frameNum
     1315       
     1316        set molPath ${framePath}.structure.components.molecule
     1317        $xmlobj put ${molPath}.lammps $frameContents
     1318        $xmlobj put ${molPath}.lammpstypemap $typemap
     1319    }
     1320}
     1321
     1322# ----------------------------------------------------------------------
     1323# USAGE: _trajtosequence <xmlobj> ?<path>?
     1324#
     1325#       Check for PDB and LAMMPS trajectories in molecule data and rewrite
     1326#       the individual models as a sequence of molecules.  Used internally
     1327#       to detect any molecule output elements that contain trajectory data.
     1328#       Trajectories will be converted into sequences of individual molecules.
     1329#       All other elements will be unaffected. Scans the entire xml tree if a
     1330#       starting path is not specified. 
     1331#
     1332# ----------------------------------------------------------------------
     1333itcl::body Rappture::Analyzer::_trajToSequence {xmlobj {path ""}} {
     1334    puts stderr "path=$path"
     1335    # Remove leading dot from path, if present.
     1336    if { [string index $path 0] == "." } {
     1337        set path [string range $path 1 end]
     1338    }
     1339    # Otherwise check each child.
     1340    foreach child [$xmlobj children $path] {
     1341        set current ${path}.${child}
     1342        if { [string match "structure*" $child] } {
     1343            # Look for trajectory if molecule element found.  Check both pdb
     1344            # data and lammps data.
     1345            set type [$xmlobj element -as type $current]
     1346            set id   [$xmlobj element -as id $current]
     1347            set pdbdata    [$xmlobj get ${current}.components.molecule.pdb]
     1348            set lammpsdata [$xmlobj get ${current}.components.molecule.lammps]
     1349            if { $pdbdata != "" && $lammpsdata != "" } {
     1350                puts stderr \
     1351                    "found both <pdb> and <lammps> elements: picking pdb"
     1352            }
     1353            set pdbdata [split $pdbdata \n]
     1354            set lammpsdata [split $lammpsdata \n]
     1355            if { [_isPdbTrajectory $pdbdata] } {
     1356                _pdbToSequence $xmlobj $path $id $current $pdbdata
     1357            } elseif { [_isLammpsTrajectory $lammpsdata] } {
     1358                _lammpsToSequence $xmlobj $path $id $current $lammpsdata
     1359            }
     1360            continue
     1361        }
     1362        # Recurse over all child nodes.
     1363        _trajToSequence $xmlobj $current
    11461364    }
    11471365}
  • branches/blt4/gui/scripts/molvisviewer.tcl

    r1764 r1795  
    780780                set _dataobjs($model-$state)  1
    781781            }
     782
     783            # lammps dump file overwrites pdb file (change this?)
     784            set lammpstypemap [$dataobj get components.molecule.lammpstypemap]
     785            set lammpsdata [$dataobj get components.molecule.lammps]
     786            if {"" != $lammpsdata} {
     787                set data3 ""
     788                set modelcount 0
     789                foreach lammpsline [split $lammpsdata "\n"] {
     790                    if {[scan $lammpsline "%d %d %f %f %f" id type x y z] == 5} {
     791                        set recname  "ATOM  "
     792                        set altLoc   ""
     793                        set resName  ""
     794                        set chainID  ""
     795                        set Seqno    ""
     796                        set occupancy  1
     797                        set tempFactor 0
     798                        set recID      ""
     799                        set segID      ""
     800                        set element    ""
     801                        set charge     ""
     802                        if { "" == $lammpstypemap} {
     803                            set atom $type
     804                        } else {
     805                            set atom [lindex $lammpstypemap [expr {$type - 1}]]
     806                            if { "" == $atom} {
     807                              set atom $type
     808                            }
     809                        }
     810                        set pdbline [format "%6s%5d %4s%1s%3s %1s%5s   %8.3f%8.3f%8.3f%6.2f%6.2f%8s\n" $recname $id $atom $altLoc $resName $chainID $Seqno $x $y $z $occupancy $tempFactor $recID]
     811                        append data3 $pdbline
     812                    }
     813                    # only read first model
     814                    if {[regexp "^ITEM: ATOMS" $lammpsline]} {
     815                      incr modelcount
     816                      if {$modelcount > 1} {
     817                        break
     818                      }
     819                    }
     820                }
     821                if {"" != $data3} {
     822                    set _pdbdata $data3
     823                    SendCmd "loadpdb -defer \"$data3\" $model $state"
     824                    set _dataobjs($model-$state) 1
     825                }
     826            }
    782827        }
    783828        if { ![info exists _model($model-transparency)] } {
     
    12661311        set _settings($this-modelimg) [Rappture::icon $option]
    12671312    }
    1268     set inner [$itk_component(main) panel "View Settings"]
     1313    set tab [$itk_component(main) panel "View Settings"]
     1314    set inner $tab.ss.frame
    12691315    $inner.pict configure -image $_settings($this-modelimg)
    12701316
Note: See TracChangeset for help on using the changeset viewer.