diff --git a/statgen/CMakeLists.txt b/statgen/CMakeLists.txt new file mode 100644 index 0000000..f8ff8e4 --- /dev/null +++ b/statgen/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 2.8) + +project(statgen) + +set(MY_CXX_FLAGS "-Wall") +set(CMAKE_CXX_FLAGS "-O0 ${MY_CXX_FLAGS}") +set(CMAKE_SHARED_LINKER_FLAGS "-lm") + +set(SOURCE_EXE main.c) +set(SOURCE_LIB add_main.c + coords.c + graph.c + int2char.c + messages.c + stat_print.c + stat_select.c + stat_sort.c + summary_stat.c) + +add_library(stat SHARED ${SOURCE_LIB}) +add_executable(statgen ${SOURCE_EXE}) + +target_link_libraries(statgen stat) \ No newline at end of file diff --git a/statgen/Makefile b/statgen/Makefile_bckp similarity index 68% rename from statgen/Makefile rename to statgen/Makefile_bckp index 5536912..ff59737 100644 --- a/statgen/Makefile +++ b/statgen/Makefile_bckp @@ -3,7 +3,7 @@ PROJECT=STATGEN CC=gcc CFLAGS=-c -Wall -fPIC LDFLAGS=-lm -SOURCES=main.c coords.c graph.c int2str.c messages.c stat_print.c stat_select.c stat_sort.c summary_stat.c +SOURCES=main.c add_main.c coords.c graph.c int2char.c messages.c stat_print.c stat_select.c stat_sort.c summary_stat.c OBJECTS=$(SOURCES:.c=.o) EXECUTABLE=statgen diff --git a/statgen/add_main.c b/statgen/add_main.c new file mode 100644 index 0000000..85aa1a6 --- /dev/null +++ b/statgen/add_main.c @@ -0,0 +1,85 @@ +/* Additional library for main.c (statgen) + */ + +#include + + +int error_checking (const float *cell, const int from, const char *input, + const int max_depth, const int num_of_inter, const char *output, + const int to, const int type_inter) +{ + if ((type_inter == 0) || (type_inter > 4)) + return 11; + if ((cell[0] == 0.0) || (cell[1] == 0.0) || (cell[2] == 0.0)) + return 12; + if ((to == -1) || (from == -1)) + return 13; + if (num_of_inter == 0) + return 14; + if (input[0] == '#') + return 15; + if (output[0] == '#') + return 16; + if ((max_depth < 3) && (max_depth != 0)) + return 19; + + return 0; +} + + +int printing_head (const char *output, const int log, const int quiet, + const char *input, const int from, const int to, const float *cell, + const int type_inter, const int *label_atom, + const int num_of_inter, const float *crit, const int max_depth) +{ + int i, j; + FILE *f_out; + + f_out = fopen (output, "w"); + fprintf (f_out, "statgen ::: V.1.0.0 ::: 2013-07-17\n\n"); + fprintf (f_out, "CONFIGURATION\n"); + + fprintf (f_out, "LOG=%i\nQUIET=%i\n", log, quiet); + fprintf (f_out, "MASK=%s\nFIRST=%i\nLAST=%i\n", input, from, to); + fprintf (f_out, "CELL=%.4f,%.4f,%.4f\n", cell[0], cell[1], cell[2]); + fprintf (f_out, "ATOMS=%i", label_atom[0]); + for (i=1; i #include -#include int reading_coords (const char *filename, const int type_inter, @@ -27,11 +26,12 @@ int reading_coords (const char *filename, const int type_inter, * coords - massive of coordinates */ { - char file_string[256]; - int atoms, i, j, tr_num_atoms, ref_mol, x, y; - float not_tr_coords[750000], ref[3]; + char at_symb[32], file_string[256]; + int atoms, cur_at_num, cur_at_type, cur_mol, i, j, tr_num_atoms, ref_mol, x, y; + float cur_coords[3], not_tr_coords[750000], ref[3]; FILE *inp; -/* file_string - temp string variable +/* cur_*, at_symb - temp variables + * file_string - temp string variable * atoms - total number of atoms in system * tr_num_atoms - number of translated atoms for writing coordinates (m.b. 8*num_atoms) * ref_mol - number of molecule for reference @@ -50,20 +50,23 @@ int reading_coords (const char *filename, const int type_inter, ref_mol = -1; fscanf (inp, "%i", &atoms); + fgets (file_string, 256, inp); for (i=0; i -#include #include -int check_cycle (const int N, const int *matrix) +int check_cycle (const int N, const int *pn) // function to return number of cycles { - int cycle, i, j; + int cycle, i; /* cycle - number of cycle */ cycle = 0; - for (i=0; i 2) && (cur_N <= depth)) { // copy connectivity matrix + cycle = 1; for (j=0; j N) depth = N; else depth = max_depth; - n_cycle = (int *) malloc ((max_depth-2) * sizeof (int)); +// convert to matrix of weight + pn = (int *) malloc (N * sizeof (int)); + n_cycle = (int *) malloc ((depth - 2) * sizeof (int)); + for (i=0; i 0) + iso[0] = check_tail (pn); + iso[1] = check_cycle (N, pn); + for (i=2; i 0) + { + check_cycle_size (N, matrix, depth, n_cycle); for (i=0; i -#include - char conv (const int fnumb, const int dig_pos) /* fnumb - integer diff --git a/statgen/int2char.h b/statgen/int2char.h new file mode 100644 index 0000000..a964562 --- /dev/null +++ b/statgen/int2char.h @@ -0,0 +1,6 @@ +#ifndef INT2CHAR_H +#define INT2CHAR_H + +char conv (const int, const int); + +#endif /* INT2CHAR_H */ \ No newline at end of file diff --git a/statgen/main.c b/statgen/main.c index 18f3e45..08cbabd 100644 --- a/statgen/main.c +++ b/statgen/main.c @@ -4,96 +4,14 @@ #include #include - -// prototypes -char conv (const int, const int); -int create_matrix (const int, const int, const int *, const int *, const float *, - const int, const float *, int *); -int message (const int, const int, const char *, FILE *); -int printing_agl (const char *, const char *, const int *, const int, - const int *, const int *, const int *, const int *, int *); -int proc_matrix (const int, const int *, int *, int *, int *, int *); -int reading_coords (const char *, const int, const int *, const float *, int *, - int *, int *, int *, int *, float *); -int summary_statistic (const char *, const int, const int, const int *, const int *); - - -int error_checking (const float *cell, int from, const char *input, - int num_of_inter, const char *output, int to, int type_inter) -{ - if ((type_inter == 0) || (type_inter > 4)) - return 11; - if ((cell[0] == 0.0) || (cell[1] == 0.0) || (cell[2] == 0.0)) - return 12; - if ((to == -1) || (from == -1)) - return 13; - if (num_of_inter == 0) - return 14; - if (input[0] == '#') - return 15; - if (output[0] == '#') - return 16; - - return 0; -} - - -int printing_head (const char *output, int log, int quiet, const char *input, - int from, int to, const float *cell, int type_inter, - const int *label_atom, int num_of_inter, const float *crit) -{ - int i; - FILE *f_out; - - f_out = fopen (output, "w"); - fprintf (f_out, "statgen ::: V.1.0.0 ::: 2013-07-17\n\n"); - fprintf (f_out, "CONFIGURATION\n"); - - fprintf (f_out, "LOG=%i\nQUIET=%i\n", log, quiet); - fprintf (f_out, "MASK=%s\nFIRST=%i\nLAST=%i\n", input, from, to); - fprintf (f_out, "CELL=%.4f,%.4f,%.4f\n", cell[0], cell[1], cell[2]); - fprintf (f_out, "ATOMS=%i", label_atom[0]); - for (i=1; i= 3)\n", tmp_str); sprintf (tmp_str, "%s -l - log enable\n", tmp_str); sprintf (tmp_str, "%s -q - quiet enable\n", tmp_str); sprintf (tmp_str, "%s -h - show this help and exit\n", tmp_str); @@ -255,6 +175,12 @@ int main (int argc, char *argv[]) strcpy (output, argv[i+1]); i++; } + else if ((argv[i][0] == '-') && (argv[i][1] == 'g')) +// graph isomorphism scan + { + sscanf (argv[i+1], "%i", &max_depth); + i++; + } else if ((argv[i][0] == '-') && (argv[i][1] == 'l')) // log mode { @@ -284,7 +210,8 @@ int main (int argc, char *argv[]) } // error checking - error = error_checking (cell, from, input, num_of_inter, output, to, type_inter); + error = error_checking (cell, from, input, max_depth, num_of_inter, output, to, + type_inter); if (error != 0) { sprintf (tmp_str, "Something wrong (error code: %i)!\nSee 'statgen -h' for more details\n", error); @@ -326,6 +253,7 @@ int main (int argc, char *argv[]) coords = (float *) malloc (3 * 8 * num_atoms * sizeof (float)); label_mol = (int *) malloc (8 * num_atoms * sizeof (int)); true_label_mol = (int *) malloc (8 * num_atoms * sizeof (int)); + type_agl = (int *) malloc ((max_depth + 2) * sizeof (int)); type_atoms = (int *) malloc (8 * num_atoms * sizeof (int)); // temporary declaration of variables agl = (int *) malloc (2 * 2 * sizeof (int)); @@ -337,6 +265,7 @@ int main (int argc, char *argv[]) if ((coords == NULL) || (label_mol == NULL) || (true_label_mol == NULL) || + (type_agl == NULL) || (type_atoms == NULL) || (agl == NULL) || (connect == NULL) || @@ -350,6 +279,9 @@ int main (int argc, char *argv[]) fputs (tmp_str, f_log); return 17; } +// set type_agl to zero + for (i=0; i -#include #include diff --git a/statgen/messages.h b/statgen/messages.h new file mode 100644 index 0000000..4a500fa --- /dev/null +++ b/statgen/messages.h @@ -0,0 +1,6 @@ +#ifndef MESSAGES_H +#define MESSAGES_H + +int message (const int, const int, const char *, FILE *); + +#endif /* MESSAGES_H */ \ No newline at end of file diff --git a/statgen/stat_print.c b/statgen/stat_print.c index 1081781..3922a38 100644 --- a/statgen/stat_print.c +++ b/statgen/stat_print.c @@ -3,20 +3,18 @@ * Usage: * printing_agl (input_file, output_file, number_of_molecules, * true_label_molecules, num_of_molecules_in_aglomerates, aglomerates, - * statistic, type_of_aglomerate) + * statistic, max_depth, type_of_aglomerate) */ #include #include - -// prototype -int graph_analyze (const int, const int *, const int, char *); +#include "graph.h" int printing_agl (const char *input, const char *output, const int *connect, const int num_mol, const int *true_label_mol, const int *num_mol_agl, - const int *agl, const int *stat, int *type_agl) + const int *agl, const int *stat, const int max_depth, int *type_agl) /* input - name of file with coordinates * output - name of output file * connect - connectivity graph for all molecules @@ -25,11 +23,11 @@ int printing_agl (const char *input, const char *output, const int *connect, * num_mol_agl - massive of numbers of molecule in aglomerates * agl - massive of aglomerates * stat - massive of statistics + * max_depth - max depth for check cycles in graph analyze * type_agl - massive of numbers of aglomerate types */ { - char iso[256]; - int i, j, k, *label_matrix, *matrix; + int i, *iso, j, k, *label_matrix, *matrix; FILE *f_out; /* iso - isomorphic graph in database * label_matrix - massive of indexes of molecule @@ -37,6 +35,7 @@ int printing_agl (const char *input, const char *output, const int *connect, * f_out - output file */ + iso = (int *) malloc (max_depth * sizeof (int)); f_out = fopen (output, "a"); // head @@ -71,10 +70,36 @@ int printing_agl (const char *input, const char *output, const int *connect, } // graph topology analyze - graph_analyze (num_mol_agl[i], matrix, 3, iso); + if (max_depth > 0) + graph_analyze (num_mol_agl[i], matrix, max_depth, iso); // printing class of aglomerate - fprintf (f_out, "AGL=%i=%s\n", num_mol_agl[i], iso); + fprintf (f_out, "AGL=%i=", num_mol_agl[i]); + for (j=0; j 2) +// branched + type_agl[3]++; + else +// not branched + type_agl[2]++; +// number of cycles + else if (j == 1) + if (iso[j] > 0) +// cycle + type_agl[1]++; + else +// linear + type_agl[0]++; + else if (j > 1) +// number of n_cycles + type_agl[j+2] += iso[j]; + + fprintf (f_out, "%i.", iso[j]); + } + fprintf (f_out, "\n"); for (j=0; j -#include #include diff --git a/statgen/stat_select.h b/statgen/stat_select.h new file mode 100644 index 0000000..4489256 --- /dev/null +++ b/statgen/stat_select.h @@ -0,0 +1,7 @@ +#ifndef STAT_SELECT_H +#define STAT_SELECT_H + +int create_matrix (const int, const int, const int *, const int *, const float *, + const int, const float *, int *); + +#endif /* STAT_SELECT_H */ \ No newline at end of file diff --git a/statgen/stat_sort.c b/statgen/stat_sort.c index 9e89dc0..69b1e21 100644 --- a/statgen/stat_sort.c +++ b/statgen/stat_sort.c @@ -5,7 +5,6 @@ * num_of_molecules_in_aglomerates, aglomerates, statistic, summary_statistic) */ -#include #include diff --git a/statgen/stat_sort.h b/statgen/stat_sort.h new file mode 100644 index 0000000..4d4c861 --- /dev/null +++ b/statgen/stat_sort.h @@ -0,0 +1,6 @@ +#ifndef STAT_SORT_H +#define STAT_SORT_H + +int proc_matrix (const int, const int *, int *, int *, int *, int *); + +#endif /* STAT_SORT_H */ \ No newline at end of file diff --git a/statgen/statgen b/statgen/statgen deleted file mode 100755 index b99e098..0000000 Binary files a/statgen/statgen and /dev/null differ diff --git a/statgen/summary_stat.c b/statgen/summary_stat.c index d028555..aa83f31 100644 --- a/statgen/summary_stat.c +++ b/statgen/summary_stat.c @@ -1,18 +1,18 @@ /* Library for summary statistic * Usage: * summary_statistic (filename, number_of_step, number_of_molecules, - * type_of_aglomerate, summary_statistic) + * max_depth, type_of_aglomerate, summary_statistic) */ #include -#include int summary_statistic (const char *filename, const int step, const int num_mol, - const int *type_agl, const int *stat_all) + const int max_depth, const int *type_agl, const int *stat_all) /* filename - name of output file * step - number of steps * num_mol - number of molecules + * max_depth - max depth for check cycles in graph analyze * type_agl - massive of numbers of aglomerate types * stat_all - massive of summary statistics */ @@ -52,12 +52,29 @@ int summary_statistic (const char *filename, const int step, const int num_mol, fprintf (f_out, " %7i %7i %9.2f %9.5f %10.5f\n", i+1, stat_all[i], conc, p, pn); } + if (max_depth > 0) + { // types of aglomerates - x = type_agl[0] + type_agl[1]; - type[0] = type_agl[0]; - type[1] = type_agl[1]; - fprintf (f_out, "------------------------------------------------\n"); - fprintf (f_out, "LINEAR=%.5f\nCYCLE=%.5f\n", type[0]/x, type[1]/x); + fprintf (f_out, "------------------------------------------------\n"); +// linear and cycle + x = type_agl[0] + type_agl[1]; + type[0] = type_agl[0]; + type[1] = type_agl[1]; + fprintf (f_out, "LINEAR=%7.5f\nCYCLE=%7.5f\n--------------------\n", type[0]/x, type[1]/x); +// branched + type[0] = type_agl[2]; + type[1] = type_agl[3]; + fprintf (f_out, "NOT BRANCHED=%7.5f\nBRANCHED=%7.5f\n--------------------\n", type[0]/x, type[1]/x); +// n_cycle + x = 0; + for (i=4; i