apbs icon indicating copy to clipboard operation
apbs copied to clipboard

Calculation of electric field

Open ESgit2021 opened this issue 3 years ago • 2 comments

Dear, I have a very simple system of highly charged sphere in ionic solution (1M). I would like to write out the gradient of the electrostatic potential (electric field) for the whole grid in all three directions. Following the example of the write out method for edens property (in the formula of which the gradient of the electric potential appears), I added a printout (in vpmg.c) to the src/mg code of three new properties, namely grad [0], grad [1], grad [2]. If I understand correctly in this way I get the gradient of the electric potential (which is equal to the electric field) in x, y and z directions. I’ve pasted the piece of code below to do this. I wonder if I understand the code correctly and in this way I get the gradient (electric field) in all three directions. case VDT_GRADX: grid = Vgrid_ctor(nx, ny, nz, hx, hy, hzed, xmin, ymin, zmin, thee->u);

        for (k=0; k<nz; k++) {
            for (j=0; j<ny; j++) {
                for (i=0; i<nx; i++) {

                    position[0] = i*hx + xmin;
                    position[1] = j*hy + ymin;
                    position[2] = k*hzed + zmin;
                    VASSERT(Vgrid_gradient(grid, position, grad));
                    /*eps = epsp + (epss-epsp)*Vacc_molAcc(acc, position,
                      pbe->solventRadius);*/
                    /*Vnm_print(2, "Vpmg_setPart:  gradient = (%g, %g, %g)\n",
                    grad[0], grad[1], grad[2]);*/
                    vec[IJK(i,j,k)] = grad[0];
                    /*vec[IJK(i,j,k)] = grad[1];
                    vec[IJK(i,j,k)] = grad[2];*/
                    
                    /*for (l=0; l<3; l++)*/
                      /*Vnm_print(2, "here edens\n");*/
                      /*vec[IJK(i,j,k)] += eps*VSQR(grad[l]);*/
                      /*vec[IJK(i,j,k)] += VSQR(grad[l]);*/
                }
            }
        }
        Vgrid_dtor(&grid);
        break;

Best regards, Ema

ESgit2021 avatar Sep 27 '21 12:09 ESgit2021

Is this code https://github.com/Electrostatics/apbs/blob/34fd2bbacb84e1289490fe746ba0cc7553a23ce2/src/mg/vgrid.c#L379 what you're looking for?

sobolevnrm avatar Sep 27 '21 12:09 sobolevnrm

Yes, i want to calculate the gradient of elec. potential on all points of a grid. So I figure this is the part of the code, (in vgrid.c) where it is calculated and i call this values (so gradient of potential on all points of the grid) into the vpmg.c to write it out with the same procedure as other features are written out (edens, ndens, qdens,...). So I already corrected all the other parts of the code, and i get three files which represent gradient calculated in three directions. I would just like to check that i call the correct part of the code, so I really get printed out the gradient of electrostatic potential (so electric field) on all points of a grid. Best

ESgit2021 avatar Sep 27 '21 12:09 ESgit2021