mirror of
https://github.com/arcan1s/moldyn.git
synced 2025-07-16 15:20:00 +00:00
Reorganization
This commit is contained in:
29
mathmech/mm_agl/src/CMakeLists.txt
Normal file
29
mathmech/mm_agl/src/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
set ("${PROJECT}_VERSION_MAJOR" 1)
|
||||
set ("${PROJECT}_VERSION_MINOR" 0)
|
||||
set ("${PROJECT}_VERSION_PATCH" 1)
|
||||
set ("${PROJECT}_VERSION" ${${PROJECT}_VERSION_MAJOR}.${${PROJECT}_VERSION_MINOR}.${${PROJECT}_VERSION_PATCH})
|
||||
|
||||
message (STATUS "${PROJECT}: Version ${${PROJECT}_VERSION}")
|
||||
|
||||
# set files
|
||||
aux_source_directory (. SOURCES)
|
||||
|
||||
# set library
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (ADDITIONAL_LIB m)
|
||||
else ()
|
||||
set (ADDITIONAL_LIB)
|
||||
endif()
|
||||
|
||||
# message
|
||||
message (STATUS "SOURCES: ${SOURCES}")
|
||||
|
||||
# link libraries and compile
|
||||
add_executable (${PROJECT} ${SOURCES})
|
||||
target_link_libraries (${PROJECT} ${ADDITIONAL_LIB})
|
||||
|
||||
# install properties
|
||||
INSTALL (TARGETS ${PROJECT} DESTINATION bin)
|
||||
if (ADD_INCLUDE)
|
||||
INSTALL (FILES ${PUBLIC_HEADERS} DESTINATION include/${PROJECT})
|
||||
endif ()
|
20
mathmech/mm_agl/src/Makefile
Normal file
20
mathmech/mm_agl/src/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
PROJECT=AGL
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-c -Wall -fPIC
|
||||
LDFLAGS=-lm
|
||||
SOURCES_DIR=src
|
||||
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=mm_agl
|
||||
|
||||
$(PROJECT): $(SOURCES) $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o test*
|
107
mathmech/mm_agl/src/add_main.c
Normal file
107
mathmech/mm_agl/src/add_main.c
Normal file
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <stdio.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;
|
||||
if (input[0] == '#')
|
||||
return 12;
|
||||
if (output[0] == '#')
|
||||
return 13;
|
||||
if (aglinp[0] == '#')
|
||||
return 14;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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);
|
||||
if (log == 1)
|
||||
message (1, mode, str, f_log);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
aglinp[0] = '#';
|
||||
for (i=0; i<3; i++)
|
||||
cell[i] = 0.0;
|
||||
input[0] = '#';
|
||||
*log = 0;
|
||||
output[0] = '#';
|
||||
*quiet = 0;
|
||||
|
||||
return 0;
|
||||
}
|
22
mathmech/mm_agl/src/add_main.h
Normal file
22
mathmech/mm_agl/src/add_main.h
Normal 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 */
|
354
mathmech/mm_agl/src/coords.c
Normal file
354
mathmech/mm_agl/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;
|
||||
}
|
16
mathmech/mm_agl/src/coords.h
Normal file
16
mathmech/mm_agl/src/coords.h
Normal 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 */
|
305
mathmech/mm_agl/src/main.c
Normal file
305
mathmech/mm_agl/src/main.c
Normal file
@ -0,0 +1,305 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
/**
|
||||
* @mainpage mm_agl
|
||||
* @image latex ./logo.png
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* <b>About this program</b>:
|
||||
* <ul>
|
||||
* <li>Program that creates PDB file with chosen aglomerate
|
||||
* </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>
|
||||
*
|
||||
* @section How-To-Use How to use
|
||||
* Usage:
|
||||
* <pre>
|
||||
* mm_agl -a AGL_INP -i INPUT -c X,Y,Z -o OUTPUT [ -l LOGFILE ] [ -q ] [ -h ]
|
||||
*
|
||||
* Parametrs:
|
||||
* -a - input file with aglomerates (in format statgen)
|
||||
* -i - input file with coordinates
|
||||
* -c - cell size (float), A
|
||||
* -o - output file name
|
||||
* -l - log enable
|
||||
* -q - quiet enable
|
||||
* -h - show this help and exit
|
||||
* </pre>
|
||||
*
|
||||
* @page Install
|
||||
*
|
||||
* @section Requirements Requirements
|
||||
* The application mm_agl 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.0.1 (2013-07-27)
|
||||
* * initial release
|
||||
*/
|
||||
|
||||
#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 "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 4 - unknown flag
|
||||
* @return 0 - exit without errors
|
||||
*/
|
||||
{
|
||||
char tmp_str[2048];
|
||||
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], *centr_coords, *coords;
|
||||
int *label_mol, log, num_atoms, num_mol, num_needed_mol, *needed_mol, quiet,
|
||||
*true_label_mol;
|
||||
|
||||
/* 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 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
|
||||
* 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, output, &quiet);
|
||||
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
if ((argv[i][0] == '-') && (argv[i][1] == 'h') && (argv[i][2] == '\0'))
|
||||
{
|
||||
sprintf (tmp_str, " mm_agl\n");
|
||||
sprintf (tmp_str, "%sProgram for create PDB file with chosen aglomerate\n", tmp_str);
|
||||
sprintf (tmp_str, "%sVersion : 1.0.1 License : GPL\n", tmp_str);
|
||||
sprintf (tmp_str, "%s Evgeniy Alekseev aka arcanis\n", tmp_str);
|
||||
sprintf (tmp_str, "%s E-mail : esalexeev@gmail.com\n\n", tmp_str);
|
||||
sprintf (tmp_str, "%sUsage:\n", tmp_str);
|
||||
sprintf (tmp_str, "%smm_agl -a AGL_INP -i INPUT -c X,Y,Z -o OUTPUT [ -l LOGFILE ] [ -q ] [ -h ]\n\n", tmp_str);
|
||||
sprintf (tmp_str, "%sParametrs:\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -a - input file with aglomerates (in format statgen)\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -i - input file with coordinates\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -c - cell size (float), A\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -o - output file name\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -l - log enable\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -q - quiet enable\n", tmp_str);
|
||||
sprintf (tmp_str, "%s -h - show this help and exit\n", tmp_str);
|
||||
fputs (tmp_str, stdout);
|
||||
return 0;
|
||||
}
|
||||
else if ((argv[i][0] == '-') && (argv[i][1] == 'a') && (argv[i][2] == '\0'))
|
||||
// input file
|
||||
{
|
||||
strcpy (aglinp, argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if ((argv[i][0] == '-') && (argv[i][1] == 'i') && (argv[i][2] == '\0'))
|
||||
// input file
|
||||
{
|
||||
strcpy (input, argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if ((argv[i][0] == '-') && (argv[i][1] == 'c') && (argv[i][2] == '\0'))
|
||||
// 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') && (argv[i][2] == '\0'))
|
||||
// output file
|
||||
{
|
||||
strcpy (output, argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if ((argv[i][0] == '-') && (argv[i][1] == 'l') && (argv[i][2] == '\0'))
|
||||
// log mode
|
||||
{
|
||||
log = 1;
|
||||
strcpy (logfile, argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if ((argv[i][0] == '-') && (argv[i][1] == 'q') && (argv[i][2] == '\0'))
|
||||
// quiet mode
|
||||
{
|
||||
quiet = 1;
|
||||
}
|
||||
else
|
||||
// unknown flag
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (log == 1)
|
||||
f_log = fopen (logfile, "w");
|
||||
|
||||
print_message (quiet, stdout, log, f_log, 0, argv[0]);
|
||||
print_message (quiet, stdout, log, f_log, 1, argv[0]);
|
||||
|
||||
// error check
|
||||
error = error_checking (aglinp, cell, input, output);
|
||||
if (error != 0)
|
||||
{
|
||||
print_message (quiet, stderr, log, f_log, 17, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_message (quiet, stdout, log, f_log, 2, argv[0]);
|
||||
|
||||
// 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 2;
|
||||
}
|
||||
fscanf (f_inp, "%i", &num_atoms);
|
||||
fclose (f_inp);
|
||||
ch_type_atoms = (char *) malloc (2 * num_atoms * sizeof (char));
|
||||
coords = (float *) malloc (3 * 8 * num_atoms * sizeof (float));
|
||||
label_mol = (int *) malloc (8 * num_atoms * sizeof (int));
|
||||
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
|
||||
if ((ch_type_atoms == NULL) ||
|
||||
(coords == NULL) ||
|
||||
(label_mol == NULL) ||
|
||||
(needed_mol == NULL) ||
|
||||
(tmp_int == NULL) ||
|
||||
(true_label_mol == NULL))
|
||||
{
|
||||
print_message (quiet, stderr, log, f_log, 19, argv[0]);
|
||||
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",
|
||||
' ', aglinp, ' ', input, ' ', output, ' ', log, ' ', quiet, ' ', cell[0], cell[1], cell[2]);
|
||||
print_message (quiet, stdout, log, f_log, 5, tmp_str);
|
||||
|
||||
print_message (quiet, stdout, log, f_log, 6, argv[0]);
|
||||
|
||||
// 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);
|
||||
print_message (quiet, stdout, log, f_log, 8, tmp_str);
|
||||
// reading coordinates
|
||||
print_message (quiet, stdout, log, f_log, 7, input);
|
||||
error = 1;
|
||||
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
|
||||
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 = 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, 4, argv[0]);
|
||||
error = 1;
|
||||
error = print_structure (output, num_needed_mol, needed_mol, num_atoms,
|
||||
label_mol, ch_type_atoms, coords);
|
||||
}
|
||||
if (error == 0)
|
||||
print_message (quiet, stderr, log, f_log, 12, output);
|
||||
|
||||
print_message (quiet, stderr, log, f_log, 13, argv[0]);
|
||||
|
||||
print_message (quiet, stdout, log, f_log, 15, argv[0]);
|
||||
// free memory
|
||||
free (ch_type_atoms);
|
||||
free (centr_coords);
|
||||
free (coords);
|
||||
free (label_mol);
|
||||
free (needed_mol);
|
||||
free (tmp_int);
|
||||
free (true_label_mol);
|
||||
|
||||
print_message (quiet, stdout, log, f_log, 16, argv[0]);
|
||||
|
||||
if (log == 1)
|
||||
fclose (f_log);
|
||||
return 0;
|
||||
}
|
119
mathmech/mm_agl/src/messages.c
Normal file
119
mathmech/mm_agl/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, "%6cAglomerate 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;
|
||||
}
|
14
mathmech/mm_agl/src/messages.h
Normal file
14
mathmech/mm_agl/src/messages.h
Normal 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 */
|
69
mathmech/mm_agl/src/print_struct.c
Normal file
69
mathmech/mm_agl/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;
|
||||
}
|
15
mathmech/mm_agl/src/print_struct.h
Normal file
15
mathmech/mm_agl/src/print_struct.h
Normal 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 */
|
51
mathmech/mm_agl/src/read_agl.c
Normal file
51
mathmech/mm_agl/src/read_agl.c
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
/* Library for reading aglomerate 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 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);
|
||||
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;
|
||||
}
|
14
mathmech/mm_agl/src/read_agl.h
Normal file
14
mathmech/mm_agl/src/read_agl.h
Normal 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 */
|
69
mathmech/mm_agl/src/select_mol.c
Normal file
69
mathmech/mm_agl/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;
|
||||
}
|
14
mathmech/mm_agl/src/select_mol.h
Normal file
14
mathmech/mm_agl/src/select_mol.h
Normal 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
mathmech/mm_agl/src/set_center.c
Normal file
61
mathmech/mm_agl/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;
|
||||
}
|
14
mathmech/mm_agl/src/set_center.h
Normal file
14
mathmech/mm_agl/src/set_center.h
Normal 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 */
|
Reference in New Issue
Block a user