1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
%clear
%clc
%% This is a testing code for our MATLAB PB solver
% It basically evaluates the residual AND absolute
% error between both the APBS and MATLAB electrostatic potential solutions.
% FOR VISUAL PORPUSE, IT ALSO GENERATES THE CORRESPONDING TWO PLOTS, ONE
% TO THE ABSOLUTE ERROR BETWEEN APBS AND MATLAB SOLUTIONS, AND THE OTHER
% FOR THE APBS AND THE MATLAB SOLUTION FOR THE ELECTROSTATIC POTENTIAL.
% IT ALSO write out THE ABSOLUTE ERROR DX FILE.
% WARNING!!!!!!!!!!!!!!! BEFORE USING IT:
% PLEASE, ADD THE PATH OF THE CORRESPONDING DX FILES FOR THE ELECTROSTATIC
% POTNETIAL SOLTIONS TO THE MATLAB SEARCH PATH
% AS IT IS DONE IN THE EXAMPLE PROVIDED IN THE NEXT TWO LINES
%MYPATH=handles.cinapbs;
%MYPATH2=handles.cinmapbs;
% COMMENT: NO MORE THAN THESE TWO DX FILES MUST BE IN SUCH DIRECTORY.
% YOU ARE DONE. NOW YOU ARE READY TO USE THIS CODE!!!!!! THANKS !!!!
% CALLED MATLAB FILES:
% data_parse.m (read dx files and convert them to data arrays)
% dx_export.m (convert data arrays to dx format)
% gridinf.m (read number of grid points, center of the grid and mesh size
% from input file)
diary ('MATLAB_screen.io')
disp('Welcome!!!!!!....')
disp(' ')
disp('This code will calculate the absolute and relative errors between the')
disp('MATLAB and APBS solutions of the PB equation....')
disp(' ')
%% Part 1. Read the data
disp('Reading the input files....')
% getting grid information
dime=handles.dime;
rmin=handles.rmin;
h=handles.h;
% reading electrostatic potential reference state generated by APBS
if strcmp(handles.apbsreference, '')==0
APBS_pot_ref=data_parse(handles.apbsreference,dime);
else
APBS_pot_ref=zeros(dime(1),dime(2),dime(3));
end
% reading electrostatic potential solvated state generated by APBS
if strcmp(handles.apbssolvated, '')==0
APBS_pot_solv=data_parse(handles.apbssolvated,dime);
else
APBS_pot_solv=zeros(dime(1),dime(2),dime(3));
end
% reading electrostatic potential reference state generated by MATLAB solver
if strcmp(handles.mapbsreference, '')==0
MATLAB_pot_ref=data_parse(handles.mapbsreference,dime);
else
MATLAB_pot_ref=zeros(dime(1),dime(2),dime(3));
end
% reading electrostatic potential solvated state generated by MATLAB solver
if strcmp(handles.mapbssolvated, '')==0
MATLAB_pot_solv=data_parse(handles.mapbssolvated,dime);
else
MATLAB_pot_solv=zeros(dime(1),dime(2),dime(3));
end
% Defining the reaction filed electostatic potential
MATLAB_pot=MATLAB_pot_solv-MATLAB_pot_ref;
APBS_pot=APBS_pot_solv-APBS_pot_ref;
disp('Done!....')
%% Part 3: Calculating the absolute error between the APBS and MATLAB solutions
diffe2=(APBS_pot-MATLAB_pot)./MATLAB_pot;
diffe=(APBS_pot-MATLAB_pot);
%
[me,ne,pe] = size(MATLAB_pot);
if me~=dime(1)||ne~=dime(2)||pe~=dime(3)
disp('mismatching dimensions')
return
end
[me,ne,pe] = size(APBS_pot);
if me~=dime(1)||ne~=dime(2)||pe~=dime(3)
disp('mismatching dimensions')
return
end
aberror=zeros(prod(dime),1);
relerror=zeros(prod(dime),1);
for i=1:dime(1)
for j=1:dime(2)
for k=1:dime(3)
pe=(k-1)*(dime(1))*(dime(2))+(j-1)*(dime(1))+i;
aberror(pe)=diffe(i,j,k);
relerror(pe)=diffe2(i,j,k);
end
end
end
% evaluating the absolute error along all the points on the grid
absolute_error=norm(aberror,2)
% evaluating the average absolute error as the rate between the abosulte error
%along all the points on the grid and the total number of grid points
average_absolute_error=absolute_error/numel(aberror)
% evaluating the relative error along all the points on the grid
relative_error=norm(relerror,2)
% evaluating the average relative error as the rate between the relative error
%along all the points on the grid and the total number of grid points
average_relative_error=relative_error/numel(relerror)
% calculating the absolute error at each point on the grid
relerror2=abs(diffe2);
aberror2=abs(diffe);
dirname='COMPARATIVE_ANALYSIS';
mkdir(handles.cout,dirname)
% checking if the user is working on a pc o unix platarform
kt = strfind(handles.cout, '/');
if numel(kt)>0
outpath=strcat(handles.cout,'/',dirname);
else
outpath=strcat(handles.cout,'\',dirname);
end
%% Part 4: Write out the absolute error in dx format
dxformat=aberror2;
namefile='Absolute Error between MATLAB and APBS solutions';
outputfile=strcat(namefile,'.dx');
run dx_export
movefile (outputfile,outpath)
%
dxformat=relerror2;
namefile='relative Error between MATLAB and APBS solutions';
outputfile=strcat(namefile,'.dx');
run dx_export
movefile (outputfile,outpath)
%
%% Part 5: Generating the surface Plots
disp('generating plots!....')
% potential surface
n=(dime(3)+1)/2;
% plotting the absolute error
name1='absolute_error';
plot1=surf(aberror2(:,:,n),'facecolor','interp');
saveas(plot1,name1,'fig');
movefile (strcat(name1,'.fig'),outpath)
saveas(gcf,strcat(name1,'.tiff'),'tiffn');
movefile (strcat(name1,'.tiff'),outpath)
% plotting the relative error
name3='relative_error';
plot1=surf(relerror2(:,:,n),'facecolor','interp');
saveas(plot1,name3,'fig');
movefile (strcat(name3,'.fig'),outpath)
saveas(gcf,strcat(name3,'.tiff'),'tiffn');
movefile (strcat(name3,'.tiff'),outpath)
figure
%plotting the electrostatic potential solutions
name2= strcat('matlab_pot','_and_','apbs_pot');
subplot(1,2,1)
surf(MATLAB_pot(:,:,n),'facecolor','interp');
subplot(1,2,2)
surf(APBS_pot(:,:,n),'facecolor','interp');
saveas(gcf,strcat(name2,'.fig'))
movefile (strcat(name2,'.fig'),outpath)
saveas(gcf,strcat(name2,'.tiff'),'tiffn');
movefile (strcat(name2,'.tiff'),outpath)
disp('Done!....')
disp('Thanks for using our code!!!!....')
%end
diary off
movefile ('MATLAB_screen.io', outpath)
clear
|