- removed *.pdf

+ release agl 1.0.1
* modified shared library (messages.c)
* small bug fixes
This commit is contained in:
arcan1s
2013-07-28 05:26:28 +04:00
parent d280eb1d3d
commit 09025fca89
25 changed files with 391 additions and 130 deletions

View File

@ -4,7 +4,7 @@ CC=gcc
CFLAGS=-c -Wall -fPIC
LDFLAGS=-lm
SOURCES_DIR=src
SOURCES=main.c add_main.c coords.c messages.c print_struct.c set_center.c read_agl.c
SOURCES=main.c add_main.c coords.c messages.c print_struct.c read_agl.c select_mol.c set_center.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=agl

View File

@ -1,13 +1,34 @@
/* Additional library for main.c (agl)
/**
* @file
*/
#include <stdio.h>
// #include "messages.h"
#include "messages.h"
/**
* @fn error_checking
*/
int error_checking (const char *aglinp, const float *cell, const char *input,
const char *output)
/**
* @brief function that checks errors in input variables
* @code
* error_checking (aglinp, cell, input, output);
* @endcode
*
* @param aglinp aglomerate file name
* @param cell massive of cell size
* @param input input file name
* @param output output file name
*
* @return 11 - error in 'cell'
* @return 12 - error in 'input'
* @return 13 - error in 'output'
* @return 14 - error in 'aglinp'
* @return 0 - exit without errors
*/
{
if ((cell[0] == 0.0) || (cell[1] == 0.0) || (cell[2] == 0.0))
return 11;
@ -22,8 +43,26 @@ int error_checking (const char *aglinp, const float *cell, const char *input,
}
/**
* @fn print_message
*/
int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log,
const int mode, const char *str)
/**
* @brief function that prints message in log and stdout
* @code
* print_message (quiet, stdout, log, f_log, 0, str);
* @endcode
*
* @param quiet status of quiet-mode
* @param std_output stdout
* @param log status of log-mode
* @param f_log log file
* @param mode number of message in "messages.c"
* @param str additional text in message
*
* @return 0 - exit without errors
*/
{
if ((quiet != 1) && (std_output != stderr))
message (0, mode, str, std_output);
@ -34,8 +73,25 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log
}
int set_defaults (char aglinp, float *cell, char *input, int *log, int *num_of_mol,
char *output, int *quiet, float *rad)
/**
* @fn set_defaults
*/
int set_defaults (char *aglinp, float *cell, char *input, int *log, char *output, int *quiet)
/**
* @brief function that sets default values of variables
* @code
* set_defaults (aglinp, cell, input, &log, output, &quiet);
* @endcode
*
* @param aglinp aglomerate file name
* @param cell massive of cell size
* @param input mask of trajectory files
* @param log status of log-mode
* @param output output file name
* @param quiet status of quiet-mode
*
* @return 0 - exit without errors
*/
{
int i;
@ -44,10 +100,8 @@ int set_defaults (char aglinp, float *cell, char *input, int *log, int *num_of_m
cell[i] = 0.0;
input[0] = '#';
*log = 0;
*num_of_mol = 1;
output[0] = '#';
*quiet = 0;
*rad = 6.0;
return 0;
}

22
agl/src/add_main.h Normal file
View File

@ -0,0 +1,22 @@
/**
* @file
*/
#ifndef ADD_MAIN_H
#define ADD_MAIN_H
/**
* @fn error_checking
*/
/**
* @fn print_message
*/
/**
* @fn set_defaults
*/
int error_checking (const char *, const float *, const char *, const char *);
int print_message (const int, FILE *, const int, FILE *, const int, const char *);
int set_defaults (char *, float *, char *, int *, char *, int *);
#endif /* ADD_MAIN_H */

16
agl/src/coords.h Normal file
View File

@ -0,0 +1,16 @@
/**
* @file
*/
#ifndef COORDS_H
#define COORDS_H
/**
* @fn reading_coords
*/
int reading_coords (const int, const char *, const int, const int *,
const float *, int *, int *, int *, int *, int *, float *,
char *);
#endif /* COORDS_H */

View File

@ -1,45 +1,62 @@
/**
* @file
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include "add_main.h"
// #include "coords.h"
// #include "messages.h"
// #include "print_struct.h"
// #include "read_agl.h"
#include "add_main.h"
#include "coords.h"
#include "messages.h"
#include "print_struct.h"
#include "read_agl.h"
#include "select_mol.h"
#include "set_center.h"
/**
* @fn main
*/
int main(int argc, char *argv[])
/**
* @return 1 - error in error_checking
* @return 2 - input file does not exist
* @return 3 - memory error
* @return 0 - exit without errors
*/
{
char tmp_str[2048];
int error, i, j, *tmp_int;
int error, i, *tmp_int;
FILE *f_inp, *f_log;
char aglinp[256], *ch_type_atoms, input[256], logfile[256], output[256];
float cell[3], *coords;
float cell[3], *centr_coords, *coords;
int *label_mol, log, num_atoms, num_mol, num_needed_mol, *needed_mol, quiet,
*true_label_mol;
/* ch_type_atoms - massive of char types for atoms
* aglinp - input file with aglomerate name
* input - input file name
* logfile - log file name
* output - output file name
/* aglinp aglomerate file name
* ch_type_atoms massive of char atom types
* input input file name
* logfile log file name
* output output file name
*
* cell - cell dimension
* coords - massive of coordinates
* cell massive of cell size
* centr_coords massive of centered coordinates
* coords massive of coordinates
*
* 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_needed_mol - number of needed molecules
* needed_mol - massive of needed molecules
* quiet - status of quiet-mode
* true_label_mol - massive of true numbers of molecule for atoms
* label_mol massive of numbers of molecule for atoms
* log status of log-mode
* num_atoms number of atoms
* num_mol number of molecules
* num_needed_mol number of needed molecules
* needed_mol massive of number of needed molecules
* quiet status of quiet-mode
* true_label_mol massive of true numbers of molecule for atoms
*/
set_defaults (aglinp, cell, input, &log, &num_of_mol, output, &quiet, &rad);
set_defaults (aglinp, cell, input, &log, output, &quiet);
for (i=1; i<argc; i++)
{
@ -64,38 +81,38 @@ int main(int argc, char *argv[])
return 0;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'a'))
// input file
// input file
{
strcpy (aglinp, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'i'))
// input file
// input file
{
strcpy (input, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'c'))
// cell size
// cell size
{
sscanf (argv[i+1], "%f,%f,%f", &cell[0], &cell[1], &cell[2]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'o'))
// output file
// output file
{
strcpy (output, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'l'))
// log mode
// log mode
{
log = 1;
strcpy (logfile, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'q'))
// quiet mode
// quiet mode
{
quiet = 1;
}
@ -117,14 +134,14 @@ int main(int argc, char *argv[])
print_message (quiet, stdout, log, f_log, 2, argv[0]);
// processing
// initial variables
// processing
// initial variables
print_message (quiet, stdout, log, f_log, 3, input);
f_inp = fopen (input, "r");
if (f_inp == NULL)
{
print_message (quiet, stderr, log, f_log, 18, input);
return 1;
return 2;
}
fscanf (f_inp, "%i", &num_atoms);
fclose (f_inp);
@ -134,7 +151,7 @@ int main(int argc, char *argv[])
needed_mol = (int *) malloc (num_atoms * sizeof (int));
tmp_int = (int *) malloc (8 * num_atoms * sizeof (int));
true_label_mol = (int *) malloc (num_atoms * sizeof (int));
// error checking
// error checking
if ((ch_type_atoms == NULL) ||
(coords == NULL) ||
(label_mol == NULL) ||
@ -143,7 +160,7 @@ int main(int argc, char *argv[])
(true_label_mol == NULL))
{
print_message (quiet, stderr, log, f_log, 19, argv[0]);
return 17;
return 3;
}
sprintf (tmp_str, "%6cAglomerate file: '%s';\n%6cInput file: '%s';\n\
%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n%6cCell size: %.4f, %.4f, %.4f\n",
@ -152,43 +169,57 @@ int main(int argc, char *argv[])
print_message (quiet, stdout, log, f_log, 6, argv[0]);
// reading aglomerate
// reading aglomerate
print_message (quiet, stdout, log, f_log, 7, aglinp);
error = reading_agl (aglinp, &num_needed_mol, tmp_str, needed_mol);
if (error == 0)
{
sprintf (tmp_str, "%6cNumber of molecules in aglomerate: %i\n", num_needed_mol);
sprintf (tmp_str, "%6cNumber of molecules in aglomerate: %i\n", ' ', num_needed_mol);
print_message (quiet, stdout, log, f_log, 8, tmp_str);
// reading coordinates
// reading coordinates
print_message (quiet, stdout, log, f_log, 7, input);
error = reading_coords (1, input, num_needed_mol, needed_mol, cell, &num_mol,
error = reading_coords (2, input, num_needed_mol, needed_mol, cell, &num_mol,
&num_atoms, true_label_mol, label_mol, tmp_int, coords,
ch_type_atoms);
centr_coords = (float *) malloc (3 * 8 * num_mol * sizeof (float));
if (centr_coords == NULL)
{
print_message (quiet, stderr, log, f_log, 19, argv[0]);
return 3;
}
// analyze
// analyze
if (error == 0)
{
sprintf (tmp_str, "%6cNumber of molecules: %i; %6cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms);
print_message (quiet, stdout, log, f_log, 8, tmp_str);
error =
error = 1;
error = set_center (num_atoms, num_mol, label_mol, coords, centr_coords);
if (error == 0)
{
print_message (quiet, stderr, log, f_log, 20, argv[0]);
error = 1;
error = select_molecule (centr_coords, num_needed_mol, needed_mol);
if (error == 0)
{
print_message (quiet, stderr, log, f_log, 21, argv[0]);
print_message (quiet, stderr, log, f_log, 4, argv[0]);
error = 1;
error = print_structure (output, num_needed_mol, needed_mol, num_atoms,
label_mol, ch_type_atoms, coords);
label_mol, ch_type_atoms, coords);
print_message (quiet, stderr, log, f_log, 12, output);
}
}
}
}
print_message (quiet, stdout, log, f_log, 13, argv[0]);
print_message (quiet, stderr, log, f_log, 13, argv[0]);
print_message (quiet, stdout, log, f_log, 15, argv[0]);
// free memory
// free memory
free (ch_type_atoms);
free (centr_coords);
free (coords);
free (label_mol);
free (needed_mol);

View File

@ -52,6 +52,7 @@ int message (const int log, const int mode, const char *text, FILE *output)
sprintf (out, "Initialization of variables from file '%s'\n", text);
break;
case 4:
sprintf (out, "%6cAglomerate was selected successfully\n", ' ');
break;
case 5:
sprintf (out, "Initial parametrs: \n%s", text);

14
agl/src/messages.h Normal file
View File

@ -0,0 +1,14 @@
/**
* @file
*/
#ifndef MESSAGES_H
#define MESSAGES_H
/**
* @fn message
*/
int message (const int, const int, const char *, FILE *);
#endif /* MESSAGES_H */

View File

@ -2,13 +2,6 @@
* @file
*/
/* Library for printing structure to pdb file
*
* Usage:
* print_structure (output, num_needed_mol, needed_mol, num_atoms,
* label_mol, char_type_atoms, coords)
*/
#include <stdio.h>

15
agl/src/print_struct.h Normal file
View File

@ -0,0 +1,15 @@
/**
* @file
*/
#ifndef PRINT_STRUCTURE_H
#define PRINT_STRUCTURE_H
/**
* @fn print_structure
*/
int print_structure (const char *, const int, const int *, const int, const int *,
const char *, const float *);
#endif /* PRINT_STRUCTURE_H */

View File

@ -1,3 +1,6 @@
/**
* @file
*/
/* Library for reading aglomerate from statgen-file
*
* Usage:
@ -7,17 +10,32 @@
#include <stdio.h>
/**
* @fn reading_agl
*/
int reading_agl (const char *aglinp, int *num_needed_mol, char *agl_class, int *needed_mol)
/* aglinp - input file with aglomerate
* num_needed_mol - number of needed molecules
* agl_class - aglomerate class
* needed_mol - massive of needed molecules
/**
* @brief function that reads aglomerate from statgen-formated file
* @code
* reading_agl (aglinput, &num_needed_mol, agl_class, needed_mol);
* @endcode
*
* @param aglinp aglomerate file name
* @param num_needed_mol number of needed molecules
* @param agl_class aglomerate 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 - aglomerate file
*/
f_agl = fopen (aglinp, "r");
fgets (tmp_str, 256, f_agl);

14
agl/src/read_agl.h Normal file
View File

@ -0,0 +1,14 @@
/**
* @file
*/
#ifndef READ_AGL_H
#define READ_AGL_H
/**
* @fn reading_agl
*/
int reading_agl (const char *, int *, char *, int *);
#endif /* READ_AGL_H */

View File

@ -1,59 +1,69 @@
/* Library for select molecules in translations
*
* Usage:
*
/**
* @file
*/
#include <math.h>
int select_molecule (const int num_atoms, const int *label_mol, const int *true_label_mol, const float *coords, const int num_needed_mol, int *needed_mol)
/**
* @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, k, *old_needed_mol;
int i, j, jmin;
old_needed_mol = (int *) malloc (num_needed_mol * sizeof (int));
if (old_needed_mol == NULL)
return 1;
/* r radius
* ref coordinated of center mass
* rmin minimal radius
* jmin index of the nearest molecule
*/
// set first molecule
ref_mol = old_needed_mol[0];
// set first molecule
needed_mol[0] = 0;
k = 1;
for (i=0; i<3; i++)
ref[i] = coords[3*0+i];
ref[i] = centr_coords[3*8*0+0+i];
// work block
for (i=1; i<num_needed_mol; i++)
for (j=0; j<8*num_atoms; j++)
if (old_needed_mol[i] == true_label_mol[label_mol[j]])
{
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)
{
if (j < num_atoms)
cur_mol = 0;
else
cur_mol = ((j - num_atoms) % 7) + 1;
// for (j=0; j<3; j++)
// centr_coords[3*(8*label_mol[i]+cur_mol)+j] += coords[3*i+j];
rmin = r;
jmin = j;
}
for (i=1; i<num_needed_mol; i++)
for (j=0; j<num_atoms; j++)
if (old_needed_mol[i] == true_label_mol[label_mol[j]])
{
if (ref_mol != true_label_mol[label_mol[j]])
{
ref_i = j;
rmin = sqrt (pow ((coords[3*j+0] - ref[0]), 2) + \
pow ((coords[3*j+1] - ref[1]), 2) + \
pow ((coords[3*j+2] - ref[2]), 2));
ref_mol = true_label_mol[label_mol[j]];
}
else
{
}
}
free (old_needed_mol);
}
// 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;
}

14
agl/src/select_mol.h Normal file
View File

@ -0,0 +1,14 @@
/**
* @file
*/
#ifndef SELECT_MOL_H
#define SELECT_MOL_H
/**
* @fn select_molecule
*/
int select_molecule (const float *, const int, int *);
#endif /* SELECT_MOL_H */

61
agl/src/set_center.c Normal file
View 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;
}

