示例#1
0
文件: tools.cpp 项目: Open-IOT/EEMD
//----------------------------------------------------------------------
float Tools::getRand() {
if(VERBOSE) printf("\nfloat Tools::getRand()\n");
    seedRandom();
	float f = (float)rand();

    return f;
}
示例#2
0
// Called from the app framework.
void appInit()
{
    int a;

    glEnable(GL_NORMALIZE);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glShadeModel(GL_FLAT);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT2);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    seedRandom(15);

    for (a = 0; a < SUPERSHAPE_COUNT; ++a)
    {
        sSuperShapeObjects[a] = createSuperShape(sSuperShapeParams[a]);
        assert(sSuperShapeObjects[a] != NULL);
    }
    sGroundPlane = createGroundPlane();
    assert(sGroundPlane != NULL);
}
示例#3
0
文件: demo.c 项目: 1974kpkpkp/WebGL
static void drawModels(float zScale)
{
    const int translationScale = 9;
    int x, y;

    seedRandom(9);

    //glScalex(1 << 16, 1 << 16, (GLfixed)(zScale * 65536));

    for (y = -5; y <= 5; ++y)
    {
        for (x = -5; x <= 5; ++x)
        {
            float buildingScale;
            GLfixed fixedScale;

            int curShape = randomUInt() % SUPERSHAPE_COUNT;
            buildingScale = sSuperShapeParams[curShape][SUPERSHAPE_PARAMS - 1];
            fixedScale = (GLfixed)(buildingScale * 65536);

#if 0
            glPushMatrix();
            glTranslatex((x * translationScale) * 65536,
                         (y * translationScale) * 65536,
                         0);
            glRotatex((GLfixed)((randomUInt() % 360) << 16), 0, 0, 1 << 16);
            glScalex(fixedScale, fixedScale, fixedScale);

            drawGLObject(sSuperShapeObjects[curShape]);
            glPopMatrix();
#endif
        }
    }

    for (x = -2; x <= 2; ++x)
    {
        const int shipScale100 = translationScale * 500;
        const int offs100 = x * shipScale100 + (sTick % shipScale100);
        float offs = offs100 * 0.01f;
        GLfixed fixedOffs = (GLfixed)(offs * 65536);
#if 0
        glPushMatrix();
        glTranslatex(fixedOffs, -4 * 65536, 2 << 16);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
        glPushMatrix();
        glTranslatex(-4 * 65536, fixedOffs, 4 << 16);
        glRotatex(90 << 16, 0, 0, 1 << 16);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
#endif
    }
}
示例#4
0
文件: demo.c 项目: 1974kpkpkp/WebGL
static void drawModels(float zScale)
{
    const int translationScale = 9;
    int x, y;

    seedRandom(9);

    glScalef(1.f, 1.f, zScale);

    for (y = -5; y <= 5; ++y)
    {
        for (x = -5; x <= 5; ++x)
        {
            float buildingScale;

            int curShape = randomUInt() % SUPERSHAPE_COUNT;
            buildingScale = sSuperShapeParams[curShape][SUPERSHAPE_PARAMS - 1];

            glPushMatrix();
            glTranslatef(x * translationScale, y * translationScale, 0);
            {
              int rv = randomUInt() % 360;
              // printf("rv=%d\n", rv);
              glRotatef(rv, 0.f, 0.f, 1.f);
            }
            // glRotatef(randomUInt() % 360, 0.f, 0.f, 1.f);
            glScalef(buildingScale, buildingScale, buildingScale);

            drawGLObject(sSuperShapeObjects[curShape]);
            glPopMatrix();
        }
    }

    for (x = -2; x <= 2; ++x)
    {
        const int shipScale100 = translationScale * 500;
        const int offs100 = x * shipScale100 + (sTick % shipScale100);
        float offs = offs100 * 0.01f;
        // GLfixed fixedOffs = (GLfixed)(offs * 65536);
        glPushMatrix();
        // glTranslatex(fixedOffs, -4 * 65536, 2 << 16);
        glTranslatef(offs, -4.f, 2.f);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
        glPushMatrix();
        // glTranslatex(-4 * 65536, fixedOffs, 4 << 16);
        glTranslatef(-4.f, offs, 4.f);
        // glRotatex(90 << 16, 0, 0, 1 << 16);
        glRotatef(90.f, 0.f, 0.f, 1.f);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
    }
}
示例#5
0
NString makePacket(std::string username, std::string password)
{
    MD5 md5;

    if (!md5IsSet)
    {
        md5_nostaleX = md5.digestFile((nostalePath + "\\NostaleX.dat").c_str());
        md5_nostale = md5.digestFile((nostalePath + "\\Nostale.dat").c_str());
        md5IsSet = true;
    }

    std::string md5_hash = md5_nostaleX + md5_nostale + username;

    NString packet("NoS0575 ");
    //packet.reserve(8 + username.length() + 1 + password.length() * 4 + 4 + 9 + 1 + 13 + 32 + 1); // Pre-allocate size
    packet << (uint32_t)(seedRandom(0x989680) + 0x86111);
    packet << ' ' << username << ' ' << encryptPass(password);
    packet << ' ' << fmt::pad(fmt::hexu(seedRandom(0x989680)), 8, '0');
    packet << (uint8_t)0x0B << "0.9.3.3055 0 " << md5.digestString(md5_hash) << (uint8_t)0x0A;

    return packet;
}
示例#6
0
文件: demo.c 项目: 1974kpkpkp/WebGL
// Called from the app framework.
void appInit()
{
    int a;

    seedRandom(15);

    for (a = 0; a < SUPERSHAPE_COUNT; ++a)
    {
        sSuperShapeObjects[a] = createSuperShape(sSuperShapeParams[a]);
        assert(sSuperShapeObjects[a] != NULL);
    }
    sGroundPlane = createGroundPlane();
    assert(sGroundPlane != NULL);
}
void genKey(){
	
	int p,q,i,j;
	long long n,tot,d,e;
	
	seedRandom();
	
	do{
		//value larger = slower, by ALOT, cause of multiplication
		p = prime(randomInt(KEYMIN,KEYMAX));
		q = prime(randomInt(KEYMIN,KEYMAX));
		printf("%lld\t%lld\n",p,q);
	}while(isPrime(p)!=0 && isPrime(q)!=0);
	
	printf("---------------\n");
	
	n = p*q;
	tot = (p-1)*(q-1);

	
	for(j=0; j <10; j++){
		i++;
		d = tot*i+1;
		e = d;
		
		int div=2;
		
		do{
			(e%div==0)? e /= div : div++;
			
		}while(isPrime(e)==1);
		
		if((e == d)) j--;
	}
	
	printf("\np: %lld\nq: %lld\nn: %lld\ntot: %lld\n",p,q,n,tot);
	
	Keys key;
	key.n = n;
	key.d=d/e;
	key.e=e;
	
	printf("\nn: %lld\nd: %lld\ne: %lld\n\n",key.n,key.d,key.e);

	writeKeys(key);
	Keys empty = {0};
	key = empty;
	menu();
	
}
示例#8
0
文件: tools.cpp 项目: Open-IOT/EEMD
//----------------------------------------------------------------------
VEC Tools::getRands(int n) {
if(VERBOSE) printf("\nVEC Tools::getRands(int n=%d)\n", n);
    VEC rands;
    rands.set_size(n);
    arma::Col<float>::iterator elem = rands.begin();
	float f;
    seedRandom();

	for (int i=0; i < n; i++) {
		f = (float)rand() / RAND_MAX;
		f = 2.0*f - 1.0;
		*elem = f;
        elem++;
	}

	return rands;
}
示例#9
0
int main(int argc, char ** argv)
{
	if (argc < 2)
	{
		printf("No.\n");
		return 1;
	}

	struct Roll * rolls = (struct Roll *) malloc(sizeof(struct Roll) * (argc - 1));
	for (int i = 1; i < argc; i++)
	{
		rolls[i - 1] = parseRoll(argv[i]);
	}

	seedRandom();

	int sum = 0;
	for (int i = 1; i < argc; i++)
	{
		int subtotal = 0;
		struct Roll roll = rolls[i - 1];
		int * results = (int *) malloc(sizeof(int) * roll.count);
		for (int count = 0 ; count < roll.count; count++)
		{
			int result = rand() % roll.size + 1;
			if (result <= roll.reroll)
			{
				count--;
				printf("Got %d; rerolling.\n", result);
			}
			else
			{
				results[count] = result;
				// printf("Got %d; continuing.\n", result);
			}
		}

		qsort(results, roll.count, sizeof(int), sortDescCmp);

		int keep = 0;
		for ( ; keep < roll.keep; keep++)
		{
			printf("%dd%d (%d): %d\n", roll.count, roll.size, keep, results[keep]);
			subtotal += results[keep];
		}
		for ( ; keep < roll.count; keep++)
		{
			printf("%dd%d (%d): %d (discarded)\n", roll.count, roll.size, keep, results[keep]);
		}

		if (roll.modifier != 0)
		{
			if (roll.modifier > 0)
			{
				printf("Subtotal: %d + %d = %d\n", subtotal, roll.modifier, subtotal + roll.modifier);
			}
			else
			{
				printf("Subtotal: %d - %d = %d\n", subtotal, -roll.modifier, subtotal + roll.modifier);
			}
			subtotal += roll.modifier;
		}
		else
		{
			printf("Subtotal: %d\n", subtotal);
		}
		sum += subtotal;
	}

	printf("Total %d\n", sum);

	return 0;
}
示例#10
0
int
main(int argc, char *argv[])
{
	GarbledCircuit gc;

    block *outputMap = allocate_blocks(2 * m);
    block *inputLabels = allocate_blocks(2 * n);
    block seed;

	int *timeGarble = calloc(times, sizeof(int));
	int *timeEval = calloc(times, sizeof(int));
	double *timeGarbleMedians = calloc(times, sizeof(double));
	double *timeEvalMedians = calloc(times, sizeof(double));

    unsigned char hash[SHA_DIGEST_LENGTH];

    GarbleType type = GARBLE_TYPE_STANDARD;

    seed = seedRandom(NULL);

    createInputLabels(inputLabels, n);
    buildAESCircuit(&gc, inputLabels);
	/* readCircuitFromFile(&gc, AES_CIRCUIT_FILE_NAME); */
    garbleCircuit(&gc, outputMap, type);
    hashGarbledCircuit(&gc, hash, type);

    {
        block *extractedLabels = allocate_blocks(n);
        block *computedOutputMap = allocate_blocks(m);
        int *inputs = calloc(n, sizeof(int));
        int *outputVals = calloc(m, sizeof(int));
        for (int i = 0; i < n; ++i) {
            inputs[i] = rand() % 2;
        }
        extractLabels(extractedLabels, inputLabels, inputs, gc.n);
        evaluate(&gc, extractedLabels, computedOutputMap, type);
        assert(mapOutputs(outputMap, computedOutputMap, outputVals, m) == SUCCESS);
        {
            GarbledCircuit gc2;

            (void) seedRandom(&seed);
            createInputLabels(inputLabels, n);
            buildAESCircuit(&gc2, inputLabels);
            assert(checkGarbledCircuit(&gc2, hash, type) == SUCCESS);
        }
        free(extractedLabels);
        free(computedOutputMap);
        free(inputs);
        free(outputVals);
    }

	for (int j = 0; j < times; j++) {
		for (int i = 0; i < times; i++) {
			timeGarble[i] = timedGarble(&gc, outputMap, type);
			timeEval[i] = timedEval(&gc, inputLabels, type);
		}
		timeGarbleMedians[j] = ((double) median(timeGarble, times)) / gc.q;
		timeEvalMedians[j] = ((double) median(timeEval, times)) / gc.q;
	}
	double garblingTime = doubleMean(timeGarbleMedians, times);
	double evalTime = doubleMean(timeEvalMedians, times);
	printf("%lf %lf\n", garblingTime, evalTime);

    free(outputMap);
    free(inputLabels);
    free(timeGarble);
    free(timeEval);
    free(timeGarbleMedians);
    free(timeEvalMedians);
	return 0;
}
示例#11
0
int main(int argc, char **argv) 
{ 
	AllScoreModels model;

	int i;
	char ann_file[256];
	char out_file[256];
	char input_file[256];
	char inspect_results_file[256];
	char list_file[256];
	char model_file[256];
	char initial_model[256];
	char model_dir[256];
	char PTM_string[256];
	char mgf_out_dir[256];
	char neg_spec_list[256];
	char tag_string[64];
	char tag_suffix[64];
	
	bool got_input_file=false,got_model_file=false, got_list_file=false;
	bool got_model_dir=false, got_initial_model=false, got_PTM_string = false, got_neg_spec_list=false;
	bool prm_only=false;
	bool prm_norm=false;
	bool pmcsqs_only = false;
	bool sqs_only = false;
	bool got_filter_spectra = false;
	bool pmcsqs_and_prm = false;
	bool train_flag = false;
	bool correct_pm = false;
	bool use_spectrum_charge = false;
	bool use_spectrum_mz     = false;
	bool perform_filter		 = true;
	bool output_aa_probs	 = false;
	bool output_cumulative_probs = false;
	bool make_inspect_tags   = false;
	bool make_training_fa	 = false;
	bool test_tags			 = false;
	bool got_make_ann_mgf	 = false;
	bool got_make_training_mgf = false;
	bool got_rescore_inspect = false;
	bool got_recalibrate_inspect = false;
	bool got_make_peak_examples  = false;

	int start_train_idx=0;
	int end_train_idx = POS_INF;
	int specific_charge=-1;
	int specific_size=-1;
	int specific_region=-1;

	int specific_idx = -1;
	
	int file_start_idx =0;
	int tag_length = 0;
	int num_solutions = 20;
	int digest_type = TRYPSIN_DIGEST;
	mass_t train_tolerance;
	float min_pmcsqs_prob = -1.0;
	mass_t fragment_tolerance = -1.0;
	mass_t pm_tolerance = -1.0;
	float sqs_filter_thresh = 0.0;
	float min_filter_prob = 0.0;
	int   num_test_cases=-1;
	int	  num_training_spectra=-1;

	seedRandom(112233);
	strcpy(tag_suffix,"tags");

	// read command line arguments
	i=1;
	while (i<argc)
	{

		if (! strcmp(argv[i],"-make_ann_mgf"))
		{
			if (++i == argc)
				print_help("Missing file ann file!");

			strcpy(ann_file,argv[i]);	

			if (++i == argc)
				print_help("Missing file out file!");

			strcpy(out_file,argv[i]);	

			got_make_ann_mgf=true;
		}
		else
		if (! strcmp(argv[i],"-make_training_mgf"))
		{
			if (++i == argc)
				print_help("Missing file out file!");

			strcpy(out_file,argv[i]);	

			if (++i == argc)
				print_help("Missing num training spectra!");

			num_training_spectra = atoi(argv[i]);
			if (num_training_spectra<=0)
				print_help("Error: -make_training_mgf [out_file] [num spectra>0]\n");
			
			got_make_training_mgf=true;
		}
		else if (!strcmp(argv[i],"-file"))
		{
			if (++i == argc)
				print_help("Missing file name!");

			strcpy(input_file,argv[i]);
			got_input_file=true;
		}
		else
		if (!strcmp(argv[i],"-list"))
		{
			if (++i == argc)
				print_help("Missing list name!");

			strcpy(list_file,argv[i]);
			got_list_file=true;
		}
		else if  (!strcmp(argv[i],"-file_start_idx"))
		{
			if (++i == argc)
				print_help("Missing file start idx!");

			file_start_idx = atoi(argv[i]);
		}
		else if (!strcmp(argv[i],"-model")) 
		{
			if (++i == argc)
				print_help("Missing model name!");

			strcpy(model_file,argv[i]);
			got_model_file=true;
		}
		else if (! strcmp(argv[i],"-model_dir"))
		{
			if (++i == argc)
				print_help("Missing model dir name!");

			strcpy(model_dir,argv[i]);
			got_model_dir=true;
		}
		else if (! strcmp(argv[i],"-fragment_tolerance"))
		{
			if (++i == argc)
				print_help("Missing model dir name!");

			fragment_tolerance = atof(argv[i]);
			if (fragment_tolerance<0 || fragment_tolerance>0.75)
				print_help("Error: -fragment_toelerance should be 0-0.75\n");
		}
		else if (! strcmp(argv[i],"-pm_tolerance"))
		{
			if (++i == argc)
				print_help("Missing model dir name!");

			pm_tolerance = atof(argv[i]);
			if (pm_tolerance<0 || pm_tolerance>5.0)
				print_help("Error: -pm_toelerance should be 0-5.0\n");
		}
		else if  (!strcmp(argv[i],"-num_solutions"))
		{
			if (++i == argc)
				print_help("Missing number of solutions!");

			num_solutions = atoi(argv[i]);
			if (num_solutions<=0 || num_solutions> 2000)
				print_help("Error: -num_solutions should be 1-2000\n");
		}
		else if (!strcmp(argv[i],"-tag_length"))
		{
			if (++i == argc)
				print_help("Missing minimum length parameter!");

			tag_length = atoi(argv[i]);
			if (tag_length<3 || tag_length>6)
				print_help("Error: -tag_length value must be 3-6\n");

		}
		else if (!strcmp(argv[i],"-digest"))
		{
			if (++i == argc)
				print_help("Missing digest type parameter : NON_SPECIFIC, TRYPSIN\n");

			if (! strcmp(argv[i],"NON_SPECIFIC"))
			{
				digest_type = NON_SPECIFIC_DIGEST;
			}
			else if (! strcmp(argv[i],"TRYPSIN"))
			{
				digest_type = TRYPSIN_DIGEST;
			}
			else
			{
				printf("Error: bad digest type: %s\n",argv[i]);
				print_help("Supported digest types: NON_SPECIFIC, TRYPSIN.");
			}
		}
		else if (! strcmp(argv[i],"-use_spectrum_charge"))
		{
			use_spectrum_charge = true;
		}
		else if (! strcmp(argv[i],"-use_spectrum_mz"))
		{
			use_spectrum_mz = true;
		}
		else if (! strcmp(argv[i],"-no_quality_filter"))
		{
			perform_filter = false;
		}
		else if (! strcmp(argv[i],"-correct_pm"))
		{
			correct_pm = true;
		}
		else if (! strcmp(argv[i],"-prm")) 
		{
			prm_only = true;
		}
		else if (! strcmp(argv[i],"-prm_norm")) 
		{
			prm_norm = true;
			prm_only = true;
		}
		else if (! strcmp(argv[i],"-output_aa_probs"))
		{
			output_aa_probs=true;
		}
		else if (! strcmp(argv[i],"-output_cumulative_probs"))
		{
			output_cumulative_probs=true;
		}
		else if (! strcmp(argv[i],"-pmcsqs_only"))
		{
			pmcsqs_only = true;
		}
		else if (! strcmp(argv[i],"-sqs_only"))
		{
			sqs_only = true;
		}
		else if (! strcmp(argv[i],"-min_filter_prob"))
		{
			if (++i == argc)
				print_help("Missing minimum probability parmater after -min_filter_prob !\n");

			min_filter_prob = -1.0;
			min_filter_prob = atof(argv[i]);
			if (min_filter_prob<0.0 || min_filter_prob>=1.0 || argv[i][0] != '0')
			{
				print_help("The flag -min_filter_prob should be followed by a minimal probability value [0-1.0]\n");
				exit(1);
			}
		}
		else if ( ! strcmp(argv[i],"-filter_spectra"))
		{
			got_filter_spectra = true;
			if (++i == argc)
				print_help("Missing minimum probability parmater after -filter_spectra !\n");
			
			sqs_filter_thresh=atof(argv[i]);

			if (sqs_filter_thresh <0 || sqs_filter_thresh>1.0)
				print_help("Error: the sqs threshold should be in the range 0-1 (recommended below 0.1)\n");
			
			if (++i == argc)
				print_help("Missing output directory for MGF files (second argument after -filter_spectra)!\n");
		
			strcpy(mgf_out_dir,argv[i]);
		}
		else if (! strcmp(argv[i],"-specific_idx"))
		{
			if (++i == argc)
				print_help("Missing idx!");
			specific_idx=atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-train_model"))
		{
			train_flag = true;
			if (++i == argc)
				print_help("Missing training tolerance!");

			train_tolerance = atof(argv[i]);
			if (train_tolerance<0.001 || train_tolerance>1.0)
				print_help("Error: training tolerance should be in the range 0.001 - 1.0\n");
		}
		else if (! strcmp(argv[i],"-start_train_idx"))
		{
			if (++i == argc)
				print_help("Missing start_train_idx!");

			start_train_idx = atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-end_train_idx"))
		{
			if (++i == argc)
				print_help("end_train_idx!");

			end_train_idx = atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-specific_reigon_model"))
		{
			if (++i == argc)
				print_help("specific_reigon_model!");

			specific_charge = atoi(argv[i++]);
			specific_size	= atoi(argv[i++]);
			specific_region = atoi(argv[i]);

		}
		else if (! strcmp(argv[i],"-specific_charge"))
		{
			if (++i == argc)
				print_help("specific_charge!");

			specific_charge = atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-specific_size"))
		{
			if (++i == argc)
				print_help("specific_size!");

			specific_size = atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-initial_model"))
		{
			got_initial_model = true;
			if (++i == argc)
				print_help("Missing initial model name!");
			strcpy(initial_model,argv[i]);
		}
		else if (! strcmp(argv[i],"-neg_spec_list"))
		{
			got_neg_spec_list = true;
			if (++i == argc)
				print_help("Missing neg spec list!");
			strcpy(neg_spec_list,argv[i]);
		}
		else if (! strcmp(argv[i],"-PTMs"))
		{
			got_PTM_string = true;
			if (++i == argc)
				print_help("Missing PTM list!");
			strcpy(PTM_string,argv[i]);
		}
		else if (! strcmp(argv[i],"-inspect_tags"))
		{
			make_inspect_tags=true;
			if (++i == argc)
				print_help("inspect_tags!");

			strcpy(tag_string,argv[i]);
		}
		else if (! strcmp(argv[i],"-rescore_inspect"))
		{
			got_rescore_inspect = true;
			if (++i == argc)
				print_help("Missing results file!");

			strcpy(inspect_results_file,argv[i]);

			if (++i == argc)
				print_help("Missing new results file!");

			strcpy(out_file,argv[i]);
		}
		else if (! strcmp(argv[i],"-recalibrate_inspect"))
		{
			got_recalibrate_inspect = true;
			if (++i == argc)
				print_help("Missing results file!");

			strcpy(inspect_results_file,argv[i]);

			if (++i == argc)
				print_help("Missing new results file!");

			strcpy(out_file,argv[i]); 		
		}
		else if ( ! strcmp(argv[i],"-make_peak_examples"))
		{
			got_make_peak_examples=true;
		}
		else if (! strcmp(argv[i],"-make_training_fa"))
		{
			make_training_fa=true;
		}
		else if (! strcmp(argv[i],"-test_tags"))
		{
			test_tags=true;
			if (++i == argc)
				print_help("test_tags!");

			strcpy(tag_string,argv[i]);
		}
		else if (! strcmp(argv[i],"-num_test_cases"))
		{
			if (++i == argc)
				print_help("num_test_cases!");

			num_test_cases = atoi(argv[i]);
		}
		else if (! strcmp(argv[i],"-tag_suffix"))
		{
			if (++i == argc)
				print_help("tag suffix!");
			strcpy(tag_suffix,argv[i]);
		}
		else
		{
			printf("**********************************************************\n");
			printf("\nError: Unkown command line option: %s\n\n",argv[i]);
			print_help("");
			exit(0); 
		}
		i++;
	}


	if (! got_model_file) 
		print_help("Error: Missing model name!");


	if (!got_input_file && ! got_list_file)
		print_help("Error: missing input file (either -file or -list must be used).");

	Config *config = model.get_config();

	if (got_model_dir)
	{
		config->set_resource_dir(string(model_dir));
	}

	

	//////////////////////////////////////////////////////////////////
	// Model Training
	if (train_flag)
	{	
		if (got_initial_model)
		{
			model.read_model(initial_model);
			if (got_PTM_string)
				config->apply_selected_PTMs(PTM_string);
			model.read_rank_models(initial_model,true);
			model.read_cum_seq_prob_models(initial_model,true);
		}
		else
		{
			config->init_with_defaults();
			config->set_tolerance(train_tolerance);
			config->set_digest_type(digest_type);
			if (got_PTM_string)
				config->apply_selected_PTMs(PTM_string);
		}

		model.set_model_name(string(model_file));
	
		SpectraAggregator sa;
		if (! got_list_file)
		{
			if (got_input_file)
			{
		//		fm.init_from_mgf(config,input_file);
				sa.initializeFromSpectraFilePath(input_file, config);
			}
			else
			{
				printf("Must supply a list of annotated spectra for training!\n");
				exit(0);
			}
		}
		else
		{
		//	fm.init_from_list_file(config,list_file);
			sa.initializeFromTextFile(list_file, config);
		}
		
		
		model.trainModelsInStages(model_file, 
								  sa,
									train_tolerance, 
									start_train_idx, 
									end_train_idx,
									specific_charge, 
									specific_size, 
									specific_region,
									(got_neg_spec_list ? neg_spec_list : NULL));

	

		model.write_model();
		exit(0);
	}
	
	///////////////////////////////////////////////////////////////////
	// Model initializing (running some sort of de novo, need a model)
	// 
	const time_t start_time = time(NULL);

	cout << "PepNovo V3. Build " << build_name << endl;
	cout << "Copyright 2008, The Regents of the University of California. All Rights Reserved." << endl;
	cout << "Created by Ari Frank ([email protected])" << endl << endl;
	cout << "Initializing models (this might take a few seconds)... " << flush;

	// TODO: incorporate PTM line into the model reading and also the other model stuff below
	model.read_model(model_file,true); 
	if (got_PTM_string)
		config->apply_selected_PTMs(PTM_string);
	model.getPeptideCompositionAssigner().init_aa_translations();
	model.read_rank_models(model_file,true);
	model.read_cum_seq_prob_models(model_file,true);

	cout << "Done." << endl;

	config = model.get_config();
	config->set_digest_type(digest_type);

	if (fragment_tolerance>0)
		config->set_tolerance(fragment_tolerance);

	if (pm_tolerance>0)
		config->setPrecursorMassTolerance(pm_tolerance);

	if (correct_pm)
		config->set_need_to_estimate_pm(1);

	if (use_spectrum_mz)
		config->set_use_spectrum_mz(1);

	if (use_spectrum_charge)
		config->set_use_spectrum_charge(1);

	if (! perform_filter)
		config->set_filter_flag(0);

	if (config->get_pm_tolerance()<0.1)
		config->set_need_to_estimate_pm(0);

	cout << setprecision(4) << fixed;
	cout << "Fragment tolerance : " << config->getTolerance() << endl;
	cout << "PM tolernace       : " << config->get_pm_tolerance() << endl;
	cout << "PTMs considered    : " ;
	if (got_PTM_string)
	{
		cout << PTM_string << endl;
	}
	else
	{
		cout << "None" << endl;
	}
	


	///////////////////////////////////////////////////////////////////
	// Training fa
	if (make_training_fa)
	{
		make_denovo_training_fa(model,input_file);
		exit(0);
	}

	///////////////////////////////////////////////////////////////////
	// Inspect tags

	if (make_inspect_tags)
	{
		create_tag_file_for_inspect(model,input_file,tag_string,tag_suffix);
		exit(0);
	}

	if (test_tags)
	{
		benchmark_tags(model,list_file,tag_string,num_test_cases);
		exit(0);
	}


	////////////////////////////////////////////////////////////////////
	// Rescore InsPecT
	if (got_rescore_inspect)
	{
		PeptideRankScorer *db_score = (PeptideRankScorer *)model.get_rank_model_ptr(0);
		db_score->rescore_inspect_results(input_file,inspect_results_file,out_file);
		exit(0);
	}

	if (got_recalibrate_inspect)
	{
		cout << "Recalibrating delta scores in " << input_file << endl;
		PeptideRankScorer *db_score = (PeptideRankScorer *)model.get_rank_model_ptr(0);
		db_score->recalibrate_inspect_delta_scores(input_file,inspect_results_file,out_file);
		exit(0);
	}

	if (got_make_peak_examples)
	{
		cout << "Making peak examples " << input_file << endl;
		PeptideRankScorer *db_score = (PeptideRankScorer *)model.get_rank_model_ptr(0);
		//db_score->make_peak_table_examples(input_file);
		exit(0);
	}



	///////////////////////////////////////////////////////////////////
	// Make input file list
	vector<string> list_vector;
	if (got_list_file)
	{
		readListOfPaths(list_file, list_vector);
	}
	else
		list_vector.push_back(input_file);

	int correct_benchmark =0;
	int total_benchmark =0;
	int counter=0;

	if (got_make_training_mgf)
	{
	//	make_training_mgf(config,list_file,num_training_spectra,out_file);
		exit(0);
	}


	if (sqs_only)
	{
		PMCSQS_Scorer *pmcsqs = (PMCSQS_Scorer *)model.get_pmcsqs_ptr();
		if (! pmcsqs ||  ! pmcsqs->getIndInitializedSqs())
		{
			cout << "Error: no spectrum quality score (SQS) for this model!" << endl;
			exit(1);
		}
	}
	else
	if (got_filter_spectra ||  pmcsqs_only)
	{
		PMCSQS_Scorer *pmcsqs = (PMCSQS_Scorer *)model.get_pmcsqs_ptr();
		if (! pmcsqs || ! pmcsqs->getIndInitializedPmc() || ! pmcsqs->getIndInitializedSqs())
		{
			cout << "Error: no parent mass correction (PMC) and/or quality score (SQS) for this model!" << endl;
			exit(1);
		}
	}




	///////////////////////////////////////////////////////////////////
	// FILTER SPECTRA
	if (got_filter_spectra)
	{
		int num_written =0;
		int num_read = 0;
		PMCSQS_Scorer *pmcsqs = (PMCSQS_Scorer *)model.get_pmcsqs_ptr();

	//	pmcsqs->output_filtered_spectra_to_mgfs(config, list_vector, mgf_out_dir, sqs_filter_thresh, num_written, num_read);
		
		time_t curr_time = time(NULL);
		double elapsed_time = (curr_time - start_time);
		cout << "Processed " << list_vector.size() << " (" << num_read << " spectra)." << endl;
		cout << "Wrote " << num_written << " spectra to mgfs in " << mgf_out_dir << endl;
		cout << "Elapsed time " << fixed << elapsed_time << " seconds." << endl;
		return 0;
	}

	//////////////////////////////////////////////////////////////////
	// PRM
	if (prm_only)
	{
		

		perform_prm_on_list_of_files(model, list_vector, min_filter_prob, file_start_idx, prm_norm);
	//	prm_benchmark(model, list_vector, min_pmcsqs_prob, file_start_idx);

	//	FileManager fm;
	//	fm.init_from_list(config,list_vector);
	//	model.learn_prm_normalizer_values(fm);
	//	model.write_prm_normalizer_values();
		return 0;
	}

	if (fabs(config->get_aa2mass()[Cys]-103.0)<1)
	{
		cout << endl <<"*** Warning: searching with unmodified cystine, usually the PTM C+57 should be included ***" << endl << endl;
	}
	cout << endl;

	//////////////////////////////////////////////////////////////////
	// PMCSQS
	if (pmcsqs_only)
	{
	//	perform_pmcsqs_on_list_of_files(model, list_vector, file_start_idx);
		return 0;
	}
 
	//////////////////////////////////////////////////////////////////
	// SQS
	if (sqs_only)
	{
	//	perform_sqs_on_list_of_files(model, list_vector, file_start_idx);
		return 0;
	}  
	
	//////////////////////////////////////////////////////////////////
	// DENOVO AND TAGS

	if (tag_length<=0)
	{
	//	perform_denovo_on_list_of_files(model, list_vector, file_start_idx, num_solutions, 7, 16, 
	//		false, min_filter_prob, output_aa_probs,  output_cumulative_probs, cout);
		new_perform_denovo_on_list_of_files(model, list_vector, file_start_idx, num_solutions, 7, 16, 
			false, min_filter_prob, output_aa_probs,  output_cumulative_probs, cout);
	}
	else
	{
		perform_tags_on_list_of_files(model,list_vector,file_start_idx,num_solutions,tag_length,
			false, min_filter_prob, output_aa_probs, output_cumulative_probs, cout);	
	}
	

#ifdef WIN32
	system("pause");
#endif

	return 0;
}
示例#12
0
// -------------------------------------------------------------------------- //
//
void Test_Interactions::testUpdateAndPickCustom()
{
    // Setup a list of custom rate processes.
    std::vector<CustomRateProcess> processes;

    // Setup a vector of dummy processes.
    std::vector<std::string> process_elements1(1);
    process_elements1[0] = "A";

    std::vector<std::string> process_elements2(1);
    process_elements2[0] = "B";

    std::vector<std::vector<double> > process_coordinates(1, std::vector<double>(3, 0.0));

    // Possible types.
    std::map<std::string, int> possible_types;
    possible_types["A"] = 0;
    possible_types["B"] = 1;
    possible_types["V"] = 2;

    const double rate = 1.0/13.7;
    Configuration c1(process_coordinates, process_elements1, possible_types);
    Configuration c2(process_coordinates, process_elements2, possible_types);
    std::vector<int> sites_vector(1,0);
    processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0));
    processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0));
    processes.push_back(CustomRateProcess(c1,c2,rate/2.0,sites_vector, 1.0));
    processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0));
    processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0));
    processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0));

    // Fake a matching by adding sites to the processes.

    // First process, 3 sites, total rate 12
    processes[0].addSite(12,  4.0);
    processes[0].addSite(123, 7.0);
    processes[0].addSite(332, 1.0);

    // Second process, 2 sites, total rate 4
    processes[1].addSite(19, 1.0);
    processes[1].addSite(12, 3.0);

    // Third process, 4 sites, total rate  3
    processes[2].addSite(19,  1.0/4.0);
    processes[2].addSite(12,  5.0/4.0);
    processes[2].addSite(234, 2.0/4.0);
    processes[2].addSite(991, 4.0/4.0);

    // The sixth process, one site, total rate 12.
    processes[5].addSite(992, 12.0);

    // Setup the interactions object.
    RateCalculator rc;
    Interactions interactions(processes, true, rc);

    // Update the probability table.
    interactions.updateProbabilityTable();

    // Check the values of the probability table.
    const std::vector<std::pair<double, int> > & probability_table = \
        interactions.probabilityTable();

    CPPUNIT_ASSERT_EQUAL( static_cast<int>(probability_table.size()),
                          static_cast<int>(processes.size()) );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[0].first,  12.0, 1.0e-14 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[1].first,  16.0, 1.0e-14 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[2].first,  19.0, 1.0e-14 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[3].first,  19.0, 1.0e-14 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[4].first,  19.0, 1.0e-14 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[5].first,  31.0, 1.0e-14 );

    CPPUNIT_ASSERT_EQUAL( probability_table[0].second, 3 );
    CPPUNIT_ASSERT_EQUAL( probability_table[1].second, 2 );
    CPPUNIT_ASSERT_EQUAL( probability_table[2].second, 4 );
    CPPUNIT_ASSERT_EQUAL( probability_table[3].second, 0 );
    CPPUNIT_ASSERT_EQUAL( probability_table[4].second, 0 );
    CPPUNIT_ASSERT_EQUAL( probability_table[5].second, 1 );


    // Make sure to seed the random number generator before we test any
    // random dependent stuff.
    seedRandom(false, 131);

    // Pick processes from this table with enough statistics should give
    // the distribution proportional to the number of available sites,
    // but with the double rate for the third process should halve
    // this entry.
    std::vector<int> picked(6,0);
    const int n_loop = 1000000;
    for (int i = 0; i < n_loop; ++i)
    {
        const int p = interactions.pickProcessIndex();

        // Make sure the picked process is not negative or too large.
        CPPUNIT_ASSERT( p >= 0 );
        CPPUNIT_ASSERT( p < static_cast<int>(probability_table.size()) );
        ++picked[p];
    }

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[0]/n_loop,
                                  12.0/31.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[1]/n_loop,
                                  4.0/31.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[2]/n_loop,
                                  3.0/31.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[3]/n_loop,
                                  0.0/31.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[4]/n_loop,
                                  0.0/31.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[5]/n_loop,
                                  12.0/31.0,
                                  1.0e-2 );

    // Check that picking the process twice with two different access methods and
    // a seed reset inbetween gives a reference to the same object.
    seedRandom(false, 87);
    const int p = interactions.pickProcessIndex();
    const Process & proc1 = (*interactions.processes()[p]);

    seedRandom(false, 87);
    const Process & proc2 = (*interactions.pickProcess());
    CPPUNIT_ASSERT_EQUAL( &proc1, &proc2 );

    // Alter the total rate in one of the processes and re-run the picking.
    interactions.processes()[5]->removeSite(992);
    interactions.processes()[5]->addSite(992, 24.0);

    // Update the probability table.
    interactions.updateProbabilityTable();
    std::vector<int> picked2(6,0);
    for (int i = 0; i < n_loop; ++i)
    {
        const int p = interactions.pickProcessIndex();

        // Make sure the picked process is not negative or too large.
        CPPUNIT_ASSERT( p >= 0 );
        CPPUNIT_ASSERT( p < static_cast<int>(probability_table.size()) );
        ++picked2[p];
    }

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[0]/n_loop,
                                  12.0/43.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[1]/n_loop,
                                  4.0/43.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[2]/n_loop,
                                  3.0/43.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[3]/n_loop,
                                  0.0/43.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[4]/n_loop,
                                  0.0/43.0,
                                  1.0e-2 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[5]/n_loop,
                                  24.0/43.0,
                                  1.0e-2 );

    // DONE
}
示例#13
0
// -------------------------------------------------------------------------- //
//
void Test_Hash::testHashCustomRateInput()
{
    // Setup a configuration and a process.

    // -----------------------------------------------------------------------
    // Setup a valid configuration.
    std::vector<std::vector<double> > coords(2, std::vector<double>(3, 0.0));

    // One cell with two atoms.
    coords[0][0] = 0.0;
    coords[0][1] = 0.0;
    coords[0][2] = 0.0;
    coords[1][0] = 0.5;
    coords[1][1] = 0.3;
    coords[1][2] = 0.1;

    // Setup elements.
    std::vector<std::vector<std::string> > elements(2);
    elements[0] = std::vector<std::string>(1,"A");
    elements[1] = std::vector<std::string>(1,"B");

    // Setup the mapping from element to integer.
    std::map<std::string, int> possible_types;
    possible_types["*"] = 0;
    possible_types["A"] = 1;
    possible_types["B"] = 2;
    possible_types["C"] = 3;
    possible_types["D"] = 4;
    possible_types["E"] = 5;
    possible_types["F"] = 6;

    // Construct the configuration.
    Configuration config(coords, elements, possible_types);

    // Setup a non periodic cooresponding lattice map.
    const std::vector<int> repetitions(3, 1);
    const std::vector<bool> periodicity(3, false);
    const int basis = 2;
    std::vector<int> basis_sites;
    basis_sites.push_back(1);
    basis_sites.push_back(0);

    LatticeMap lattice_map(basis, repetitions, periodicity);
    config.initMatchLists(lattice_map, 13);

    // Construct a process that should match the second index.

    // Setup the two configurations.
    std::vector<std::vector<std::string> > elements1;
    elements1.push_back(std::vector<std::string>(1,"B"));
    elements1.push_back(std::vector<std::string>(1,"A"));
    std::vector<std::vector<std::string> > elements2;
    elements2.push_back(std::vector<std::string>(1,"C"));
    elements2.push_back(std::vector<std::string>(1,"A"));
    // Setup coordinates.
    std::vector<std::vector<double> > process_coords(2,std::vector<double>(3,0.0));
    process_coords[1][0] =  -0.5;
    process_coords[1][1] =  -0.5;
    process_coords[1][2] =  -0.5;
    // The configurations.
    const Configuration config1(process_coords, elements1, possible_types);
    const Configuration config2(process_coords, elements2, possible_types);

    // Construct the process with a random rate.
    seedRandom(19, true);
    const double rate = 13.7*randomDouble01();
    const CustomRateProcess process1(config1, config2, rate, basis_sites, 12.0, std::vector<int>(0), std::vector<Coordinate>(0), 917);
    const CustomRateProcess process2(config1, config2, rate, basis_sites, 12.0, std::vector<int>(0), std::vector<Coordinate>(0), 916);
    int index;
    // -----------------------------------------------------------------------

    {
        // Get the hash.
        index = 1;
        const unsigned long int hash1 = hashCustomRateInput(index, process1, config);
        const unsigned long int ref1 = 18009609292013583759u;
        CPPUNIT_ASSERT_EQUAL(hash1, ref1);

        // Get the hash.
        index = 0;
        const unsigned long int hash0 = hashCustomRateInput(index, process1, config);
        const unsigned long int ref0 = 4224368175550234772u;
        CPPUNIT_ASSERT_EQUAL(hash0, ref0);
    }

    {
        // Check against another process that differs in the process number.
        index = 1;
        const unsigned long int hash1 = hashCustomRateInput(index, process2, config);
        const unsigned long int ref1 = 4824710481459367137u;
        CPPUNIT_ASSERT_EQUAL(hash1, ref1);

        index = 0;
        const unsigned long int hash0 = hashCustomRateInput(index, process2, config);
        const unsigned long int ref0 = 17780468236463825071u;
        CPPUNIT_ASSERT_EQUAL(hash0, ref0);
    }

    // Check performance.
    if (false)
    {
        double t1 = cpu_time();
        unsigned long int hash_loop;
        for (int i = 0; i < 10000000; ++i)
        {
            hash_loop = hashCustomRateInput(index, process2, config);
        }
        double t2 = cpu_time();

        // Printout to avoid optimization.
        printf("hash0 %lx\n %e", hash_loop, (t2-t1)/10000000);
    }
}
示例#14
0
/**
  * Post constructor initialisation method.
  *
  * This call will initialised the scheduler, memory allocator and Bluetooth stack.
  *
  * This is required as the Bluetooth stack can't be brought up in a
  * static context i.e. in a constructor.
  *
  * @code
  * uBit.init();
  * @endcode
  *
  * @note This method must be called before user code utilises any functionality
  *       contained by uBit.
  */
