Пример #1
0
bool SelectionTool::canPerform(const Object *o) const
{
    if (!o->inherits(CLASSNAME(PointObject))) return false;

    if (interaction().button() == Qt::LeftButton) return true;
    if (interaction().type() == Interaction::Move) return true;

    return false;
}
void GameObjectManager::update(const float currentTime, const float elapsedTime)
{
    Itr<BaseGameObject> it = _objects.GetFirst();
    while (it)
    {
        if (it->interactive())
        {
            interaction(it);
        }
        ++it;
    }
    it = _objects.GetFirst();
    BaseGameObject* deleted = NULL;
    while (it)
    {
        it->update(elapsedTime);
        if (it->deleted())
            deleted = it;
        ++it;
        if (deleted != NULL)
        {
            SAFE_DELETE(deleted);
            deleted = NULL;
        }
    }
}
Пример #3
0
int main()
{
    int do_what;
    int power;
    while (1)
    {
        printf("Please choose what to do:\n1--------->create a new user\n2--------->start server\n3--------->input command\n4--------->exit\n");
        scanf("%d",&do_what);
        switch (do_what)
        {
        case 1:
            create_user();
            break;
        case 2:
            init();
            int listenfd;
            power = interaction(listen_port,&listenfd);
            s_get_client(power,listenfd);
            break;
        case 3:
            get_command();
            break;
        case 4:
            exit(0);
        }
    }

}
Пример #4
0
static void power_hint(struct power_module *module, power_hint_t hint,
        void *data)
{
    /* Check if this hint has been overridden. */
    if (power_hint_override(module, hint, data) == HINT_HANDLED) {
        /* The power_hint has been handled. We can skip the rest. */
        return;
    }

    switch(hint) {
        case POWER_HINT_VSYNC:
        break;
        case POWER_HINT_INTERACTION:
        {
            int resources[] = {0x702, 0x20F, 0x30F};
            int duration = 3000;

            interaction(duration, sizeof(resources)/sizeof(resources[0]), resources);
        }
        break;
        case POWER_HINT_VIDEO_ENCODE:
            process_video_encode_hint(data);
        break;
        case POWER_HINT_VIDEO_DECODE:
            process_video_decode_hint(data);
        break;
    }
}
Пример #5
0
void Viewport::mouseMoveEvent(QMouseEvent *event)
{
    QPointF pos = map(event->pos());
    QPointF t = pos - _lastMousePos;
    Interaction interaction(t, event->modifiers());
    if (scene()) scene()->processInteraction(interaction);
    _lastMousePos = map(event->pos());
}
Пример #6
0
void Viewport::mouseReleaseEvent(QMouseEvent *event)
{
    QPointF pos = map(event->pos());
    _lastMousePos = pos;

    Interaction interaction(event->button(), pos, Interaction::Release, Interaction::NoClick, event->modifiers());
    if (scene()) scene()->processInteraction(interaction);
}
Пример #7
0
void Engine::drawObjects()
{
	checkKeys();
	interaction();

	camera->lookAt(player->GetX(), player->GetY(), player->GetZ());
			
	drawAxes();
	player->draw();
			
	for(int i = 0; i < 3; i++) { surface[i]->draw(); }

	calculateFPS();
	interf->draw();
}
Пример #8
0
static int dts_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in ) {
	sasl_interact_t *interact = in;

	if (!ld) {
		return LDAP_PARAM_ERROR;
	}

	while( interact->id != SASL_CB_LIST_END ) {
		int rc = interaction(flags, interact, defaults);
		if (rc)  {
			return rc;
		}
		interact++;
	}
	return LDAP_SUCCESS;
}
Пример #9
0
void SekHeng::Update(double dt) {
    time += dt;
    preventSpamming();
    //when the quest is activated, checking whether the player has the hammer
    if (Application::IsKeyPressed('E') && stage == 1 &&
        interaction() == false && hammerInHand == true) {
        FinishedQuest();
    }
    //when the quest is activated, checking whether the player has the hammer
    
    //Checking whether is this an active quest and the hammer is not collected,
    //If the hammer is within it's interacting boundary, the hammer is collected
    else if (hammerInHand == false && Application::IsKeyPressed('E') &&
        interactingWithItem() == false && stage == 1) {
        hammerInHand = true;
    }
}
Пример #10
0
SEXP interactionR (SEXP Rdata, SEXP Rnrows, SEXP Rncols, SEXP Rchoice)
{
      const int *data;
      const int *nrows, *ncols, *choice;
         SEXP res;
         PROTECT(Rdata = AS_INTEGER(Rdata));
         PROTECT(Rnrows= AS_INTEGER(Rnrows));
         PROTECT(Rncols= AS_INTEGER(Rncols));
		 PROTECT(Rchoice= AS_INTEGER(Rchoice));
         data = INTEGER_POINTER(Rdata);
         nrows= INTEGER_POINTER(Rnrows);
         ncols= INTEGER_POINTER(Rncols);   
		 choice= INTEGER_POINTER(Rchoice);    
         PROTECT(res = NEW_NUMERIC(1));
		 REAL(res)[0] = interaction(data, *nrows, *ncols, *choice);
		 UNPROTECT(5);
      return res;
}
Пример #11
0
void SelectionTool::perform_virtual(Object *o)
{
    PointObject* pointObject = (PointObject*) o;
    Point* p = pointObject->pointAt(interaction(o).point());

    if (p && interaction().click() == Interaction::DoubleClick) {
        PointEditDialog::exec_static(p,
                                     pointObject->inherits(CLASSNAME(Spline)) && ((Spline*) pointObject)->type() == Spline::Bezier,
                                     parentWidget());
    }

    if (interaction().type() == Interaction::Press) {
        if (p && !p->isSelected()) {
            _justSelectedOrRemoved = true;
        }
        if (interaction().modifiers() != Qt::SHIFT)
            pointObject->deselectAllPoints();
        if (p) {
            pointObject->selectPoint(p);
        }
    } else if (interaction().type() == Interaction::Release) {
        if (interaction().modifiers() != Qt::SHIFT) {
            pointObject->deselectAllPoints();
        }
        if (p && !p->isSelected()) {
            pointObject->selectPoint(p);
        }
        if (p && p->isSelected() && !_justSelectedOrRemoved) {
            pointObject->deselectPoint(p);
        }
        _justSelectedOrRemoved = false;
    } else if (interaction().type() == Interaction::Move) {
        for (Point* point : pointObject->selection()) {
            point->move(interaction(o).point());
        }
        if (!pointObject->selection().isEmpty()) {
            pointObject->emitChanged();
            _justSelectedOrRemoved = true;
        }
    }
}
Пример #12
0
float Hp::calculate(vector<Atom*> atoms,
		    string assigned_parameters)
{

  /*** set vdw radii ***/
  if (assigned_parameters=="")
    {
      printf("No parameters have been set for atoms, using GP vdw distances\n");
      Generalparameters GP(rep);
      GP.set_vdw_radii(atoms);
    }

  float res = 0;
  float temp_result;

  Distances dist(rep);
  
  /*** find hydrophobic protein atoms ***/
  find_hydrophobic_atoms(atoms);
  
  for(unsigned int p=0; p<atoms.size(); p++)
    if(atoms[p]->is_hydrophobic)
      for(unsigned int l=0; l<p; l++)
	if(atoms[l]->is_hydrophobic)
	  {
	    temp_result = interaction(dist.calculate(atoms[p],atoms[l],true), atoms[p]->vdw_dist + atoms[l]->vdw_dist);
	    res += temp_result;
	            
	    printf("Hydrophobic atoms %s-%d and %s-%d at distance %f has interaction %f\n",
		   atoms[p]->element.c_str(),
		   p+1,
		   atoms[l]->element.c_str(),
		   l+1,
		   dist.calculate(atoms[p],atoms[l],true),
		   temp_result);
	  }
  

   
  return res;
}
Пример #13
0
int lutil_sasl_interact(
	LDAP *ld,
	unsigned flags,
	void *defaults,
	void *in )
{
	sasl_interact_t *interact = in;

	if( ld == NULL ) return LDAP_PARAM_ERROR;

	if( flags == LDAP_SASL_INTERACTIVE ) {
		fputs( _("SASL Interaction\n"), stderr );
	}

	while( interact->id != SASL_CB_LIST_END ) {
		int rc = interaction( flags, interact, defaults );

		if( rc )  return rc;
		interact++;
	}
	
	return LDAP_SUCCESS;
}
Пример #14
0
/**
  * Builds the full MomHamiltonian matrix
  */
