A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  
 
iNMR icon

Functions for Scripting

This page contains the Lua functions defined by iNMR. The embedded Lua interpreter also recognizes many standard functions and the default Lua libraries. You can easily add your own functions: write them into a file called Lua.init and specify (into the Preferences dialog) the name of the folder surrounding it. Your functions will be automatically loaded whenever you open the console.

The iNMR console is not a unix shell. Before using io.read() be sure to open an input stream (normally a file). Otherwise iNMR will hang. To get the keyboard input, use ask() instead.

 

A

abc()

Equivalent to the palette command to perform fully automated baseline correction.

absint()

Absolute Integrals: the values are not normalized.

acut( [min], [merge], [max_ratio], [DoCut] )

Performs automatic 1D integration. min = minimum number of points into each integral region; merge = amount, in ppm, that is added on both sides of each region; max_ratio = the allowed ratio between the most intense and the less intense integral; DoCut = if you want to perform automatic scale fragmentation (instead of integration), pass this optional Boolean value (pass true).

adj()

Equivalent to a double click: changes the amplification so that the highest peak fits exactly into the window.

heightperpix = amp( [factor] )

Amplifies the spectrum by the given factor. If factor < 1, a deamplification occurs. Use without arguments to redraw the spectrum (most of the console commands do not update the display!). Returns the height of a peak that would fill a single point on the spectrum.

aph( baseline_is_flat )

Automatic phase correction. Accepts a boolean argument. If "true", applies the more accurate metabolomic method.

arrow( fromX, from Y, toX, toY, options )

Creates an arrow (frequency label). Requires the first 4 parameters (in ppm units when they make sense).

string = ask( prompt )

Asks the user to enter a string. Returns the string. Ex:
x = ask "enter a number"
Lua performs automatic conversions from strings to numbers.

 

B

bidi( code_letter )

Family of 2D-related commands to change the plot mode. Possible Values for code_letter are:

  • A = Arrayed Plot
  • B = ChessBoard Plot
  • C = Contour Plot
  • W = Water Contour Plot
  • F = Fast Plot
  • S = Stacked Plot
  • Z = White-Washed Plot

bin( from, to, bin_size )

Performs binning in the specified region. All arguments are in ppm units.

bline( degree, filter[, partial] )

Performs a baseline correction by a Whittaker Smoother along X.

 

C

path = choosefile()

Standard Choose File dialog.

clear()

Clears the console history log.

table = clip( index )

Returns the given note as a table with fields named: kind, x, y, data. Arrows and frames also contain the additional fields xx and yy.

string = cliptext( [string] )

If a string is passed as parameter, it is moved onto the clipboard. Otherwise, if the clipboard contains any text, this function returns a copy of it.

closex()

Close Extract.

color( { r; g, b; } [, { r; g, b; } [, ...] ] )

Sets the main color or sets one or more gradient of colors in all open windows. In the latter case, check the console option “For All Windows”. Ex.:

red = {r=1; g=0; b=0;}
blue = {r=0; g=0; b=1;}
color( red )
color( red, blue ) -- creates a gradient across the windows
color{ r=0; g=0; b=0; } amp() -- makes the spectrum black
There is no limit to the number of colors you can pass to this command.

table = copy()

Returns the real data points into the selected region. The returned table contains the number of points into the 3 fields x, y and z and the single values into the elements [1] .. [x*y*z]. Ex.:

perm() -- makes permanent the 1D baseline correction
region( 4, 3 )
T = copy()
print( T.x ) -- prints the number of selected points
print( T[1] ) -- prints the height of the spectrum at 4 ppm

copylog()

Copies into the clipboard the console history log.

cw( true / false )

An internal script (Custom Workflow) overrides the standard workflow. If the script is not found, no automatic processing is done.

 

D

window = dec([window, row/command])

The deconvolution windows can be created, closed and completely controlled with this single command. Find the description here.

delint()

Deletes all integrals.

 

E

exact()

Expands and shrinks the integral regions until their values are as near as possibe to the nearest integer.

export( “/absolute/path” )

Equivalent to the namesake menu command. It's an error if the file already exists. You can remove it with:
os.execute("rm -rf /absolute/path") You can open it with:
os.execute("open \"/absolute/path/plist.inmr\"")
or:
open "/absolute/path/plist.inmr"

extract( mode )

Equivalent to the namesake menu command. Available modes: 0 = extract (default), 1 = collapse; 2 = skyline.

 

