Esempio n. 1
0
static void * power_acquisition_job(void *arg) {
	INIT_JOB_THREAD();

	while(1) {
		nanosleep((struct timespec[]){{0, ACQUIRING_INTERVAL * 1000000}}, NULL);
		get_energy();
	}
Esempio n. 2
0
/** \brief Compute vital state (satiation, energy, age) for the next cycle.

    - Mark creature as aged, if age is greater as max age.
    - Mark creature as starved, if satiation falls under half of the maximum
    satiation.
    - Mark creature as underfed, if energy level falls under half of the maximum
    energy.
*/
void
Creature::next_vital_state() {

    if (living_state == LivingState::alive()) {

        set_age(get_age() + 1);
        if (get_age() == get_max_age()) {
            living_state = LivingState::aged();
        }
        else {
            set_satiation(get_raw_satiation() - get_satiation_consumption());
            if (get_satiation() == 0) {
                living_state = LivingState::starved();
            }
            else {

                // TODO (joobog#2#): code verbessern
                double value = 2 * get_energy_consumption() *
                    ((double) get_satiation() /
                     (double) get_max_satiation() - (double) 0.5);

                if ( value < 0) {
                    set_energy(get_raw_energy() - (unsigned int) (-value));
                }
                if ( value > 0) {
                    set_energy(get_raw_energy() + (unsigned int) value);
                }

                if (get_energy() == 0) {
                    living_state = LivingState::underfed();
                }
            }
        }
    }
}
Esempio n. 3
0
double PIC::total_kinetic_energy()
{
 long j, n=part.size();
 double tem1=0.0;
 for(j=0; j<n; j++)
	     tem1+=macroN*get_energy(j);
 return tem1;
}
Esempio n. 4
0
void PitchFlockViewer::plot_bend ()
{
  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  const float * restrict power = get_power();
  const float * restrict energy = get_energy();
  const float * restrict bend = synth().get_bend();
  float * restrict red = m_bend_image.red;
  float * restrict green = m_bend_image.green;
  float * restrict blue = m_bend_image.blue;

  float energy_gain = m_energy_gain.update(max(get_energy()));
  float power_gain = m_power_gain.update(max(get_power()));
  float bend_variance = norm_squared(synth().get_bend()) / I;
  float bend_gain = m_bend_gain.update(bend_variance);
  float min_freq = min(synth().get_freq());
  float max_freq = max(synth().get_freq());
  float pitch_scale = 1 / log(max_freq / min_freq);

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {

      float m = energy_gain * energy[i];
      float e = power_gain * power[i];

      float b = atanf(0.5f * bend_gain * bend[i]) / M_PI + 0.5f;
      float p = static_cast<float>(i) / I + pitch_scale * log(1 + bend[i]);

      BilinearInterpolate lin(b * X, X, p * Y, Y);

      lin.imax(red, e);
      lin.imax(green, m);
      lin.imax(blue, 1);
    }

    m_image_mutex.unlock();
  }
}
Esempio n. 5
0
void PitchFlockViewer::plot_pca_4d ()
{
  float timescale = FLOCK_PCA_TIMESCALE_SEC * DEFAULT_AUDIO_FRAMERATE;
  float dt = 1 / timescale;

  m_pca.add_sample(synth().get_beat(), dt);

  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  float * restrict select_x = m_select_x;
  float * restrict select_y = m_select_y1;

  float pca_gain = sqrtf(I) / 8;
  const float * restrict energy = get_energy();
  const float * restrict pca_w = m_pca.component(0);
  const float * restrict pca_x = m_pca.component(1);
  const float * restrict pca_y = m_pca.component(2);
  const float * restrict pca_z = m_pca.component(3);
  const float * restrict pca_u = m_pca.component(4);
  const float * restrict pca_v = m_pca.component(5);

  const float ru = 1.0f;
  const float bu = cos(2 * M_PI / 3);
  const float bv = sin(2 * M_PI / 3);
  const float gu = cos(-2 * M_PI / 3);
  const float gv = sin(-2 * M_PI / 3);

  float * restrict energy_image = m_energy_image;
  float * restrict red = m_pca_image.red;
  float * restrict green = m_pca_image.green;
  float * restrict blue = m_pca_image.blue;

  const LinAlg::Orientation4D angle = m_angle4;

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {
      float m = energy[i];
      float wxyz[4] = {pca_w[i], pca_x[i], pca_y[i], pca_z[i]};
      float u = pca_u[i] * pca_gain;
      float v = pca_v[i] * pca_gain;

      float uv_scale = 1 / (1 + sqrt(max(1e-20f, sqr(u) + sqr(v))));
      u *= uv_scale;
      v *= uv_scale;

      float r = sqr((1 + ru * u) / 2);
      float g = sqr((1 + gu * u + gv * v) / 2);
      float b = sqr((1 + bu * u + bv * v) / 2);

      float x = pca_gain * angle.coord_dot(0, wxyz);
      float y = pca_gain * angle.coord_dot(1, wxyz);

      float x_01 = select_x[i] = (1 + x) / 2;
      float y_01 = select_y[i] = (1 + y) / 2;

      BilinearInterpolate lin(x_01 * X, X, y_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);
    }

    m_image_mutex.unlock();
  }
}
Esempio n. 6
0
void PitchFlockViewer::plot_pca_freq ()
{
  float timescale = FLOCK_PCA_TIMESCALE_SEC * DEFAULT_AUDIO_FRAMERATE;
  float dt = 1 / timescale;

  m_pca.add_sample(synth().get_beat(), dt);

  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  float * restrict select_x = m_select_x;
  float * restrict select_y1 = m_select_y1;
  float * restrict select_y2 = m_select_y2;

  float pca_gain = sqrtf(I) / 8;
  float dx_gain = sqrtf(I) / synth().num_tones();
  const float * restrict energy = get_energy();
  const float * restrict pca_y = m_pca.component(0);
  const float * restrict pca_z = m_pca.component(1);
  const float * restrict pca_u = m_pca.component(2);
  const float * restrict pca_v = m_pca.component(3);
  const float * restrict pca_dx = m_pca.component(4);

  const float ru = 1.0f;
  const float bu = cos(2 * M_PI / 3);
  const float bv = sin(2 * M_PI / 3);
  const float gu = cos(-2 * M_PI / 3);
  const float gv = sin(-2 * M_PI / 3);

  float * restrict energy_image = m_energy_image;
  float * restrict red = m_pca_image.red;
  float * restrict green = m_pca_image.green;
  float * restrict blue = m_pca_image.blue;

  const LinAlg::Orientation3D angle = m_angle3;
  const float skew = 1.0f / 20;

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {
      float m = energy[i];
      float xyz[3] = {
        1 - (i + 0.5f) / I * 2 + pca_dx[i] * dx_gain,
        pca_y[i] * pca_gain,
        pca_z[i] * pca_gain
      };
      float u = pca_u[i] * pca_gain;
      float v = pca_v[i] * pca_gain;

      float uv_scale = 1 / (1 + sqrt(max(1e-20f, sqr(u) + sqr(v))));
      u *= uv_scale;
      v *= uv_scale;

      float r = sqr((1 + ru * u) / 2);
      float g = sqr((1 + gu * u + gv * v) / 2);
      float b = sqr((1 + bu * u + bv * v) / 2);

      float x = angle.coord_dot(0, xyz);
      float y = angle.coord_dot(1, xyz);
      float z = angle.coord_dot(2, xyz);

      float y1 = y - skew * z;
      float y2 = y + skew * z;

      float x_01 = select_x[i] = (1 + x) / 2;
      float y1_01 = select_y1[i] = (1 + y1) / 4;
      float y2_01 = select_y2[i] = (1 + y2 + 2) / 4;

      BilinearInterpolate lin(x_01 * X, X, y1_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);

      lin.y(y2_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);
    }

    m_image_mutex.unlock();
  }
}
Esempio n. 7
0
		bool is_damaged() const { return get_energy() != MAX_ENERGY; }
