Generating cube files for density

I am trying to dump cube files using psi4.core.CubeProperties.compute_density() method in the python interface and it gives an error message regarding arguments types. The strange point is that while a psi4 matrix object is given it requests again for a psi4 matrix object.

psi4.core.CubeProperties.compute_density(wfn.Da())

TypeError: compute_density(): incompatible function arguments. The following argument types are supported:
1. (self: psi4.core.CubeProperties, D: psi::Matrix, key: str) → None

Invoked with: <psi4.core.Matrix object at 0x2ae0e5260720>

Any help will be appreciated.
Ehsan

There’s nothing strange about it; the error message tells you precisely what the problem is.

The function expects a second argument, key, which needs to be a string. This string tells Psi4 what kind of density you’re asking it to plot. Here, you want to send it the string "Da".

If I can ask, what properties are you trying to get? Most users shouldn’t need to use the psi4.core.CubeProperties object directly but should be able to use psi4.cubeprop(wfn), with the appropriate tasks set.

Thank you for your reply. Unfortunately, it does not work even by passing the second argument, which must be of the string type, let’s say here “Da”. Still, I find it strange because it shows the type of given arguments, which are exactly what the method expects, and the error message is only about the incompatibility of the type of arguments NOT the minimum number of required arguments (e.g. something like “TypeError: missing positional argument” is not displayed):
psi4.core.CubeProperties.compute_density(wfn.Da(), “Da”)
TypeError: compute_density(): incompatible function arguments. The following argument types are supported:
1. (self: psi4.core.CubeProperties, D: psi::Matrix, key: str) → None

Invoked with: <psi4.core.Matrix object at 0x2b1cf4ec5590>, ‘Da’

Concerning the use of psi4.cubeprop(wfn), it is possible to get the cube files from wfn with the python driver by using psi4.set_options({‘cubeprop_tasks’: [‘density’]}) instead of set cubeprop_tasks [‘density’], however I am looking for a way to directly get the cube files from a density matrix, or from densities on the grids. In principle, the most desirable thing for me is to plot densities on a grid of choice.

  1. “the error message is only about the incompatibility of the type of arguments NOT the minimum number of required arguments” This isn’t changeable, either practically or theoretically. The practical reason is that Psi4 uses a pre-existing library for this called pybind11. The only way it’s getting changed is if we change it in all of pybind, which isn’t practical. And even theoretically, it’s a bad idea. In this simple case, it’s perfectly clear that the number of arguments is wrong. In more general cases, it isn’t clear. The pybind interface allows us to define multiple signatures for a function, which may have different numbers of arguments. If psi4.Matrix alone has constructors which require between on to four arguments.
  2. Ah, I forgot a step. compute_density isn’t a static method. Create a CubeProperties object and then call its compute_density method. This is what the self argument is trying to tell us.
  3. Well, if you can create a CubicScalarGrid object, you could call the compute_density method on that to get the cube file you want. How comfortable are you in delving into the source code? This is not a standard feature, and I don’t have the time to walk you through it (as you can see from how late even this reply was).