Docstoc

User Programming

Document Sample
User Programming Powered By Docstoc
					                                            User Programming
                                                          Varian NMR Systems

       User Programming Course Outline

INTRODUCTION                   PULSE SEQUENCE PROGRAMMING
   Resource materials             hardware interaction
   VNMRJ structure                beginning C
   User Interface                 basic pulse sequences
BASIC SYSTEM ADMINISTRATION       advanced sequences

   The Windowing Environment   MAGICAL II
   Editors                         macros
                               BASIC CONCEPTS of VNMRJ
                                 User Programming
                                      Varian NMR Systems

   Putting it all Together

Pulse Sequence Programming
• Pulse sequence itself
• setup macro
• parameter set customizations
• Adding to GUI
        • processing macros
        • Controlling Pbox
                                                  User Programming
                                                               Varian NMR Systems

                            Introduction

Resource Materials
                                     Resource Materials
On the Spectrometer
                                     Hard copy - "how to"
     man(subject)
     help(subject)                       System Operation
     VNMR on-line                        Guide to NMR Experiments
     VNMR news/E-mail                    System Administration
     EXISTING CODE & FILES !!!!
                                         VNMRJ Pulse Sequences
                                         User Guide: Liquids NMR
Hard copy - reference
                                         User Guide: Solids NMR
     Command & Parameter Reference
     User Programming                    User Guide: Imaging
                                              User Programming
                                                       Varian NMR Systems

                       Introduction

VNMR Structure                             In VNMR
Equivalent Paths
       /export/home/user/vnmrsys = ~/vnmrsys = userdir = $vnmruser
               Each unique NMR user area
                                                       In Shell

       /export/home/vnmr = /vnmr = systemdir = $vnmrsystem

               System VNMR Software area
                                        User Programming
                                             Varian NMR Systems

               VNMR directories/files

Conpar


  System configuration:
  contains critical system parameters
      number and type of channels
      shim set type
      lock frequency
      .....
                                      User Programming
                                             Varian NMR Systems

           VNMRJ directories/files

Conpar


  UNITY+, INOVA and VNMRS systems autoconfigure,
  Gemini 2000, Unity, VXR-S systems cannot autoconfigure
                                    User Programming
                                             Varian NMR Systems

      VNMR directories/files


devicenames - printer names - used by VNMR
/vnmr/bin/adddevices is used to add new devices
                                                    User Programming
                                                                 Varian NMR Systems

                 VNMRJ directories/files



psglib                                 shapelib
    source code for pulse sequences         shaped pulse files

seqlib                                 shims
    compiled pulse sequences                shim files

Use the User equivalent directories for modifications
                                                User Programming
                                                          Varian NMR Systems

               VNMRJ directories/files

maclib                             parlib
   MAGICAL macros used by the         Parameters for individual
   system                             experiments
                                            cosy.par, noesy.par
templates
                                            this directory is actually
   text files controlling VNMRJ             linked to one of the
   parameter pages and interface            directories par200 - par750

                                   stdpar
                                      Nucleus parameter files
                                            e.g. H1.par, C13.par
                              User Programming
                                   Varian NMR Systems

Basic System Administration


  The Windowing Environment
  Editor
                                                    User Programming
                                                               Varian NMR Systems

            The X Windows Environment

What is X Windows?                      Nomenclature


                                           The computer that you are using as
   X is a standardized windowing           a display is the X Client (X
   environment . X has the advantage       terminal).
   that it separates the functions of      The computer that is running the
   computation and display.                software is the X Server.
                                           The X Server and X Client may
                                           either be the same or different.
                                                User Programming
                                                        Varian NMR Systems

        The X Windows Environment


Where the X Server is not the same computer as the X Client, the
two are normally connected via ethernet.

It is not simple to connect via serial ports!
                                                             User Programming
                                                                         Varian NMR Systems

                                     Editors

Although strictly not necessary, an editor   There are a number of editors available.
makes life much easier when using the        The two that are used most are
system.
You will use an editor for                        textedit - a mouse driven editor
     writing macros                               vi - a character based editor
     writing menus
     writing pulse sequences
     other VNMRJ text manipulations
     Unix/Linux text manipulations
                                                   User Programming
                                                         Varian NMR Systems

                       Editors

The choice of an editor is somewhat governed by the use
to which it is put:


     vi is generally used by software engineers. It is
     keyboard-controlled only, but is efficient.


     Text based editor is generally used by people used to
     PC based packages. Example – dtpad
     (/usr/dt/bin/dtpad)
                                                     User Programming
                                                                Varian NMR Systems

                          Editors

The default editor in VNMRJ is vi!


You can change this default by setting the environmental variable
vnmreditor in your .login file.
     For example, setenv vnmreditor dtpad
      VNMR will use dtpad the next time you login
See the CPR (for example - macroedit)
                                                   User Programming
                                                              Varian NMR Systems

     A few Vi Editor Commands
Insert mode                            P - put yanked line above cursor
i - insert before cursor               p - put yanked line below cursor
a - insert after cursor                :w - write file
o - insert on newline                  :q - quit
ESC to exit insert mode                :q! - force quit no write
Command mode                           :wq - write and quit
dw - delete word                       :r - read
dd - delete line                       ZZ - write and quit
cw - change word                       CTRL-d - scroll forward
u - undo                               CTRL-u - scroll back
/ - search forward                     CTRL-f - next screen
n - next occurrence                    CTRL-b - previous screen
Y- yank line
                use arrow keys to navigate within screen
                                            User Programming
                                                     Varian NMR Systems

                      textedit


dtpad is much more of a wysiwyg editor. It uses the mouse
and the left keypad to operate.
Text based editor is OS specific.

Linux system can use the editor from the toolbar
                                   User Programming
                                        Varian NMR Systems

Pulse Sequence Programming

Syllabus
    Pulse sequence execution
    Hardware issues
    Programming & compilation of sequences
    Pulse sequence statements
    Phase and other calculations
    Access to parameters
    Advanced programming
                                                       User Programming
                                                                   Varian NMR Systems

                  Pulse Sequence Execution

When “go” runs:
    go is a macro which looks first for a    The A-codes are downloaded to the
                                             acquisition computer.
    macro usergo and executes it if it
                                             The A-codes describe 1 transient and
    exists.
                                             the number of times it must be repeated
    Next, go looks for a macro go_{seqfil}   to acquire 1 fid.
    and executes it if it exists.            There is a set of A-codes for
    go next executes the Acq program              each fid in an array
    which looks up parameters in the              each increment in a nD
    current experiment, then runs a               experiment
    program stored in seqlib ({seqfil} )
    which outputs a series of
    instructions (A-codes).
                                                               User Programming
                                                                             Varian NMR Systems

                 Pulse Sequence Execution

"run" time execution                            “real time” execution
Some calculations are executed only once        Some calculations must occur during
when program runs.                              execution.
This value is used for rest of pulse sequence   For example, the steady state counter ct is
and does not change, for example -              updated for each transient
     tau = 1.0/(2.0*J);                              add(one,ct,v4);
This is a run time statement.
                                                This is a real time statement
Run-time statements are evaluated and
                                                Real-time statements are evaluated and