Esempio n. 8
0
		bool is_dead() const { return get_energy() == 0; }
Esempio n. 9
0
		bool is_alive() const { return get_energy() != 0; }
Esempio n. 10
0
int main(int argc, char *argv[])
{
   FILE **fp,*fp2;
   Input input;
/* struct dirent **files; */

   char **symbol,*tmp;
   int count,evnum,i,j,noweight=FALSE,stop=0,tech=ERD,tmpi,*Z,ZZ;
   int e,tof;
/* int *step; */
   double beamM,energy,*emax,*M,*M2,tmpd,***sto,***weight;
   gsto_table_t *table;

   if(argc == 1){
      printf("Usage: tof_list [filename] [filename] ...\n");
      exit(1);
   }

   fp = (FILE **) malloc(sizeof(FILE *)*(argc-1));
   input.ecalib = (double *) malloc(sizeof(double)*(argc-1));
   symbol = (char **) malloc(sizeof(char *)*(argc-1));
   tmp = (char *) malloc(sizeof(char)*WORD_LENGTH);
/*   evnum = (int *) malloc(sizeof(int)*(argc-1)); */
/* step = (int *) malloc(sizeof(int)*(argc-1)); */
   Z = (int *) malloc(sizeof(int)*(argc-1));
/*   e = (double *) malloc(sizeof(double)*(argc-1)); */
   emax = (double *) malloc(sizeof(double)*(argc-1));
   M = (double *) malloc(sizeof(double)*(argc-1));
   M2 = (double *) malloc(sizeof(double)*(argc-1));
/*   tof = (double *) malloc(sizeof(double)*(argc-1)); */
   sto = (double ***) malloc(sizeof(double **)*(argc-1));
   weight = (double ***) malloc(sizeof(double **)*(argc-1));

   read_input(&input);

/* Useless filename.* feature

   for(i=0; (*tmp++ = *argv[1]++) != '.'; i++);
   for(j=i; j>0; j--,tmp--);
   if(*argv[1] == '*'){
      argc = 1;
      for(j=scandir(".",&files,0,alphasort); j>0; j--)
         if(!strncmp(files[j]->d_name,tmp,i))
            sscanf(files[j]->d_name,"%s",argv[argc++]);
   }
   else for(; i>-1; i--,argv[1]--);

*/
    table=gsto_init(MAXELEMENTS, XSTR(STOPPING_DATA));
    if(!table) {
        fprintf(stderr, "Could not init stopping table.\n");
        return 0;
    }
    gsto_auto_assign_range(table, 1, MAXELEMENTS, 6, 6); /* TODO: only assign relevant stopping */
    if(!gsto_load(table)) {
        fprintf(stderr, "Error in loading stopping.\n");
        return 0;
    }
    for(i=0; i<argc-1; i++){
      input.ecalib[i] = 0.0;
      symbol[i] = (char *) malloc(sizeof(char)*3);
      fp[i] = fopen(argv[i+1],"r");
      if(fp[i] == NULL){
         fprintf(stderr,"Could not open data file %s\n",argv[i+1]);
         exit(2);
      }
      while(*argv[i+1]++ != '.');
	  Z[i]=0; /* In Windows GCC, Z[i] is initialized with a large number as it's content, so this had to be done */
      while(isdigit(*argv[i+1])) Z[i] = Z[i]*10 + *argv[i+1]++ - '0';
      while(isalpha(*argv[i+1])) *symbol[i]++ = *argv[i+1]++; *symbol[i] = '\0';
      while(!isupper(*--symbol[i]));
      ZZ = Z[i];
      M[i] = get_mass(symbol[i],&ZZ);
	  M2[i] = 0;
      tmpi = input.beamZ;
      beamM = get_mass(input.beam,&tmpi);
      emax[i] = input.beamE*4.0*ipow(cos(input.theta*C_DEG),2)*beamM*M[i]/ipow(beamM+M[i],2);
      sto[i] = set_sto(table, (Z[i])?Z[i]:ZZ,M[i],emax[i]*MAX_FACTOR);
/*    step[i] = get_step(emax[i]*MAX_FACTOR,sto[i]); */
      weight[i] = set_weight(symbol[i],(Z[i])?Z[i]:ZZ,&input);
      Z[i] = ZZ;
      if(*argv[i+1] == '.'){
         if(*++argv[i+1] == 'e'){
            tmp = strcpy(tmp,symbol[i]);
            if((fp2 = fopen(strcat(tmp,".calib"),"r")) == NULL){
               fprintf(stderr,"Could not locate calibration file %s\n",tmp);
               exit(3);
            }
            fscanf(fp2,"%lf",&input.ecalib[i]);
            fclose(fp2);
         }
      }
   }
   gsto_deallocate(table); /* Stopping data loaded in already, this is not used anymore */
   for(i=0; i<argc-2; i++)
      for(j=i+1; j<argc-1; j++)
         if(!strcmp(symbol[i],symbol[j])) noweight = TRUE;

   char herp_c [100];
   char *herp_d;
   int derp_n;
   char herpderp_1 [10];
   char herpderp_2 [10];
   float user_weight = 1.0;
   
   char herp_type [3];
   char herp_scatter [6];
   int herp_isotope=0;
   for(i=0;i<argc-1;i++){
	  tech = ERD;
	  herp_d = (char *) malloc(sizeof(char)*WORD_LENGTH);
      /* Don't read the first ten lines, except the one line which 
         contains the user-specified weight factor which is memorized. */
      for(derp_n=0;derp_n<10;derp_n++){
	     fgets(herp_c, 100, fp[i]);
         if(derp_n == 1){
            sscanf(herp_c, "%s %s", &herpderp_1, &herp_type);
			if (strcmp(herp_type, "RBS") == 0) tech = RBS;
         }
         if(derp_n == 2){
			sscanf(herp_c, "%s %s %f", &herpderp_1, &herpderp_2, &user_weight);
         }
		 if(derp_n == 5 && tech == 0){
            sscanf(herp_c, "%s %s %s", &herpderp_1, &herpderp_2, herp_d);
			
			// Parse isotope from string
			while(isdigit(*herp_d)) herp_isotope = herp_isotope*10 + *herp_d++ - '0';
			
			// Parse element
			sscanf(herp_d, "%s", herp_scatter);
			
			//printf("Scatter element: %s\n", herp_scatter);
			//printf("Scatter isotope: %i\n", herp_isotope);
			//printf("Scatter isotope mass: %8.4f\n", get_mass(herp_scatter, &herp_isotope)/C_U);
			// Get new mass and update values to scatter element.
			M2[i] = get_mass(herp_scatter, &herp_isotope);
			Z[i] = herp_isotope;
			/*
			emax[i] = input.beamE*4.0*ipow(cos(input.theta*C_DEG),2)*beamM*M[i]/ipow(beamM+M[i],2);
#ifdef ZBL96
			sto[i] = set_sto((Z[i])?Z[i]:ZZ,M[i],emax[i]*MAX_FACTOR);
#else
			sto[i] = set_sto(stopping, (Z[i])?Z[i]:ZZ,M[i],emax[i]*MAX_FACTOR);
#endif
			*/
         }
         
	  }
      while(fscanf(fp[i], "%i %i %i", &tof, &e, &evnum) == 3){
         if(e > 0){
            if(tof == 0){
               energy  = e + ((double)(rand())/RAND_MAX) - 0.5;
               energy *= input.ecalib[i];
               energy *= C_MEV;
            } else {
               energy = tof +  ((double)(rand())/RAND_MAX) - 0.5;
               energy = get_energy(input.tof,energy*input.calib1 + input.calib2,M[i]);
            }
            tmpd = get_eloss(energy,sto[i]);
            energy = (tmpd > -0.1)?energy + tmpd*input.foil_thick:-1.0;
            if(energy > -0.1 && energy < emax[i]*MAX_FACTOR){
               printf("%5.1f %5.1f ",ANGLE1,ANGLE2);
               //printf("%10.5lf %3d %8.4f ",energy/C_MEV,Z[i],M[i]/C_U); // Original
               printf("%10.5lf %3d %8.4f ",energy/C_MEV, Z[i], (tech == 0)?M2[i]/C_U:M[i]/C_U);
               printf("%s %6.3f %5d\n",(tech)?"ERD":"RBS",(noweight)?1.0:get_weight(weight[i],energy)*user_weight,evnum);
            }
         }
      }
      fclose(fp[i]);
   }

#if 0
   for(i=0; i<argc-1; i++)
      fscanf(fp[i],"%lf %lf %d",&tof[i],&e[i],&evnum[i]);

   for(count=0; stop<argc-1; count++){
      stop = 0;
      for(i=0; i<argc-1; i++){
         if(!evnum[i]) stop++;
         else if(count == evnum[i]){
            if((int)(e[i])){
               if(!(int)(tof[i])) tof[i] = e[i];
               /* Randomize input channel */
                  tof[i] += -0.5 + ((double)(rand())/RAND_MAX);
               /* Calculate energy from channel */
                  tof[i] = (input.ecalib[i]>0.00001)?tof[i]*input.ecalib[i]:get_energy(input.tof,tof[i]*input.calib1 + input.calib2,M[i]);
               /* Calculate and add energy loss in carbon foil */
                  tmpd = get_eloss(tof[i],sto[i]);
                  tof[i] = (tmpd>-0.1)?tof[i]+tmpd*input.foil_thick:-1.0;
/*             for(j=0; j<step[i]; j++)
                  tof[i] += get_eloss(tof[i],sto[i])*input.foil_thick/step[i]; */
               if(tof[i]>-0.1 && tof[i]<emax[i]*MAX_FACTOR){
                  printf("%5.1f %5.1f ",ANGLE1,ANGLE2);
                  printf("%10.5lf %3d %8.4f ",tof[i]/C_MEV,Z[i],M[i]/C_U);
                  printf("%s %6.3f %5d\n",(tech)?"ERD":"RBS",(noweight)?1.0:get_weight(weight[i],tof[i]),evnum[i]);
               }
            }
            if(fscanf(fp[i],"%lf %lf %d",&tof[i],&e[i],&evnum[i]) != 3)
               evnum[i] = 0;
         }
      }
   }
#endif

   for(i=0; i<argc-1; i++)
      fclose(fp[i]);

   exit(0);

}
Esempio n. 11
0
/**
 * IMPLEMENTATION D'UN RECUIT SIMULÉ 
 *
 * Voisinage : On enlève une station d'une remorque, et on l'insert_best 
 * (ou juste insert) dans une des remorque (sa remorque y compris, sa place
 * peut n'être plus optimale avec d'autres insertions)
 *
 * Energie : 
 *  - Version 0 : Cout de la solution
 *
 * Temperature : 
 *  - Version 0 : Décroissance de la température en T(n+1) = lambda * T(n)
 *   avec lambda = 0.99
 *
 * Solution initiale : La solution la plus bête possible, pour ne pas ensuite
 * être gêné par une solution qui serait trop bonne.
 * 
 * Algorithme :
 *  s := s0     // solution
 *  e := E(s)   // energie
 *  k := 0      // Iteration
 *  tant que k < kmax et e > emax
 *    sn := voisin(s)
 *    en := E(sn)
 *    si en < e ou aléatoire() < P(en - e, temp(k/kmax)) alors
 *      s := sn; e := en
 *    k := k + 1
 *  retourne s
 * 
 * @return Si une solution a pu être trouvée
 */
