My software notes

April 14, 2011

[NMRPipe]–making a 3D cube

Filed under: NMRPipe and NMRview,softwares and scripts — kpwu @ 1:37 pm
Tags: ,

***NOTE on April 20****

The nmrCube.tcl has been included in the new version of NMRPipe package and it can label axis, tics and tic values now.

New post is available to show to changes.

*************************

On Feb 18th, an user asked whether there are ways to make a 3D cube of NMR data at the NMRPipe discussion group at Yahoo. Frank Delaglio, the author of NMRPipe, provided a very very nice script to generate the cube. The script is pasted in this post and user can copy it, save it (e.g. nmrCube.tcl) and chmod a+x nmrCube.tcl to make it executable.

I have example pictures showing at here using my 15N-edited NOESY-Hsqc spectrum.

The default colors for background and foreground are black and white, respectively. nmrCube.tcl will draw multi-color peaks in the cube based on the 15N frequency. Here is the example:

I modify the script by changing the default colors (shown in red in the script at here) and run the script like this way:
/path/nmrCube.tcl -hi 5.0e+5 -colors red (fix height and color all peaks in red). The cube is then looked like this way:

So far, no ways for labeling axis and rotation.

===== copy the script and save it as nmrCube.tcl to run ==========

#!/bin/sh
# The next line restarts using nmrWish \
exec nmrWish “$0” — “$@”

set auto_path “[split $env(TCLPATH) :] $auto_path”
set ARGV [concat $argv0 $argv]
set ARGC [llength $ARGV]

if {[info exists env(NMRTXT)]} \
{
set tStr ” ($env(NMRTXT)/rgb.txt).”
} \
else \
{
set tStr “.”
}

if {[flagLoc $ARGV -help]} \
{
puts “Draw a Simple Static 3D Cube Display of NMRPipe-Format 3D Data:”
puts ” -in inName \[ft/test%03d.ft3\] 3D Spectrum to Draw.”
puts ” -hi hi \[1.0e+5\] Contour Height.”
puts “Spectral Orientation for Drawing :”
puts ” -xName xName \[X_AXIS\] Spectral Axis Name for Plot X-Axis.”
puts ” -yName yName \[Y_AXIS\] Spectral Axis Name for Plot Y-Axis.”
puts ” -zName zName \[Z_AXIS\] Spectral Axis Name for Plot Z-Axis.”
puts “Drawing Sizes:”
puts ” -cxSize cxSize \[400\] Plot X-Axis Size, Pixels.”
puts ” -czSize cySize \[400\] Plot Y-Axis Size, Pixels.”
puts ” -czSize czSize \[Auto\] Plot Z-Axis Size, Pixels.”
puts ” -xAdj xAdj \[16\] Window Horizontal Offset, Pixels.”
puts ” -yAdj yAdj \[32\] Window Vertical Offset, Pixels.”
puts “Drawing Colors:”
puts ” -colors cList \[red …\] List of Colors for Spectral
Drawing.”
puts ” -fgColor fg \[white\] Forground Color (for Box Outlines).”
puts ” -bgColor bg \[black\] Background Color.”
puts “Notes:”
puts ” 1. The graphic produced is a simple stack of fixed-sized 2D”
puts ” plots with a linear offset.”
puts ” 2. Use ‘-colors multi’ for spectral colors selected according”
puts ” to intensity rather than Z-Axis position.”
puts ” 3. See file ‘rgb.txt’ in the NMRPipe ‘nmrtxt’ directory for valid”
puts ” colors$tStr”
exit 0
}

set inName ft/test%03d.ft3
set hi 1.0e+5

set tMargin 40
set bMargin 120
set lMargin 40
set rMargin 120

set cxSize 400
set cySize 400
set czSize Auto

set xAdj 16
set yAdj 32

set bgColor white #was black
set fgColor black # was white
set colorA black # was white
set colorS white # was black

set xName X_AXIS
set yName Y_AXIS
set zName Z_AXIS

set colorList {red orange yellow green blue cyan orchid}

getArgD $ARGV -in inName
getArgD $ARGV -hi hi

getArgD $ARGV -xName xName
getArgD $ARGV -yName yName
getArgD $ARGV -zName zName

getArgD $ARGV -tMargin tMargin
getArgD $ARGV -bMargin bMargin
getArgD $ARGV -rMargin rMargin
getArgD $ARGV -lMargin lMargin

getArgD $ARGV -cxSize cxSize
getArgD $ARGV -cySize cySize
getArgD $ARGV -czSize czSize

getArgD $ARGV -xAdj xAdj
getArgD $ARGV -yAdj yAdj