void MicroBit::init()
{
    if (status & MICROBIT_INITIALIZED)
        return;

#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR)
    // Bring up a nested heap allocator.
    microbit_create_nested_heap(MICROBIT_NESTED_HEAP_SIZE);
#endif

    // Bring up fiber scheduler.
    scheduler_init(messageBus);

    // Seed our random number generator
    seedRandom();

    // Create an event handler to trap any handlers being created for I2C services.
    // We do this to enable initialisation of those services only when they're used,
    // which saves processor time, memeory and battery life.
    messageBus.listen(MICROBIT_ID_MESSAGE_BUS_LISTENER, MICROBIT_EVT_ANY, this, &MicroBit::onListenerRegisteredEvent);

    status |= MICROBIT_INITIALIZED;

#if CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE)
    // Test if we need to enter BLE pairing mode...
    int i=0;
    sleep(100);
    while (buttonA.isPressed() && buttonB.isPressed() && i<10)
    {
        sleep(100);
        i++;

        if (i == 10)
        {
#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD)
            microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT);
#endif
            // Start the BLE stack, if it isn't already running.
            if (!ble)
            {
                bleManager.init(getName(), getSerial(), messageBus, true);
                ble = bleManager.ble;
            }

            // Enter pairing mode, using the LED matrix for any necessary pairing operations
            bleManager.pairingMode(display, buttonA);
        }
    }
