Release envir-1.0.1

* edited shared library
- deleted binary file and archive
This commit is contained in:
arcan1s
2013-07-24 18:04:32 +04:00
parent 69d9cf2936
commit 815fce8045
32 changed files with 4908 additions and 256 deletions

View File

@ -0,0 +1,81 @@
ATOM 1 CL MOL 1 -2.664 11.890 -17.525
ATOM 2 CA MOL 1 -0.917 12.008 -17.545
ATOM 3 CA MOL 1 -0.265 12.628 -16.449
ATOM 4 CA MOL 1 1.141 12.679 -16.437
ATOM 5 CA MOL 1 1.865 12.184 -17.521
ATOM 6 CA MOL 1 1.222 11.648 -18.663
ATOM 7 CA MOL 1 -0.191 11.514 -18.640
ATOM 8 HC MOL 1 -0.936 12.995 -15.629
ATOM 9 HC MOL 1 1.720 13.106 -15.622
ATOM 10 HC MOL 1 2.954 12.258 -17.471
ATOM 11 HC MOL 1 1.854 11.343 -19.523
ATOM 12 HC MOL 1 -0.575 11.044 -19.540
ATOM 13 CL MOL 2 -6.134 15.323 -13.160
ATOM 14 CA MOL 2 -6.616 14.489 -14.639
ATOM 15 CA MOL 2 -5.740 13.483 -15.125
ATOM 16 CA MOL 2 -6.152 12.814 -16.307
ATOM 17 CA MOL 2 -7.335 13.116 -16.943
ATOM 18 CA MOL 2 -8.190 14.137 -16.492
ATOM 19 CA MOL 2 -7.807 14.850 -15.301
ATOM 20 HC MOL 2 -4.814 13.230 -14.622
ATOM 21 HC MOL 2 -5.487 12.040 -16.714
ATOM 22 HC MOL 2 -7.577 12.578 -17.866
ATOM 23 HC MOL 2 -9.151 14.499 -16.876
ATOM 24 HC MOL 2 -8.450 15.630 -14.941
ATOM 25 CL MOL 3 -2.291 10.911 -13.849
ATOM 26 CT MOL 3 -4.546 8.879 -13.092
ATOM 27 CA MOL 3 -3.302 8.337 -13.634
ATOM 28 CA MOL 3 -3.217 6.974 -13.798
ATOM 29 CA MOL 3 -2.019 6.430 -14.303
ATOM 30 CA MOL 3 -0.898 7.214 -14.678
ATOM 31 CA MOL 3 -1.007 8.608 -14.483
ATOM 32 CA MOL 3 -2.180 9.166 -13.977
ATOM 33 HC MOL 3 -4.397 9.808 -12.580
ATOM 34 HC MOL 3 -5.405 9.060 -13.843
ATOM 35 HC MOL 3 -4.909 8.193 -12.354
ATOM 36 HC MOL 3 -3.970 6.222 -13.557
ATOM 37 HC MOL 3 -1.981 5.395 -14.406
ATOM 38 HC MOL 3 -0.061 6.767 -15.059
ATOM 39 HC MOL 3 -0.201 9.202 -14.754
ATOM 40 CL MOL 4 2.265 8.067 -16.401
ATOM 41 CT MOL 4 4.304 6.644 -14.331
ATOM 42 CA MOL 4 4.338 6.294 -15.835
ATOM 43 CA MOL 4 5.247 5.306 -16.251
ATOM 44 CA MOL 4 5.322 4.933 -17.599
ATOM 45 CA MOL 4 4.536 5.582 -18.550
ATOM 46 CA MOL 4 3.626 6.566 -18.144
ATOM 47 CA MOL 4 3.505 6.893 -16.799
ATOM 48 HC MOL 4 4.424 5.830 -13.614
ATOM 49 HC MOL 4 5.154 7.258 -14.121
ATOM 50 HC MOL 4 3.454 7.240 -14.005
ATOM 51 HC MOL 4 5.828 4.872 -15.488
ATOM 52 HC MOL 4 5.986 4.115 -17.892
ATOM 53 HC MOL 4 4.692 5.261 -19.616
ATOM 54 HC MOL 4 2.976 7.091 -18.806
ATOM 55 CL MOL 5 -2.477 15.433 -17.197
ATOM 56 CA MOL 5 -3.971 16.235 -16.853
ATOM 57 CA MOL 5 -4.072 17.013 -15.698
ATOM 58 CA MOL 5 -5.276 17.755 -15.484
ATOM 59 CA MOL 5 -6.309 17.673 -16.459
ATOM 60 CA MOL 5 -6.182 16.896 -17.601
ATOM 61 CA MOL 5 -5.009 16.172 -17.784
ATOM 62 HC MOL 5 -3.234 17.123 -14.977
ATOM 63 HC MOL 5 -5.390 18.375 -14.614
ATOM 64 HC MOL 5 -7.255 18.222 -16.363
ATOM 65 HC MOL 5 -7.001 16.802 -18.354
ATOM 66 HC MOL 5 -5.054 15.588 -18.738
ATOM 67 CL MOL 6 4.729 13.255 -14.510
ATOM 68 CT MOL 6 4.715 14.006 -11.534
ATOM 69 CA MOL 6 3.736 12.879 -11.996
ATOM 70 CA MOL 6 2.904 12.242 -11.010
ATOM 71 CA MOL 6 2.037 11.182 -11.384
ATOM 72 CA MOL 6 1.961 10.754 -12.723
ATOM 73 CA MOL 6 2.804 11.402 -13.660
ATOM 74 CA MOL 6 3.692 12.421 -13.322
ATOM 75 HC MOL 6 5.739 13.830 -11.938
ATOM 76 HC MOL 6 4.503 15.011 -11.742
ATOM 77 HC MOL 6 4.934 14.104 -10.476
ATOM 78 HC MOL 6 2.865 12.507 -9.941
ATOM 79 HC MOL 6 1.422 10.678 -10.663
ATOM 80 HC MOL 6 1.383 9.975 -13.034
ATOM 81 HC MOL 6 2.733 11.097 -14.681

