Any way to export surfaces?

Sorry for asking yet another surface-related question. I really don’t want to give up on Avogadro since it seems so slick~

I was able to do all my modifications in the source code and visualize some complicated modified surface. Now: Is it possible to export that surface somehow? When I click File->Export->Molecule and select ‘Gaussian cube format’, it says that ‘Unable to find a suitable file writer for the selected format’.

Is it possible to export a surface in any way (rasterized or otherwise), e.g. in a cube file? I saw that chemical json is a thing … does that contain surface information and might be convertible to a cube?

Thanks again for the help!

1 Like

At the moment, we don’t write cube files unfortunately. If that’s useful to you, I can probably help you hack it into quantumio/gaussiancube.cpp.

The cjson files will include the data, but at the moment, not in a way to export to cube.

Beyond that, it seems like it would be useful to save the rasterized mesh - any particular format you prefer?

1 Like

Thanks for the reply!

I was looking around a bit for cjson-ready software, but there aren’t many other tools that use that format …?

Maybe I’m misunderstanding, but a rasterized mesh would be for instance a cube file, right? I like cubes the most because I have the most experience working with them. If you have an other format in mind, let me know. Essentially I want to create a normal density and a modified density and then compare the two by taking the difference, hence I need the rasterized files.

If you could help me or set me up to include a cube exporter into the quantumio/gaussiancube.cpp, that would be great!

I tried a few different things today (and/or rather: tried to understand what is going on in the quantumio part of the code.) It seems to me that what is required is sort of ‘reversing’ the read in part that is already there. For this, a bunch of getter methods would be needed to ‘replace’ the setter methods in the read in part (e.g. setPosition3d(pos) on line 95 would be replaced by a `getPosition3d() function, that then can be written into the out stream). As far as I can see though, none of these getter functions exist?

I’m not super proficient in C++ and as far as I see, there is no other file writer that makes it easy to copy and adapt some parts.

I don’t have a lot of time over the next few days, but I took an initial effort at it here:

In particular, if you tap on the “files changed” tab, you can see my modifications to gaussiancube.cpp. I think it needs some formatting work, but I haven’t had time to compare the output from the patch to real cube files. Feel free to take a look and go from there.

I’ll probably have some time on Monday or Tuesday to finish it. I can certainly provide advice / guidance in the meantime, but we have a “visit weekend” for incoming graduate students so I won’t have much time to write code / compile myself.

1 Like

I absolutely didn’t mean to transfer my hurry over to you, it will just take the time it takes.

I understand most of the code you wrote, thanks a bunch. I put a breaking point inside the write function but when I run the code in debug mode, it doesn’t stop anywhere inside the write function when I try and export as a *.cube but throws me an Open Babel Warning, that conversion didn’t succeed. So I assume that Avogadro doesn’t call the cube writer but automatically falls back on OB and tries to convert the file with it.

Whoops. Just pushed a quick change - to set the flag as ReadWrite in that pull request.

in gaussiancube.h:

    return ReadWrite | File | Stream | String;
1 Like

Ha, tiny amendment and it works, great!

So I found a few things to correct and produce a correct cube. One thing I couldn’t figure out:

  • You use atom.atomicNumber() to produce the atomic number but for me it generates ^H and ^A symbols for H2O (escape characters). Is this the right function or data type?

I will try to push my changes for the few finicky parts tomorrow. If you know the problem above from the top of your head, I can include it as well.

The finished cube looks like this (where the only thing I did manually was putting the atomic numbers.)

1 Like

Great!

Thanks - just saw this now. It needs a static_cast to an integer. To save memory with large molecules, the atomic number pretends to be a character (i.e., we’re not likely to see more than 255 elements).

    outStream << std::setw(3) << std::left << static_cast<int>(atom.atomicNumber())

If you aren’t able to push, feel free to put up your copy / diff on pastebin or GitHub Gist and I’ll take it from there.

I’ll look around - I know the cube format supports more than one cube, which I’ll sort out later.

1 Like