예제 #1
0
void read_coordinates(char *argv[])
{
  static FILE *fp;
  static char Species[20];
  static double tmp0,tmp1;
  static int i,j;

  Gxyz = (double**)malloc(sizeof(double*)*(atomnum+1)); 
  for (i=0; i<=atomnum; i++){
    Gxyz[i] = (double*)malloc(sizeof(double)*60); 
  }

  if ((fp = fopen(argv[2],"r")) != NULL){
    printf("Read the coordinates file (%s)\n",argv[2]);

    /****************************************************
                         open the file
    ****************************************************/

    input_open(argv[2]);

    /****************************************************
                         read data
    ****************************************************/

    if (fp=input_find("<Atoms.SpeciesAndCoordinates") ) {
      for (i=1; i<=atomnum; i++){
        fscanf(fp,"%i %s %lf %lf %lf %lf %lf",&j,&Species,
	       &Gxyz[i][1],&Gxyz[i][2],&Gxyz[i][3],&tmp0,&tmp1);

        if (i!=j){
          printf("Format error of the sequential number %i in <Atoms.SpeciesAndCoordinates\n",j);
          exit(0);
        }
      }

      if (!input_last("Atoms.SpeciesAndCoordinates>")) {
        /* format error */
        printf("Format error for Atoms.SpeciesAndCoordinates\n");
        exit(0);
      }
    }

    /****************************************************
                       input_close
    ****************************************************/

    input_close();
  }
  else {
    printf("Failure of reading the coordinates file (%s).\n",argv[2]);
  }

  for (i=1; i<=atomnum; i++){
    printf("i=%i  coodinates=%15.12f %15.12f %15.12f\n",
	   i,Gxyz[i][1],Gxyz[i][2],Gxyz[i][3]);
  }

}
예제 #2
0
파일: funcs.c 프로젝트: portis/YATC
void input_add(gchar *name, gboolean cont)
{
  input *itmp = input_find(name);

  if (itmp==NULL)
    {
      itmp = (input *)calloc(sizeof(input), 1);
      itmp->name = g_strdup(name);
      itmp->controllable = cont;
    }

  g_ptr_array_add(intab, itmp);
}
예제 #3
0
void Show_DFT_DATA(char *argv[]) 
{
  FILE *fp,*fp0,*fp1,*fp2,*fp3;
  int Num_DatFiles,i,j,k,fp_OK;
  int Num_Atoms;
  int NGrid1_1,NGrid1_2,NGrid1_3;
  int NGrid2_1,NGrid2_2,NGrid2_3;
  double Utot1,Utot2,dU,dF;
  double gx,gy,gz,fx,fy,fz;
  double sum1,sum2;
  double time1,TotalTime;
  char SN[30][YOUSO10];
  char SB[30][YOUSO10];
  char SV[30][YOUSO10];
  char fname[YOUSO10];
  char fname0[YOUSO10];
  char fname1[YOUSO10];
  char fname2[YOUSO10];
  char fname_dat[YOUSO10];
  char fname_dat2[YOUSO10];
  char fname_out1[YOUSO10];
  char fname_out2[YOUSO10];
  char ftmp[YOUSO10];
  fname_type *fndat;
  int numprocs,myid;

  char *dir;
  char input_dir[300];
  char *output_file;
  DIR *dp;
  struct dirent *entry;

  MPI_Request request;
  MPI_Status  status;

  /* set up MPI */

  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);

  sprintf(input_dir,"%s",argv[2]);

  printf("%s\n",input_dir);
  
  /* print the header */

  if (myid==Host_ID){

    /* set dir */

    dir = input_dir;

    /* count the number of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){

      if ( strstr(entry->d_name,".dat")!=NULL ){ 
          
        Num_DatFiles++;
      }
    }
    closedir(dp);

    fndat = (fname_type*)malloc(sizeof(fname_type)*Num_DatFiles);

    /* store the name of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){
 
      if ( strstr(entry->d_name,".dat")!=NULL ){ 

        sprintf(fndat[Num_DatFiles].fn,"%s/%s",input_dir,entry->d_name);  
        Num_DatFiles++;
      }
    }
    closedir(dp);

  } /* if (myid==Host_ID) */

  if (myid==Host_ID){
    printf(" %2d dat files are found in the directory '%s'.\n\n\n",Num_DatFiles,input_dir);
  }

  /***********************************************************
         start calculations
  ***********************************************************/

  for (i=0; i<Num_DatFiles; i++){

    sprintf(fname_dat,"%s",fndat[i].fn);

    input_open(fname_dat);
    input_int("Species.Number",&SpeciesNum,0);

    /* read Definition.of.Atomic.Species */

    if (fp=input_find("<Definition.of.Atomic.Species")) {

      for (k=0; k<SpeciesNum; k++){
        fscanf(fp,"%s %s %s",SN[k],SB[k],SV[k]);

        printf("i=%2d k=%2d %s %s\n",i,k,SB[k],SV[k]);

	/*
        SpeciesString2int(i);
	*/
      }

      if (! input_last("Definition.of.Atomic.Species>")) {
	MPI_Finalize();
	exit(0);
      }
    }

    input_close();
  }

  if (myid==Host_ID){
    free(fndat);
  }

  MPI_Barrier(mpi_comm_level1);
  MPI_Finalize();
  exit(0);
}
예제 #4
0
파일: esp.c 프로젝트: certik/openmx
void read_input(char *file)
{
  static int i,j,spe,po;
  static int coordinates_unit;
  static int ct_AN;
  double r_vec[20],r_vec2[20];
  int i_vec[20],i_vec2[20];
  char *s_vec[20],Species[20];
  char buf[MAXBUF];
  FILE *fp;


  if (input_open(file)){

    /****************************************************
                 find dipole moment
    ****************************************************/

    if (fp=input_find("Dipole") ) {
      fscanf(fp,"%s",buf);
      fscanf(fp,"%s",buf);
      fscanf(fp,"%s %lf %lf %lf",buf,&Ref_DipMx,&Ref_DipMy,&Ref_DipMz);
    }

    input_close();
  }
  else {
    exit(0);
  }

  /****************************************************
              Definition of Atomic Species
  ****************************************************/

  /*
  input_int("Species.Number",&SpeciesNum,0);
  if (SpeciesNum<=0){
    printf("Species.Number may be wrong.\n");
    po++;
  }

  SpeName = (char**)malloc(sizeof(char*)*SpeciesNum);
  for (spe=0; spe<SpeciesNum; spe++){
    SpeName[spe] = (char*)malloc(sizeof(char)*YOUSO10);
  }  

  SpeBasis = (char**)malloc(sizeof(char*)*SpeciesNum);
  for (spe=0; spe<SpeciesNum; spe++){
    SpeBasis[spe] = (char*)malloc(sizeof(char)*YOUSO10);
  }  

  SpeVPS = (char**)malloc(sizeof(char*)*SpeciesNum);
  for (spe=0; spe<SpeciesNum; spe++){
    SpeVPS[spe] = (char*)malloc(sizeof(char)*YOUSO10);
  }  

  if (fp=input_find("<Definition.of.Atomic.Species")) {
    for (i=0; i<SpeciesNum; i++){
      fscanf(fp,"%s %s %s",SpeName[i],SpeBasis[i],SpeVPS[i]);
    }
    if (! input_last("Definition.of.Atomic.Species>")) {

      po++;

      printf("Format error for Definition.of.Atomic.Species\n");
      exit(0);
    }
  }
  */

  /****************************************************
                        atoms
  ****************************************************/

  /*
  input_int("Atoms.Number",&atomnum,0);
  s_vec[0]="Ang";  s_vec[1]="AU";
  i_vec[0]= 0;     i_vec[1]= 1;
  input_string2int("Atoms.SpeciesAndCoordinates.Unit",
                   &coordinates_unit,2,s_vec,i_vec);

  if (fp=input_find("<Atoms.SpeciesAndCoordinates") ) {

    for (i=1; i<=atomnum; i++){
      fgets(buf,MAXBUF,fp);

      sscanf(buf,"%i %s %lf %lf %lf",
             &j, &Species, &Gxyz[i][1],&Gxyz[i][2],&Gxyz[i][3]);

      WhatSpecies[i] = Species2int(Species);

      printf("i=%3d spe=%2d %15.12f %15.12f %15.12f\n",
              i,WhatSpecies[i],Gxyz[i][1],Gxyz[i][2],Gxyz[i][3]);

      if (i!=j){
	printf("Format error of the sequential number %i in <Atoms.SpeciesAndCoordinates\n",j);
	po++;
      }
    }

    ungetc('\n',fp);
    if (!input_last("Atoms.SpeciesAndCoordinates>")) {

      printf("Format error for Atoms.SpeciesAndCoordinates\n");
      po++;
    }

    if (coordinates_unit==0){
      for (i=1; i<=atomnum; i++){
	Gxyz[i][1] = Gxyz[i][1]/BohrR;
	Gxyz[i][2] = Gxyz[i][2]/BohrR;
	Gxyz[i][3] = Gxyz[i][3]/BohrR;
      }
    }
  }
  */


}
예제 #5
0
파일: Runtest.c 프로젝트: rigarash/openmx
void Runtest(char *mode, int argc, char *argv[]) 
{
  FILE *fp,*fp0,*fp1,*fp2,*fp3;
  int Num_DatFiles,i,j,k,fp_OK;
  int Num_Atoms;
  int NGrid1_1,NGrid1_2,NGrid1_3;
  int NGrid2_1,NGrid2_2,NGrid2_3;
  double Utot1,Utot2,dU,dF;
  double Spread1,Spread2;
  double Omega1,Omega2;
  double gx,gy,gz,fx,fy,fz;
  double sum1,sum2;
  double time1,TotalTime;
  char fname[YOUSO10];
  char fname0[YOUSO10];
  char fname1[YOUSO10];
  char fname2[YOUSO10];
  char fname_dat[YOUSO10];
  char fname_dat2[YOUSO10];
  char fname_out1[YOUSO10];
  char fname_out2[YOUSO10];
  char ftmp[YOUSO10];
  fname_type *fndat;
  char operate[800];
  int numprocs,myid;

  char *dir;
  char *input_dir;
  char *output_file;
  DIR *dp;
  struct dirent *entry;

  MPI_Request request;
  MPI_Status  status;

  /* set up MPI */

  MPI_Comm_size(MPI_COMM_WORLD1, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD1, &myid);

  if (strcasecmp(mode,"S")==0){  
    input_dir = "input_example";
    output_file = "runtest.result";
  }
  else if (strcasecmp(mode,"L")==0){  
    input_dir = "large_example";
    output_file = "runtestL.result";
  }
  else if (strcasecmp(mode,"L2")==0){  
    input_dir = "large2_example";
    output_file = "runtestL2.result";
  }
  else if (strcasecmp(mode,"G")==0){  
    input_dir = "geoopt_example";
    output_file = "runtestG.result";
  }
  else if (strcasecmp(mode,"WF")==0){  
    input_dir = "wf_example";
    output_file = "runtestWF.result";
  }
  else if (strcasecmp(mode,"NEGF")==0){  
    input_dir = "negf_example";
    output_file = "runtestNEGF.result";
  }

  /* set Runtest_flag */

  Runtest_flag = 1;

  /* initialize TotalTime */

  TotalTime = 0.0;

  /* print the header */

  if (myid==Host_ID){

    printf("\n*******************************************************\n");  fflush(stdout);
    printf("*******************************************************\n");    fflush(stdout);
    printf(" Welcome to OpenMX   Ver. %s                           \n",Version_OpenMX); fflush(stdout);
    printf(" Copyright (C), 2002-2013, T.Ozaki                     \n");    fflush(stdout);
    printf(" OpenMX comes with ABSOLUTELY NO WARRANTY.             \n");    fflush(stdout);
    printf(" This is free software, and you are welcome to         \n");    fflush(stdout);
    printf(" redistribute it under the constitution of the GNU-GPL.\n");    fflush(stdout);
    printf("*******************************************************\n");    fflush(stdout);
    printf("*******************************************************\n\n\n");fflush(stdout);  

    printf("\n");
    printf(" OpenMX is now in the mode to check whether OpenMX runs normally\n"); fflush(stdout);
    printf(" on your machine or not by comparing the stored *.out and\n");        fflush(stdout);
    printf(" generated *.out \n"); fflush(stdout);
    printf("\n");fflush(stdout);

    /* set dir */

    dir = input_dir;

    /* count the number of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){

      if ( strstr(entry->d_name,".dat")!=NULL ){ 
          
        Num_DatFiles++;
      }
    }
    closedir(dp);

    fndat = (fname_type*)malloc(sizeof(fname_type)*Num_DatFiles);

    /* store the name of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){
 
      if ( strstr(entry->d_name,".dat")!=NULL ){ 

        sprintf(fndat[Num_DatFiles].fn,"%s/%s",input_dir,entry->d_name);  
        Num_DatFiles++;
      }
    }
    closedir(dp);

    /* sorting fndat */

    qsort(fndat, Num_DatFiles, sizeof(fname_type), stringcomp);  

    /*
    for (i=0; i<Num_DatFiles; i++){
      printf("i=%2d %s\n",i,fndat[i].fn);
    } 
    */

  } /* if (myid==Host_ID) */

  sprintf(fname2,"%s",output_file);

  if (myid==Host_ID){
    fp = fopen(fname2, "r");   
    if (fp!=NULL){
      fclose(fp); 
      sprintf(operate,"%s",fname2);
      remove(operate);
    }
  }

  if (myid==Host_ID){
    printf(" %2d dat files are found in the directory '%s'.\n\n\n",Num_DatFiles,input_dir);
  }

  MPI_Bcast(&Num_DatFiles, 1, MPI_INT, Host_ID, MPI_COMM_WORLD1);

  /***********************************************************
                      start calculations
  ***********************************************************/

  for (i=0; i<Num_DatFiles; i++){

    if (myid==Host_ID){
      sprintf(fname_dat,"%s",fndat[i].fn);
    }  

    MPI_Bcast(&fname_dat, YOUSO10, MPI_CHAR, Host_ID, MPI_COMM_WORLD1);

    /* run openmx */

    argv[1] = fname_dat;
    run_main(argc, argv, numprocs, myid); 

    /***********************************************************
          comparison between two files and save the result               
    ***********************************************************/

    if (myid==Host_ID){

      input_open(fname_dat);
      input_string("System.Name",fname_dat2,"default");
      input_close();

      /* compare two out files */

      sprintf(fname_out1,"%s.out",fname_dat2);
      sprintf(fname_out2,"%s/%s.out",input_dir,fname_dat2);

      /* generated file */

      input_open(fname_out1);
      input_double("Utot.",&Utot1,(double)0.0);

      /* for Wannier functions */

      if (strcasecmp(mode,"WF")==0){  
        input_double("Sum.of.Spreads.",&Spread1,(double)0.0);
        input_double("Total.Omega.=",&Omega1,(double)0.0);
      }

      input_int("Num.Grid1.",&NGrid1_1,(int)0);
      input_int("Num.Grid2.",&NGrid1_2,(int)0);
      input_int("Num.Grid3.",&NGrid1_3,(int)0);

      input_double("Elapsed.Time.",&time1,(double)0.0);

      TotalTime += time1;

      if (fp3=input_find("<coordinates.forces")) {
          
	fscanf(fp3,"%d",&Num_Atoms);

	sum1 = 0.0;
	for (j=1; j<=Num_Atoms; j++){  
	  fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf",
		 &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz);
	  sum1 += fx + fy + fz;
	}

	if ( ! input_last("coordinates.forces>") ) {
	  printf("Format error for coordinates.forces\n");
	}
      }
      else {
	sum1 = 1000.0;
      }

      input_close();

      /* stored file */

      input_open(fname_out2);

      /* Utot */

      input_double("Utot.",&Utot2,(double)0.0);

      /* for Wannier functions */

      if (strcasecmp(mode,"WF")==0){  
        input_double("Sum.of.Spreads.",&Spread2,(double)0.0);
        input_double("Total.Omega.=",&Omega2,(double)0.0);
      }

      /* grids */

      input_int("Num.Grid1.",&NGrid2_1,(int)0);
      input_int("Num.Grid2.",&NGrid2_2,(int)0);
      input_int("Num.Grid3.",&NGrid2_3,(int)0);

      /* coordinates and forces */

      if (fp3=input_find("<coordinates.forces")) {
          
	fscanf(fp3,"%d",&Num_Atoms);

	sum2 = 0.0;
	for (j=1; j<=Num_Atoms; j++){  
	  fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf",
		 &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz);
	  sum2 += fx + fy + fz;
	}

	if ( ! input_last("coordinates.forces>") ) {
	  /* format error */
	  printf("Format error for coordinates.forces\n");
	}
      }
      else {
	sum2 = 100.0;
      }

      input_close();

      dU = fabs(Utot1 - Utot2);
      dF = fabs(sum1 - sum2);

      /* write the result to a file, runtest.result */

      if ( (fp2 = fopen(fname2,"a")) != NULL ){

	if (  (NGrid1_1!=NGrid2_1)
	      || (NGrid1_2!=NGrid2_2)
	      || (NGrid1_3!=NGrid2_3) )
	  {
	    fprintf(fp2,"  Invalid comparison due to the different number of grids.\n");
	    fprintf(fp2,"  You may use a different radix for FFT.\n");
	  }

        if (strcasecmp(mode,"WF")==0){  

	  fprintf(fp2,"%4d  %-32.30s Elapsed time(s)=%8.2f  diff spread=%15.12f  diff Omega=%15.12f\n",
		  i+1,fname_dat,time1,fabs(Spread1-Spread2),fabs(Omega1-Omega2));
	}
        else{

	  fprintf(fp2,"%4d  %-32.30s Elapsed time(s)=%8.2f  diff Utot=%15.12f  diff Force=%15.12f\n",
		i+1,fname_dat,time1,dU,dF);
	}

	if (i==(Num_DatFiles-1)){
	  fprintf(fp2,"\n\nTotal elapsed time (s) %11.2f\n",TotalTime);
	}

	fclose(fp2);
      }
    }

  }

  /* tell us the end of calculation */
  if (myid==Host_ID){
    printf("\n\n\n\n");
    printf("The comparison can be found in a file '%s'.\n\n\n",output_file);
  }

  if (myid==Host_ID){
    free(fndat);
  }


  MPI_Barrier(MPI_COMM_WORLD1);
  MPI_Finalize();
  exit(0);
}