executed in the host.                           executed in the acquisition system.
                                        User Programming
                                                  Varian NMR Systems

                   gating


Pulse execution requires hardware to be turned on or off.
    transmitter gate
    amplifier blanking gate
    LO gate
    receiver gate
                                        User Programming
                                                 Varian NMR Systems

               Event timing

A finite amount of time is required to gate the
hardware. Communication may occur via the AP bus
(frequency setting), RS232 ports (VT Unit) or high
speed lines (pulses). This is system specific:

INOVA or previous: uses AP bus
VNMRS: no AP bus
                                                 User Programming
                                                          Varian NMR Systems

                  AP Bus timing


AP bus instructions incur a delay of 0.5 ms on INOVA, 1.15µs on U+,
1.2 ms on Mercury, 2.15 µs on Unity, VXR-S and Gemini 2000.


Each instruction is one or more FIFO events
Multiple events may be required by a statement
Delays associated with statements in UP chapter 2
Exact delays are accessible in /vnmr/psg/apdelay.h
                 User Programming
                      Varian NMR Systems




Unity Inova RF
                 User Programming
                                   Varian NMR Systems




                 PTS: Resolution- 0.1 Hz
                 Phase: 0-360 in 0.25 degree steps
                 Amplitude: 60 dB in 0-4095 linear steps
                 RF Attn: 79 dB: -16-63 in 1 dB steps
                 Filters: 8 pole quasi elliptical
                 ADC: 16 bit-500kHz




Unity Inova RF
INOVA RF   User Programming
                             Varian NMR Systems




           PTS: Resolution- 0.1 Hz
           Phase: 0-360 in 0.25 degree steps
           Amplitude: 60 dB in 0-4095 linear steps
           RF Attn: 79 dB: -16-63 in 1 dB steps
           Filters: 8 pole quasi elliptical
           ADC: 16 bit-500kHz
                                            VNMRS RF                                 User Programming
                                                                                                   Varian NMR Systems
                                                                                                Varian
                                                                                                DDR –
                                                                                              20 MHz IF
                                                                                               sampled
                                                                                              directly at
                                                                                             80 MHz rate



                                                  RF
                                               Attenuator



               SDRAM
           (Error Correcting)               Flash
                 64 Mb                      32 Mb
                                  DMA EBC




                                                                  Register     Instruction
                                                                                                                      RF Transmitter
                                                    EBC
                                                                  Decode          FIFO
Ethernet




                                                                                                    FIFO
              PowerPC                                                               RF             & Timer
                                                    IntC Config




                                                                                    Math
                                GPIO
RS232




                                IntC                                                                                 Attn, Synth, Users
                                                                             FPGA                           RF Aux

                                                                                                            SyncIN

                                                                                                            GPIO        Sync
                                                                       User Programming
                                                                                     Varian NMR Systems

                Pulse Sequence Programming

1. Pulse Sequences are written onto a framework of   3. Pulse sequence source code is created with vi or
the C programming language.                          your favorite editor and stored in psglib. Each
                                                     defined user may have his or her own psglib.
2. Extensive knowledge of the C programming
language is NOT necessary to write pulse             4. Unlike macros, pulse sequences must be

sequences.                                           compiled before they can be used. Compiled pulse
                                                     sequences are found in seqlib. Only the system
                                                     manager may put compiled sequences into the

                                                     system seqlib.
                                                 User Programming
                                                            Varian NMR Systems

        User Friendly Sequences

1. Each pulse sequence should have its own setup macro that
accesses any needed parameters.


2. Pulse sequence specific parameters should be stored in the
library parlib.


3. Each pulse sequence should have its help file that explains
what parameters are and what values are reasonable for the
parameters.
                                                   User Programming
                                                             Varian NMR Systems

                        C Framework

The syntax for a pulse program   a. Each sequence must begin with the
is as follows:                   #include <standard.h> declaration.
                                 b. The body of the pulse sequence follows
#include <standard.h>            the first { . Each statement must be terminated
pulsesequence()                  by a semicolon.
{                                c. Any new variables must be declared.
pulse sequence statements ....   d. The pulse sequence ends with }.
}
                                              User Programming
                                                       Varian NMR Systems

Basic C for Pulse Sequence Programming


   Most statements take the form
      statement(argument);
   Most arguments are real numbers and can be represented as:
       Variables - example d1
       constants - example 5.2
       expressions - example 2.0*pw
                                      User Programming
                                                  Varian NMR Systems

Basic C for Pulse Sequence Programming

                          Types
You can declare any
number of new variables
                          char     character            8 bits
for use as parameters.
                          short    short int            16 bits
                          int      integer              32 bits
Variables must be of a
                          float    floating point       32 bits
specific type:
                          double   double precision fp 64 bits
                          Shape    character            (only
                                               with Pbox_psg.h )
                                                        User Programming
                                                             Varian NMR Systems

Basic C for Pulse Sequence Programming


 Most real numerical variables will be of type double
 Integers will be of type int
 strings (like dmm) will be of type char with dimension MAXSTR
 An example is


 double j1hx,tau1; or
 Double j1hx=getval(“j1hx”);
 char fad[MAXSTR];
                                                          User Programming
                                                                      Varian NMR Systems

        Pulse Sequence Compilation


The pulse sequence is a program that is compiled by issuing a command
seqgen filename or seqgen filename.c


This adds dps extensions


It checks for syntax errors


It combines the pulse sequence function with necessary psg object libraries
to produce executable code which is stored under the name filename in
~/vnmrsys/seqlib
                               User Programming
                                    Varian NMR Systems

  Pulse Sequence Statements
Pulse sequences may contain:

PULSES
DELAYS
RECEIVER control statements
PHASE calculations
POWER control statements
XMTR, DECPLR gate control
AP tables
miscellaneous statements
                                               User Programming
                                                          Varian NMR Systems

                    Control Statements

Math statements

     Boolean Logic
          if (dm[0]==„n‟) statement;   /* C language */

     Loops
          for (i=0,i<count,i++) statement; /* C language*/
          loop(v1,v2); /* unity real time loop*/
            endloop(v2);
          loop(2,v1,v2); /* G2000 rt loop*/
            endloop(2);
          starthardloop(v10); /*not G2000 -hardware loop*/
            endhardloop();

     C statements
          tpwr=tpwr+6.0;
            i3++;
                                                      User Programming
                                                                Varian NMR Systems

                  DELAY Statements

delay(time); - Time must be a REAL number.


hsdelay(time); - Homospoil delay using z1 shim coil.


Actual homospoil time is controlled by the parameter hst. (The use of this
statement has largely been superceded by the use of pulsed field gradient
pulses.)
Examples
     delay(d1);
     hsdelay(d1); /* will give homospoil of hst in the d1 delay if hs=„y‟ */
                                             User Programming
                                                       Varian NMR Systems

               DELAY Statements

vdelay(timebase,count);
    timebase can be NSEC,USEC,MSEC or SEC
    count must be a real time variable
    delay length for NSEC timebase is 100 + (count)*resolution nsec.
    Resolution = 12.5 ns for INOVA. If count = 4, the delay would
    be (100 + (4*12.5)) or 150 ns.
Example
    vdelay(NSEC,v5); /*normal syntax*/
                                                       User Programming
                                                                  Varian NMR Systems

                      DELAY Statements

