Beispiel #1
0
void App::save_config(){
    log("Zapisywanie ustawieñ...");
    //wczytanie starego pliku
    vector<string> *lines = get_all_lines("config.txt");
    if(lines==NULL){ //jeœli nie by³o pliku
        lines = new vector<string>;
    }
    //aktualizacja danych
    update_config(lines, "instrument=", config->midi_instrument);
    update_config(lines, "volume=", config->midi_volume);
    update_config(lines, "basetone=", config->midi_basetone);
    update_config(lines, "pause=", config->midi_pause);
    update_config(lines, "interval_type=", config->ustawienia_type);
    //ci¹g w³¹czonych interwa³ów
    string interwaly = "";
    for(int i=0; i<12; i++){
        if(config->ustawienia_interwaly[i]){
            interwaly += "1";
        }else{
            interwaly += "0";
        }
    }
    update_config(lines, "interwaly=", interwaly);
    //ci¹g w³¹czonych oktaw
    string oktawy = "";
    for(int i=0; i<7; i++){
        if(config->ustawienia_oktawy[i]){
            oktawy += "1";
        }else{
            oktawy += "0";
        }
    }
    update_config(lines, "oktawy=", oktawy);
    //zapisanie do pliku
    fstream plik;
    plik.open("config.txt",fstream::out|fstream::trunc|fstream::binary);
    if(!plik.good()){
        plik.close();
        return;
    }
    for(unsigned int i=0; i<lines->size(); i++){
        if(i<lines->size()-1 || lines->at(i).length()>0){
            plik<<lines->at(i)<<endl;
        }
    }
    plik.close();
    lines->clear();
    delete lines;
}
Beispiel #2
0
int ext_apbs(int isize, gmx_bool bVerbose, char *fnApbsOut, char *fnPolAPBS, double *PolarEnergy, double *APolarEnergy, double *AtomEnergy)	{
	char *apbs_cmd = NULL;
	const char *apbs_env = NULL;
	FILE *fApbsOut;
	char **data=NULL;
	bool bID_A=FALSE, bID_B =FALSE, bWCA_end=FALSE;
	int nlines, i;
	int mol1_start = 0, mol2_start = 0;
	int mol1_lastID = 0, mol2_lastID = 0;

	double totEnergy1, totEnergy2;
	double *atEnergy1=NULL, *atEnergy2=NULL;
	int at_count = 0;

	/* Getting path from $APBS environment */
	apbs_env = getenv("APBS");
	snew(apbs_cmd, strlen(apbs_env)+64);

	/* Constructing APBS command for polar solvation energy*/
	if (PolarEnergy != NULL)
		sprintf(apbs_cmd, "$APBS %s --output-file=%s %s", fnPolAPBS, fnApbsOut, bVerbose?"":" >/dev/null 2>&1");

	/* Constructing APBS command for WCA energy*/
	if (APolarEnergy != NULL)	{
		if (have_mpirun(apbs_env))
			gmx_fatal(FARGS,"Do not use MPI for WCA...");
		sprintf(apbs_cmd, "$APBS %s > %s", fnPolAPBS, fnApbsOut);
	}

	/* Executing APBS command */
	if(0 != system(apbs_cmd))
		  gmx_fatal(FARGS,"Failed to execute command: %s", apbs_cmd);

	/* Reading APBS output file */
	fApbsOut = fopen(fnApbsOut, "r");
	data = get_all_lines(fApbsOut, &nlines);
	fclose(fApbsOut);

	/* Memory allocation for atom energy */
	if (AtomEnergy != NULL)	{
		snew(atEnergy1, 1);
		snew(atEnergy2, 1);
		at_count = 1;
	}

	if (PolarEnergy != NULL)	{

		/* Identifying indices (line number) of mol1 and mol2 */
		for(i=0; i<nlines; i++)	{
			if (strstr(data[i],"elec name mol1") !=NULL)	{
				mol1_start = i;
			}
			if (strstr(data[i],"elec name mol2") !=NULL)	{
				mol2_start = i;
			}
		}

		/* Identifying last energy calculation index */
		for(i=0; i<nlines; i++)	{
			if ( (strstr(data[i],"id") !=NULL) && (i < mol2_start) )	{
				mol1_lastID = i;
			}
			if (strstr(data[i],"id") !=NULL)	{
				mol2_lastID = i;
			}
		}

		/* Extracting energy values */
		for(i=0; i<nlines; i++)	{

			if ((strstr(data[i],"id")!=NULL) && (i == mol1_lastID) )
				bID_A = TRUE;

			if( (strstr(data[i],"id")!=NULL) && (i == mol2_lastID) )
				bID_B = TRUE;

			if ( (strstr(data[i],"end")!=NULL) && (bID_A == TRUE) )	{
				bID_A =FALSE;
				if ((AtomEnergy != NULL) && (at_count-1 != isize) )	{
					gmx_fatal(FARGS,"Number of atoms in selected index (%d) does not match with number of atoms (%d) in APBS output. \n", isize, at_count);
				}
				at_count = 1;
			}

			if ( (strstr(data[i],"end")!=NULL) && (bID_B == TRUE) )	{
				bID_B =FALSE;
				if ((AtomEnergy != NULL) && (at_count-1 != isize) )	{
					gmx_fatal(FARGS,"Number of atoms in selected index (%d) does not match with number of atoms (%d) in APBS output. \n", isize, at_count);
				}
				at_count = 1;
				break;
			}

			if ( (strstr(data[i], "totEnergy") != NULL) && (bID_A == TRUE) )	{
				totEnergy1 = get_totEnergy(data[i]);
			}

			if ( (strstr(data[i], "totEnergy") != NULL) && (bID_B == TRUE) )	{
				totEnergy2 = get_totEnergy(data[i]);
			}

			if ((AtomEnergy != NULL) && (strstr(data[i], "atom") != NULL) && (bID_A == TRUE)) {
				if (at_count > 1)
					srenew(atEnergy1, at_count);
				atEnergy1[at_count-1] = get_AtomEnergy(data[i]);
				at_count += 1;
			}

			if ((AtomEnergy != NULL) && (strstr(data[i], "atom") != NULL) && (bID_B == TRUE)) {
				if (at_count > 1)
					srenew(atEnergy2, at_count);
				atEnergy2[at_count-1] = get_AtomEnergy(data[i]);
				at_count += 1;
			}
		}

		*PolarEnergy = totEnergy1 - totEnergy2;

		if (AtomEnergy != NULL)
			for(i=0; i<isize; i++)	{
				AtomEnergy[i] = atEnergy1[i] - atEnergy2[i];
			}
	}

	if (APolarEnergy != NULL)	{

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

			if (strstr(data[i], "Total WCA energy") != NULL)	{
				*APolarEnergy = get_WCAEnergy(data[i]);
				bWCA_end = TRUE;
			}

			if (bWCA_end)	{
				if ((AtomEnergy != NULL) && (at_count-1 != isize) )	{
					gmx_fatal(FARGS,"Number of atoms in selected index (%d) does not match with number of atoms (%d) in APBS output. \n", isize, at_count);
				}
				at_count = 1;
				break;
			}

			if (strstr(data[i], "WCA energy for atom") != NULL)	{
				if (at_count > 1)
					srenew(atEnergy1, at_count);
				atEnergy1[at_count-1] = get_AtomWCAEnergy(data[i]);
				at_count += 1;
			}
		}

		if (AtomEnergy != NULL)
			for(i=0; i<isize; i++)	{
				AtomEnergy[i] = atEnergy1[i];
			}
	}

	/* memory cleanup */
	for(i=0;i<nlines;i++)
		free(data[i]);
	free(data);
	sfree(apbs_cmd);
	if (AtomEnergy != NULL)	{
		sfree(atEnergy1);
		sfree(atEnergy2);
	}

	return 0;
}
Beispiel #3
0
void App::load_config(){
	log("Wczytywanie ustawieñ...");
    //domyœlne wartoœci
    config->midi_instrument = 25;
    config->midi_volume = 100;
    config->midi_basetone = 60;
    config->midi_pause = 500;
    config->ustawienia_type = TYP_INTERWAL_RM;
    for(int i=0; i<12; i++)
        config->ustawienia_interwaly[i]=false;
    config->ustawienia_interwaly[0] = true;
    config->ustawienia_interwaly[1] = true;
    config->ustawienia_interwaly[2] = true;
    for(int i=0; i<7; i++)
        config->ustawienia_oktawy[i]=false;
    config->ustawienia_oktawy[2] = true;
    config->ustawienia_oktawy[3] = true;
    //wczytanie pliku
    vector<string> *lines = get_all_lines("config.txt");
    if(lines==NULL){
        echo("B³¹d: Brak pliku konfiguracyjnego");
        return;
    }
    int next2 = 0;
    if(next_element("instrument=",lines,next2)){
        config->midi_instrument = atoi(lines->at(next2).c_str());
    }
    if(next_element("volume=",lines,next2)){
        config->midi_volume = atoi(lines->at(next2).c_str());
    }
    if(next_element("basetone=",lines,next2)){
        config->midi_basetone = atoi(lines->at(next2).c_str());
    }
    if(next_element("pause=",lines,next2)){
        config->midi_pause = atoi(lines->at(next2).c_str());
    }
    if(next_element("interval_type=",lines,next2)){
        config->ustawienia_type = atoi(lines->at(next2).c_str());
        if(config->ustawienia_type<0) config->ustawienia_type = 0;
        if(config->ustawienia_type>6) config->ustawienia_type = 6;
    }
    if(next_element("interwaly=",lines,next2)){
        string interwaly = lines->at(next2);
        if(interwaly.length()>=12){
            for(int i=0; i<12; i++){
                if(interwaly[i]=='1'){
                    config->ustawienia_interwaly[i] = true;
                }else{
                    config->ustawienia_interwaly[i] = false;
                }
            }
        }
    }
    if(next_element("oktawy=",lines,next2)){
        string oktawy = lines->at(next2);
        if(oktawy.length()>=7){
            for(int i=0; i<7; i++){
                if(oktawy[i]=='1'){
                    config->ustawienia_oktawy[i] = true;
                }else{
                    config->ustawienia_oktawy[i] = false;
                }
            }
        }
    }
    lines->clear();
    delete lines;
}