Added lib 'stat_select.c'

This commit is contained in:
arcan1s
2013-07-16 04:01:37 +04:00
parent 51bf658d18
commit 9957e98086
5 changed files with 194 additions and 11 deletions

Binary file not shown.

View File

@ -1,8 +1,10 @@
/* Usage: /* Library for reading coordinates from input file
* reading_coords(filename, label, coords) *
* Usage:
* reading_coords (filename, type_interaction, labels, cell,
* &number_of_molecules, &number_of_atoms, label_molecule, type_atoms, coords)
*/ */
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -24,29 +26,42 @@ char conv (int fnumb, int dig_pos)
} }
int reading_coords (char *filename, int type_inter, int *label_atom, float *cell, int *label_mol, int *num_atoms, float *coords, int *type_atoms) int reading_coords (char *filename, int type_inter, const int *label_atom,
const float *cell, int *num_mol, int *num_atoms,
int *label_mol, int *type_atoms, float *coords)
/* filename - name of file with coordinates /* filename - name of file with coordinates
* type_inter - type interaction (number of molecules for interaction) * type_inter - type interaction (number of molecules for interaction)
* label_atom - types of atom for interaction * label_atom - types of atom for interaction
* cell - cell dimention * cell - cell dimension
* label_mol - massive of numbers of molecule for atoms * num_mol - number of molecules for writing coordinates
* num_atoms - number of atoms for writing coordinates * num_atoms - number of atoms for writing coordinates
* coords - massive of coordinates * label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms * type_atoms - massive of atom types for atoms
* coords - massive of coordinates
*/ */
{ {
char file_string[256]; char file_string[256];
int atoms, i, j, tr_num_atoms, ref_mol, x, y, z; int atoms, i, j, tr_num_atoms, ref_mol, x, y, z;
float not_tr_coords[750000], ref[3]; float not_tr_coords[750000], ref[3];
FILE *inp; 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_atoms = 0;
*num_mol = 0;
// Reading file // Reading file
inp = fopen (filename, "r+"); inp = fopen (filename, "r+");
if (inp == NULL) if (inp == NULL)
return 1; return 1;
ref_mol = -1;
fscanf (inp, "%i", &atoms); fscanf (inp, "%i", &atoms);
for (i=0; i<atoms; i++) for (i=0; i<atoms; i++)
{ {
@ -59,7 +74,12 @@ int reading_coords (char *filename, int type_inter, int *label_atom, float *cell
not_tr_coords[3**num_atoms+1] = atof (&file_string[23]); not_tr_coords[3**num_atoms+1] = atof (&file_string[23]);
not_tr_coords[3**num_atoms+2] = atof (&file_string[35]); not_tr_coords[3**num_atoms+2] = atof (&file_string[35]);
label_mol[*num_atoms] = atoi (&file_string[53]); if (ref_mol != atoi (&file_string[53]))
{
ref_mol = atoi (&file_string[53]);
*num_mol = *num_mol + 1;
}
label_mol[*num_atoms] = num_mol - 1;
type_atoms[*num_atoms] = j; type_atoms[*num_atoms] = j;
*num_atoms = *num_atoms + 1; *num_atoms = *num_atoms + 1;
@ -267,13 +287,20 @@ int reading_coords (char *filename, int type_inter, int *label_atom, float *cell
} }
} }
// Reading number of molecules
// *num_mol = 1;
// ref_mol = label_mol[0];
// for (i=0; i<*num_atoms; i++)
// if (ref_mol != label_mol[i])
// *num_mol = *num_mol + 1;
//
return 0; return 0;
} }
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
// int i, label_atom[5], label_mol[200000], num_atoms, type_atoms[200000]; // int i, label_atom[5], label_mol[200000], num_atoms, num_mol, type_atoms[200000];
// float a[600000], cell[3]; // float a[600000], cell[3];
// //
// for (i=0; i<5; i++) // for (i=0; i<5; i++)
@ -283,7 +310,7 @@ int main (int argc, char *argv[])
// cell[1] = 34.7930; // cell[1] = 34.7930;
// cell[2] = 34.7925; // cell[2] = 34.7925;
// //
// reading_coords ("oct.001", 1, label_atom, cell, label_mol, &num_atoms, a, type_atoms); // reading_coords ("oct.001", 1, label_atom, cell, &num_mol, &num_atoms, label_mol, type_atoms, a);
//
return 0; return 0;
} }

BIN
stat_new/stat Executable file

Binary file not shown.

107
stat_new/stat_select.c Normal file
View File

@ -0,0 +1,107 @@
/* 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>
float radii (const float *a, const float *b)
{
return sqrt (pow((a[0]-b[0]), 2) + pow((a[1]-b[1]), 2) + pow((a[2]-b[2]), 2));
}
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, int *num_bonds)
{
float x[2][3];
int cur_num_inter, i, j, k, l, num_inter, ***label_inter;
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;
}
}
// 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])
{
for (k=0; k<3; k++)
{
x[0][k] = coords[3*i+k];
x[1][k] = coords[3*j+k];
}
for (k=0; k<num_of_inter; k++)
if (crit[16*k+4*type_atoms[i]+type_atoms[j]] != 0.0)
if (radii (x[0], x[1]) <= 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[j]][label_mol[i]][4*type_atoms[i]+type_atoms[j]] = 1;
}
}
for (i=0; i<num_mol; i++)
{
num_bonds[i] = 0;
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=0; 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;
num_bonds[i]++;
num_bonds[j]++;
}
}
}
// 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;
}
int main (int argc, char *argv[])
{
return 0;
}

49
stat_new/stat_sort.c Normal file
View File

@ -0,0 +1,49 @@
/* Library for processing connectivity matrix
*
* Usage:
*/
#include <stdio.h>
#include <stdlib.h>
int proc_matrix (int num_mol, const int *connect, const int *num_bond, int *num_mol_agl, int *agl, int *stat)
{
int i, j, p, *bin;
// definition and zeroing
bin = (int *) malloc (num_mol * sizeof (int));
for (i=0; i<num_mol; i++)
bin[i] = 0;
for (i=0; i<5000; i++)
{
stat[i] = 0;
num_mol_agl[i] = 0;
for (j=0; j<5000; j++)
agl[5000*i+j] = 0;
}
p = num_mol;
for (i=0; i<num_mol; i++)
if (num_bond[i] == 0)
{
bin[i] = 0;
stat[0]++;
p--;
}
while (p > 0)
{
}
free (bin);
return 0;
}
int main (int argc, char *argv[])
{
return 0;
}