#endif

    // Attempt to bring up a second heap region, using unused memory normally reserved for Soft Device.
#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD)
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
    microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT);
#else
    microbit_create_heap(MICROBIT_SRAM_BASE, MICROBIT_SD_LIMIT);
#endif
#endif

#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
    // Start the BLE stack, if it isn't already running.
    if (!ble)
    {
        bleManager.init(getName(), getSerial(), messageBus, false);
        ble = bleManager.ble;
    }
#endif
}
示例#15
0
文件: diffusion.c 项目: RoaldFre/DNA
int main(int argc, char **argv)
{
	seedRandom();

	parseArguments(argc, argv);
	const char *filenameBase = measurementConf.measureFile;

	allocWorld(1, worldSize);
	fillStrand(&world.strands[0], baseSequence);

	initGrid(numBoxes, worldSize);
	killMomentum();

	assert(worldSanityCheck());

	/* Integrator config */
	Integrator integrator;
	integrator.type = integratorType;
	switch (integratorType) {
	case VERLET:
		integrator.settings.verlet = verletSettings;
		break;
	case LANGEVIN:
		integrator.settings.langevin = langevinSettings;
		break;
	default:
		die("Unknown integrator type!\n");
	}
	integratorConf.integrator = integrator;

	/* Measurement header */
	char *measHeaderStrings[2];
	measHeaderStrings[0] = getWorldInfo();
	measHeaderStrings[1] = integratorInfo(&integratorConf);
	char *measHeader = asprintfOrDie("%s%s",
				measHeaderStrings[0], measHeaderStrings[1]);
	free(measHeaderStrings[0]); free(measHeaderStrings[1]);
	measurementConf.measureHeader = measHeader;

	/* Integrator task */
	Task integratorTask = makeIntegratorTask(&integratorConf);

	/* Verbose task */
	Measurement verbose;
	verbose.measConf = verboseConf;
	verbose.sampler = dumpStatsSampler();
	Task verboseTask = measurementTask(&verbose);

	/* Diffusion task */
	Measurement diffusion;
	diffusion.sampler = strandCOMSquaredDisplacementSampler(&world.strands[0]);
	diffusion.measConf = measurementConf;
	Task diffusionTask = measurementTask(&diffusion);

	/* End to end task */
	char *endToEndFile = asprintfOrDie("%s%s", filenameBase,
						END_TO_END_DIST_FILE_SUFFIX);
	Measurement endToEnd;
	endToEnd.sampler = endToEndDistSampler(&world.strands[0]);
	endToEnd.measConf = measurementConf; /* struct copy */
	endToEnd.measConf.measureFile = endToEndFile;
	endToEnd.measConf.verbose = false; /* Let output come from 
						 diffusion sampler */
	Task endToEndTask = measurementTask(&endToEnd);	

	/* Temperature task */
	char *temperatureFile = asprintfOrDie("%s%s", filenameBase,
						TEMPERATURE_FILE_SUFFIX);
	Measurement tempMeas;
	tempMeas.sampler = temperatureSampler();
	tempMeas.measConf = measurementConf; /* struct copy */
	tempMeas.measConf.measureFile = temperatureFile;
	tempMeas.measConf.verbose = false; /* Let output come from 
						 diffusion sampler */
	Task temperatureTask = measurementTask(&tempMeas);	

	/* Render task */
	Task renderTask = makeRenderTask(&renderConf);

	/* Combined task */
	Task *tasks[6];
	tasks[0] = (render ? &renderTask : NULL);
	tasks[1] = &integratorTask;
	tasks[2] = &verboseTask;
	tasks[3] = &diffusionTask;
	tasks[4] = (measureEndToEndDistance ? &endToEndTask : NULL);
	tasks[5] = (measureTemperature ? &temperatureTask : NULL);
	Task task = sequence(tasks, 6);

	setHeatBathTemperature(temperature);
	registerInteractions(interactionSettings);

	bool everythingOK = run(&task);

	freeWorld();
	free(endToEndFile);
	free(temperatureFile);
	free(measHeader);

	if (!everythingOK)
		return 1;
	return 0;
}