From 0e332af53b0e10fdb58742037cbb537c5781e6db Mon Sep 17 00:00:00 2001 From: "k.ido" <13773226+k-ido@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:16:15 +0900 Subject: [PATCH] add sgn func --- src/ComplexUHF/output.c | 23 ++++++++++++-------- src/ComplexUHF/readdef.c | 47 +++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/ComplexUHF/output.c b/src/ComplexUHF/output.c index c0d85af9..2cfe8041 100644 --- a/src/ComplexUHF/output.c +++ b/src/ComplexUHF/output.c @@ -243,7 +243,7 @@ int MakeOrbitalFile(struct BindStruct *X){ } void OutputAntiParallel_2(struct BindStruct *X,double complex **UHF_Fij,double complex *ParamOrbital,int *CountOrbital){ - int i,j,Orbitalidx,isite,jsite; + int i,j,Orbitalidx,Orbitalsgn, isite,jsite; char fileName[256]; FILE *fp; @@ -258,10 +258,11 @@ void OutputAntiParallel_2(struct BindStruct *X,double complex **UHF_Fij,double c isite = i + 0 * X->Def.Nsite; jsite = j + 1 * X->Def.Nsite; Orbitalidx = X->Def.OrbitalIdx[isite][jsite]; + Orbitalsgn = X->Def.OrbitalSgn[isite][jsite]; fprintf(fp," %d %d %lf %lf\n",i,j,creal(UHF_Fij[i][j]),cimag(UHF_Fij[i][j])); //printf(" %d %d %d \n", isite,jsite,Orbitalidx); if(Orbitalidx != -1) { - ParamOrbital[Orbitalidx] += UHF_Fij[i][j]; + ParamOrbital[Orbitalidx] += UHF_Fij[i][j]*Orbitalsgn; CountOrbital[Orbitalidx] += 1; //printf(" %d %d %d %lf %lf \n", isite,jsite,Orbitalidx,creal(ParamOrbital[Orbitalidx]),cimag(ParamOrbital[Orbitalidx])); } @@ -280,7 +281,7 @@ void OutputAntiParallel_2(struct BindStruct *X,double complex **UHF_Fij,double c void OutputAntiParallel(struct BindStruct *X,double complex **UHF_Fij,double complex *ParamOrbital,int *CountOrbital){ - int i,j,Orbitalidx,isite,jsite; + int i,j,Orbitalidx,Orbitalsgn,isite,jsite; char fileName[256]; FILE *fp; @@ -295,9 +296,10 @@ void OutputAntiParallel(struct BindStruct *X,double complex **UHF_Fij,double com isite = i + 0 * X->Def.Nsite; jsite = j + 1 * X->Def.Nsite; Orbitalidx = X->Def.OrbitalIdx[isite][jsite]; + Orbitalsgn = X->Def.OrbitalSgn[isite][jsite]; fprintf(fp," %d %d %lf %lf\n",i,j,creal(UHF_Fij[isite][jsite]),cimag(UHF_Fij[isite][jsite])); if(Orbitalidx != -1) { - ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]; + ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]*Orbitalsgn; CountOrbital[Orbitalidx] += 1; } } @@ -313,7 +315,7 @@ void OutputAntiParallel(struct BindStruct *X,double complex **UHF_Fij,double com } void OutputParallel(struct BindStruct *X,double complex **UHF_Fij,double complex *ParamOrbital,int *CountOrbital){ - int i,j,Orbitalidx,isite,jsite,ini,fin,tmp_i; + int i,j,Orbitalidx,Orbitalsgn,isite,jsite,ini,fin,tmp_i; char fileName[256]; FILE *fp; @@ -331,17 +333,19 @@ void OutputParallel(struct BindStruct *X,double complex **UHF_Fij,double complex isite = i + 0 * X->Def.Nsite; jsite = j + 0 * X->Def.Nsite; Orbitalidx = X->Def.OrbitalIdx[isite][jsite]; + Orbitalsgn = X->Def.OrbitalSgn[isite][jsite]; fprintf(fp," %d %d %lf %lf\n",isite,jsite,creal(UHF_Fij[isite][jsite]),cimag(UHF_Fij[isite][jsite])); if(Orbitalidx != -1) { - ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]; + ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]*Orbitalsgn; CountOrbital[Orbitalidx] += 1; } isite = i + 1 * X->Def.Nsite; jsite = j + 1 * X->Def.Nsite; Orbitalidx = X->Def.OrbitalIdx[isite][jsite]; + Orbitalsgn = X->Def.OrbitalSgn[isite][jsite]; fprintf(fp," %d %d %lf %lf\n",isite,jsite,creal(UHF_Fij[isite][jsite]),cimag(UHF_Fij[isite][jsite])); if(Orbitalidx != -1) { - ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]; + ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]*Orbitalsgn; CountOrbital[Orbitalidx] += 1; } }//for(j = i+1; j < X->Def.Nsite; j++) @@ -361,7 +365,7 @@ void OutputParallel(struct BindStruct *X,double complex **UHF_Fij,double complex } void OutputGeneral(struct BindStruct *X,double complex **UHF_Fij,double complex *ParamOrbital,int *CountOrbital){ - int i,j,Orbitalidx,isite,jsite,ispin,jspin; + int i,j,Orbitalidx,Orbitalsgn,isite,jsite,ispin,jspin; char fileName[256]; FILE *fp; for (i = 0; i < X->Def.NOrbitalIdx; i++) { @@ -377,10 +381,11 @@ void OutputGeneral(struct BindStruct *X,double complex **UHF_Fij,double complex isite = i + ispin * X->Def.Nsite; jsite = j + jspin * X->Def.Nsite; Orbitalidx = X->Def.OrbitalIdx[isite][jsite]; + Orbitalsgn = X->Def.OrbitalSgn[isite][jsite]; fprintf(fp," %d %d %lf %lf\n",isite,jsite,creal(UHF_Fij[isite][jsite]),cimag(UHF_Fij[isite][jsite])); if (Orbitalidx != -1) { // ParamOrbital[Orbitalidx]+=UHF_Fij[isite][jsite]; - ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]; + ParamOrbital[Orbitalidx] += UHF_Fij[isite][jsite]*Orbitalsgn; CountOrbital[Orbitalidx] += 1; //printf("debug: Orbitaidx[%d][%d]=%d, UHF_Fij=%lf, %lf \n", isite, jsite, Orbitalidx, creal(UHF_Fij[isite][jsite]), cimag(UHF_Fij[isite][jsite])); //printf("debug: Orbitaidx[%d][%d]=%d, ParamOrbital_Fij=%lf, %lf \n", isite, jsite, Orbitalidx, creal(ParamOrbital[Orbitalidx]), cimag(ParamOrbital[Orbitalidx])); diff --git a/src/ComplexUHF/readdef.c b/src/ComplexUHF/readdef.c index 9bad8b1f..ca6fd26a 100644 --- a/src/ComplexUHF/readdef.c +++ b/src/ComplexUHF/readdef.c @@ -400,8 +400,9 @@ int ReadDefFileIdxPara( int iKWidx = 0; int i, j; int spn_i, spn_j, all_i, all_j; - int fij; - int idx, Orbitalidx;//, Orbitalsgn; + int fij, fijsgn; + int ndata; + int idx, Orbitalidx, Orbitalsgn; int x0, x1, x2, x3; int info, i_spin, j_spin; double dReValue; @@ -415,6 +416,7 @@ int ReadDefFileIdxPara( for (i = 0; i < X->Nsite; i++) { for (j = 0; j < X->Nsite; j++) { X->OrbitalIdx[i][j] = -1; + X->OrbitalSgn[i][j] = 0; } } } @@ -422,6 +424,7 @@ int ReadDefFileIdxPara( for (i = 0; i < X->Nsite*2; i++) { for (j = 0; j < X->Nsite*2; j++) { X->OrbitalIdx[i][j] = -1; + X->OrbitalSgn[i][j] = 0; } } } @@ -597,11 +600,17 @@ int ReadDefFileIdxPara( idx = 0; if(X->iFlgOrbitalGeneral==0) { while( fgets(ctmp2, sizeof(ctmp2)/sizeof(char), fp) != NULL){ - sscanf(ctmp2, "%d %d %d\n", + ndata = sscanf(ctmp2, "%d %d %d %d\n", &i, &j, - &Orbitalidx); + &Orbitalidx, + &Orbitalsgn); + //printf("Debug: %d %d %d %d %d\n", ndata, i, j, Orbitalidx, Orbitalsgn); X->OrbitalIdx[i+X->Nsite*0][j+X->Nsite*1]=Orbitalidx; + if (ndata == 3){ //sgn does not exist in input file + Orbitalsgn = 1; + } + X->OrbitalSgn[i+X->Nsite*0][j+X->Nsite*1]=Orbitalsgn; if(CheckPairSite(i, j, X->Nsite) != 0){ fprintf(stderr, "Error: Site index is incorrect. \n"); info=1; @@ -614,11 +623,17 @@ int ReadDefFileIdxPara( info=ReadDefFileError(defname); } }else{//general orbital - while( fscanf(fp, "%d %d %d\n", &i, &j, &fij) != EOF){ + //while( fscanf(fp, "%d %d %d %d\n", &i, &j, &fij, &fijsgn) != EOF){ + while( fgets(ctmp2, sizeof(ctmp2)/sizeof(char), fp) != NULL){ + ndata = sscanf(ctmp2, "%d %d %d %d\n", &i, &j, &fij, &fijsgn); spn_i = 0; spn_j = 1; all_i = i+spn_i*X->Nsite; //fsz all_j = j+spn_j*X->Nsite; //fsz + if (ndata == 3){ //sgn does not exist in input file + fijsgn = 1; + } + //printf("Debug: %d %d %d %d %d\n", ndata, i, j, fij, fijsgn); if(CheckPairSite(i, j, X->Nsite) != 0){ fprintf(stderr, "Error: Site index is incorrect. \n"); info=1; @@ -626,8 +641,10 @@ int ReadDefFileIdxPara( } idx++; X->OrbitalIdx[all_i][all_j]=fij; + X->OrbitalSgn[all_i][all_j]=fijsgn; // Note F_{IJ}=-F_{JI} X->OrbitalIdx[all_j][all_i]=fij; + X->OrbitalSgn[all_j][all_i]=-fijsgn; if(idx==(X->Nsite*X->Nsite)) break; } } @@ -637,8 +654,14 @@ int ReadDefFileIdxPara( /*orbitalidxt.def------------------------------------*/ idx = 0; int fij_org; - while (fscanf(fp, "%d %d %d\n", &i, &j, &fij_org) != EOF) { + //while (fscanf(fp, "%d %d %d %d\n", &i, &j, &fij_org, &fijsgn) != EOF) { + while( fgets(ctmp2, sizeof(ctmp2)/sizeof(char), fp) != NULL){ + ndata = sscanf(ctmp2, "%d %d %d %d\n", &i, &j, &fij_org, &fijsgn); //fprintf(stdout, "Debug: test-1 %d %d %d %d\n", i, j, fij, idx0); + if (ndata == 3){ //sgn does not exist in input file + fijsgn = 1; + } + //printf("Debug: %d %d %d %d %d\n", ndata, i, j, fij_org, fijsgn); for (spn_i = 0; spn_i < 2; spn_i++) { all_i = i + spn_i * X->Nsite; //fsz all_j = j + spn_i * X->Nsite; //fsz @@ -650,7 +673,9 @@ int ReadDefFileIdxPara( idx++; fij = X->NOrbitalAP + 2 * fij_org + spn_i; X->OrbitalIdx[all_i][all_j] = fij; + X->OrbitalSgn[all_i][all_j] = fijsgn; X->OrbitalIdx[all_j][all_i] = fij; + X->OrbitalSgn[all_j][all_i] = -fijsgn; } if (idx == (X->Nsite * (X->Nsite - 1))) { break; @@ -665,13 +690,19 @@ int ReadDefFileIdxPara( idx = 0; while (fgets(ctmp2, sizeof(ctmp2) / sizeof(char), fp) != NULL) { //TODO: Replace for spin dependent - sscanf(ctmp2, "%d %d %d %d %d\n", + ndata = sscanf(ctmp2, "%d %d %d %d %d %d\n", &i, &i_spin, &j, &j_spin, - &Orbitalidx); + &Orbitalidx, + &Orbitalsgn); + if (ndata == 5){ //sgn does not exist in input file + Orbitalsgn = 1; + } + //printf("Debug: %d %d %d %d %d %d %d\n", ndata, i, i_spin, j, j_spin, Orbitalidx, Orbitalsgn); (X->OrbitalIdx[i + X->Nsite * i_spin][j + X->Nsite * j_spin]) = Orbitalidx; + (X->OrbitalSgn[i + X->Nsite * i_spin][j + X->Nsite * j_spin]) = Orbitalsgn; idx++; if (idx == X->Nsite * (2 * X->Nsite - 1)) break; }