bool AnnealingSolver::solve() {
  if (log2()) {
      cout << "\n---AnnealingSolver::solve START instance: "
           << inst->name << " de taille "
           << inst->stations->size() << "\n";
  }

  // Seed initialisation
  srand (time(NULL));
  // ((double) rand() / (RAND_MAX)) // double btwn 0 and 1

  // Arguments
  Options* args = Options::args;
  const string sinserter = args->station_inserter;
  const string rchooser = args->remorque_chooser;
  int itermax = args->itermax;
  int recuit_variant = args->recuit_variant;
  double temp_init = args->temp_init;
  double lambda = args->lambda;
  int size_palier = args->size_palier;

  // Par défaut (-1) on ne fait qu'une seule itération
  itermax =  itermax == -1 ? 1 : itermax;
  temp_init =  temp_init == 10000.0 ? 10000.0 : temp_init;
  lambda =  lambda == 0.99 ? 0.99 : lambda;
  size_palier =  size_palier == 10 ? 10 : size_palier;

  double taux_acceptation_min = 0.000001;
  double taux_acceptation = 1;
  double nb_accepted = 0;

  // Recuit informations
  double temperature = temp_init;   // Initial temperature (default)
  double energy_max = 0;  // Energy maximum of acceptation
  double energy;          // Energy
  int k = 0;              // Iteration
  Solution* neighbour = new Solution(inst); // Intermediate solution

  // INITIAL SOLUTION (Stupid)
  Solution* sol = new Solution(inst);
  get_initial_solution(sol);
  energy = get_energy(sol);
  logn2("AnnealingSolver::Cost of the initial solution = "+sol->get_cost_string());
  logn2("AnnealingSolver::Energy of the initial solution = "+to_string(energy));

  // Result File 
  ofstream energy_file;
  energy_file.open("energy.csv",ios::app);
  energy_file << "\n"<< inst->name << ";" << time(NULL) << "\nEnergy;";

  ofstream temp_file;
  temp_file.open("temp.csv",ios::app);
  temp_file << "\n"<< inst->name << ";" << time(NULL) << "\nTemperature;";

  ofstream taux_acceptation_file;
  taux_acceptation_file.open("taux_acceptation.csv",ios::app);
  taux_acceptation_file << "\n"<< inst->name << ";" << time(NULL) << "\nTaux d'acceptation;";

  Solution* best_sol = new Solution(inst);
  best_sol->copy(sol);

  // RECUIT
  while (k < itermax && 
         energy > energy_max && 
         taux_acceptation > taux_acceptation_min) 
  {
    logn3("AnnealingSolver:: Iteration number "+to_string(k));

    energy_file << energy << ";";    
    temp_file << temperature << ";";    
    taux_acceptation_file << taux_acceptation << ";";    

    // Updating Temperature
    if (k % size_palier == 0)
      temperature = get_next_temperature(temperature,lambda);
    logn3("AnnealingSolver:: Temperature value "+to_string(temperature));

    // Getting neighbour
    get_neighbour(neighbour,sol,recuit_variant);
    double energy_neighbour = get_energy(neighbour);
    logn3("AnnealingSolver:: Energy of neighbour = "+to_string(energy_neighbour));

    // Choosing the solution
    if (energy_neighbour < energy ||
        ((double) rand() / (RAND_MAX)) < exp((energy - energy_neighbour)/temperature)) 
    {
      logn3("AnnealingSolver:: New solution found, energy = "+to_string(energy_neighbour));
      if (energy_neighbour < energy)
        cout << "-"; // Better
      else 
        cout << "+"; // Metropolis

      nb_accepted++;

      sol->clear();
      sol->copy(neighbour);

      if (sol->get_cost() < best_sol->get_cost()) {
        // We have a better solution 
        cout << endl << "AnnealingSolver:: Better sol found : " 
          << sol->get_cost() << " Temp : " << temperature << endl;
        best_sol->clear();
        best_sol->copy(sol);
      }

      energy = energy_neighbour;
    }
    else { // neighbour rejected 
      cout << ".";
    }

    // Updating iteration
    ++k;
    taux_acceptation = nb_accepted / k ;
  }
  cout << endl;

  energy_file << "\n" << best_sol->get_cost_string() << "\n";
  temp_file << "\n" << best_sol->get_cost_string() << "\n";
  taux_acceptation_file << "\n" << best_sol->get_cost_string() << "\n";

  energy_file.close();
  temp_file.close();
  taux_acceptation_file.close();

  this->found = true;
  this->solution = best_sol;
  logn2("StupidSolver::solve: END");
  return found;
}
Esempio n. 12
0
int	gmx_energy2bfac (int argc, char *argv[])		{
  const char *desc[] =
    { "It maps the binding energy contribution of each residue on the structure.",
      "The energy will be written in the B-factor field of the output PDB file/s",
      "This PDB file can be used with any molecular visualizer and ",
      "residues can be viewed in color according to the energy of respective residue.",
      "The molecular visualizer should support method to color residues by B-factor values."
	};


  t_filenm fnm[] =
  {
    { efTPS, "-s", NULL, ffREAD },
    { efDAT, "-i", "decomp_energy", ffREAD },
    { efNDX, "-n", "index", ffOPTRD },
    { efPDB, "-c", "complex.pdb", ffOPTWR },
    { efPDB, "-s1", "subunit_1.pdb", ffOPTWR },
    { efPDB, "-s2", "subunit_2.pdb", ffOPTWR },
  };

  char title[STRLEN], buf[256];
  t_topology top;
  int ePBC;
  rvec *xtop;
  matrix box;
  t_atoms *atoms;
  char *atomtype, *resname, *atomname, **modresname = NULL;
  output_env_t oenv;

  //Variable for index file
  int *isize;	//Number of index group
  atom_id **index;
  char **grpnm;

  int i=0,j=0,k=0;
  gmx_bool *bAtomA, *bAtomB, *bAtomAB;
  int nres = 0, prev_res, curr_res;
  gmx_bool *bResA, *bResB;
  real *energy;
  char fnEnergy[256];
  FILE *fComplex, *fS1, *fS2;

  #define NFILE asize(fnm)
  CopyRightMsg();
  //To show the option on the screen and to take the all option
  parse_common_args(&argc, argv,
      PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT | PCA_BE_NICE, NFILE, fnm,
      0, NULL, asize(desc), desc, 0, NULL, &oenv);

  read_tps_conf(ftp2fn(efTPS, NFILE, fnm), title, &top, &ePBC, &xtop, NULL, box, FALSE);
  atoms = &(top.atoms);

  if (opt2fn_null("-i", NFILE, fnm) == NULL )
    gmx_fatal(FARGS, "Residue energy file is missing, use \"-i\" option\n");
  else
      sprintf(fnEnergy, "%s", opt2fn("-i", NFILE, fnm));

  snew(isize, 2);
  snew(index, 2);
  snew(grpnm, 2);
  printf(
      "\n\n\nEnter the group number for Protein or first Protein or first group\n\n");
  get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &isize[0], &index[0],
      &grpnm[0]);
  printf(
      "\n\n\nEnter the group number of Ligand or second Protein or second group\n\n");
  get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &isize[1], &index[1],
      &grpnm[1]);

  srenew(index, 3);
  srenew(isize, 3);
  isize[2] = isize[0] + isize[1];
  snew(index[2], isize[0]+isize[1]);
  for (i = 0; i < isize[0]; i++)
	  index[2][i] = index[0][i];
  for (i = 0; i < isize[1]; i++)
	  index[2][i + isize[0]] = index[1][i];

  snew(bResA,top.atoms.nres);
  snew(bResB,top.atoms.nres);

  for(i = 0; i<top.atoms.nres;i++)
  {
	  bResA[i] = FALSE;
	  bResB[i] = FALSE;
  }

  nres = 1;
  prev_res = atoms->atom[index[2][0]].resind;
  bResA[atoms->atom[index[2][0]].resind] = TRUE;

  for(i=0;i<isize[2];i++)
  {
	  curr_res = atoms->atom[index[2][i]].resind;
	  if(curr_res != prev_res)
	  {
		  nres++;
		  if(i<isize[0])
			  bResA[atoms->atom[index[2][i]].resind] = TRUE;
		  else
			  bResB[atoms->atom[index[2][i]].resind] = TRUE;

		  prev_res = curr_res;
	  }
  }

  printf("\nTotal number of residues in topology: %d \n", nres);

  snew(energy,nres);
  get_energy( fnEnergy, nres, energy);

  snew(atoms->pdbinfo, atoms->nr);

  for(i = 0; i<isize[2];i++)
  {
	  if((bResA[atoms->atom[index[2][i]].resind]) || (bResB[atoms->atom[index[2][i]].resind]))	{
		 atoms->pdbinfo[index[2][i]].bfac = energy[atoms->atom[index[2][i]].resind];
		 atoms->pdbinfo[index[2][i]].occup = 1.00;
	  }
	  else{
		  atoms->pdbinfo[index[2][i]].bfac = 0.00;
		  atoms->pdbinfo[index[2][i]].occup = 1.00;
	  }
  }

  fComplex = gmx_ffopen(opt2fn("-c", NFILE, fnm),"w");
  write_pdbfile_indexed(fComplex,NULL,atoms,xtop,ePBC,box,' ',-1,isize[2],index[2],NULL,TRUE);

  fS1 = gmx_ffopen(opt2fn("-s1", NFILE, fnm),"w");
  write_pdbfile_indexed(fS1,NULL,atoms,xtop,ePBC,box,' ',-1,isize[0],index[0],NULL,TRUE);

  fS2 = gmx_ffopen(opt2fn("-s2", NFILE, fnm),"w");
  write_pdbfile_indexed(fS2,NULL,atoms,xtop,ePBC,box,' ',-1,isize[1],index[1],NULL,TRUE);

