fixed trj2pdb and trj

This commit is contained in:
arcan1s
2014-01-28 05:48:38 +04:00
parent 26fc6b9e7e
commit f124bfbcdd
5 changed files with 132 additions and 117 deletions

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include "add_main.h"
#include <mathmech/messages.h> #include <mathmech/messages.h>
@ -12,25 +13,6 @@
*/ */
int error_checking (const char *input, const char *input_at, const char *output, int error_checking (const char *input, const char *input_at, const char *output,
const int step, const int type) const int step, const int type)
/**
* @brief function that checks errors in input variables
* @code
* error_checking (cell, from, input, num_needed_at, needed_at, output, to);
* @endcode
*
* @param input input file name
* @param input_at input file name with atom types
* @param output output file name
* @param step number of trajectory steps
* @param type type of trajectory
*
* @return 11 - error in 'input_at'
* @return 12 - error in 'input'
* @return 13 - error in 'output'
* @return 14 - error in 'step'
* @return 15 - error in 'type'
* @return 0 - exit without errors
*/
{ {
if (input_at[0] == '#') if (input_at[0] == '#')
return 11; return 11;
@ -52,21 +34,6 @@ int error_checking (const char *input, const char *input_at, const char *output,
*/ */
int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log,
const int mode, const char *str) 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)) if ((quiet != 1) && (std_output != stderr))
message (0, mode, str, std_output); message (0, mode, str, std_output);
@ -82,23 +49,6 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log
*/ */
int set_defaults (char *input, char *input_at, int *log, char *output, int *step, int set_defaults (char *input, char *input_at, int *log, char *output, int *step,
int *total_types, int *type, int *quiet) int *total_types, int *type, int *quiet)
/**
* @brief function that sets default values of variables
* @code
* set_defaults (input, input_at, &log, output, &step, &type, &quiet);
* @endcode
*
* @param input input file name
* @param input_at input file name with atom types
* @param log status of log-mode
* @param output output file name
* @param step number of trajectory steps
* @param total_types number of different atom types
* @param type type of trajectory
* @param quiet status of quiet-mode
*
* @return 0 - exit without errors
*/
{ {
input[0] = '#'; input[0] = '#';
input_at[0] = '#'; input_at[0] = '#';

View File

@ -5,18 +5,77 @@
#ifndef ADD_MAIN_H #ifndef ADD_MAIN_H
#define ADD_MAIN_H #define ADD_MAIN_H
/** /**
* @fn error_checking * @fn error_checking
*/ */
int error_checking (const char *input, const char *input_at, const char *output,
const int step, const int type);
/**
* @brief function that checks errors in input variables
* @code
* error_checking (input, input_at, output, step, type);
* @endcode
*
* @param input input file name
* @param input_at input file name with atom types
* @param output output file name
* @param step number of trajectory steps
* @param type type of trajectory
*
* @return 11 - error in 'input_at'
* @return 12 - error in 'input'
* @return 13 - error in 'output'
* @return 14 - error in 'step'
* @return 15 - error in 'type'
* @return 0 - exit without errors
*/
/** /**
* @fn print_message * @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
*/
/** /**
* @fn set_defaults * @fn set_defaults
*/ */
int set_defaults (char *input, char *input_at, int *log, char *output, int *step,
int *total_types, int *type, int *quiet);
/**
* @brief function that sets default values of variables
* @code
* set_defaults (input, input_at, &log, output, &step, &total_types, &type, &quiet);
* @endcode
*
* @param input input file name
* @param input_at input file name with atom types
* @param log status of log-mode
* @param output output file name
* @param step number of trajectory steps
* @param total_types number of different atom types
* @param type type of trajectory
* @param quiet status of quiet-mode
*
* @return 0 - exit without errors
*/
int error_checking (const char *, const char *, const char *, const int, const int);
int print_message (const int, FILE *, const int, FILE *, const int, const char *);
int set_defaults (char *, char *, int *, char *, int *, int *, int *, int *);
#endif /* ADD_MAIN_H */ #endif /* ADD_MAIN_H */

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include "add_main.h"
#include <mathmech/messages.h> #include <mathmech/messages.h>
@ -11,21 +12,6 @@
* @fn error_checking * @fn error_checking
*/ */
int error_checking (const const char *input, const char *output) int error_checking (const const char *input, const char *output)
/**
* @brief function that checks errors in input variables
* @code
* error_checking (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 'input'
* @return 12 - error in 'output'
* @return 0 - exit without errors
*/
{ {
if (input[0] == '#') if (input[0] == '#')
return 11; return 11;
@ -41,21 +27,6 @@ int error_checking (const const char *input, const char *output)
*/ */
int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log,
const int mode, const char *str) 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)) if ((quiet != 1) && (std_output != stderr))
message (0, mode, str, std_output); message (0, mode, str, std_output);
@ -70,19 +41,6 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log
* @fn set_defaults * @fn set_defaults
*/ */
int set_defaults (char *input, int *log, char *output, int *quiet) int set_defaults (char *input, int *log, char *output, int *quiet)
/**
* @brief function that sets default values of variables
* @code
* set_defaults (input, &log, output, &quiet);
* @endcode
*
* @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
*/
{ {
input[0] = '#'; input[0] = '#';
*log = 0; *log = 0;

View File

@ -5,18 +5,67 @@
#ifndef ADD_MAIN_H #ifndef ADD_MAIN_H
#define ADD_MAIN_H #define ADD_MAIN_H
/** /**
* @fn error_checking * @fn error_checking
*/ */
int error_checking (const const char *input, const char *output);
/**
* @brief function that checks errors in input variables
* @code
* error_checking (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 'input'
* @return 12 - error in 'output'
* @return 0 - exit without errors
*/
/** /**
* @fn print_message * @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
*/
/** /**
* @fn set_defaults * @fn set_defaults
*/ */
int set_defaults (char *input, int *log, char *output, int *quiet);
/**
* @brief function that sets default values of variables
* @code
* set_defaults (input, &log, output, &quiet);
* @endcode
*
* @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 error_checking (const char *, const char *);
int print_message (const int, FILE *, const int, FILE *, const int, const char *);
int set_defaults (char *, int *, char *, int *);
#endif /* ADD_MAIN_H */ #endif /* ADD_MAIN_H */

View File

@ -9,9 +9,9 @@
#include "add_main.h" #include "add_main.h"
#include <version.h> #include <version.h>
#include <mathmech/coords.h>
#include <mathmech/messages.h> #include <mathmech/messages.h>
#include <mathmech/print_struct.h> #include <mathmech/print_struct.h>
#include <mathmech/var_types.h>
/** /**
@ -31,22 +31,21 @@ int main(int argc, char *argv[])
FILE *f_inp, *f_log; FILE *f_inp, *f_log;
char input[256], logfile[256], output[256]; char input[256], logfile[256], output[256];
float cell[3]; int log, *needed_mol, quiet, *true_label_mol;
int log, *needed_mol, num_atoms, num_mol, quiet, *true_label_mol;
atom_info *_atom_info; atom_info *_atom_info;
system_info _system_info;
/* input input file name /* input input file name
* logfile log file name * logfile log file name
* output output file name * output output file name
* *
* cell sell size
*
* log status of log-mode * log status of log-mode
* needed_mol massive of numbers of needed molecule * needed_mol massive of numbers of needed molecule
* num_atoms number of atoms * num_atoms number of atoms
* num_mol number of molecules * num_mol number of molecules
* quiet status of quiet-mode * quiet status of quiet-mode
* true_label_mol massive of true numbers of molecule for atoms * true_label_mol massive of true numbers of molecule for atoms
*
* _atom_info atom information structure * _atom_info atom information structure
*/ */
@ -128,11 +127,11 @@ int main(int argc, char *argv[])
print_message (quiet, stderr, log, f_log, 18, input); print_message (quiet, stderr, log, f_log, 18, input);
return 2; return 2;
} }
fscanf (f_inp, "%i", &num_atoms); fscanf (f_inp, "%i", &_system_info.num_atoms);
fclose (f_inp); fclose (f_inp);
_atom_info = (atom_info *) malloc (8 * num_atoms * sizeof (atom_info)); _atom_info = (atom_info *) malloc (8 * _system_info.num_atoms * sizeof (atom_info));
needed_mol = (int *) malloc (num_atoms * sizeof (int)); needed_mol = (int *) malloc (_system_info.num_atoms * sizeof (int));
true_label_mol = (int *) malloc (num_atoms * sizeof (int)); true_label_mol = (int *) malloc (_system_info.num_atoms * sizeof (int));
// error checking // error checking
if ((_atom_info == NULL) || if ((_atom_info == NULL) ||
(needed_mol == NULL) || (needed_mol == NULL) ||
@ -142,7 +141,7 @@ int main(int argc, char *argv[])
return 3; return 3;
} }
for (i=0; i<3; i++) for (i=0; i<3; i++)
cell[i] = 0.0; _system_info.cell[i] = 0.0;
sprintf (tmp_str, "%6cInput file: '%s';\n%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n", sprintf (tmp_str, "%6cInput file: '%s';\n%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n",
' ', input, ' ', output, ' ', log, ' ', quiet); ' ', input, ' ', output, ' ', log, ' ', quiet);
print_message (quiet, stdout, log, f_log, 5, tmp_str); print_message (quiet, stdout, log, f_log, 5, tmp_str);
@ -152,18 +151,18 @@ int main(int argc, char *argv[])
// reading coordinates // reading coordinates
print_message (quiet, stdout, log, f_log, 7, input); print_message (quiet, stdout, log, f_log, 7, input);
error = 1; error = 1;
error = reading_coords (1, input, tmp_int, &tmp_int, cell, &num_mol, &num_atoms, error = reading_coords (1, input, tmp_int, &tmp_int, &_system_info, true_label_mol,
true_label_mol, _atom_info); _atom_info);
// print coordinates // print coordinates
if (error == 0) if (error == 0)
{ {
sprintf (tmp_str, "%6cNumber of molecules: %i; %6cNumber of atoms: %i\n", sprintf (tmp_str, "%6cNumber of molecules: %i; %6cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms); ' ', _system_info.num_mol, ' ', _system_info.num_atoms);
for (i=0; i<num_mol; i++) for (i=0; i<_system_info.num_mol; i++)
needed_mol[i] = 8 * i; needed_mol[i] = 8 * i;
error = 1; error = 1;
error = print_structure (output, num_mol, needed_mol, num_atoms, _atom_info); error = print_structure (output, _system_info.num_mol, needed_mol, _system_info, _atom_info);
} }
if (error == 0) if (error == 0)
print_message (quiet, stderr, log, f_log, 12, output); print_message (quiet, stderr, log, f_log, 12, output);