mirror of
https://github.com/arcan1s/moldyn.git
synced 2025-07-16 15:20:00 +00:00
start moving to another architecture
This commit is contained in:
21
mathmech/mm/src/CMakeLists.txt
Normal file
21
mathmech/mm/src/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
# set files
|
||||
file (GLOB SOURCES *.c)
|
||||
file (GLOB HEADERS *.h)
|
||||
|
||||
# set library
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (ADDITIONAL_LIB m)
|
||||
else ()
|
||||
set (ADDITIONAL_LIB)
|
||||
endif ()
|
||||
|
||||
# message
|
||||
message (STATUS "${PROJECT} SOURCES: ${SOURCES}")
|
||||
message (STATUS "${PROJECT} HEADERS: ${HEADERS}")
|
||||
|
||||
# link libraries and compile
|
||||
add_library (${PROJECT} SHARED ${SOURCES} ${HEADERS})
|
||||
target_link_libraries (${PROJECT} ${ADDITIONAL_LIB})
|
||||
|
||||
# install properties
|
||||
install (TARGETS ${PROJECT} DESTINATION lib)
|
87
mathmech/mm/src/atom_types.c
Normal file
87
mathmech/mm/src/atom_types.c
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn reading_atoms
|
||||
*/
|
||||
int reading_atoms (const char *input_at, int *num_types, int *num_mol, int *num_atoms,
|
||||
char *ch_atom_types, int *atom_types, const int total_types)
|
||||
/**
|
||||
* @brief function that reads atom types from input file
|
||||
* @code
|
||||
* reading_atoms (input_at, &num_types, num_mol, num_atoms, ch_atom_types, atom_types,
|
||||
* total_types);
|
||||
* @endcode
|
||||
*
|
||||
* @param input_at input file name with atom types
|
||||
* @param num_types number of molecule types
|
||||
* @param num_mol massive of number of molecules of selected type
|
||||
* @param num_atoms massive of number of atoms of selected molecule
|
||||
* @param ch_atom_types massive of char atom types
|
||||
* @param atom_types massive of atom types
|
||||
* @param total_types number of different atom types
|
||||
*
|
||||
* @return 1 - error in opening file
|
||||
* @return 2 - error in file format
|
||||
* @return 3 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
char at_symb[2], tmp_str[256];
|
||||
int at_ndx, i, j, total_atoms;
|
||||
FILE *f_inp;
|
||||
|
||||
/* at_* temp variables
|
||||
* total_atoms total atom types
|
||||
* f_inp input file
|
||||
*/
|
||||
|
||||
f_inp = fopen (input_at, "r");
|
||||
if (f_inp == NULL)
|
||||
return 1;
|
||||
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "NUMTYPES=%i", num_types);
|
||||
if (*num_types == 0)
|
||||
return 2;
|
||||
else if (*num_types > total_types)
|
||||
return 3;
|
||||
|
||||
total_atoms = 0;
|
||||
for (i=0; i<*num_types; i++)
|
||||
{
|
||||
// read constants
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "NUMMOL=%i", &num_mol[i]);
|
||||
if (num_mol[i] == 0)
|
||||
return 2;
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "NUMAT=%i", &num_atoms[i]);
|
||||
if (num_atoms[i] == 0)
|
||||
return 2;
|
||||
else if ((total_atoms + num_atoms[i]) > total_types)
|
||||
return 2;
|
||||
|
||||
// read atoms
|
||||
for (j=0; j<num_atoms[i]; j++)
|
||||
{
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
at_ndx = -1;
|
||||
sscanf (tmp_str, "%2s=%i", at_symb, &at_ndx);
|
||||
if (at_ndx == -1)
|
||||
return 2;
|
||||
ch_atom_types[2*total_atoms+2*j+0] = at_symb[0];
|
||||
ch_atom_types[2*total_atoms+2*j+1] = at_symb[1];
|
||||
atom_types[total_atoms+j] = at_ndx;
|
||||
}
|
||||
total_atoms += num_atoms[i];
|
||||
}
|
||||
|
||||
fclose (f_inp);
|
||||
|
||||
return 0;
|
||||
}
|
354
mathmech/mm/src/coords.c
Normal file
354
mathmech/mm/src/coords.c
Normal file
@ -0,0 +1,354 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* @fn reading_coords
|
||||
*/
|
||||
int reading_coords (const int mode, const char *filename, const 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, char *ch_type_atoms)
|
||||
/**
|
||||
* @brief function that reads coordinates from special file format
|
||||
* @code
|
||||
* reading_coords (0, filename, type_inter, label_atom, cell, &num_mol, &num_atoms,
|
||||
* true_label_mol, label_mol, type_atoms, coords, ch_type_atoms);
|
||||
* @endcode
|
||||
*
|
||||
* @param mode mode of reading; '1' is statgen, '2' is envir or
|
||||
* frad, '3' is agl
|
||||
* @param filename input file name
|
||||
* @param type_inter number of needed atoms
|
||||
* (number of needed molecules)
|
||||
* @param label_atom massive of needed atom types
|
||||
* (massive of needed molecules)
|
||||
* @param cell massive of cell size
|
||||
* @param num_mol number of molecules
|
||||
* @param num_atoms number of atoms
|
||||
* @param true_label_mol massive of true numbers of molecule for atoms
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param type_atoms massive of atom types
|
||||
* @param coords massive of coordinates
|
||||
* @param ch_type_atoms massive of char atom types
|
||||
*
|
||||
* @return 1 - file $filename does not exist
|
||||
* @return 2 - unknown mode
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
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, ref[3];
|
||||
FILE *inp;
|
||||
|
||||
/* cur_* temp variables
|
||||
* at_symb temp variable
|
||||
* file_string temp string variable
|
||||
* atoms total number of atoms in system
|
||||
* tr_num_atoms number of translated atoms (must be 8*num_atoms)
|
||||
* ref_mol number of molecule for reference in translation
|
||||
* not_tr_coords massive of not translated coordinates
|
||||
* ref massive of coordinates of reference molecule
|
||||
* inp input file
|
||||
*/
|
||||
|
||||
/// <b>Work blocks</b>
|
||||
|
||||
*num_atoms = 0;
|
||||
*num_mol = 0;
|
||||
|
||||
/// <pre> reading file </pre>
|
||||
inp = fopen (filename, "r");
|
||||
if (inp == NULL)
|
||||
return 1;
|
||||
|
||||
ref_mol = -1;
|
||||
fscanf (inp, "%i", &atoms);
|
||||
not_tr_coords = (float *) malloc (3 * atoms * sizeof (float));
|
||||
fgets (file_string, 256, inp);
|
||||
for (i=0; i<atoms; i++)
|
||||
{
|
||||
fgets (file_string, 256, inp);
|
||||
sscanf (file_string, "%i%s%f%f%f%i%i", &cur_at_num, at_symb, &cur_coords[0],
|
||||
&cur_coords[1], &cur_coords[2], &cur_at_type, &cur_mol);
|
||||
|
||||
// reading variables according to selected mode
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
// mode == 0 (selected atoms)
|
||||
for (j=0; j<type_inter; j++)
|
||||
if (cur_at_type == label_atom[j])
|
||||
{
|
||||
not_tr_coords[3**num_atoms+0] = cur_coords[0];
|
||||
not_tr_coords[3**num_atoms+1] = cur_coords[1];
|
||||
not_tr_coords[3**num_atoms+2] = cur_coords[2];
|
||||
|
||||
if (ref_mol != cur_mol)
|
||||
{
|
||||
ref_mol = cur_mol;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// mode == 1 (all atoms)
|
||||
not_tr_coords[3**num_atoms+0] = cur_coords[0];
|
||||
not_tr_coords[3**num_atoms+1] = cur_coords[1];
|
||||
not_tr_coords[3**num_atoms+2] = cur_coords[2];
|
||||
ch_type_atoms[2**num_atoms+0] = at_symb[0];
|
||||
ch_type_atoms[2**num_atoms+1] = at_symb[1];
|
||||
|
||||
if (ref_mol != cur_mol)
|
||||
{
|
||||
ref_mol = cur_mol;
|
||||
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;
|
||||
break;
|
||||
case 2:
|
||||
// mode == 2 (selected molecules)
|
||||
for (j=0; j<type_inter; j++)
|
||||
if (cur_mol == label_atom[j])
|
||||
{
|
||||
not_tr_coords[3**num_atoms+0] = cur_coords[0];
|
||||
not_tr_coords[3**num_atoms+1] = cur_coords[1];
|
||||
not_tr_coords[3**num_atoms+2] = cur_coords[2];
|
||||
ch_type_atoms[2**num_atoms+0] = at_symb[0];
|
||||
ch_type_atoms[2**num_atoms+1] = at_symb[1];
|
||||
|
||||
if (ref_mol != cur_mol)
|
||||
{
|
||||
ref_mol = cur_mol;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
default: return 2;
|
||||
}
|
||||
}
|
||||
fclose (inp);
|
||||
|
||||
/// <pre> translation </pre>
|
||||
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[3*0+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++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <pre> free memory </pre>
|
||||
free (not_tr_coords);
|
||||
|
||||
return 0;
|
||||
}
|
51
mathmech/mm/src/envir_search.c
Normal file
51
mathmech/mm/src/envir_search.c
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn search_envir
|
||||
*/
|
||||
int search_envir (const int num_of_mol, const int num_mol, const float *centr_coords,
|
||||
const double rad, int *needed_mol, int *num_needed_mol)
|
||||
/**
|
||||
* @brief function that searchs environment
|
||||
* @code
|
||||
* search_envir (number_of_molecule, num_mol, centr_coords, rad, needed_mol,
|
||||
* &num_needed_mol);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_of_mol number of molecule
|
||||
* @param num_mol number of molecules
|
||||
* @param centr_coords massive of centered coordinates
|
||||
* @param rad radius of environment sphere
|
||||
* @param needed_mol massive of number of needed molecules
|
||||
* @param num_needed_mol number of needed molecules
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
float r;
|
||||
int i;
|
||||
|
||||
/* r radius
|
||||
*/
|
||||
|
||||
*num_needed_mol = 0;
|
||||
|
||||
for (i=0; i<8*num_mol; i++)
|
||||
{
|
||||
r = sqrt (pow ((centr_coords[3*i+0]-centr_coords[3*8*(num_of_mol-1)+0]), 2) +
|
||||
pow ((centr_coords[3*i+1]-centr_coords[3*8*(num_of_mol-1)+1]), 2) +
|
||||
pow ((centr_coords[3*i+2]-centr_coords[3*8*(num_of_mol-1)+2]), 2));
|
||||
if (r < rad)
|
||||
{
|
||||
needed_mol[*num_needed_mol] = i;
|
||||
*num_needed_mol = *num_needed_mol + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
195
mathmech/mm/src/graph.c
Normal file
195
mathmech/mm/src/graph.c
Normal file
@ -0,0 +1,195 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn check_cycle
|
||||
*/
|
||||
int check_cycle (const int N, const int *pn)
|
||||
/**
|
||||
* @brief function that calculates number of cycles in graph
|
||||
* @code
|
||||
* cycle = check_cycle (N, pn);
|
||||
* @endcode
|
||||
*
|
||||
* @param N number of vertexes
|
||||
* @param pn massive of number of vertexes with weight equals to i
|
||||
*
|
||||
* @return number of cycles
|
||||
*/
|
||||
{
|
||||
int cycle, i;
|
||||
|
||||
/* cycle number of cycle
|
||||
*/
|
||||
|
||||
cycle = 0;
|
||||
for (i=1; i<N; i++)
|
||||
cycle += i*pn[i];
|
||||
|
||||
// for linear (0.5*cycle == N-1)
|
||||
cycle = 0.5 * cycle - (N - 1);
|
||||
|
||||
return cycle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn check_cycle_size
|
||||
*/
|
||||
int check_cycle_size (const int N, const int *matrix, const int depth, int *n_cycle)
|
||||
/**
|
||||
* @brief function that returns number of cycles different size
|
||||
* @code
|
||||
* check_cycle_size (N, matrix, depth, n_cycle);
|
||||
* @endcode
|
||||
*
|
||||
* @param N number of vertexes
|
||||
* @param matrix connectivity matrix
|
||||
* @param depth depth of search (maximum number of vertexes in cycle)
|
||||
* @param n_cycle massive of number of cycle with number of vertexes
|
||||
* equals to i
|
||||
*
|
||||
* @return 1 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int cur_N, cycle, i, j, k, n, p, *vertex;
|
||||
|
||||
/* cur_N current number of elements in submatrix
|
||||
* cycle if (cycle == 1) that cycle exist
|
||||
* n number of samples
|
||||
* vertex vertexes of subgraph
|
||||
*/
|
||||
|
||||
vertex = (int *) malloc (N * sizeof (int));
|
||||
if (vertex == NULL)
|
||||
return 1;
|
||||
for (i=0; i<depth-2; i++)
|
||||
n_cycle[i] = 0;
|
||||
|
||||
// matrix generation from
|
||||
// http://wincode.org/acm-icpc/subsets-generation
|
||||
n = pow (2, N);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
cur_N = 0;
|
||||
for (j=0; j<N; j++)
|
||||
if ( i & (1 << j))
|
||||
{
|
||||
vertex[cur_N] = j;
|
||||
cur_N++;
|
||||
}
|
||||
|
||||
if ((cur_N > 2) && (cur_N <= depth))
|
||||
{
|
||||
// copy connectivity matrix
|
||||
cycle = 1;
|
||||
for (j=0; j<cur_N; j++)
|
||||
{
|
||||
p = 0;
|
||||
for (k=0; k<cur_N; k++)
|
||||
p += matrix[vertex[j]*N+vertex[k]];
|
||||
if (p != 2)
|
||||
cycle = 0;
|
||||
}
|
||||
|
||||
// analyze subgraph
|
||||
if (cycle == 1)
|
||||
n_cycle[cur_N-3]++;
|
||||
}
|
||||
}
|
||||
|
||||
free (vertex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn check_tail
|
||||
*/
|
||||
int check_tail (const int *pn)
|
||||
/**
|
||||
* @brief function that calculates number of tails
|
||||
* @code
|
||||
* tails = check_tail (pn);
|
||||
* @endcode
|
||||
*
|
||||
* @param pn massive of number of vertexes with weight equals to i
|
||||
*
|
||||
* @return number of tails
|
||||
*/
|
||||
{
|
||||
return pn[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn graph_analyze
|
||||
*/
|
||||
int graph_analyze (const int N, const int *matrix, const int max_depth, int *iso)
|
||||
/**
|
||||
* @brief function that analyzes graph isomorhic class
|
||||
* @code
|
||||
* graph_analyze (N, matrix, max_depth, iso);
|
||||
* @endcode
|
||||
*
|
||||
* @param N number of vertexes
|
||||
* @param matrix connectivity matrix
|
||||
* @param max_depth maximum depth of search for check_cycle_size
|
||||
* @param iso isomorphism class
|
||||
*
|
||||
* @return 1 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int depth, i, j, *n_cycle, p, *pn;
|
||||
|
||||
/* depth depth of search for check_cycle_size
|
||||
* n_cycle number of cycle
|
||||
* p current weight
|
||||
* pn massive of number of vertexes with weight equals to i
|
||||
*/
|
||||
|
||||
if (max_depth > N)
|
||||
depth = N;
|
||||
else
|
||||
depth = max_depth;
|
||||
// convert to matrix of weight
|
||||
pn = (int *) malloc (N * sizeof (int));
|
||||
n_cycle = (int *) malloc ((depth - 2) * sizeof (int));
|
||||
if ((pn == NULL) ||
|
||||
(n_cycle == NULL))
|
||||
return 1;
|
||||
for (i=0; i<N; i++)
|
||||
pn[i] = 0;
|
||||
for (i=0; i<N; i++)
|
||||
{
|
||||
p = 0;
|
||||
for (j=0; j<N; j++)
|
||||
p += matrix[i*N+j];
|
||||
pn[p]++;
|
||||
}
|
||||
|
||||
iso[0] = check_tail (pn);
|
||||
iso[1] = check_cycle (N, pn);
|
||||
for (i=2; i<max_depth; i++)
|
||||
iso[i] = 0;
|
||||
if (iso[1] > 0)
|
||||
{
|
||||
check_cycle_size (N, matrix, depth, n_cycle);
|
||||
for (i=0; i<depth-2; i++)
|
||||
iso[i+2] = n_cycle[i];
|
||||
}
|
||||
|
||||
// free memory
|
||||
free (n_cycle);
|
||||
free (pn);
|
||||
|
||||
return 0;
|
||||
}
|
103
mathmech/mm/src/main.c
Normal file
103
mathmech/mm/src/main.c
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
/**
|
||||
* @mainpage libmm
|
||||
* @image latex ./logo.png
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* <b>About this program</b>:
|
||||
* <ul>
|
||||
* <li>Library for mathmech
|
||||
* </ul>
|
||||
*
|
||||
* <b>Developer</b>:
|
||||
* <ul>
|
||||
* <li>Evgeniy Alekseev aka arcanis <pre><esalexeev (at) gmail (dot) com></pre>
|
||||
*</ul>
|
||||
* <b>License</b>:
|
||||
* <ul>
|
||||
* <li>GPL
|
||||
* </ul>
|
||||
*
|
||||
* @page Install
|
||||
*
|
||||
* @section Requirements Requirements
|
||||
* The application mmlib requires the following external stuff:
|
||||
* - cmake >= 2.8
|
||||
* - gcc >= 4.8
|
||||
*
|
||||
* @section How-To How to install
|
||||
*
|
||||
* @subsection Linux Linux
|
||||
* @code
|
||||
* mkdir build && cd build
|
||||
* cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../
|
||||
* make
|
||||
* make install
|
||||
* @endcode
|
||||
*
|
||||
* @subsection Windows Windows
|
||||
* @code
|
||||
* create project file using 'cmake'
|
||||
* compile project
|
||||
* @endcode
|
||||
* You may also download compiled executable file for Win_x86.
|
||||
*
|
||||
* @page Changelog
|
||||
* V.1.1.1 (2013-09-03)
|
||||
* <ul>
|
||||
* <li>optimization
|
||||
* </ul>
|
||||
* V.1.1.0 (2013-09-02)
|
||||
* <ul>
|
||||
* <li>added help window
|
||||
* <li>added help docs
|
||||
* <li>small bug fixes
|
||||
* </ul>
|
||||
* V.1.0.3 (2013-08-30)
|
||||
* <ul>
|
||||
* <li>bug fixes
|
||||
* </ul>
|
||||
* V.1.0.1 (2013-07-27)
|
||||
* <ul>
|
||||
* <li>initial release
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mathmech/atom_types.h>
|
||||
#include <mathmech/coords.h>
|
||||
#include <mathmech/envir_search.h>
|
||||
#include <mathmech/graph.h>
|
||||
#include <mathmech/messages.h>
|
||||
#include <mathmech/print_struct.h>
|
||||
#include <mathmech/print_trj.h>
|
||||
#include <mathmech/radf.h>
|
||||
#include <mathmech/radf_proc.h>
|
||||
#include <mathmech/read_agl.h>
|
||||
#include <mathmech/read_gmx.h>
|
||||
#include <mathmech/read_puma.h>
|
||||
#include <mathmech/select_mol.h>
|
||||
#include <mathmech/set_center.h>
|
||||
#include <mathmech/stat_print.h>
|
||||
#include <mathmech/stat_select.h>
|
||||
#include <mathmech/stat_sort.h>
|
||||
#include <mathmech/summary_stat.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn main
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
/**
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
return 0;
|
||||
}
|
119
mathmech/mm/src/messages.c
Normal file
119
mathmech/mm/src/messages.c
Normal file
@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn message
|
||||
*/
|
||||
int message (const int log, const int mode, const char *text, FILE *output)
|
||||
/**
|
||||
* @brief function that prints messages to output
|
||||
* @code
|
||||
* message (log, mode, text, output);
|
||||
* @endcode
|
||||
*
|
||||
* @param log equal to 1 if print to logfile
|
||||
* @param mode number of message
|
||||
* @param text additional text
|
||||
* @param output output file (may be stdout)
|
||||
*
|
||||
* @return 1 - unknown mode
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
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, output);
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
sprintf (out, "Start program: '%s'\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:
|
||||
sprintf (out, "%6cAgglomerate was selected successfully\n", ' ');
|
||||
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, "Print result to file '%s'\n", text);
|
||||
break;
|
||||
case 15:
|
||||
sprintf (out, "Free memory\n");
|
||||
break;
|
||||
case 16:
|
||||
sprintf (out, "Exiting without errors\n");
|
||||
break;
|
||||
case 17:
|
||||
sprintf (out, "Something wrong!\nSee '%s -h' for more details\n", text);
|
||||
break;
|
||||
case 18:
|
||||
sprintf (out, "File '%s' not found\nError\n", text);
|
||||
break;
|
||||
case 19:
|
||||
sprintf (out, "Memory error\n");
|
||||
break;
|
||||
case 20:
|
||||
sprintf (out, "%6cCenter of molecules was set successfully\n", ' ');
|
||||
break;
|
||||
case 21:
|
||||
sprintf (out, "%6cEnvironment was selected successfully\n", ' ');
|
||||
break;
|
||||
case 22:
|
||||
sprintf (out, "%6cRADF was appended successfully\n", ' ');
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
fputs (out, output);
|
||||
return 0;
|
||||
}
|
69
mathmech/mm/src/print_struct.c
Normal file
69
mathmech/mm/src/print_struct.c
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn print_structure
|
||||
*/
|
||||
int print_structure (const char *output, const int num_needed_mol, const int *needed_mol,
|
||||
const int num_atoms, const int *label_mol, const char *ch_type_atoms,
|
||||
const float *coords)
|
||||
/**
|
||||
* @brief function that prints structure to pdb file
|
||||
* @code
|
||||
* print_structure (output, num_needed_mol, needed_mol, num_atoms, label_mol,
|
||||
* char_type_atoms, coords);
|
||||
* @endcode
|
||||
*
|
||||
* @param output output file name
|
||||
* @param num_needed_mol number of needed molecules
|
||||
* @param needed_mol massive of number of needed molecules
|
||||
* @param num_atoms number of atoms
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param ch_type_atoms massive of char atom types
|
||||
* @param coords massive of coordinates
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int cur_atom, cur_atom_num, cur_mol, i, j;
|
||||
FILE *f_out;
|
||||
|
||||
/* cur_atom current atom
|
||||
* cur_atom_num true atom number
|
||||
* cur_mol current molecule
|
||||
* f_out output file
|
||||
*/
|
||||
|
||||
cur_atom = 1;
|
||||
f_out = fopen (output, "w");
|
||||
|
||||
for (i=0; i<num_needed_mol; i++)
|
||||
for (j=0; j<8*num_atoms; j++)
|
||||
{
|
||||
if (j < num_atoms)
|
||||
{
|
||||
cur_mol = 0;
|
||||
cur_atom_num = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_mol = ((j - num_atoms) % 7) + 1;
|
||||
cur_atom_num = (j - num_atoms) / 7;
|
||||
}
|
||||
if (needed_mol[i] == (8*label_mol[j]+cur_mol))
|
||||
{
|
||||
fprintf(f_out, "ATOM %5i %c%c MOL %4i %8.3f%8.3f%8.3f\n", cur_atom,
|
||||
ch_type_atoms[2*cur_atom_num+0], ch_type_atoms[2*cur_atom_num+1],
|
||||
i+1, coords[3*j+0], coords[3*j+1], coords[3*j+2]);
|
||||
cur_atom++;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f_out);
|
||||
|
||||
return 0;
|
||||
}
|
71
mathmech/mm/src/print_trj.c
Normal file
71
mathmech/mm/src/print_trj.c
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn printing_trj
|
||||
*/
|
||||
int printing_trj (const char *filename, const int atoms, const int num_types, const int *num_mol,
|
||||
const int *num_atoms, const char *ch_atom_types, const int *atom_types,
|
||||
const float *coords)
|
||||
/**
|
||||
* @brief function that prints trajectory snapshots
|
||||
* @code
|
||||
* printing_trj (filename, atoms, num_types, num_mol, num_atoms, ch_atom_types,
|
||||
* atom_types, coords);
|
||||
* @endcode
|
||||
*
|
||||
* @param filename output file name
|
||||
* @param atoms number of atoms in system
|
||||
* @param num_types number of molecule types
|
||||
* @param num_mol massive of number of molecule of selected type
|
||||
* @param num_atoms massive of number of atoms of selected molecule
|
||||
* @param ch_atom_types massive of char atom types
|
||||
* @param atom_types massive of atom types
|
||||
* @param coords massive of coordinates
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int cur_mol, cur_type[2], i, j, k, l;
|
||||
FILE *f_out;
|
||||
|
||||
/* cur_mol number of current molecule
|
||||
* cur_type number of current atom type
|
||||
* f_out output file
|
||||
*/
|
||||
|
||||
cur_mol = 1;
|
||||
f_out = fopen (filename, "w");
|
||||
fprintf (f_out, " %6i\n", atoms);
|
||||
|
||||
i = 0;
|
||||
while (i < atoms)
|
||||
{
|
||||
cur_type[0] = 0;
|
||||
for (j=0; j<num_types; j++)
|
||||
{
|
||||
for (k=0; k<num_mol[j]; k++)
|
||||
{
|
||||
cur_type[1] = cur_type[0];
|
||||
for (l=0; l<num_atoms[j]; l++)
|
||||
{
|
||||
fprintf (f_out, "%5i %c%c %12.6f%12.6f%12.6f %2i %4i\n", i+1,
|
||||
ch_atom_types[2*cur_type[1]+0], ch_atom_types[2*cur_type[1]+1], coords[3*i+0],
|
||||
coords[3*i+1], coords[3*i+2], atom_types[cur_type[1]], cur_mol);
|
||||
cur_type[1]++;
|
||||
i++;
|
||||
}
|
||||
cur_mol++;
|
||||
}
|
||||
cur_type[0] += num_atoms[j];
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f_out);
|
||||
|
||||
return 0;
|
||||
}
|
302
mathmech/mm/src/radf.c
Normal file
302
mathmech/mm/src/radf.c
Normal file
@ -0,0 +1,302 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// pi
|
||||
#if !defined __USE_BSD && !defined __USE_XOPEN
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif /* __USE_BSD && __USE_XOPEN */
|
||||
#endif /* M_PI */
|
||||
|
||||
|
||||
/**
|
||||
* @fn search_rdf
|
||||
*/
|
||||
int search_rdf (const int num_atoms, const int *type_atoms, const int *label_mol,
|
||||
const float *coords, const double r_min, const double r_max,
|
||||
const double r_step, int *radf)
|
||||
/**
|
||||
* @brief function that searchs molecule for rdf massive
|
||||
* @code
|
||||
* search_rdf (num_atoms, type_atoms, label_mol, coords, r_min, r_max, r_step, radf);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_atoms number of atoms
|
||||
* @param type_atoms massive of atom types
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param coords massive of coordinates
|
||||
* @param r_min minimal radius
|
||||
* @param r_max maximal radius
|
||||
* @param r_step radius step
|
||||
* @param radf not normed RDF
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
float r;
|
||||
int i, j, k;
|
||||
|
||||
/* r radius
|
||||
*/
|
||||
|
||||
for (i=0; i<num_atoms; i++)
|
||||
for (j=0; j<8*num_atoms; j++)
|
||||
if (((type_atoms[i] == 0) && (type_atoms[j] == 1)) ||
|
||||
((type_atoms[i] == 1) && (type_atoms[j] == 0)))
|
||||
{
|
||||
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));
|
||||
|
||||
if ((r >= r_min) && (r <= r_max))
|
||||
{
|
||||
k = (r - r_min) / r_step;
|
||||
radf[k]++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn search_rdf_centr
|
||||
*/
|
||||
int search_rdf_centr (const int num_atoms, const int *type_atoms, const int *label_mol,
|
||||
const float *coords, const double r_min, const double r_max,
|
||||
const double r_step, int *radf)
|
||||
/**
|
||||
* @brief function that searchs molecule for rdf massive by centered coordinates
|
||||
* @code
|
||||
* search_rdf_centr (num_atoms, type_atoms, label_mol, coords, r_min, r_max, r_step,
|
||||
* radf);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_atoms number of atoms
|
||||
* @param type_atoms massive of atom types
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param coords massive of coordinates
|
||||
* @param r_min minimal radius
|
||||
* @param r_max maximal radius
|
||||
* @param r_step radius step
|
||||
* @param radf not normed RDF
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
* @return 1 - error in set center (missing atoms)
|
||||
*/
|
||||
{
|
||||
float r, cur_coords[2][3];
|
||||
int coef, cur_at, i, j, k, l;
|
||||
|
||||
/* cur_coords centered coordinates
|
||||
* r radius
|
||||
* coef ==1 if j<num_atoms, ==7 if j>=num_atoms
|
||||
* cur_at number of founded atoms
|
||||
*/
|
||||
|
||||
for (i=0; i<num_atoms; i++)
|
||||
if ((type_atoms[i] == 0) || (type_atoms[i] == 3))
|
||||
for (j=0; j<8*num_atoms; j++)
|
||||
if (((type_atoms[i] == 0) && (type_atoms[j] == 3)) ||
|
||||
((type_atoms[i] == 3) && (type_atoms[j] == 0)))
|
||||
{
|
||||
// set center for i-molecule
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] = coords[3*i+l];
|
||||
cur_at = 1;
|
||||
for (k=1; k<6; k++)
|
||||
if (label_mol[i+k] == label_mol[i])
|
||||
if ((type_atoms[i+k] == type_atoms[i] + 1) ||
|
||||
(type_atoms[i+k] == type_atoms[i] + 2))
|
||||
{
|
||||
cur_at++;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] += coords[3*(i+k)+l];
|
||||
}
|
||||
if (cur_at == 3)
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] = cur_coords[0][l] / cur_at;
|
||||
else
|
||||
return 1;
|
||||
// set center for j-molecule
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] = coords[3*j+l];
|
||||
cur_at = 1;
|
||||
if (j < num_atoms)
|
||||
coef = 1;
|
||||
else
|
||||
coef = 7;
|
||||
for (k=1; k<6; k++)
|
||||
if (label_mol[j+coef*k] == label_mol[j])
|
||||
if ((type_atoms[j+coef*k] == type_atoms[j] + 1) ||
|
||||
(type_atoms[j+coef*k] == type_atoms[j] + 2))
|
||||
{
|
||||
cur_at++;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] += coords[3*(j+coef*k)+l];
|
||||
}
|
||||
if (cur_at == 3)
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] = cur_coords[1][l] / cur_at;
|
||||
else
|
||||
return 1;
|
||||
|
||||
r = sqrt (pow ((cur_coords[0][0] - cur_coords[1][0]), 2) +
|
||||
pow ((cur_coords[0][1] - cur_coords[1][1]), 2) +
|
||||
pow ((cur_coords[0][2] - cur_coords[1][2]), 2));
|
||||
|
||||
if ((r >= r_min) && (r <= r_max))
|
||||
{
|
||||
k = (r - r_min) / r_step;
|
||||
radf[k]++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn search_radf
|
||||
*/
|
||||
int search_radf (const int num_atoms, const int *type_atoms, const int *label_mol,
|
||||
const float *coords, const double r_min, const double r_max,
|
||||
const double r_step, const double ang_min, const double ang_max,
|
||||
const double ang_step, int *radf)
|
||||
/**
|
||||
* @brief function that searchs molecule for radf massive
|
||||
* @code
|
||||
* search_radf (num_atoms, type_atoms, label_mol, coords, r_min, r_max, r_step,
|
||||
* ang_min, ang_max, ang_step, radf);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_atoms number of atoms
|
||||
* @param type_atoms massive of atom types
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param coords massive of coordinates
|
||||
* @param r_min minimal radius
|
||||
* @param r_max maximal radius
|
||||
* @param r_step radius step
|
||||
* @param ang_min minimal angle
|
||||
* @param ang_max maximal angle
|
||||
* @param ang_step anlge step
|
||||
* @param radf not normed RADF
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
* @return 1 - error in set center (missing atoms)
|
||||
*/
|
||||
{
|
||||
float ang, cos_ang, cur_coords[2][3], normal[2][3], r;
|
||||
int coef, cur_at, i, j, k, l, n, n_max, plane_index[6];
|
||||
|
||||
/* ang angle
|
||||
* cur_coords centered coordinates
|
||||
* normal normal to planes
|
||||
* r radius
|
||||
* coef ==1 if j<num_atoms, ==7 if j>=num_atoms
|
||||
* cur_at number of founded atoms
|
||||
* n_max range of angles
|
||||
* plane_index atoms forming plane
|
||||
*/
|
||||
|
||||
for (i=0; i<num_atoms; i++)
|
||||
if ((type_atoms[i] == 0) || (type_atoms[i] == 3))
|
||||
for (j=0; j<8*num_atoms; j++)
|
||||
if (((type_atoms[i] == 0) && (type_atoms[j] == 3)) ||
|
||||
((type_atoms[i] == 3) && (type_atoms[j] == 0)))
|
||||
{
|
||||
// set center for i-molecule
|
||||
plane_index[type_atoms[i]] = i;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] = coords[3*i+l];
|
||||
cur_at = 1;
|
||||
for (k=1; k<6; k++)
|
||||
if (label_mol[i+k] == label_mol[i])
|
||||
if ((type_atoms[i+k] == type_atoms[i] + 1) ||
|
||||
(type_atoms[i+k] == type_atoms[i] + 2))
|
||||
{
|
||||
cur_at++;
|
||||
plane_index[type_atoms[i+k]] = i + k;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] += coords[3*(i+k)+l];
|
||||
}
|
||||
if (cur_at == 3)
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[0][l] = cur_coords[0][l] / cur_at;
|
||||
else
|
||||
return 1;
|
||||
// set center for j-molecule
|
||||
plane_index[type_atoms[j]] = j;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] = coords[3*j+l];
|
||||
cur_at = 1;
|
||||
if (j < num_atoms)
|
||||
coef = 1;
|
||||
else
|
||||
coef = 7;
|
||||
for (k=1; k<6; k++)
|
||||
if (label_mol[j+coef*k] == label_mol[j])
|
||||
if ((type_atoms[j+coef*k] == type_atoms[j] + 1) ||
|
||||
(type_atoms[j+coef*k] == type_atoms[j] + 2))
|
||||
{
|
||||
cur_at++;
|
||||
plane_index[type_atoms[j+coef*k]] = j + coef * k;
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] += coords[3*(j+coef*k)+l];
|
||||
}
|
||||
if (cur_at == 3)
|
||||
for (l=0; l<3; l++)
|
||||
cur_coords[1][l] = cur_coords[1][l] / cur_at;
|
||||
else
|
||||
return 1;
|
||||
|
||||
r = sqrt (pow ((cur_coords[0][0] - cur_coords[1][0]), 2) +
|
||||
pow ((cur_coords[0][1] - cur_coords[1][1]), 2) +
|
||||
pow ((cur_coords[0][2] - cur_coords[1][2]), 2));
|
||||
// define planes
|
||||
normal[0][0] = (coords[3*plane_index[1]+1] - coords[3*plane_index[0]+1]) *
|
||||
(coords[3*plane_index[2]+2] - coords[3*plane_index[0]+2]) -
|
||||
(coords[3*plane_index[1]+2] - coords[3*plane_index[0]+2]) *
|
||||
(coords[3*plane_index[2]+1] - coords[3*plane_index[0]+1]);
|
||||
normal[0][1] = (coords[3*plane_index[1]+2] - coords[3*plane_index[0]+2]) *
|
||||
(coords[3*plane_index[2]+0] - coords[3*plane_index[0]+0]) -
|
||||
(coords[3*plane_index[1]+0] - coords[3*plane_index[0]+0]) *
|
||||
(coords[3*plane_index[2]+2] - coords[3*plane_index[0]+2]);
|
||||
normal[0][2] = (coords[3*plane_index[1]+0] - coords[3*plane_index[0]+0]) *
|
||||
(coords[3*plane_index[2]+1] - coords[3*plane_index[0]+1]) -
|
||||
(coords[3*plane_index[1]+1] - coords[3*plane_index[0]+1]) *
|
||||
(coords[3*plane_index[2]+0] - coords[3*plane_index[0]+0]);
|
||||
normal[1][0] = (coords[3*plane_index[4]+1] - coords[3*plane_index[3]+1]) *
|
||||
(coords[3*plane_index[5]+2] - coords[3*plane_index[3]+2]) -
|
||||
(coords[3*plane_index[4]+2] - coords[3*plane_index[3]+2]) *
|
||||
(coords[3*plane_index[5]+1] - coords[3*plane_index[3]+1]);
|
||||
normal[1][1] = (coords[3*plane_index[4]+2] - coords[3*plane_index[3]+2]) *
|
||||
(coords[3*plane_index[5]+0] - coords[3*plane_index[3]+0]) -
|
||||
(coords[3*plane_index[4]+0] - coords[3*plane_index[3]+0]) *
|
||||
(coords[3*plane_index[5]+2] - coords[3*plane_index[3]+2]);
|
||||
normal[1][2] = (coords[3*plane_index[4]+0] - coords[3*plane_index[3]+0]) *
|
||||
(coords[3*plane_index[5]+1] - coords[3*plane_index[3]+1]) -
|
||||
(coords[3*plane_index[4]+1] - coords[3*plane_index[3]+1]) *
|
||||
(coords[3*plane_index[5]+0] - coords[3*plane_index[3]+0]);
|
||||
cos_ang = (normal[0][0] * normal[1][0] + normal[0][1] * normal[1][1] + normal[0][2] * normal[1][2]) /
|
||||
(sqrt (pow ((normal[0][0]), 2) + pow ((normal[0][1]), 2) + pow ((normal[0][2]), 2)) *
|
||||
sqrt (pow ((normal[1][0]), 2) + pow ((normal[1][1]), 2) + pow ((normal[1][2]), 2)));
|
||||
ang = 180 / M_PI * acos (cos_ang);
|
||||
if (ang > 90)
|
||||
ang = 180 - ang;
|
||||
|
||||
n_max = (ang_max - ang_min) / ang_step;
|
||||
if ((r >= r_min) && (r <= r_max))
|
||||
if ((ang >= ang_min) && (ang <= ang_max))
|
||||
{
|
||||
k = (r - r_min) / r_step;
|
||||
n = (ang - ang_min) / ang_step;
|
||||
radf[n_max*k+n]++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
137
mathmech/mm/src/radf_proc.c
Normal file
137
mathmech/mm/src/radf_proc.c
Normal file
@ -0,0 +1,137 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// pi
|
||||
#if !defined __USE_BSD && !defined __USE_XOPEN
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif /* __USE_BSD && __USE_XOPEN */
|
||||
#endif /* M_PI */
|
||||
|
||||
|
||||
/**
|
||||
* @fn print_result
|
||||
*/
|
||||
int print_result (const char *output, const int matrix, const int mode,
|
||||
const int step, const int num_atoms, const double r_min,
|
||||
const double r_max, const double r_step, const double ang_min,
|
||||
const double ang_max, const double ang_step, const float *cell,
|
||||
const int *radf)
|
||||
/**
|
||||
* @brief function that print result to output file
|
||||
* @code
|
||||
* print_result (output, matrix, mode, step, num_atoms, r_min, r_max, r_step, ang_min,
|
||||
* ang_max, ang_step, cell, radf);
|
||||
* @endcode
|
||||
*
|
||||
* @param output output file name
|
||||
* @param matrix status of matrix-mode
|
||||
* @param mode 1 - if RDF, 2 - if RDF for center mass, 3 - if RADF
|
||||
* @param step $(to - from + 1)
|
||||
* @param num_atoms number of atoms
|
||||
* @param r_min minimal radius
|
||||
* @param r_max maximal radius
|
||||
* @param r_step radius step
|
||||
* @param ang_min minimal angle
|
||||
* @param ang_max maximal angle
|
||||
* @param ang_step angle step
|
||||
* @param cell cell size
|
||||
* @param radf not normed RADF
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
float ang, dv, norm, r, ro;
|
||||
int i, j, k, n;
|
||||
FILE *f_out;
|
||||
|
||||
/* ang angle
|
||||
* dv volume
|
||||
* norm normed RDF
|
||||
* r radius
|
||||
* ro density
|
||||
* f_out output file
|
||||
*/
|
||||
|
||||
f_out = fopen (output, "a");
|
||||
fprintf (f_out, "SUMMARY STATISTIC\n");
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, "| r | dV | RDF | RDFnorm |\n------------------------------------------\n");
|
||||
k = (r_max - r_min) / r_step;
|
||||
for (i=0; i<k; i++)
|
||||
{
|
||||
r = r_min + (0.5 + i) * r_step;
|
||||
dv = 4 * M_PI * pow (r, 2) * r_step;
|
||||
ro = num_atoms / (2 * cell[0] * cell[1] * cell[2]);
|
||||
norm = radf[i] / (dv * ro * num_atoms * step);
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, " %9.4f %10.4e %9i %9.6f \n", r, dv, radf[i] / 2, norm);
|
||||
else
|
||||
fprintf (f_out, " %9.4f %9.6f\n", r, norm);
|
||||
}
|
||||
fprintf (f_out, "------------------------------------------\n");
|
||||
break;
|
||||
case 1:
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, "| r | dV | RDF | RDFnorm |\n------------------------------------------\n");
|
||||
k = (r_max - r_min) / r_step;
|
||||
for (i=0; i<k; i++)
|
||||
{
|
||||
r = r_min + (0.5 + i) * r_step;
|
||||
dv = 4 * M_PI * pow (r, 2) * r_step;
|
||||
ro = num_atoms / (3 * 2 * cell[0] * cell[1] * cell[2]);
|
||||
norm = radf[i] / (dv * ro * num_atoms / 3 * step);
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, " %9.4f %10.4e %9i %9.6f \n", r, dv, radf[i] / 2, norm);
|
||||
else
|
||||
fprintf (f_out, " %9.4f %9.6f\n", r, norm);
|
||||
}
|
||||
fprintf (f_out, "------------------------------------------\n");
|
||||
break;
|
||||
case 2:
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, "| r | ang | dV | RDF | RDFnorm |\n----------------------------------------------------\n");
|
||||
k = (r_max - r_min) / r_step;
|
||||
n = (ang_max - ang_min) / ang_step;
|
||||
if (matrix == 1)
|
||||
{
|
||||
fprintf (f_out, " r\\ang ");
|
||||
for (j=0; j<n; j++)
|
||||
fprintf (f_out, " %9.2f", ang_min+(0.5+j)*ang_step);
|
||||
fprintf (f_out, "\n");
|
||||
}
|
||||
for (i=0; i<k; i++)
|
||||
{
|
||||
if (matrix == 1)
|
||||
fprintf (f_out, " %9.4f", r);
|
||||
for (j=0; j<n; j++)
|
||||
{
|
||||
r = r_min + (0.5 + i) * r_step;
|
||||
ang = ang_min + (0.5 + j) * ang_step;
|
||||
dv = 4 * M_PI * pow (r, 2) * sin (M_PI * ang / 180) * r_step * (M_PI * ang_step / 180);
|
||||
ro = num_atoms / (3 * 2 * cell[0] * cell[1] * cell[2]);
|
||||
norm = radf[n*i+j] / (dv * ro * num_atoms / 3 * step);
|
||||
if (matrix == 0)
|
||||
fprintf (f_out, " %9.4f %9.2f %10.4e %9i %9.6f \n", r, ang, dv, radf[n*i+j] / 2, norm);
|
||||
else
|
||||
fprintf (f_out, " %9.6f", norm);
|
||||
}
|
||||
if (matrix == 1)
|
||||
fprintf (f_out, "\n");
|
||||
}
|
||||
fprintf (f_out, "----------------------------------------------------\n");
|
||||
break;
|
||||
}
|
||||
|
||||
fclose (f_out);
|
||||
|
||||
return 0;
|
||||
}
|
51
mathmech/mm/src/read_agl.c
Normal file
51
mathmech/mm/src/read_agl.c
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
/* Library for reading agglomerate from statgen-file
|
||||
*
|
||||
* Usage:
|
||||
* reading_agl (aglinput, &num_needed_mol, agl_class, needed_mol)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn reading_agl
|
||||
*/
|
||||
int reading_agl (const char *aglinp, int *num_needed_mol, char *agl_class, int *needed_mol)
|
||||
/**
|
||||
* @brief function that reads agglomerate from statgen-formated file
|
||||
* @code
|
||||
* reading_agl (aglinput, &num_needed_mol, agl_class, needed_mol);
|
||||
* @endcode
|
||||
*
|
||||
* @param aglinp agglomerate file name
|
||||
* @param num_needed_mol number of needed molecules
|
||||
* @param agl_class agglomerate class
|
||||
* @param needed_mol massive of numbed of needed molecules
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
char connect[256], tmp_str[256];
|
||||
int i;
|
||||
FILE *f_agl;
|
||||
|
||||
/* connect - connectivity matrix for molecule
|
||||
* f_agl - agglomerate file
|
||||
*/
|
||||
|
||||
f_agl = fopen (aglinp, "r");
|
||||
|
||||
fgets (tmp_str, 256, f_agl);
|
||||
sscanf (tmp_str, "AGL=%i=%s", num_needed_mol, agl_class);
|
||||
for (i=0; i<*num_needed_mol; i++)
|
||||
{
|
||||
fgets (tmp_str, 256, f_agl);
|
||||
sscanf (tmp_str, "%i=%s", &needed_mol[i], connect);
|
||||
}
|
||||
fclose (f_agl);
|
||||
|
||||
return 0;
|
||||
}
|
154
mathmech/mm/src/read_gmx.c
Normal file
154
mathmech/mm/src/read_gmx.c
Normal file
@ -0,0 +1,154 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mathmech/print_trj.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn translate_coords
|
||||
*/
|
||||
int translate_coords (const float coords, const float cell, float *trans)
|
||||
/**
|
||||
* @brief funtion that translates coordinate
|
||||
* @code
|
||||
* translate_coords (coords[3*i+j], cell[j], trans);
|
||||
* @endcode
|
||||
*
|
||||
* @param coords coordinate
|
||||
* @param cell cell size
|
||||
* @param trans massive of translated coordinates
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
trans[0] = coords;
|
||||
trans[1] = coords - cell;
|
||||
trans[2] = coords + cell;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn rw_gmx
|
||||
*/
|
||||
int rw_gmx (const char *input, const int step, const char *output, const int num_types,
|
||||
const int *num_mol, const int *num_atoms, const char *ch_atom_types,
|
||||
const int *atom_types, float *coords)
|
||||
/**
|
||||
* @brief function that read GROMACS trajectory file and write to output
|
||||
* @code
|
||||
* rw_gmx (input, step, output, num_types, num_mol, num_atoms, ch_atom_types,
|
||||
* atom_types, coords);
|
||||
* @endcode
|
||||
*
|
||||
* @param input input file name
|
||||
* @param step number of trajectory steps
|
||||
* @param output mask of output files
|
||||
* @param num_types number of molecule types
|
||||
* @param num_mol massive of number of molecule of selected type
|
||||
* @param num_atoms massive of number of atoms of selected molecule
|
||||
* @param ch_atom_types massive of char atom types
|
||||
* @param atom_types massive of atom types
|
||||
* @param coords massive of coordinates
|
||||
*
|
||||
* @return 1 - file does not exist
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
char filename[256], tmp_str[256];
|
||||
float cell[3], trans[3], r_min;
|
||||
int atoms, i, j, k, l, m, n;
|
||||
FILE *f_inp;
|
||||
|
||||
/* filename output file name
|
||||
* cell cell size
|
||||
* trans translated coordinates
|
||||
* r_min minimal radius
|
||||
* atom number of atoms
|
||||
* f_inp input file
|
||||
*/
|
||||
|
||||
f_inp = fopen (input, "r");
|
||||
if (f_inp == NULL)
|
||||
return 1;
|
||||
|
||||
for (i=0; i<step; i++)
|
||||
{
|
||||
// initial variables
|
||||
sprintf (filename, "%s.%03i", output, i+1);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, " natoms=%i%s", &atoms, tmp_str);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, " box[ 0]={%f%s", &cell[0], tmp_str);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, " box[ 1]={%f,%f%s", &cell[1], &cell[1], tmp_str);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, " box[ 2]={%f,%f,%f%s", &cell[2], &cell[2], &cell[2], tmp_str);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
for (j=0; j<3; j++)
|
||||
cell[j] = 10 * cell[j];
|
||||
// coordinates
|
||||
for (j=0; j<atoms; j++)
|
||||
{
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, " x[%i]={%f,%f,%f%s", &k, &coords[3*j+0], &coords[3*j+1],
|
||||
&coords[3*j+2], tmp_str);
|
||||
for (k=0; k<3; k++)
|
||||
coords[3*j+k] = 10 * coords[3*j+k];
|
||||
}
|
||||
// velocities
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
for (j=0; j<atoms; j++)
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
|
||||
// processing coordinates
|
||||
j = 0;
|
||||
while (j < atoms)
|
||||
for (k=0; k<num_types; k++)
|
||||
for (l=0; l<num_mol[k]; l++)
|
||||
{
|
||||
for (m=1; m<num_atoms[k]; m++)
|
||||
for (n=0; n<3; n++)
|
||||
{
|
||||
r_min = fabs (coords[3*(j+m)+n] - coords[3*j+n]);
|
||||
translate_coords (coords[3*(j+m)+n], cell[n], trans);
|
||||
if (fabs (trans[1] - coords[3*j+n]) < r_min)
|
||||
coords[3*(j+m)+n] = trans[1];
|
||||
if (fabs (trans[2] - coords[3*j+n]) < r_min)
|
||||
coords[3*(j+m)+n] = trans[2];
|
||||
}
|
||||
j += num_atoms[k];
|
||||
}
|
||||
j = 0;
|
||||
while (j < atoms)
|
||||
for (k=0; k<num_types; k++)
|
||||
for (l=0; l<num_mol[k]; l++)
|
||||
{
|
||||
for (m=0; m<3; m++)
|
||||
{
|
||||
while (coords[3*j+m] > cell[m]/2)
|
||||
for (n=j; n<j+num_atoms[k]; n++)
|
||||
coords[3*n+m] -= cell[m];
|
||||
while (coords[3*j+m] < -cell[m]/2)
|
||||
for (n=j; n<j+num_atoms[k]; n++)
|
||||
coords[3*n+m] += cell[m];
|
||||
}
|
||||
j += num_atoms[k];
|
||||
}
|
||||
|
||||
// write to output
|
||||
printing_trj (filename, atoms, num_types, num_mol, num_atoms, ch_atom_types,
|
||||
atom_types, coords);
|
||||
}
|
||||
|
||||
fclose (f_inp);
|
||||
|
||||
return 0;
|
||||
}
|
94
mathmech/mm/src/read_puma.c
Normal file
94
mathmech/mm/src/read_puma.c
Normal file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mathmech/print_trj.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn rw_puma
|
||||
*/
|
||||
int rw_puma (const char *input, const int step, const char *output, const int num_types,
|
||||
const int *num_mol, const int *num_atoms, const char *ch_atom_types,
|
||||
const int *atom_types, float *coords)
|
||||
/**
|
||||
* @brief function that read PUMA trajectory file and write to output
|
||||
* @code
|
||||
* rw_puma (input, step, output, num_types, num_mol, num_atoms, ch_atom_types,
|
||||
* atom_types, coords);
|
||||
* @endcode
|
||||
*
|
||||
* @param input input file name
|
||||
* @param step number of trajectory steps
|
||||
* @param output mask of output files
|
||||
* @param num_types number of molecule types
|
||||
* @param num_mol massive of number of molecule of selected type
|
||||
* @param num_atoms massive of number of atoms of selected molecule
|
||||
* @param ch_atom_types massive of char atom types
|
||||
* @param atom_types massive of atom types
|
||||
* @param coords massive of coordinates
|
||||
*
|
||||
* @return 1 - file does not exist
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
char filename[256], tmp_str[256];
|
||||
float cell[3];
|
||||
int atoms, i, j, k, l, m, n;
|
||||
FILE *f_inp;
|
||||
|
||||
/* filename output file name
|
||||
* cell cell size
|
||||
* atom number of atoms
|
||||
* f_inp input file
|
||||
*/
|
||||
|
||||
f_inp = fopen (input, "r");
|
||||
if (f_inp == NULL)
|
||||
return 1;
|
||||
|
||||
for (i=0; i<step; i++)
|
||||
{
|
||||
// initial variables
|
||||
sprintf (filename, "%s.%03i", output, i+1);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "%s%s%i%s", tmp_str, tmp_str, &atoms, tmp_str);
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "%f%f%f", &cell[0], &cell[1], &cell[2]);
|
||||
// coordinates
|
||||
for (j=0; j<atoms; j++)
|
||||
{
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
sscanf (tmp_str, "%f%f%f", &coords[3*j+0], &coords[3*j+1], &coords[3*j+2]);
|
||||
}
|
||||
fgets (tmp_str, 256, f_inp);
|
||||
|
||||
// processing coordinates
|
||||
j = 0;
|
||||
while (j < atoms)
|
||||
for (k=0; k<num_types; k++)
|
||||
for (l=0; l<num_mol[k]; l++)
|
||||
{
|
||||
for (m=0; m<3; m++)
|
||||
{
|
||||
while (coords[3*j+m] > cell[m]/2)
|
||||
for (n=j; n<j+num_atoms[k]; n++)
|
||||
coords[3*n+m] -= cell[m];
|
||||
while (coords[3*j+m] < -cell[m]/2)
|
||||
for (n=j; n<j+num_atoms[k]; n++)
|
||||
coords[3*n+m] += cell[m];
|
||||
}
|
||||
j += num_atoms[k];
|
||||
}
|
||||
|
||||
// write to output
|
||||
printing_trj (filename, atoms, num_types, num_mol, num_atoms, ch_atom_types,
|
||||
atom_types, coords);
|
||||
}
|
||||
|
||||
fclose (f_inp);
|
||||
|
||||
return 0;
|
||||
}
|
69
mathmech/mm/src/select_mol.c
Normal file
69
mathmech/mm/src/select_mol.c
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn select_molecule
|
||||
*/
|
||||
int select_molecule (const float *centr_coords, const int num_needed_mol, int *needed_mol)
|
||||
/**
|
||||
* @brief function that selects molecules from array of translated molecules
|
||||
* @code
|
||||
* select_molecule (centr_coords, num_needed_mol, needed_mol);
|
||||
* @endcode
|
||||
*
|
||||
* @param centr_coords massive of centered coordinates
|
||||
* @param num_needed_mol number of needed molecules
|
||||
* @param needed_mol massive of number of needed molecules
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
float r, ref[3], rmin;
|
||||
int i, j, jmin;
|
||||
|
||||
/* r radius
|
||||
* ref coordinated of center mass
|
||||
* rmin minimal radius
|
||||
* jmin index of the nearest molecule
|
||||
*/
|
||||
|
||||
// set first molecule
|
||||
needed_mol[0] = 0;
|
||||
for (i=0; i<3; i++)
|
||||
ref[i] = centr_coords[3*8*0+0+i];
|
||||
|
||||
// work block
|
||||
for (i=1; i<num_needed_mol; i++)
|
||||
{
|
||||
rmin = sqrt (pow ((centr_coords[3*8*i+0+0] - ref[0]), 2) + \
|
||||
pow ((centr_coords[3*8*i+0+1] - ref[1]), 2) + \
|
||||
pow ((centr_coords[3*8*i+0+2] - ref[2]), 2));
|
||||
jmin = 0;
|
||||
for (j=1; j<8; j++)
|
||||
{
|
||||
r = sqrt (pow ((centr_coords[3*8*i+j+0] - ref[0]), 2) + \
|
||||
pow ((centr_coords[3*8*i+j+1] - ref[1]), 2) + \
|
||||
pow ((centr_coords[3*8*i+j+2] - ref[2]), 2));
|
||||
if (r < rmin)
|
||||
{
|
||||
rmin = r;
|
||||
jmin = j;
|
||||
}
|
||||
}
|
||||
|
||||
// add molecule
|
||||
needed_mol[i] = 8 * i + jmin;
|
||||
// update ref
|
||||
for (j=0; j<3; j++)
|
||||
{
|
||||
ref[j] += centr_coords[3*8*i+jmin+j];
|
||||
ref[j] = ref[j] / 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
61
mathmech/mm/src/set_center.c
Normal file
61
mathmech/mm/src/set_center.c
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @fn set_center
|
||||
*/
|
||||
int set_center (const int num_atoms, const int num_mol, const int *label_mol,
|
||||
const float *coords, float *centr_coords)
|
||||
/**
|
||||
* @brief function that searchs center mass of molecules
|
||||
* @code
|
||||
* set_center (num_of_atoms, num_of_molecules, label_molecules, coords, centr_coords);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_atoms number of atoms
|
||||
* @param num_mol number of molecules
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param coords massive of coordinates
|
||||
* @param centr_coords massive of centered coordinates
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int at_in_mol, cur_mol, i, j, k;
|
||||
|
||||
/* at_int_mol number of atoms in molecule
|
||||
* cur_mol current molecule
|
||||
*/
|
||||
|
||||
for (i=0; i<8*num_mol; i++)
|
||||
for (j=0; j<3; j++)
|
||||
centr_coords[i*3+j] = 0.0;
|
||||
|
||||
for (i=0; i<8*num_atoms; i++)
|
||||
{
|
||||
if (i < num_atoms)
|
||||
cur_mol = 0;
|
||||
else
|
||||
cur_mol = ((i - num_atoms) % 7) + 1;
|
||||
for (j=0; j<3; j++)
|
||||
centr_coords[3*(8*label_mol[i]+cur_mol)+j] += coords[3*i+j];
|
||||
}
|
||||
|
||||
at_in_mol = 0;
|
||||
cur_mol = 0;
|
||||
for (i=0; i<num_atoms; i++)
|
||||
if (cur_mol != label_mol[i])
|
||||
{
|
||||
for (j=0; j<8; j++)
|
||||
for (k=0; k<3; k++)
|
||||
centr_coords[3*(8*cur_mol+j)+k] = centr_coords[3*(8*cur_mol+j)+k] / at_in_mol;
|
||||
at_in_mol = 0;
|
||||
cur_mol = label_mol[i];
|
||||
}
|
||||
else
|
||||
at_in_mol++;
|
||||
|
||||
return 0;
|
||||
}
|
141
mathmech/mm/src/stat_print.c
Normal file
141
mathmech/mm/src/stat_print.c
Normal file
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <mathmech/graph.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn printing_agl
|
||||
*/
|
||||
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, const int max_depth, int *type_agl)
|
||||
/**
|
||||
* @brief function that prints agglomerates to output file
|
||||
* @code
|
||||
* printing_agl (input_file, output_file, number_of_molecules, true_label_molecules,
|
||||
* num_of_molecules_in_agglomerates, agglomerates, statistic, max_depth,
|
||||
* type_of_agglomerate);
|
||||
* @endcode
|
||||
*
|
||||
* @param input input file name
|
||||
* @param output output file name
|
||||
* @param connect connectivity graph for all molecules
|
||||
* @param num_mol number of molecules
|
||||
* @param true_label_mol massive of true numbers of molecule for atoms
|
||||
* @param num_mol_agl massive of number of molecules in agglomerates
|
||||
* @param agl massive of agglomerates
|
||||
* @param stat massive of statistic
|
||||
* @param max_depth maximum depth for check cycles in graph analyze
|
||||
* @param type_agl massive of number of agglomerate types
|
||||
*
|
||||
* @return 1 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int error, i, *iso, j, k, *label_matrix, *matrix;
|
||||
FILE *f_out;
|
||||
|
||||
/* iso isomorphic graph in database
|
||||
* label_matrix massive of indexes of molecule
|
||||
* matrix connectivity graph
|
||||
* f_out output file
|
||||
*/
|
||||
|
||||
/// <b>Work blocks</b>
|
||||
|
||||
iso = (int *) malloc (max_depth * sizeof (int));
|
||||
if (iso == NULL)
|
||||
return 1;
|
||||
f_out = fopen (output, "a");
|
||||
|
||||
/// <pre> print header </pre>
|
||||
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");
|
||||
|
||||
/// <pre> print body </pre>
|
||||
for (i=0; i<num_mol; i++)
|
||||
if (num_mol_agl[i] > 0)
|
||||
{
|
||||
/// <pre> creating connectivity graph </pre>
|
||||
label_matrix = (int *) malloc (num_mol * sizeof (int));
|
||||
matrix = (int *) malloc (num_mol_agl[i] * num_mol_agl[i] * sizeof (int));
|
||||
if ((matrix == NULL) ||
|
||||
(label_matrix == NULL))
|
||||
return 1;
|
||||
for (j=0; j<num_mol_agl[i]; j++)
|
||||
for (k=0; k<num_mol_agl[i]; k++)
|
||||
matrix[num_mol_agl[i]*j+k] = 0;
|
||||
|
||||
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]]*num_mol_agl[i]+label_matrix[agl[num_mol*i+k]]] = 1;
|
||||
matrix[label_matrix[agl[num_mol*i+k]]*num_mol_agl[i]+label_matrix[agl[num_mol*i+j]]] = 1;
|
||||
}
|
||||
|
||||
/// <pre> graph topology analyze </pre>
|
||||
if (max_depth > 0)
|
||||
error = graph_analyze (num_mol_agl[i], matrix, max_depth, iso);
|
||||
if (error > 0)
|
||||
return 1;
|
||||
|
||||
// print class of agglomerate
|
||||
fprintf (f_out, "AGL=%i=", num_mol_agl[i]);
|
||||
for (j=0; j<max_depth; j++)
|
||||
{
|
||||
// number of tails
|
||||
if (j == 0)
|
||||
if ((iso[j] == 0) || ((iso[j] <= 2) && (iso[j] == 0)))
|
||||
// not branched
|
||||
type_agl[2]++;
|
||||
// branched
|
||||
else
|
||||
type_agl[3]++;
|
||||
// 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<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*num_mol_agl[i]+k] == 1)
|
||||
fprintf (f_out, "%i,", true_label_mol[agl[num_mol*i+k]]);
|
||||
fprintf (f_out, "\n");
|
||||
}
|
||||
|
||||
/// <pre> free memory </pre>
|
||||
free (matrix);
|
||||
free (label_matrix);
|
||||
}
|
||||
|
||||
fprintf (f_out, "---------------------------------------------------\n");
|
||||
fclose (f_out);
|
||||
|
||||
/// <pre> free memory </pre>
|
||||
free (iso);
|
||||
|
||||
return 0;
|
||||
}
|
118
mathmech/mm/src/stat_select.c
Normal file
118
mathmech/mm/src/stat_select.c
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn create_matrix
|
||||
*/
|
||||
int create_matrix (const int num_mol, const int num_atoms, const int *label_mol,
|
||||
const int *type_atoms, const float *coords, const int num_of_inter,
|
||||
const float *crit, int *connect)
|
||||
/**
|
||||
* @brief function that creates connectivity matrix
|
||||
* @code
|
||||
* create_matrix (number_of_molecules, number_of_atoms, label_molecule, type_atoms,
|
||||
* coords, number_of_interactions, criteria, connect_matrix);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_mol number of molecules
|
||||
* @param num_atoms number of atoms
|
||||
* @param label_mol massive of numbers of molecule for atoms
|
||||
* @param type_atoms massive of atom types
|
||||
* @param coords massive of coordinates
|
||||
* @param num_of_inter number of different interactions
|
||||
* @param crit massive of criteria
|
||||
* @param connect connectivity graph for all molecules
|
||||
*
|
||||
* @return 1 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
||||
/// <b>Work blocks</b>
|
||||
|
||||
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;
|
||||
|
||||
/// <pre> creating initial connectivity matrix </pre>
|
||||
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;
|
||||
|
||||
/// <pre> processing of initial connectivity matrix </pre>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <pre> free memory</pre>
|
||||
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;
|
||||
}
|
100
mathmech/mm/src/stat_sort.c
Normal file
100
mathmech/mm/src/stat_sort.c
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn proc_matrix
|
||||
*/
|
||||
int proc_matrix (const int num_mol, const int *connect, int *num_mol_agl, int *agl,
|
||||
int *stat, int *stat_all)
|
||||
/**
|
||||
* @brief function that processes connectivity matrix
|
||||
* @code
|
||||
* proc_matrix (number_of_molecules, connect_matrix, num_of_molecules_in_agglomerates,
|
||||
* agglomerates, statistic, summary_statistic);
|
||||
* @endcode
|
||||
*
|
||||
* @param num_mol number of molecules
|
||||
* @param connect connectivity graph for all molecules
|
||||
* @param num_mol_agl massive of number of molecules in agglomerates
|
||||
* @param agl massive of agglomerates
|
||||
* @param stat massive of statistic
|
||||
* @param stat_all massive of summary statistic
|
||||
*
|
||||
* @return 1 - memory error
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
int i, j, k, p, *bin;
|
||||
|
||||
/* p weight / graph index
|
||||
* bin binary massive of labels
|
||||
*/
|
||||
|
||||
/// <b>Work blocks</b>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// <pre> select non-bonded molecules </pre>
|
||||
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]++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <pre> unwraping of connectivity matrix </pre>
|
||||
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++;
|
||||
}
|
||||
|
||||
/// <pre> filling statistic array </pre>
|
||||
i = 0;
|
||||
while (num_mol_agl[i] > 0)
|
||||
{
|
||||
stat[num_mol_agl[i]-1]++;
|
||||
stat_all[num_mol_agl[i]-1]++;
|
||||
i++;
|
||||
}
|
||||
|
||||
/// <pre> free memory </pre>
|
||||
free (bin);
|
||||
|
||||
return 0;
|
||||
}
|
93
mathmech/mm/src/summary_stat.c
Normal file
93
mathmech/mm/src/summary_stat.c
Normal file
@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/**
|
||||
* @fn summary_statistic
|
||||
*/
|
||||
int summary_statistic (const char *filename, const int step, const int num_mol,
|
||||
const int max_depth, const int *type_agl, const int *stat_all)
|
||||
/**
|
||||
* @brief function that prints summary statistic
|
||||
* @code
|
||||
* summary_statistic (filename, number_of_step, number_of_molecules, max_depth,
|
||||
* type_of_agglomerate, summary_statistic);
|
||||
* @endcode
|
||||
*
|
||||
* @param filename output file name
|
||||
* @param step number of steps
|
||||
* @param num_mol number of molecules
|
||||
* @param max_depth maximum depth for check cycles in graph analyze
|
||||
* @param type_agl massive of number of agglomerate types
|
||||
* @param stat_all massive of summary statistic
|
||||
*
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
float conc, p, pn, type[2], x, y;
|
||||
int i, index;
|
||||
FILE *f_out;
|
||||
|
||||
/* conc concentrate of agglomerates
|
||||
* p probability of agglomerates
|
||||
* pn weight probability of agglomerates
|
||||
* 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);
|
||||
}
|
||||
fprintf (f_out, "------------------------------------------------\n");
|
||||
|
||||
if (max_depth > 0)
|
||||
{
|
||||
// types of agglomerates
|
||||
// linear and cycle
|
||||
x = type_agl[0] + type_agl[1];
|
||||
type[0] = type_agl[0];
|
||||
type[1] = type_agl[1];
|
||||
fprintf (f_out, "LINEAR=%.5f\nCYCLE=%.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=%.5f\nBRANCHED=%.5f\n--------------------\n", type[0]/x, type[1]/x);
|
||||
// n_cycle
|
||||
x = 0;
|
||||
for (i=4; i<max_depth+2; i++)
|
||||
x += type_agl[i];
|
||||
for (i=4; i<max_depth+2; i++)
|
||||
{
|
||||
type[0] = type_agl[i];
|
||||
fprintf (f_out, "CYCLE_'%2i'=%.5f\n", i-1, type[0]/x);
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f_out);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user