61
envir/src/CMakeLists.txt Normal file
View File

@ -0,0 +1,61 @@
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})
## set files
# main files
set (MAIN_SOURCES main)
# not public srcs
set (PRIVATE_CLASSES)
# headers only files
SET (HEADERS_ONLY)
# public srcs
set (PUBLIC_CLASSES add_main
coords
envir_search
messages
print_struct
set_center)
# public headers
set (PUBLIC_HEADERS)
# shared libraries
if (CMAKE_COMPILER_IS_GNUCXX)
set (ADDITIONAL_LIB m)
else ()
set (ADDITIONAL_LIB)
endif()
set (SOURCES)
# append list
foreach (class ${PRIVATE_CLASSES})
LIST (APPEND SOURCES ${class}.c)
LIST (APPEND HEADERS ${class}.h)
endforeach ()
foreach (class ${HEADERS_ONLY})
LIST (APPEND HEADERS ${class}.h)
endforeach ()
foreach (class ${PUBLIC_CLASSES})
LIST (APPEND SOURCES ${class}.c)
LIST (APPEND HEADERS ../include/${PROJECT}/${class}.h)
LIST (APPEND PUBLIC_HEADERS ../include/${PROJECT}/${class}.h)
endforeach ()
# message
message (STATUS "SOURCES: ${SOURCES}")
# link libraries and compile
add_executable (${PROJECT} ${MAIN_SOURCES} ${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 ()

21
envir/src/Makefile Normal file
View File

@ -0,0 +1,21 @@
PROJECT=ENVIR
CC=gcc
CFLAGS=-c -Wall -fPIC
LDFLAGS=-lm
SOURCES_DIR=src
SOURCES=main.c add_main.c coords.c envir_search.c messages.c print_struct.c set_center.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=envir
$(PROJECT): $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f *.o

49
envir/src/add_main.c Normal file
View File

@ -0,0 +1,49 @@
/* Additional library for main.c (envir)
*/
#include <stdio.h>
// #include "messages.h"
int error_checking (const float *cell, const char *input, const char *output)
{
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;
return 0;
}
int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log,
const int mode, const char *str)
{
if ((quiet != 1) && (std_output != stderr))
message (0, mode, str, std_output);
if (log == 1)
message (1, mode, str, f_log);
return 0;
}
int set_defaults (float *cell, char *input, int *log, int *num_of_mol, char *output,
int *quiet, float *rad)
{
int i;
for (i=0; i<3; i++)
cell[i] = 0.0;
input[0] = '#';
*log = 0;
*num_of_mol = 1;
output[0] = '#';
*quiet = 0;
*rad = 6.0;
return 0;
}

313
envir/src/coords.c Normal file
View File

@ -0,0 +1,313 @@
/* Library for reading coordinates from input file
*
* Usage:
* reading_coords (mode, filename, type_interaction, labels,
* cell, &number_of_molecules, &number_of_atoms, true_label_molecule,
* label_molecule, type_atoms, coords, char_type_atoms)
*/
#include <stdio.h>
#include <stdlib.h>
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)
/* filename - name of file with coordinates
* type_inter - type interaction (number of molecules for interaction)
* label_atom - types of atom for interaction
* cell - cell dimension
* num_mol - number of molecules for writing coordinates
* num_atoms - number of atoms for writing coordinates
* true_label_mol - massive of true numbers of molecule for atoms
* label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms
* coords - massive of coordinates
* ch_type_atoms - massive of char types for atoms
*/
{
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_*, at_symb - temp variables
* file_string - temp string variable
* atoms - total number of atoms in system
* tr_num_atoms - number of translated atoms for writing coordinates (m.b. 8*num_atoms)
* ref_mol - number of molecule for reference
* not_tr_coords - not translated coordinates
* ref - coordinates of reference molecule
* inp - file with input data
*/
*num_atoms = 0;
*num_mol = 0;
// Reading file
inp = fopen (filename, "r");
if (inp == NULL)
return 1;
ref_mol = -1;
fscanf (inp, "%i", &atoms);
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);
switch (mode)
{
case 0:
// for statgen
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:
// for envir
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 1;
}
}
fclose (inp);
// Translation
tr_num_atoms = *num_atoms;
for (i=0; i<*num_atoms; i++)
for (j=0; j<3; j++)
coords[3*i+j] = not_tr_coords[3*i+j];
// Assign initial value to reference coordinates
ref_mol = label_mol[0];
for (i=0; i<3; i++)
ref[i] = coords[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++;
}
}
// free memory
free (not_tr_coords);
return 0;
}