getArgD $ARGV -bgColor bgColor
getArgD $ARGV -fgColor bgColor
getArgD $ARGV -colorA colorA
getArgD $ARGV -colorS colorS

getListArgD $ARGV -colors colorList

#
#———————————————————-

wm geom . +$xAdj+$yAdj
wm title . $inName

#
# Check input and its number of planes:

set thisName [format $inName 1]

if {![file exists $thisName]} \
{
puts stderr “Error Finding 3D Input $inName”
exit 1
}

set error [rdFDATA $thisName fdata]

if {$error} \
{
puts stderr “Error Reading Header from 3D Input $inName”
exit 1
}

set dimCount [getParmI $fdata FDDIMCOUNT NULL_DIM]
set zSize [getParmI $fdata NDSIZE CUR_ZDIM]

if {$dimCount != 3 || $zSize < 1} \
{
puts stderr “3D Drawing Error: Data is not 3D.”
exit 1
}

#
# Create the graphics area:

if {![strcasecmp $czSize Auto]} {set czSize [expr int(0.25*($cxSize + $cySize))]}

set wxSize [expr $bMargin + $lMargin + $cxSize + $czSize]
set wySize [expr $tMargin + $bMargin + $cySize + $czSize]

canvas .c -width $wxSize -height $wySize -border 0
pack .c -in . -side top -expand 1 -fill both

button .q -text Quit -command exit
pack .q -in . -side top -expand 1 -fill x

update

.c create pixmap 0 0 -width $wxSize -height $wySize -win 1

#
# Draw the planes:

set nC [llength $colorList]

if {!$nC} \
{
set colorList white
set nC 1
}

set cxn [expr 1 + $wxSize – $rMargin]
set cx1 [expr 1 + $cxn – $cxSize]

set cyn $tMargin
set cy1 [expr $cyn + $cySize – 1]

set iz 1

set xOff [expr int(double($czSize)*($zSize – $iz)/($zSize – 1))]
set yOff [expr int(double($czSize)*($zSize – $iz)/($zSize – 1))]

set tx1 [expr $cx1 – $xOff]
set txn [expr $cxn – $xOff]

set ty1 [expr $cy1 + $yOff]
set tyn [expr $cyn + $yOff]

drawRec -win 1 -x 0% 100% -y 0% 100% -fg $bgColor
drawBox -win 1 -x $cx1 $cxn -y $cy1 $cyn -fg $fgColor

drawLine -win 1 -x $tx1 $cx1 -y $ty1 $cy1 -fg $fgColor
drawLine -win 1 -x $txn $cxn -y $ty1 $cy1 -fg $fgColor

for {set iz $zSize} {$iz >= 1} {incr iz -1} \
{
set xOff [expr int(double($czSize)*($zSize – $iz)/($zSize – 1))]
set yOff [expr int(double($czSize)*($zSize – $iz)/($zSize – 1))]
set ic [expr int(double($nC)*($zSize – $iz)/($zSize – 1))]

if {$ic > $nC – 1} {set ic [expr $nC – 1]}
set color [lindex $colorList $ic]

set tx1 [expr $cx1 – $xOff]
set txn [expr $cxn – $xOff]

set ty1 [expr $cy1 + $xOff]
set tyn [expr $cyn + $xOff]

readROI -ndim 2 -roi 1 -in $inName \
-x $xName 0% 100% -y $yName 0% 100% -dz $zName $iz 0

defineCell -win 1 -cell 1 -x $tx1 $txn -y $ty1 $tyn
defineCell -win 1 -cell 1 -x $tx1 $txn -y $ty1 $tyn

drawROI -win 1 -cell 1 -roi 1 -win 1 \
-hi $hi -bg None -fg None -nobox -color1 $color -color2 $color

update
}

drawLine -win 1 -x $tx1 $cx1 -y $tyn $cyn -fg $fgColor
drawLine -win 1 -x $txn $cxn -y $tyn $cyn -fg $fgColor
drawBox -win 1 -x $tx1 $txn -y $ty1 $tyn -fg $fgColor

update

Advertisements

2 Comments »

  1. […] week, I posted a blog article that we can make a cube of 3D NMR data but that scripts (at that time) can not draw the labels/axis […]

    Pingback by Cube view of 3D NMR data « My software notes — April 20, 2011 @ 5:19 pm | Reply

  2. ./nmrCube.tcl
    dyld: Library not loaded: /usr/local/nmr/lib/libtk8.4.dylib
    Referenced from: /Applications/NMRPipeX/nmrbin.mac/nmrWish
    Reason: image not found
    Trace/BPT trap

    How to troubleshoot this?

    Comment by gery — September 25, 2015 @ 7:04 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: