File: from_formula_stochastic.cpp

package info (click to toggle)
isospec 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,472 kB
  • sloc: cpp: 9,530; python: 2,095; makefile: 180; ansic: 100; sh: 88
file content (57 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "isoSpec++.h"
#include "fixedEnvelopes.h"
#include <cassert>

using namespace IsoSpec;

#ifndef ISOSPEC_TESTS_SKIP_MAIN

size_t test_stochastic(const char* formula, size_t molecules, double precision, bool print_confs);

int main(int argc, char** argv)
{
	if(argc < 3)
	{
		std::cout << "Proper usage (for example): ./from_formula_stochastic C10000H1000O1000N1000 10000000" << std::endl;
		std::cout << "...will the configurations with ionic current of 10000000 for the above molecule" << std::endl;
                std::cout << "Proper usage (for example): ./from_formula_stochastic C10000H1000O1000N1000 10000000 false" << std::endl;
                std::cout << "...will just count them" << std::endl;
		return -1;
	}

        bool print_confs = true;

        if(argc > 3)
            print_confs = (strcmp(argv[3], "true") == 0);

	size_t no_visited = test_stochastic(argv[1], atoi(argv[2]), 0.999, print_confs);
	
	std::cout << "The number of visited configurations is:" << no_visited << std::endl;

}
#endif /* ISOSPEC_TESTS_SKIP_MAIN */


size_t test_stochastic(const char* formula, size_t molecules, double precision, bool print_confs)
{
    FixedEnvelope fe = FixedEnvelope::FromStochastic(formula, molecules, precision, 5.0, print_confs);
    if(!print_confs)
        return fe.confs_no();

    const double* probs = fe.probs();
    double* masses = fe.release_masses();
    const int* confs = fe.confs();

    for(size_t ii=0; ii<fe.confs_no(); ii++)
    {
        std::cout << "PROB: " << probs[ii] << "  \tMASS: " << masses[ii] << "\tCONF: ";
        const int* space = confs + ii*fe.getAllDim();
        for(int ii=0; ii<fe.getAllDim(); ii++)
            std::cout << space[ii] << " ";
        std::cout << std::endl;

    }
    free(masses);
    return 0;
}