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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HARTREE 27.2113845
static void compare_and_print_error(char *buf,char *str,int val1,int val2)
{
if ( val1 != val2 ) {
printf("ERROR %s %d %d\n",str,val1,val2);
printf("buf=<%s>\n",buf);
exit(0);
}
}
#define LEN 256
void TRAN_Connect_Read_Hamiltonian(
char *filename,
int SpinP_switch,
int *WhatSpecies,
int *FNAN,
int **natn,
int **ncn,
int *Spe_Total_CNO,
/* output */
double *****H,
double ****OLP
)
{
FILE *fp;
char buf[LEN];
int atomnum,Catomnum, Latomnum,Ratomnum;
int spin;
int ct_AN, wan1,TNO1,i_fnan, h_AN, Gh_AN, Rn, wan2,TNO2;
int i,j;
int i_ct_AN, i_h_AN, i_Gh_AN, i_Rn, i_TNO1, i_TNO2;
int i_SpinP_switch;
printf("TRAN_Connect_Read_Hamiltonian file=%s in\n",filename);
if ( (fp=fopen(filename,"r"))==NULL ) {
printf("can not open a file = %s\n",filename);
exit(0);
}
fgets(buf,LEN,fp);
sscanf(buf,"%d",&atomnum);
fgets(buf,LEN,fp);
sscanf(buf,"%d",&Catomnum);
fgets(buf,LEN,fp);
sscanf(buf,"%d",&Latomnum);
fgets(buf,LEN,fp);
sscanf(buf,"%d",&Ratomnum);
fgets(buf,LEN,fp);
sscanf(buf,"%d",&i_SpinP_switch);
compare_and_print_error(buf,"i_SpinP_switch,SpinP_switch",i_SpinP_switch,SpinP_switch);
for (spin=0; spin<=SpinP_switch; spin++){
/* fprintf(fp," Kohn-Sham Hamiltonian: spin=%i\n",spin); */
fgets(buf,LEN,fp);
for (ct_AN=1; ct_AN<=atomnum; ct_AN++){
wan1 = WhatSpecies[ct_AN];
TNO1 = Spe_Total_CNO[wan1];
/* fprintf(fp,"%i =FNAN[ct_AN] \n",FNAN[ct_AN]); */
fgets(buf,LEN,fp);
sscanf(buf,"%d",&i_fnan);
compare_and_print_error(buf,"i_fnan,FNAN[ct_AN]",i_fnan,FNAN[ct_AN]);
for (h_AN=0; h_AN<=FNAN[ct_AN]; h_AN++){
Gh_AN = natn[ct_AN][h_AN];
Rn = ncn[ct_AN][h_AN];
wan2 = WhatSpecies[Gh_AN];
TNO2 = Spe_Total_CNO[wan2];
/*fprintf(fp,"%i =glbal index \n",ct_AN);
*fprintf(fp,"%i =local index \n",h_AN);
*fprintf(fp,"%i =grobal \n",Gh_AN);
*fprintf(fp,"%i =Rn \n",Rn);
*fprintf(fp,"%i %i =orbitalnum \n",TNO1,TNO2);
*/
fgets(buf,LEN,fp);
printf("globalindex: %s",buf);
sscanf(buf,"%d", &i_ct_AN);
compare_and_print_error(buf,"i_ct_AN,ct_AN",i_ct_AN,ct_AN);
fgets(buf,LEN,fp);
printf("localindex: %s",buf);
sscanf(buf,"%d", &i_h_AN);
compare_and_print_error(buf,"i_h_AN,h_AN",i_h_AN,h_AN);
fgets(buf,LEN,fp);
printf("global %s",buf);
sscanf(buf,"%d", &i_Gh_AN);
compare_and_print_error(buf,"i_Gh_AN,Gh_AN",i_Gh_AN,Gh_AN);
fgets(buf,LEN,fp);
printf("Rn: %s",buf);
sscanf(buf,"%d", &i_Rn);
compare_and_print_error(buf,"i_Rn,Rn",i_Rn,Rn);
fgets(buf,LEN,fp);
printf("TNO1,TNO2: %s",buf);
sscanf(buf,"%d %d", &i_TNO1,&i_TNO2);
compare_and_print_error(buf,"i_TNO1,TNO1",i_TNO1,TNO1);
compare_and_print_error(buf,"i_TNO2,TNO2",i_TNO2,TNO2);
for (i=0; i<TNO1; i++){
for (j=0; j<TNO2; j++){
/* fprintf(fp,"%28.17f ",H[spin][ct_AN][h_AN][i][j]);
* fprintf(fp,"\n");
*/
fgets(buf,LEN,fp);
sscanf(buf,"%lf",&H[spin][ct_AN][h_AN][i][j]);
H[spin][ct_AN][h_AN][i][j] *= HARTREE;
}
}
}
}
}
/* fprintf(fp," Overlap matrix\n"); */
fgets(buf,LEN,fp);
for (ct_AN=1; ct_AN<=atomnum; ct_AN++){
wan1 = WhatSpecies[ct_AN];
TNO1 = Spe_Total_CNO[wan1];
/* fprintf(fp,"%i =FNAN[ct_AN] \n",FNAN[ct_AN]); */
fgets(buf,LEN,fp);
sscanf(buf,"%d",&i_fnan);
for (h_AN=0; h_AN<=FNAN[ct_AN]; h_AN++){
Gh_AN = natn[ct_AN][h_AN];
Rn = ncn[ct_AN][h_AN];
wan2 = WhatSpecies[Gh_AN];
TNO2 = Spe_Total_CNO[wan2];
/* fprintf(fp,"%i =glbal index \n",ct_AN);
* fprintf(fp,"%i =local index \n",h_AN);
* fprintf(fp,"%i =grobal \n",Gh_AN);
* fprintf(fp,"%i =Rn \n",Rn);
* fprintf(fp,"%i %i =orbitalnum \n",TNO1,TNO2);
*/
fgets(buf,LEN,fp);
sscanf(buf,"%d", &ct_AN);
fgets(buf,LEN,fp);
sscanf(buf,"%d", &h_AN);
fgets(buf,LEN,fp);
sscanf(buf,"%d", &Gh_AN);
fgets(buf,LEN,fp);
sscanf(buf,"%d", &Rn);
fgets(buf,LEN,fp);
sscanf(buf,"%d %d", &TNO1, &TNO2);
for (i=0; i<TNO1; i++){
for (j=0; j<TNO2; j++){
/* fprintf(fp,"%28.17f ",OLP[ct_AN][h_AN][i][j]);
* fprintf(fp,"\n");
*/
fgets(buf,LEN,fp);
sscanf(buf,"%lf",&OLP[ct_AN][h_AN][i][j]);
}
}
}
}
fclose(fp);
printf("TRAN_Connect_Read_Hamiltonian end\n");
}
|