40
envir/src/envir_search.c Normal file
View File

@ -0,0 +1,40 @@
/* Library for search environment
*
* Usage:
* search_envir (number_of_molecule, num_mol, centr_coords, rad, needed_mol,
* &num_needed_mol)
*/
#include <math.h>
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)
/* num_of_mol - number of molecule for search
* num_mol - number of molecules for writing coordinates
* centr_coords - massive of centered coordinates
* rad - criterion
* needed_mol - massive of needed molecules
* num_needed_mol - number of needed molecules
*/
{
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;
}

220
envir/src/main.c Normal file
View File

@ -0,0 +1,220 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include "add_main.h"
// #include "coords.h"
// #include "envir_search.h"
// #include "messages.h"
// #include "print_struct.h"
// #include "set_center.h"
int main(int argc, char *argv[])
{
char tmp_str[2048];
int error, i, j, *tmp_int;
FILE *f_inp, *f_log;
char *ch_type_atoms, input[256], logfile[256], output[256];
float cell[3], *centr_coords, *coords, rad;
int *label_mol, log, num_atoms, num_mol, num_needed_mol, num_of_mol,
*needed_mol, quiet, *true_label_mol;
/* ch_type_atoms - massive of char types for atoms
* input - input file name
* logfile - log file name
* output - output file name
*
* cell - cell dimension
* centr_coords - massive of coordinates of center molecules
* coords - massive of coordinates
* rad - criterion
*
* 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
* num_of_mol - number of molecule for search
* needed_mol - massive of needed molecules
* quiet - status of quiet-mode
* true_label_mol - massive of true numbers of molecule for atoms
*/
set_defaults (cell, input, &log, &num_of_mol, output, &quiet, &rad);
for (i=1; i<argc; i++)
{
if ((argv[i][0] == '-') && (argv[i][1] == 'h'))
{
sprintf (tmp_str, " envir\n");
sprintf (tmp_str, "%sProgram for search environment for chosen molecule by geometric criterion\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, "%senvir -i FILENAME -c X,Y,Z -o FILEMANE [ -n NUM_OF_MOLECULE ] [ -r RADIUS ] [ -l LOGFILE] [ -q ] [ -h ]\n\n", tmp_str);
sprintf (tmp_str, "%sParametrs:\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 with coordinates\n", tmp_str);
sprintf (tmp_str, "%s -n - number of molecule for search (integer). Default is 1\n", tmp_str);
sprintf (tmp_str, "%s -r - radius of environment (float). Default is 6.0\n", tmp_str);
sprintf (tmp_str, "%s -l - log enable\n", tmp_str);
sprintf (tmp_str, "%s -q - quiet enable\n", tmp_str);
sprintf (tmp_str, "%s -h - show this help and exit\n", tmp_str);
fputs (tmp_str, stdout);
return 0;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'i'))
// input file
{
strcpy (input, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'c'))
// cell size
{
sscanf (argv[i+1], "%f,%f,%f", &cell[0], &cell[1], &cell[2]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'o'))
// output file
{
strcpy (output, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'n'))
// number of molecule
{
sscanf (argv[i+1], "%i", &num_of_mol);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
// radius of environment
{
sscanf (argv[i+1], "%f", &rad);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'l'))
// log mode
{
log = 1;
strcpy (logfile, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'q'))
// quiet mode
{
quiet = 1;
}
}
if (log == 1)
f_log = fopen (logfile, "w");
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 (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 1;
}
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));
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) ||
(tmp_int == NULL) ||
(true_label_mol == NULL))
{
print_message (quiet, stderr, log, f_log, 19, argv[0]);
return 17;
}
sprintf (tmp_str, "%6cInput file: '%s';\n%6cOutput file: '%s';\n%6cLog: %i;\n\
%6cQuiet: %i;\n%6cCell size: %.4f, %.4f, %.4f;\n%6cSelect molecule: %i;\n\
%6cCriterion: %.1f\n", ' ', input, ' ', output, ' ', log, ' ', quiet, ' ', cell[0],
cell[1], cell[2], ' ' , num_of_mol, ' ', rad);
print_message (quiet, stdout, log, f_log, 5, tmp_str);
print_message (quiet, stdout, log, f_log, 6, argv[0]);
// 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,
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));
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 checking
if ((centr_coords == NULL) ||
(needed_mol == NULL))
{
print_message (quiet, stderr, log, f_log, 19, argv[0]);
return 17;
}
// analyze
if (error == 0)
{
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 = 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 = 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);
}
}
}
print_message (quiet, stdout, 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;
}

99
envir/src/messages.c Normal file
View File

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

3376
envir/src/oct-clb.150 Executable file

File diff suppressed because it is too large Load Diff

58
envir/src/print_struct.c Normal file
View File

@ -0,0 +1,58 @@
/* 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>
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)
/* output - output file name
* num_needed_mol - number of needed molecules
* needed_mol - massive of needed molecules
* num_atoms - number of atoms
* label_mol - massive of numbers of molecule for atoms
* ch_type_atoms - massive of char types for atoms
* coords - massive of coordinates
*/
{
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
*/
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;
}

52
envir/src/set_center.c Normal file
View File

@ -0,0 +1,52 @@
/* Library for search center mass of molecules
*
* Usage:
* set_center (num_of_atoms, num_of_molecules, label_molecules, coords,
* centr_coords)
*/
int set_center (const int num_atoms, const int num_mol, const int *label_mol,
const float *coords, float *centr_coords)
/* num_atoms - number of atoms for writing coordinates
* num_mol - number of molecules for writing coordinates
* label_mol - massive of numbers of molecule for atoms
* coords - massive of coordinates
* coords - massive of coordinates of center molecules
*/
{
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;
}