|
funkalicious 0.1
|
00001 /* 00002 ** wavefunc_max_change.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 Copyright (C) 2010 Joseph Pingenot 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Affero General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Affero General Public License for more details. 00018 00019 You should have received a copy of the GNU Affero General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 00022 ** Started on Wed Mar 3 16:24:09 2010 Johnny Q. Hacker 00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue 00024 */ 00025 00026 #include <stdio.h> 00027 #include <math.h> 00028 #include <glib-2.0/glib.h> 00029 #include <gio/gio.h> 00030 #include <libpostproc/lp_wavefunction.h> 00031 #include <libpostproc/unit_conversion.h> 00032 00033 int main(int argc, char** argv) { 00034 g_type_init(); 00035 if(argc != 3) { 00036 fprintf(stderr, "ERROR: only got %d arguments, but must have two: the names of two wavefunctions to compare!\n", argc); 00037 fprintf(stdout, "USAGE: %s a b\n", argv[0]); 00038 fprintf(stdout, "Returns the maximum difference in wave function probability densities between a and b as an absolute number (|b|^2 - |a|^2), and as a percentage of the average of a.\n"); 00039 return 1; 00040 } 00041 00042 GError *e = NULL; 00043 00044 char* wffa=argv[1]; 00045 char* wffb=argv[2]; 00046 00047 struct wavefunction a, b; 00048 a.file = g_file_new_for_commandline_arg(wffa); 00049 b.file = g_file_new_for_commandline_arg(wffb); 00050 b.charge = a.charge = +1.0; 00051 00052 /*This is kind of cumbersome, but it works right now. Perhaps I'll write a 00053 one-wf version at some point.*/ 00054 GList* la = g_list_append(NULL, &a); 00055 GList* lb = g_list_append(NULL, &b); 00056 00057 load_wavefunctions(la, &e); 00058 if(e != NULL) { 00059 fprintf(stderr, "ERROR: failed to load first wavefunction (%s): %s\n", wffa, e->message); 00060 return 4; 00061 } 00062 load_wavefunctions(lb, &e); 00063 if(e != NULL) { 00064 fprintf(stderr, "ERROR: failed to load first wavefunction (%s): %s\n", wffa, e->message); 00065 return 5; 00066 } 00067 00068 /*Verify dimensions.*/ 00069 if(a.N[0] != b.N[0]) { 00070 fprintf(stderr, "ERROR: wavefunction x dimensions are not identical! a.N[0]=%d b.N[0]=%d\n", a.N[0], b.N[0]); 00071 return 6; 00072 } 00073 if(a.N[1] != b.N[1]) { 00074 fprintf(stderr, "ERROR: wavefunction y dimensions are not identical! a.N[0]=%d b.N[0]=%d\n", a.N[1], b.N[1]); 00075 return 7; 00076 } 00077 if(a.N[2] != b.N[2]) { 00078 fprintf(stderr, "ERROR: wavefunction z dimensions are not identical! a.N[0]=%d b.N[0]=%d\n", a.N[2], b.N[2]); 00079 return 8; 00080 } 00081 00082 struct density *density_a = get_density_for_list_of_wavefunctions(la, &e); 00083 if(e != NULL) { 00084 fprintf(stderr, "ERROR: failed to process first wavefunction (%s): %s\n", wffa, e->message); 00085 return 2; 00086 } 00087 struct density* density_b = get_density_for_list_of_wavefunctions(lb, &e); 00088 if(e != NULL) { 00089 fprintf(stderr, "ERROR: failed to process second wavefunction (%s): %s\n", wffb, e->message); 00090 return 3; 00091 } 00092 00093 double delta; 00094 double max_delta = nan("Nan"); 00095 double avg_a = 0; 00096 double avg_b = 0; 00097 double avg_delta = 0; 00098 /*Values of a, b at the max delta point.*/ 00099 double bmax_del=0, amax_del=0; 00100 double aye=0, bee=0; 00101 int xmax=0, ymax=0, zmax=0; 00102 for(int k=0; k<density_a->N[2]; k++) { 00103 for(int j=0; j<density_a->N[1]; j++) { 00104 for(int i=0; i<density_a->N[0]; i++) { 00105 bee = density_b->storage[get_density_storage_index_(i, j, k, density_a->N[0], density_a->N[1])]; 00106 aye = density_a->storage[get_density_storage_index_(i, j, k, density_a->N[0], density_a->N[1])]; 00107 delta= bee - aye; 00108 //fprintf(stderr, "%d/%d/%d: %g\t%g\t%g\t%g\n", i, j, k, aye, bee, delta, max_delta); 00109 if(isnan(max_delta) || (fabs(delta) > fabs(max_delta))) { 00110 max_delta = delta; 00111 bmax_del = bee; 00112 amax_del = aye; 00113 xmax=i; 00114 ymax=j; 00115 zmax=k; 00116 } 00117 avg_delta += fabs(delta); 00118 avg_a += density_a->storage[get_density_storage_index_(i, j, k, density_a->N[0], density_a->N[1])]; 00119 avg_b += density_b->storage[get_density_storage_index_(i, j, k, density_b->N[0], density_b->N[1])]; 00120 } 00121 } 00122 } 00123 avg_a /= (density_a->N[0]*density_a->N[1]*density_a->N[2]); 00124 avg_b /= (density_b->N[0]*density_b->N[1]*density_b->N[2]); 00125 avg_delta /= (density_a->N[0]*density_a->N[1]*density_a->N[2]); 00126 printf("#max_delta\tavg_delta\ta@max\tb@max\t%%a@max\t%%b@max\t%% avg_a\t%%avg_b\t%%avg_delta\tix@max\tiy@max\tiz@max\tx@max(nm)\ty@max(nm\tz@max(nm)\n"); 00127 printf("%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%d\t%d\t%d\t%g\t%g\t%g\n", max_delta, avg_delta, amax_del, bmax_del, max_delta/amax_del, max_delta/bmax_del, max_delta/avg_a, max_delta/avg_b, max_delta/avg_delta, xmax, ymax, zmax, bohr_to_nm(xmax*density_a->dx[0]), bohr_to_nm(xmax*density_a->dx[1]), bohr_to_nm(xmax*density_a->dx[2])); 00128 return 0; 00129 }