void MomHamiltonian::BuildFullHam()
{
    if( !baseUp.size() || !baseDown.size() )
    {
        std::cerr << "Build base before building MomHamiltonian" << std::endl;
        return;
    }

    blockmat.resize(L);

    for(int B=0; B<L; B++)
    {
        int cur_dim = mombase[B].size();

        blockmat[B].reset(new double [cur_dim*cur_dim]);

        for(int i=0; i<cur_dim; i++)
        {
            int a = mombase[B][i].first;
            int b = mombase[B][i].second;

            for(int j=i; j<cur_dim; j++)
            {
                int c = mombase[B][j].first;
                int d = mombase[B][j].second;

                blockmat[B][j+cur_dim*i] = U/L*interaction(a,b,c,d);

                blockmat[B][i+cur_dim*j] = blockmat[B][j+cur_dim*i];

            }

            blockmat[B][i+cur_dim*i] += J * (hopping(baseUp[a]) + hopping(baseDown[b]));
        }
    }
}
Пример #15
0
void * jouer_radio_VS(void * rdy_p)
{
  extern sem_t * mutex_play_a;
  extern char coup_jouer[13];
  char *coup;
  struct coup * pere;
  char joueur;
  int i;
  /* close(pipeDes[0]); */
  pion ** grille;
  initMap();
  joueur = 'A';
  grille = initGrille();
  coup = malloc(sizeof(char) * 13);
  for (i = 0; i < 13; i++)
  {
    coup[i] = 0;
  }

  int mode = 2;
  int difficulter = 1;
  int type = 0;
  updateMap(grille);
  sem_post(mutex_play_a);

  while (!victoire)
  {
    ready_to_play = 0;
    if (joueur == 'A')
    {
      /* updateMap(grille); */
      //affiche()
      pere = malloc(sizeof(struct coup));
      pere->proto = NULL;
      pere->coupSuivant = NULL;
      pere = coupsPossibles(grille, 'A', pere);
      /* write(pipeDes_read[1],"ready",strlen("ready")); */
      printf("UNLOCK1\n");
      fflush(stdout);
      sem_post(mutex_play_a);
      interaction(coup, grille, &joueur, mode, pere);
      if (action(grille, coup, pere, 1) == -1)
        jouerCoupIA(grille, 'A', difficulter, 0, 0, type, coup);
      copy_str(coup_jouer, coup);
      printf("UNLOCK2\n");
      fflush(stdout);
      sem_post(mutex_play_a);
      freeCoup(pere, 1);
      joueur = 'B';
    }
    if (joueur == 'B')
    {
      updateMap(grille);
      //affiche();

      if (!victoire)
      {
        //affiche()
        pere = malloc(sizeof(struct coup));
        pere->proto = NULL;
        pere->coupSuivant = NULL;
        pere = coupsPossibles(grille, 'B', pere);
        /* write(pipeDes_read[1],"ready",strlen("ready")); */
        printf("UNLOCK3\n");
        fflush(stdout);

        sem_post(mutex_play_a);
        interaction(coup, grille, &joueur, mode, pere);
        if (action(grille, coup, pere, 1) == -1)
          jouerCoupIA(grille, 'B', difficulter, 0, 0, type, coup);
        copy_str(coup_jouer, coup);
        printf("UNLOCK4\n");
        fflush(stdout);

        sem_post(mutex_play_a);
        freeCoup(pere, 1);
        joueur = 'A';

      }
    }
  }
  freeMap();
  free(grille);
  free(coup);
  return NULL;
}
Пример #16
0
void * jouer_radio_IA(void * rdy_p)
{
  char *coup;
  void ** rdy = (void **)rdy_p;
  int * desc_pipe_write = (int *)rdy[0];
  int * desc_pipe_read = (int *)rdy[1];
  struct coup * pere;
  char joueur;
  int i;
  int pipeDes_write[2];
  pipe(pipeDes_write);
  int pipeDes_read[2];
  pipe(pipeDes_read);  /* close(pipeDes[0]); */
  pion ** grille;
  initMap();
  joueur = 'A';
  grille = initGrille();
  coup = malloc(sizeof(char) * 13);
  for (i = 0; i < 13; i++)
  {
    coup[i] = 0;
  }

  int mode = 2;
  int difficulter = 1;
  int type = 0;
  * desc_pipe_write = pipeDes_write[1];
  * desc_pipe_read = pipeDes_read[0];
  free(rdy_p);
  updateMap(grille);


  while (!victoire)
  {
    ready_to_play = 0;
    if (joueur == 'A')
    {
      /* updateMap(grille); */
      //affiche();
      pere = malloc(sizeof(struct coup));
      pere->proto = NULL;
      pere->coupSuivant = NULL;
      pere = coupsPossibles(grille, 'A', pere);
      /* updateMap(grille); */
      do
      {
        write(pipeDes_read[1], "ready", strlen("ready"));
        interaction(coup, grille, &joueur, mode, pere);
        if (action(grille, coup, pere, 1) != -1)break;
        /* updateMap(grille); */
        write(pipeDes_read[1], "bad_coup_in", strlen("bad_coup_in_"));
      }
      while (42);
      freeCoup(pere, 1);
      joueur = 'B';
    }
    if (joueur == 'B')
    {
      /* updateMap(grille); */
      //affiche();

      if (!victoire)
      {
        jouerCoupIA(grille, 'B', difficulter, 0, 0, type, coup);
        joueur = 'A';
        updateMap(grille);
        write(pipeDes_read[1], coup, strlen(coup));
      }
    }
  }
  freeMap();
  free(grille);
  free(coup);
  close(pipeDes_write[1]);
  close(pipeDes_write[0]);
  close(pipeDes_read[1]);
  close(pipeDes_read[0]);
  return NULL;
}
Пример #17
0
void loop() {

  recieve_commands();
  
  if (!docking && !auto_cover) {
    execute_move();
    interaction();
  }
  
  if (move_time == 0) {

    if (stream)   // @t
      stream_data();

    if (exp_auto) // @a
      feb_experiment_scanning();//katie_auto();

    if (auto_on )   // @u
      katie_auto();

    // if (auto_cover){ /// send state message at a regular interval during script
    //   int diff = millis() - picture_timer;
    //   if (diff > 3000) {
    //     send_state("picture timer");
    //     picture_timer = millis();
    //   }
    // }

    if (exp_stream )  // @e
      // arduino_hub_stream(); // experiment_dec_2013

    if (debug_stream )   // @g
      stream_debug_sensors();
  }

  BUTTONS_STATE = COIFetchSingleSensor(BUTTONS);
  if (PLAY_BUTTON(BUTTONS_STATE) == HIGH) {
      delay(200);
      COIChangeMode(CMD_MODE_PASSIVE);
      play_toggle = true;
      send_response("SAFE MODE ON", 1);
    }

  if ((CHARGING_SOURCE_STATE == 1  || CHARGING_SOURCE_STATE == 2) && play_toggle == true ) {
    charge_toggle = true;
    play_toggle = false;
    send_response("CHARGING SOURCE DETECTED", 1);
  }

  if ((CHARGING_SOURCE_STATE == 0) && (OI_MODE_STATE == OI_PASSIVE) && (charge_toggle == true) && (play_toggle == false)){
    COIChangeMode(CMD_MODE_FULL);
    charge_toggle = false;
    send_response("FULL MODE ON", 1);
  }

  update_battery_sensors();
  charger();

  if (!digitalRead(INPUT_20) && !auto_cover ) { // check to see if not in script so command does not interfere
    //update_create_fast_sensors(); // so that collision detection works
    BUMPS_WHEEL_DROPS_STATE         = COIFetchSingleSensor(BUMPS_WHEELS);
    //charger();  // detects charger (once this works move make nest it deeper in framework)
  }

   if ((BUMPS_WHEEL_DROPS_STATE > 0 && BUMPS_WHEEL_DROPS_STATE < 4) && bp == false) {
          bp = true;
          send_state("collision detected");
        }
   if ((BUMPS_WHEEL_DROPS_STATE == 0) && bp == true) {
          bp = false;
          send_state("bumper released");
        }

  //heading = update_header(heading, COIFetchSingleSensor(ANGLE_SINCE_LAST); // Mostly for testing, for now
  delay(20); // serial gets overrun if no delay

}
/*
phase 3

*/
int phase3(){
	
	int numSwitching = 0;
	int minIncrease = 0;
	int* roadMap = (int*)malloc(sizeof(int)*numVcore);

	ExecutionSlice* currSlice;
	ExecutionSlice* candSlice;

	ExecutionSlice* planTail = &exePlan;

	for(int i = 0;i<numVcore;i++){
		roadMap[i] = -1;
	}
	
	while(eSlice.next != NULL){
		// find the execution slice with the least marginal number of swtiching
		candSlice = eSlice.next;
		minIncrease = computeInc(candSlice, roadMap);
		currSlice = candSlice->next;
		
		while(currSlice != NULL){
			// compute increase 
			int numIncrease = computeInc(currSlice, roadMap); 
			if(numIncrease < minIncrease){
				candSlice = currSlice;
			}
			else if(numIncrease == minIncrease){
				if(interaction(candSlice) > interaction(currSlice)){
					candSlice = currSlice;
				}
			}
			currSlice = currSlice->next;
		};

		// update current status
		int vCore = 0;
		minIncrease += numSwitching;
		for(int i = 0; i<numPcore; i++){
			vCore = candSlice->mapping[i];
			if(vCore != -1){
				if((roadMap[vCore] != -1) && (roadMap[vCore] != i)){
					numSwitching++;
				}
				roadMap[vCore] = i;
			}
		}
		if(minIncrease != numSwitching){
			// something wrong
			fprintf(stderr, "Switching time anomaly\n");
		}

		// remove from queue
		candSlice->prev->next = candSlice->next;
		if(candSlice->next != NULL){
			candSlice->next->prev = candSlice->prev;
		}
		// insert candSlice into plan
		planTail->next = candSlice;
		candSlice->prev = planTail;
		candSlice->next = NULL;
		planTail = planTail->next;		
	};

	//outputSlices(&exePlan);

	free(roadMap);

	return numSwitching;
}
Пример #19
0
double *integration_eam_p(double *y, void *params, unsigned int S, int *stab, Params *p)
{

    char *buffer = (char*)malloc(100);
    sprintf(buffer, "%s/cycle%d.txt",p->folder,p->cycle_num);
    FILE *outname = fopen(buffer,"w");
    fprintf(outname,"\n%d\t",0);
    print_double_array(y,S,outname);
  

    // DEFINE AND INITIALIZE THE VARIABLES
    //------------------------------------
    int theend = 0;
    int theend2 = 0;
    double *biomass = (double*)malloc(S * sizeof(double));   // array for the temporal mean biomasses calculation
    double *minis = (double*)malloc(S * sizeof(double));     // array for the minimum densities
    double *maxis = (double*)malloc(S * sizeof(double));     // array for the maximum densities
    double *check1 = (double*)malloc(S * sizeof(double));    // array for the minimum densities
    double *check2 = (double*)malloc(S * sizeof(double));    // array for the maximum densities

    for(int i = 0 ; i < S ; ++i)
    {
	biomass[i] = 0.0;
    }
    memcpy(minis,biomass,S * sizeof(double));
    memcpy(maxis,biomass,S * sizeof(double));
    memcpy(check1,biomass,S * sizeof(double));
    memcpy(check2,biomass,S * sizeof(double));


    // PRINT THE INITIAL DENSITIES
    //----------------------------
    //display_densities(y,S,0);    

    // CALCULATION OF INTERACTIONS AND PREFERENCES
    //--------------------------------------------
    interaction((isll*)params,p);

    // DEFINE THE INTEGRATION SYSTEM WITH THE FUNCTION FOO_EAM
    //--------------------------------------------------------
    gsl_odeiv2_system sys = {foo_eam, NULL,S, params};
    //gsl_odeiv2_system sys = {foo_eam, jac_eam,S, params};

        // DEFINE THE SOLVER
    //------------------
    //gsl_odeiv2_driver *d = gsl_odeiv2_driver_alloc_y_new(&sys, gsl_odeiv2_step_rk8pd, 1e-15, 1e-15,1e-20);
    gsl_odeiv2_driver *d = gsl_odeiv2_driver_alloc_y_new(&sys, gsl_odeiv2_step_rkck, 1e-12, 1e-12,0);         // the faster
    //gsl_odeiv2_driver *d = gsl_odeiv2_driver_alloc_y_new(&sys, gsl_odeiv2_step_rkf45, 1e-15, 1e-15,1e-20);    

    // STARTING TIME
    //--------------
    double t = 0.0;
    int a = EAM_TMAX - EAM_B;
    int b = EAM_B * 3;


    //-------------//
    // INTEGRATION //
    //------------ //

    // MODE WITH CHECKING TIME
    //------------------------
    if(EAM_EQ_MOD)  
    {
        // RUN UNTIL CHECKING TIME
        //------------------------
      runi_p(d,&t,y,1,(EAM_TE_START) ,S,outname);

        int run_cycles = (int)((a - EAM_TE_START) / b);                                                       // number of checking times
	int left_time = EAM_TMAX - (run_cycles * b);                                                          // time left to reach EAM_TMAX if not stopped before
	int index = EAM_TE_START + 1;
	for(int i = 0 ; i < run_cycles ; ++i)
	{
	    theend = index + EAM_B - 1;
	    runb_p(d,&t,y,check1,index, theend,S,outname);
	    theend2 = theend  + EAM_B;
	    runb_p(d,&t,y,check2,(theend + 1), theend2,S,outname);                                      

	    // IF STABILITY IS REACHED, STOP THE INTEGRATION 
	    //----------------------------------------------
	    if(compare_dd(check1,check2,S) == 1)
	    {
		p->time_eq = index + b - 1;
	        runb_plus_stab_p(d,&t,y,biomass,minis,maxis,(theend2 + 1),p->time_eq,S,stab,outname);

                // FREE THE MEMORY
                //----------------
		free(minis);
		free(maxis);
		free(check1);
		free(check2);
		gsl_odeiv2_driver_free(d);
		fclose(outname);
		free(buffer);
		return(biomass);
	    }
	    else
	      {
		runi_p(d,&t,y,(theend2 + 1),(index + b - 1),S,outname);
	      }
	    index += b;
	}

	// IF STABILITY IS NOT REACHED, FINISH THE INTEGRATION AND CALCULATE THE TEMPORAL BIOMASS
	//---------------------------------------------------------------------------------------
        if(left_time != 0)runi_p(d,&t,y,index,(a-1) ,S,outname);
	runb_p(d,&t,y,biomass,a,EAM_TMAX,S,outname);
	*stab = 0;
	p->time_eq =  EAM_TMAX;     
    }
    else  

    // MODE WITHOUT CHECKING TIME
    //---------------------------           
    {
        int index = EAM_TMAX - b;
        runi_p(d,&t,y,1,index,S,outname);
	theend = index + EAM_B;
	runb_p(d,&t,y,check1,(index + 1), theend,S,outname);
	theend2 = theend  + EAM_B;
	runb_p(d,&t,y,check2,(theend + 1), theend2,S,outname); 
	if(compare_dd(check1,check2,S) == 1)
	{
	    runb_plus_stab_p(d,&t,y,biomass,minis,maxis,(theend2 + 1),EAM_TMAX,S,stab,outname);
	}
	else
	{
	    runb_p(d,&t,y,biomass,(theend2 + 1),EAM_TMAX,S,outname);
	    *stab = 0;
	}
	p->time_eq =  EAM_TMAX;
    }
        // FREE THE MEMORY
        //----------------
        free(minis);
        free(maxis);
        free(check1);
        free(check2);
        gsl_odeiv2_driver_free(d);
	fclose(outname);
	free(buffer);
        return (biomass);

}
Пример #20
0
/**
 * This methods calculates the eigenvalues for a range of U values. The interval is [Ubegin, Uend]
 * with a stepsize of step. The resulting data is written to a file in the HDF5 file format.
 * @param Ubegin the startpoint for U
 * @param Uend the endpoint for U. We demand Ubegin < Uend
 * @param step the stepsize to use for U
 * @param filename the name of the file write to written the eigenvalues to
 */
