| Bsoft 2.0.5 Bernard's software package

bgex.cpp
Go to the documentation of this file.
1
9 #include "molecule_to_map.h"
10 #include "mol_select.h"
11 #include "mol_util.h"
12 #include "rwmolecule.h"
13 #include "rwimg.h"
14 #include "utilities.h"
15 #include "options.h"
16 #include "timer.h"
17
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20
21 /* Usage assistance */
22 const char* use[] = {
23 " ",
24 "Usage: bgex [options] out.pdb out.map",
25 "-------------------------------------",
26 "Calculates and compares atomic models and maps.",
27 "A coordinate file is required.",
28 "If a map file is given, the occupancy of the atoms are calculated.",
29 " ",
30 "Selections:",
31 "-select CA Atom selection (default all).",
32 "-chains B,G,O,Z Select chains or molecules by ID (default all).",
33 "-limits -50.5,10,0,40,-100,-20 Coordinate limits (default -10000,-10000,-10000,10000,10000,10000).",
34 " ",
35 "Actions:",
36 "-potential Calculate an atomic potential map (default simple gaussian expansion).",
37 " ",
38 "Parameters:",
39 "-verbose 7 Verbosity of output.",
40 "-datatype u Force writing of a new image data type.",
41 "-origin 0,0,0 Origin placement within image (default 0,0,0).",
42 "-size 10,10,10 Map size, input map size otherwise (voxels).",
43 "-sampling 1 Sampling (default 1 angstrom/voxel).",
44 "-resolution 3 Resolution (default 2 angstrom, only simple gaussian expansion).",
45 "-wrap Wrap around periodic boundaries (default off).",
46 "-Bfactor 30 Global B-factor (default 0 angstrom squared).",
47 "-symmetry 1 Space group (default 1).",
48 "-unitcell 50,50,50,90,90,90 Unit cell parameters (angstrom & degrees).",
49 " ",
50 "Input:",
51 "-coordinates file.pdb Input coordinate file.",
52 "-map file.map Input map file.",
53 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
54 " ",
55 NULL
56 };
57
58 int main(int argc, char **argv)
59 {
60 // Initialize variables
61 Bstring atom_select("ALL");
62 Bstring chain_select;
63 DataType nudatatype(Unknown_Type); // Conversion to new type
64 Vector3<double> origin; // Coordinate origin placement
65 int set_origin(0); // Flag to set origin
66 Vector3<long> size; // New map size
67 Vector3<double> sam; // Sampling in angstrom/voxel side
68 double resolution(2); // Resolution = 2 angstrom
69 int wrap(0); // No wrapping as default
70 int gextype(0); // Type of gaussian used: 0 = single, 1 = atomic potential
71 double Bfactor(0); // B-factor = 30 angstrom squared
72 int spacegroup(1);
73 UnitCell uc(0,0,0,M_PI_2,M_PI_2,M_PI_2);
74 Bstring coorfile; // Atomic coordinates
75 Bstring mapfile; // Map to compare with
76 Bstring paramfile; // Use default parameter file
77
78 int optind;
79 Boption* option = get_option_list(use, argc, argv, optind);
80 Boption* curropt;
81 for ( curropt = option; curropt; curropt = curropt->next ) {
82 if ( curropt->tag == "select" ) {
83 atom_select = curropt->value;
84 if ( atom_select.length() < 1 )
85 cerr << "-select: A selection must be specified!" << endl;
86 }
87 if ( curropt->tag == "chains" ) {
88 chain_select = curropt->value;
89 if ( chain_select.length() < 1 )
90 cerr << "-chains: A selection must be specified!" << endl;
91 }
92 if ( curropt->tag == "potential" )
93 gextype = 1;
94 if ( curropt->tag == "datatype" )
95 nudatatype = curropt->datatype();
96 if ( curropt->tag == "coordinates" )
97 coorfile = curropt->filename();
98 if ( curropt->tag == "map" )
99 mapfile = curropt->filename();
100 if ( curropt->tag == "origin" ) {
101 if ( curropt->value[0] == 'c' ) {
102 set_origin = 2;
103 } else {
104 origin = curropt->origin();
105 set_origin = 1;
106 }
107 }
108 if ( curropt->tag == "size" )
109 size = curropt->size();
110 if ( curropt->tag == "sampling" )
111 sam = curropt->sampling();
112 if ( curropt->tag == "resolution" )
113 if ( ( resolution = curropt->value.real() ) < 0.001 )
114 cerr << "-resolution: Resolution must be specified!" << endl;
115 if ( curropt->tag == "wrap" )
116 wrap = 1;
117 if ( curropt->tag == "Bfactor" )
118 if ( ( Bfactor = curropt->value.real() ) < 0.001 )
119 cerr << "-Bfactor: The B-factor must be specified!" << endl;
120 if ( curropt->tag == "unitcell" )
121 uc = curropt->unit_cell();
122 if ( curropt->tag == "symmetry" )
123 if ( ( spacegroup = curropt->value.integer() ) < 1 )
124 cerr << "-symmetry: The space group number must be specified!" << endl;
125 if ( curropt->tag == "parameters" )
126 paramfile = curropt->filename();
127 }
128 option_kill(option);
129
130 double ti = timer_start();
131
132 Bmolgroup* molgroup = NULL;
133 Bimage* p = NULL;
134 Bstring ext;
135
136 if ( coorfile.length() ) {
137 molgroup = read_molecule(coorfile, atom_select, paramfile);
138 if ( !molgroup->mol->res ) {
139 cerr << "Error: Problem with coordinate file " << coorfile << ", exiting!" << endl;
140 bexit(-1);
141 }
142 }
143
144 if ( mapfile.length() ) {
145 p = read_img(mapfile, 1, -1);
146 if ( !p ) {
147 cerr << "Error: Map file " << mapfile << " not read!" << endl;
148 bexit(-1);
149 }
150 }
151
152 if ( molgroup == NULL ) {
153 cerr << "Error: No coordinate file given!" << endl;
154 bexit(-1);
155 }
156
157 // Set some parameters from input
158 if ( p ) {
159 if ( set_origin ) {
160 if ( set_origin == 2 ) origin = p->default_origin();
161 } else origin = p->image->origin();
162 if ( sam.volume() > 0 ) p->sampling(sam);
163 if ( size[0] <= 0 || size[1] <= 0 || size[2] <= 0 ) {
164 size = {p->sizeX(), p->sizeY(), p->sizeZ()};
165 if ( !uc.a() ) uc[0] = p->sizeX()*p->sampling()[0];
166 if ( !uc.b() ) uc[1] = p->sizeY()*p->sampling()[1];
167 if ( !uc.c() ) uc[2] = p->sizeZ()*p->sampling()[2];
168 }
169 }
170
171 if ( set_origin == 2 ) origin = {double(size[0]/2), double(size[1]/2), double(size[2]/2)};
172
173 if ( chain_select.length() )
174 molgroup_select_chains(molgroup, chain_select);
175
176 // Calculate the density
177 Bimage* pcalc = img_from_molecule(molgroup, origin,
178 size, sam, resolution, Bfactor, wrap, gextype, spacegroup, uc);
179
180 double mw = molgroup_calculate_weight(molgroup);
181
182 if ( pcalc )
183 pcalc->mass_threshold(0, mw, RHO);
184
185 // If a map is also given, compare it to the generated density
186 if ( p )
187 compare_mol_map(molgroup, pcalc, p);
188
189 // Write output file(s)
190 while ( optind < argc ) {
191 ext = argv[optind];
192 ext = ext.extension();
193 if ( ext.contains("pdb") || ext.contains("gro") ) {
194 if ( molgroup ) write_molecule(argv[optind++], molgroup);
195 } else if ( pcalc ) {
196 pcalc->change_type(nudatatype);
197 pcalc->label(get_cmd_line(argc, argv));
198 write_img(argv[optind++], pcalc, 0);
199 }
200 }
201
202 if ( molgroup ) molgroup_kill(molgroup);
203 if ( p ) delete p;
204 if ( pcalc ) delete pcalc;
205
206 if ( verbose & VERB_TIME )
207 timer_report(ti);
208
209 bexit(0);
210 }
211
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Boption::unit_cell
UnitCell unit_cell()
Definition: options.h:291
M_PI_2
#define M_PI_2
Definition: utilities.h:62
UnitCell
Definition: UnitCell.h:22
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Bstring::real
double real()
Definition: Bstring.cpp:545
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
molecule_to_map.h
Header file for functions to calculate a 3D map from atomic coordinates.
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
Boption::tag
Bstring tag
Definition: options.h:29
mol_select.h
Library routines to select atomic coordinates.
Bstring::length
long length() const
Definition: Bstring.cpp:263
UnitCell::a
void a(double d)
Definition: UnitCell.h:36
compare_mol_map
int compare_mol_map(Bmolgroup *molgroup, Bimage *pcalc, Bimage *pimg)
Compares reference and calculated maps and calculates an occupancy for every atom in the molecule set...
Definition: molecule_to_map.cpp:277
molgroup_select_chains
int molgroup_select_chains(Bmolgroup *molgroup, Bstring chains)
Selects molecules.
Definition: mol_select.cpp:168
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_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
mol_util.h
Library routines used for atomic coordinates.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
rwmolecule.h
Header file for reading reflection files.
use
const char * use[]
Definition: bgex.cpp:22
Bmolgroup
Definition: rwmolecule.h:170
molgroup_calculate_weight
double molgroup_calculate_weight(Bmolgroup *molgroup)
Calculates the weight of each molecule.
Definition: mol_util.cpp:270
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:515
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bimage::mass_threshold
double mass_threshold(long img_num, double mol_weight, double rho)
Finds the density threshold associated with a particular molecular weight.
Definition: Bimage_segment.cpp:834
UnitCell::b
void b(double d)
Definition: UnitCell.h:37
main
int main(int argc, char **argv)
Definition: bgex.cpp:58
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
verbose
int verbose
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< double >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
RHO
#define RHO
Definition: utilities.h:91
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
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
img_from_molecule
Bimage * img_from_molecule(Bmolgroup *molgroup, Vector3< double > origin, Vector3< long > size, Vector3< double > sam, double resolution, double Bfactor, int wrap, int gextype, int spacegroup, UnitCell unit_cell)
Calculates a 3D density map from a set of atomic coordinates.
Definition: molecule_to_map.cpp:53
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
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
UnitCell::c
void c(double d)
Definition: UnitCell.h:38
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
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