Customize software | Video tutorial to single-point calculation wrapper script (4/5)

Philip Zhu
41 followers
11 Video Views·Feb 11, 2025
Video tutorial to smart single-point calculation wrapper script. Github:
https://github.com/PhilipZhu/singlepoint-energy-batch
The last example shows the basic usage of the wrapper script using the default calculator ORCA.
But you may not want to use the same software for everything.
So, in this example, I will show you how to configure this wrapper script so that it can support any software that you want to use.
In this case, I will use Gaussian, for example, which is another electronic structure calculation software.
Here is an input file for Gaussian.
And since I have already have Gaussian installed on this computer, I can run this input.
And then it generated a log file.
And in this log file, we can see it generated a lot of things.
And this hf is the energy that we wanted.
It's the HF energy that we asked for.
So, we will customize this wrapper script to support Gaussian calculations, the HF calculations like this.
So here I have input.xyz, and also I have cloned the git report, same as before.
And if we run this and see the help message, you can see that the usage is that you run this executable with "-s",
and software.ini, where this software.ini will support the custom software.
And then you run input.xyz.
So we will write this software.ini for Gaussian.
This software.ini is a file that is sourced.
So it is also in bash, but it's just defining a few variables and a few functions that will recognize the format of your custom software.
And let's see.
The default software section near the beginning of this script can be copied as a template,
so that means we can this script and copy this section, the default software settings, until the end of this settings.
We just copy this and then create a software.ini file and paste it.
And we will delete some of the sections to simplify, to clean it up.
Okay, so this is basically copied from the source code.
This is the default software.
And basically, there are several sections.
These are the recommended definitions.
This variable, basically if you uncomment it, it will give you the directory of this software.ini path, which might be useful.
So you can keep it commented, but you can uncomment it if you need it.
And this software.ini's usage is not really mandatory.
If you want other people to use it, you should implement this.
If only you want to use it, it doesn't matter, as long as you know what you are doing.
And then, there are user definitions.
The whole sections, you can do whatever you want.
Define variables, load modules.
Then, there is a required variable definition.
You need to define three variables.
The executable for your input script, in this case, we are going to just define it as g09.
Because that is what we did here.
So, basically, our wrapper script will run this.
So, it will run g09.
And calculate the input file name.
This, actually, you can rename it as anything.
On the com file for Gaussian.
And then, this is the standard out.
So, this you can name it as a name.
Because your input is input.xyz.
And the software, the wrapper software will create an input file for each of these frames.
And name that input file as anything.com in the corresponding calculation folders.
In that calculation folder, it will run g09 and that input script.
And then, redirect the standard out to this file.
And that's it.
So, basically, for Gaussian, as you have noticed, when we run this, there is no standard output.
And it created a log file.
That means, this stdout is actually going to be empty.
Which doesn't matter, the file there.
But, it will create in the same folder called anything.log.
This is the file that will actually contain the energy that we wanted.
Now, here we have some required function definitions.
So, let's delete these, because all of these are for Borca.
We are going to rewrite all of these.
Split input.
The job of this split input is to generate input files for g09, for Gaussian.
So, basically, with the name format xxnnnn.
Which means, if you run split input with input.xyz.
Sure, it's not defined, but if you run that, it is supposed to create a file named xx1.
In this xx1, you will have a Gaussian input corresponding to this frame.
And it will create another file called xxx2, which corresponds to this frame.
You can name it xxx0002, doesn't matter.
It's suggested that it should be numbers.
You can have leading zeros, if it is convenient to do so.
But, it's better to keep it in numbers.
Because, it basically counts, this is the number 1 frame, number 2 frame.
So, keep it in numbers.
Let's finish looking at the other three scripts.
We need to also define a function that returns true or false based on whether this job is finished or not.
So, usually, this could be a simple grab line.
Because, if previous examples are the Gaussian input,
this normal termination, terminationGaussian09, is an indication that this Gaussian finished without issues.
Therefore, if you grab for this, in this config.log, it will return you something.
That means, what you can do is that grab for normal termination, grab for this.
Note that this is no longer stdout, since we have noted that the stdout will be empty.
So, anything.log will be needed.
Here, we are grabbing this normal termination from anything.log.
And then, wordCount, the line number, is not equal to zero.
That means, the number of lines that are found inside this log is not zero.
Which means, it has a line that has normal termination.
So, if this is true, then it indicates it's finished.
So, that's it for this function.
These temp files, in orca, there are some temp files that, after calculation, you want to remove.
And see that presence of temp files or the output files indicate another job might be running.
The description here is a little bit inaccurate, I think.
Ignore these two lines for now.
I think I might have to update this description later.
But, right now, these temp files will be removed after the job finishes.
So, you want to list all the file names that indicate it's a temp file, but Gaussian doesn't generate temp files.
So, just leave it like that.
Delete it and leave it like that.
And here, getResult.
getResult is a function that we use to collect energies.
So, how do we collect energies?
Let's go back to the examples of Gaussian input.
And we have this output.
So, we find that the energy we need is from this line.
So, we can grab for this.
So, we can grab for this and we want to remove everything from start to here.
So, from the start of the line, multiple characters until match this.
And we want to escape this special character.
So, we replace it with nothing.
So, that gives us from here to here.
So, we have replaced everything here with empty string and we get the remaining.
Now, we do the same thing for this RNST.
So, basically this script deletes this and deletes this.
So, the remaining part is the energy that we want.
So, this is the script that we want.
Paste it here.
However, we need to update this.
This is not config.log.
So, this should be able to grab from the output the energy value that is calculated from the function.
So, now these three functions are very easy to implement.
The most work is on these functions, the split input.
And remember that the job of split input of input.xy is to generate files named as xx01, xx02 for each of these strings.
So, since this is a little bit more involved, I will fast forward a little bit.
So, we can implement a function such like this.
We get the input xyz file name.
We get the number of atoms in each frame because the first line indicated the number of atoms in each frame.
Then we get the total number of lines.
We get the number of frames by dividing the total number of lines by number of atoms plus 2.
Because each frame has number of atoms of lines plus the comment line plus the first line.
So, it's number of atoms lines plus 2.
We get the number of frames.
So, based on the number of frames, we do a for loop.
Do a for loop from 1 to number of frames.
And in each of the frames, we generate a file called xx01, xx02.
And we get a head which we will prepare later.
And here is why this variable might be useful from here.
Because we can put this template head into the same folder as the script.
And then we can do the same as tail.
And in the middle, this will get the lines that contains these configurations.
If this is the first frame, it will get this.
If this is the second frame, it will get this.
And then we tell number of atoms which means that if this is the first frame, we get this.
And then we get the tail which just keeps these two lines.
So, we will get the structures in between the head and tail.
So, what this do is that this is the targeted input file that we needed.
And we want to prepare a head template that contains this information.
And we want to prepare a tail template that contains two empty lines required by Cauchy to terminate the program.
And then we insert these configurations from the frames.
So, that's a simple example for this system.
Of course, you can write a more advanced format conversion script using Fortran, Python and other things.
And you can call these Python scripts from these bash scripts as well.
So, this is just a simple example of this conversion.
So, now we prepare a head and a tail and we should be done.
So, let's see.
Head like this and tail, two empty lines.
And that should be done.
So, the software.ini should be able to find the head and then cap head.
And then, it should be able to grab, for each frame, grab the coordinate and then cap the two empty lines from.
And it will pipe it into a file named xx1, xx2.
So, let's test it.
So, we can run single point with s and then software.ini, input.xyz and see if it works.
Okay, now it works.
And you can see in this input.dir calculations, c1 is generated with anything.com and anything.log that we defined.
And we are able to grab this information.
So, that's an example of defining software.ini.
And the only involving part is defining this split input functions, which you could use AI to do it for new softwares.
You could also refer to several templates that I have already written inside here.
So, inside the template by software, all of these templates you can see are more advanced software.ini than what we have just written.
That's it for the examples of single point calculations.