F

fill( new_size[, use_LP] )

Sets a couple of FT parameters but performs no processing.

name, size = font( [fontname[, fontsize]] )

Sets and returns the font used for notes (not the one used for scales and integrals).

Boolean forall( [true / false] )

Sets and returns the value of the option “For All Documents”.

format “format_name”

Applies the specified format.

ft( swap, mirror, real, balanced )

Sets 4 Boolean options but performs no processing.

full()

Equivalent to the menu command with the same name.

 

G

table = getf([index] or [“x”/“y”/“z”])

Returns information about the specified dimension (default = X dimension). Ex.
t = getf(1) print( t.atom, t.mass, t.size, t.start, t.width, t.MHz, t.zero )
fy = getf(“y”)

[f1[, f2[, ...]] = getmarks([“h”])

Returns the ordered values of the vertical marks (horizontal if the optional parameter “h” is passed).

 

H

number = hat( x[, y[, z]])

Returns the intensity of the spectrum at the given ppm frequency.

hilbert()

Recreates the imaginary part.

 

I

area, left, right[, bottom, top[, Zmax, Zmin]] = intreg( index )
number = intreg( )
intreg( index, newvalue )

If invoked without arguments, returns the number of integrals. In invoked with a valid index (starting from 1) returns the value of the integral, followed by the limits of the integral region. If invoked with a non valid index, returns nil. If invoked with two values, changes the normalization factor.

 

J

 

K

 

L

 

M

magn(true/false)

Equivalent to the menu command “Magnitude”. Default = TRUE.

mark( [[“h”],][f1[, f2[, ... ]]] )

The first parameter can be “h” (to work on the horizontal marks). Otherwise omit this parameter to work on the vertical marks. The selected pool (vertical or horizontal) is deleted. New marks are created with the optional parameters that follows.

 

N

next_window()

After this command, all the operations are performed on the next window only.

noneg()

All negative points are set to zero.

nD, ft_index = numdim()

Returns the number of dimensions of the active spectrum and the index of the next dimension to be transformed (=0 if the spectrum is in frequency domain).

 

O

open( “/absolute/path” )

It's equivalent to dragging a folder or a file onto the iNMR icon.

ovadd( “/absolute/path”[, vert_offset, hor_offset, amplification )

Adds the document with the given path as overlay or changes the parameters of an existing overlay.

ovly( command )

Executes the given command with the Overlay Manager. The argument is a 4-letters command string, chosen from the following set: ALLW, SAME, AbsI, FitI, SORT, EDIT, BACO.

 

P

[width, height] = paper( [width, height] )

Changes the window size. Arguments in screen units. This handy command is ideal to set the size of bitmaps before creating them. If invoked without arguments, returns the dimensions of the topmost window.

paste( points )

Pastes the points into the selected region. The argument of this function is a table obtained with the command “copy” or any table in the same simple format. It is YOUR responsibility to ensure that the table and the selection have matching sizes. If the table is smaller than the selection, it is filled with zeroes. You can use “copy” and “paste” to sum a peak to another one. Passing the empty table is the way to set the selected data points to zero: “paste {}”.

string = pathtofile()

Returns the POSIX path to the original file (e.g.: “fid”) from which the current spectrum has been loaded. Ex.:
print( pathtofile() )

number = peak( )
x[, y[, z ]] = peak( index )

If invoked without arguments, returns the number of entries in the peak-picking list. In invoked with a valid index (starting from 1) returns the frequency(es) of the peak, in ppm units. If invoked with a non valid index, returns nil.

perm( )

Makes permanent the baseline correction in the selected range. If nothing is selected is like if everything is selected. This command lets you correct different spectral regions with different polynomials. Has no equivalent in the GUI.

ph0, ph1 = phase( ph0[, ph1] )

Sets or returns the phase correction parameters.

phrow( row[, ph0[, ph1]] )

Corrects the phase of a single row of a multidimensional spectrum. This command can be used only once per row, unless you reload the spectrum again.

picture( “/Users/home/path/to/file”, “type” )

Creates a picture file. Valid types are: “PDF ”, “PNGf”, “JPEG”, “TIFF”, “BMP ”, “PICT”. Mind the spaces after PDF and BMP!

poly( degree, filter[, partial] )

Performs a polynomial baseline correction along X.

predict( first, last, coefficients, base_points )

Performs Linear Prediction: “first” and “last” are in units of points.

press( code_letter )

Simulates the pressing of a keyboard key. Ex.:
region( 8, 6 ) press "z" -- expands the region from 8 to 6 ppm
press "\28" -- simulates the "left arrow" key

print( list, of, arguments, ... )

This is a handy Lua command!

 

Q

 

R

refer( center, max_distance )

Finds the maximum in the range center ± max_distance. Changes the scale reference so that the maximum falls exactly at “center”. Ex.:
refer( 7.26, 0.05 ) -- finds CDCl3 and adopts it as the reference
refer() -- equivalent to refer( 0 , 0.1 )
Works with 1D spectra only. max_distance is optional but, if given, must be positive.

region( left, right[, bottom, top[, Zmax, Zmin]] )

Selects a region for integration, zooming, cut...

reload()

Equivalent to the menu command with the same name. If an optional number is passed, and if it is zero, the reloaded FID is treated as a frequency domain spectrum. This change is permanent. The only way to undo it is the command "Revert to Saved".

resize( Xtable, Ytable[, Ztable] )

Changes the size of a multidimensional matrix. Must be followed by a paste() command if the matrix becomes larger. The parameters are of the same kind obtained by the command getf.

status = rkpp( true / false )

Turns ON/OFF the Rance-Kay pre-processing for 3-D Varian FIDs.

run "script name without .lua extension"

Runs a user defined script (a Lua program written by you). You specify the base path in the Preferences dialog and the rest of the path as the argument to “run”. Similar to the Lua function “dofile” (also working, but only with absolute paths).

 

S

setfid( [f1], [f2], [f3] )

Equivalent of the Metadata dialog, lets you override the built-in importers. f1, f2 and f3 are tables like those returned by getf().

string = shell( shell_command )

Runs a shell command and returns the standard output. [Mac only]

shift( amount[, index] )

Changes the scale reference by the specified amount (in ppm units). If you don't specify the dimension (1 for f1, 2 for f2...), the X axis is assumed.

shuffle( numeric_code )

Sets the shuffling protocol. 0 = none. 1 = phase sensitive. 2 = echo-antiecho.

simlist( )

Equivalent to the menu command: Simulate > List of Peaks.

small( first_pt, last_pt, f_index )

Extracts a submatrix from the spectrum. The new size will be: last_pt - first_pt. Repeat for each dimension. FIDs always start from point zero, even if the scale tells a different value.

name = solvent()

Returns the solvent name.

splitim( [2] )

Means: split interleaved matrix. Selects every other row of a 2-D matrix, in time domain. The other rows (in even positions) are removed. If the optional parameter 2 is added, the even rows are preserved and the odd rows removed.

straight()

Equivalent to the menu command “Straight Line”.

[n, x[], z[]] = stripes([n, x[], z[], δx])

For 3D spectra only, creates n stripes (if all the 4 parameters are given) or returns the corresponding parameters. x[] and z[] are the ppm coordinates of each stripe, δx is the width of each stripe. For the command to work, it is imperative to set x.M and z.M to the values of the isotopes corresponding to the x and z axes, e.g.: x.M = 1; z.M = 15.

suppress( selectivity[, ppm1[, ppm2...]] )

Suppresses the given frequency(es). Works in time domain only. If no frequency is specified, the transmitter position is assumed.

string = sys_slash( )

Returns “/” on the Mac and “\” on Windows.

 

T

table = target( [new_target] )

If invoked without arguments returns an array containing the active documents; if the option “for all documents” is deselected, the list will contain at most a single document. If invoked with an address, sets the active document.

text( “your note”, ppmX, Y[, unicode] )

Creates a new ASCII note at position [ppmX, Y]. Set the last optional parameter to TRUE if you want a Unicode note.

string = title( new_title )

Sets or returns the internal title (metadata).

number = todo( index )

Sets or returns the index of the next dimension to be transformed. Ex.:
old_index = todo()
todo( new_index )
-- do something...
todo( old_index ) -- always remember to restore the correct index !

Xindex, Yindex = transpose( [newXindex, newYindex] )

Transposes a 2D spectrum or, if you omit the arguments, returns the current indeces.

 

U

 

V

 

W

weight( exponential, gaussian, sine, sine_sqr )

Sets some FT parameters but does no processing. All arguments are optional.

wft( [weight[, transform[, hyperize ]]] )

Performs weighting, zero-filling and Fourier Transform. Accepts 3 optional Boolean arguments which, if set to false, skip part of the processing.

 

X

 

Y

 

Z