| Bsoft 2.0.5 Bernard's software package

model_mechanics.cpp
Go to the documentation of this file.
1
9 #include "model_mechanics.h"
10 #include "model_poly.h"
11 #include "model_shell.h"
12 #include "model_transform.h"
13 #include "model_util.h"
14 #include "math_util.h"
15 #include "random_numbers.h"
16 #include "symmetry.h"
17 #include "Vector3.h"
18 #include "linked_list.h"
19 #include "utilities.h"
20
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23
24 #define ETERMS 16
25
40 double model_mechanics(Bmodel* model, Bmodparam* mp, int mm_type, int max_iter,
41 double max_shift, double velocitylimit)
42 {
43 if ( !model->sel ) {
44 cerr << "Error: No model selected!" << endl << endl;
45 return 0;
46 }
47
48 if ( !model->poly ) model_poly_generate(model);
49
50 if ( max_shift < 1 ) max_shift = 1e30;
51
52 Vector3<int> ksize;
53 Bimage* map = NULL;
54
55 if ( mp->Kmap && model->fmap.length() > 1 ) {
56 map = read_img(model->fmap, 1, model->img_num);
57 map->rescale_to_avg_std(0, 1);
58 if ( mp->sigma < map->sampling()[0] ) mp->sigma = map->sampling()[0];
59 ksize = Vector3<int>((int) (6*mp->sigma/map->sampling()[0]), (int) (6*mp->sigma/map->sampling()[1]), (int) (6*mp->sigma/map->sampling()[2]));
60 }
61
62 if ( verbose ) {
63 if ( mm_type ) {
64 cout << "Dynamics for model " << model->id << ":" << endl;
65 cout << "Time step: " << mp->timestep << endl;
66 cout << "Kfriction: " << mp->Kfriction << endl;
67 } else {
68 cout << "Minimizing model " << model->id << ":" << endl;
69 }
70 cout << "Kdistance: " << mp->Kdistance << endl;
71 cout << "Klink: " << mp->Klink << endl;
72 cout << "Kangle: " << mp->Kangle << endl;
73 cout << "Kpolyangle: " << mp->Kpolyangle << endl;
74 cout << "Kpolygon: " << mp->Kpolygon << endl;
75 cout << "Kpolyplane: " << mp->Kpolyplane << endl;
76 cout << "Kpoint and decay: " << mp->Kpoint << " (" << mp->pointdecay << ")" << endl;
77 cout << "Kradial and radius: " << mp->Kradial << " (" << mp->radius << ")" << endl;
78 cout << "Kplane: " << mp->Kplane << endl;
79 if ( mp->guide ) {
80 cout << "Guide model: " << mp->guide->id << endl;
81 cout << "Kguide: " << mp->Kguide << endl;
82 }
83 if ( map ) {
84 cout << "Map: " << model->fmap << endl;
85 cout << "Kmap: " << mp->Kmap << endl;
86 cout << "Sigma: " << mp->sigma << " A" << endl;
87 cout << "Kernel size: " << ksize << endl;
88 }
89 cout << "Maximum shift per iteration: " << max_shift << " A" << endl;
90 cout << "Model mass: " << model_mass(model) << " Da" << endl << endl;
91 }
92
93
94 long i, iter(0);
95 int h[ETERMS];
96 double E[ETERMS], E0[ETERMS], Epot0;
97 for ( i=0; i<ETERMS; i++ ) {
98 E[i] = E0[i] = 0;
99 h[i] = 0;
100 }
101 if ( mp->Klink > 0 ) h[0] = 1;
102 if ( mp->Kangle > 0 ) h[1] = 1;
103 if ( mp->Kpolyangle > 0 ) h[2] = 1;
104 if ( mp->Kpolygon > 0 ) h[3] = 1;
105 if ( mp->Kpolyplane > 0 ) h[4] = 1;
106 if ( mp->Kdistance > 0 ) h[5] = 1;
107 if ( mp->Kpoint > 0 ) h[6] = 1;
108 if ( mp->Kradial > 0 ) h[7] = 1;
109 if ( mp->Kplane > 0 ) h[8] = 1;
110 if ( mp->Kguide > 0 ) h[9] = 1;
111 if ( mp->Kmap ) h[10] = 1;
112
113 Bstring* head_list = NULL;
114 Bstring* head;
115 string_add(&head_list, "Elink ");
116 string_add(&head_list, "Eangle ");
117 string_add(&head_list, "Epolyangle");
118 string_add(&head_list, "Epolygon ");
119 string_add(&head_list, "Epolyplane");
120 string_add(&head_list, "Edistance ");
121 string_add(&head_list, "Epoint ");
122 string_add(&head_list, "Eradial ");
123 string_add(&head_list, "Eplane ");
124 string_add(&head_list, "Eguide ");
125 string_add(&head_list, "Emap ");
126
127
128 model_calculate_deviations(model, mp);
129
130 Vector3<double> refcom = model_center_of_mass(model);
131
132 double gyrad0 = model_gyration_radius(model);
133
134 // if ( verbose & VERB_PROCESS ) {
135 if ( verbose ) {
136 cout << "Iter";
137 for ( i=0, head = head_list; i<ETERMS && head; i++, head = head->next ) if ( h[i] )
138 cout << tab << *head;
139 cout << "\tEpotential";
140 if ( mm_type ) cout << "\tEkinetic";
141 cout << endl;
142 }
143 for ( iter=1; iter<=max_iter; iter++ ) {
144 model_zero_forces(model);
145 E[0] = mp->Elink = model_link_energy(model, mp);
146 E[1] = mp->Eangle = model_angle_energy(model, mp);
147 E[2] = mp->Epolyangle = model_polygon_angle_energy(model, mp->Kpolyangle);
148 E[3] = mp->Epolygon = model_polygon_energy(model, mp->Kpolygon);
149 E[4] = mp->Epolyplane = model_polygon_plane_energy(model, mp->Kpolyplane);
150 // E[5] = mp->Edistance = model_distance_energy(model, mp);
151 E[5] = mp->Edistance = model_neighbor_distance_energy(model, mp);
152 E[6] = mp->Epoint = model_point_force(model, mp->point, mp->Kpoint, mp->pointdecay);
153 E[7] = mp->Eradial = model_radial_energy(model, mp->point, mp->radius, mp->Kradial);
154 E[8] = mp->Eplane = model_neighbor_plane_energy(model, mp->Kplane);
155 E[9] = mp->Eguide = model_polyhedron_guide_energy(model, mp->guide, mp->Kguide);
156 E[10] = mp->Emap = model_map_energy(model, map, mp->Kmap, mp->sigma);
157 for ( i=0, mp->Epot=0; i<ETERMS; i++ ) mp->Epot += E[i];
158 if ( !isfinite(mp->Epot) ) {
159 cerr << endl << "***** Warning: The system exploded!!! *****" << endl << endl;
160 return mp->Epot;
161 }
162 if ( iter == 1 ) {
163 for ( i=0; i<ETERMS; i++ ) E0[i] = E[i];
164 Epot0 = mp->Epot;
165 }
166 if ( mm_type < 1 ) model_minimize(model, max_shift);
167 else mp->Ekin = model_verlet(model, mp->timestep, mp->Kfriction, velocitylimit);
168 model_shift(model, refcom - model_center_of_mass(model));
169 // if ( verbose & VERB_PROCESS ) {
170 if ( verbose ) {
171 cout << iter;
172 for ( i=0; i<ETERMS; i++ ) if ( h[i] )
173 cout << tab << E[i];
174 cout << tab << mp->Epot;
175 if ( mm_type ) cout << tab << mp->Ekin;
176 if ( verbose < VERB_PROCESS ) {
177 cout << "\r" << flush;
178 } else {
179 cout << endl;
180 }
181 }
182 }
183
184 double gyrad = model_gyration_radius(model);
185
186 if ( verbose ) {
187 cout << endl << endl;
188 cout << "EnergyTerm\tStart \tEnd \tChange" << endl;
189 for ( i=0, head = head_list; i<ETERMS && head; i++, head = head->next ) if ( h[i] ) {
190 cout << *head << tab << E0[i] << tab << E[i] << tab << E[i] - E0[i] << endl;
191 }
192 cout << "Epotential\t" << Epot0 << tab << mp->Epot << tab << mp->Epot - Epot0 << endl;
193 if ( mm_type ) cout << "Ekinetic\t\t" << mp->Ekin << endl;
194 cout << "Gyration radius\t" << gyrad0 << tab << gyrad << tab << gyrad - gyrad0 << endl;
195 cout << endl;
196 }
197
198 delete map;
199
200 model_calculate_deviations(model, mp);
201
202 return mp->Epot+mp->Ekin;
203 }
204
215 int model_minimize(Bmodel* model, double max_shift)
216 {
217 int n;
218 // Bmodel* mp;
219 Bcomponent* comp;
220
221 double irm = 1.0/get_rand_max();
222 Vector3<double> shift;
223
224 for ( n=0, comp = model->comp; comp; comp = comp->next, n++ ) if ( comp->sel ) {
225 if ( comp->type->mass > 0 ) comp->vec /= comp->type->mass;
226 shift = comp->vec * (random()*irm);
227 shift = shift.min(max_shift);
228 shift = shift.max(-max_shift);
229 comp->loc += shift;
230 comp->fom = comp->vec.length();
231 }
232
233 return n;
234 }
235
254 double model_verlet(Bmodel* model, double timestep, double Kfriction, double velocitylimit)
255 {
256 double vel, Ekin(0);
257 double minvel = -velocitylimit, maxvel = velocitylimit; // Maximum velocity per time step
258 Bcomponent* comp;
259
260 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
261 comp->vel += comp->vec * (timestep/comp->type->mass);
262 comp->vel *= Kfriction;
263 comp->vel = vector3_scalar_range(comp->vel, minvel, maxvel);
264 comp->loc += comp->vel * timestep;
265 // if ( wrap ) comp->loc = vector3_set_PBC(comp->loc, box);
266 vel = comp->vel.length();
267 Ekin += 0.5*comp->type->mass*vel*vel;
268 comp->fom = vel;
269 }
270
271 return Ekin;
272 }
273
274 /*
275 @brief Calculates the harmonic potential between components.
276 @param *link link.
277 @param d0 reference distance between components.
278 @param Kd distance force constant.
279 @return double link energy.
280
281 The harmonic energy function:
282 E = Kd*(d - d0)^2
283 The force is zero when d = reference link length (d0).
284 **/
285 double component_harmonic_potential(Bcomponent* comp1, Bcomponent* comp2, double d0, double Kd)
286 {
287 if ( d0 <= 0 || Kd <= 0 ) return 0;
288
289 double d, dev, fac, E(0);
290 Vector3<double> v, F;
291
292 v = comp1->loc - comp2->loc;
293 d = v.length();
294 dev = d - d0;
295 E = Kd*dev*dev;
296 if ( d ) {
297 fac = -2*Kd*dev/d;
298 F = v * fac;
299 comp1->vec += F;
300 comp2->vec -= F;
301 }
302
303 if ( verbose & VERB_DEBUG )
304 cout << "DEBUG component_harmonic_potential: c1=" << comp1->id <<
305 " c2=" << comp2->id << " Kd=" << Kd << " d0=" << d0 << " E=" << E << endl;
306
307 return E;
308 }
309
310 /*
311 @brief Calculates the soft sphere potential between components.
312 @param comp1 first component.
313 @param comp2 second component.
314 @param d0 reference distance between components.
315 @param Kd distance force constant.
316 @return double distance energy.
317
318 The soft sphere potential is given by:
319 E = Kd*(d0/d)^12
320 The potential is set to zero for d > 3*d0;
321 **/
322 double component_soft_potential(Bcomponent* comp1, Bcomponent* comp2, double d0, double Kd)
323 {
324 if ( d0 <= 0 || Kd <= 0 ) return 0;
325
326 double d2, d02 = d0*d0, fac, E(0);
327 double rd2, rd6, rd12;
328 Vector3<double> v, F;
329
330 v = comp2->loc - comp1->loc; // Points from 1 to 2
331 d2 = v.length2();
332 if ( d2 < 9*d02 ) {
333 rd2 = d02/d2;
334 rd6 = rd2*rd2*rd2;
335 rd12 = rd6*rd6;
336 E = Kd*rd12;
337 fac = -12*Kd*rd12/d2;
338 F = v * fac; // Force on 1 in direction of 2
339 comp1->vec += F;
340 comp2->vec -= F;
341 }
342
343 return E;
344 }
345
346 /*
347 @brief Calculates the Lennard-Jones potential between components.
348 @param comp1 first component.
349 @param comp2 second component.
350 @param d0 reference distance between components.
351 @param Kd distance force constant.
352 @return double distance energy.
353
354 The Lennard-Jones potential is given by:
355 E = Kd*((d0/d)^12 - 2*(d0/d)^6)
356 The force is zero when d = d0.
357 The potential is set to zero for d > 3*d0;
358 **/
359 double component_lennard_jones_potential(Bcomponent* comp1, Bcomponent* comp2, double d0, double Kd)
360 {
361 if ( d0 <= 0 || Kd <= 0 ) return 0;
362
363 double d2, d02 = d0*d0, fac, E(0);
364 double rd2, rd6, rd12;
365 Vector3<double> v, F;
366
367 v = comp2->loc - comp1->loc; // Points from 1 to 2
368 d2 = v.length2();
369 if ( d2 < 9*d02 ) {
370 rd2 = d02/d2;
371 rd6 = rd2*rd2*rd2;
372 rd12 = rd6*rd6;
373 E = Kd*(rd12 - 2*rd6);
374 fac = -12*Kd*(rd12 - rd6)/d2;
375 F = v * fac; // Force on 1 in direction of 2
376 comp1->vec += F;
377 comp2->vec -= F;
378 }
379
380 return E;
381 }
382
383 /*
384 @brief Calculates the Morse potential between components.
385 @param comp1 first component.
386 @param comp2 second component.
387 @param d0 reference distance between components.
388 @param Kd distance force constant.
389 @return double distance energy.
390
391 The Morse potential is given by:
392 E = Kd*((1-exp((a/d0)*(d0-d)))^2 - 1)
393 The width of the energy well is given by a, set here to 6.
394 The force is zero when d = d0.
395 The potential is set to zero for d > 3*d0;
396 **/
397 double component_morse_potential(Bcomponent* comp1, Bcomponent* comp2, double d0, double Kd)
398 {
399 if ( d0 <= 0 || Kd <= 0 ) return 0;
400
401 double d, fac, E(0);
402 double ef, ef1, a = 6/d0;
403 Vector3<double> v, F;
404
405 v = comp2->loc - comp1->loc; // Points from 1 to 2
406 d = v.length();
407 if ( d < 3*d0 ) {
408 ef = exp(a*(d0 - d));
409 ef1 = 1 - ef;
410 E = Kd*(ef1*ef1 - 1);
411 fac = 2*a*Kd*ef1*ef/d;
412 F = v * fac; // Force on 1 in direction of 2
413 comp1->vec += F;
414 comp2->vec -= F;
415 }
416
417 return E;
418 }
419
420 /*
421 @brief Calculates the potential between two links to a component.
422 @param comp component.
423 @param comp1 first component linked to.
424 @param comp2 second component linked to.
425 @param a0 reference angle between linked components.
426 @param Ka angular force constant.
427 @return double angular energy.
428
429 The angular potential is given by:
430 E = Ka*(a - a0)^2
431 The force is zero when a = a0.
432 **/
433 double component_angular_potential(Bcomponent* comp, Bcomponent* comp1, Bcomponent* comp2, double a0, double Ka)
434 {
435 if ( Ka <= 0 ) return 0;
436
437 double v1len, v2len, da, fac, E(0);
438 Vector3<double> v1, v2, n;
439
440 v1 = comp1->loc - comp->loc;
441 v2 = comp2->loc - comp->loc;
442 n = v1.cross(v2);
443 n.normalize();
444 v1len = v1.normalize();
445 v2len = v2.normalize();
446 da = acos(v1.scalar(v2)) - a0;
447 fac = -2*Ka*da;
448 E = Ka*da*da*v1len*v2len;
449 comp1->vec -= n.cross(v1) * fac * v1len;
450 comp2->vec += n.cross(v2) * fac * v2len;
451
452 return E;
453 }
454
455 /*
456 @brief Calculates the potential between a component and a point.
457 @param comp component.
458 @param point reference point = radial center.
459 @param d0 reference distance between component and point.
460 @param Kradial radial force constant.
461 @return double radial energy.
462
463 The radial potential is given by:
464 E = Kd*(d - d0)^2
465 The force is zero when d = d0.
466 **/
467 double component_radial_potential(Bcomponent* comp, Vector3<double> point, double d0, double Kradial)
468 {
469 if ( Kradial <= 0 ) return 0;
470
471 double d, dev, fac, E(0);
472 Vector3<double> v, F;
473
474 v = comp->loc - point; // Points from center to component
475 d = v.length();
476 dev = d - d0;
477 E = Kradial*dev*dev;
478 if ( d ) {
479 fac = -2*Kradial*dev/d;
480 F = v * fac;
481 comp->vec += F;
482 }
483
484 return E;
485 }
486
501 double model_distance_energy(Bmodel* model, Bmodparam* mp)
502 {
503 if ( mp->Kdistance <= 0 ) return 0;
504
505 if ( verbose & VERB_DEBUG )
506 cout << "DEBUG model_distance_energy: Kd=" << mp->Kdistance << endl;
507
508 long i;
509 double Kd, E(0);
510 Bcomponent* comp;
511 Bcomponent* comp2;
512
513 for ( comp = model->comp; comp->next; comp = comp->next ) if ( comp->sel && comp->type->index >= 0 ) {
514 for ( comp2 = comp->next; comp2; comp2 = comp2->next ) if ( comp2->sel && comp2->type->index >= 0 ) {
515 i = comp->type->index*mp->ntype + comp2->type->index;
516 Kd = mp->Kdistance * mp->Kd[i];
517 if ( verbose & VERB_DEBUG )
518 cout << "DEBUG model_distance_energy: c1=" << comp->id <<
519 " c2=" << comp2->id << " type=" << mp->pot[i] <<
520 " Kd=" << Kd << " d0=" << mp->dist[i] << endl;
521 switch ( mp->pot[i] ) {
522 case 1:
523 E += component_harmonic_potential(comp, comp2, mp->dist[i], Kd);
524 break;
525 case 2:
526 E += component_soft_potential(comp, comp2, mp->dist[i], Kd);
527 break;
528 case 3:
529 E += component_lennard_jones_potential(comp, comp2, mp->dist[i], Kd);
530 break;
531 case 4:
532 E += component_morse_potential(comp, comp2, mp->dist[i], Kd);
533 break;
534 // default:
535 }
536 }
537 }
538
539 return E;
540 }
541
556 double model_neighbor_distance_energy(Bmodel* model, Bmodparam* mp)
557 {
558 if ( mp->Kdistance <= 0 ) return 0;
559
560 if ( verbose & VERB_DEBUG )
561 cout << "DEBUG model_neighbor_distance_energy: Kd=" << mp->Kdistance << endl;
562
563 long i, i1, i2, n;
564 double Kd, E(0);
565 Bcomponent* comp;
566 Bcomponent* comp2;
567
568 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
569 i1 = comp->type->index;
570 // if ( i1 >= 0 ) {
571 for ( n=0; n<MAXLINK && comp->neighbor[n]; n++ ) {
572 comp2 = comp->neighbor[n];
573 i2 = comp2->type->index;
574 if ( ( comp->id < comp2->id ) && comp2->sel ) {
575 i = i1*mp->ntype + i2;
576 Kd = mp->Kdistance * mp->Kd[i];
577 if ( verbose & VERB_DEBUG )
578 cout << "DEBUG model_neighbor_distance_energy: c1=" << comp->id <<
579 " c2=" << comp2->id << " type=" << mp->pot[i] <<
580 " Kd=" << Kd << " d0=" << mp->dist[i] << endl;
581 switch ( mp->pot[i] ) {
582 case 1:
583 E += component_harmonic_potential(comp, comp2, mp->dist[i], Kd);
584 break;
585 case 2:
586 E += component_soft_potential(comp, comp2, mp->dist[i], Kd);
587 break;
588 case 3:
589 E += component_lennard_jones_potential(comp, comp2, mp->dist[i], Kd);
590 break;
591 case 4:
592 E += component_morse_potential(comp, comp2, mp->dist[i], Kd);
593 break;
594 // default:
595 }
596 }
597 }
598 // }
599 }
600
601 return E;
602 }
603
616 double model_soft_sphere_energy(Bmodel* model, double Kd, double d0)
617 {
618 if ( Kd <= 0 ) return 0;
619
620 double E(0);
621 Bcomponent* comp;
622 Bcomponent* comp2;
623
624 for ( comp = model->comp; comp->next; comp = comp->next )
625 for ( comp2 = comp->next; comp2; comp2 = comp2->next )
626 E += component_soft_potential(comp, comp2, d0, Kd);
627
628 return E;
629 }
630
644 double model_lennard_jones_energy(Bmodel* model, double Kd, double d0)
645 {
646 if ( Kd <= 0 ) return 0;
647
648 double E(0);
649 Bcomponent* comp;
650 Bcomponent* comp2;
651
652 for ( comp = model->comp; comp->next; comp = comp->next )
653 for ( comp2 = comp->next; comp2; comp2 = comp2->next )
654 E += component_lennard_jones_potential(comp, comp2, d0, Kd);
655
656 return E;
657 }
658
673 double model_morse_energy(Bmodel* model, double Kd, double d0)
674 {
675 if ( Kd <= 0 ) return 0;
676
677 double E(0);
678 Bcomponent* comp;
679 Bcomponent* comp2;
680
681 for ( comp = model->comp; comp->next; comp = comp->next )
682 for ( comp2 = comp->next; comp2; comp2 = comp2->next )
683 E += component_morse_potential(comp, comp2, d0, Kd);
684
685 return E;
686 }
687
699 double model_link_energy(Bmodel* model, Bmodparam* mp)
700 {
701 if ( mp->Klink <= 0 ) return 0;
702
703 int i;
704 double E(0);
705 Blink* link;
706
707 for ( link = model->link; link; link = link->next ) {
708 i = link->comp[0]->type->index*mp->ntype + link->comp[1]->type->index;
709 E += component_harmonic_potential(link->comp[0], link->comp[1],
710 mp->llen[i], mp->Klink * mp->Kl[i]);
711 }
712
713 return E;
714 }
715
727 double model_link_energy(Bmodel* model, double Klink)
728 {
729 if ( Klink <= 0 ) return 0;
730
731 double E(0);
732 Blink* link;
733
734 for ( link = model->link; link; link = link->next )
735 E += component_harmonic_potential(link->comp[0], link->comp[1], link->length, Klink);
736
737 return E;
738 }
739
751 double model_angle_energy(Bmodel* model, Bmodparam* mp)
752 {
753 if ( mp->Kangle <= 0 ) return 0;
754
755 int i, j, k;
756 double E(0);
757
758 Bcomponent* comp;
759 Bcomponent* comp1;
760 Bcomponent* comp2;
761
762 for ( comp = model->comp; comp; comp = comp->next ) {
763 for ( j=1; j<MAXLINK && comp->link[j]; j++ ) {
764 comp1 = comp->link[j];
765 for ( k=0; k<j && comp->link[k]; k++ ) {
766 comp2 = comp->link[k];
767 i = (comp->type->index*mp->ntype + comp1->type->index)*mp->ntype + comp2->type->index;
768 E += component_angular_potential(comp, comp1, comp2, mp->angle[i], mp->Kangle * mp->Ka[i]);
769 }
770 }
771 }
772
773 return E;
774 }
775
776
794 double model_polygon_angle_energy(Bmodel* model, double Kpolyangle)
795 {
796 if ( Kpolyangle <= 0 ) return 0;
797
798 int i;
799 double a0, E(0);
800 Bpolygon* poly;
801 Bcomponent *comp, *comp1, *comp2;
802
803 if ( !model->poly ) model_poly_generate(model);
804
805 for ( poly = model->poly; poly; poly = poly->next ) if ( poly->closed ) {
806 a0 = M_PI*(1 - 2.0L/poly->number);
807 for ( i=0, comp1 = poly->comp[poly->number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp, i++ ) {
808 comp = poly->comp[i];
809 comp2 = poly->comp[i+1];
810 if ( !comp2 ) comp2 = poly->comp[0];
811 E += component_angular_potential(comp, comp1, comp2, a0, Kpolyangle);
812 }
813 }
814
815 return E;
816 }
817
834 double model_polygon_energy(Bmodel* model, double linklength, double Kpoly)
835 {
836 if ( Kpoly <= 0 ) return 0;
837
838 int i;
839 double dr, dist, dev, fac, E(0);
840 Vector3<double> d, polycen, dcen;
841 Bpolygon* poly;
842
843 if ( !model->poly ) model_poly_generate(model);
844
845 for ( poly = model->poly; poly; poly = poly->next ) if ( poly->closed ) {
846 for ( i=0, polycen = 0; i<MAXLINK && poly->comp[i]; i++ )
847 polycen += poly->comp[i]->loc; // Center of polygon
848 polycen /= i;
849 if ( linklength > 0 ) {
850 dr = linklength/sqrt(2*(1 - cos(TWOPI/i))); // Reference distance to polygon center
851 } else {
852 for ( i=0, dcen = 0; i<MAXLINK && poly->comp[i]; i++ )
853 dcen += poly->comp[i]->loc.distance(polycen); // Distance to center
854 dcen /= i;
855 dr = dcen.length(); // Reference distance to polygon center
856 }
857 for ( i=0; i<MAXLINK && poly->comp[i]; i++ ) {
858 d = poly->comp[i]->loc - polycen;
859 dist = d.length();
860 dev = dist - dr;
861 E += Kpoly*dev*dev;
862 fac = -2*Kpoly*dev/dist;
863 poly->comp[i]->vec += d*fac;
864 }
865 }
866
867 return E;
868 }
869
882 double model_polygon_energy(Bmodel* model, double Kpoly)
883 {
884 return model_polygon_energy(model, 0, Kpoly);
885 }
886
900 double model_polygon_plane_energy(Bmodel* model, double Kpolyplane)
901 {
902 if ( Kpolyplane <= 0 ) return 0;
903
904 long i;
905 double dev, fac, E(0), offset;
906 Vector3<double> normal;
907 Bpolygon* poly;
908
909 if ( !model->poly ) model_poly_generate(model);
910
911 for ( poly = model->poly; poly; poly = poly->next ) if ( poly->closed ) {
912 normal = component_plane(poly->comp, offset);
913 for ( i=0; i<MAXLINK && poly->comp[i]; i++ ) {
914 dev = poly->comp[i]->loc.scalar(normal) - offset;
915 E += Kpolyplane*dev*dev;
916 fac = -2*Kpolyplane*dev;
917 poly->comp[i]->vec += normal*fac;
918 }
919 }
920
921 return E;
922 }
923
937 double model_neighbor_plane_energy(Bmodel* model, double Kplane)
938 {
939 if ( Kplane <= 0 ) return 0;
940
941 double dev, fac, E(0), offset;
942 Vector3<double> v, normal, center;
943 Bcomponent* comp;
944
945 for ( comp = model->comp; comp; comp = comp->next ) {
946 normal = component_plane(comp->neighbor, offset);
947 dev = comp->loc.scalar(normal) - offset;
948 E += Kplane*dev*dev;
949 fac = -2*Kplane*dev;
950 comp->vec += normal*fac;
951 /* for ( i=0; i<MAXLINK && comp->neighbor[i]; i++ ) {
952 v = comp->neighbor[i]->loc - comp->loc;
953 v -= normal * normal.scalar(v);
954 dev = v.normalize() - 50;
955 E += Kplane*dev*dev;
956 fac = -2*Kplane*dev;
957 comp->vec += v*fac;
958 }*/
959 }
960
961 return E;
962 }
963
984 double model_point_force(Bmodel* model, Vector3<double> point, double Kpoint, double decay)
985 {
986 if ( Kpoint <= 0 ) return 0;
987
988 double dist, en1, energy(0);
989 Vector3<double> dir;
990 Bmodel* mp;
991 Bcomponent* comp;
992
993 for ( mp = model; mp; mp = mp->next ) {
994 for ( comp = mp->comp; comp; comp = comp->next ) {
995 dir = comp->loc - point;
996 dist = dir.length();
997 en1 = Kpoint*exp(-decay*dist);
998 energy += en1;
999 comp->vec += dir * (decay*en1/dist);
1000 }
1001 }
1002
1003 return energy;
1004 }
1005
1019 double model_radial_energy(Bmodel* model, Vector3<double> point, double d0, double Kradial)
1020 {
1021 if ( Kradial <= 0 ) return 0;
1022
1023 double E(0);
1024 Bcomponent* comp;
1025
1026 for ( comp = model->comp; comp; comp = comp->next )
1027 E += component_radial_potential(comp, point, d0, Kradial);
1028
1029 return E;
1030 }
1031
1041 double model_polyhedron_guide_energy(Bmodel* model, Bmodel* gmod, double Kguide)
1042 {
1043 if ( Kguide <= 0 ) return 0;
1044 if ( !gmod ) return 0;
1045
1046 int n;
1047 double d, len, fac, E(0);
1048 Vector3<double> center, F;
1049 Bcomponent* comp;
1050 Bcomponent* gcomp;
1051
1052 // Calculate the center of the vertices in the guide model
1053 for ( n=0, gcomp = gmod->comp; gcomp; gcomp = gcomp->next, n++ )
1054 center += gcomp->loc;
1055
1056 if ( n ) center /= n;
1057
1058 // Calculate the component vectors in the guide model
1059 for ( gcomp = gmod->comp; gcomp; gcomp = gcomp->next )
1060 gcomp->vec = gcomp->loc;
1061 // gcomp->vec = gcomp->loc - center;
1062
1063 for ( comp = model->comp; comp; comp = comp->next ) {
1064 d = model_inside_outside(comp->loc, gmod, 0, 1);
1065 if ( !isfinite(d) ) {
1066 cerr << "d not finite: " << d << endl;
1067 bexit(-1);
1068 }
1069 E += Kguide*d*d;
1070 len = comp->loc.length();
1071 if ( len ) {
1072 fac = 2*Kguide*d/len;
1073 F = comp->loc * fac;
1074 comp->vec += F;
1075 }
1076 }
1077
1078 return E;
1079 }
1080
1091 double model_map_energy(Bmodel* model, Bimage* map, double Kmap)
1092 {
1093 if ( !model ) return 0;
1094 if ( !map ) return 0;
1095 if ( Kmap == 0 ) return 0;
1096
1097 map->change_type(Float);
1098
1099 long i, n(0);
1100 long x, y, z;
1101 long slicesize = map->sizeX()*map->sizeY();
1102 double E(0);
1103 Vector3<double> invunit(0.5*Kmap/map->sampling()[0], 0.5*Kmap/map->sampling()[1], 0.5*Kmap/map->sampling()[2]);
1104 Vector3<double> F;
1105 Bcomponent* comp;
1106
1107 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1108 x = (long) (comp->loc[0]/map->sampling()[0] + map->image->origin()[0] + 0.5);
1109 y = (long) (comp->loc[1]/map->sampling()[1] + map->image->origin()[1] + 0.5);
1110 z = (long) (comp->loc[2]/map->sampling()[2] + map->image->origin()[2] + 0.5);
1111 if ( x>0 && x<map->sizeX()-1 && y>0 && y<map->sizeY()-1 && z>0 && z<map->sizeZ()-1 ) {
1112 i = map->index(0, x, y, z, 0);
1113 F = Vector3<double>((*map)[i+1] - (*map)[i-1], (*map)[i+map->sizeX()] - (*map)[i-map->sizeX()],
1114 (*map)[i+slicesize] - (*map)[i-slicesize]);
1115 E -= (*map)[i];
1116 comp->vec += F * invunit;
1117 n++;
1118 }
1119 }
1120
1121 if ( n < 1 ) {
1122 if ( verbose & VERB_PROCESS )
1123 cout << "Warning: Model outside map boundaries!" << endl;
1124 E = 1e100;
1125 } else
1126 E = Kmap*((E/n + map->average())/map->standard_deviation() + 10);
1127
1128 return E;
1129 }
1130
1131 double model_map_energy(Bmodel* model, Bimage* map, double Kmap, double sigma)
1132 {
1133 if ( !model ) return 0;
1134 if ( !map ) return 0;
1135 if ( Kmap == 0 ) return 0;
1136
1137 if ( sigma < map->sampling()[0] ) sigma = map->sampling()[0];
1138
1139 map->change_type(Float);
1140
1141 Vector3<double> pixsigma(sigma/map->sampling()[0], sigma/map->sampling()[1], sigma/map->sampling()[2]);
1142 // Vector3<double> pixsigma2 = pixsigma*pixsigma;
1143 Vector3<int> ksize = Vector3<int>((int) (6*pixsigma[0]), (int) (6*pixsigma[1]), (int) (6*pixsigma[2]));
1144 ksize = ksize.max(3);
1145 Vector3<int> hksize = ksize/2;
1146 double* kernel = new double[(long)ksize.volume()];
1147
1148 long i, k, n(0);
1149 long x, y, z, ix, iy, iz, kx, ky, kz;
1150 double dx, dy, dz, v, w, E1, E(0);
1151 double sigma2 = sigma*sigma;
1152 double ffac = Kmap/sigma2;
1153 Vector3<double> F;
1154 Bcomponent* comp;
1155
1156 for ( i=0, z=0; z<ksize[2]; z++ ) {
1157 dz = (z - hksize[2])/pixsigma[2];
1158 for ( y=0; y<ksize[1]; y++ ) {
1159 dy = (y - hksize[1])/pixsigma[1];
1160 for ( x=0; x<ksize[0]; x++, i++ ) {
1161 dx = (x - hksize[0])/pixsigma[0];
1162 kernel[i] = exp(-0.5*(dx*dx + dy*dy + dz*dz));
1163 }
1164 }
1165 }
1166
1167 for ( comp = model->comp; comp; comp = comp->next ) {
1168 x = (long) (comp->loc[0]/map->sampling()[0] + map->image->origin()[0] + 0.5);
1169 y = (long) (comp->loc[1]/map->sampling()[1] + map->image->origin()[1] + 0.5);
1170 z = (long) (comp->loc[2]/map->sampling()[2] + map->image->origin()[2] + 0.5);
1171 E1 = w =0;
1172 F = 0;
1173 for ( iz = z - hksize[2], kz=0; kz<ksize[2]; iz++, kz++ ) if ( iz>=0 && iz<map->sizeZ() ) {
1174 dz = (kz - hksize[2])*map->sampling()[2];
1175 for ( iy = y - hksize[1], ky=0; ky<ksize[1]; iy++, ky++ ) if ( iy>=0 && iy<map->sizeY() ) {
1176 dy = (ky - hksize[1])*map->sampling()[1];
1177 for ( ix = x - hksize[0], kx=0; kx<ksize[0]; ix++, kx++ ) if ( ix>=0 && ix<map->sizeX() ) {
1178 dx = (kx - hksize[0])*map->sampling()[0];
1179 i = map->index(0, x, y, z, 0);
1180 k = (kz*ksize[1] + ky)*ksize[0] + kx;
1181 v = (*map)[i]*kernel[k];
1182 w += kernel[k];
1183 E1 += v;
1184 F += Vector3<double>(v*dx, v*dy, v*dz);
1185 }
1186 }
1187 }
1188 if ( w ) {
1189 E1 /= w; // Average density, correction for kernel volume
1190 F /= w; // Average force
1191 comp->density = E1;
1192 if ( comp->type->mass ) {
1193 E1 *= comp->type->mass;
1194 F *= comp->type->mass;
1195 }
1196 E -= E1;
1197 comp->vec += F * ffac;
1198 n++;
1199 }
1200 }
1201
1202 if ( n < 1 ) {
1203 if ( verbose & VERB_PROCESS )
1204 cout << "Warning: Model outside map boundaries!" << endl;
1205 E = 1e100;
1206 } else
1207 E = Kmap*E/n;
1208
1209 delete[] kernel;
1210
1211 return E;
1212 }
1213
1221 int model_zero_forces(Bmodel* model)
1222 {
1223 int n(0);
1224 Bcomponent* comp;
1225
1226 for ( comp = model->comp; comp; comp = comp->next, n++ )
1227 comp->vec = 0;
1228
1229 return n;
1230 }
1231
1247 int model_calculate_deviations(Bmodel* model)
1248 {
1249 int i, n;
1250 double ll, d, dd, a, aa, ar, ad;
1251 Vector3<double> d1, d2;
1252 Bcomponent *comp1, *comp2, *comp3;
1253 Blink* link;
1254 Bpolygon* poly;
1255
1256 for ( n=0, ll=dd=0, link = model->link; link; link = link->next, n++ ) {
1257 d = link->comp[0]->loc.distance(link->comp[1]->loc);
1258 ll += d;
1259 d -= link->length;
1260 dd += d*d;
1261 }
1262
1263 if ( n ) {
1264 ll /= n;
1265 dd = sqrt(dd/n);
1266 }
1267
1268 if ( verbose )
1269 cout << "Link average and deviation: " << ll << " " << dd << " A" << endl;
1270
1271 for ( n=0, aa=ad=0, poly = model->poly; poly; poly = poly->next ) if ( poly->closed ) {
1272 ar = M_PI*(1 - 2.0L/poly->number);
1273 for ( i=0, comp1 = poly->comp[poly->number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp2, i++ ) {
1274 comp2 = poly->comp[i];
1275 comp3 = poly->comp[i+1];
1276 if ( !comp3 ) comp3 = poly->comp[0];
1277 d1 = comp2->loc - comp1->loc;
1278 d2 = comp2->loc - comp3->loc;
1279 a = d1.angle(d2);
1280 aa += a;
1281 a -= ar;
1282 ad += a*a;
1283 n++;
1284 }
1285 }
1286
1287 if ( n ) {
1288 aa /= n;
1289 ad = sqrt(ad/n);
1290 }
1291
1292 if ( verbose )
1293 cout << "Angle average and deviation: " << aa*180.0/M_PI << " " << ad*180.0/M_PI << " degrees" << endl << endl;
1294
1295 return 0;
1296 }
1297
1298 int model_calculate_deviations(Bmodel* model, Bmodparam* mp)
1299 {
1300 int i, j, k, n;
1301 double ll, d, dd, a, aa, ar, ad;
1302 Vector3<double> d1, d2;
1303 Bcomponent *comp, *comp1, *comp2;
1304 Blink* link;
1305 Bpolygon* poly;
1306
1307 if ( verbose )
1308 cout << " \tAverage\tDeviation" << endl;
1309
1310 for ( n=0, ll=dd=0, link = model->link; link; link = link->next, n++ ) {
1311 i = link->comp[0]->type->index*mp->ntype + link->comp[1]->type->index;
1312 d = link->comp[0]->loc.distance(link->comp[1]->loc);
1313 ll += d;
1314 d -= mp->llen[i];
1315 dd += d*d;
1316 }
1317
1318 if ( n ) {
1319 ll /= n;
1320 dd = sqrt(dd/n);
1321 }
1322
1323 if ( verbose )
1324 cout << "Links \t" << ll << tab << dd << endl;
1325
1326 for ( n=0, aa=ad=0, comp = model->comp; comp; comp = comp->next ) {
1327 for ( j=1; j<MAXLINK && comp->link[j]; j++ ) {
1328 comp1 = comp->link[j];
1329 for ( k=0; k<j && comp->link[k]; k++ ) {
1330 comp2 = comp->link[k];
1331 i = (comp->type->index*mp->ntype + comp1->type->index)*mp->ntype + comp2->type->index;
1332 if ( mp->angle[i] ) {
1333 d1 = comp1->loc - comp->loc;
1334 d2 = comp2->loc - comp->loc;
1335 a = d1.angle(d2);
1336 aa += a;
1337 a -= mp->angle[i];
1338 ad += a*a;
1339 n++;
1340 }
1341 }
1342 }
1343 }
1344
1345 if ( n ) {
1346 aa /= n;
1347 ad = sqrt(ad/n);
1348 }
1349
1350 if ( verbose )
1351 cout << "Angles \t" << aa*180.0/M_PI << tab << ad*180.0/M_PI << endl;
1352
1353 for ( n=0, aa=ad=0, poly = model->poly; poly; poly = poly->next ) if ( poly->closed ) {
1354 ar = M_PI*(1 - 2.0L/poly->number);
1355 for ( i=0, comp1 = poly->comp[poly->number-1]; i<MAXLINK && poly->comp[i]; comp1 = comp, i++ ) {
1356 comp = poly->comp[i];
1357 comp2 = poly->comp[i+1];
1358 if ( !comp2 ) comp2 = poly->comp[0];
1359 d1 = comp1->loc - comp->loc;
1360 d2 = comp2->loc - comp->loc;
1361 a = d1.angle(d2);
1362 aa += a;
1363 a -= ar;
1364 ad += a*a;
1365 n++;
1366 }
1367 }
1368
1369 if ( n ) {
1370 aa /= n;
1371 ad = sqrt(ad/n);
1372 }
1373
1374 if ( verbose )
1375 cout << "Polygon angles\t" << aa*180.0/M_PI << tab << ad*180.0/M_PI << endl << endl;
1376
1377 return 0;
1378 }
1379
1380
1381 double model_average_linklength(Bmodel* model)
1382 {
1383 int n(0);
1384 double linklength(0);
1385 Blink* link;
1386
1387 for ( link = model->link; link; link = link->next, n++ )
1388 linklength += link->length;
1389
1390 if ( n ) linklength /= n;
1391
1392 return linklength;
1393 }
1394
1411 int model_regularize(Bmodel* model, int max_iter, double distance,
1412 double Kdistance, double Klink, double Kpolyangle, double Kpolygon,
1413 double Kpolyplane, double Kpoint, double decay)
1414 {
1415 if ( !model->sel ) {
1416 cout << "No model selected for regularization!" << endl << endl;
1417 return 0;
1418 }
1419
1420 double linklength = model_average_linklength(model);
1421
1422 double max_shift = 0.1*linklength;
1423
1424 if ( max_shift < 1 ) max_shift = 0.1*distance;
1425
1426 if ( max_shift < 1 ) max_shift = 10;
1427
1428 if ( verbose ) {
1429 cout << "Regularizing a model:" << endl;
1430 cout << "Reference distance: " << distance << " A" << endl;
1431 cout << "Kdistance: " << Kdistance << endl;
1432 cout << "Link length: " << linklength << " A" << endl;
1433 cout << "Klink: " << Klink << endl;
1434 cout << "Kpolyangle: " << Kpolyangle << endl;
1435 cout << "Kpolygon: " << Kpolygon << endl;
1436 cout << "Kpolyplane: " << Kpolyplane << endl;
1437 cout << "Kpoint: " << Kpoint << " (" << decay << ")" << endl;
1438 cout << "Maximum shift per iteration: " << max_shift << " A" << endl << endl;
1439 }
1440
1441 long iter(0);
1442 double Edist0(0), Elink0(0), Eangle0(0), Epoly0(0), Eplane0(0), Epoint0(0), E0(0);
1443 double Edist(0), Elink(0), Eangle(0), Epoly(0), Eplane(0), Epoint(0), E(0);
1444
1445 model_calculate_deviations(model);
1446
1447 Vector3<double> refcom = model_center_of_mass(model);
1448
1449 if ( verbose & VERB_PROCESS )
1450 cout << "Iter\tEdist\tElink\tEangle\tEpoly\tEplane\tEpoint\tE" << endl;
1451 for ( iter=1; iter<=max_iter; iter++ ) {
1452 model_zero_forces(model);
1453 Edist = model_lennard_jones_energy(model, Kdistance, distance);
1454 Elink = model_link_energy(model, Klink);
1455 Eangle = model_polygon_angle_energy(model, Kpolyangle);
1456 Epoly = model_polygon_energy(model, Kpolygon);
1457 Eplane = model_polygon_plane_energy(model, Kpolyplane);
1458 Epoint = model_point_force(model, refcom, Kpoint, decay);
1459 E = Edist + Elink + Eangle + Epoly + Eplane + Epoint;
1460 if ( iter == 1 ) {
1461 Edist0 = Edist;
1462 Elink0 = Elink;
1463 Eangle0 = Eangle;
1464 Epoly0 = Epoly;
1465 Eplane0 = Eplane;
1466 Epoint0 = Epoint;
1467 E0 = E;
1468 }
1469 model_minimize(model, max_shift);
1470 model_shift(model, refcom - model_center_of_mass(model));
1471 if ( verbose & VERB_PROCESS )
1472 cout << iter << tab << Edist << tab << Elink << tab << Eangle << tab
1473 << Epoly << tab << Eplane << tab << Epoint << tab << E << endl;
1474 }
1475
1476 if ( verbose ) {
1477 cout << endl << "\tEdistance\tElinklength\tEangledev\tEpolyreg\tEpolyplane\tEpointdist\tE" << endl;
1478 cout << "Start:\t" << Edist0 << tab << Elink0 << tab << Eangle0 << tab <<
1479 Epoly0 << tab << Eplane0 << tab << Epoint0 << tab << E0 << endl;
1480 cout << "End:\t" << Edist << tab << Elink << tab << Eangle << tab <<
1481 Epoly << tab << Eplane << tab << Epoint << tab << E << endl;
1482 cout << "Change:\t" << Edist - Edist0 << tab << Elink - Elink0 << tab <<
1483 Eangle - Eangle0 << tab << Epoly - Epoly0 << tab << Eplane - Eplane0 << tab <<
1484 Epoint - Epoint0 << tab << E - E0 << endl << endl;
1485 }
1486
1487 model_calculate_deviations(model);
1488
1489 return 0;
1490 }
1491
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bmodparam::Elink
double Elink
Definition: rwmodel_param.h:60
component_radial_potential
double component_radial_potential(Bcomponent *comp, Vector3< double > point, double d0, double Kradial)
Definition: model_mechanics.cpp:467
Bmodparam::Kpolyplane
double Kpolyplane
Definition: rwmodel_param.h:44
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
Bmodel::img_num
int img_num
Definition: rwmodel.h:127
verbose
int verbose
MAXLINK
#define MAXLINK
Definition: rwmodel.h:14
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
Vector3::cross
Vector3 cross(const Vector3 &v)
Definition: Vector3.h:250
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
component_lennard_jones_potential
double component_lennard_jones_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
Definition: model_mechanics.cpp:359
Bmodparam::Kpoint
double Kpoint
Definition: rwmodel_param.h:45
Vector3::normalize
double normalize()
Definition: Vector3.h:236
Blink
Definition: rwmodel.h:82
Bmodel::id
Bstring id
Definition: rwmodel.h:121
Bmodparam::Kradial
double Kradial
Definition: rwmodel_param.h:46
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
Vector3::length
double length()
Definition: Vector3.h:222
Bmodparam::Epoint
double Epoint
Definition: rwmodel_param.h:65
Bmodparam::Kplane
double Kplane
Definition: rwmodel_param.h:47
symmetry.h
Header file for general symmetry functions.
model_minimize
int model_minimize(Bmodel *model, double max_shift)
Move components random distances down the energy gradient.
Definition: model_mechanics.cpp:215
utilities.h
Header file for general utilities.
model_util.h
Library routines used for model processing.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
model_shell.h
Library routines used for shell model processing.
model_polygon_angle_energy
double model_polygon_angle_energy(Bmodel *model, double Kpolyangle)
Calculates the link angular forces and energy.
Definition: model_mechanics.cpp:794
model_lennard_jones_energy
double model_lennard_jones_energy(Bmodel *model, double Kd, double d0)
Calculates the Lennard-Jones potential between components.
Definition: model_mechanics.cpp:644
Bmodparam::Kfriction
double Kfriction
Definition: rwmodel_param.h:38
Bpolygon::comp
Bcomponent * comp[MAXLINK]
Definition: rwmodel.h:105
Bmodparam::radius
double radius
Definition: rwmodel_param.h:53
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:383
Bpolygon
Definition: rwmodel.h:102
component_angular_potential
double component_angular_potential(Bcomponent *comp, Bcomponent *comp1, Bcomponent *comp2, double a0, double Ka)
Definition: model_mechanics.cpp:433
Bmodparam::Kdistance
double Kdistance
Definition: rwmodel_param.h:39
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmodparam::Eguide
double Eguide
Definition: rwmodel_param.h:68
Bcomptype::mass
float mass
Definition: rwmodel.h:32
Bmodel::sel
int sel
Definition: rwmodel.h:129
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
model_verlet
double model_verlet(Bmodel *model, double timestep, double Kfriction, double velocitylimit)
Model dynamics using the velocity verlet integrator.
Definition: model_mechanics.cpp:254
Bmodparam::pot
int * pot
Definition: rwmodel_param.h:78
model_radial_energy
double model_radial_energy(Bmodel *model, Vector3< double > point, double d0, double Kradial)
Calculates the potential between a components and a point.
Definition: model_mechanics.cpp:1019
model_mechanics.h
Functions to do molecular mechanics.
Bcomponent::neighbor
Bcomponent * neighbor[MAXLINK]
Definition: rwmodel.h:56
ETERMS
#define ETERMS
Definition: model_mechanics.cpp:24
Bcomponent::vel
Vector3< float > vel
Definition: rwmodel.h:61
Blink::comp
Bcomponent * comp[2]
Definition: rwmodel.h:84
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
model_polygon_energy
double model_polygon_energy(Bmodel *model, double linklength, double Kpoly)
Calculates the polygon regularity.
Definition: model_mechanics.cpp:834
model_soft_sphere_energy
double model_soft_sphere_energy(Bmodel *model, double Kd, double d0)
Calculates the soft sphere potential between components.
Definition: model_mechanics.cpp:616
Float
Definition: utilities.h:157
Vector3::max
Type max()
Definition: Vector3.h:175
model_link_energy
double model_link_energy(Bmodel *model, Bmodparam *mp)
Calculates the model link energy.
Definition: model_mechanics.cpp:699
Bmodparam
Definition: rwmodel_param.h:35
Bpolygon::number
int number
Definition: rwmodel.h:104
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
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmodparam::Kangle
double Kangle
Definition: rwmodel_param.h:41
Bmodparam::Kl
float * Kl
Definition: rwmodel_param.h:76
Bcomptype::index
int index
Definition: rwmodel.h:28
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
Bmodparam::dist
float * dist
Definition: rwmodel_param.h:75
isfinite
bool isfinite(complex< T > &value)
Blink::length
float length
Definition: rwmodel.h:86
model_point_force
double model_point_force(Bmodel *model, Vector3< double > point, double Kpoint, double decay)
Calculates the forces and energy resulting from a single point force.
Definition: model_mechanics.cpp:984
Blink::next
Blink * next
Definition: rwmodel.h:83
Bcomponent::fom
float fom
Definition: rwmodel.h:65
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:247
model_shift
long model_shift(Bmodel *model, Vector3< double > shift)
Shifts a model.
Definition: model_transform.cpp:43
model_map_energy
double model_map_energy(Bmodel *model, Bimage *map, double Kmap)
Energy calculation of a model into a map.
Definition: model_mechanics.cpp:1091
Bstring::next
Bstring * next
Definition: Bstring.h:31
Bmodparam::Epolyangle
double Epolyangle
Definition: rwmodel_param.h:62
model_gyration_radius
double model_gyration_radius(Bmodel *model)
Calculates the radius of gyration for a model.
Definition: model_util.cpp:503
Vector3::angle
double angle(Vector3< T2 > &v)
Definition: Vector3.h:257
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
Bcomponent::density
float density
Definition: rwmodel.h:64
model_polyhedron_guide_energy
double model_polyhedron_guide_energy(Bmodel *model, Bmodel *gmod, double Kguide)
Calculates the potential with respect to a guide polyhedron.
Definition: model_mechanics.cpp:1041
Bpolygon::next
Bpolygon * next
Definition: rwmodel.h:103
Bmodparam::sigma
double sigma
Definition: rwmodel_param.h:58
Bmodparam::Edistance
double Edistance
Definition: rwmodel_param.h:59
Bmodparam::Eplane
double Eplane
Definition: rwmodel_param.h:67
irm
double irm(1.0L/get_rand_max())
model_poly_generate
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Definition: model_poly.cpp:145
Bmodparam::llen
float * llen
Definition: rwmodel_param.h:74
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
vector3_scalar_range
Vector3< Type > vector3_scalar_range(Vector3< Type > vec, double min, double max)
Definition: Vector3.h:652
model_poly.h
Functions to manipulate polyhedral coordinate files.
Vector3::length2
double length2()
Definition: Vector3.h:221
model_distance_energy
double model_distance_energy(Bmodel *model, Bmodparam *mp)
Calculates the distance-related potentials between components.
Definition: model_mechanics.cpp:501
Bmodparam::Ka
float * Ka
Definition: rwmodel_param.h:80
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:537
model_zero_forces
int model_zero_forces(Bmodel *model)
Zeroes the component forces.
Definition: model_mechanics.cpp:1221
Bmodparam::Eangle
double Eangle
Definition: rwmodel_param.h:61
Bcomponent::sel
int sel
Definition: rwmodel.h:66
Bmodparam::ntype
int ntype
Definition: rwmodel_param.h:72
model
Bmodel * model
Definition: bshow.cpp:32
Bmodparam::Ekin
double Ekin
Definition: rwmodel_param.h:70
Bmodparam::Epolygon
double Epolygon
Definition: rwmodel_param.h:63
Bmodparam::Eradial
double Eradial
Definition: rwmodel_param.h:66
component_plane
Vector3< double > component_plane(Bcomponent **comparray, double &offset)
Calculates a plane through an array of components.
Definition: model_util.cpp:933
Bmodparam::timestep
double timestep
Definition: rwmodel_param.h:37
random_numbers.h
Header file for functions for creating random images.
Bmodparam::Kpolygon
double Kpolygon
Definition: rwmodel_param.h:43
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bcomponent::link
Bcomponent * link[MAXLINK]
Definition: rwmodel.h:55
Bmodel::link
Blink * link
Definition: rwmodel.h:133
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
component_harmonic_potential
double component_harmonic_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
Definition: model_mechanics.cpp:285
Bcomponent::vec
Vector3< float > vec
Definition: rwmodel.h:60
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
Bmodparam::Kmap
double Kmap
Definition: rwmodel_param.h:49
Bmodparam::angle
float * angle
Definition: rwmodel_param.h:79
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
model_morse_energy
double model_morse_energy(Bmodel *model, double Kd, double d0)
Calculates the Morse potential between components.
Definition: model_mechanics.cpp:673
Bmodparam::Kpolyangle
double Kpolyangle
Definition: rwmodel_param.h:42
Vector3< int >
component_soft_potential
double component_soft_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
Definition: model_mechanics.cpp:322
model_calculate_deviations
int model_calculate_deviations(Bmodel *model)
Calculates the deviations from regularity in a polyhedral model.
Definition: model_mechanics.cpp:1247
Vector3.h
Class for 3-value vectors.
model_average_linklength
double model_average_linklength(Bmodel *model)
Definition: model_mechanics.cpp:1381
model_polygon_plane_energy
double model_polygon_plane_energy(Bmodel *model, double Kpolyplane)
Calculates the polygon planarity energy and forces.
Definition: model_mechanics.cpp:900
Vector3::min
Type min()
Definition: Vector3.h:169
model_angle_energy
double model_angle_energy(Bmodel *model, Bmodparam *mp)
Calculates the model angular energy.
Definition: model_mechanics.cpp:751
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
Bmodel
Definition: rwmodel.h:119
Bmodparam::pointdecay
double pointdecay
Definition: rwmodel_param.h:52
Bmodparam::Emap
double Emap
Definition: rwmodel_param.h:69
kernel
Definition: kernlut.h:13
model_center_of_mass
Vector3< double > model_center_of_mass(Bmodel *model)
Definition: model_util.cpp:475
model_regularize
int model_regularize(Bmodel *model, int max_iter, double distance, double Kdistance, double Klink, double Kpolyangle, double Kpolygon, double Kpolyplane, double Kpoint, double decay)
Regularizes a model.
Definition: model_mechanics.cpp:1411
model_mass
double model_mass(Bmodel *model)
Calculates the mass of a model from component masses.
Definition: model_util.cpp:416
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
Bmodparam::Kd
float * Kd
Definition: rwmodel_param.h:77
Vector3::volume
double volume()
Definition: Vector3.h:235
Bmodparam::guide
Bmodel * guide
Definition: rwmodel_param.h:55
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
model_inside_outside
double model_inside_outside(Vector3< double > vec, Bmodel *model, int curv_flag, int fast)
Definition: model_shell.cpp:401
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
model_transform.h
Library routines used for model transformation.
Bmodparam::Epolyplane
double Epolyplane
Definition: rwmodel_param.h:64
Bmodparam::Klink
double Klink
Definition: rwmodel_param.h:40
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
TWOPI
#define TWOPI
Definition: utilities.h:68
model_neighbor_distance_energy
double model_neighbor_distance_energy(Bmodel *model, Bmodparam *mp)
Calculates the distance-related potentials between components and their neighbors.
Definition: model_mechanics.cpp:556
component_morse_potential
double component_morse_potential(Bcomponent *comp1, Bcomponent *comp2, double d0, double Kd)
Definition: model_mechanics.cpp:397
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
model_neighbor_plane_energy
double model_neighbor_plane_energy(Bmodel *model, double Kplane)
Calculates the planarity energy and forces with respect to neighbors.
Definition: model_mechanics.cpp:937
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
math_util.h
Header file for general utilities.
Bmodparam::Epot
double Epot
Definition: rwmodel_param.h:71
Bpolygon::closed
int closed
Definition: rwmodel.h:107
Bmodparam::point
Vector3< float > point
Definition: rwmodel_param.h:54
Bmodparam::Kguide
double Kguide
Definition: rwmodel_param.h:48
Bcomponent
Definition: rwmodel.h:51