initdelay & incdelay enable real-time
incremental delays
initdelay(time_increment,index);         incdelay(count,index);
                                             count must be a real time variable
    Initializes the time increment and   Example
    delay index.                             initdelay(mintau,DELAY3);
    Index is one of the indices
                                             incdelay(v4,DELAY3);
    DELAY1,DELAY2,...,DELAY5.
                                             /*will delay v4*mintau */
                                                                User Programming
                                                                       Varian NMR Systems

                             PULSE Events

The state of the receiver determines the
state of:                                      RF
Preamplifier blanking
Transmitter blanking


                                                         rof1         rof2
                                                                 pw


                                           Receiver
                                            Gate



                                           Transmitter
                                              Gate
                                                                  User Programming
                                                                              Varian NMR Systems

      PULSE (Observe Channel) Statements

rgpulse(pulsewidth,phase,RG1,RG2); -            simpulse(obswidth,decwidth,obsphase,decphase,
Receiver Gated PULSE. RG1 and RG2 are           RG1,RG2); Performs simultaneous pulse on
often set as rof1 and rof2. The receiver is     channels 1 and 2 (the “decoupler” and observe
gated off by RG1 microseconds before the        channel transmitter).
pulse and gated back on RG2 seconds after the
end. Pulse width must be a REAL number or       Example
expression.
Example                                         simpulse(pw,pp,oph,t3,rof1,rof2);
rgpulse(pw,oph,rof1,rof2);
                                              User Programming
                                                   Varian NMR Systems

      PULSE (Observe Channel) Statements

obspulse(pulsewidth); - Simple observe
PULSE. Receiver gates are rof1 and rof2.
Phase is automatically “oph”


Example obspulse(pw);


pulse(pulsewidth, phase); - Simple observe
PULSE. Receiver gates are rof1 and rof2.
Phase is specified by variable or constant.


Example pulse(pw, zero);
          pulse(pw, oph);
                                                User Programming
                                                              Varian NMR Systems

    Non-Observe Channel Pulses

decrgpulse(width,phase,RG1,RG2);
    pulsed at current power level of decoupler (channel 2).
    if tn and dn have different amp bands, decoupler amp is CW
    else decoupler amp is in pulse mode and blanked
dec2rgpulse - 3 rf channels
dec3rgpulse - 4 rf channels
 Example
    decrgpulse(pp,t4,rof1,0.0);
                                                 User Programming
                                                           Varian NMR Systems

        POWER Control Statements


obspower(tpwr); Sets power of observe channel to value of tpwr.
Argument is a variable of type real.
Functionally the same as rlpower(tpwr, OBSch);


decpower(pwxlvl); Sets power of 1st decoupler to value of pwxlvl
dec2power(39); dec3power(value); …. Etc.
                                          User Programming
                                                    Varian NMR Systems

Frequency Control Statements


 Similar to power control statements…
 The actual time for this statement varies with
 system type. Where timing is critical, make sure
 that you use the predefined variables from
 /vnmr/psg/apdelay.h



 obsoffset(tof); decoffset(dof); , etc.
                                                     User Programming
                                                          Varian NMR Systems

         GATING Control Statements

STATUS CONCEPT
        Convenient way to pass parameter control into pulse sequences
   status(state); controls decoupler and hs gating
   state = A,B,...Z
   dm, dmm,dm2,dmm2 etc. are under status control

   dm = “Decoupler mode”
   dmm = “decoupler modulation mode”

   EXAMPLES:
      dm=„nny‟ dm=„ynn‟ dm=„y‟
                                                           User Programming
                                                                       Varian NMR Systems

                    REAL TIME Variables


v1 to v14 - Real time variables that are used in the calculation of loops, phases etc.
ct        Completed transient counter. Starting point for most calculations
oph       Observe receiver phase (0123). This can be changed by the user.
          zero, one, two,three are 0, 90, 180, and 270 respectively.
bsctr     Block size counter
                                               User Programming
                                                          Varian NMR Systems

                 INTEGER Math

assign(vi,vj);   set vj equal to vi
add(vi,vj,vk);   set vk equal to vi+vj
sub(vi,vj,vk);   set vk equal to vi-vj

dbl(vi,vj);      set vj equal to 2*vi
hlv(vi,vj);      set vj equal to integer part of 0.5*vi
mod4(vi,vj);     set vj equal to vi mod 4
mod2(vi,vj);     set vj equal to vi mod 2
incr(vi);        increment vi by 1
decr(vi);        decrement vi by 1
                                                    User Programming
                                                         Varian NMR Systems

                     Integer Math


modn(vi,vj,vk)      set vk equal to vi mod vj
divn(vi,vj,vk)      set vk equal to vi div vj
mult(vi,vj,vk)      set vk equal to vi*vj
initval(value,vi)   initialize vi to a specific value
                                   User Programming
                                        Varian NMR Systems

        Integer Math

Example Calculations


mod2(ct,v1);     v1 = 0101010...
dbl(v1,v2);      v2 = 020202...
hlv(ct,v1);      v1=0011223344...
hlv(v1,v2);      v2=00001111....
dbl(v1,v1);      v1=00220022...
add(v1,v2,v3);   v3=00221133...
mod4(v3,oph);    oph=00221133...
                                             User Programming
                                                    Varian NMR Systems

                 Real Time Loops
                        The acquisition computer generates timer
                        words as determined by execution of these
loop(count,index)       commands.
endloop(index)

                        EXAMPLE
ifzero(vi)
elsenz(vi)
                             mod2(ct,v1);
endif(vi)                    ifzero(v1);
                              delay(d2/2);
                             elsenz(v1);
                              delay(d2);
                             endif(v1);
                                                        User Programming
                                                                   Varian NMR Systems

                   Phase-related Statements
                                         Example
phase may be changed before a pulse to      decphase(three);
avoid settling delays                       rgpulse(pw,oph,rof1,0.0);
txphase(phase);                             decpulse(pp,three);
decphase(phase);                            This example changes the decoupler
dec2phase(phase);                           phase to 270° before the observe
                                            channel pulse so that it is stable for
dec3phase(phase);
                                            the decoupler pulse which comes
phase must be real time variable.           immediately after.
                                                            User Programming
                                                                        Varian NMR Systems

         Phase Cycling with Integer Math

Calculation of Exorcycle Phase               cycle = 0123 1230 2301 3012
                                         mod4(ct,v3);   /*v3=0123 0123 0123 0123*/

   Cycle = 0000111122223333              add(v1,v3,v3); /*v3=0123 1230 2301 3012*/
hlv(ct,v1); /*v1=0011223344556677*/
hlv(v1,v2); /*v2=0000 1111 2222 3333*/       cycle = 0202 1313 0202 1313
                                         mod2(ct,v4);   /*v4=0101 0101 0101 0101*/
                                         dbl(v4,v4);    /*v4=0202 0202 0202 0202*/
                                         mod4(v1,v5);   /*v5=0011 2233 0011 2233*/
                                         hlv(v5,v5);    /*v5=0000 1111 0000 1111*/

                                         add(v5,v4,v4); /*v4=0202 1313 0202 1313*/
                                                         User Programming
                                                                     Varian NMR Systems

                     REAL-TIME AP Tables

