Hi all,<br><br>I wrote a program to calculate the electrical conductivity at zero field using the Green-Kubo relation, as follows. But I found the calculated data are strange: in the first stage, the data are very big, while in the end stage it is a negative value, also quite big. (I used the system with about 3500 atoms, 4 ns&nbsp; (every 100 ns are taken as one ensemble). 
<br><br>Is there anyone who can give some suggestions?&nbsp; Thanks.<br><br><br clear="all">#ifdef HAVE_CONFIG_H<br>#include &lt;config.h&gt;<br>#endif<br>#include &lt;stdio.h&gt;<br>#include &lt;math.h&gt;<br><br>#include &quot;
confio.h&quot;<br>#include &quot;copyrite.h&quot;<br>#include &quot;fatal.h&quot;<br>#include &quot;futil.h&quot;<br>#include &quot;gstat.h&quot;<br>#include &quot;macros.h&quot;<br>#include &quot;maths.h&quot;<br>#include &quot;
physics.h&quot;<br>#include &quot;index.h&quot;<br>#include &quot;smalloc.h&quot;<br>#include &quot;statutil.h&quot;<br>#include &quot;string.h&quot;<br>#include &quot;sysstuff.h&quot;<br>#include &quot;txtdump.h&quot;<br>
#include &quot;typedefs.h&quot;<br>#include &quot;vec.h&quot;<br>#include &quot;strdb.h&quot;<br>#include &quot;xvgr.h&quot;<br><br><br>int main(int argc,char *argv[])<br>{<br>&nbsp; static char *desc[] = {<br>&nbsp;&nbsp;&nbsp; &quot;This program is wroten to calculate the Electrcal Conductivity.&quot;,
<br>&nbsp;&nbsp;&nbsp; &quot;The Green-Kubo relation is used. See the reference:&quot;,<br>&nbsp;&nbsp;&nbsp; &quot;J-P Hansen, I. R. McDonald: Theory for Simple Liquids, 2nd Edition, P242.&quot;<br>&nbsp; };<br>&nbsp; t_pargs pa[] = {<br>&nbsp; };<br>&nbsp; #define NPA asize(pa)
<br>&nbsp; <br>&nbsp;&nbsp; t_filenm&nbsp; fnm[] = {<br>&nbsp;&nbsp;&nbsp; { efTRX, &quot;-f&quot;,&nbsp; NULL,&nbsp;&nbsp; ffREAD&nbsp; },<br>&nbsp;&nbsp;&nbsp; { efTPX, &quot;-s&quot;,&nbsp; NULL,&nbsp;&nbsp; ffREAD&nbsp; }, <br>&nbsp;&nbsp;&nbsp; { efNDX, &quot;-n&quot;,&nbsp; NULL,&nbsp;&nbsp; ffOPTRD },<br>&nbsp;&nbsp;&nbsp; { efXVG, &quot;-o&quot;,&nbsp; &quot;EC&quot;,&nbsp;&nbsp; ffWRITE }
<br>&nbsp; };<br>#define NFILE asize(fnm)<br><br>&nbsp; FILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *fp_EC;&nbsp; <br>&nbsp; t_topology top;<br>&nbsp; t_trxframe fr;<br>&nbsp; bool&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bTop=FALSE;<br>&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gnx;<br>&nbsp; atom_id&nbsp;&nbsp;&nbsp; *index;<br>&nbsp; char&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *grpname;<br>&nbsp; char&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title[256];
<br>&nbsp; real&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q,t,t0;<br>&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status,i,j;<br>&nbsp; real&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *qv,*qv0;<br>&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i_T_N,T_N=10,Ensemble_N;<br>&nbsp; real&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Integrand,*Integral,EC;<br>&nbsp; real&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T_fac;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; real kb=1.381e-23,e=1.6e-19
,v_c=1e3,t_c=1e-12;&nbsp; //v_c: the coefficient between nm/ps and m/s<br>&nbsp; real&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T=425,V=47.3,Pref;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Temperature, Volume and Prefacor <br>&nbsp; <br>&nbsp; //printf(&quot;\nPlease input the Temperature(K) and Volume(nm^3),\n&amp; How many data points per ensemble:\n&quot;);
<br>&nbsp; //scanf(&quot;%f&nbsp; %f&nbsp; %g&quot;,&amp;T,&amp;V,&amp;T_N);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; V=V*1.0e-27;<br>&nbsp; Pref = 1.0/(kb*T)*(e*v_c)*(e*v_c)*t_c/V;<br>&nbsp; printf(&quot;Prefactor = %10g\n&quot;, Pref); <br>&nbsp; printf(&quot;\n&quot;);<br>&nbsp; <br>
&nbsp; //CopyRight(stderr,argv[0]);<br>&nbsp; parse_common_args(&amp;argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL);<br>&nbsp;<br>&nbsp; bTop=read_tps_conf(ftp2fn(efTPX,NFILE,fnm),title,&amp;top,NULL,NULL,NULL,TRUE);
<br>&nbsp; get_index(&amp;top.atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&amp;gnx,&amp;index,&amp;grpname);<br>&nbsp;<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br>&nbsp; sprintf(title,&quot;Electrical Conductivity: %s&quot;,grpname);<br>&nbsp; fp_EC=xvgropen(opt2fn(&quot;-o&quot;,NFILE,fnm),title,&quot;t (ps)&quot;,&quot;EC (S/m)&quot;);
<br>&nbsp; <br>&nbsp; snew(qv0,DIM);<br>&nbsp; snew(qv,DIM);<br>&nbsp; snew(Integrand,T_N);<br>&nbsp; snew(Integral,T_N);<br>&nbsp; <br>&nbsp; read_first_frame(&amp;status,ftp2fn(efTRX,NFILE,fnm),&amp;fr,TRX_NEED_V);<br>&nbsp; <br>&nbsp; for(i=0; i&lt;T_N; i++)<br>&nbsp;&nbsp;&nbsp; &nbsp; Integral[i]=0;
<br>&nbsp; Ensemble_N=0;<br>&nbsp; EC=0;<br>&nbsp; <br>&nbsp; next_ensemble:<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; t0=fr.time;<br>&nbsp;&nbsp; <br>&nbsp; for(i=0; i&lt;DIM; i++)<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; qv0[i]=0;<br>&nbsp; for(i=0; i&lt;gnx; i++) {<br>&nbsp;&nbsp;&nbsp; &nbsp; q = top.atoms.atom[index[i]].q;<br>&nbsp;&nbsp;&nbsp; &nbsp; qv0[0] += q*
fr.v[index[i]][XX];<br>&nbsp;&nbsp;&nbsp; &nbsp; qv0[1] += q*fr.v[index[i]][YY];<br>&nbsp;&nbsp;&nbsp; &nbsp; qv0[2] += q*fr.v[index[i]][ZZ];<br>&nbsp; }<br>&nbsp; i_T_N = 0;<br>&nbsp; do {<br>&nbsp;&nbsp;&nbsp; &nbsp; t=fr.time;<br>&nbsp;&nbsp;&nbsp; &nbsp; for(i=0; i&lt;DIM; i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; qv[i]=0;<br>&nbsp;&nbsp;&nbsp; &nbsp; for(i=0; i&lt;gnx; i++) {
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; q = top.atoms.atom[index[i]].q;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; qv[0] += q*fr.v[index[i]][XX];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; qv[1] += q*fr.v[index[i]][YY];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; qv[2] += q*fr.v[index[i]][ZZ];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp; Integrand[i_T_N] = qv[0]*qv0[0]+qv[1]*qv0[1]+qv[2]*qv0[2];
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; // T_fac is the factor between time and i_T_N<br>&nbsp;&nbsp;&nbsp; &nbsp; if(i_T_N==(T_N-1))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; T_fac = (t-t0)/i_T_N;<br>&nbsp;&nbsp;&nbsp; &nbsp; i_T_N++;<br>&nbsp;&nbsp;&nbsp; &nbsp; if (i_T_N == T_N) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; for (j=0; j&lt;T_N; j++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; Integral[j] += Integrand[j];
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; Ensemble_N++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (read_next_frame(status,&amp;fr))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;goto next_ensemble;<br>&nbsp;&nbsp;&nbsp; &nbsp; }<br>&nbsp; } while (read_next_frame(status,&amp;fr));<br>&nbsp;<br>&nbsp; close_trj(status);<br>&nbsp; <br><br>&nbsp; for (i=0; i&lt;T_N; i++)
<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp; EC += Pref*Integral[i]/Ensemble_N*T_fac;<br>&nbsp;&nbsp;&nbsp; &nbsp; fprintf(fp_EC, &quot;%7.3f&nbsp; %10g \n&quot;,i*T_fac,EC);<br>&nbsp; }<br>&nbsp; ffclose(fp_EC);<br>&nbsp; thanx(stderr);<br>&nbsp; return 0;<br>}<br>-- <br>Sincerely yours,<br>**********************************************
<br>Baofu Qiao, PhD<br>Frankfurt Institute for Advanced Studies<br>Max-von-Laue-Str. 1<br>60438 Frankfurt am Main, Germany TEL:+49-69-7984-7529<br>**********************************************