/**************************************** Function name : paw_find_word Description : gives the location of the word in the file; if successfull returns 0 and places the file pointer right after the word; if fails returns 1 Return type : int Argument : char* my_word Argument : FILE *fp Author : Marat Valiev Date & Time : 1/7/99 3:58:25 PM ****************************************/ int paw_find_word(char* my_word, FILE *fp) { char *w; rewind(fp); w = paw_get_word(fp); if (strcmp(my_word,w)!=0) { rewind(fp); w = paw_get_word(fp); while ((w!=NIL) && (strcmp(my_word,w)!=0)) w = paw_get_word(fp); } if (w==NIL) { if (paw_debug()) printf("warning: %s section not found\n",my_word); return 1; } else { return 0; } }
/**************************************** Function name : paw_solve_pseudo_orbitals Description : Return type : void Author : Marat Valiev Date & Time : 5/15/00 ****************************************/ void paw_solve_pseudo_orbitals() { int i; int k; int i_end_point; int Ngrid; double scale; double *rgrid; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); for (i=0;i<= nbasis-1;i++) { i_end_point = paw_get_grid_index(1.2*r_orbital[i]); paw_solve_paw_scattering(orb_l[i], 3*r_orbital[i], e_ps[i], psi_ps[i],psi_ps_prime[i]); if (paw_debug()) printf("%d%s log derivative %le %le \n",prin_n[i],paw_spd_Name(orb_l[i]), psi_ps_prime[i][i_end_point]/(psi_ps[i][i_end_point]*rgrid[i_end_point]*paw_log_amesh_LogGrid()), phi0_prime[i][i_end_point]/(phi0[i][i_end_point]*rgrid[i_end_point]*paw_log_amesh_LogGrid())); /*rescale the orbitals*/ scale = phi_ps0[i][i_r_orbital[i]]/psi_ps[i][i_r_orbital[i]]; for (k=0;k<=i_end_point;++k) { psi_ps[i][k] = psi_ps[i][k]*scale; psi_ps_prime[i][k] = psi_ps_prime[i][k]*scale; } for (k=i_end_point+1;k<=Ngrid-1;++k) { psi_ps[i][k] = phi_ps0[i][k]; psi_ps_prime[i][k] = phi_ps0_prime[i][k]; } } }
/**************************************** Function name : generate_projectors Description : Return type : void Author : Marat Valiev Date & Time : 4/7/99 2:31:54 PM ****************************************/ void paw_generate_projectors() { int i; int j; double norm; double norm_error; if (strcmp(projector_method,"vanderbilt")==0) { paw_generate_projectors_vanderbilt(); } else if (strcmp(projector_method,"blochl")==0) { paw_generate_projectors_blochl(); } else { printf("error, unknown projector_method in generate_projectors \n"); exit(1); } /*Check paw basis orthogonality*/ norm_error = 0.0; for (i = 0; i <= nbasis-1; i++) { for (j = 0; j <= nbasis-1; j++) { if (orb_l[i] == orb_l[j]) { norm = paw_dot_product(prj_ps[i],phi_ps[j]); if (i==j) norm = norm - 1.0; if (fabs(norm) > norm_error) norm_error=fabs(norm); } } } if (paw_debug()) printf("paw basis is orthogonal to within %le \n",norm_error); projectors_done = True; }
/**************************************** Function name : paw_init_LogGrid Description : Return type : void Argument : double Z -> ion charge Argument : FILE *fp Author : Marat Valiev Date & Time : 1/7/99 4:26:57 PM ****************************************/ void paw_init_LogGrid_from_file( double Z, FILE *fp) { int i; char input[30]; strcpy(input,"<grid>"); if (paw_find_word(input,fp) != 0) { if (paw_debug()) printf("Using default parameters\n"); Lmax=25.0; amesh=1.005; log_amesh = log(amesh); r0 = r0Z/Z; Ngrid = (int) floor(log(Lmax/r0)/log_amesh)+1; } else { fscanf(fp,"%le",&Lmax); fscanf(fp,"%d", &Ngrid); fscanf(fp,"%le",&r0); log_amesh = log(Lmax/r0)/(Ngrid-1); amesh = exp(log_amesh); } Lmax = r0*pow(amesh,Ngrid-1); rgrid = paw_alloc_LogGrid(); rgrid2 = paw_alloc_LogGrid(); rgrid3 = paw_alloc_LogGrid(); scratch = paw_alloc_LogGrid(); /* define rgrid */ rgrid[0] = r0; for (i=1; i <= Ngrid-1; ++i) rgrid[i] = amesh*rgrid[i-1]; for (i=0; i <= Ngrid-1; ++i) { rgrid2[i] = rgrid[i]*rgrid[i]; rgrid3[i] = rgrid[i]*rgrid[i]*rgrid[i]; } }
void paw_print_paw_potential_to_file(char* atom_name) { int i; int j; int k; int Ngrid; int *prin_n; int * orb_l; double *rgrid; char data_filename[300]; char script_filename[300]; char nl_name[20]; FILE *fp; if (paw_debug()) { Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); prin_n = paw_get_pointer_paw_n_array(); orb_l = paw_get_pointer_paw_l_array(); sprintf(data_filename,"%s%s_pot.dat",paw_sdir(),atom_name); fp = fopen(data_filename,"w+"); for (k=0; k<=Ngrid-1; k++) { fprintf(fp,"%le\t%le\t%le", rgrid[k], V_ref[k], V_pseudo[k]); for (i=0; i<=nbasis-1; i++) fprintf(fp,"\t%le ",V_paw[i][k]); fprintf(fp,"\n"); } fclose(fp); sprintf(script_filename,"%s%s_ref_pot.plt",paw_sdir(),atom_name); fp = fopen(script_filename,"w+"); fprintf(fp,"set data style lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%f] \n",2*r_ref); fprintf(fp,"set grid \n"); fprintf(fp,"set nokey \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set title \" %s reference potential\n",atom_name); fprintf(fp,"plot \"%s\" using 1:2 \n",data_filename); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); sprintf(script_filename,"%s%s_loc_pot.plt",paw_sdir(),atom_name); fp = fopen(script_filename,"w+"); fprintf(fp,"set data style lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%f] \n",2*r_ref); fprintf(fp,"set grid \n"); fprintf(fp,"set nokey \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set title \" %s local potential\n",atom_name); fprintf(fp,"plot \"%s\" using 1:3 \n",data_filename); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); /*gnu script file */ for (i=0,j=4; i<=nbasis-1; i++,j=j+1) { sprintf(nl_name,"%d%s",prin_n[i],paw_spd_Name(orb_l[i])); sprintf(script_filename,"%s%s_%s_pot.plt",paw_sdir(),atom_name,nl_name); fp = fopen(script_filename,"w+"); fprintf(fp,"set data style lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%f] \n",1.5*r_potential[i]); fprintf(fp,"set grid \n"); fprintf(fp,"set nokey \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set title \" %s paw potential for %s orbital\" \n", atom_name,nl_name); fprintf(fp,"plot \"%s\" using 1:%d \n",data_filename,j); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); } } }
/**************************************** Function name : paw_generate_pseudopot Description : Return type : void Author : Marat Valiev Date & Time : 4/10/99 7:40:00 PM ****************************************/ void paw_generate_pseudopot() { int k; int Ngrid; double charge; double ps_charge; double Z; double *Vh; double *Vx; double *Vc; double *rho; double *rho_ps; double *rho_core; double *rho_core_ps; double *full_density; double *full_ps_density; double* V_comp; double *rgrid; FILE *fp; char data_filename[300]; if ( !(paw_projectors_are_done()) ) { printf("error, pseudopotential cannot be generated "); printf(" because projectors have not been yet \n"); exit(1); } Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); Vh = paw_alloc_LogGrid(); Vx = paw_alloc_LogGrid(); Vc = paw_alloc_LogGrid(); full_density = paw_alloc_LogGrid(); full_ps_density = paw_alloc_LogGrid(); Z = paw_get_ion_charge(); paw_set_core(); /*get densities*/ rho = paw_get_pointer_paw_density(); rho_ps = paw_get_pointer_paw_ps_density(); rho_core = paw_get_pointer_core_density(); rho_core_ps = paw_get_pointer_ps_core_density(); paw_Zero_LogGrid(full_density); paw_Zero_LogGrid(full_ps_density); for (k=0;k<=Ngrid-1;k++) { full_density[k] = rho[k] + rho_core[k]; full_ps_density[k] = rho_ps[k] + rho_core_ps[k]; } charge = paw_Integrate_LogGrid(full_density); ps_charge = paw_Integrate_LogGrid(full_ps_density); V_comp = paw_find_comp_charge_potential(Z,charge,ps_charge); paw_generate_hartree_pot(full_ps_density); Vh = paw_get_hartree_pot(); paw_generate_exchange_pot_LDA(full_ps_density); Vx = paw_get_exchange_potential(); paw_generate_corr_pot_LDA(full_ps_density); Vc = paw_get_corr_pot_LDA(); /*form pseudopotential*/ for (k=0;k<=Ngrid-1;k++) { V_pseudo[k] = V_ref[k] - Vh[k]- V_comp[k]- Vc[k] - Vx[k]; } if (paw_debug()) { sprintf(data_filename,"%sdensity",paw_sdir()); fp = fopen(data_filename,"w"); for (k=0;k<Ngrid;++k) fprintf(fp,"%f %f %f\n",rgrid[k],rho[k] - rho_ps[k],V_pseudo[k]); fclose(fp); } paw_dealloc_LogGrid(full_density); paw_dealloc_LogGrid(full_ps_density); }
void paw_generate_projectors_blochl() { int i; int j; int k; int Ngrid; double norm; double max_prj; double max_phi; double max_phi_ps; double tmp_prj; double *V_ref; double *V; double *rgrid; double **b; double **L; double **U; double **L_inv; double **U_inv; double **test_matrix; char output[300]; FILE *fp; /*make sure the pseudo orbitalas were found*/ if (! pseudo_orbitals_done) { printf("cannot calculate projectors\n"); printf("pseudo basis is not ready\n"); exit(1); } Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); b = paw_alloc_2d_array(nbasis,nbasis); L = paw_alloc_2d_array(nbasis,nbasis); L_inv = paw_alloc_2d_array(nbasis,nbasis); U = paw_alloc_2d_array(nbasis,nbasis); U_inv = paw_alloc_2d_array(nbasis,nbasis); test_matrix = paw_alloc_2d_array(nbasis,nbasis); /*obtain the ref potential*/ V_ref = paw_get_ref_pot(); /*form initial guess for projectors as in Blochl*/ for (i = 0; i < nbasis; ++i) { V = paw_get_paw_potential(i); for (k = 0; k < Ngrid; ++k) prj_ps[i][k] = (V_ref[k] - V[k])*phi_ps[i][k]; if (paw_debug()) { sprintf(output, "%s%s_%d%d", paw_sdir(),"p",prin_n[i],orb_l[i]); fp = fopen(output, "w+"); for (k = 0; k < Ngrid; ++k) { fprintf(fp, "%le\t %le\t %le \n", rgrid[k], prj_ps[i][k],(V_ref[k] - V[k])); } fclose(fp); } } /*check for accidental null projectors*/ for (i = 0; i < nbasis; ++i) { max_prj = 0.0; for (k = 0; k < Ngrid; ++k) { tmp_prj = fabs(prj_ps[i][k]); if (tmp_prj > max_prj) max_prj = tmp_prj; } if (max_prj <0.000001) { printf("found null projectors, aborting the program ... \n"); exit(1); } } for (i=0;i<=nbasis-1;i++) { for (j=0;j<=nbasis-1;j++) { if (orb_l[i] == orb_l[j] ) { b[i][j] = paw_dot_product(phi_ps[j],prj_ps[i]); } else { b[i][j] = 0.0; } } } paw_lu_decompose(nbasis, b, L, U); paw_triang_matrix_inverse("l",nbasis,L,L_inv); paw_triang_matrix_inverse("u",nbasis,U,U_inv); for (i=0;i<=nbasis-1;i++) { for (k = 0; k <= Ngrid-1; k++) prj_ps0[i][k] = prj_ps[i][k]; } for (i=0;i<=nbasis-1;i++) { paw_Zero_LogGrid(prj_ps[i]); paw_Zero_LogGrid(phi[i]); paw_Zero_LogGrid(phi_ps[i]); paw_Zero_LogGrid(phi_prime[i]); paw_Zero_LogGrid(phi_ps_prime[i]); } for (i=0;i<=nbasis-1;i++) { for (j=0;j<=i;j++) { for (k = 0; k <= Ngrid-1; k++) { prj_ps[i][k] = prj_ps[i][k] + L_inv[i][j]*prj_ps0[j][k]; phi[i][k] = phi[i][k] + U_inv[j][i]*phi0[j][k]; phi_ps[i][k] = phi_ps[i][k] + U_inv[j][i]*phi_ps0[j][k]; phi_prime[i][k] = phi_prime[i][k] + U_inv[j][i]*phi0_prime[j][k]; phi_ps_prime[i][k] = phi_ps_prime[i][k] + U_inv[j][i]*phi_ps0_prime[j][k]; } } } for (i=0;i<=nbasis-1;i++) paw_Zero_LogGrid(prj_ps0[i]); for (i=0;i<=nbasis-1;i++) { for (j=0;j<=nbasis-1;j++) { for (k = 0; k <= Ngrid-1; k++) { prj_ps0[i][k] = prj_ps0[i][k] + U_inv[i][j]*prj_ps[j][k]; } } } /*rescale basis*/ for (i = 0; i <= nbasis-1; i++) { max_prj = 0.0; max_phi = 0.0; max_phi_ps = 0.0; for (k = 0; k < i_r_orbital[i]; k++) { if (max_prj < fabs(prj_ps[i][k])) max_prj = fabs(prj_ps[i][k]); if (max_phi_ps < fabs(phi_ps[i][k])) max_phi_ps = fabs(phi_ps[i][k]); } if (max_prj == 0.0 || max_phi_ps == 0.0) { printf("division by zero while rescaling basis\n"); exit(99); } norm = 0.75*sqrt(max_phi_ps/max_prj); max_prj = 0.0; max_phi = 0.0; max_phi_ps = 0.0; scaling_factor[i] = norm; for (k = 0; k < Ngrid; ++k) { prj_ps[i][k] = prj_ps[i][k]*norm; phi[i][k] = phi[i][k]/norm; phi_ps[i][k] = phi_ps[i][k]/norm; phi_prime[i][k] = phi_prime[i][k]/norm; phi_ps_prime[i][k] = phi_ps_prime[i][k]/norm; } } for (i = 0; i <= nbasis-1; i++) { for (j = 0; j <= nbasis-1; j++) { tr_matrix[i][j] = U_inv[i][j]; } } if (paw_debug()) printf("derivative=%f\n",phi_ps_prime[0][0]/(rgrid[0]*paw_log_amesh_LogGrid())); }
void paw_generate_projectors_vanderbilt() { int i; int j; int k; int Ngrid; double norm; double max_prj; double max_phi; double max_phi_ps; double tmp_prj; double *V_ref; double *V; double *rgrid; double **b; double **prj_ps0; char output[300]; FILE *fp; /*make sure the pseudo orbitalas were found*/ if (! pseudo_orbitals_done) { printf("cannot calculate projectors\n"); printf("pseudo basis is not ready\n"); exit(1); } Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); b = paw_alloc_2d_array(nbasis,nbasis); prj_ps0 = paw_alloc_2d_array(nbasis,Ngrid); /*obtain the ref potential*/ V_ref = paw_get_ref_pot(); /*form initial guess for projectors as in Blochl*/ for (i = 0; i < nbasis; ++i) { V = paw_get_paw_potential(i); for (k = 0; k < Ngrid; ++k) prj_ps[i][k] = (V_ref[k] - V[k])*phi_ps[i][k]; if (paw_debug()) { sprintf(output, "%s%s_%d%d", paw_sdir(),"p",prin_n[i],orb_l[i]); fp = fopen(output, "w+"); for (k = 0; k < Ngrid; ++k) { fprintf(fp, "%le\t %le\t %le \n", rgrid[k], prj_ps[i][k],(V_ref[k] - V[k])); } fclose(fp); } } /*check for accidental null projectors*/ for (i = 0; i < nbasis; ++i) { max_prj = 0.0; for (k = 0; k < Ngrid; ++k) { tmp_prj = fabs(prj_ps[i][k]); if (tmp_prj > max_prj) max_prj = tmp_prj; } if (max_prj <0.000001) { printf("found null projectors, aborting the program ... \n"); exit(1); } } for (i=0;i<=nbasis-1;i++) { for (j=0;j<=nbasis-1;j++) { if (orb_l[i] == orb_l[j] ) { b[i][j] = paw_dot_product(phi_ps[j],prj_ps[i]); } else { b[i][j] = 0.0; } } } paw_get_inverse(b,nbasis); for (i=0;i<=nbasis-1;i++) { for (k = 0; k <= Ngrid-1; k++) prj_ps0[i][k] = prj_ps[i][k]; } for (i=0;i<=nbasis-1;i++) { paw_Zero_LogGrid(prj_ps[i]); } for (i=0;i<=nbasis-1;i++) { for (j=0;j<=nbasis-1;j++) { for (k = 0; k <= Ngrid-1; k++) prj_ps[i][k] = prj_ps[i][k] + b[i][j]*prj_ps0[j][k]; } } for (i=0;i<=nbasis-1;i++) { norm = paw_dot_product(prj_ps[i],phi_ps[i]); if (fabs(norm) < SMALL) { printf("division by zero while normalizing prj_pss"); exit(99); } if (paw_debug()) printf("prj_ps norm=%le\n",norm); for (k = 0; k < Ngrid; ++k) prj_ps[i][k] = prj_ps[i][k]/norm; } /*rescale basis*/ for (i = 0; i <= nbasis-1; i++) { max_prj = 0.0; max_phi = 0.0; max_phi_ps = 0.0; for (k = 0; k < i_r_orbital[i]; k++) { if (max_prj < fabs(prj_ps[i][k])) max_prj = fabs(prj_ps[i][k]); if (max_phi_ps < fabs(phi_ps[i][k])) max_phi_ps = fabs(phi_ps[i][k]); } if (max_prj == 0.0 || max_phi_ps == 0.0) { printf("division by zero while rescaling basis\n"); exit(99); } norm = 0.75*sqrt(max_phi_ps/max_prj); max_prj = 0.0; max_phi = 0.0; max_phi_ps = 0.0; for (k = 0; k < Ngrid; ++k) { prj_ps[i][k] = prj_ps[i][k]*norm; phi[i][k] = phi[i][k]/norm; phi_ps[i][k] = phi_ps[i][k]/norm; phi_prime[i][k] = phi_prime[i][k]/norm; phi_ps_prime[i][k] = phi_ps_prime[i][k]/norm; } } }
/**************************************** Function name : solve_pseudo_orbitals Description : Return type : void Author : Marat Valiev Date & Time : 4/7/99 2:31:16 PM ****************************************/ void paw_generate_pseudo_orbitals() { int i; int k; int Ngrid; int max_iter; int converged; int iteration; int match; int status; double log_amesh; double f1,f2; double *V; double *rgrid; double *f; double norm; char output[300]; FILE *fp; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); log_amesh = paw_log_amesh_LogGrid(); /*set maximum number of iterations*/ max_iter = 600; for (i = 0; i <= nbasis-1; i++) { iteration = 0; converged = False; status = False; match = i_r_orbital[i]; /*Start the selfconsistent loop over given ps state */ while ((iteration <= max_iter) && (!converged)) { ++iteration; /* get pseudopotential*/ V = paw_get_paw_potential(i); /* if(orb_type[i]==bound || orb_type[i]==virt) { status = paw_R_Schrodinger(prin_n_ps[i], orb_l[i], V, &e_ps[i], phi_ps[i], phi_ps_prime[i]); } else if(orb_type[i]==scattering) { status = paw_R_Schrodinger_Fixed_Logderiv(prin_n_ps[i], orb_l[i], V, match, log_deriv[i], &e_ps[i], phi_ps[i], phi_ps_prime[i]); } else { printf("unknown orbital type\n"); exit(1); } */ status = paw_R_Schrodinger_Fixed_Logderiv(prin_n_ps[i], orb_l[i], V, match, log_deriv[i], &e_ps[i], phi_ps[i], phi_ps_prime[i]); /*Update pseudopotential potential*/ paw_update_paw_potential(&converged, i, e[i], e_ps[i],phi_ps[i]); } /*report on convergence status*/ if (converged && (status)) { if (paw_debug()) printf("\n%d%d pseudo orbital with the eigenvalue=%f has been found\n", prin_n[i], orb_l[i], e_ps[i]); } else { if (paw_debug()) printf("Unable to find %d%d orbital\n ", prin_n[i], orb_l[i]); } norm = phi[i][match]/phi_ps[i][match]; /*scale ps orbital */ for (k=0;k<=match;k++) { phi_ps[i][k]=phi_ps[i][k]*norm; phi_ps_prime[i][k]=phi_ps_prime[i][k]*norm; } for (k=match+1;k<=Ngrid-1;k++) { phi_ps[i][k]=phi[i][k]; phi_ps_prime[i][k]=phi_prime[i][k]; } } if (paw_debug()) { for (i = 0; i <= nbasis-1; ++i) { sprintf(output, "%s%s%d%d", paw_sdir(),"test",prin_n[i],orb_l[i]); fp = fopen(output, "w+"); for (k = 0; k < Ngrid; k++) { fprintf(fp, "%f\t%f\t%f\n", rgrid[k], phi[i][k],phi_ps[i][k]); } fclose(fp); } } pseudo_orbitals_done = True; /* save original basis functions */ for (i=0;i<=nbasis-1;i++) { for (k = 0; k <= Ngrid-1; k++) { phi0[i][k] = phi[i][k]; phi0_prime[i][k] = phi_prime[i][k]; phi_ps0[i][k] = phi_ps[i][k]; phi_ps0_prime[i][k] = phi_ps_prime[i][k]; } } /* calculate densities */ paw_Zero_LogGrid(rho); paw_Zero_LogGrid(rho_ps); for (i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) { rho[k] += fill[i]*pow((phi0[i][k]/rgrid[k]),2.0); rho_ps[k] += fill[i]*pow((phi_ps0[i][k]/rgrid[k]),2.0); } } /*calculate kinetic energy*/ ekin = paw_get_kinetic_energy(nbasis, orb_l, fill, phi, phi_prime); f = paw_alloc_LogGrid(); for (i = 0; i <= nbasis-1; i++) { for (k=0; k<=Ngrid-1; k++) { f[k] = 0.5*phi_prime[i][k]/(rgrid[k]*log_amesh)* phi_prime[i][k]/(rgrid[k]*log_amesh) - 0.5*phi_ps_prime[i][k]/(rgrid[k]*log_amesh)* phi_ps_prime[i][k]/(rgrid[k]*log_amesh); } f1 = paw_Def_Integr(0.0,f,0.0,Ngrid-1); for (k=0; k<=Ngrid-1; k++) { f[k] = 0.5*phi_prime[i][k]/(rgrid[k]*log_amesh)* phi_prime[i][k]/(rgrid[k]*log_amesh); } f2 = paw_Def_Integr(0.0,f,0.0,Ngrid-1); delta_ekin[i] = (int)(100*f1/f2); if (paw_debug()) printf("kinetic energy of the %d%s orbital was reduced by %d%s\n", prin_n[i],paw_spd_Name(orb_l[i]),delta_ekin[i],"%"); } paw_dealloc_LogGrid(f); }
/**************************************** Function name : paw_solve_pseudo_orbitals Description : Return type : void Author : Marat Valiev Date & Time : 5/15/00 ****************************************/ void paw_scattering_test(double e1,double e2,int number_points ,int l, double r ) { int i; int k; int i_end_point; int Ngrid; double *rgrid; FILE *fp; double *V_ks; double *psi1; double *psi1_prime; double *psi; double *psi_prime; double *log_grid_ae; double *log_grid_paw; double de; double* e3; double e_test; double log_amesh; /*char output[30];*/ char data_filename[300]; char script_filename[300]; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); log_amesh = paw_log_amesh_LogGrid(); psi1 = paw_alloc_LogGrid(); psi1_prime = paw_alloc_LogGrid(); psi = paw_alloc_LogGrid(); psi_prime = paw_alloc_LogGrid(); log_grid_ae = paw_alloc_1d_array(number_points); log_grid_paw = paw_alloc_1d_array(number_points); e3 = paw_alloc_1d_array(number_points); de = (e2-e1)/number_points; V_ks = paw_get_kohn_sham_potential(); i_end_point = paw_get_grid_index(r); for (i=0;i<= number_points-1;i++) { e_test = e1+de*i; e3[i] = e_test; paw_solve_paw_scattering(l, r, e_test, psi,psi_prime); paw_R_Schrodinger_Fixed_E( l, V_ks, i_end_point, e_test, psi1, psi1_prime ); log_grid_ae[i] = psi1_prime[i_end_point-1]/(psi1[i_end_point-1]*rgrid[i_end_point-1]*log_amesh); log_grid_paw[i] = psi_prime[i_end_point-1]/(psi[i_end_point-1]*rgrid[i_end_point-1]*log_amesh); } if (paw_debug()) { sprintf(data_filename,"%s%s_%s_scat_test.dat", paw_sdir(),paw_get_atom_name(),paw_spd_Name(l)); fp = fopen(data_filename,"w+"); for (k=0; k<=number_points-1; k++) { fprintf(fp,"%le\t%le\t%le\n", e3[k],log_grid_ae[k],log_grid_paw[k]); } fclose(fp); sprintf(script_filename,"%s%s_%s_scat_test.plt", paw_sdir(),paw_get_atom_name(),paw_spd_Name(l)); printf("script_filename: %s\n",script_filename); fp = fopen(script_filename,"w+"); fprintf(fp,"set style data lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[%f:%f] \n",e1,e2); fprintf(fp,"set grid \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"e (Hartree)\" \n"); fprintf(fp,"set ylabel \"logarithmic derivative at r=%f\" \n",r); fprintf(fp,"set title \" %s %s channel scattering test\n",paw_get_atom_name(),paw_spd_Name(l)); fprintf(fp,"plot \"%s\" using 1:2 title \"all electron\",",data_filename); fprintf(fp,"\"\" using 1:3 title \"paw\" \n"); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); } }
/**************************************** Function name : paw_print_basis_to_file Description : Return type : void Author : Marat Valiev Date & Time : 3/31/99 3:01:57 PM ****************************************/ void paw_print_basis_test_to_file(char* atom_name) { int i; int j; int k; int Ngrid; double *rgrid; char data_filename[300]; char script_filename[300]; char nl_name[20]; char title[20]; FILE *fp; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); if (paw_debug()) { sprintf(data_filename,"%s%s_test.dat",paw_sdir(),atom_name); printf("data_filename: %s\n",data_filename); fp = fopen(data_filename,"w+"); for (k=0; k<=Ngrid-1; k++) { fprintf(fp,"%le", rgrid[k]); for (i=0; i<=nbasis-1; i++) fprintf(fp,"\t%le \t%le",phi_ps0[i][k],psi_ps[i][k]); fprintf(fp,"\n"); } fclose(fp); /*gnu script file */ for (i=0,j=2; i<=nbasis-1; i++,j=j+2) { sprintf(nl_name,"%d%s",prin_n[i],paw_spd_Name(orb_l[i])); sprintf(script_filename,"%s%s_%s_test.plt",paw_sdir(),atom_name,nl_name); printf("script_filename: %s \n",script_filename); fp = fopen(script_filename,"w+"); fprintf(fp,"set style data lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%f] \n",1.5*r_orbital[i]); fprintf(fp,"set grid \n"); fprintf(fp,"set key \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set title \" %s paw_basis test for %s\\n (e=%f Hartree)\" \n", nl_name,atom_name,e_ps[i]); sprintf(title,"%s (%f)",nl_name,e_ps[i]); fprintf(fp,"plot \"%s\" using 1:%d title \" original pseudo orbital \" , ",data_filename,j); fprintf(fp,"\"%s\" using 1:%d title \" solution of PAW Hamiltonian \" with points\n",data_filename,j+1); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); } } }
/**************************************** Function name : paw_print_basis_to_file Description : Return type : void Author : Marat Valiev Date & Time : 3/31/99 3:01:57 PM ****************************************/ void paw_print_basis_to_file(char* atom_name) { int i; int j; int k; int Ngrid; double *rgrid; char data_filename[300]; char script_filename[300]; char nl_name[20]; char title[20]; FILE *fp; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); if (paw_debug()) { sprintf(data_filename,"%s%s_paw.dat",paw_sdir(),atom_name); fp = fopen(data_filename,"w+"); for (k=0; k<=Ngrid-1; k++) { fprintf(fp,"%le", rgrid[k]); for (i=0; i<=nbasis-1; i++) fprintf(fp,"\t%le \t%le \t%le ",phi[i][k],phi_ps[i][k],prj_ps[i][k]); fprintf(fp,"\n"); } fclose(fp); /* individual orbitals gnu script file */ for (i=0,j=2; i<=nbasis-1; i++,j=j+3) { sprintf(nl_name,"%d%s",prin_n[i],paw_spd_Name(orb_l[i])); sprintf(script_filename,"%s%s_%s_paw.plt",paw_sdir(),atom_name,nl_name); fp = fopen(script_filename,"w+"); fprintf(fp,"set style data lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%f] \n",1.5*r_orbital[i]); fprintf(fp,"set grid \n"); fprintf(fp,"set key \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set title \" %s paw_basis for %s\\n (e=%f Hartree)\" \n", nl_name,atom_name,e_ps[i]); sprintf(title,"%s (%f)",nl_name,e_ps[i]); fprintf(fp,"plot \"%s\" using 1:%d title \" all-electron orbital \" , ",data_filename,j); fprintf(fp,"\"%s\" using 1:%d title \" pseudo orbital \" , ",data_filename,j+1); fprintf(fp,"\"%s\" using 1:%d title \" projector \" \n",data_filename,j+2); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); } } }
/**************************************** Function name : paw_save_orbitals_to_file Description : Return type : void Author : Marat Valiev Date & Time : 3/31/99 3:01:57 PM ****************************************/ void paw_print_orbitals_to_file(char* atom_name) { int i; int k; int Ngrid; double *rgrid; char data_filename[300]; char script_filename[300]; char nl_name[20]; char title[20]; FILE *fp; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); if (paw_debug()) { sprintf(data_filename,"%s%s_orb.dat",paw_sdir(),atom_name); fp = fopen(data_filename,"w+"); for (k=0; k<=Ngrid-1; k++) { fprintf(fp,"%le", rgrid[k]); for (i=0; i<=Ntotal-1; i++) { fprintf(fp,"\t%le",psi[i][k]); } fprintf(fp,"\n"); } fclose(fp); /* all orbitals gnu script file */ sprintf(script_filename,"%s%s_all_orb.plt",paw_sdir(),atom_name); fp = fopen(script_filename,"w+"); fprintf(fp, "set title \" Kohn-Sham bound states for %s \" \n", atom_name); fprintf(fp,"set nolabel \n"); fprintf(fp,"set key right top box\n"); fprintf(fp,"set grid \n"); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set style data lines \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:5] \n"); i=0; sprintf(nl_name,"%d%s",n[i],paw_spd_Name(l[i])); sprintf(title,"%s (%f)",nl_name,eigenvalue[i]); fprintf(fp,"plot \"%s\" using 1:2 title \"%s\" ",data_filename,title); for (i=1; i<=Nbound-1; i++) { sprintf(nl_name,"%d%s",n[i],paw_spd_Name(l[i])); sprintf(title,"%s (%f)",nl_name,eigenvalue[i]); fprintf(fp,",\"\" using 1:%d title \"%s\" ",i+2,title); } fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); /* individual orbitals gnu script file */ for (i=0; i<=Ntotal-1; i++) { sprintf(nl_name,"%d%s",n[i],paw_spd_Name(l[i])); sprintf(script_filename,"%s%s_%s_orb.plt",paw_sdir(),atom_name,nl_name); fp = fopen(script_filename,"w+"); fprintf(fp,"set style data lines \n"); fprintf(fp,"set nolabel \n"); fprintf(fp,"set autoscale \n"); fprintf(fp,"set xr[0:%d] \n",n[i]+l[i]); fprintf(fp,"set xlabel \"r (a0)\" \n"); fprintf(fp,"set grid \n"); fprintf(fp,"set nokey \n"); fprintf(fp,"set title \" %s orbital for %s\\n (e=%f Hartree)\" \n", nl_name,atom_name,eigenvalue[i]); sprintf(title,"%s (%f)",nl_name,eigenvalue[i]); fprintf(fp,"plot \"%s\" using 1:%d title \"%s\" ",data_filename,i+2,title); fprintf(fp,"\n"); fprintf(fp,"pause -1\n"); fclose(fp); } } }
void paw_generate_basis_file(char *outfile) { char* atom_name; FILE *fp; int i; int k; double tmp; double *Vpseudo; double *rho_core; double *rho_core_ps; int nbasis; int Ngrid; double *rgrid; int* prin_n; int* prin_n_ps; int *l; double* e; double** psi; double** psi_ps0; double** psi_prime; double** psi_ps; double** psi_ps_prime; double** prj_ps; double** prj_ps0; Ngrid = paw_N_LogGrid(); rgrid = paw_r_LogGrid(); atom_name = paw_get_atom_name(); nbasis = paw_get_nbasis(); prin_n = paw_get_pointer_paw_n_array(); prin_n_ps = paw_get_pointer_paw_n_ps_array(); l = paw_get_pointer_paw_l_array(); e = paw_get_pointer_paw_e_array(); psi = paw_get_pointer_paw_psi_array(); psi_ps = paw_get_pointer_paw_psi_ps_array(); psi_prime = paw_get_pointer_paw_psi_prime_array(); psi_ps_prime = paw_get_pointer_paw_psi_ps_prime_array(); prj_ps = paw_get_pointer_paw_prj_ps_array(); prj_ps0 = paw_get_pointer_paw_prj_ps0_array(); rho_core = paw_get_pointer_core_density(); rho_core_ps = paw_get_pointer_ps_core_density(); Vpseudo = paw_get_pointer_pseudopotential(); psi_ps0 = paw_get_pointer_paw_psi_ps_unscr_array(); /* output the basis file */ /*sprintf(output, "%s_basis", atom_name);*/ if (paw_debug()) printf("paw basis file generated: %s\n",outfile); fp = fopen(outfile, "w+"); fprintf(fp,"4\n"); /*dummy tag*/ /* new*/ fprintf(fp,"%s\n",atom_name); /* new*/ fprintf(fp,"%lf\n",paw_get_Zvalence()); /* new*/ fprintf(fp,"%15.11e\n",rgrid[0]); fprintf(fp,"%15.11e\n",rgrid[Ngrid-1]); fprintf(fp,"%d\n",Ngrid); fprintf(fp,"%d\n",nbasis); /* printout cutoff radii */ /* new*/ for (i=0; i<nbasis; ++i) fprintf(fp,"%le ",paw_get_r_orbital(i)); /* new*/ fprintf(fp,"\n"); /* new*/ fprintf(fp,"%d\n",paw_get_max_i_r_orbital()); fprintf(fp,"%s\n",paw_get_comment()); /* new*/ fprintf(fp,"%15.11e\n",paw_get_core_kinetic_energy()); for ( i = 0; i < nbasis; ++i) fprintf(fp, "%d\t %15.11e\t %d\t %d\n",prin_n[i],e[i],prin_n_ps[i],l[i]); for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) fprintf(fp, "%15.11e \n",psi[i][k]); } for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) { tmp = psi_prime[i][k]/(rgrid[k]*paw_log_amesh_LogGrid()); fprintf(fp, "%15.11e \n",psi_prime[i][k]/(rgrid[k]*paw_log_amesh_LogGrid())); } } for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) fprintf(fp, "%15.11e \n",psi_ps[i][k]); } for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) { tmp = psi_ps_prime[i][k]/(rgrid[k]*paw_log_amesh_LogGrid()); fprintf(fp, "%15.11e \n",psi_ps_prime[i][k]/(rgrid[k]*paw_log_amesh_LogGrid())); } } for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) fprintf(fp, "%15.11e \n",prj_ps[i][k]); } for (k = 0; k <= Ngrid-1; k++) { fprintf(fp, "%15.11e \n",rho_core[k]/(4.0*PI)); } for (k = 0; k <= Ngrid-1; k++) { fprintf(fp, "%15.11e \n",rho_core_ps[k]/(4.0*PI)); } for (k = 0; k <= Ngrid-1; k++) { fprintf(fp, "%15.11e \n",Vpseudo[k]); } fprintf(fp,"%15.11e\n",paw_get_sigma_comp()); fprintf(fp,"%15.11e\n",paw_get_ion_charge()); for ( i = 0; i <= nbasis-1; i++) { for (k = 0; k <= Ngrid-1; k++) fprintf(fp, "%15.11e \n",prj_ps0[i][k]); } fclose(fp); }