| Bsoft 2.0.5 Bernard's software package

bmm.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "rwmodel_param.h"
11 #include "model_mechanics.h"
12 #include "model_transform.h"
13 #include "model_color.h"
14 #include "model_select.h"
15 #include "model_links.h"
16 #include "model_neighbors.h"
17 #include "model_util.h"
18 #include "utilities.h"
19 #include "options.h"
20 #include "timer.h"
21
22 // Declaration of global variables
23 extern int verbose; // Level of output to the screen
24
25
26 /* Usage assistance */
27 const char* use[] = {
28 " ",
29 "Usage: bmm [options] in1.star [in2.star ...]",
30 "--------------------------------------------",
31 "Refines membrane models.",
32 " ",
33 "Actions:",
34 "-center Center before all other operations.",
35 "-minimize 150 Number of iterations for minimizing a model.",
36 "-dynamics 500 Number of iterations for running dynamics on a model.",
37 " ",
38 "Selections:",
39 "-all Reset selection to all components before other selections.",
40 "-select #Mod1@14 Select models and components.",
41 " ",
42 "Parameters:",
43 "-verbose 7 Verbosity of output.",
44 "-componentradius 0.5 Component display radius.",
45 "-linkradius 0.5 Link display radius.",
46 " ",
47 "Parameters for minimization:",
48 "-shift 6.8 Maximum shift per iteration (angstrom, default infinite).",
49 " ",
50 "Parameters for dynamics:",
51 "-timestep 0.01 Integration time step (default 0.001).",
52 "-velocitylimit 0.01 Limit on the velocity (default 0.1 per time step).",
53 "-friction 0.2 Friction constant (default 1 = no friction).",
54 " ",
55 "Parameters for mechanics:",
56 "-neighbors 7,45 Neighbor designation: number and neighborhood scale (default 8,50).",
57 "-Kdistance 0.1 Distance force constant (default 0).",
58 "-Klink 0.01 Link force constant (default 0).",
59 "-Kangle 0.1 Angle force constant (default 0).",
60 "-Kpolyangle 0.1 Polygon angle force constant (default 0).",
61 "-Kpolygon 0.001 Polygon regularity force constant (default 0).",
62 "-Kpolyplane 0.1 Polygon planarity force constant (default 0).",
63 "-Kpoint 0.1,0.02 Point force constant and decay (default 0,0.01).",
64 "-Kradial 0.1 Radial force constant (default 0).",
65 "-radius 212 Reference radial distance (default 0).",
66 "-Kplane 0.2 Neighbor plane force constant (default 0).",
67 "-Kguide 0.5 Polyhedron guide force constant (default 0).",
68 "-Kmap 0.5 Map force constant (default 0).",
69 "-sigma 17 Sigma determining kernel size for fitting a map (default map pixel size).",
70 " ",
71 "Input:",
72 "-parameters parm.star Model parameter file (default atom_prop.star).",
73 "-guide file.star Polyhedron guide model file.",
74 " ",
75 "Output:",
76 "-output file.star Output model file.",
77 "-writeparam dm.star Write model parameter file.",
78 " ",
79 NULL
80 };
81
82 int main(int argc, char **argv)
83 {
84 /* Initialize variables */
85 int reset(0); // Keep selection as read from file
86 int center(0); // Flag to center the structure
87 long max_iter(0); // Number of iterations/cycles for minimization
88 int mm_type(0); // Type of mechanics: 0=minimization, 1=dynamics
89 double compradius(0); // Component display radius
90 double linkradius(0); // Link display radius
91 double max_shift(0); // Maximum shift per iteration
92 double timestep(0.001); // Integration time step
93 double velocitylimit(0.1); // Limit on velocity per time step
94 double Kfriction(1); // Friction constant, 1=no friction
95 long neighbors(8); // Number of neighbors to generate
96 double neighbor_scale(50); // Neighborhood scale
97 double Kdistance(0); // Distance force constant
98 double Klink(0); // Link force constant
99 double Kangle(0); // Angle force constant
100 double Kpolyangle(0); // Angle force constant for polygons
101 double Kpolygon(0); // Polygon regularity force constant
102 double Kpolyplane(0); // Polygon planarity force constant
103 double Kpoint(0); // Point force constant
104 double decay = 0.01; // Point force decay with distance
105 double Kradial(0); // Radial force constant
106 double radius(0); // Reference radial distance
107 double Kplane(0); // Neighbor plane force constant
108 double Kguide(0); // Polyhedron guide force constant
109 double Kmap(0); // Map force constant
110 double sigma(0); // Sigma determining kernel size for fitting a map
111 Bstring map_path; // Path to density map
112 Bstring mod_select; // Model and component selection
113 Bstring atom_select("ALL");
114 Bstring paramfile; // Use default parameter file
115 Bstring guidefile; // Polyhedron guide file
116 Bstring outfile; // Output model file name
117 Bstring mpfile; // Distance matrix file
118
119 int optind;
120 Boption* option = get_option_list(use, argc, argv, optind);
121 Boption* curropt;
122 for ( curropt = option; curropt; curropt = curropt->next ) {
123 if ( curropt->tag == "center" ) center = 1;
124 if ( curropt->tag == "minimize" ) {
125 if ( ( max_iter = curropt->value.integer() ) < 1 )
126 cerr << "-minimize: The number of iterations must be specified!" << endl;
127 else mm_type = 0;
128 }
129 if ( curropt->tag == "dynamics" ) {
130 if ( ( max_iter = curropt->value.integer() ) < 1 )
131 cerr << "-dynamics: The number of iterations must be specified!" << endl;
132 else mm_type = 1;
133 }
134 if ( curropt->tag == "all" ) reset = 1;
135 if ( curropt->tag == "select" )
136 mod_select = curropt->value;
137 if ( curropt->tag == "componentradius" )
138 if ( ( compradius = curropt->value.real() ) < 0.001 )
139 cerr << "-componentradius: The component display radius must be specified!" << endl;
140 if ( curropt->tag == "linkradius" )
141 if ( ( linkradius = curropt->value.real() ) < 0.001 )
142 cerr << "-linkradius: The link display radius must be specified!" << endl;
143 if ( curropt->tag == "shift" )
144 if ( ( max_shift = curropt->value.real() ) < 0.001 )
145 cerr << "-shift: The maximum shift distance must be specified!" << endl;
146 if ( curropt->tag == "timestep" )
147 if ( ( timestep = curropt->value.real() ) < 0.001 )
148 cerr << "-timestep: The time step must be specified!" << endl;
149 if ( curropt->tag == "velocitylimit" )
150 if ( ( velocitylimit = curropt->value.real() ) < 0.001 )
151 cerr << "-velocitylimit: The velocity limit must be specified!" << endl;
152 if ( curropt->tag == "friction" )
153 if ( ( Kfriction = curropt->value.real() ) < 1e-30 )
154 cerr << "-friction: The friction constant must be specified!" << endl;
155 if ( curropt->tag == "neighbors" )
156 if ( curropt->values(neighbors, neighbor_scale) < 1 )
157 cerr << "-neighbors: The number of neighbors must be specified!" << endl;
158 if ( curropt->tag == "Kdistance" )
159 if ( ( Kdistance = curropt->value.real() ) < 1e-30 )
160 cerr << "-Kdistance: The distance force constant must be specified!" << endl;
161 if ( curropt->tag == "Klink" )
162 if ( ( Klink = curropt->value.real() ) < 1e-30 )
163 cerr << "-Klink: The link force constant must be specified!" << endl;
164 if ( curropt->tag == "Kangle" )
165 if ( ( Kangle = curropt->value.real() ) < 1e-30 )
166 cerr << "-Kangle: The angle force constant must be specified!" << endl;
167 if ( curropt->tag == "Kpolyangle" )
168 if ( ( Kpolyangle = curropt->value.real() ) < 1e-30 )
169 cerr << "-Kpolyangle: The angle force constant for polygons must be specified!" << endl;
170 if ( curropt->tag == "Kpolygon" )
171 if ( ( Kpolygon = curropt->value.real() ) < 1e-30 )
172 cerr << "-Kpolygon: The polygon regularity force constant must be specified!" << endl;
173 if ( curropt->tag == "Kpolyplane" )
174 if ( ( Kpolyplane = curropt->value.real() ) < 1e-30 )
175 cerr << "-Kpolyplane: The polygon planarity force constant must be specified!" << endl;
176 if ( curropt->tag == "Kpoint" )
177 if ( curropt->values(Kpoint, decay) < 1 )
178 cerr << "-Kpoint: The point force constant must be specified!" << endl;
179 if ( curropt->tag == "Kradial" )
180 if ( ( Kradial = curropt->value.real() ) < 1e-30 )
181 cerr << "-Kradial: The radial force constant must be specified!" << endl;
182 if ( curropt->tag == "radius" )
183 if ( ( radius = curropt->value.real() ) < 1e-30 )
184 cerr << "-radius: The reference radial distance must be specified!" << endl;
185 if ( curropt->tag == "Kplane" )
186 if ( ( Kplane = curropt->value.real() ) < 1e-30 )
187 cerr << "-Kplane: The neighbor plane force constant must be specified!" << endl;
188 if ( curropt->tag == "Kguide" )
189 if ( ( Kguide = curropt->value.real() ) < 1e-30 )
190 cerr << "-Kguide: The polyhedron guide force constant must be specified!" << endl;
191 if ( curropt->tag == "Kmap" )
192 if ( ( Kmap = curropt->value.real() ) < 1e-30 )
193 cerr << "-Kmap: The map force constant must be specified!" << endl;
194 if ( curropt->tag == "sigma" )
195 if ( ( sigma = curropt->value.real() ) < 1e-30 )
196 cerr << "-sigma: The sigma value must be specified!" << endl;
197 if ( curropt->tag == "parameters" )
198 paramfile = curropt->filename();
199 if ( curropt->tag == "guide" )
200 guidefile = curropt->filename();
201 if ( curropt->tag == "output" )
202 outfile = curropt->filename();
203 if ( curropt->tag == "writeparam" )
204 mpfile = curropt->filename();
205 }
206 option_kill(option);
207
208 double ti = timer_start();
209
210 // Read all the parameter files
211 Bstring* file_list = NULL;
212 while ( optind < argc ) string_add(&file_list, argv[optind++]);
213 if ( !file_list ) {
214 cerr << "Error: No model files specified!" << endl;
215 bexit(-1);
216 }
217
218 Bmodel* model = read_model(file_list, paramfile);
219 string_kill(file_list);
220
221 if ( !model ) {
222 cerr << "Error: Input file not read!" << endl;
223 bexit(-1);
224 }
225
226 if ( reset ) models_process(model, model_reset_selection);
227
228 if ( mod_select.length() ) model_select(model, mod_select);
229
230 Bmodparam* mp = NULL;;
231 if ( paramfile.length() )
232 mp = model_param_read(paramfile);
233 else
234 mp = model_param_generate(model);
235
236 if ( timestep > 0 ) mp->timestep = timestep;
237 if ( Kfriction > 0 ) mp->Kfriction = Kfriction;
238 if ( Kdistance > 0 ) mp->Kdistance = Kdistance;
239 if ( Klink > 0 ) mp->Klink = Klink;
240 if ( Kangle > 0 ) mp->Kangle = Kangle;
241 if ( Kpolyangle > 0 ) mp->Kpolyangle = Kpolyangle;
242 if ( Kpolygon > 0 ) mp->Kpolygon = Kpolygon;
243 if ( Kpolyplane > 0 ) mp->Kpolyplane = Kpolyplane;
244 if ( Kpoint > 0 ) mp->Kpoint = Kpoint;
245 if ( Kradial > 0 ) mp->Kradial = Kradial;
246 if ( radius > 0 ) mp->radius = radius;
247 if ( Kplane > 0 ) mp->Kplane = Kplane;
248 if ( Kguide > 0 ) mp->Kguide = Kguide;
249 if ( Kmap > 0 ) mp->Kmap = Kmap;
250 if ( sigma > 0 ) mp->sigma = sigma;
251
252 if ( Kguide > 0 && guidefile.length() )
253 mp->guide = read_model(guidefile, paramfile);
254
255 model_param_set_type_indices(model, mp);
256
257 model_param_display(mp);
258
259 if ( center ) models_process(model, model_center);
260
261 model_set_neighbors(model, neighbors, neighbor_scale);
262
263 model_check(model, map_path);
264
265 model_selection_stats(model);
266
267 if ( max_iter )
268 model_mechanics(model, mp, mm_type, max_iter, max_shift, velocitylimit);
269
270 model_color_by_fom(model);
271
272 if ( compradius > 0 ) models_process(model, compradius, model_set_component_radius);
273
274 if ( linkradius > 0 ) models_process(model, linkradius, model_set_link_radius);
275
276 if ( outfile.length() ) {
277 model_update_comment(model, argc, argv);
278 write_model(outfile, model);
279 }
280
281 if ( mpfile.length() ) {
282 mp->comment += command_line_time(argc, argv);
283 model_param_write(mpfile, mp);
284 }
285
286 model_kill(model);
287 model_param_kill(mp);
288
289 if ( verbose & VERB_TIME )
290 timer_report(ti);
291
292 bexit(0);
293 }
294
Bmodparam::Kpolyplane
double Kpolyplane
Definition: rwmodel_param.h:44
Bstring::real
double real()
Definition: Bstring.cpp:545
model_set_component_radius
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
Definition: rwmodel.cpp:1264
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
model_param_read
Bmodparam * model_param_read(Bstring &filename)
Reads a model parameter file.
Definition: rwmodel_param.cpp:79
Bmodparam::Kpoint
double Kpoint
Definition: rwmodel_param.h:45
Bmodparam::Kradial
double Kradial
Definition: rwmodel_param.h:46
Bmodparam::Kplane
double Kplane
Definition: rwmodel_param.h:47
utilities.h
Header file for general utilities.
model_select
long model_select(Bmodel *model, Bstring &comptype)
Selects models, components and component types.
Definition: model_select.cpp:36
model_util.h
Library routines used for model processing.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bmodparam::Kfriction
double Kfriction
Definition: rwmodel_param.h:38
Bmodparam::radius
double radius
Definition: rwmodel_param.h:53
Bmodparam::Kdistance
double Kdistance
Definition: rwmodel_param.h:39
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_mechanics.h
Functions to do molecular mechanics.
model_links.h
Library routines used for model link processing.
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: bmm.cpp:27
model_color_by_fom
int model_color_by_fom(Bmodel *model)
Colors model components by fom.
Definition: model_color.cpp:159
Bmodparam
Definition: rwmodel_param.h:35
model_param_display
int model_param_display(Bmodparam *mp)
Displays a model parameter in the shell.
Definition: rwmodel_param.cpp:303
model_color.h
Functions to color models.
Bmodparam::Kangle
double Kangle
Definition: rwmodel_param.h:41
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
model_set_link_radius
long model_set_link_radius(Bmodel *model, double linkrad)
Set the display radius for all links to a specific value.
Definition: model_links.cpp:139
model_param_generate
Bmodparam * model_param_generate(Bmodel *model)
Generates a model parameter file from a model.
Definition: rwmodel_param.cpp:374
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
model_update_comment
int model_update_comment(Bmodel *model, int n, char **strings)
Puts a set of strings and time in the comment of a model.
Definition: rwmodel.cpp:1158
Bmodparam::sigma
double sigma
Definition: rwmodel_param.h:58
verbose
int verbose
model_mechanics
double model_mechanics(Bmodel *model, Bmodparam *mp, int mm_type, int max_iter, double max_shift, double velocitylimit)
Minimizes the energy of a model.
Definition: model_mechanics.cpp:40
model_selection_stats
long model_selection_stats(Bmodel *model)
Calculates selection statistics.
Definition: model_select.cpp:870
model
Bmodel * model
Definition: bshow.cpp:32
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
Bmodparam::timestep
double timestep
Definition: rwmodel_param.h:37
Boption::next
Boption * next
Definition: options.h:28
Bmodparam::comment
Bstring comment
Definition: rwmodel_param.h:36
Bmodparam::Kpolygon
double Kpolygon
Definition: rwmodel_param.h:43
Bstring
Definition: Bstring.h:29
model_reset_selection
long model_reset_selection(Bmodel *model)
Resets the selection to all components.
Definition: model_select.cpp:232
rwmodel_param.h
Header to read and write model dynamics parameters in STAR format.
Bmodparam::Kmap
double Kmap
Definition: rwmodel_param.h:49
rwmodel.h
Header file for reading and writing atomic model files.
Bmodparam::Kpolyangle
double Kpolyangle
Definition: rwmodel_param.h:42
model_param_write
int model_param_write(Bstring &filename, Bmodparam *mp)
Writes a model parameter file.
Definition: rwmodel_param.cpp:233
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
model_center
long model_center(Bmodel *model)
Shifts one models to its center of mass.
Definition: model_transform.cpp:27
command_line_time
Bstring command_line_time(int n, char **strings)
Returns a set of strings and time in a string.
Definition: utilities.cpp:60
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
model_neighbors.h
Functions to manipulate model component neighbors.
options.h
Header file for option handlers.
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
model_set_neighbors
int model_set_neighbors(Bmodel *model, int number)
Sets the desired number of components as neighbors for each component.
Definition: model_neighbors.cpp:28
model_select.h
Header file for reading and writing atomic model files.
Bmodparam::guide
Bmodel * guide
Definition: rwmodel_param.h:55
main
int main(int argc, char **argv)
Definition: bmm.cpp:82
model_transform.h
Library routines used for model transformation.
Bmodparam::Klink
double Klink
Definition: rwmodel_param.h:40
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
model_param_set_type_indices
int model_param_set_type_indices(Bmodel *model, Bmodparam *mp)
Sets the component type indices from the model parameters.
Definition: rwmodel_param.cpp:491
model_param_kill
int model_param_kill(Bmodparam *mp)
Deallocates memory for a model parameter structure.
Definition: rwmodel_param.cpp:50
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
model_check
int model_check(Bmodel *model, Bstring path)
Checks model properties.
Definition: rwmodel.cpp:592
Bmodparam::Kguide
double Kguide
Definition: rwmodel_param.h:48