Пример #1
0
static void clust_stat(FILE *fp,int start,int end,t_pdbfile *pdbf[])
{
  int i;
  t_lsq ed,ef;
  
  init_lsq(&ed);
  init_lsq(&ef);
  for(i=start; (i<end); i++) {
    add_lsq(&ed,i-start,pdbf[i]->edocked);
    add_lsq(&ef,i-start,pdbf[i]->efree);
  }
  fprintf(fp,"  <%12s> = %8.3f (+/- %6.3f)\n",etitles[FALSE],
	  aver_lsq(&ed),sigma_lsq(&ed));
  fprintf(fp,"  <%12s> = %8.3f (+/- %6.3f)\n",etitles[TRUE],
	  aver_lsq(&ef),sigma_lsq(&ef));
  done_lsq(&ed);
  done_lsq(&ef);
}
Пример #2
0
void done_lsq(t_lsq *lsq)
{
  init_lsq(lsq);
}
Пример #3
0
static void do_bonds(FILE *log,char *fn,char *fbond,char *fdist,
		     int gnx,atom_id index[],
		     real blen,real tol,bool bAver,
		     t_topology *top,int ePBC,bool bAverDist)
{
#define MAXTAB 1000
  FILE   *out,*outd=NULL;
  int    *btab=NULL;
  real   b0=0,b1,db=0;
  real   bond,bav;
  t_lsq  b_one,*b_all=NULL;
  /*real   mean, mean2, sqrdev2, sigma2; 
    int    counter;*/
  rvec   *x;
  rvec   dx;
  int    status,natoms;
  matrix box;
  real   t,fac;
  int    bind,i,nframes,i0,i1;
  t_pbc  pbc;
  
  if (!bAver) {
    snew(b_all,gnx/2);
    for(i=0; (i<gnx/2); i++)
      init_lsq(&(b_all[i]));
  }
  else {
    init_lsq(&b_one);
    snew(btab,MAXTAB+1);
  }
  
  natoms=read_first_x(&status,fn,&t,&x,box);
  if (natoms == 0) 
    gmx_fatal(FARGS,"No atoms in trajectory!");
  
  if (fdist) {
    outd = xvgropen(fdist,bAverDist ? "Average distance" : "Distances",
		    "Time (ps)","Distance (nm)");
    if (!bAverDist) 
      make_dist_leg(outd,gnx,index,&(top->atoms));
  }
  
  nframes=0;
  do {
    set_pbc(&pbc,ePBC,box);
    if (fdist)
      fprintf(outd," %8.4f",t);
    nframes++; /* count frames */
    bav = 0.0;
    for(i=0; (i<gnx); i+=2) {
      pbc_dx(&pbc,x[index[i]],x[index[i+1]],dx);
      bond   = norm(dx);
      if (bAverDist)
	bav += bond;
      else if (fdist)
	fprintf(outd," %.3f",bond);
      if (bAver) {
	add_lsq(&b_one,t,bond);
	if (db == 0) {
	  if (blen == -1) {
	    b0 = 0;
	    b1 = 0.2;
	    db = (b1-b0)/MAXTAB;
	  }
	  else {
	    b0   = (1.0-tol)*blen;
	    b1   = (1.0+tol)*blen;
	    db   = (2.0*(b1-b0))/MAXTAB;
	  }
	}
	bind = (int)((bond-b0)/db+0.5);
	if ((bind >= 0) && (bind <= MAXTAB))
	  btab[bind]++;
	else {
	  /*
	    printf("bond: %4d-%4d bond=%10.5e, dx=(%10.5e,%10.5e,%10.5e)\n",
	    index[i],index[i+1],bond,dx[XX],dx[YY],dx[ZZ]);
	  */
	}
      }
      else {
	add_lsq(&(b_all[i/2]),t,bond);
      }
    }
    if (bAverDist)
      fprintf(outd," %.5f",bav*2.0/gnx);
    if (fdist)
      fprintf(outd,"\n");
  } while (read_next_x(status,&t,natoms,x,box));
  close_trj(status);

  if (fdist)
    ffclose(outd);
  
  /*
    mean = mean / counter;
    mean2 = mean2 / counter;
    sqrdev2 = (mean2 - mean*mean);
    sigma2 = sqrdev2*counter / (counter - 1);
  */
  /* For definitions see "Weet wat je meet" */
  if (bAver) {
    printf("\n");
    printf("Total number of samples               : %d\n",
	    npoints_lsq(&b_one));
    printf("Mean                                  : %g\n",
	    aver_lsq(&b_one));
    printf("Standard deviation of the distribution: %g\n",
	    sigma_lsq(&b_one));
    printf("Standard deviation of the mean        : %g\n",
	    error_lsq(&b_one));
	    
    out=xvgropen(fbond,"Bond Stretching Distribution",
		 "Bond Length (nm)","");
    
    for(i0=0;      ((i0 < MAXTAB) && (btab[i0]==0)); i0++)
      ;
    i0=max(0,i0-1);
    for(i1=MAXTAB; ((i1 > 0)      && (btab[i1]==0)); i1--)
      ;
    i1=min(MAXTAB,i1+1);
    
    if (i0 >= i1)
      gmx_fatal(FARGS,"No distribution... (i0 = %d, i1 = %d)? ? ! ! ? !",i0,i1);
    
    fac=2.0/(nframes*gnx*db);
    for(i=i0; (i<=i1); i++)
      fprintf(out,"%8.5f  %8.5f\n",b0+i*db,btab[i]*fac);
    fclose(out);
  }
  else {
    fprintf(log,"%5s  %5s  %8s  %8s\n","i","j","b_aver","sigma");
    for(i=0; (i<gnx/2); i++) {
      fprintf(log,"%5u  %5u  %8.5f  %8.5f\n",1+index[2*i],1+index[2*i+1],
	      aver_lsq(&b_all[i]),sigma_lsq(&b_all[i]));
    }
  }
}