void MomHamiltonian::GenerateData(double Ubegin, double Uend, double step, std::string filename)
{
    double Ucur = Ubegin;

    if( !baseUp.size() || !baseDown.size() )
        BuildBase();

    std::vector<double> eigenvalues(dim);

    hid_t       file_id, group_id, dataset_id, dataspace_id, attribute_id;
    herr_t      status;

    file_id = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    HDF5_STATUS_CHECK(file_id);

    group_id = H5Gcreate(file_id, "run", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    HDF5_STATUS_CHECK(group_id);

    dataspace_id = H5Screate(H5S_SCALAR);

    attribute_id = H5Acreate (group_id, "L", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_INT, &L );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "Nu", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_INT, &Nu );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "Nd", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_INT, &Nd );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "J", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &J );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "Ubegin", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &Ubegin );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "Uend", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &Uend );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    attribute_id = H5Acreate (group_id, "Ustep", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &step );
    HDF5_STATUS_CHECK(status);
    status = H5Aclose(attribute_id);
    HDF5_STATUS_CHECK(status);

    status = H5Sclose(dataspace_id);
    HDF5_STATUS_CHECK(status);

    status = H5Gclose(group_id);
    HDF5_STATUS_CHECK(status);

    status = H5Fclose(file_id);
    HDF5_STATUS_CHECK(status);

    std::vector<double> diagonalelements(dim);

    std::vector< std::unique_ptr<double []> > offdiag;
    offdiag.resize(L);

    // make sure that we don't rebuild the whole hamiltonian every time.
    // store the hopping and interaction part seperate so we can just
    // add them in every step
    #pragma omp parallel for
    for(int B=0; B<L; B++)
    {
        int cur_dim = mombase[B].size();
        int offset = 0;

        for(int tmp=0; tmp<B; tmp++)
            offset += mombase[tmp].size();

        offdiag[B].reset(new double [cur_dim*cur_dim]);

        for(int i=0; i<cur_dim; i++)
        {
            int a = mombase[B][i].first;
            int b = mombase[B][i].second;

            diagonalelements[offset+i] = hopping(baseUp[a]) + hopping(baseDown[b]);

            for(int j=i; j<cur_dim; j++)
            {
                int c = mombase[B][j].first;
                int d = mombase[B][j].second;

                offdiag[B][j+cur_dim*i] = 1.0/L*interaction(a,b,c,d);
                offdiag[B][i+cur_dim*j] = offdiag[B][j+cur_dim*i];
            }
        }
    }


    while(Ucur <= Uend)
    {
        std::cout << "U = " << Ucur << std::endl;
        setU(Ucur);

        // make hamiltonian
        #pragma omp parallel for
        for(int B=0; B<L; B++)
        {
            int cur_dim = mombase[B].size();
            int offset = 0;

            for(int tmp=0; tmp<B; tmp++)
                offset += mombase[tmp].size();

            std::memcpy(blockmat[B].get(),offdiag[B].get(),cur_dim*cur_dim*sizeof(double));

            int tmp = cur_dim*cur_dim;
            int inc = 1;
            dscal_(&tmp,&Ucur,blockmat[B].get(),&inc);

            for(int i=0; i<cur_dim; i++)
                blockmat[B][i+cur_dim*i] += diagonalelements[offset+i];
        }


        #pragma omp parallel for
        for(int B=0; B<L; B++)
        {
            int dim = mombase[B].size();
            int offset = 0;

            for(int tmp=0; tmp<B; tmp++)
                offset += mombase[tmp].size();

            Diagonalize(dim, blockmat[B].get(), &eigenvalues[offset], false);
        }

        hid_t U_id;
        std::stringstream name;
        name << std::setprecision(5) << std::fixed << "/run/" << Ucur;

        file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
        HDF5_STATUS_CHECK(file_id);

        U_id = H5Gcreate(file_id, name.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        HDF5_STATUS_CHECK(U_id);

        for(int B=0; B<L; B++)
        {
            int dim = mombase[B].size();
            int offset = 0;

            for(int tmp=0; tmp<B; tmp++)
                offset += mombase[tmp].size();

            hsize_t dimarr = dim;

            dataspace_id = H5Screate_simple(1, &dimarr, NULL);

            std::stringstream cur_block;
            cur_block << B;
            dataset_id = H5Dcreate(U_id, cur_block.str().c_str(), H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

            status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &eigenvalues[offset] );
            HDF5_STATUS_CHECK(status);

            status = H5Sclose(dataspace_id);
            HDF5_STATUS_CHECK(status);

            status = H5Dclose(dataset_id);
            HDF5_STATUS_CHECK(status);
        }

        status = H5Gclose(U_id);
        HDF5_STATUS_CHECK(status);

        status = H5Fclose(file_id);
        HDF5_STATUS_CHECK(status);

        Ucur += step;
    }
}
Пример #21
0
float Hp::calculate(vector<Atom*> protein_atoms, 
		    vector<Atom*> ligand_atoms,
		    vector<vector<float> > distances, 
		    string assigned_parametersA,
		    string assigned_parametersB)
{

//   if(include_surf_factor == 1)
//     {
//       Topology top(rep);
//       top.generate_topology(protein_atoms, ligand_atoms);
//       ligand_surf_dists = top.get_ligand_surface_distances();
//       protein_surf_dists = top.get_protein_surface_distances();
//     }


  /*** set vdw radii ***/
  if (assigned_parametersA=="")
    {
      printf("No parameters have been set for protein atoms, using GP vdw distances\n");
      Generalparameters GP(rep);
      GP.set_vdw_radii(protein_atoms);
    }
  if(assigned_parametersB=="")
    {
      printf("No parameters have been set for ligand atoms, using GP vdw distances\n");
      Generalparameters GP(rep);
      GP.set_vdw_radii(ligand_atoms);
    }

  float res = 0;
  float temp_result;

  /*** find hydrophobic protein atoms ***/
  find_hydrophobic_atoms(protein_atoms);
  find_hydrophobic_atoms(ligand_atoms);
  
  for(unsigned int p=0; p<protein_atoms.size(); p++)
    if(protein_atoms[p]->is_hydrophobic)
      for(unsigned int l=0; l<ligand_atoms.size(); l++)
	if(ligand_atoms[l]->is_hydrophobic)
	  {
	    temp_result = interaction(sqrt(distances[p][l]), protein_atoms[p]->vdw_dist + ligand_atoms[l]->vdw_dist);
	    if(include_surf_factor == 1)
	      temp_result = temp_result*(protein_atoms[p]->desolvation_factor + ligand_atoms[l]->desolvation_factor)/2; //using average desolvation_factor factor of the two atoms
	    
	    res += temp_result;

	   
// 	    printf("Hydrophobic protein atom %s-%d and Ligand atom %s-%d at distance %f has interaction %f\n",
// 		   protein_atoms[p]->element.c_str(),
// 		   p+1,
// 		   ligand_atoms[l]->element.c_str(),
// 		   l+1,
// 		   sqrt(distances[p][l]),
//		   interaction(sqrt(distances[p][l]), protein_atoms[p]->vdw_dist + ligand_atoms[l]->vdw_dist));
	   }
  


//    printf("Testing interaction:\n");
//    float d =0.0;
//    float r1 = 1.70;
//    float r2 = 1.20;
//    while(d<10)
//      {
//        printf("At %3f interaction is %f\n",d,interaction(d, r1+r2));
//        d =d +0.1;
//      }
    
  return res;
}