Bsoft  2.1.0
Bernard's software package
bcatmol.cpp
Go to the documentation of this file.
1 
9 #include "rwmolecule.h"
10 #include "mol_transform.h"
11 #include "mol_util.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
19 
20 // Usage assistance
21 const char* use[] = {
22 " ",
23 "Usage: bcatmol [options] input.pdb [input2.pdb ...]",
24 "---------------------------------------------------",
25 "Concatenates sets of coordinates with shifts from sets of files.",
26 " ",
27 "Actions:",
28 "-select CA Atom selection (default all).",
29 "-rename D Rename molecules from the given letter.",
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbosity of output.",
33 "-box 10,10,10 Size of enclosing box (angstrom, default from coordinates).",
34 "-pbc Resolve periodic boundary bonds before catenation.",
35 " ",
36 "Input:",
37 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
38 " ",
39 "Output:",
40 "-output output.pdb Output coordinate file (default temp.pdb).",
41 " ",
42 NULL
43 };
44 
45 int main(int argc, char **argv)
46 {
47  // Initialize variables
48  Bstring atom_select("all"); // Selection
49  Vector3<double> box; // Size of enclosing box, default from coordinates
50  int set_pbc(0); // Flag for resolving wrapped coordinates
51  char first_name(0); // First molecule name for renaming
52  Bstring catfile("temp.pdb"); // Default output file
53  Bstring paramfile; // Use default parameter file
54 
55  int optind;
56  Boption* option = get_option_list(use, argc, argv, optind);
57  Boption* curropt;
58  for ( curropt = option; curropt; curropt = curropt->next ) {
59  if ( curropt->tag == "select" ) {
60  atom_select = curropt->value;
61  if ( atom_select.length() < 1 )
62  cerr << "-select: A selection must be specified!" << endl;
63  }
64  if ( curropt->tag == "rename" )
65  if ( ( first_name = curropt->value[0] ) < 1 )
66  cerr << "-rename: The first molecule name must be specified!" << endl;
67  if ( curropt->tag == "box" ) {
68  box = curropt->vector3();
69  if ( box.volume() < 1 )
70  cerr << "-box: All three dimensions must be specified" << endl;
71  }
72  if ( curropt->tag == "pbc" )
73  set_pbc = 1; // Resolve periodic boundaries
74  if ( curropt->tag == "parameters" )
75  paramfile = curropt->filename();
76  if ( curropt->tag == "output" )
77  catfile = curropt->filename();
78  }
79  option_kill(option);
80 
81  double ti = timer_start();
82 
83  if ( !catfile.length() ) {
84  cerr << "Error: No output file name given!" << endl;
85  bexit(-1);
86  }
87 
88  // Read all the parameter files
89  Bstring* file_list = NULL;
90  while ( optind < argc ) string_add(&file_list, argv[optind++]);
91  if ( !file_list ) {
92  cerr << "Error: No molecule files specified!" << endl;
93  bexit(-1);
94  }
95 
96  Bmolgroup* molgroup = read_molecule(file_list, set_pbc, box, atom_select, paramfile);
97 
98  if ( first_name )
99  molgroup_rename(molgroup, first_name);
100 
101  molecule_update_comment(molgroup, argc, argv);
102  write_molecule(catfile, molgroup);
103 
104  molgroup_kill(molgroup);
105 
106  if ( verbose & VERB_TIME )
107  timer_report(ti);
108 
109  bexit(0);
110 }
111 
Boption
A class for a command line input option.
Definition: options.h:26
verbose
int verbose
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
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:1467
Bstring
Definition: Bstring.h:29
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
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
options.h
Header file for option handlers.
mol_transform.h
Library routines used for atomic coordinate transformations.
Boption::tag
Bstring tag
Definition: options.h:29
rwmolecule.h
Header file for reading reflection files.
Boption::value
Bstring value
Definition: options.h:30
timer.h
Utilities for timing functions.
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
utilities.h
Header file for general utilities.
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
Vector3::volume
double volume()
Definition: Vector3.h:237
molgroup_rename
int molgroup_rename(Bmolgroup *molgroup, char first_name)
Renames molecules.
Definition: mol_util.cpp:161
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
Bmolgroup
Definition: rwmolecule.h:170
use
const char * use[]
Definition: bcatmol.cpp:21
main
int main(int argc, char **argv)
Definition: bcatmol.cpp:45
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
mol_util.h
Library routines used for atomic coordinates.