14
agl/src/set_center.h Normal file
View File

@ -0,0 +1,14 @@
/**
* @file
*/
#ifndef SET_CENTER_H
#define SET_CENTER_H
/**
* @fn set_center
*/
int set_center (const int, const int, const int *, const float *, float *);
#endif /* SET_CENTER_H */

Binary file not shown.

View File

@ -18,8 +18,8 @@ int error_checking (const float *cell, const char *input, const char *output)
* @endcode
*
* @param cell massive of cell size
* @param input first trajectory step
* @param output last trajectory step
* @param input input file name
* @param output output file name
*
* @return 11 - error in 'cell'
* @return 12 - error in 'input'
@ -74,7 +74,7 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log
int set_defaults (float *cell, char *input, int *log, int *num_of_mol, char *output,
int *quiet, float *rad)
/**
* @brief function for set default values of variables
* @brief function that sets default values of variables
* @code
* set_defaults (cell, &from, input, &log, &max_depth, &num_of_inter, output, &to,
* &type_inter, &quiet);

View File

@ -2,13 +2,6 @@
* @file
*/
/* Library for search environment
*
* Usage:
* search_envir (number_of_molecule, num_mol, centr_coords, rad, needed_mol,
* &num_needed_mol)
*/
#include <math.h>

View File

