Release statgen 1.0.0

+ added messages
  + added error checking
  * some bug fix
This commit is contained in:
arcan1s
2013-07-19 17:09:58 +04:00
parent 41c6657090
commit 6426504bba
12 changed files with 113655 additions and 0 deletions

20
statgen/Makefile Normal file
View File

@ -0,0 +1,20 @@
PROJECT=STATGEN
CC=gcc
CFLAGS=-c -Wall -fPIC
LDFLAGS=-lm
SOURCES=main.c coords.c int2str.c messages.c stat_print.c stat_select.c stat_sort.c summary_stat.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=statgen
$(PROJECT): $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f *.o

279
statgen/coords.c Normal file
View File

@ -0,0 +1,279 @@
/* Library for reading coordinates from input file
*
* Usage:
* reading_coords (filename, type_interaction, labels, cell,
* &number_of_molecules, &number_of_atoms, true_label_molecule, label_molecule,
* type_atoms, coords)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int reading_coords (char *filename, int type_inter, const int *label_atom,
const float *cell, int *num_mol, int *num_atoms,
int *true_label_mol, int *label_mol,
int *type_atoms, float *coords)
/* filename - name of file with coordinates
* type_inter - type interaction (number of molecules for interaction)
* label_atom - types of atom for interaction
* cell - cell dimension
* num_mol - number of molecules for writing coordinates
* num_atoms - number of atoms for writing coordinates
* true_label_mol - massive of true numbers of molecule for atoms
* label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms
* 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];
FILE *inp;
/* 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
* not_tr_coords - not translated coordinates
* ref - coordinates of reference molecule
* inp - file with input data
*/
*num_atoms = 0;
*num_mol = 0;
// Reading file
inp = fopen (filename, "r");
if (inp == NULL)
return 1;
ref_mol = -1;
fscanf (inp, "%i", &atoms);
for (i=0; i<atoms; i++)
{
fgets (file_string, 256, inp);
for (j=0; j<type_inter; j++)
if (atoi (&file_string[47]) == label_atom[j])
{
not_tr_coords[3**num_atoms+0] = atof (&file_string[10]);
not_tr_coords[3**num_atoms+1] = atof (&file_string[23]);
not_tr_coords[3**num_atoms+2] = atof (&file_string[35]);
if (ref_mol != atoi (&file_string[53]))
{
ref_mol = atoi (&file_string[53]);
true_label_mol[*num_mol] = ref_mol;
*num_mol = *num_mol + 1;
}
label_mol[*num_atoms] = *num_mol - 1;
type_atoms[*num_atoms] = j;
*num_atoms = *num_atoms + 1;
}
}
fclose (inp);
// Translation
tr_num_atoms = *num_atoms;
for (i=0; i<*num_atoms; i++)
for (j=0; j<3; j++)
coords[3*i+j] = not_tr_coords[3*i+j];
// Assign initial value to reference coordinates
ref_mol = label_mol[0];
for (i=0; i<3; i++)
ref[i] = coords[i];
for (i=0; i<*num_atoms; i++)
{
if (label_mol[i] != ref_mol)
{
ref_mol = label_mol[i];
for (j=0; j<3; j++)
ref[j] = not_tr_coords[3*i+j];
}
for (x=0; x<3; x++)
{
if (ref[x] >= 0.0)
// if xyz >= 0.0 A
{
for (j=0; j<3; j++)
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
else
// if xyz < 0.0 A
{
for (j=0; j<3; j++)
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
for (x=0; x<3; x++)
{
for (y=x+1; y<3; y++)
{
if ((ref[x] >= 0.0) && (ref[y] >= 0.0))
// if xyz and xyz >= 0.0 A
{
for (j=0; j<3; j++)
if ((j == x) || (j == y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[x] < 0.0) && (ref[y] < 0.0))
// if xyz and xyz < 0.0 A
{
for (j=0; j<3; j++)
if ((j == x) || (j == y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
for (y=0; y<3; y++)
if ((ref[x] < 0.0) && (ref[y] >= 0.0))
// if xyz OR xyz >= 0.0
{
for (j=0; j<3; j++)
{
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
if (j == y)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
if ((j != x) && (j != y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
}
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
if ((ref[0] >= 0.0) && (ref[1] >= 0.0) && (ref[2] >= 0.0))
// if x and y and z >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] >= 0.0) && (ref[2] < 0.0))
// if x and y >= 0.0 A and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] < 0.0) && (ref[2] >= 0.0))
// if x and z >= 0.0 A and y < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] >= 0.0) && (ref[2] >= 0.0))
// if y and z >= 0.0 A and x < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] < 0.0) && (ref[2] >= 0.0))
// if x and y < 0.0 A and z >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] >= 0.0) && (ref[2] < 0.0))
// if x and z < 0.0 A and y >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] < 0.0) && (ref[2] < 0.0))
// if x >= 0.0 A and y and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] < 0.0) && (ref[2] < 0.0))
// if x and y and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
return 0;
}

26
statgen/int2str.c Normal file
View File

@ -0,0 +1,26 @@
/* Library for converting integer to string
* Usage
* char = conv (number, position)
*/
#include <stdio.h>
#include <stdlib.h>
char conv (int fnumb, int dig_pos)
/* fnumb - integer
* dig_pos - position
*/
{
int d, h, o;
char const digit[] = "0123456789";
h = fnumb / 100;
d = (fnumb % 100) / 10;
o = fnumb % 10;
if (dig_pos == 1) return digit[o];
if (dig_pos == 2) return digit[d];
if (dig_pos == 3) return digit[h];
else return digit[0];
}

534
statgen/main.c Normal file
View File

@ -0,0 +1,534 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// prototypes
char conv (int, int);
int create_matrix (int, int, const int *, const int *, const float *, int,
const float *, int *);
int message (int, int, const char *, FILE *);
int printing_agl (char *, char *, const int *, int, const int *, const int *,
const int *, const int *, int *);
int proc_matrix (int, const int *, int *, int *, int *, int *);
int reading_coords (char *, int, const int *, const float *, int *, int *,
int *, int *, int *, float *);
int summary_statistic (char *, int, 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<type_inter; i++)
fprintf (f_out, ",%i", label_atom[i]);
fprintf (f_out, "\n");
for (i=0; i<num_of_inter; i++)
{
fprintf (f_out, "INTERACTION=");
fprintf (f_out, "0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", crit[16*i+0], crit[16*i+1],
crit[16*i+5]);
fprintf (f_out, "0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", crit[16*i+2], crit[16*i+6],
crit[16*i+10]);
fprintf (f_out, "0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f\n", crit[16*i+3],
crit[16*i+7], crit[16*i+11], crit[16*i+15]);
}
fprintf (f_out, "END\n\n");
fclose (f_out);
return 0;
}
int set_defaults (float *cell, int *from, char *input, int *log, int *num_of_inter,
char *output, int *to, int *type_agl, int *type_inter, int *quiet)
{
int i;
for (i=0; i<3; i++)
cell[i] = 0.0;
*from = -1;
input[0] = '#';
*log = 0;
*num_of_inter = 0;
output[0] = '#';
*to = -1;
type_agl[0] = 0;
type_agl[1] = 0;
*type_inter = 0;
*quiet = 0;
return 0;
}
int main (int argc, char *argv[])
{
char filename[256], tmp_str[2048];
int error, i, index, j, k, label[2];
float label_fl;
FILE *f_inp, *f_log;
char input[256], logfile[256], output[256];
float cell[3], *coords, *crit;
int *agl, *connect, from, *label_atom, *label_mol, log, num_atoms, num_mol,
*num_mol_agl, num_of_inter, *stat, *stat_all, step, to, *true_label_mol,
type_agl[2], *type_atoms, type_inter, quiet;
/* input - mask of input files
* logfile - log file name
* output - output file name
*
* cell - cell dimension
* coords - massive of coordinates
* crit - massive of criteria
*
* agl - massive of aglomerates
* connect - connectivity graph for all molecules
* from - start point
* label_atom - types of atom for interaction
* label_mol - massive of numbers of molecule for atoms
* log - status of log-mode
* num_atoms - number of atoms for writing coordinates
* num_mol - number of molecules for writing coordinates
* num_mol_agl - massive of numbers of molecule in aglomerates
* num_of_inter - number of different interactions
* stat - massive of statistics
* stat_all - massive of summary statistics
* step - $(to - from + 1)
* to - finish point
* true_label_mol - massive of true numbers of molecule for atoms
* type_agl - massive of numbers of aglomerate types
* type_atoms - massive of atom types for atoms
* type_inter - type interaction (number of molecules for interaction)
* quiet - status of quiet-mode
*/
set_defaults (cell, &from, input, &log, &num_of_inter, output, &to, type_agl,
&type_inter, &quiet);
// reading number of interactions
for (i=1; i<argc; i++)
if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
num_of_inter++;
if (num_of_inter > 0)
{
crit = (float *) malloc ( 16 * num_of_inter * sizeof (float));
for (i=0; i<16*num_of_inter; i++)
crit[i] = 0.0;
num_of_inter = 0;
}
// reading arguments
for (i=1; i<argc; i++)
{
if ((argv[i][0] == '-') && (argv[i][1] == 'h'))
{
sprintf (tmp_str, " statgen\n");
sprintf (tmp_str, "%sProgram for analyze molecular dynamic trajectories\n", tmp_str);
sprintf (tmp_str, "%sVersion : 1.0.0 License : GPL\n", tmp_str);
sprintf (tmp_str, "%s Evgeniy Alekseev aka arcanis\n", tmp_str);
sprintf (tmp_str, "%s E-mail : esalexeev@gmail.com\n\n", tmp_str);
sprintf (tmp_str, "%sUsage:\n", tmp_str);
sprintf (tmp_str, "%sstatgen -i INPUT -s FIRST,LAST -c X,Y,Z -a ... -r ... -o OUTPUT [ -l LOGFILE ] [ -q ] [ -h ]\n\n", tmp_str);
sprintf (tmp_str, "%sParametrs:\n", tmp_str);
sprintf (tmp_str, "%s -i - mask of input files\n", tmp_str);
sprintf (tmp_str, "%s -s - trajectory steps (integer)\n", tmp_str);
sprintf (tmp_str, "%s -c - cell size (float), A\n", tmp_str);
sprintf (tmp_str, "%s -a - atom types (integer). Format: 'ATOM1' or 'ATOM1,ATOM2' or etc\n", tmp_str);
sprintf (tmp_str, "%s -r - criteria (float), A. Format: '0-0:2.4,0-1:3.0' means 0-0-interaction\n", tmp_str);
sprintf (tmp_str, "%s (<2.4 A) and 0-1 (<3.0) are needed. This flag can be used multiple times\n", tmp_str);
sprintf (tmp_str, "%s -o - output file name\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);
fputs (tmp_str, stdout);
return 0;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'i'))
// mask of input files
{
strcpy (input, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 's'))
// steps
{
sscanf (argv[i+1], "%i,%i", &from, &to);
if (from > to)
{
to += from;
from = to - from;
to -= from;
}
step = to - from + 1;
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'c'))
// cell size
{
sscanf (argv[i+1], "%f,%f,%f", &cell[0], &cell[1], &cell[2]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'a'))
// atom types
{
type_inter = 1;
for (j=0; j<strlen(argv[i+1]); j++)
if (argv[i+1][j] == ',')
type_inter++;
label_atom = (int *) malloc (type_inter * sizeof (int));
switch (type_inter)
{
case 1:
sscanf (argv[i+1], "%i", &label_atom[0]);
break;
case 2:
sscanf (argv[i+1], "%i,%i", &label_atom[0], &label_atom[1]);
break;
case 3:
sscanf (argv[i+1], "%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2]);
break;
case 4:
sscanf (argv[i+1], "%i,%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2], &label_atom[3]);
break;
}
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
// criteria
{
index = 0;
sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
for (j=index; j<strlen(argv[i+1]); j++)
if (argv[i+1][j] == ',')
{
index = j+1;
sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
}
num_of_inter++;
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'o'))
// output file
{
strcpy (output, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'l'))
// log mode
{
log = 1;
strcpy (logfile, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'q'))
// quiet mode
{
quiet = 1;
}
}
if (log == 1)
f_log = fopen (logfile, "w");
if (quiet != 1)
{
message (0, 0, argv[0], stdout);
message (0, 1, argv[0], stdout);
}
if (log == 1)
{
message (1, 0, argv[0], f_log);
message (1, 1, argv[0], f_log);
}
// error checking
error = error_checking (cell, from, input, 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);
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 1;
}
if (quiet != 1)
message (0, 2, argv[0], stdout);
if (log == 1)
message (1, 2, argv[0], f_log);
// processing
// initial variables
k = strlen (input);
strcpy (filename, input);
filename[k] = '.';
filename[k+1] = conv (from, 3);
filename[k+2] = conv (from, 2);
filename[k+3] = conv (from, 1);
filename[k+4] = '\0';
if (quiet != 1)
message (0, 3, filename, stdout);
if (log == 1)
message (1, 3, filename, f_log);
f_inp = fopen (filename, "r");
if (f_inp == NULL)
{
sprintf (tmp_str, "\nFile '%s' not found\nError", filename);
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 1;
}
fscanf (f_inp, "%i", &num_atoms);
fclose (f_inp);
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_atoms = (int *) malloc (8 * num_atoms * sizeof (int));
// temporary declaration of variables
agl = (int *) malloc (2 * 2 * sizeof (int));
connect = (int *) malloc (2 * 2 * sizeof (int));
num_mol_agl = (int *) malloc (2 * sizeof (int));
stat = (int *) malloc (2 * sizeof (int));
stat_all = (int *) malloc (2 * sizeof (int));
// error checking
if ((coords == NULL) ||
(label_mol == NULL) ||
(true_label_mol == NULL) ||
(type_atoms == NULL) ||
(agl == NULL) ||
(connect == NULL) ||
(num_mol_agl == NULL) ||
(stat == NULL) ||
(stat_all == NULL))
{
sprintf (tmp_str, "\nMemory error (error code: 17)\n");
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 17;
}
if (quiet != 1)
{
sprintf (tmp_str, "%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n\
%6cMask: %s;\n%6cFirst step: %i;\n%6cLast step: %i;\n%6cCell size: %.4f, %.4f, %.4f;\n\
%6cSelect atoms: %i", ' ', output, ' ', log, ' ', quiet, ' ', input, ' ', from,
' ' , to, ' ', cell[0], cell[1], cell[2], ' ' , label_atom[0]);
for (i=1; i<type_inter; i++)
sprintf (tmp_str, "%s,%i", tmp_str, label_atom[i]);
sprintf (tmp_str, "%s;\n", tmp_str);
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%6cInteraction: ", tmp_str, ' ');
sprintf (tmp_str, "%s0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", tmp_str, crit[16*i+0],
crit[16*i+1], crit[16*i+5]);
sprintf (tmp_str, "%s0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", tmp_str, crit[16*i+2],
crit[16*i+6], crit[16*i+10]);
sprintf (tmp_str, "%s0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f;\n", tmp_str,
crit[16*i+3], crit[16*i+7], crit[16*i+11], crit[16*i+15]);
}
message (0, 5, tmp_str, stdout);
}
if (log == 1)
{
sprintf (tmp_str, "%34cOutput file: '%s';\n%34cLog: %i;\n%34cQuiet: %i;\n\
%34cMask: %s;\n%34cFirst step: %i;\n%34cLast step: %i;\n%34cCell size: %.4f, %.4f, %.4f;\n\
%34cSelect atoms: %i", ' ', output, ' ', log, ' ', quiet, ' ', input, ' ', from,
' ' , to, ' ', cell[0], cell[1], cell[2], ' ' , label_atom[0]);
for (i=1; i<type_inter; i++)
sprintf (tmp_str, "%s,%i", tmp_str, label_atom[i]);
sprintf (tmp_str, "%s;\n", tmp_str);
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%34cInteraction: ", tmp_str, ' ');
sprintf (tmp_str, "%s0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", tmp_str, crit[16*i+0],
crit[16*i+1], crit[16*i+5]);
sprintf (tmp_str, "%s0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", tmp_str, crit[16*i+2],
crit[16*i+6], crit[16*i+10]);
sprintf (tmp_str, "%s0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f;\n", tmp_str,
crit[16*i+3], crit[16*i+7], crit[16*i+11], crit[16*i+15]);
}
message (1, 5, tmp_str, f_log);
}
// head
printing_head (output, log, quiet, input, from, to, cell, type_inter, label_atom,
num_of_inter, crit);
// main cycle
if (quiet != 1)
message (0, 6, argv[0], stdout);
if (log == 1)
message (1, 6, argv[0], f_log);
for (i=from; i<to+1; i++)
{
// reading coordinates
filename[k+1] = conv (i, 3);
filename[k+2] = conv (i, 2);
filename[k+3] = conv (i, 1);
filename[k+4] = '\0';
if (quiet != 1)
message (0, 7, filename, stdout);
if (log == 1)
message (1, 7, filename, f_log);
error = reading_coords (filename, type_inter, label_atom, cell, &num_mol,
&num_atoms, true_label_mol, label_mol, type_atoms, coords);
if (error != 1)
{
if (quiet != 1)
{
sprintf (tmp_str, "%6cNumber of molecules: %i\n%6cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms);
message (0, 8, tmp_str, stdout);
}
if (log == 1)
{
sprintf (tmp_str, "%6cNumber of molecules: %i\n%34cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms);
message (1, 8, tmp_str, f_log);
}
}
// resize dynamic arrays
agl = (int *) realloc (agl, num_mol * num_mol * sizeof (int));
connect = (int *) realloc (connect, num_mol * num_mol * sizeof (int));
num_mol_agl = (int *) realloc (num_mol_agl, num_mol * sizeof (int));
stat = (int *) realloc (stat, num_mol * sizeof (int));
if (i == from)
{
stat_all = (int *) realloc (stat_all, num_mol * sizeof (int));
for (j=0; j<num_mol; j++)
stat_all[j] = 0;
}
// error checking
if ((agl == NULL) ||
(connect == NULL) ||
(num_mol_agl == NULL) ||
(stat == NULL) ||
(stat_all == NULL))
{
sprintf (tmp_str, "\nMemory error (error code: 18)\n");
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 18;
}
if (quiet != 1)
message (0, 9, argv[0], stdout);
if (log == 1)
message (1, 9, argv[0], f_log);
// analyze
if (error == 0)
{
error = 1;
error = create_matrix (num_mol, num_atoms, label_mol, type_atoms, coords,
num_of_inter, crit, connect);
if (error == 0)
{
if (quiet != 1)
message (0, 10, argv[0], stdout);
if (log == 1)
message (1, 10, argv[0], f_log);
error = 1;
error = proc_matrix (num_mol, connect, num_mol_agl, agl, stat, stat_all);
if (error == 0)
{
if (quiet != 1)
message (0, 11, argv[0], stdout);
if (log == 1)
message (1, 11, argv[0], f_log);
error = printing_agl (filename, output, connect, num_mol,
true_label_mol, num_mol_agl, agl, stat, type_agl);
if (error == 0)
{
if (quiet != 1)
message (0, 12, output, stdout);
if (log == 1)
message (1, 12, output, f_log);
}
}
}
}
}
if (quiet != 1)
{
message (0, 13, argv[0], stdout);
message (0, 14, output, stdout);
}
if (log == 1)
{
message (1, 13, argv[0], f_log);
message (1, 14, output, f_log);
}
// tail
summary_statistic (output, step, num_mol, type_agl, stat_all);
if (quiet != 1)
message (0, 15, argv[0], stdout);
if (log == 1)
message (1, 15, argv[0], f_log);
// free memory
free (agl);
free (connect);
free (coords);
free (crit);
free (label_mol);
free (num_mol_agl);
free (stat);
free (stat_all);
free (true_label_mol);
free (type_atoms);
if (quiet != 1)
message (0, 16, argv[0], stdout);
if (log == 1)
message (1, 16, argv[0], f_log);
if (log == 1)
fclose (f_log);
return 0;
}

85
statgen/messages.c Normal file
View File

@ -0,0 +1,85 @@
/* Library for printing messages at stdout
*
* Usage:
* message (log, mode, text, stdout)
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
int message (int log, int mode, const char *text, FILE *stdout)
/* mode - number of message
* text - additional text
*/
{
char out[4096];
if (log == 1)
{
char time_str[256];
time_t t = time(NULL);
struct tm* aTm = localtime(&t);
sprintf(time_str, "[%04d-%02d-%02d %02d:%02d:%02d] [%2i]: ", aTm->tm_year+1900,
aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec, mode);
fputs (time_str, stdout);
}
switch (mode)
{
case 0:
sprintf (out, "Starting program: '%s' (Ver.1.0.0)\n", text);
break;
case 1:
sprintf (out, "Checking errors\n");
break;
case 2:
sprintf (out, "Errors are not detected\n");
break;
case 3:
sprintf (out, "Initialization of variables from file '%s'\n", text);
break;
case 4:
break;
case 5:
sprintf (out, "Initial parametrs: \n%s", text);
break;
case 6:
sprintf (out, "Processing\n");
break;
case 7:
sprintf (out, "Open file: '%s'\n", text);
break;
case 8:
sprintf (out, "%s", text);
break;
case 9:
sprintf (out, "%6cSize of variables was changed successfully\n", ' ');
break;
case 10:
sprintf (out, "%6cConnectivity matrix was created successfully\n", ' ');
break;
case 11:
sprintf (out, "%6cConnectivity matrix was processed successfully\n", ' ');
break;
case 12:
sprintf (out, "%6cResult was printed to file '%s' successfully\n", ' ', text);
break;
case 13:
sprintf (out, "End of processing\n");
break;
case 14:
sprintf (out, "Printing summary statistic to file '%s'\n", text);
break;
case 15:
sprintf (out, "Free memory\n");
break;
case 16:
sprintf (out, "Exiting without errors\n");
break;
}
fputs (out, stdout);
return 0;
}

3376
statgen/oct-clb.001 Executable file

File diff suppressed because it is too large Load Diff

105726
statgen/oct-clb_4.55.dat Executable file

File diff suppressed because it is too large Load Diff

3241
statgen/oct.001 Executable file

File diff suppressed because it is too large Load Diff

111
statgen/stat_print.c Normal file
View File

@ -0,0 +1,111 @@
/* Library for printing aglomerates
*
* Usage:
* printing_agl (input_file, output_file, number_of_molecules,
* true_label_molecules, num_of_molecules_in_aglomerates, aglomerates,
* statistic, type_of_aglomerate)
*/
#include <stdio.h>
#include <stdlib.h>
int printing_agl (char *input, char *output, const int *connect, int num_mol,
const int *true_label_mol, const int *num_mol_agl,
const int *agl, const int *stat, int *type_agl)
/* input - name of file with coordinates
* output - name of output file
* connect - connectivity graph for all molecules
* num_mol - number of molecules
* true_label_mol - massive of true numbers of molecule for atoms
* num_mol_agl - massive of numbers of molecule in aglomerates
* agl - massive of aglomerates
* stat - massive of statistics
* type_agl - massive of numbers of aglomerate types
*/
{
int i, iso, j, k, p, type, *label_matrix, **matrix;
FILE *f_out;
/* iso - isomorphic graph in database
* type - number of cycle in aglomerates
* label_matrix - massive of indexes of molecule
* matrix - connectivity graph
* f_out - output file
*/
f_out = fopen (output, "a");
// head
fprintf (f_out, "FILE=%s\nSTATISTIC\n| n | N |\n-----------------\n", input);
for (i=0; i<num_mol; i++)
if (stat[i] != 0)
fprintf (f_out, " %7i %7i \n", i+1, stat[i]);
fprintf (f_out, "-----------------\n");
// body
for (i=0; i<num_mol; i++)
if (num_mol_agl[i] > 0)
{
// creating connectivity graph
matrix = (int **) malloc (num_mol_agl[i] * sizeof (int *));
for (j=0; j<num_mol_agl[i]; j++)
{
matrix[j] = (int *) malloc (num_mol_agl[i] * sizeof (int));
for (k=0; k<num_mol_agl[i]; k++)
matrix[j][k] = 0;
}
label_matrix = (int *) malloc (num_mol * sizeof (int));
if ((matrix == NULL) ||
(label_matrix == NULL))
return 1;
for (j=0; j<num_mol_agl[i]; j++)
label_matrix[agl[num_mol*i+j]] = j;
for (j=0; j<num_mol_agl[i]; j++)
for (k=j+1; k<num_mol_agl[i]; k++)
if (connect[num_mol*agl[num_mol*i+j]+agl[num_mol*i+k]] == 1)
{
matrix[label_matrix[agl[num_mol*i+j]]][label_matrix[agl[num_mol*i+k]]] = 1;
matrix[label_matrix[agl[num_mol*i+k]]][label_matrix[agl[num_mol*i+j]]] = 1;
}
// TODO: analyze of topology
iso = 0;
p = 0;
for (j=0; j<num_mol_agl[i]; j++)
for (k=0; k<num_mol_agl[i]; k++)
p += matrix[j][k];
if (p == (2*num_mol_agl[i]-2))
{
type = 0;
type_agl[0]++;
}
else
{
type = (p - (2*num_mol_agl[i]-2)) / 2;
type_agl[1]++;
}
// printing class of aglomerate
fprintf (f_out, "AGL=%i=%i=%i\n", num_mol_agl[i], type, iso);
for (j=0; j<num_mol_agl[i]; j++)
{
fprintf (f_out, "%7i=", true_label_mol[agl[num_mol*i+j]]);
for (k=0; k<num_mol_agl[i]; k++)
{
if (matrix[j][k] == 1)
fprintf (f_out, "%i,", true_label_mol[agl[num_mol*i+k]]);
}
fprintf (f_out, "\n");
}
// free memory
for (j=0; j<num_mol_agl[i]; j++)
free (matrix[j]);
free (matrix);
free (label_matrix);
}
fprintf (f_out, "---------------------------------------------------\n");
fclose (f_out);
return 0;
}

106
statgen/stat_select.c Normal file
View File

@ -0,0 +1,106 @@
/* Library for creating connectivity matrix
*
* Usage:
* create_matrix (number_of_molecules, number_of_atoms, label_molecule,
* type_atoms, coords, number_of_interactions, criteria, connect_matrix)
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int create_matrix (int num_mol, int num_atoms, const int *label_mol,
const int *type_atoms, const float *coords, int num_of_inter,
const float *crit, int *connect)
/* num_mol - number of molecules
* num_atoms - number of atoms
* label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms
* coords - massive of coordinates
* num_of_inter - number of different interactions
* crit - massive of criteria
* connect - connectivity graph for all molecules
*/
{
float r;
int cur_num_inter, i, j, k, l, num_inter, ***label_inter;
/* r - radius
* cur_num_inter - current number of true interactions
* num_inter - needed number of true interactions
* label_inter - temporary massive of true interactions
*/
label_inter = (int ***) malloc (num_mol * sizeof (int **));
for (i=0; i<num_mol; i++)
{
label_inter[i] = (int **) malloc (num_mol * sizeof (int *));
for (j=0; j<num_mol; j++)
{
label_inter[i][j] = (int *) malloc (16 * sizeof (int));
for (k=0; k<16; k++)
label_inter[i][j][k] = 0;
}
}
if (label_inter == NULL)
return 1;
// creating initial connectivity matrix
for (i=0; i<num_atoms*8; i++)
for (j=i+1; j<num_atoms*8; j++)
// if atoms from different molecules
if (label_mol[i] != label_mol[j])
{
r = sqrt (pow ((coords[3*i+0]-coords[3*j+0]), 2) +
pow ((coords[3*i+1]-coords[3*j+1]), 2) +
pow ((coords[3*i+2]-coords[3*j+2]), 2));
for (k=0; k<num_of_inter; k++)
if (crit[16*k+4*type_atoms[i]+type_atoms[j]] != 0.0)
if (r < crit[16*k+4*type_atoms[i]+type_atoms[j]])
{
label_inter[label_mol[i]][label_mol[j]][4*type_atoms[i]+type_atoms[j]] = 1;
label_inter[label_mol[i]][label_mol[j]][4*type_atoms[j]+type_atoms[i]] = 1;
label_inter[label_mol[j]][label_mol[i]][4*type_atoms[i]+type_atoms[j]] = 1;
label_inter[label_mol[j]][label_mol[i]][4*type_atoms[j]+type_atoms[i]] = 1;
}
}
for (i=0; i<num_mol; i++)
for (j=0; j<num_mol; j++)
connect[i*num_mol+j] = 0;
// processing of initial connectivity matrix
for (k=0; k<num_of_inter; k++)
{
// determination of the number of interactions
num_inter = 0;
for (l=0; l<16; l++)
if (crit[16*k+l] != 0.0)
num_inter++;
for (i=0; i<num_mol; i++)
for (j=i+1; j<num_mol; j++)
{
cur_num_inter = 0;
for (l=0; l<16; l++)
cur_num_inter += label_inter[i][j][l];
if (cur_num_inter == num_inter)
{
connect[i*num_mol+j] = 1;
connect[j*num_mol+i] = 1;
}
}
}
// free memory
for (i=0; i<num_mol; i++)
{
for (j=0; j<num_mol; j++)
free (label_inter[i][j]);
free (label_inter[i]);
}
free (label_inter);
return 0;
}

87
statgen/stat_sort.c Normal file
View File

@ -0,0 +1,87 @@
/* Library for processing connectivity matrix
*
* Usage:
* proc_matrix (number_of_molecules, connect_matrix,
* num_of_molecules_in_aglomerates, aglomerates, statistic, summary_statistic)
*/
#include <stdio.h>
#include <stdlib.h>
int proc_matrix (int num_mol, const int *connect, int *num_mol_agl, int *agl,
int *stat, int *stat_all)
/* num_mol - number of molecules
* connect - connectivity graph for all molecules
* num_mol_agl - massive of numbers of molecule in aglomerates
* agl - massive of aglomerates
* stat - massive of statistics
* stat_all - massive of summary statistics
*/
{
int i, j, k, p, *bin;
/* p - weight / graph index
* bin - binary massive of labels
*/
// definition and zeroing
bin = (int *) malloc (num_mol * sizeof (int));
if (bin == NULL)
return 1;
for (i=0; i<num_mol; i++)
{
bin[i] = 1;
stat[i] = 0;
num_mol_agl[i] = 0;
for (j=0; j<num_mol; j++)
agl[num_mol*i+j] = 0;
}
// select non-bonded molecules
for (i=0; i<num_mol; i++)
{
p = 0;
for (j=0; j<num_mol; j++)
p += connect[i*num_mol+j];
if (p == 0)
{
bin[i] = 0;
stat[0]++;
stat_all[0]++;
}
}
// unwraping of connectivity matrix
p = 0;
for (i=0; i<num_mol; i++)
if (bin[i] == 1)
{
agl[num_mol*p+num_mol_agl[p]] = i;
num_mol_agl[p]++;
bin[i] = 0;
for (j=0; j<num_mol_agl[p]; j++)
for (k=0; k<num_mol; k++)
if ((connect[agl[num_mol*p+j]*num_mol+k] == 1) && (bin[k] == 1))
{
agl[num_mol*p+num_mol_agl[p]] = k;
num_mol_agl[p]++;
bin[k] = 0;
}
p++;
}
// filling statistic array
i = 0;
while (num_mol_agl[i] > 0)
{
stat[num_mol_agl[i]-1]++;
stat_all[num_mol_agl[i]-1]++;
i++;
}
free (bin);
return 0;
}

64
statgen/summary_stat.c Normal file
View File

@ -0,0 +1,64 @@
/* Library for summary statistic
* Usage:
* summary_statistic (filename, number_of_step, number_of_molecules,
* type_of_aglomerate, summary_statistic)
*/
#include <stdio.h>
#include <stdlib.h>
int summary_statistic (char *filename, int step, int num_mol, const int *type_agl, const int *stat_all)
/* filename - name of output file
* step - number of steps
* num_mol - number of molecules
* type_agl - massive of numbers of aglomerate types
* stat_all - massive of summary statistics
*/
{
float conc, p, pn, type[2], x, y;
int i, index;
FILE *f_out;
/* conc - concentrate of aglomerates
* p - probability of aglomerates
* pn - weight probability of aglomerates
* f_out - output file
*/
index = 0;
for (i=0; i<num_mol; i++)
if (stat_all[i] != 0)
index = i;
// head
f_out = fopen (filename, "a");
fprintf (f_out, "SUMMARY STATISTIC\n");
fprintf (f_out, "| n | N | C | p | pn |\n------------------------------------------------\n");
for (i=0; i<index+1; i++)
{
// calculating concentrates
x = stat_all[i];
y = step;
conc = x / y;
// calculating probabilityes
x = (i + 1) * stat_all[i];
y = step * num_mol;
p = x / y;
pn = (i + 1) * p;
fprintf (f_out, " %7i %7i %9.2f %9.5f %10.5f\n", i+1, stat_all[i], conc, p, pn);
}
// 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);
fclose (f_out);
return 0;
}