table name is assigned one of the       a. Tables can be used to store phase cycles,
variables t1 - t60                      arrays etc.
                                        b. Tables are associated with the variables
table name is separated from            t1-t60
statements                              c. The values stored must be integers in the
by = sign                               range -32767 to 32768
                                        Example:
elements are separated by white space        t1 = 1 2 3 0 2 3 0 1 3 0 1 2 0 1 2 3
                                        use in pulse sequence
                                             rgpulse(p1,t1,rof1,rof2);
                                                    User Programming
                                                             Varian NMR Systems

            Phase Tables within Sequence
static int phasecycle[8]={0,2,1,3,1,3,2,0};
{
.
.
.
settable(t3,8,phasecycle);

Phase tables within pulse sequence are best when phase cycling is known.
This usage is also “self-documenting”, not relying on external table.
Phase tables from ~/vnmrsys/tablib are good for determining phase cycle.
                                           User Programming
                                                Varian NMR Systems

Example Pulsesequence

  #include <standard.h>
  static int phasecycle[4] = {0, 2,1,3};
  pulsesequence()
  {
  status(A);
  hsdelay(d1);
  status(B);
  rgpulse(p1,zero,rof1,rof2);
  hsdelay(d2);
  status(C);
  settable(t1,4,phasecycle);
  rgpulse(pw,t1,rof1,rof2);
  setreceiver(t1);
  }
                                                User Programming
                                                          Varian NMR Systems

              Phase Table Summary

load table statements from text file…
loadtable(“ph1”);
         or
declare an integer array in a table within the pulsesequence…
static int ph1[8]={0,0,1,1,2,2,3,3};
       pulsesequence()
       {
       always
         settable(tablename,numelements,intarray);
         settable(t1,8,ph1);
setreceiver(tablename) -cycle the receiver using the named table
         setreceiver(t60);
                                       User Programming
                                                 Varian NMR Systems

Access to parameters/variables

variables known to VNMRJ do not have to be declared
to be used in a pulse sequence
    EXAMPLES
     alfa
     d1,d2,d3,d4
     dpwr
     tpwr
     pw, p1, pw90,.. Many more.
variables unknown to VNMRJ have to be declared
before use in a pulse sequence
                                                      User Programming
                                                                Varian NMR Systems

                 Access to Parameters
declared variables must be retrieved by the pulse sequence.


getval("parametername") - retrieves the value of the non-string parameter
parametername and makes it available in the pulse sequence. Syntax is
internalname=getval("parametername").
This is very important for parameters created for the experiment. For example
in the DEPT pulse sequence the parameter j1xh must be created and retrieved
for use by the pulse sequence.
example:            j1xh = getval("j1xh");
                                                           User Programming
                                                                      Varian NMR Systems

                  Example Pulse Sequence
#include <standard.h>
{
    double jhh;     /*declare the variable jhh*/
    jhh = getval("jhh");     /*retrieve the variable*/
    d3=1/(2.0*jhh);     /*calculate a fixed delay using known variable d3 and jhh*/
    mod4(ct,v1);          /*v1 = 0123*/
    mod2(ct,v2);        /*v2 = 0101*/
    dbl(v1,v2);            /*v2 = 0202*/
    delay(d1);            /*d1 is a known variable*/
    pulse(pw,v1);      /*pw is known, v1 real time variable*/
    delay(1/2.0*jhh);     /*directly calculate delay*/
    pulse(2.0*pw,zero);    /*calculate a 180*/
    delay(d3);       /*use previously calculated delay*/
}
                                        User Programming
                                             Varian NMR Systems

                         Exercise

Write the following pulse sequence:
    delay - 90 - delay -180 - acquire

    with phases:
    180 degree pulse = X
    90 = 3201 3201 3201 3201
    Receiver = 1230 1230 1230 1230
                                        User Programming
                                                Varian NMR Systems

               Exercise

Write the phase sensitive homonuclear 2D pulse sequence
pecosy.
d1 - 90(ph1) - t1 - 35(ph2) - acquire [even transients]
d1 - 90(ph1) - t1 - delaypw90time - acquire [odd transients]
Ph1 = 0 0 0 0 2 2 2 2 1 1 1 1 3 3 3 3
Ph2 = 0 2 2 0 0 2 2 0 1 3 3 1 1 3 3 1
Rec = 0 2 0 2 2 0 2 0 1 3 1 3 3 1 3 1
                                                                User Programming
                                                                         Varian NMR Systems

       PECOSY - declare variables
4 errors.. Let‟s compile and see what happens!
/* primitive ecosy.c - L. Mueller J.Magn. Reson. 72,191-196 (1987).


Version 1.0 phases are as implemented by Nemeth and Cheatham MRC 91 */
#include <standard.h>


static int    ph1[16] = {0,0,0,0,2,2,2,2,1,1,1,1,3,3,3,3},
              ph2[16] = {0,2,2,0,0,2,2,0,1,3,3,1,1,3,3,1},
              recph[16] = {0,2,0,2,2,0,2,0,1,3,1,3,3,1,3,1};
pulsesequence()
{
double sstrim;
int iphase;


sstrim = getval("sstrim");
phase = getval("phase")
iphase = (int) (phase + 0.5);
                                                             User Programming
                                                                  Varian NMR Systems

PECOSY Calculations & sspulse
mod2(ct,v10); /* 0101... counter for phase compensation */


settable(t1,16,ph1);
settable(t2,16,ph2);
settable(t3,16,ph3);


getelem(t1, ct, v1);


if (iphase == 2) /* hypercomplex F1 quadrature */
incr(v1);


if (sstrim != 0.0)
 {
    rgpulse(sstrim,zero,2.0e-6,2.0e-6);
    rgpulse(sstrim,one,1.0e-6,2.0e-5);
}
                                                                       User Programming
                                                                              Varian NMR Systems

       PECOSY - finish pulsesequence
status(A);
hsdelay(d1);


rgpulse(p1, v1, rof1,2.0e-6);
status(B);
delay(d2);
ifzero(v10);
rgpulse(pw, t2, 0.0, rof1); /* use pw=35 degrees for measuring couplings */
elsenz(v10);
delay(pw + rof1); /* compensate phase between diagonal and crosspeaks */
endif(v10);
setreceiver(t3);
status(C);
rcvron(); delay(rof1);
}
                                                    User Programming
                                                              Varian NMR Systems

             Channel Independence

INOVA, UNITY+, VNMRS

Provided that only obspower, decpower etc. are used, generalized rf
channel remapping is available through the parameter rfchannel
    Example
    rfchannel=„213‟ makes ch 2 observe, ch 1 decouple and ch 3 the
    2nd decoupler

    (Typically the case for Indirect detection experiments in modern
    spectrometers with 1H-only 2nd channel.)
                                                         User Programming
                                                                  Varian NMR Systems

                   HARDWARE Looping

Hardware loop capability depends on type of acquisition hardware used on the
system.
    i. Output boards - limited hardlooping - 63 events

    ii. Acquisition controller boards - 1024 events

    iii. Unity plus/INOVA Pulse Sequence Generation boards     - 2048 events


    iv. VNMRS – no distinction between hardware and software looping
                  hardloop statements are executed as software loops
                                               User Programming
                                                          Varian NMR Systems

HARDWARE Looping (U+ and INOVA)

Events
   An event is a single activation of the timing circuit
   Time bases: 25ns (U, U+), 1µs, 1ms, 1sec, 12.5 ns (INOVA)
   maximum of two time bases per delay
   counter goes from 2 to 4095 for each time base

   Example a 35µs pulse is 1 event: 350 counts on 0.1µs time base

   example a 542.4µs is 2 events: 542 counts on 1µs time base, 4
   counts in .1µs time base
                                                            User Programming
                                                                       Varian NMR Systems

                      HARDWARE Looping

starthardloop(numberofrepetitions)              v. the maximum number of points that
                                                can be acquired within a hard loop is
endhardloop()
                                                     63 for output board
    i. only pulses, delays, acquires allowed         1024 for Aqc control board
    ii. No nesting                                   2048 for Pulse Seq. Controller
    iii. number of repetitions must be a real
    time variable                               Example
    iv. for output boards it is usually         initval(loops,v3);
    necessary to insert a short delay (0.2e-
                                                starthardloop(v3);
    6sec) between one endhardloop and a
    second starthardloop
                                                endhardloop();
                                                     User Programming
                                                               Varian NMR Systems

HARDWARE Looping-Explicit Acquisition

  Basic explicit acquisition sequence using hardlooping that permits other
  statements during acquisition:


  delay(alfa+1.0/(beta*fb));           /*beta delay for receiver*/
  initval(np/2,v9);
  starthardloop(v9);
  acquire(2.0,1.0/sw);
  endhardloop();
                                                         User Programming
                                                                       Varian NMR Systems

                       Pulse Field Gradients

rgradient(gradient,amplitude)                zgradpulse(amplitude,width)
 gradient is coil direction (usually 'z„)        gives a pulse-like element for z-
                                                 axis pfg gradient pulses.
 amplitude is between 32K and -32K
                                                 amplitude is within ±32K
 This is used when psg statements are
                                                 width is in seconds
 used during gradient, or when gradient is
 along x or y directions.                    Example
Example
                                                 zgradpulse(gzlvl1,gt1);
    rgradient(„z‟,4000);
    delay(gt1);
    rgradient(„z‟,2000);
    delay(gt2);
    rgradient(„z‟,0.0);
                                         User Programming
                                                  Varian NMR Systems

Pulse Sequences: A Closer look


psg - contains source code for statements
header (xx.h) files contain constants and definitions
example: apdelay.h - times for ap delays

/vnmr/psg
                                                 User Programming
                                                           Varian NMR Systems

                  New Functions

New functions can be created in psg as xxx.c and referenced as an
include file.

These functions may be coded directly into the sequence or placed on top
of pulse sequence as an include statement.


#include <standard.h>
#include <myroutine.c>
                                                        User Programming
                                                                  Varian NMR Systems

                 Small Angle Phase Shifts

stepsize(base,device);
    sets the step size of the s.a.phase shift   obsstepsize(30.0);
    stepsize(60.0,TODEV); /*60 degree           decstepsize(45.0);
    step size for obs xmtr*/
                                                dec2stepsize(60.0); etc..
    This does function, but now replaced!
                                                User Programming
                                                        Varian NMR Systems

       Small Angle Phase Shifts

EXAMPLE
obsstepsize(60.0);
initval(6.0,v1);
modn(ct,v1,v2); /*v2 = 012345012345*/
xmtrphase(v2); /*phase = 0,60,120,180,240,300*/
     carry over = 0,0,90,180,180,270
mod4(ct,v3);
pulse(pw,v3);      /*specified phase = 0,90,180,270*/
     actual = 0,90,270,450,180,360
     actual = specified + carry over
                                                       User Programming
                                                                  Varian NMR Systems

            Small Angle Phase Shifts


xmtrphase(multiplier);                    If the product of (base*multiplier) is
                                          greater than 90, the sub-90 part of the
dcplrphase(multipler);
                                          phase is set by xmtrphase..
dcplr2phase(multiplier);


multiplier must be a real time variable
multiplier * base = phase
                                       User Programming
                                                Varian NMR Systems

           Pulse Shaping

Files are in shapelib

Files are simple text files with an extension

.RF – rf pulses
.DEC – decoupling or spin locks
.GRD - gradients
                     User Programming
                            Varian NMR Systems

Multifrequency excitation
                                              User Programming
                                                        Varian NMR Systems

 How to generate a shaped pulse?

Shaped pulse is a series of rectangular pulses with different
                  amplitude and/or phase
                                                     User Programming
                                                                   Varian NMR Systems

     How to generate a shaped pulse?


                            4096 linear steps over 60 dB

  Provide amplitude and                  RF transmitter/modulator
  phase information in a                                IF                  RF
                                         Amplitude
 “Table”. Drive amplitude                 Control
  and phase modulators
                                           Phase            Phase           LO
                                          Control          Modulator


Standard on ALL channels
                                                           0.25o steps (INOVA)
                                                           0.043o steps (VNMRS)
                                                 User Programming
                                                             Varian NMR Systems
   How to generate a shaped pulse?
              [INOVA]

Provide amplitude and phase information as a “Table” to a
                 Waveform Generator

Waveform Generator
                                     RF transmitter/modulator
        Duration                                    IF              RF
                                     Amplitude
                                      Control
        Amplitude

                                       Phase      Phase             LO
        Phase
                                      Control    Modulator

Transmitter Control


                    Optional for ALL channels
                                                   User Programming
                                                               Varian NMR Systems
     How to generate a shaped pulse?
                [VNMRS]

Amplitude and phase information are stored in the RF Controller


  RF Controller Memory
                                       RF transmitter/modulator
          Duration                                    IF              RF
                                       Amplitude
                                        Control
          Amplitude

                                         Phase      Phase             LO
          Phase
                                        Control    Modulator




                      Optional for ALL channels
                               User Programming
                                      Varian NMR Systems

              RF shape files


Phase   amplitude   duration   gate

…..     …..         …..        …..
…..     …..         …..        …..
                 User Programming
                      Varian NMR Systems
RF shape files
  [example]
                                     User Programming
                                            Varian NMR Systems

                   DEC shape files


tipangle   phase         amplitude   gate

…..        …..           …..         …..
…..        …..           …..         …..
                  User Programming
                       Varian NMR Systems
DEC shape files
  [example]
                                                User Programming
                                                          Varian NMR Systems

                      Pulse Shaping

RF PATTERNS .. .RF                 DECOUPLER PATTERNS.. .DEC


   Column 2 - amplitude                 Column 1 - Tip angle per element
   Column 1 - phase                     Column 2 - RF phase
   Column 3 - relative duration         Column 3 - Amplitude
   Column 4 - xmtr gate                 Column 4 - Transmitter gate



                    Gradient Patterns.. .GRD
                       column 1 - signed magnitude
                       column 2 - relative duration
                       column 3 - gating
                           User Programming
                                Varian NMR Systems

    Software Tools



   Pbox [Pandora‟s Box]

   Pulsetool

   MAGICAL macros
     convolute
     setpower
     attval
                                          User Programming
                                                  Varian NMR Systems

                         PBox



 Powerful tool to create pulse and decoupling patterns
 Menu driven
 Easy to use
 Integrated into VNMR environment
                               User Programming
                                    Varian NMR Systems

                 PBox

             [/vnmr/wavelib]
wavelib

excitation




inversion




decoupling
                                                           User Programming
                                                                 Varian NMR Systems



                 Shaped Decoupling
            [Execution] – programming issues
                            Using “status”

Programmed decoupling during status(C):
  dm = „nny‟
  dmm = „ccp‟
                                                    Get from Pbox generated
  dpwr = decoupling power
                                                         xxxxx.DEC file
  dmf = appropriate number
  dseq = „xxxxx‟
  dres = appropriate value
   dmf is “modulation frequency”
   dres – is the tip angle resolution in the decoupling shape
                                    User Programming
                                            Varian NMR Systems

         Pulse Shaping

obsprgoff
decprgoff
dec2prgoff

turn off programmable control of device
normally will also need xmtroff() as well
                                             User Programming
                                                     Varian NMR Systems

                      Pulse Shaping

obsprgon(name,pw90,tipangle_resol);
   start programmable control of xmtr
decprgon
dec2prgon
These statements will return an integer value of the number of 50 ns
ticks in 1 cycle of the pattern. Explicit gating of the relevant
transmitter is required.
Example
   int tix;
   tix=obsprgon(“mlev16”,pw90,tres);
   xmtron();
                                        User Programming
                                                    Varian NMR Systems



          Shaped Decoupling
      [Execution] – programming issues
              Using in the sequence

…..
decpower(xx);
decprgon(decseq.name, 1/decseq.dmf, decseq.dres);
decon();
delay(z);
decoff();
decprgoff();
decpower(yy);
…..
                                          User Programming
                                                    Varian NMR Systems



            Shaped Decoupling
        [Execution] – programming issues
  Using in the sequence [homonuclear decoupling]


…..
obspower(xx);
obsprgon(decseq.name, 1/decseq.dmf, decseq.dres);
xmtron();
delay(z);
xmtroff();
obsprgoff();
obspower(yy);
…..
                                                         User Programming
                                                                     Varian NMR Systems

                      Pulse Shaping

shaped_pulse(shape,width,phase,RG1,RG2);
decshaped_pulse(shape,width,phase,RG1,RG2);
simshaped_pulse(obsshape,decshape,obswidth,decwidth,obsphas
e,decphase,RG1,RG2);
sim3shapedpulse(obsshape,decshape,dec2shape,obswidth,decwid
th,dec2width,obsphase,decphase,dec2phase,RG1,RG2);


   setting one of the pulsewidths to 0.0 will yield a 2-pulse on any channel
   combination.
   Using “” in the shape name field will result in a normal rectangular pulse for
   that channel. This is useful when that channel does not have a waveform
   generator (INOVA), or when a normal rectangular pulse is desired.
                                     User Programming
                                             Varian NMR Systems

              Pulse Shaping

spinlock control
    spinlock(name,pw90,tipangle_resol,phase,ncycles);
    decspinlock
    dec2spinlock
    dec3spinlock
    Example
        spinlock(“mlev16”,pw90,tres,one,4);
                                                 User Programming
                                                           Varian NMR Systems

                    Pulse Shaping

Statements for AP Bus
These provide wfg capability for INOVA & Unity plus systems without a
waveform generator being used.
    apshaped_pulse(pattern,width,phase,power,phasetable,rg1,rg2);
    apshaped_decpulse
    apshaped_dec2pulse
    Example
         apshaped_pulse(“sinc”,pw,oph,t14,t9,rof1,rof2);
         Shaped_pulse, decshaped_pulse, etc..now do
         this automatically!!
                                                    User Programming
                                                         Varian NMR Systems
                 Excitation Sculpting
 [Double Pulse Field Gradient Spin Echo – DPFGSE]




                          DPFGSE



gradient



           Shaka, et. al., JACS, 117, 4199 (1995)
                                      User Programming
                                           Varian NMR Systems
    Excitation Sculpting
        [DPFGSE “operator”]




       D1                   D2




  G1        G1         G2        G2


Shaka, et. al., JACS, 117, 4199 (1995)
                                                      User Programming
                                                           Varian NMR Systems
                       Excitation Sculpting
                                   Features




 The “sculptured” bandwidth is the
  inversion profiles of the two pulses
 The phase of the “selected” resonance
                                                 D1             D2
  at the end of D2 is same as that at the
  beginning of D1
 All the transverse magnetizations
  outside the bandwidth are dephased
  by G1 and G2                              G1        G1   G2        G2
                                          User Programming
                                                   Varian NMR Systems

               Excitation Sculpting
                     Example: selexcit

d(GGTTGGTGTGGTTGG)




                                      H1‟ region


                          Base H region
                                   User Programming
                                        Varian NMR Systems
           Excitation Sculpting
            Application: NOESY1D




             DPFGSE            mix



gradient
                   User Programming
                        Varian NMR Systems
Excitation Sculpting
      NOESY1D
                                                     User Programming
                                                               Varian NMR Systems

                                IPA
Interactive Parameter Adjustment
    Only available on U+ and INOVA
    IPA allows adjustment of various pulse sequence attributes in acqi
    IPA is pulse sequence statement oriented rather than parameter oriented.
    Statements available are
         idelay - delay
         idecpulse, idecrgpulse - decoupler pulse
         iobspulse, ipulse, irgpulse - observe channel pulse
         ioffset - frequency offset
         ipwrf, ipwrm - fine power adjustment
    These statements may replace the normal equivalents without any overt
    change in go, however, when run in acqi (after gf) the same parameter is
    adjustable when IPA is selected.
    Note. The parameter value is not returned to VNMRJ.
                                                 User Programming
                                                              Varian NMR Systems
                         SpinCAD

SpinCAD is a graphical pulse sequence programming tool.


Drag and drop familiar NMR elements to make new pulse sequences.


SpinCAD allows direct setting of the spectrometer hardware.


SpinCAD enables control of up to EIGHT channels.


SpinCAD has not been implemented in VNMRS
                   User Programming
                            Varian NMR Systems
Starting SpinCAD
                   Type spincad on the command
                   line.
                   User Programming
                           Varian NMR Systems
Programming in SpinCAD
                    Drag a delay and drop in
                       the canvas.


                    Drag a pulse and drop next
                       to the delay.


                    The front of the pulse is
                       docked to the end of the
                       delay.


                    Keep adding elements until
                       the sequence is
                       completed.
                  User Programming
                               Varian NMR Systems
Spin-echo in SpinCAD
                       Drag & drop delay at the
                          start.
                       Next get a pulse. The front
                          of the pulse is docked
                          to the end of the delay.
                       Drag & drop another delay
                          next to the first pulse.
                       Drag & drop another pulse
                          in the middle of the
                          second delay.
                       Drag & drop acquire all
                          points.
               User Programming
                             Varian NMR Systems

SpinCAD vs C   #include <standard.h>
               static int phi1[4]={0,1,2,3},
               phi2[4]={1,2,3,0};
               Pulsesequence()
               {
               status(A);
               settable(t1,4,phi1);
               settable(t2,4,phi2);
               delay(d1);
               rgpulse(pw,t1,rof1,rof2);
               delay(d2/2.0-pw);
               rgpulse(2.0*pw,t2,rof1,rof2);
               delay(d2/2.0-pw);
               setreceiver(t1);
               status(B);
               }
                   User Programming
                          Varian NMR Systems

SpinCAD-Pull Down Menus
                      User Programming
                                Varian NMR Systems
Triple Resonance Experiments
                        Flexibility like in „c‟
                            programming.

                        There are several if
                           statements.

                        Receiver phase is selected
                           by the if statement flag
                           setting.

                        Uses 4 of the possible 8
                           channels.

                        Channel name can be
                           anything.
                     User Programming
                             Varian NMR Systems

More Than Triple Resonance
                      User Programming
                              Varian NMR Systems
Auto-Creation of Parameters
                 User Programming
                            Varian NMR Systems
Desktop Publishing

                     Graphics of the pulse
                     sequence can be created.


                     Shows sequence of the
                     events in the pulse scheme.
                                                User Programming
                                                          Varian NMR Systems

                      Magical II™
(MAGnetics Instrument Control and Analysis Language, version II.)



                    Syllabus
                        Macros
                        Menus
                        Parameters
                                       User Programming
                                                   Varian NMR Systems

                   Magical II macros

Basic Macro Programming       Very advanced features
Language Features
                                     read/write files
MAGICAL II supports
   tokens                            pattern searching
   variables                         pass variables
   expressions
   conditional statements            shell command access
   looping
                                                User Programming
                                                           Varian NMR Systems

                                tokens

identifiers -                        abort      endwhile      sqrt

name of command or variable
                                     abortoff   if            trunc


                                     aborton    mod           typeof
reserved words -
recognized in both upper and lower   and        not           then

case forms
                                     break      or            until


                                     do         repeat         while


                                     else       return


                                     endif      size
                                                  User Programming
                                                                Varian NMR Systems

                        tokens

constants - floating and string
operators -
    scientific               sqrt(), trunc(), typeof(),size()
     unary                             -
     multiplicative.         *, /, %, mod
     additive                +, -
     relational              <, >, <=, >=
     equality                =, <>
     logical                 not, and, or
     assignment.             =
                                                               User Programming
                                                                           Varian NMR Systems

                                     Variables

Global or External                      Local
                                        variables created within a macro and "belong" to
 available within a SPECIFIC            that macro exist only as long as the macro executes
experiment usually experimental
                                        begin with $ Examples $height, $freq, etc.
parameters, nt, at, etc.
                                        no variable declaration necessary
include : r1,r2,r3,r4,r5,r6,r7 and
n1,n2,n3                                EXCEPTION - when the first use of a string
                                        variable is the return argument from a
                                        procedure.
                                        $age=' ' input('Input your age: '):$age string
                                        input('Input your age: '):$age      real
                                                     User Programming
                                                                 Varian NMR Systems

                         macro arguments

Macro and program output:                 Example -
    A macro may return arguments to the
                                          peak:$height,$freq
    calling program using the return      The output of the peak program is
    statement. The calling program        captured in the local variables $height
    nominates the result parameters by    and $freq.

    specifying them after a :
                                          Both arguments are not needed, i.e.
                                          peak:$height is also correct.
                                              User Programming
                                                         Varian NMR Systems

              Macro arguments

Macro input

   arguments passed to a macro are referenced by $n where n is
   the argument number

   the number of arguments passed to the macro is referenced by
   the variable $#
                                           User Programming
                                                       Varian NMR Systems

            Expressions

mathematical
   d3=2*pw+rof2
   $average=($1+$2)/$#


boolean
   internally, false is defined to be 0.0, any other
   number is true.
                                                  User Programming
                                                          Varian NMR Systems

             Name Replacement

An identifier surrounded by curly braces, {}, results in the
identifier being replaced by its value.


EXAMPLE
    pw=20.0        "pw is equal to 20.0"
    $a='pw'        "$a is equal to the string 'pw'"
    $a={pw}        "$a is equal to 20.0"

ANOTHER EXAMPLE
    $cmd='wft'
    {$cmd}                   "do a wft”
                                                User Programming
                                                          Varian NMR Systems

                  Conditional Statements

if booleanexpressionistrue then   For each if there must be an endif !!
         dosomething endif
                                  nested if statements are allowed
if booleanexpressionistrue then
         dosomething
else
         dosomethingelse
endif
                                                                 User Programming
                                                                          Varian NMR Systems

                            Macro arguments

EXAMPLE: hetcon which sets contour             "hetcon(length) - length is length along f2
plot size for inverse heteronuclear            and height is f1”
correlation experiments. The macro
accepts an argument for length of f2 and
adjusts the height of the f1 dimension to be        trace='f2'
2/3 of this value.
                                                    wc=$1
                                                    wc2=$1*0.67
                                                    dconi


                                               hetcon(200) would produce a contour map
                                               200x134 mm
                                                        User Programming
                                                                    Varian NMR Systems

                 Macro arguments

Improved hetcon macro…
“hetcon(length, width) - if only 1 argument, height is 2/3 of length”
“Defaults to 180mm length”


if ($#=0) then $len=180 $hgt=0.67*$len endif
if ($#=1) then $len=$1 $hgt=0.67*$len endif
if ($#=2) then $len=$1 $hgt=$2 endif

trace=„f2‟ wc=$len wc2=$hgt sc=6 sc2=0 dconi
                                                User Programming
                                                              Varian NMR Systems

                 Macro example


Design a macro to setup plots of 1D spectra around on the top
or side of a 2D plot.


Make macro either plot to paper or file OR simply setup the
desired regions.
                                       Macro example User Programming
                                                                                       Varian NMR Systems

"getrefb - a macro to setup plot top and side
projections"                                         if (trace='f2') then

if ($# < 1) then                                     $sp=sp $wp=wp $sp1=sp1 $wp1=wp1

input('Enter exp# where the spectrum to go on TOP    endif
resides. '):$top
                                                     if (trace='f1') then
input('Enter exp # where the spectrum to go on the
                                                     $sp1=sp $wp1=wp $sp=sp1 $wp=wp1
SIDE resides. 0 for no side.. '):$side
                                                     endif
$1=$top
                                                     jexp($1) sc=$sc sc2=$sc2 wc=$wc wc2=$wc2
$2=$side
                                                     sp=$sp wp=$wp vp=0 ds
endif
                                                     if ($#=3) then pl('top') endif
if ($#=1) then
                                                     if ($2 <> 0) then
$2=0
                                                     jexp($2) sc=$sc sc2=$sc2 wc=$wc wc2=$wc2
endif
                                                     sp=$sp1 wp=$wp1 vp=0 ds
if ($#=3) then
                                                     if ($#=3) then pl('side') endif
if ($3='p') then $comd='page'
                                                     endif
else $comd='page($3)' endif
                                                     if ($#=3) then
endif
                                                     exec($comd)
$sc=sc $sc2=sc2 $wc2=wc2 $wc=wc
                                                     endif
                                                    User Programming
                                                               Varian NMR Systems

                                 loops

“while loop”                         Remember: If the boolean expression
     while booleanexpressionistrue   initially evaluates to false then the while
     do                              will not be executed even once. The
         something                   repeat statement always performs an
     endwhile                        action once.


“repeat loop”                        Always remember to avoid endless
     repeat                          loops!
         something
     until booleanexpr.is.true
                                             User Programming
                                                       Varian NMR Systems

            Example “maxpk”

"maxpk(first,last) - find the tallest peak in a series of spectra"
$first=$1
repeat
     select($1) peak:$ht
     if $1=$first
          then $maxht=$ht
     else
          if $ht>$maxht then $maxht=$ht
          endif
     endif
     $1=$1+1
until $1>$2
                                                        User Programming
                                                                  Varian NMR Systems

                      Macro Exercise

                                  "myprocess - a macro to process and display 1d or 2d
Design a macro to process and     data"
display either 1D or 2D data...
                                  rt($1)
                                  exists('ni','parameter'):$e


                                  if ($e=0) then
                                  wft f full vp=15 ds dc dscale
                                  endif


                                  if ($e=1) then
                                  wft2da f full dconi
                                  endif
                                                    User Programming
                                                              Varian NMR Systems

                          Unix Interaction

shell command allows execution of a        shell(command) executes the
                                           Unix command. The text window
Unix command.
                                           is stdout and stdin is null.
                                                 example -
    shell produces a "pop up" window             shell('df') "run Unix df
    for Unix. Unix commands can be               command and display in text
                                                 window"
    typed in this - they are executed in   shell(command):file does the
    foreground. VNMR operation is          same as above, except that the
    suspended until you exit (or ctrl/D)   output is redirected to <file>.
    from the window.
                                           shell(command+'&') runs in
                                           background
                                    User Programming
                                            Varian NMR Systems

            Macro Exercise


Create a macro to process and display an
entire directory of fids one after the other.
                                                              User Programming
                                                                        Varian NMR Systems

           Macro ftall Example p.1
"ftall - a macro to process and display an entire directory of fids "


exists('/vnmr/tmp/templace','file'):$e
if ($e=1) then
shell('rm -r /vnmr/tmp/templace'):$dum
endif


shell('mkdir /vnmr/tmp/templace; cp -r *.fid /vnmr/tmp/templace')
shell('cd /vnmr/tmp/templace ; ls > list'):$dum


cd('/vnmr/tmp/templace')
$file='list'
nrecords($file):$count
$numfids=$count-1        // list is also included in the file list
write('line3','Number of fids = %s',$numfids)
                                                  User Programming
                                                       Varian NMR Systems

     Macro ftall example p.2

lookup('file',$file)
$i=1
repeat
             lookup('read',1):$name
             if ($name <> 'list') then
                         myprocess($name)
             endif
             $i=$i+1
             write('line3','increment = %s',$i)
until ($i>$count)
cd
shell('rm -r /vnmr/tmp/templace')
                                                 User Programming
                                                       Varian NMR Systems

         Macro to read a file for parameter values
"testread is a macro that reads a file and reads lines and updates a
parameter"
 $file = '' $file = $1
write('line3','file name is = %s ',$file)
nrecords($file):$count
write('line3', '# of lines = %s',$count)
$i = 1
lookup('file',$file)
repeat
         lookup('read',1):$val
         write('line3', '%s value is =%s',$i,$val)
         d2[$i] = $val
         $i=$i+1
until $i > $count
da
                                                        User Programming
                                                                   Varian NMR Systems

                              Argument types

To determine the type of an argument           HINT: C-like logic statements
that is passed to a macro the typeof()         if athing then
operator is provided.                          doanastything
                                                   is equivalent to the statement
typeof() -
                                               if athing is not equal to 0 then
     returns false (zero) if the variable is
                                               doanastything
     real or does not exist.
                                               Remember that 0 is false, any
     returns true (one) if the variable is a
     string.                                   number other than 0 is true.
EXAMPLE
if typeof('$1') then doonenastything
                                                                User Programming
                                                                          Varian NMR Systems

                          Macro termination
return command

    terminates execution of a macro
    return(value1,value2,…) allows the macro to return a value to a calling macro.
    Example:
    “abs(value)- returns absolute value of a number”
    if $1 > 0 then return ($1) endif
    if $1 < 0 then return (-$1) endif
    Another macro that uses abs will have a syntax:
    abs($num):$absnum
abort command

    terminates execution of a macro and of all higher (calling) macros.
    takes no arguments.
                                            User Programming
                                                      Varian NMR Systems

     Execution Priorities

1. Command


2. users maclib directory


3. directory pointed to by maclibpath variable


4. directory pointed to by sysmaclibpath variable
  (e.g. sysmaclibpath=/vnmr/maclib/maclib.autotest)
5. system maclib directory
                 User Programming
                       Varian NMR Systems




VNMRJ Basic Concepts
                          User Programming
                               Varian NMR Systems

VNMRJ 1.1D - Experimental Interface
                             User Programming
                                  Varian NMR Systems
/vnmr/templates/vnmrj/interface
         User Programming
                Varian NMR Systems
ToolPanel.xml
                              User Programming
                                    Varian NMR Systems

/vnmr/templates/layout/default/TopPanel.xml
                           User Programming
                                 Varian NMR Systems

/vnmr/templates/layout/default
                                  User Programming
                                        Varian NMR Systems

       /vnmr/templates/layout/default
acq_action.xml




proc_action.xml
                      User Programming
                            Varian NMR Systems

/vnmr/walkup/templates/vnmrj/interface




     ToolPanel.xml for apptype=‘walkup’
                           User Programming
                                 Varian NMR Systems

/vnmr/adm/users/protocolListWalkup.xml




            protocolListWalkup.xml
                          User Programming
                                 Varian NMR Systems
vnmrj adm - Administrator tool
                                   User Programming
                                        Varian NMR Systems

           New Concepts
Protocol - strictly - an xml object.
Vnmrsys/templates/vnmrj/protocols.


Really - A collection of files
{parameters, sequence, xml object, macros}
                                                     User Programming
                                                              Varian NMR Systems

          Example Protocol : Carbon.xml

<template type="basic" name="Carbon" author="varian" investigator=""
  time_created="20040408T120000" apptype="std1d"
  application="liquids" scans="Carbon" seqfil="s2pul">
 <protocol title="Carbon" type="protocol">
  <action type="LIB" status="Ready" lock="off" title="Carbon"
exp="Carbon"
   time="10 min" macro="cqexp('Carbon','std1d')" data="" />
 </protocol>
</template>


You COULD just put your old-style Vnmr classic into the macro field.
                                                  User Programming
                                                          Varian NMR Systems

      Example Protocol as a macro only!!

<template type="basic" name="Carbon" author="varian" investigator=""
  time_created="20040408T120000" apptype="std1d"
  application="liquids" scans="Carbon" seqfil="s2pul">
 <protocol title="Carbon" type="protocol">
  <action type=”CMD" status="Ready" lock="off" title="Carbon"
exp="Carbon"
   time="10 min" macro=”mydarnmacro” data="" />
 </protocol>
</template>
                                            User Programming
                                                    Varian NMR Systems

               So.. What is different?


   By sorting experiments into groups of similar types,


                         APPTYPE


Setup and processing macros for specific experiments
virtually disappear!

				
DOCUMENT INFO