# Codes for post-processing Gaussian cube files?

I have generated MOs of a molecular system and I need to recreate its electronic density via $$\rho(r)=\sum_{A_i}|\psi_i(\mathbf{r})|^2$$ where $$A$$ is a set of occupied MOs. I am trying to do this via extracting each MO individually in Gaussian16 Cubegen utility:

cubegen 16 MO=$${i} input.fchk MO$${i}.cube


I am looking for post-processing codes which can manipulate gaussian cube data, i.e., square and summation, preferably in a batch-processing fashion. For the codes I know, Gaussian's Cubman can add only two cubes files at a time; another code has issues with Gaussian's MO cube file format. I tried to understand PySCF implementation, but I am not able to fully grasp it. If someone has a simpler, standalone implementation for such a code, please let me know in the answers below.

• +1. By the way, we have a GAUSSIAN Chat Room would you mind saying hello there so that we can have you there as a member of the chat room? Aug 1 '20 at 16:15
• Mathematica 12.3 has an option to load .cube files and turn them into the electronic orbitals plots: reference.wolfram.com/language/ref/format/Cube.html Sep 17 '21 at 7:27

## Multiwfn

Multiwfn is a great tool for cube file analysis and wfn file analysis that can probably do almost everything you want to do. It is capable of doing math between cube files, outputting that file and then continuing to do more math. I believe it also allows for custom formulas to be input into the source code in some straightforward way (I have never needed to) then use it for convenience.

• +1. I'm glad this problem got solved for the user so quickly! Maybe this is a question where we want to enforce this policy: mattermodeling.meta.stackexchange.com/a/126/5. In that case you can focus on one of Multiwfn or ASE and give someone else a chance at explaining ASE in more detail. Whatever rep you think you might lose due to only talking about Multiwfn, you'll gain from this becoming a Hot Network Question. Aug 1 '20 at 17:51
• If someone wants to provide a better explanation of either tool, I will expand either of mine and remove the one they do. I just wanted to provide a good answer for the moment with the two tools I have used for this purpose. Aug 1 '20 at 17:55
• @TristanMaxson Thanks for your answer. I checked Multiwfn options and its I/O seems to be in the same fashion as G16 (ex: sobereva.com/wfnbbs/viewtopic.php?id=157). I am not sure if Mutliwfn would allow batch processing of multiple cube files. I'll try the ASE option and let you know.
– mykd
Aug 1 '20 at 18:20
• What type of batch processing would you like to do exactly? Can you provide an example task that matches what you really would like to do as a batch process? Aug 1 '20 at 18:31
• @TristanMaxson For ex., I have ~200 cube files, so instead of sending arguments to code again and again, it would be really convenient if a list of relevant cube files could be directly parsed to the code without any further intervention from the user.
– mykd
Aug 1 '20 at 18:57

## TheoDORE

Dealing with cube files is fairly easy as long as they all have the same grid definition. A cube file is basically just a long vector of numbers and you can add and multiply them as you wish. You can for example check lib_util.py of the TheoDORE package. This might do what you want in a simple scriptable form. Maybe the lin_comb routine does what you want. Or you can write an analagous routine for adding squared values.

Why the need to reprocess .cube files, when you can

1. generate a cube straight away for the electron density with cubegen (see Density=Type in the cubegen documentation or
2. skip the cube files altogether and use the formatted checkpoint file for visualization, allowing an adaptable level of resolution and avoiding a huge amount of unnecessary storage?

There are a bunch of programs that can read Gaussian formatted checkpoint files, e.g. Avogadro and IQmol, and visualize loads of properties.

• Hi Susi, thanks for your response. I know I can use *.fchk file to visualize orbitals or electron density, but I need to use the cube files in a further procedure where I cannot use a *.fchk file. Hence, I was asking help for this roundabout way.
– mykd
Aug 3 '20 at 9:05
• Um, why couldn't you use fchk files in a further procedure? The fchk contains all the information a cube file does, and more, and in a much more compact form... You can reproduce cubes from fchk files, but not the other way around! Aug 3 '20 at 9:15
• Going further, I need to transform or change the contributions of MOs. to the electron density of the system. Plus I used Gaussian16 for testing purposes, but I might need to work to ORCA or NWchem as the situation demands. Across all the CompChem platforms the definition of *.cube file remains consistent and that's why I am using it. Also there is little to no description about the *.fchk format and its content, online or in Gaussian manual.
– mykd
Aug 3 '20 at 9:33
• Transforming orbitals is extremely simple if you have the orbital coefficient matrices, which are accessible in the checkpoint file, or from a number of programs such as Psi4 and PySCF straight via Python. Cube files are very bad for anything quantitative, since the resolution is insufficient for anything except well-bound valence electrons. Aug 4 '20 at 12:46
• Hi Susi, is there anyway I can discuss with you privately? I rather not fully explain what my final target is on a public forum.
– mykd
Aug 4 '20 at 14:02

You can enter an input file stream in gaussian cubman to add/subtract cube files. Eg. here is an input file named test.txt which has all answers to add two cube files (a.cube and b.cube) and gives an output sum.cube,

Add
a.cube
yes
b.cube
yes
sum.cube
yes


You can run this simply by entering,

cubman < test.txt


to get the required output.

You can write a batch script to run multiple operations.