| Bsoft 2.0.5 Bernard's software package

bmol.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "mol_transform.h"
11 #include "mol_edit.h"
12 #include "mol_select.h"
13 #include "mol_util.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: bmol [options] in.pdb out.pdb",
25 "------------------------------------",
26 "Edits, analyzes and transforms atomic coordinate files.",
27 " ",
28 "Selections:",
29 "-select CA Atom selection (default all).",
30 "-chains B,G,O,Z Select chains or molecules by ID (default all).",
31 "-limits -50.5,10,0,40,-100,-20 Coordinate limits (default -10000,-10000,-10000,10000,10000,10000).",
32 " ",
33 "Actions:",
34 "-invert 10,-5.3,2.6 Invert through a point.",
35 "-translate 0,-50,22 Translate (angstrom).",
36 "-scale 2,1.5,2.2 Scale the coordinates.",
37 "-rotate 0.5,0,5.8,45 Rotate around a vector (x,y,z) by an angle.",
38 "-toview 0.3,0.5,0.8,33 Rotate to view: vector {xyz} and angle (default 0,0,1,0).",
39 "-fromview 0.3,0.5,0.8,33 Rotate from view: vector {xyz} and angle (default 0,0,1,0).",
40 "-radius 41.8 Force all coordinates to this radius (default not).",
41 "-rename D Rename molecules from the given letter.",
42 "-renumber 52 Renumber residues from the given number.",
43 "-occupancy 27,99,3 Set an occupancy range (res1,res2) to a value.",
44 "-box 15,66,54 Consolidate structure within box (0,0,0 means no change).",
45 "-wrap 15,66,54 Pack coordinates within periodic box.",
46 "-Bfactor Analyze B-factors.",
47 "-Sequence Output sequence as string of letters.",
48 "-Mass Calculate the total molecular weight and volume.",
49 "-Volume 1 Calculate the Van der Waals volume, wrapping flag (default 0).",
50 "-Composition Calculate the composition.",
51 "-Center Calculate the center of mass.",
52 "-Translate Translate the coordinate set to the center of mass.",
53 "-Place -43.2,33,0 Place the center-of-mass at the given coordinates.",
54 "-Axes Calculate the orthogonal axes.",
55 "-Radialdensity 0.05,6,1 Calculate the radial density function at a given sampling",
56 " and distance cutoff (angstrom) with optional wrapping.",
57 " ",
58 "Parameters:",
59 "-verbose 7 Verbosity of output.",
60 "-origin 10,-10,20 Origin for rotation (default 0,0,0, can be \"center\" for COM)",
61 " ",
62 "Input:",
63 "-parameters parm.star Atomic properties parameter file (default atom_prop.star).",
64 " ",
65 NULL
66 };
67
68 int main(int argc, char **argv)
69 {
70 /* Initialize variables */
71 Bstring atom_select("ALL");
72 Bstring chain_select;
73 int set_minmax(0); // Flag for setting min and max
74 double rmin(0); // Inner radius
75 double rmax(10000); // Outer radius
76 int set_invert(0);
77 int com_origin(0); // Flag to set the center-of-mass as origin of rotation
78 Vector3<double> point; // Inversion point
79 Transform t; // Transformation details
80 View view; // View to rotate to
81 int rot_from(0); // Rotation from view flag
82 Vector3<double> min(-10000,-10000,-10000); // Coordinate minima
83 Vector3<double> max(10000,10000,10000); // Coordinate maxima
84 Vector3<double> box = max - min; // Enclosing box
85 Vector3<double> place; // Coordinates for placing a molecule
86 char first_name(0); // First molecule name for renaming
87 int first_res(0); // Don't renumber
88 int range_first(0); // For resetting occupancy
89 int range_last(0);
90 double set_radius(0); // Spherical radius to enforce
91 double occupancy(0);
92 int set_occupancy(0); // Flag for setting occupancy
93 int set_pbc(0); // Flag for resolving wrapped coordinates
94 int set_wrap(0); // Flag for wrapping coordinates
95 int show_seq(0); // Flag to show the sequence(s)
96 int show_MW(0); // Flag for calculating the MW(s)
97 int show_Volume(0); // Flag for calculating the Van der Waals volume
98 int show_composition(0); // Flag for calculating the composition
99 int show_COM(0); // Flag for calculating the center of mass
100 int translate_COM(0); // Flag for translating to the center of mass
101 int orth_axes(0); // Flag for calculating orthogonal axes
102 int setBfac(0);
103 double rdf_sampling(0); // Sampling for radial density function
104 double rdf_cutoff(5); // Distance cutoff for radial density function
105 int wrap(0); // No wrapping as default
106 Bstring paramfile; // Use default parameter file
107
108 int optind;
109 Boption* option = get_option_list(use, argc, argv, optind);
110 Boption* curropt;
111 for ( curropt = option; curropt; curropt = curropt->next ) {
112 if ( curropt->tag == "select" ) {
113 atom_select = curropt->value;
114 if ( atom_select.length() < 1 )
115 cerr << "-select: A selection must be specified!" << endl;
116 }
117 if ( curropt->tag == "chains" ) {
118 chain_select = curropt->value;
119 if ( chain_select.length() < 1 )
120 cerr << "-chains: A selection must be specified!" << endl;
121 }
122 if ( curropt->tag == "invert" ) {
123 point = curropt->vector3();
124 set_invert = 1;
125 }
126 if ( curropt->tag == "translate" )
127 t.trans = curropt->vector3();
128 if ( curropt->tag == "scale" )
129 t.scale = curropt->vector3();
130 if ( curropt->tag == "rotate" ) {
131 vector<double> d = curropt->value.split_into_doubles(",");
132 if ( d.size() < 4 )
133 cerr << "-rotate: All three vector elements and an angle must be specified!" << endl;
134 else {
135 t.axis = Vector3<double>(d[0], d[1], d[2]);
136 t.angle = d[3] * M_PI/180.0;
137 }
138 }
139 if ( curropt->tag == "toview" )
140 view = curropt->view();
141 if ( curropt->tag == "fromview" ) {
142 view = curropt->view();
143 rot_from = 1;
144 }
145 if ( curropt->tag == "origin" ) {
146 if ( curropt->value.contains("cen") )
147 com_origin = 1;
148 else
149 t.origin = curropt->origin();
150 }
151 if ( curropt->tag == "limits" ) {
152 if ( curropt->box(min, max) < 6 )
153 cerr << "-limits: All 6 limits must be specified!" << endl;
154 else
155 set_minmax = 1;
156 }
157 if ( curropt->tag == "radius" )
158 if ( ( set_radius = curropt->value.real() ) < 1 )
159 cerr << "-radius: The radius must be specified!" << endl;
160 if ( curropt->tag == "rename" )
161 if ( ( first_name = curropt->value[0] ) < 1 )
162 cerr << "-rename: The first molecule name must be specified!" << endl;
163 if ( curropt->tag == "renumber" )
164 if ( ( first_res = curropt->value.integer() ) < 1 )
165 cerr << "-renumber: The first residue number must be specified!" << endl;
166 if ( curropt->tag == "occupancy" ) {
167 if ( curropt->values(range_first, range_last, occupancy) < 3 )
168 cerr << "-occupancy: A range and value must be specified!" << endl;
169 else
170 set_occupancy = 1;
171 }
172 if ( curropt->tag == "box" ) {
173 box = curropt->size();
174 set_pbc = 1; // Resolve periodic boundaries
175 }
176 if ( curropt->tag == "wrap" ) {
177 box = curropt->size();
178 set_wrap = 1; // Wrap within periodic boundaries
179 }
180 if ( curropt->tag == "Bfactor" )
181 setBfac = 1;
182 if ( curropt->tag == "Sequence" )
183 show_seq = 1;
184 if ( curropt->tag == "Mass" )
185 show_MW = 1;
186 if ( curropt->tag == "Volume" ) {
187 if ( ( show_Volume = curropt->value.integer() ) < 1 )
188 cerr << "-Volume: A wrapping flag must be specified!" << endl;
189 else
190 show_Volume++;
191 }
192 if ( curropt->tag == "Composition" )
193 show_composition = 1;
194 if ( curropt->tag == "Center" )
195 show_COM = 1;
196 if ( curropt->tag == "Translate" )
197 translate_COM = 1;
198 if ( curropt->tag == "Place" )
199 place = curropt->vector3();
200 if ( curropt->tag == "Axes" )
201 orth_axes = 1;
202 if ( curropt->tag == "Radialdensity" )
203 if ( curropt->values(rdf_sampling, rdf_cutoff, wrap) < 1 )
204 cerr << "-Radialdensity: The sampling must be specified!" << endl;
205 if ( curropt->tag == "parameters" )
206 paramfile = curropt->filename();
207 }
208 option_kill(option);
209
210 if ( optind >= argc ) bexit(-1);
211
212 double ti = timer_start();
213
214 Bstring filename(argv[optind++]);
215 Bmolgroup* mgtemp = NULL;
216 Bmolgroup* molgroup = read_molecule(filename, atom_select, paramfile);
217 if ( !molgroup ) {
218 cerr << "Error: Coordinate file not read!" << endl;
219 bexit(-1);
220 }
221
222 if ( chain_select.length() )
223 molgroup_select_chains(molgroup, chain_select);
224
225 /* Select some atoms in a ring between rmin and rmax */
226 if ( ( rmin > 0 ) || ( rmax < 1000 ) )
227 molgroup_coor_select_ring(molgroup, rmin, rmax);
228
229 /* Select atoms between desired limits */
230 if ( set_minmax )
231 molgroup_coor_select(molgroup, min, max);
232
233
234 if ( com_origin )
235 t.origin = molgroup_center_of_mass(molgroup);
236 else if ( show_COM )
237 molgroup_show_center_of_mass(molgroup);
238
239 if ( translate_COM )
240 molgroup_shift_to_center_of_mass(molgroup);
241
242 if ( place.length() > 0 )
243 molgroup_place_at_coordinates(molgroup, place);
244
245 if ( orth_axes )
246 molgroup_principal_axes(molgroup, NULL);
247
248 if ( set_radius )
249 molgroup_set_radius(molgroup, set_radius);
250
251 if ( set_invert )
252 molgroup_coor_invert(molgroup, point);
253
254 if ( fabs(t.scale.volume() - 1) < 1e-10 ) {
255 if ( view[2] < 1 ) {
256 if ( rot_from )
257 mgtemp = molgroup_rotate_from_view(molgroup, view, t.origin, t.trans);
258 else
259 mgtemp = molgroup_rotate_to_view(molgroup, view, t.origin, t.trans);
260 molgroup_kill(molgroup);
261 molgroup = mgtemp;
262 } else if ( t.angle == 0 ) {
263 molgroup_coor_shift(molgroup, t.trans);
264 } else {
265 molgroup_coor_rotate(molgroup, t);
266 }
267 } else {
268 molgroup_coor_transform(molgroup, t);
269 }
270
271 if ( set_pbc || set_wrap ) molgroup->box = box;
272
273 if ( set_pbc ) molgroup_resolve_pbc(molgroup);
274 else if ( set_wrap ) molgroup_pack_in_periodic_box(molgroup);
275
276 molgroup_stats(molgroup);
277
278 if ( setBfac )
279 molgroup_Bfactors(molgroup);
280
281 if ( show_seq )
282 molgroup_print_sequence(molgroup);
283
284 if ( show_MW )
285 molgroup_calculate_weight(molgroup);
286
287 if ( show_Volume )
288 molgroup_volume(molgroup, paramfile, show_Volume-1);
289
290 if ( show_composition )
291 molgroup_composition(molgroup, paramfile);
292
293 if ( first_name )
294 molgroup_rename(molgroup, first_name);
295
296 if ( first_res > 0 )
297 molgroup_residue_renumber(molgroup, first_res);
298
299 if ( set_occupancy )
300 molgroup_coor_reset_occupancy(molgroup, range_first,
301 range_last, occupancy);
302
303 if ( rdf_sampling > 0 )
304 molgroup_radial_density(molgroup, rdf_sampling, rdf_cutoff, wrap);
305
306 if ( optind < argc ) {
307 molecule_update_comment(molgroup, argc, argv);
308 if ( write_molecule(argv[optind], molgroup) < 1 )
309 cerr << "Error: " << argv[optind] << " not written!" << endl;
310 }
311
312 molgroup_kill(molgroup);
313
314 if ( verbose & VERB_TIME )
315 timer_report(ti);
316
317 bexit(0);
318 }
Bstring::real
double real()
Definition: Bstring.cpp:545
molgroup_coor_select_ring
int molgroup_coor_select_ring(Bmolgroup *molgroup, double rmin, double rmax)
Selects atoms in a ring.
Definition: mol_select.cpp:195
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
Vector3::length
double length()
Definition: Vector3.h:222
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
molgroup_composition
int molgroup_composition(Bmolgroup *molgroup, Bstring &paramfile)
Calculates the elemental composition of a molecular system.
Definition: mol_util.cpp:699
Boption::tag
Bstring tag
Definition: options.h:29
Transform::angle
double angle
Definition: Transform.h:29
molgroup_show_center_of_mass
Vector3< double > molgroup_show_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:387
mol_select.h
Library routines to select atomic coordinates.
Bstring::length
long length() const
Definition: Bstring.cpp:263
mol_transform.h
Library routines used for atomic coordinate transformations.
molgroup_select_chains
int molgroup_select_chains(Bmolgroup *molgroup, Bstring chains)
Selects molecules.
Definition: mol_select.cpp:168
molgroup_rotate_from_view
Bmolgroup * molgroup_rotate_from_view(Bmolgroup *molgroup, View view, Vector3< double > origin, Vector3< double > trans)
Rotates a molecule group from a specified view and translates it afterwards.
Definition: mol_transform.cpp:203
molgroup_rename
int molgroup_rename(Bmolgroup *molgroup, char first_name)
Renames molecules.
Definition: mol_util.cpp:161
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
molgroup_pack_in_periodic_box
int molgroup_pack_in_periodic_box(Bmolgroup *molgroup)
Distributes coordinates across periodic box boundaries.
Definition: mol_transform.cpp:513
molgroup_coor_reset_occupancy
int molgroup_coor_reset_occupancy(Bmolgroup *molgroup, int range_first, int range_last, double occupancy)
Sets occupancies to new values..
Definition: mol_util.cpp:243
Boption::filename
Bstring filename()
Definition: options.h:85
molgroup_resolve_pbc
int molgroup_resolve_pbc(Bmolgroup *molgroup)
Recombines coordinates split across periodic box boundaries.
Definition: mol_transform.cpp:450
timer.h
Utilities for timing functions.
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
molgroup_center_of_mass
Vector3< double > molgroup_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:307
mol_util.h
Library routines used for atomic coordinates.
Boption::size
Vector3< long > size()
Definition: options.h:163
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Transform
Definition: Transform.h:24
M_PI
#define M_PI
Definition: utilities.h:59
rwmolecule.h
Header file for reading reflection files.
Bmolgroup
Definition: rwmolecule.h:170
molgroup_stats
long molgroup_stats(Bmolgroup *molgroup, int show)
Calculates the statistics of a molecule group.
Definition: rwmolecule.cpp:1291
Boption::box
long box(Vector3< T1 > &st, Vector3< T2 > &sz)
Definition: options.h:214
molgroup_calculate_weight
double molgroup_calculate_weight(Bmolgroup *molgroup)
Calculates the weight of each molecule.
Definition: mol_util.cpp:270
Boption::view
View view()
Definition: options.h:259
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_set_radius
int molgroup_set_radius(Bmolgroup *molgroup, double radius)
Shifts all coordinates to a given radius.
Definition: mol_util.cpp:114
molgroup_rotate_to_view
Bmolgroup * molgroup_rotate_to_view(Bmolgroup *molgroup, View view, Vector3< double > origin, Vector3< double > trans)
Rotates a molecule group to a specified view and translates it afterwards.
Definition: mol_transform.cpp:180
Transform::scale
Vector3< double > scale
Definition: Transform.h:31
molgroup_radial_density
int molgroup_radial_density(Bmolgroup *molgroup, double interval, double cutoff, int wrap)
Calculates a radial distribution function.
Definition: mol_util.cpp:780
molgroup_shift_to_center_of_mass
int molgroup_shift_to_center_of_mass(Bmolgroup *molgroup)
Translates a set of coordinates to the center of mass.
Definition: mol_transform.cpp:625
molgroup_coor_invert
int molgroup_coor_invert(Bmolgroup *molgroup, Vector3< double > point)
Inverts the coordinates of a molecule through a given point.
Definition: mol_transform.cpp:419
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Transform::origin
Vector3< double > origin
Definition: Transform.h:27
Boption::next
Boption * next
Definition: options.h:28
molgroup_Bfactors
int molgroup_Bfactors(Bmolgroup *molgroup)
Calculates the average Bfactors for residues in molecules.
Definition: mol_util.cpp:28
verbose
int verbose
Bstring
Definition: Bstring.h:29
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
molgroup_print_sequence
int molgroup_print_sequence(Bmolgroup *molgroup)
Prints the sequence of a molecule as a single letter code string.
Definition: mol_util.cpp:92
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
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
View
Definition: View.h:26
molgroup_principal_axes
Vector3< double > molgroup_principal_axes(Bmolgroup *molgroup, Vector3< double > *eigenvec)
Calculates the principal axes of a molecule group.
Definition: mol_util.cpp:455
molgroup_coor_shift
int molgroup_coor_shift(Bmolgroup *molgroup, Vector3< double > shift)
Translates a molecule group.
Definition: mol_transform.cpp:28
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
molgroup_volume
double molgroup_volume(Bmolgroup *molgroup, Bstring &paramfile, int wrap)
Calculates the volume of a molecular system.
Definition: mol_util.cpp:586
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Transform::axis
Vector3< double > axis
Definition: Transform.h:28
molgroup_residue_renumber
int molgroup_residue_renumber(Bmolgroup *molgroup, int first)
Renumbers residues.
Definition: mol_util.cpp:182
molgroup_coor_rotate
int molgroup_coor_rotate(Bmolgroup *molgroup, Transform t)
Rotates and translates a molecule group.
Definition: mol_transform.cpp:87
options.h
Header file for option handlers.
use
const char * use[]
Definition: bmol.cpp:22
molgroup_coor_select
int molgroup_coor_select(Bmolgroup *molgroup, Vector3< double > min, Vector3< double > max)
Selects atoms within a box.
Definition: mol_select.cpp:233
main
int main(int argc, char **argv)
Definition: bmol.cpp:68
Vector3::volume
double volume()
Definition: Vector3.h:235
molgroup_place_at_coordinates
int molgroup_place_at_coordinates(Bmolgroup *molgroup, Vector3< double > location)
Translates a set of coordinates to a defined center-of-mass.
Definition: mol_transform.cpp:666
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
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
mol_edit.h
Library routines used for atomic coordinates.
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
molgroup_coor_transform
int molgroup_coor_transform(Bmolgroup *molgroup, Transform t)
Rotates and translates a molecule group.
Definition: mol_transform.cpp:332