Friday, 17 December 2010

using "tee" for interactive input generation

Here is just a little rather simple thing which took me a long time to find out.

The question was: If you have a program that needs interactive input generation, can you still create something like an input file? The motivation was mainly the define program of Turbomole. Assuming you have 100 molecules (or structures of one molecule) and you want to do the same type of calculation on all of them. Running define for 100 times is not really the most exciting option. So what can you do?

You run
tee define.in | define
on the first molecule and use the interactive input facility. The file define.in will contain your input.

For the next 99 molecules you can just use
define < define.in > define.out
in any kind of loop structure (using separate directories for each job).

In that fashion you had the advantages of an interactive input generator but you are still able to automatize things.

5 comments:

Frank Uhlig said...

Very nice, never considered doing this with 'tee'. Thanks.

Just fyi, it can be very bothering to work with define, because you are not able to edit your input lines. By using rlwrap (a readline wrapper) you can edit your input line, have tab-completion and create a history.
rlwrap is afaik included in the repos of the major LINUX distributions, thus easy to intall. If done so, it's just 'rlwrap define' and you're good to go...

Hope this is helpful for you,

cheers Frank

Felix said...

thanks, I'll try it out. but I haven't really understood yet what it does

Frank Uhlig said...

Okay, you called define and you're typing your input. Except for using backspace to delete some of the input, you can't really edit what you just typed. rlwrap uses the GNU readline library to take care of the latter task so that you are able to edit your keyboard input within define. Additionally, you have the possibility to create and edit a file named $HOME/.define_completions for the lazy people among us who enjoy tab-completion (this file just contains a list of words that will be used as options for completing your input)

There are also a .define_history and .definerc file for a history and default settings. Although I never used the latter one in any specific matter.

A somewhat analogous comparison would be sh vs bash (although not a very thorough comparison)

Hope that makes it more clear.

Felix said...

ok, i see.

for this specific purpose I wanted to avoid the interactive input alltogether and just type
"define < define.in"

but it is definitely a nice tool to have lrwrap in other cases. I often catch myself typing \tab and producing weird signs in the program...

Frank Uhlig said...

I realized and my idea was to use it in the first task, namely 'tee define.in | define'. So that you don't have any nasty symbols in define.in

What I realized just now is that this does _not_ work in conjunction with rlwrap.

Sorry for being a little bit overzealous here...