| Bsoft 2.0.5 Bernard's software package

bsplitmol.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "utilities.h"
11 #include "options.h"
12 #include "timer.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 // Usage assistance
18 const char* use[] = {
19 " ",
20 "Usage: bsplitmol [options] input.pdb output.pdb",
21 "-----------------------------------------------",
22 "Splits sets of coordinates to different numbered files.",
23 " ",
24 "Parameters:",
25 "-verbose 7 Verbosity of output.",
26 "-first 5 Number given to the first file (default 0).",
27 "-digits 3 Number of digits inserted before the last period in the output file name.",
28 " ",
29 "Input:",
30 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
31 " ",
32 NULL
33 };
34
35 int main(int argc, char **argv)
36 {
37 // Initialize variables
38 Bstring atom_select("all"); // Selection
39 int first_number(0); // Number given to first file
40 int digits(3); // File number size
41 Bstring paramfile = NULL; // Use default parameter file
42
43 int optind;
44 Boption* option = get_option_list(use, argc, argv, optind);
45 Boption* curropt;
46 for ( curropt = option; curropt; curropt = curropt->next ) {
47 if ( curropt->tag == "first" )
48 if ( ( first_number = curropt->value.integer() ) < 0 )
49 cerr << "-first: A number must be specified!" << endl;
50 if ( curropt->tag == "digits" )
51 if ( ( digits = curropt->value.integer() ) < 1 )
52 cerr << "-digits: A number of digits must be specified!" << endl;
53 if ( curropt->tag == "parameters" )
54 paramfile = curropt->filename();
55 }
56 option_kill(option);
57
58 double ti = timer_start();
59
60 Bstring inputfile = argv[optind++];
61 Bmolgroup* molgroup = read_molecule(inputfile, atom_select, paramfile);
62 if ( molgroup == NULL ) {
63 cerr << "Error: No input file read!" << endl;
64 bexit(-1);
65 }
66
67 if ( optind >= argc ) bexit(0);
68
69 long i, nmol = 0;
70 Bmolecule* mol, *mol2;
71 for ( mol=molgroup->mol; mol; mol=mol->next ) nmol++;
72
73 if ( verbose & VERB_LABEL )
74 cout << "Splitting " << inputfile << " up into " << nmol << " files" << endl << endl;
75
76 Bstring outputfile = argv[optind];
77 Bstring filename;
78 char format[32];
79
80 if ( digits < 0.44*log(1.0*nmol) + 1 ) digits = (int) (0.44*log(1.0*nmol) + 1);
81 snprintf(format, 32, "_%%0%dd.", digits);
82
83 Bmolgroup* molgroup_out = molgroup_init();
84 molecule_update_comment(molgroup_out, argc, argv);
85 for ( i=0, mol=molgroup->mol; mol; mol=mol2, i++ ) {
86 mol2 = mol->next;
87 mol->next = NULL;
88 molgroup_out->mol = mol;
89 // filename = number_filename(outputfile, i+first_number, digits);
90 filename = outputfile.pre_rev('.') + Bstring(i+first_number, format) + outputfile.post_rev('.');
91 write_molecule(filename, molgroup_out);
92 molecule_kill(mol);
93 molgroup_out->mol = NULL;
94 }
95
96 molgroup->mol = NULL;
97 molgroup_kill(molgroup);
98 molgroup_kill(molgroup_out);
99
100 if ( verbose & VERB_TIME )
101 timer_report(ti);
102
103 bexit(0);
104 }
105
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
utilities.h
Header file for general utilities.
molecule_kill
int molecule_kill(Bmolecule *mol)
Destroys a molecule.
Definition: rwmolecule.cpp:417
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
use
const char * use[]
Definition: bsplitmol.cpp:18
rwmolecule.h
Header file for reading reflection files.
Bmolgroup
Definition: rwmolecule.h:170
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
molgroup_init
Bmolgroup * molgroup_init()
Initializes and allocates a new molecule group.
Definition: rwmolecule.cpp:45
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bmolecule
Definition: rwmolecule.h:107
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
verbose
int verbose
molecule_update_comment
int molecule_update_comment(Bmolgroup *molgroup, int n, char **strings)
Puts a set of strings and time in the main comment of a molecule group.
Definition: rwmolecule.cpp:1462
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
main
int main(int argc, char **argv)
Definition: bsplitmol.cpp:35
options.h
Header file for option handlers.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
read_molecule
Bmolgroup * read_molecule(const char *filename, const char *select, const char *paramfile)
The generalized function for reading molecular files.
Definition: rwmolecule.cpp:818