| Bsoft 2.0.5 Bernard's software package

bmonte.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "rwimg.h"
11 #include "rwmd.h"
12 #include "mol_monte.h"
13 #include "mol_bonds.h"
14 #include "mol_transform.h"
15 #include "utilities.h"
16 #include "options.h"
17 #include "timer.h"
18
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21
22 /* Usage assistance */
23 const char* use[] = {
24 " ",
25 "Usage: bmonte [options] input.pdb output.pdb",
26 "--------------------------------------------",
27 "Minimizes the energy of a set of molecular structures using a Monte Carlo Metropolis algorithm.",
28 "The -grid and -orientation options only work with rigid bodies, not atoms,",
29 " and their output is to a model parameter file (.star).",
30 " ",
31 "Actions:",
32 "-rigid mol Rigidity: all/whole = single rigid body (default),",
33 " group = each file with a molecule group is a rigid body,",
34 " molecule = each molecule is a rigid body,",
35 " atom = each atom can move.",
36 "-concurrent Run all models simultaneously (default each model separately),",
37 "-grid 3.5,5,4.2 Search on a grid with this sampling and within the bounding box (angstroms).",
38 "-orientations 12.5 Search all orientations with the given angular step size (degrees).",
39 " ",
40 "Parameters:",
41 "-verbose 7 Verbosity of output.",
42 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
43 "-bbox 0,82.5,50,50,80,50 Bounding box center and size (default from coordinates or map).",
44 "-wrap Wrap around (periodic boundaries).",
45 "-resolution 20 Resolution limit (angstrom).",
46 "-iterations 60 Maximum number of iterations (default 1).",
47 "-Kbond 150 Bond strength (default 0).",
48 "-Kangle 4 Angle strength (default 0).",
49 "-Kvdw 0.1 Van der Waals strength (default 0).",
50 "-Kelectrostatic 0.4 Electrostatic strength (default 0).",
51 "-Kseparation 0.02 Separation energy constant (default 0).",
52 "-Kmap 1.5 Map energy constant (default 1 if -Map option is used).",
53 "-separation 4.5 Separation distance for overlap calculation (default 4 A).",
54 "-cutoff 7.8 Distance cutoff for non-bonded forces (default 5 A).",
55 "-beta 12 Inverse of mean energy per atom and degree of freedom (default 10).",
56 "-angle 1.5 Maximum angular increment per iteration (default 1 degree).",
57 "-shift 3.1 Maximum shift per iteration (default 1 angstrom).",
58 "-bondsteps 5 Number of steps along a bond for map fitting (default none).",
59 "-location 12,5.3,6 Location of harmonic force to apply to center-of-mass.",
60 "-Klocation 16.8,0.2 Magnitude of harmonic force and decay constant.",
61 "-SS 2.05 Set disulphide reference bond length.",
62 " ",
63 "Input:",
64 "-parameters md.star Molecular dynamics parameter file.",
65 "-Model locations.star Model parameter file with initial rigid body locations.",
66 "-Map file.map Map to use as an additional restraint.",
67 "-Mask mask.mrc Mask to limit grid-searches (must be byte data type).",
68 " ",
69 NULL
70 };
71
72 int main(int argc, char **argv)
73 {
74 // Initialize variables
75 Vector3<double> sam; // Map sampling
76 Vector3<double> grid_sampling; // Grid sampling
77 Vector3<double> bbox_center; // Bounding box center
78 Vector3<double> bbox_size; // Bounding box size
79 double angle_step(0); // Angle step size for orientation search
80 int wrap(0); // No wrapping as default
81 double resolution(0); // Must be set > 0 to limit resolution
82 unsigned long max_iter(1); // Maximum number of iterations
83 double Kbond(0); // Bond strength
84 double Kangle(0); // Angle strength
85 double Kelec(0); // Electrostatic strength
86 double Kvdw(0); // Van der Waals strength
87 double Ksep(0); // Separation energy constant
88 double Kmap(0); // Map energy constant
89 double separation(4); // Separation distance for overlap calculation
90 double cutoff(5); // Distance cutoff for non-bonded forces
91 double beta(10); // Equivalent of 1/kT
92 double max_angle(M_PI/180.0); // Maximum angular deviation
93 double max_shift(1); // Maximum allowed shift
94 int bond_steps(0); // Number of steps along bond
95 double Kpoint(0); // Harmonic location force constant
96 double pointdecay(0.1); // Point force decay constant
97 Vector3<double> location; // Point for harmonic force
98 int rigid(0); // Flag to treat the whole ensemble as a rigid body
99 int concurrent(0); // Flag to run all models simultaneously
100 double ss(0); // SS bond length
101 Bstring atom_select("all"); // Selection
102 Bstring modelfile; // Input model file
103 Bstring mapfile; // Input map file
104 Bstring maskfile; // Input map file
105 Bstring paramfile; // Parameter file
106
107 random_seed();
108
109 int optind;
110 Boption* option = get_option_list(use, argc, argv, optind);
111 Boption* curropt;
112 for ( curropt = option; curropt; curropt = curropt->next ) {
113 if ( curropt->tag == "rigid" ) {
114 if ( curropt->value[0] == 'g' ) rigid = 1;
115 if ( curropt->value[0] == 'm' ) rigid = 2;
116 if ( curropt->value[0] == 'a' ) rigid = 3;
117 }
118 if ( curropt->tag == "concurrent" ) concurrent = 1;
119 if ( curropt->tag == "grid" )
120 grid_sampling = curropt->sampling();
121 if ( curropt->tag == "orientations" ) {
122 if ( ( angle_step = curropt->value.real() ) < 0.1 )
123 cerr << "-orientations: An angle step size must be specified!" << endl;
124 else
125 angle_step *= M_PI/180.0;
126 }
127 if ( curropt->tag == "sampling" )
128 sam = curropt->sampling();
129 if ( curropt->tag == "bbox" )
130 if ( curropt->box(bbox_center, bbox_size) < 6 )
131 cerr << "-bbox: All 6 values must be specified!" << endl;
132 if ( curropt->tag == "wrap" )
133 wrap = 1;
134 if ( curropt->tag == "resolution" )
135 if ( ( resolution = curropt->value.real() ) < 0.001 )
136 cerr << "-resolution: A resolution limit must be specified!" << endl;
137 if ( curropt->tag == "iterations" )
138 if ( ( max_iter = curropt->value.integer() ) < 1 )
139 cerr << "-iterations: A number must be specified!" << endl;
140 if ( curropt->tag == "Kbond" )
141 if ( ( Kbond = curropt->value.real() ) < 1e-30 )
142 cerr << "-Kbond: The bond strength must be specified!" << endl;
143 if ( curropt->tag == "Kangle" )
144 if ( ( Kangle = curropt->value.real() ) < 1e-30 )
145 cerr << "-Kangle: The angle strength must be specified!" << endl;
146 if ( curropt->tag == "Kelectrostatic" )
147 if ( ( Kelec = curropt->value.real() ) < 1e-30 )
148 cerr << "-Kelectrostatic: The electrostatic strength must be specified!" << endl;
149 if ( curropt->tag == "Kvdw" )
150 if ( ( Kvdw = curropt->value.real() ) < 1e-30 )
151 cerr << "-Kvdw: The Van der Waals strength must be specified!" << endl;
152 if ( curropt->tag == "Kseparation" )
153 if ( ( Ksep = curropt->value.real() ) < 1e-30 )
154 cerr << "-Kseparation: The separation energy constant strength must be specified!" << endl;
155 if ( curropt->tag == "Kmap" )
156 if ( ( Kmap = curropt->value.real() ) < 1e-30 )
157 cerr << "-Kmap: The map energy constant strength must be specified!" << endl;
158 if ( curropt->tag == "separation" )
159 if ( ( separation = curropt->value.real() ) < 1e-30 )
160 cerr << "-separation: The separation distance must be specified!" << endl;
161 if ( curropt->tag == "cutoff" )
162 if ( ( cutoff = curropt->value.real() ) < 1e-30 )
163 cerr << "-cutoff: The cutoff distance must be specified!" << endl;
164 if ( curropt->tag == "beta" )
165 if ( ( beta = curropt->value.real() ) < 1e-30 )
166 cerr << "-beta: A value must be specified!" << endl;
167 if ( curropt->tag == "angle" ) {
168 if ( ( max_angle = curropt->value.real() ) < 1e-30 )
169 cerr << "-angle: An angle must be specified!" << endl;
170 else
171 max_angle = angle_set_negPI_to_PI(max_angle*M_PI/180.0);
172 }
173 if ( curropt->tag == "shift" )
174 if ( ( max_shift = curropt->value.real() ) < 1e-30 )
175 cerr << "-shift: A distance must be specified!" << endl;
176 if ( curropt->tag == "bondsteps" )
177 if ( ( bond_steps = curropt->value.integer() ) < 1 )
178 cerr << "-bondsteps: The bond step length must be specified!" << endl;
179 if ( curropt->tag == "location" )
180 location = curropt->vector3();
181 if ( curropt->tag == "Klocation" )
182 if ( curropt->values(Kpoint, pointdecay) < 1 )
183 cerr << "-Klocation: The location force constant must be specified!" << endl;
184 if ( curropt->tag == "SS" )
185 if ( ( ss = curropt->value.real() ) < 1e-30 )
186 cerr << "-SS: A bond length must be specified!" << endl;
187 if ( curropt->tag == "parameters" )
188 paramfile = curropt->filename();
189 if ( curropt->tag == "Model" )
190 modelfile = curropt->filename();
191 if ( curropt->tag == "Map" )
192 mapfile = curropt->filename();
193 if ( curropt->tag == "Mask" )
194 maskfile = curropt->filename();
195 }
196 option_kill(option);
197
198 double ti = timer_start();
199
200 Bmd* md = NULL;
201 if ( paramfile.length() ) {
202 md = read_md_parameters(paramfile);
203 } else {
204 md = md_init();
205 }
206 md->Kbond = Kbond;
207 md->Kangle = Kangle;
208 md->Kelec = Kelec;
209 md->Kvdw = Kvdw;
210 md->Ksep = Ksep;
211 md->Kpoint = Kpoint;
212 md->point = location;
213 md->pointdecay = pointdecay;
214 md->sepdist = separation;
215 md->bondsteps = bond_steps;
216 md->cutoff = cutoff;
217 md->wrap = wrap;
218
219 // Read the molecule file
220 Bstring filename(argv[optind++]);
221 Bmolgroup* molgroup = read_molecule(filename, atom_select, paramfile);
222 if ( !molgroup ) {
223 cerr << "Error: No molecules read!" << endl;
224 bexit(-1);
225 }
226
227 molecule_update_comment(molgroup, argc, argv);
228
229 if ( rigid == 3 ) {
230 md_generate_bond_list(molgroup, md);
231 md_bond_list_set_parameters(molgroup->bond, md->bond);
232 md_generate_angle_list(molgroup, md);
233 md_angle_list_set_parameters(molgroup->angle, md->angle);
234 }
235
236 if ( ss ) {
237 Bbondtype* bt = new Bbondtype;
238 strcpy(bt->type1, "S");
239 strcpy(bt->type2, "S");
240 bt->covlength = ss;
241 md_bond_list_set_parameters(molgroup->bond, bt);
242 delete bt;
243 }
244
245 // Read the map file
246 long natom_in(0);
247 Bimage* map = NULL;
248 Bimage* pmask = NULL;
249 Bmodel* model = NULL;
250
251 filename = 0;
252 if ( optind < argc )
253 filename = argv[optind];
254
255 if ( mapfile.length() ) {
256 map = read_img(mapfile, 1, 0);
257 if ( sam.volume() ) map->sampling(sam);
258 molgroup_set_box_to_map_boundaries(molgroup, map);
259 natom_in = molgroup_test_if_within_box(molgroup, molgroup->min, molgroup->max);
260 if ( natom_in < 2 ) {
261 molgroup_place_at_coordinates(molgroup, ((molgroup->max + molgroup->min) * 0.5));
262 molgroup_set_box_to_map_boundaries(molgroup, map);
263 }
264 md->Kmap = 1;
265 if ( Kmap ) md->Kmap = Kmap;
266 }
267
268 if ( maskfile.length() ) {
269 pmask = read_img(maskfile, 1, 0);
270 if ( sam.volume() ) pmask->sampling(sam);
271 }
272
273 if ( bbox_size[0] > 0 && bbox_size[1] > 0 && bbox_size[2] > 0 ) {
274 molgroup->min = bbox_center - (bbox_size * 0.5);
275 molgroup->max = bbox_center + (bbox_size * 0.5);
276 molgroup->box = bbox_size;
277 }
278
279 if ( modelfile.length() ) {
280 model = read_model(&modelfile);
281 } else if ( grid_sampling[0] > 0 ) {
282 model = molgroup_generate_masked_grid_list(molgroup, grid_sampling, pmask);
283 } else if ( angle_step > 0 ) {
284 model = molgroup_generate_orientation_list(molgroup, angle_step);
285 }
286
287 if ( model ) {
288 if ( concurrent )
289 mcm_molecule_groups(molgroup, model, md, map, beta, max_angle, max_shift, max_iter, rigid);
290 else
291 mcm_molecule_list(molgroup, model, md, map, beta, max_angle, max_shift, max_iter, rigid);
292 if ( filename.length() )
293 write_model(filename, model);
294 } else {
295 if ( rigid < 3 ) {
296 molgroup = monte_carlo_metropolis(molgroup, md, map, beta, max_angle, max_shift,
297 max_iter, rigid, monte_rigid_body_fit_energy, molgroup_rigid_body_transform);
298 } else {
299 if ( bond_steps > 0 )
300 molgroup = monte_carlo_metropolis(molgroup, md, map, beta, max_angle, max_shift,
301 max_iter, rigid, monte_bond_fit_energy, molgroup_move_atoms_down_energy);
302 else
303 molgroup = monte_carlo_metropolis(molgroup, md, map, beta, max_angle, max_shift,
304 max_iter, rigid, monte_atom_fit_energy, molgroup_move_atoms_down_energy);
305 }
306 if ( filename.length() )
307 write_molecule(filename, molgroup);
308 }
309
310 delete map;
311 delete pmask;
312 molgroup_list_kill(molgroup);
313 model_kill(model);
314 md_kill(md);
315
316 if ( verbose & VERB_TIME )
317 timer_report(ti);
318
319 bexit(0);
320 }
321
Bmolgroup::angle
Bangle * angle
Definition: rwmolecule.h:191
main
int main(int argc, char **argv)
Definition: bmonte.cpp:72
monte_atom_fit_energy
double monte_atom_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for fitting atoms to a map.
Definition: mol_monte.cpp:693
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
Bmd::point
Vector3< float > point
Definition: rwmd.h:82
monte_carlo_metropolis
Bmolgroup * monte_carlo_metropolis(Bmolgroup *molgroup, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid, double(Efunc)(Bmolgroup *, Bimage *, Bmd *), int(Tfunc)(Bmolgroup *, double, double))
Definition: mol_monte.cpp:71
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
verbose
int verbose
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Bmd::Ksep
double Ksep
Definition: rwmd.h:63
Boption::tag
Bstring tag
Definition: options.h:29
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
Bstring::length
long length() const
Definition: Bstring.cpp:263
molgroup_test_if_within_box
long molgroup_test_if_within_box(Bmolgroup *molgroup, Vector3< double > min, Vector3< double > max)
Tests if a molecule overlaps with a defined box.
Definition: mol_monte.cpp:626
md_generate_bond_list
Bbond * md_generate_bond_list(Bmolgroup *molgroup, Bmd *md)
Generates a distance-based bond list.
Definition: mol_bonds.cpp:30
mol_transform.h
Library routines used for atomic coordinate transformations.
Bmd
Definition: rwmd.h:56
mcm_molecule_list
Bmolgroup * mcm_molecule_list(Bmolgroup *molgroup, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid)
Bbondtype::covlength
float covlength
Definition: rwmd.h:25
Bmd::Kmap
double Kmap
Definition: rwmd.h:65
molgroup_generate_orientation_list
Bmolgroup * molgroup_generate_orientation_list(Bmolgroup *molgroup, double angle_step, Bstring filename, int whole)
Generates multiple versions of a molecule at different locations.
Definition: mol_monte.cpp:386
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
monte_bond_fit_energy
double monte_bond_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for fitting bonds to a map.
Definition: mol_monte.cpp:725
molgroup_set_box_to_map_boundaries
int molgroup_set_box_to_map_boundaries(Bmolgroup *molgroup, Bimage *map)
Sets the box in a molgroup to that defined by the map boundaries.
Definition: mol_monte.cpp:604
Boption::filename
Bstring filename()
Definition: options.h:85
Bmd::angle
Bangletype * angle
Definition: rwmd.h:85
timer.h
Utilities for timing functions.
md_angle_list_set_parameters
int md_angle_list_set_parameters(Bangle *anglelist, Bangletype *angletype)
Assigns angles from angle types.
Definition: mol_bonds.cpp:485
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
Bimage
General image parameter class.
Definition: Bimage.h:163
Bbondtype::type2
char type2[8]
Definition: rwmd.h:24
M_PI
#define M_PI
Definition: utilities.h:59
Bmd::Kpoint
double Kpoint
Definition: rwmd.h:64
molgroup_move_atoms_down_energy
int molgroup_move_atoms_down_energy(Bmolgroup *molgroup, double max_angle, double max_shift)
Move atoms random distances down the energy gradient.
Definition: mol_monte.cpp:891
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
rwmolecule.h
Header file for reading reflection files.
mcm_molecule_groups
int mcm_molecule_groups(Bmolgroup *molgroup, Bmodel *model, Bmd *md, Bimage *map, double beta, double max_angle, double max_shift, long max_iter, int rigid)
Monte Carlo fit of a set of molecule groups.
Definition: mol_monte.cpp:543
Bmolgroup
Definition: rwmolecule.h:170
Boption::box
long box(Vector3< T1 > &st, Vector3< T2 > &sz)
Definition: options.h:214
Bmd::pointdecay
double pointdecay
Definition: rwmd.h:70
Bmd::Kbond
double Kbond
Definition: rwmd.h:59
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bmd::Kelec
double Kelec
Definition: rwmd.h:61
Bmolgroup::max
Vector3< double > max
Definition: rwmolecule.h:183
Bbondtype::type1
char type1[8]
Definition: rwmd.h:23
md_generate_angle_list
Bangle * md_generate_angle_list(Bmolgroup *molgroup, Bmd *md)
Generates an angle list.
Definition: mol_bonds.cpp:415
mol_monte.h
Headers of functions using a monte carlo metroplis algorithm to energy minimize molecular positions.
molgroup_list_kill
int molgroup_list_kill(Bmolgroup *molgroup)
Destroys a molecule group linked list.
Definition: rwmolecule.cpp:347
model
Bmodel * model
Definition: bshow.cpp:32
read_md_parameters
Bmd * read_md_parameters(Bstring &filename)
Reading molecular dynamics parameters from STAR files.
Definition: rwmd.cpp:80
Bmolgroup::bond
Bbond * bond
Definition: rwmolecule.h:190
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:28
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
Bmd::Kangle
double Kangle
Definition: rwmd.h:60
Boption::next
Boption * next
Definition: options.h:28
mol_bonds.h
Header for molecular dynamics.
Bstring
Definition: Bstring.h:29
md_bond_list_set_parameters
double md_bond_list_set_parameters(Bbond *bondlist, Bbondtype *bondtype)
Assigns covalent bond lengths to bonds.
Definition: mol_bonds.cpp:299
beta
double beta(double volt)
Calculates the relative electron velocity.
Definition: ctf.cpp:447
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
monte_rigid_body_fit_energy
double monte_rigid_body_fit_energy(Bmolgroup *molgroup, Bimage *map, Bmd *md)
Calculates the potential energy for rigid body fitting.
Definition: mol_monte.cpp:661
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
molgroup_rigid_body_transform
int molgroup_rigid_body_transform(Bmolgroup *molgroup, double max_angle, double shift_std)
Randomly transforms a molecule or molecule group.
Definition: mol_monte.cpp:847
Bmd::wrap
int wrap
Definition: rwmd.h:72
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bmd::sepdist
double sepdist
Definition: rwmd.h:68
use
const char * use[]
Definition: bmonte.cpp:23
Bmd::cutoff
double cutoff
Definition: rwmd.h:69
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
Bmodel
Definition: rwmodel.h:119
rwmd.h
Header to read and write molecular dynamics parameters in STAR format.
md_init
Bmd * md_init()
Initializes a molecular dynamics structure.
Definition: rwmd.cpp:28
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
rwimg.h
Header file for 2D and 3D image I/O.
Bbondtype
Definition: rwmd.h:21
options.h
Header file for option handlers.
Bmd::bond
Bbondtype * bond
Definition: rwmd.h:84
md_kill
int md_kill(Bmd *md)
Deallocates a molecular dynamics structure.
Definition: rwmd.cpp:417
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
Bmd::bondsteps
int bondsteps
Definition: rwmd.h:71
Bmd::Kvdw
double Kvdw
Definition: rwmd.h:62
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
molgroup_generate_masked_grid_list
Bmolgroup * molgroup_generate_masked_grid_list(Bmolgroup *molgroup, Bimage *pmask, Vector3< double > grid_sampling, Bstring filename)
Generates multiple versions of a molecule at different locations.
Definition: mol_monte.cpp:260
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