@ -27,7 +27,7 @@ int main(int argc, char *argv[])
*/
{
char tmp_str[2048];
int error, i, j, *tmp_int;
int error, i, *tmp_int;
FILE *f_inp, *f_log;
char *ch_type_atoms, input[256], logfile[256], output[256];
@ -177,7 +177,7 @@ int main(int argc, char *argv[])
// reading coordinates
print_message (quiet, stdout, log, f_log, 7, input);
error = reading_coords (1, input, tmp_int, tmp_int, cell, &num_mol, &num_atoms,
error = reading_coords (1, input, tmp_int[0], tmp_int, cell, &num_mol, &num_atoms,
true_label_mol, label_mol, tmp_int, coords, ch_type_atoms);
centr_coords = (float *) malloc (3 * 8 * num_mol * sizeof (float));
needed_mol = (int *) malloc (num_mol * sizeof (int));
@ -198,15 +198,18 @@ int main(int argc, char *argv[])
// analyze
if (error == 0)
{
error = 1;
error = set_center (num_atoms, num_mol, label_mol, coords, centr_coords);
if (error == 0)
{
print_message (quiet, stderr, log, f_log, 20, argv[0]);
error = 1;
error = search_envir (num_of_mol, num_mol, centr_coords, rad, needed_mol,
&num_needed_mol);
if (error == 0)
{
print_message (quiet, stderr, log, f_log, 21, argv[0]);
error = 1;
error = print_structure (output, num_needed_mol, needed_mol, num_atoms,
label_mol, ch_type_atoms, coords);
print_message (quiet, stderr, log, f_log, 12, output);

View File

@ -52,6 +52,7 @@ int message (const int log, const int mode, const char *text, FILE *output)
sprintf (out, "Initialization of variables from file '%s'\n", text);
break;
case 4:
sprintf (out, "%6cAglomerate was selected successfully\n", ' ');
break;
case 5:
sprintf (out, "Initial parametrs: \n%s", text);

View File

@ -2,13 +2,6 @@
* @file
*/
/* Library for printing structure to pdb file
*
* Usage:
* print_structure (output, num_needed_mol, needed_mol, num_atoms,
* label_mol, char_type_atoms, coords)
*/
#include <stdio.h>

View File

@ -2,13 +2,6 @@
* @file
*/
/* Library for search center mass of molecules
*
* Usage:
* set_center (num_of_atoms, num_of_molecules, label_molecules, coords,
* centr_coords)
*/
/**
* @fn set_center

View File

@ -156,7 +156,7 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log
int set_defaults (float *cell, int *from, char *input, int *log, int *max_depth,
int *num_of_inter, char *output, int *to, int *type_inter, int *quiet)
/**
* @brief function for set default values of variables
* @brief function that sets default values of variables
* @code
* set_defaults (cell, &from, input, &log, &max_depth, &num_of_inter, output, &to,
* &type_inter, &quiet);

View File

@ -52,6 +52,7 @@ int message (const int log, const int mode, const char *text, FILE *output)
sprintf (out, "Initialization of variables from file '%s'\n", text);
break;
case 4:
sprintf (out, "%6cAglomerate was selected successfully\n", ' ');
break;
case 5:
sprintf (out, "Initial parametrs: \n%s", text);

Binary file not shown.