Bsoft  2.1.0
Bernard's software package
model_util.cpp
Go to the documentation of this file.
1 
9 #include "model_util.h"
10 #include "model_transform.h"
11 #include "model_select.h"
12 #include "model_links.h"
13 #include "mol_transform.h"
14 #include "mol_compare.h"
15 #include "mol_util.h"
16 #include "symmetry.h"
17 #include "matrix_linear.h"
18 #include "matrix_util.h"
19 #include "Matrix3.h"
20 #include "random_numbers.h"
21 #include "linked_list.h"
22 #include "utilities.h"
23 
24 // Declaration of global variables
25 extern int verbose; // Level of output to the screen
26 
36 long models_process(Bmodel* model, long (modfunc)(Bmodel*))
37 {
38  long n(0);
39  Bmodel* mp;
40 
41  for ( mp = model; mp; mp = mp->next )
42  n += (modfunc)(mp);
43 
44  if ( verbose & VERB_PROCESS )
45  cout << "Elements processed: " << n << endl << endl;
46 
47  return n;
48 }
49 
60 long models_process(Bmodel* model, long i, long (modfunc)(Bmodel*, long))
61 {
62  long n(0);
63  Bmodel* mp;
64 
65  for ( mp = model; mp; mp = mp->next )
66  n += (modfunc)(mp, i);
67 
68  if ( verbose & VERB_PROCESS )
69  cout << "Elements processed: " << n << endl << endl;
70 
71  return n;
72 }
73 
84 long models_process(Bmodel* model, double d, long (modfunc)(Bmodel*, double))
85 {
86  long n(0);
87  Bmodel* mp;
88 
89  for ( mp = model; mp; mp = mp->next )
90  n += (modfunc)(mp, d);
91 
92  if ( verbose & VERB_PROCESS )
93  cout << "Elements processed: " << n << endl << endl;
94 
95  return n;
96 }
97 
108 long models_process(Bmodel* model, Bstring& str, long (modfunc)(Bmodel*, Bstring& str))
109 {
110  long n(0);
111  Bmodel* mp;
112 
113  for ( mp = model; mp; mp = mp->next )
114  n += (modfunc)(mp, str);
115 
116  if ( verbose & VERB_PROCESS )
117  cout << "Elements processed: " << n << endl << endl;
118 
119  return n;
120 }
121 
128 {
129  if ( !model ) return 0;
130 
131  long nmod(0), ncomp;
132  Bmodel* mp;
133  Bcomponent* comp;
134  Bstring type_id, sym, fmap;
135 
136  cout << "Model\tType\tNcomp\tPG\tHand\tFOM\tSelect\tMap\tNumber" << endl;
137  for ( mp = model; mp; mp = mp->next, nmod++ ) {
138  for ( ncomp=0, comp = mp->comp; comp; comp = comp->next ) ncomp++;
139  if ( mp->type_id.length() ) type_id = mp->type_id;
140  else type_id = "?";
141  if ( mp->symmetry.length() ) sym = mp->symmetry;
142  else sym = "?";
143  if ( mp->fmap.length() ) fmap = mp->fmap;
144  else fmap = "?";
145  cout << mp->id << tab << type_id << tab << ncomp << tab << sym << tab << mp->hand << tab <<
146  mp->fom << tab << mp->sel << tab << fmap << tab << mp->img_num << endl;
147  }
148  cout << endl;
149 
150  return nmod;
151 }
152 
159 {
160  if ( !model ) return 0;
161 
162  long i, nmod(0), nct(0);
163  Bmodel* mp;
164  Bcomponent* comp;
165  Bcomptype* ct;
166  Bstring type_id, sym, fmap;
167  Bstring* comptypelist = NULL;
168  Bstring* comptype = NULL;
169  Bstring* type = NULL;
170 
171  for ( mp = model; mp; mp = mp->next, nmod++ ) if ( mp->sel ) {
172  for ( ct = mp->type; ct; ct = ct->next ) {
173  for ( type = comptypelist; type && *type != ct->id; type = type->next ) ;
174  if ( !type ) {
175  comptype = string_add(&comptype, ct->id);
176  if ( !comptypelist ) comptypelist = comptype;
177  nct++;
178  }
179  }
180  }
181 
182  int* n = new int[nct];
183  int* ntot = new int[nct];
184  for ( i=0; i<nct; i++ ) ntot[i] = 0;
185 
186  cout << "Model";
187  for ( comptype = comptypelist; comptype; comptype = comptype->next )
188  cout << tab << *comptype;
189  cout << endl;
190 
191  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
192  for ( i=0; i<nct; i++ ) n[i] = 0;
193  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel ) {
194  for ( i=0, comptype = comptypelist; comptype && *comptype != comp->type->id; comptype = comptype->next, i++ ) ;
195  if ( comptype ) n[i]++;
196  }
197  cout << mp->id;
198  for ( i=0, comptype = comptypelist; comptype; comptype = comptype->next, i++ ) {
199  ntot[i] += n[i];
200  cout << tab << n[i];
201  }
202  cout << endl;
203  nmod++;
204  }
205 
206  cout << "Total";
207  for ( i=0, comptype = comptypelist; comptype; comptype = comptype->next, i++ )
208  cout << tab << ntot[i];
209  cout << endl << endl;
210 
211  delete[] n;
212  delete[] ntot;
213 
214  return nmod;
215 }
216 
228 {
229  int i;
230  Bmodel* mp;
231  Bcomptype* ct;
232  Bcomptype* ctref;
233  Bcomponent* comp;
234  Bcomponent* compref;
235  Blink* link;
236  Blink* linkref;
237  Bpolygon* poly;
238  Bpolygon* polyref;
239 
240  if ( verbose & VERB_FULL )
241  cout << "Replacing components in a model from a reference model: " << modref->id << endl;
242 
243  long n = count_list((char *) modref->comp);
244 
245  for ( mp = model; mp; mp = mp->next ) {
249  poly_list_kill(mp->poly);
250  mp->type = ct = NULL;
251  mp->comp = comp = NULL;
252  mp->link = link = NULL;
253  mp->poly = poly = NULL;
254  for ( ctref = modref->type; ctref; ctref = ctref->next ) {
255  ct = (Bcomptype *) add_item((char **) &ct, sizeof(Bcomptype));
256  if ( !mp->type ) mp->type = ct;
257  component_type_copy(ctref, ct);
258  }
259  for ( compref = modref->comp; compref; compref = compref->next ) {
260  comp = (Bcomponent *) add_item((char **) &comp, sizeof(Bcomponent));
261  if ( !mp->comp ) mp->comp = comp;
262  component_copy(compref, comp);
263  comp->type = model_add_type_by_id(mp, compref->type->id);
264  }
265  for ( linkref = modref->link; linkref; linkref = linkref->next ) {
266  link = (Blink *) add_item((char **) &link, sizeof(Blink));
267  if ( !modref->link ) modref->link = link;
268  for ( compref = modref->comp, comp = mp->comp; compref; compref = compref->next, comp = comp->next ) {
269  if ( linkref->comp[0] == compref ) link->comp[0] = comp;
270  if ( linkref->comp[1] == compref ) link->comp[1] = comp;
271  }
272  link->length = linkref->length;
273  link->radius = linkref->radius;
274  for ( i=0; i<4; i++ ) link->color[i] = linkref->color[i];
275  }
276  for ( polyref = modref->poly; polyref; polyref = polyref->next ) {
277  poly = (Bpolygon *) add_item((char **) &poly, sizeof(Bpolygon));
278  if ( !modref->poly ) modref->poly = poly;
279  poly->number = polyref->number;
280  poly->normal = polyref->normal;
281  poly->closed = polyref->closed;
282  for ( compref = modref->comp, comp = mp->comp; compref; compref = compref->next, comp = comp->next ) {
283  for ( i=0; polyref->comp[i]; i++ )
284  if ( polyref->comp[i] == compref ) poly->comp[i] = comp;
285  }
286  }
287  }
288 
290 
291  return n;
292 }
293 
300 {
301  if ( !model ) return 0;
302 
303  long nct, ncomp, nlink;
304  Bmodel* mp;
305  Bcomptype* ct = model->type;
306  Bcomponent* comp = model->comp;
307  Blink* link = model->link;
308 
309  if ( comp ) for ( ; comp->next; comp = comp->next ) ;
310  if ( link ) for ( ; link->next; link = link->next ) ;
311 
312  for ( mp = model->next; mp; mp = mp->next ) {
313  if ( ct ) ct->next = mp->type;
314  else model->type = ct = mp->type;
315  mp->type = NULL;
316  if ( ct ) for ( ; ct->next; ct = ct->next ) ;
317  if ( comp ) comp->next = mp->comp;
318  else model->comp = comp = mp->comp;
319  mp->comp = NULL;
320  if ( comp ) for ( ; comp->next; comp = comp->next ) ;
321  if ( link ) link->next = mp->link;
322  else model->link = link = mp->link;
323  mp->link = NULL;
324  if ( link ) for ( ; link->next; link = link->next ) ;
325  }
326 
328  model->next = NULL;
329 
330  for ( nct=0, ct = model->type; ct; ct = ct->next ) nct++;
331 
332  // Renumber all the components
333  for ( ncomp=0, comp = model->comp; comp; comp = comp->next )
334  comp->id = Bstring(++ncomp, "%d");
335 
336  for ( nlink=0, link = model->link; link; link = link->next ) nlink++;
337 
338  if ( verbose & VERB_PROCESS ) {
339  cout << "Merged component types: " << nct << endl;
340  cout << "Merged components: " << ncomp << endl;
341  cout << "Merged links: " << nlink << endl;
342  cout << endl;
343  }
344 
345  return ncomp;
346 }
347 
357 {
358  if ( !model ) return 0;
359 
360  long n(0);
361  Bmodel* mp;
362 
363  for ( mp = model; mp; mp = mp->next )
364  mp->id += Bstring(++n, "_%04d");
365 
366  return n;
367 }
368 
379 {
380  if ( !model ) return 0;
381  if ( !model->sel ) return 0;
382 
383  long i, n(0);
384  Bcomponent* comp;
385 
386  Bstring ctstr[10];
387  ctstr[0] = "NIL";
388  ctstr[1] = "MON";
389  ctstr[2] = "DI";
390  ctstr[3] = "TRI";
391  ctstr[4] = "TET";
392  ctstr[5] = "PEN";
393  ctstr[6] = "HEX";
394  ctstr[7] = "HEP";
395  ctstr[8] = "OCT";
396  ctstr[9] = "NON";
397 
398  for ( comp = model->comp; comp; comp = comp->next, n++ ) {
399  for ( i=0; comp->link[i]; i++ ) ;
400  if ( i > 9 ) i = 9;
401  comp->type = model_add_type_by_id(model, ctstr[i]);
402  }
403 
404  return n;
405 }
406 
417 {
418  double mass = 0;
419 
420  if ( !model ) return mass;
421  if ( !model->sel ) return mass;
422 
423  Bcomptype* ct = NULL;
424  Bcomponent* comp;
425 
426  for ( comp = model->comp; comp; comp = comp->next ) {
427  ct = comp->type;
428  if ( ct ) mass += ct->mass;
429  }
430 
431  if ( verbose & VERB_FULL )
432  cout << "Model: " << model->id << " Mass = " << mass << endl;
433 
434  return mass;
435 }
436 
446 {
447  long nmod(0);
448  Bmodel* mp;
449 
450  cout << "Model\tMass" << endl;
451  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
452  cout << mp->id << tab << model_mass(mp) << endl;
453  nmod++;
454  }
455  cout << endl;
456 
457  return nmod;
458 }
459 
460 
471  Vector3<double> center = {cen3[0], cen3[1], cen3[2]};
472  return center;
473 }
474 
476 {
477  Vector3<double> com;
478 
479  if ( !model ) return com;
480  if ( !model->sel ) return com;
481 
482  int n = 0;
483  Bcomponent* comp;
484 
485  for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
486  com += comp->loc;
487  n++;
488  }
489 
490  com /= n;
491 
492  return com;
493 }
494 
504 {
505  if ( !model ) return 0;
506  if ( !model->sel ) return 0;
507 
508  int n;
509  double d, R;
510  Bcomponent* comp;
511 
513 
514  for ( n = 0, R = 0, comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
515  d = (comp->loc - com).length();
516  R += d*d;
517  n++;
518  }
519 
520  if ( n ) R = sqrt(R/n);
521 
522  return R;
523 }
524 
535 {
536  Vector3<double> eigenval;
537 
538  if ( !model ) return eigenval;
539  if ( !model->sel ) return eigenval;
540 
541  double summass(0);
542  Vector3<double> loc, vec, vec2, vecx;
543  Bcomponent* comp;
544 
545 // Vector3<double> com = model_center_of_mass(model);
546 
547  for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
548  loc = comp->loc;
549  vec += loc; // Sums
550  vec2 += loc*loc; // Square sums
551  vecx[0] += loc[0]*loc[1]; // Cross-term sums
552  vecx[1] += loc[0]*loc[2];
553  vecx[2] += loc[1]*loc[2];
554  summass += 1;
555  }
556 
557  if ( verbose & VERB_PROCESS ) {
558  cout << "Model: " << model->id << endl;
559  cout << "Number of components: " << summass << endl;
560  }
561 
562  if ( summass < 1 ) {
563  cout << "Error: No components found!" << endl << endl;
564  return vec;
565  }
566 
567  vec /= summass;
568  vec2 /= summass;
569  vecx /= summass;
570 
571  return principal_axes(vec, vec2, vecx, eigenvec);
572 }
573 
575 {
576  if ( !model ) return -1;
577 
578  Vector3<double> pax;
579  Bmodel* mp;
580 
581  if ( verbose )
582  cout << "Principal axes:" << endl << "Model\tMajor\tMiddle\tMinor" << endl;
583  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
584  pax = model_principal_axes(mp, NULL);
585  if ( verbose )
586  cout << mp->id << tab << pax[0] << tab << pax[1] << tab << pax[2] << endl;
587  }
588 
589  if ( verbose )
590  cout << endl;
591 
592  return 0;
593 }
594 
595 
605 long model_radial_distribution(Bmodel* model, double interval)
606 {
607  if ( interval <= 0 ) interval = 1;
608  if ( !model ) return 0;
609  if ( !model->sel ) return 0;
610 
611  Vector3<double> min(1e10,1e10,1e10), max(-1e10,-1e10,-1e10);
612  Bcomponent* comp1, *comp2;
613 
614  for ( comp1 = model->comp; comp1; comp1 = comp1->next ) if ( comp1->sel ) {
615  min = min.min(comp1->loc);
616  max = max.max(comp1->loc);
617  }
618 
619  int r, rmax = (int) (max.distance(min)/interval + 1);
620  double d;
621  int* rdf = new int[rmax];
622  for ( r=0; r<rmax; r++ ) rdf[r] = 0;
623 
624  for ( comp1 = model->comp; comp1->next; comp1 = comp1->next ) if ( comp1->sel ) {
625  for ( comp2 = comp1->next; comp2; comp2 = comp2->next ) if ( comp2->sel ) {
626  d = comp1->loc.distance(comp2->loc);
627  r = (int) (d/interval + 0.5);
628  if ( r < rmax ) rdf[r]++;
629  }
630  }
631 
632 // if ( verbose ) {
633  cout << "Radius\tCount" << endl;
634  for ( r=0; r<rmax; r++ )
635  cout << r*interval << tab << rdf[r] << endl;
636  cout << endl;
637 // }
638 
639  delete[] rdf;
640 
641  return 0;
642 }
643 
644 long molgroup_write_into_grid(Bmolgroup* molgroup, Vector3<int> size, Vector3<double> min, double sampling, int* grid)
645 {
646  long i, x, y, z;
647  Bmolecule* mol;
648  Bresidue* res;
649  Batom* atom;
650 
651  long vol = (long) size.volume();
652  char* tgrid = new char[vol];
653  for ( i=0; i<vol; i++ ) tgrid[i] = 0;
654 
655  for ( mol=molgroup->mol; mol; mol=mol->next ) {
656  for ( res=mol->res; res; res=res->next ) {
657  for ( atom=res->atom; atom; atom=atom->next ) {
658  x = (int) ((atom->coord[0] - min[0])/sampling);
659  y = (int) ((atom->coord[1] - min[1])/sampling);
660  z = (int) ((atom->coord[2] - min[2])/sampling);
661  i = (z*size[1]+y)*size[0]+x;
662  if ( i < 0 || i > vol ) {
663  cerr << "Error in molgroup_write_into_grid: i=" << i << " (vol=" << vol << ")" << endl;
664  return -1;
665  }
666  tgrid[i] = 1;
667  }
668  }
669  }
670 
671  for ( i=0; i<vol; i++ ) grid[i] += tgrid[i];
672 
673  delete[] tgrid;
674 
675  return 0;
676 }
677 
688 Bmolgroup* model_assemble(Bmodel* model, Bstring& paramfile, int separate)
689 {
690  Bcomponent* comp = NULL;
691 // Bcomptype* comptype = NULL;
692 
693  Bmolgroup* mglist = NULL;
694  Bmolgroup* molgroup = NULL;
695  Bmolgroup* molgroup1 = NULL;
696  Bmolecule* mol = NULL;
697  Bstring atom_select("all");
698  Quaternion q;
699  Transform t;
700 
701  long i, nsel, nover;
702  double sampling = 5;
703  Vector3<double> min(model->comp->loc), max(model->comp->loc);
704  Vector3<int> size;
705 
706  if ( verbose )
707  cout << "Assembling components" << endl;
708 
709  for ( nsel=0, comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
710  min = min.min(comp->loc);
711  max = max.max(comp->loc);
712  nsel++;
713  }
714  molgroup1 = read_molecule(model->type->fmod, atom_select, paramfile);
715  min -= molgroup1->box;
716  max += molgroup1->box;
717  molgroup_kill(molgroup1);
718  for ( i=0; i<3; i++ ) size[i] = (int) ((max[i] - min[i])/sampling);
719 
720  if ( nsel < 1 ) {
721  cerr << "Error: No components are selected!" << endl;
722  return NULL;
723  }
724 
725  long vol = (long) size.volume();
726  int* grid = new int[vol];
727  for ( i=0; i<vol; i++ ) grid[i] = 0;
728 
729  for ( nsel=0, comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
730  nsel++;
731 // comptype = model_get_type(model, comp->type);
732  molgroup1 = read_molecule(comp->type->fmod, atom_select, paramfile);
733  molgroup1->id = comp->id;
734 // q = quaternion_from_view(comp->view);
735  q = comp->view.quaternion();
736 // t = transform_from_quaternion(q);
737  t = Transform(q);
738  t.origin = molgroup_center_of_mass(molgroup1);
739  t.trans = comp->loc - t.origin;
740  molgroup_coor_rotate(molgroup1, t);
741  molgroup_stats(molgroup1);
742  if ( molgroup_write_into_grid(molgroup1, size, min, sampling, grid) < 0 ) {
743  error_show("Error in model_assemble", __FILE__, __LINE__);
744  return NULL;
745  }
746  if ( separate ) {
747  if ( !mglist ) mglist = molgroup = molgroup1;
748  else {
749  molgroup->next = molgroup1;
750  molgroup = molgroup1;
751  }
752  } else {
753  if ( molgroup ) {
754  if ( mol ) {
755  for ( ; mol->next; mol = mol->next ) ;
756  mol->next = molgroup1->mol;
757  } else {
758  mol = molgroup->mol = molgroup1->mol;
759  }
760  molgroup1->mol = NULL;
761  molgroup_kill(molgroup1);
762  } else {
763  mglist = molgroup = molgroup1;
764  mol = molgroup->mol;
765  }
766  }
767  }
768 
769  for ( i=nover=0; i<vol; i++ ) if ( grid[i] > 1 ) nover++;
770 
771  delete[] grid;
772 
773  if ( verbose ) {
774  cout << "Components assembled: " << nsel << endl;
775  cout << "Molecule group overlap: " <<
776  sampling*sampling*sampling*nover << " A3 (" << nover*100.0/size.volume() << " %)" << endl << endl;
777  }
778 
779  return mglist;
780 }
781 
791 {
792  Bstring id, path;
793  Bstring comptype("VER");
794  Bmolgroup* mg;
795  Bmolecule* mol;
796 
797  int i, j, n=0;
798  Bmodel* model = NULL;
799  Bmodel* mp = NULL;
800  Bcomponent* comp = NULL;
801 
802  if ( verbose & VERB_PROCESS )
803  cout << "Generating a centers-of-mass model" << endl << endl;
804 
805  for ( i=1, mg = molgroup; mg; mg = mg->next, i++ ) {
806  mp = (Bmodel *) add_item((char **) &mp, sizeof(Bmodel));
807  if ( !model ) model = mp;
808  if ( mg->id.length() ) mp->id = mg->id;
809  else mp->id = Bstring(i, "%d");
810  comp = NULL;
811  for ( j=1, mol = molgroup->mol; mol; mol = mol->next, j++, n++ ) {
812  cout << "Adding molecule " << j << " as component" << endl;
813  comp = component_add(&comp, j);
814  if ( !mp->comp ) mp->comp = comp;
815  comp->loc = mol_center_of_mass(mol);
816  if ( mol->id.length() ) id = mol->id.no_space();
817  else id = comptype;
818  comp->type = model_add_type_by_id_and_filename(mp, id, molgroup->filename, 0);
819  }
820  }
821 
822  cout << "Models generated: " << --i << endl;
823  cout << "Components generated: " << n << endl << endl;
824 
825  model_check(model, path);
826 
827  return model;
828 }
829 
840 {
841  long nsel(0);
842  Bcomponent* comp = NULL;
843  Bmolgroup* mg = NULL;
844 
845  if ( verbose )
846  cout << "Updating component centers-of-mass" << endl << endl;
847 
848  for ( nsel=0, comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
849  nsel++;
850  for ( mg = molgroup; mg; mg = mg->next ) if ( comp->id == mg->id ) break;
851  if ( mg ) comp->loc = molgroup_center_of_mass(mg);
852  }
853 
854  return nsel;
855 }
856 
867 {
868  Bmodel* mp;
869  Bcomponent* comp;
870  Bcomponent* comp_avg;
871 
872  if ( verbose & VERB_PROCESS )
873  cout << "Averaging every " << number << " of selected components" << endl;
874 
875  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
876  comp_avg = NULL;
877  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel ) {
878  if ( !comp_avg ) {
879  comp_avg = comp;
880  comp_avg->sel = 1;
881  } else {
882  comp->sel = 0;
883  comp_avg->loc += comp->loc;
884  comp_avg->sel++;
885  if ( comp_avg->sel == number ) {
886  comp_avg->loc /= comp_avg->sel;
887  comp_avg = NULL;
888  }
889  }
890  } else comp->sel = 1;
891  if ( comp_avg ) comp_avg->loc /= comp_avg->sel;
892  }
893 
895 }
896 
904 {
905  Bmodel* mp;
906  Bcomponent* comp;
907 
908  for ( n=0, mp = model; mp; mp = mp->next ) if ( mp->sel )
909  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel ) n++;
910 
911  Bcomponent** comparray = new Bcomponent*[n];
912 
913  for ( n=0, mp = model; mp; mp = mp->next ) if ( mp->sel )
914  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel )
915  comparray[n++] = comp;
916 
917  return comparray;
918 }
919 
933 Vector3<double> component_plane(Bcomponent** comparray, double& offset)
934 {
935  long i, j, n;
936  vector<double> b(3);
937  Matrix a(3,3);
938  Vector3<double> loc, normal, center;
939 
940  for ( i=0; i<3; i++ ) b[i] = 0;
941 
942  center = 0;
943  for ( n=0; n<MAXLINK && comparray[n]; n++ ) {
944  loc = comparray[n]->loc;
945  center += loc;
946  for ( i=0; i<3; i++ ) {
947  for ( j=0; j<=i; j++ )
948  a[3][i] += loc[i]*loc[j];
949  b[i] += loc[i];
950  }
951  }
952  center /= n;
953 
954  for ( i=1; i<3; i++ )
955  for ( j=0; j<i; j++ )
956  a[3][j] = a[3][i];
957 
958  offset = 0;
959  if ( a[0][0] == 0 ) {
960  normal = Vector3<double>(1, 0, 0);
961  } else if ( a[1][1] == 0 ) {
962  normal = Vector3<double>(0, 1, 0);
963  } else if ( a[2][2] == 0 ) {
964  normal = Vector3<double>(0, 0, 1);
965  } else {
966  a.LU_decomposition(b);
967  normal = Vector3<double>(b[0], b[1], b[2]);
968  normal.normalize();
969  }
970 
971  offset = center.scalar(normal);
972 
973  return normal;
974 }
975 
976 
model_list
long model_list(Bmodel *model)
Lists models in table form.
Definition: model_util.cpp:127
molgroup_write_into_grid
long molgroup_write_into_grid(Bmolgroup *molgroup, Vector3< int > size, Vector3< double > min, double sampling, int *grid)
Definition: model_util.cpp:644
Bmodel::fom
float fom
Definition: rwmodel.h:128
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
molgroup_stats
long molgroup_stats(Bmolgroup *molgroup, int show)
Calculates the statistics of a molecule group.
Definition: rwmolecule.cpp:1296
model_check
int model_check(Bmodel *model, Bstring path)
Checks model properties.
Definition: rwmodel.cpp:595
matrix_linear.h
Header file for matrix functions.
Bcomponent
Definition: rwmodel.h:51
matrix_util.h
Utility functions for matrices.
Bpolygon::next
Bpolygon * next
Definition: rwmodel.h:103
model_radial_distribution
long model_radial_distribution(Bmodel *model, double interval)
Calculates the radial distribution function of a model.
Definition: model_util.cpp:605
mol_center_of_mass
Vector3< double > mol_center_of_mass(Bmolecule *mol)
Calculates the center of mass of a molecule.
Definition: mol_util.cpp:401
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bmodel::hand
int hand
Definition: rwmodel.h:123
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
model_replace_components
long model_replace_components(Bmodel *model, Bmodel *modref)
Replaces all components in a model with reference components.
Definition: model_util.cpp:227
model_center_of_mass
Vector3< double > model_center_of_mass(Bmodel *model)
Definition: model_util.cpp:475
Bcomptype::fmod
Bstring fmod
Definition: rwmodel.h:29
Quaternion
Definition: Quaternion.h:25
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bstring
Definition: Bstring.h:29
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
component_plane
Vector3< double > component_plane(Bcomponent **comparray, double &offset)
Calculates a plane through an array of components.
Definition: model_util.cpp:933
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:270
symmetry.h
Header file for general symmetry functions.
Bcomptype
Definition: rwmodel.h:25
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Vector3< double >
random_numbers.h
Header file for functions for creating random images.
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
Matrix3.h
3x3 Matrix manipulation functions
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
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
component_get_array
Bcomponent ** component_get_array(Bmodel *model, long &n)
Generates an array of pointers to component structures.
Definition: model_util.cpp:903
Bpolygon::normal
Vector3< float > normal
Definition: rwmodel.h:106
principal_axes
Vector3< double > principal_axes(Vector3< double > avg, Vector3< double > avg2, Vector3< double > avgx, Vector3< double > *eigenvec)
Calculates the principal axes of 3D coordinates.
Definition: matrix.cpp:706
comp_type_list_kill
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
Definition: rwmodel.cpp:929
Bcomptype::mass
float mass
Definition: rwmodel.h:32
Bmodel::link
Blink * link
Definition: rwmodel.h:133
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:249
length
double length(vector< T > v)
Definition: Vector3.h:530
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
mol_transform.h
Library routines used for atomic coordinate transformations.
Transform::origin
Vector3< double > origin
Definition: Transform.h:27
Batom::next
Batom * next
Definition: rwmolecule.h:25
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
molgroup_coor_rotate
int molgroup_coor_rotate(Bmolgroup *molgroup, Transform t)
Rotates and translates a molecule group.
Definition: mol_transform.cpp:87
component_list_kill
int component_list_kill(Bcomponent *comp)
Deallocates memory for a list of components.
Definition: rwmodel.cpp:894
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
model_generate_com
Bmodel * model_generate_com(Bmolgroup *molgroup)
Calculates the centers-of-mass of molecule group components and generates a new model.
Definition: model_util.cpp:790
Bpolygon::closed
int closed
Definition: rwmodel.h:107
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
verbose
int verbose
model_principal_axes
Vector3< double > model_principal_axes(Bmodel *model, Vector3< double > *eigenvec)
Calculates the principal axes of a model.
Definition: model_util.cpp:534
Vector3::normalize
double normalize()
Definition: Vector3.h:238
model_add_type_by_id_and_filename
Bcomptype * model_add_type_by_id_and_filename(Bmodel *model, Bstring &id, Bstring &filename, int num)
Add a type to a model if the type with the given id and file name does not exist already.
Definition: rwmodel.cpp:468
Bmodel::id
Bstring id
Definition: rwmodel.h:121
model_delete_non_selected
long model_delete_non_selected(Bmodel **model)
Deletes selected components and associated links from the model.
Definition: model_select.cpp:781
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1127
Bmolecule
Definition: rwmolecule.h:107
model_select.h
Header file for reading and writing atomic model files.
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
Bmolgroup::filename
Bstring filename
Definition: rwmolecule.h:172
Bmodel::sel
int sel
Definition: rwmodel.h:129
Matrix::LU_decomposition
double LU_decomposition()
Matrix inversion by LU decomposition.
Definition: matrix.cpp:78
model_mass
double model_mass(Bmodel *model)
Calculates the mass of a model from component masses.
Definition: model_util.cpp:416
Bmolgroup::next
Bmolgroup * next
Definition: rwmolecule.h:171
model_average_components
long model_average_components(Bmodel *model, int number)
Averages sequential components.
Definition: model_util.cpp:866
mol_compare.h
Library routines used to compare sets of atomic coordinates.
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
Bmodel
Definition: rwmodel.h:119
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
model_list_comp
long model_list_comp(Bmodel *model)
Lists models with component counts in table form.
Definition: model_util.cpp:158
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
model_update_centers_of_mass
long model_update_centers_of_mass(Bmodel *model, Bmolgroup *molgroup)
Updates the centers-of-mass of molecule group components.
Definition: model_util.cpp:839
Bmodel::img_num
int img_num
Definition: rwmodel.h:127
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bpolygon::comp
Bcomponent * comp[MAXLINK]
Definition: rwmodel.h:105
Bcomponent::view
View view
Definition: rwmodel.h:59
Bpolygon
Definition: rwmodel.h:102
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
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
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
model
Bmodel * model
Definition: bshow.cpp:34
Vector3::volume
double volume()
Definition: Vector3.h:237
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Bstring::next
Bstring * next
Definition: Bstring.h:31
model_center_of_mass_nu
Vector3< double > model_center_of_mass_nu(Bmodel *model)
Calculates the center-of-mass of a model.
Definition: model_util.cpp:469
model_rename_components
long model_rename_components(Bmodel *model)
Rename components.
Definition: model_util.cpp:378
model_assemble
Bmolgroup * model_assemble(Bmodel *model, Bstring &paramfile, int separate)
Concatenates selected molecules into one group.
Definition: model_util.cpp:688
View::quaternion
Quaternion quaternion()
Definition: View.h:130
Bresidue
Definition: rwmolecule.h:49
linked_list.h
Header file for generalized linked list functions.
poly_list_kill
int poly_list_kill(Bpolygon *poly)
Deallocates memory for a list of polygons.
Definition: rwmodel.cpp:1073
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
model_transform.h
Library routines used for model transformation.
model_util.h
Library routines used for model processing.
model_add_type_by_id
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Definition: rwmodel.cpp:414
Vector3::min
Type min()
Definition: Vector3.h:169
Bmolgroup
Definition: rwmolecule.h:170
model_merge
long model_merge(Bmodel *model)
Merges components from all models into one.
Definition: model_util.cpp:299
Bpolygon::number
int number
Definition: rwmodel.h:104
Bmodel::type
Bcomptype * type
Definition: rwmodel.h:131
Bcomptype::next
Bcomptype * next
Definition: rwmodel.h:26
model_gyration_radius
double model_gyration_radius(Bmodel *model)
Calculates the radius of gyration for a model.
Definition: model_util.cpp:503
Transform
Definition: Transform.h:24
component_type_copy
int component_type_copy(Bcomptype *fromct, Bcomptype *toct)
Copies all elements from one component to another.
Definition: rwmodel.cpp:766
component_copy
int component_copy(Bcomponent *fromcomp, Bcomponent *tocomp)
Copies all elements from one component to another.
Definition: rwmodel.cpp:786
model_link_list_kill
int model_link_list_kill(Bmodel *model)
Deallocates memory for a list of component links.
Definition: rwmodel.cpp:953
Bmolgroup::id
Bstring id
Definition: rwmolecule.h:174
Matrix
Definition: Matrix.h:22
MAXLINK
#define MAXLINK
Definition: rwmodel.h:14
model_number_ids
long model_number_ids(Bmodel *model)
Add a number to each model id.
Definition: model_util.cpp:356
Bcomponent::link
Bcomponent * link[MAXLINK]
Definition: rwmodel.h:55
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
model_mass_all
long model_mass_all(Bmodel *model)
Calculates the masses of all the models in the list.
Definition: model_util.cpp:445
Bstring::no_space
Bstring no_space()
Definition: Bstring.cpp:340
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
Batom
Definition: rwmolecule.h:24
Bmodel::type_id
Bstring type_id
Definition: rwmodel.h:122
Bmolecule::id
Bstring id
Definition: rwmolecule.h:110
Bcomponent::sel
int sel
Definition: rwmodel.h:66
mol_util.h
Library routines used for atomic coordinates.
Vector3::max
Type max()
Definition: Vector3.h:175