From 1988e119f26a356dede75c9a79132b11ea2c302d Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sat, 9 Sep 2023 23:02:12 -0400 Subject: [PATCH] plot_cubefile: adjusted grid spacing to include the cell edges --- src/madness/mra/funcplot.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/madness/mra/funcplot.h b/src/madness/mra/funcplot.h index 4b7e20def14..c6b919c2661 100644 --- a/src/madness/mra/funcplot.h +++ b/src/madness/mra/funcplot.h @@ -952,10 +952,15 @@ void plot_plane(World& world, const std::vector >& vfuncti fprintf(file,"%d %12.8f %12.8f %12.8f \n",int(molecular_info.size()), cell(0,0),cell(1,0),cell(2,0)); + // grid spacing for each dimension such that the cell edges are plotted + const auto xdelta = xlen/(npt[0]-1); + const auto ydelta = ylen/(npt[1]-1); + const auto zdelta = zlen/(npt[2]-1); + // print the cell constants - fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[0],xlen/npt[0],0.0,0.0); - fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[1],0.0,ylen/npt[1],0.0); - fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[2],0.0,0.0,zlen/npt[2]); + fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[0],xdelta,0.0,0.0); + fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[1],0.0,ydelta,0.0); + fprintf(file,"%d %12.6f %12.6f %12.6f\n",npt[2],0.0,0.0,zdelta); // print the molecule for (const std::string& s : molecular_info) fprintf(file,"%s",s.c_str()); @@ -966,9 +971,9 @@ void plot_plane(World& world, const std::vector >& vfuncti for (int i = 0; i < npt[0]; ++i) { for (int j = 0; j < npt[1]; ++j) { for (int k = 0; k < npt[2]; ++k) { - double x = cell(0, 0) + origin[0] + xlen / npt[0] * i; - double y = cell(1, 0) + origin[1] + ylen / npt[1] * j; - double z = cell(2, 0) + origin[2] + zlen / npt[2] * k; + double x = cell(0, 0) + origin[0] + xdelta * i; + double y = cell(1, 0) + origin[1] + ydelta * j; + double z = cell(2, 0) + origin[2] + zdelta * k; // the original format has up to 6 entries per line: https://paulbourke.net/dataformats/cube/ // stick with this, even though many codes can read an arbitrary number of entries per line if (count_per_line < 6) {