Scripting at all costs? No thanks

created: 1267985878|%e %B %Y, %H:%M
TAGS: scripting thoughts

python.png

Here some thoughts about scripting Vs manual donkey job. To clarify, is always better to do a script when we have to deal with repetitive tasks, such as file modification?
For instance, I usually have to work with gromacs and modify pdb files, topologies and other files, but I do this with Vi. why? Here my reasons.

Scripting is in general a good thing: allows to do things faster and better. In general. The downside is that to be valid, a script should be a good script, even in is a non-optimize code. And for "good" script I mean a well written bunch of lines of code: indented, commented, and flexible, both regarding the execution and the management of errors. This is an investment of time, which is good if we have always, exactly the same problem to solve, or the same task to do.

You have to calculate a distance between a list of coordinates? go with a script.
You have to do a sequence of bash command? do a script.
You have to read specific data from a well formatted file? go with a script.

You have to do something with data that vary from time to time or work with files that can have slightly different structures? Don't waste time with a script. It is much easier if we are the intelligent script rather than write one. So, we have just to find the right tools to to our job, in a fast and flexible way.

So, my idea is that when a script is starting to get an intricate sequence of if.. else if.. else ..for.. while… try… catch… etc. to try to deal with different type of input or output, better try to do by ourself the real thing, rather than waste weeks programming. For the well known Murphy's law, we will always find a situation in which our nice script of 100000 lines, fails.

So here we are, human scripts. boring, slow and likely to do mistakes. Or not? Likely, not… at least if you use linux and you are not afraid to learn a bit of bash and the supreme Vi. Here a practical example where having a script is totally useless:

Let's suppose I generate a polymer with my script and save it as pdb file. Now, I need to generate the Gromacs topology and I want to use pdb2gmx. Well, the pdb must then be adapted to the data in the Gromacs rtp file: atom names, residue names and residue numbers must be conveniently assigned, according to those in the rtp file. And all this, maintaining the pdb fix format. A script to do this should read the data in the rtp, understand where those data apply to the pdb file and modify the pdb in the proper way, keeping the right format. Rtp and pdb files can vary a lot from case to case and a script that will account for all the possibilities is out of reach. Much better do the things by our own, even if it seems a complicate (and boring) job. Nothing could be more wrong. Open your rtp in a vi terminal, open the pdb file in another and modify it using the substitution commands in vi and vi macros, defined on the fly. With a bit of experience, in 2 minutes a pdb of hundreds thousands of line is properly modified, ready to be used with pdb2gmx. ant 1min30sec will be used by vi… your job was finished after the first 30 sec:)

So, my idea is to do scripts when it is easy or difficult, but cannot be done otherwise in a simpler way. For the remaining cases, let your brain be the intelligent script, and manually use the powerful tools that are out there.

Bookmark and Share

Rate this post:

rating: 0+x

Comments: 0


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License