return 0;
}
Esempio n. 13
0
double PIC::shift_xyz(double dt, double boundary, double delta_max, double Emax, double E0, long *d1)
{
  long j;
  int ref=0, sec=0;
  double gamma, u2, r2;
  double T0=2.0, phi_emit=0.0, energy=0.0;
  double ut=clight*sqrt(pow(fabs(charge_p)*T0/(mass_p*clight*clight)+1.0,2)-1.0);
  vector<Particle> part_new; 
  for(j=0; j<part.size(); j++)
   {
	u2=pow(part[j].uy,2)+pow(part[j].ux,2)+pow(part[j].uz,2);
	gamma=sqrt(1.0+u2/pow(clight,2));
	part[j].x+=part[j].ux*dt/gamma;
	part[j].y+=part[j].uy*dt/gamma;
        r2=pow(part[j].y,2)+pow(part[j].x,2);
	if ( sqrt(r2) > boundary ) 
	  {
	   ref=reflection(get_energy(j),E0,d1);
	   if (delta_max > 0.0) sec=secondary(get_energy(j),delta_max,Emax,d1);	
	   if ( ref == 1)
	    	{ 
		     //phi_emit=0.5*PI*(2.0*ran1(d1)-1.0);
			 //part[j].ux=-ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
			 //part[j].uy=-ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		     //part[j].ux=-part[j].ux;
		     //part[j].uy=-part[j].uy;
		         reflection_circular(part[j].ux,part[j].uy,part[j].x,part[j].y);
		         part[j].x=0.99*boundary*part[j].x/sqrt(r2);  
			 part[j].y=0.99*boundary*part[j].y/sqrt(r2);
		    } 
	   else { 
		     if (sec == 0) 
		       {   
			energy+=get_energy(j);
		        part.erase(part.begin()+j);
		       }
	         else if (sec == 1)
	          { 
		       energy+=get_energy(j);
			   phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
			   emission_circular(part[j].ux,part[j].uy,part[j].x,part[j].y,phi_emit,ut);
			   //part[j].ux=-ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
			   //part[j].uy=-ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       part[j].x=0.99*boundary*part[j].x/sqrt(r2);  
			   part[j].y=0.99*boundary*part[j].y/sqrt(r2);  
		      }
	         else if (sec == 2)
	          { 
		       energy+=get_energy(j);
		       Particle part_inj;
		       phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
		       emission_circular(part[j].ux,part[j].uy,part[j].x,part[j].y,phi_emit,ut);
		       //part[j].ux=-ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
		       //part[j].uy=-ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
		       emission_circular(part_inj.ux,part_inj.uy,part[j].x,part[j].y,phi_emit,ut);
		       //part_inj.ux = -ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
		       //part_inj.uy = -ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       part_inj.uz = 0.0;
		       part[j].x=0.99*boundary*part[j].x/sqrt(r2);  
		       part[j].y=0.99*boundary*part[j].y/sqrt(r2);  
		       part_inj.x = part[j].x;
			   part_inj.y = part[j].y; 
			   part_inj.z = part[j].z;
			   part_new.push_back(part_inj);
		     }
		    else if (sec == 3)
	         { 
		       energy+=get_energy(j);
		       Particle part_inj, part_inj_2;
		        phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
			emission_circular(part[j].ux,part[j].uy,part[j].x,part[j].y,phi_emit,ut);
		       //part[j].ux=-ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
		       //part[j].uy=-ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
		       emission_circular(part_inj.ux,part_inj.uy,part[j].x,part[j].y,phi_emit,ut);
		       //part_inj.ux = -ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
		       //part_inj.uy = -ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       part_inj.uz = 0.0;
		       phi_emit=0.1*PI*(2.0*ran1(d1)-1.0);
		       emission_circular(part_inj_2.ux,part_inj_2.uy,part[j].x,part[j].y,phi_emit,ut);
		       //part_inj_2.ux = -ut*(cos(phi_emit)*part[j].x/sqrt(r2)-sin(phi_emit)*part[j].y/sqrt(r2));
		       //part_inj_2.uy = -ut*(sin(phi_emit)*part[j].y/sqrt(r2)+cos(phi_emit)*part[j].y/sqrt(r2));
		       part_inj_2.uz = 0.0;
		       part[j].x=0.99*boundary*part[j].x/sqrt(r2);  
		       part[j].y=0.99*boundary*part[j].y/sqrt(r2);  
		           part_inj.x = part[j].x;
			   part_inj.y = part[j].y; 
			   part_inj.z = part[j].z;
			   part_inj_2.x = part[j].x;
			   part_inj_2.y = part[j].y; 
			   part_inj_2.z = part[j].z;
			   part_new.push_back(part_inj);
			   part_new.push_back(part_inj_2);
		     }
			else {cout << "shift_xyz: n>4" << endl; exit(0);}
		    }
	  }	
   }
   for(j=0; j<part_new.size(); j++)
	    part.push_back(part_new[j]);
	return macroN*energy;
}
Esempio n. 14
0
void bird_style_pics(int step)
{
	int kx, ky, krp, nc, nm;
	PARTICLE *p;
	double avr_conc[NC], avr_temp[NC], avr_mass[NC], new_avr_vx[NC], new_avr_vy[NC];
	for (nc = 0; nc < NC; nc++)
	{
		new_avr_vx[nc] = 0;
		new_avr_vy[nc] = 0;
		for (kx = 0; kx < KX; kx++)
		{
			for (ky = 0; ky < KY; ky++)
			{
				temp_field[nc][kx][ky] = 0.0;
				conc_field[nc][kx][ky] = 0.0;
				mass_field[nc][kx][ky] = 0.0;
				impulse_field[nc][kx][ky] = 0.0;
			}
		}
		for (kx = 0; kx < MAX_PLOT_VEL; kx++)
		{
			distr_x[nc][kx] = 0;
			distr_y[nc][kx] = 0;
		}
	}
	for (krp = 0; krp < KRP; krp++)
	{
		for (kx = 0; kx < KX; kx++)
		{
			for (ky = 0; ky < KY; ky++)
			{
				for (nc = 0; nc < NC; nc++)
				{
					for (nm = 0; nm < NM; nm++)
					{
						p = &camera[krp][kx][ky][nc][nm];
						conc_field[nc][kx][ky] += p->weight;
						temp_field[nc][kx][ky] += get_energy(p);
						mass_field[nc][kx][ky] += p->weight * p->mass * SIZEX * SIZEY * SIZEZ;
						impulse_field[nc][kx][ky] += p->weight * atan2(p->v.y, p->v.x);
						new_avr_vx[nc] += p->weight * p->v.x;
						new_avr_vy[nc] += p->weight * p->v.y;
						int num_vel_x = (int)(p->v.x + 0.5 * MAX_PLOT_VEL), num_vel_y = (int)(p->v.y + 0.5 * MAX_PLOT_VEL);
						if ((num_vel_x < MAX_PLOT_VEL)&&(num_vel_x>0)) {distr_x[nc][num_vel_x] += p->weight;}
						if ((num_vel_y < MAX_PLOT_VEL)&&(num_vel_y>0)) {distr_y[nc][num_vel_y] += p->weight;}
// 						if (fabs(p->v.x) < 0.5*MAX_PLOT_VEL) {distr_x[nc][(int)(p->v.x + 0.5 * MAX_PLOT_VEL)] += p->weight;}
// 						if (fabs(p->v.y) < 0.5*MAX_PLOT_VEL) {distr_y[nc][(int)(p->v.y + 0.5 * MAX_PLOT_VEL)] += p->weight;}
					}
				}
			}
		}
	}
	for (nc = 0; nc < NC; nc++)
	{
		avr_conc[nc] = 0;
		avr_temp[nc] = 0;
		avr_mass[nc] = 0;
		for (kx = 0; kx < KX; kx++)
		{
			for (ky = 0; ky < KY; ky++)
			{
				temp_field[nc][kx][ky] /= KRP;
				avr_temp[nc] += temp_field[nc][kx][ky];
				conc_field[nc][kx][ky] /= KRP;
				avr_conc[nc] += conc_field[nc][kx][ky];
				mass_field[nc][kx][ky] /= KRP;
				avr_mass[nc] += mass_field[nc][kx][ky];
				impulse_field[nc][kx][ky] = (conc_field[nc][kx][ky]>0)?(impulse_field[nc][kx][ky]/(conc_field[nc][kx][ky]*KRP)):100.0;
			}
		}
		avr_vx[nc] = (avr_conc[nc] > 0) ? new_avr_vx[nc]/(avr_conc[nc] * KRP) : 0;
		avr_vy[nc] = (avr_conc[nc] > 0) ? new_avr_vy[nc]/(avr_conc[nc] * KRP) : 0;
		printf("comp#%i: temp = %5.5e; conc = %5.5e; mass = %5.5e; vx = %e; vy = %e;\n", nc, avr_temp[nc]/(KX*KY), avr_conc[nc]/(KX*KY), avr_mass[nc] /(KX*KY), avr_vx[nc], avr_vy[nc]);
		
	}
	save_plot("temp2/plotx", distr_x, step);
	save_plot("temp2/ploty", distr_y, step);
	save_field("temp2/temp", temp_field, step);
	save_field("temp2/conc", conc_field, step);
	save_field("temp2/full_mass", mass_field, step);
	save_three_column("temp2/impulse", impulse_field, step);
//	print_forces(step);
}