#!/usr/bin/wish -f # # installation: # save this file as rmscop to a directory in your path # edit points marked 'local-config' if required # # $Header: /nfs/offa/beo/local/www/dev/docs/std/rs/RCS/rmscop.txt,v 1.5 1996/08/24 11:03:18 th Exp $ # # Copyright (C) 1994-6 Tim Hubbard (th@mrc-lmb.cam.ac.uk) # Centre for Protein Engineering, MRC Centre, Cambridge, UK # All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation # # 28/4/00 - made locally configurable # 17/8/95 - beta version # 1/10/95 - added ability to read/display PDB file directly # 30/4/96 - added ftp to /usr/tmp ability # 20/7/96 - fixed to work under tk4.0 # # Function: # # tcl/tk script to direct rasmol commands from scop to # existing rasmol windows # # Usage: # # rmscop # # starts xterm, rasmol windows # # rmscop coordinatefilename # # displays coordinatefilename in existing rasmol window or starts # rasmol if none running # # rmscop rasmolscriptfile # # loads coordinatefile specified by 'load' in rasmolscriptfile # into existing rasmol window or starts rasmol if none running # # Known bugs: # # Will only deal with N rasmols, according to the number of duplicated # commands in this script - generation of buttons is not in a loop # since there seems no way to memorize # the different exit commands without defining each explicitly # # if there is no argument, assume this was a command from the user # interpret it as an instruction to start rasmol # --- SITE-CONFIG # Works with SCOP now, but fails with PDBSUM, HOMSTRAD! - Shyam # works as a "rasmolscript" with SSM - 20030521.llc # 1. location of pdb files on your system and local naming conventions # set pdbdir {} # set pdbdir {/nfs/alf1/pdb/} # prefix of local pdb filenames # set pdbpref {} # set pdbpref {pdb} # extension of local pdb filenames # set pdbext {} # set pdbext {.ent} # 2. name of rasmol in your path # RasMol2 is known to work with rmscop # (ftp://ftp.dcs.ed.ac.uk/pub/rasmol/v2.6beta) # set rasmol {} # set rasmol {/usr/local/bin/rasmol} # 3. FTP parameters # PDB at RCSB # set ftpserver {ftp.rcsb.org} # set ftpserverdir {/pub/pdb/data/structures/all/pdb/} # set ftpext {.ent} # PDB at EBI set ftpserver {ftp.ebi.ac.uk} set ftpserverdir {/pub/databases/rcsb/pdb/data/structures/all/pdb/} set ftpext {.ent} # compression ext of pdb files downloaded using ftp # set cmpext {<.ext>} # set cmpext {.Z} # 4. location of pdb files on local machine after download using ftp # must have write permission # set ftpdir {} # set ftpdir {/tmp/} # Optional: type of terminal to use for command line I/O with RasMol set term {xterm} # --- SITE-CONFIG END #================================================================ # Do not change anything below this !!!!!!!!!!!!!!!! #================================================================ # No args -> launch rasmol and exit if {$argc != 1} { exec $term -geometry 80x10+10-10 -fn 6x10 -sb -e $rasmol & exit } # check if argv points to real file. If not, stop with error. set fname [lindex $argv 0] if {!([file exists $fname])} { puts stdout "Arguments must be files of valid rasmol commands" exit } set f [open $fname r] # 20030509.llc add it here and made the regexp "loose" (inline only) # to work with SSM while {[gets $f line] >=0} { if {[regexp {inline} $line]} { close $f exec $term -geometry 80x10+10-10 -fn 6x10 -sb -e $rasmol -script $fname exit } } # firstline is used later gets $f firstline # If the input file contains the "load inline" command, it should also # contain the atomic coordinates -> load file as a script and exit. # Note: Here we are assuming that the "load inline" command will not # reside in the first line of the input file. while {[gets $f line] >=0} { if {[regexp {inline} $line]} { close $f exec $term -geometry 80x10+10-10 -fn 6x10 -sb -e $rasmol -script $fname exit } } close $f # List with RasMol windows set rasWins {} # Check nb of RasMol windows proc getRasmolWins {} { global rasWins # Empty list set rasWins {} set x 0 # Loop on interps atom foreach rwin [winfo interps] { # Got a rasmol win? if {[string match rasmol* $rwin] && ([string length $rwin] < 11)} { # Keep window ID lappend rasWins $rwin incr x } } # Return nb of win picked return $x } # check if any RasMol windows. If not, start rasmol. set nbRas [getRasmolWins] if {$nbRas == 0} { # Launch RasMol now exec $term -geometry 80x10+10-10 -fn 6x10 -sb -e $rasmol & # Wait for RasMol set count 0 while {! $nbRas} { set nbRas [getRasmolWins] update incr count if {$count == 20} { tk_dialog -text "Couldn't catch new RasMol window!\nIs it started? Try to start it in a separate shell." -title {Error} -string {ok} # From now on can be troubles, exit prog now exit } # Wait a bit set i 0 while {$i < 60000} { incr i } } } set f [open $fname r] # get entry name set entry "" set ftpfetch 0 while {$entry=="" && [gets $f line] >=0} { regexp -nocase {^load( pdb)? pdb([0-9s][0-9a-z]+)\.ent} $line all hom entry } close $f # define PDB first line card identifiers that can identify a file if {[regexp -nocase {^(HEADER|ATOM|REMARK)} $firstline]} { # It's a PDB file set com1 {[zap][load FILE][wireframe off][backbone 80][colour structure]} regsub FILE $com1 $fname com set com1 $com } else { # deal with file existence # look for file set check ${pdbdir}${pdbpref}${entry}${pdbext} if {[file exists ${pdbdir}${pdbpref}${entry}${pdbext}]} { set pdbfile "${pdbdir}${pdbpref}${entry}${pdbext}" # look for compressed file in temp dir } elseif {[file exists ${ftpdir}pdb${entry}${ftpext}${cmpext}]} { set pdbfile "${ftpdir}pdb${entry}${ftpext}${cmpext}" # download using ftp } else { # report download set win .download toplevel $win wm geometry $win wm title $win "Fetching file $entry to $ftpdir via FTP..." frame $win.stat -bd 2 -relief raised pack $win.stat -fill x # Label label $win.stat.label -text "Fetching file $entry to $ftpdir via FTP..." pack $win.stat.label -fill x update set ftpfetch 1 # Get original dir set pwd [pwd] # move to tmp ftp dir cd $ftpdir # write ftp commands in a temp file set tmp "$ftpdir/ftptmpfile" set ft [open $tmp w] exec /bin/chmod +w $tmp puts $ft "user ftp rmscop@rasmol.user" puts $ft "binary" puts $ft "cd ${ftpserverdir}" puts $ft "get pdb${entry}${ftpext}$cmpext" puts "get pdb${entry}${ftpext}$cmpext" puts $ft "bye" close $ft # Execute cmd now exec ftp -n $ftpserver < ${ftpdir}ftptmpfile update set pdbfile "${ftpdir}/pdb${entry}${ftpext}${cmpext}" exec /bin/chmod +w $pdbfile # exec /bin/rm $tmp cd $pwd destroy $win } # check for rsgen.cgi output set f [open $fname r] set coml {[zap} while {[gets $f line] >=0} { # replace with file we are going to actually load regsub {load( pdb)? pdb[0-9s][0-9a-z]+\.ent} $line "load ${pdbfile}" t1 set line $t1 lappend coml $line } lappend coml ] close $f set com [join $coml @] regsub -all {@@} $com {@} com1 regsub -all {@\]} $com1 {]} com2 regsub -all {@} $com2 {][} com # looking for the segment # cpk on][select not 'region'][backbone 80 # to turn this off regsub {(cpk on\]\[select not)(.*)(\]\[backbone) 80(\]\[select) all} $com {\1\2\3 off\4\2} com1 } # commands are in $com and $com1 # now work out where to send them: # more than one rasmol running, must choose between them... if { $nbRas > 1} { wm geometry . +10+10 button .quit -text "Quit" -command {destroy .} pack .quit -side bottom -fill x if {$com != $com1} { frame .left pack .left -side left frame .right pack .right -side right } else { frame .left pack .left -side top -fill x } # 1 set y 0 set yy 10 set rmc1 [lindex $rasWins $y] incr y +1 button .$y -text "->rasmol $y (all)" -command { send $rmc1 $com exit } pack .$y -in .left -fill x if {$com != $com1} { button .$yy -text "(region only)" -command { send $rmc1 $com1 exit } pack .$yy -in .right } # 2 set rmc2 [lindex $rasWins $y] incr y +1 button .$y -text "->rasmol $y (all)" -command { send $rmc2 $com exit } pack .$y -in .left -fill x incr yy +1 if {$com != $com1} { button .$yy -text "(region only)" -command { send $rmc2 $com1 exit } pack .$yy -in .right } if {$nbRas > $y} { set rmc3 [lindex $rasWins $y] incr y +1 button .$y -text "->rasmol $y (all)" -command { send $rmc3 $com exit } pack .$y -in .left -fill x incr yy +1 if {$com != $com1} { button .$yy -text "(region only)" -command { send $rmc3 $com1 exit } pack .$yy -in .right } } if {$nbRas > $y} { set rmc4 [lindex $rasWins $y] incr y +1 button .$y -text "->rasmol $y (all)" -command { send $rmc4 $com exit } pack .$y -in .left -fill x incr yy +1 if {$com != $com1} { button .$yy -text "(region only)" -command { send $rmc4 $com1 exit } pack .$yy -in .right } } } else { # must be only 1 -> send cmd directly set rasapp [lindex $rasWins 0] send $rasapp $com exit }