Bsoft  2.1.0
Bernard's software package
rwmodel.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "rwmodel_star.h"
11 #include "rwmodel_xml.h"
12 #include "rwmodel_cmm.h"
13 #include "rwmodel_bild.h"
14 #include "rwmodel_mol.h"
15 #include "rwmodel_vega.h"
16 #include "model_links.h"
17 #include "file_util.h"
18 #include "linked_list.h"
19 #include "Color.h"
20 #include "utilities.h"
21 
22 // Declaration of global variables
23 extern int verbose; // Level of output to the screen
24 extern string command; // Command line
25 
26 // Internal function prototypes
27 
28 
30 {
31  return read_model(&filename);
32 }
33 
34 Bmodel* read_model(Bstring* file_list)
35 {
36  Bstring paramfile;
37  return read_model(file_list, paramfile);
38 }
39 
40 Bmodel* read_model(Bstring& filename, Bstring& paramfile)
41 {
42  return read_model(&filename, paramfile);
43 }
44 
51 Bmodel* read_model(Bstring* file_list, Bstring& paramfile)
52 {
53  Bstring ext = file_list->extension();
54 
55  if ( verbose & VERB_DEBUG )
56  cout << "DEBUG read_model: extension=" << ext << endl;
57 
58  Bmodel* model = NULL;
59  Bstring path;
60 
61  if ( ext.contains("star") || ext.contains("cif") )
62  model = read_model_star(file_list);
63  else if ( ext.contains("xml") )
64  model = read_model_xml(file_list);
65  else if ( ext.contains("cmm") )
66  model = read_model_chimera(file_list);
67  else if ( ext.contains("bld") || ext.contains("bild") )
68  model = read_model_bild(file_list);
69  else if ( ext.contains("v3d") )
70  model = read_model_vega(file_list);
71  else
72  model = read_model_molecule(file_list, paramfile);
73 
74  if ( !model ) {
75  cerr << "Error: File with extension " << ext << " not read!" << endl;
76  error_show(file_list->c_str(), __FILE__, __LINE__);
77  } else {
78 // if ( !model->link ) model_list_setup_links(model);
79  path = file_list->pre_rev('/');
80  model_check(model, path);
81  }
82 
83  return model;
84 }
85 
92 int write_model(Bstring& filename, Bmodel* model)
93 {
94  if ( !model ) return 0;
95 
96  int n(0);
97 
99 
100  if ( model->split == 9 ) {
101  n = write_model_star(filename, model);
102  return n;
103  }
104 
105  if ( filename.empty() ) {
106  cerr << "Error: No model filename!" << endl;
107  return -1;
108  }
109 
110  Bstring ext = filename.extension();
111 
112  if ( verbose & VERB_DEBUG )
113  cout << "DEBUG write_model: extension=" << ext << endl;
114 
115  if ( verbose & VERB_LABEL )
116  cout << "Writing file: " << filename << endl;
117 
118 // Bstring path = filename.pre_rev('/');
119 // model_check(model, path);
120 
121  if ( ext.contains("star") || ext.contains("cif") )
122  n = write_model_star(filename, model);
123  else if ( ext.contains("xml") )
124  n = write_model_xml(filename, model);
125  else if ( ext.contains("cmm") )
126  n = write_model_chimera(filename, model);
127  else if ( ext.contains("bld") || ext.contains("bild") )
128  n = write_model_bild(filename, model);
129  else if ( ext.contains("v3d") )
130  n = write_model_vega(filename, model);
131  else
132  n = write_model_molecule(filename, model);
133 
134  if ( n < 0 ) {
135  cerr << "Error: File with extension " << ext << " not written!" << endl;
136  error_show(filename.c_str(), __FILE__, __LINE__);
137  }
138 
139  return n;
140 }
141 
148 {
149  Bmodel* model = new Bmodel;
150  memset(model, 0, sizeof(Bmodel));
151 
152  model->id = id;
153  model->type_id = "?";
154  model->symmetry = "C1";
155  model->sel = 1;
156 
157  return model;
158 }
159 
160 Bmodel* model_init(const char* cid)
161 {
162  Bstring id(cid);
163  Bmodel* model = model_init(id);
164  id = 0;
165 
166  return model;
167 }
168 
182 {
183  Bmodel* this_model = *model;
184  Bmodel* new_model = model_init(id);
185 
186  if ( verbose & VERB_DEBUG )
187  cout << "DEBUG model_add: type=" << new_model->id << endl;
188 
189  if ( !this_model )
190  *model = new_model;
191  else {
192  while ( this_model->next ) this_model = this_model->next;
193  this_model->next = new_model;
194  }
195 
196  return new_model;
197 }
198 
199 Bmodel* model_add(Bmodel** model, const char* cid)
200 {
201  Bstring id(cid);
202  Bmodel* new_model = model_add(model, id);
203  id = 0;
204 
205  return new_model;
206 }
207 
209 {
210  Bmodel* mp = NULL;
211 
212  if ( *model )
213  for ( mp = *model; mp->next; mp = mp->next ) ; // Pointer to last model
214 
215  if ( mp ) mp->next = model_nu;
216  else *model = model_nu;
217 
218  return model_nu;
219 }
220 
234 {
235  Bcomptype* this_type = *type;
236  Bcomptype* new_type = new Bcomptype;
237  memset(new_type, 0, sizeof(Bcomptype));
238 
239  new_type->id = id;
240  new_type->fmod = "?";
241  new_type->mass = 1;
242  new_type->fom = 1;
243  new_type->sel = 1;
244 
245  if ( verbose & VERB_DEBUG )
246  cout << "DEBUG component_type_add: type=" << new_type->id << endl;
247 
248  if ( !this_type )
249  *type = new_type;
250  else {
251  while ( this_type->next ) this_type = this_type->next;
252  this_type->next = new_type;
253  }
254 
255  return new_type;
256 }
257 
271 {
272  Bcomponent* this_comp = *comp;
273  Bcomponent* new_comp = new Bcomponent;
274  memset(new_comp, 0, sizeof(Bcomponent));
275 
276  new_comp->id = id;
277  new_comp->view[2] = 1;
278  new_comp->radius = 1;
279  new_comp->color = RGBA<float>(1,1,1,1);
280  new_comp->density = 1;
281  new_comp->fom = 1;
282  new_comp->sel = 1;
283 
284  if ( verbose & VERB_DEBUG )
285  cout << "DEBUG component_add: id=" << new_comp->id << endl;
286 
287  if ( !this_comp )
288  *comp = new_comp;
289  else {
290  while ( this_comp->next ) this_comp = this_comp->next;
291  this_comp->next = new_comp;
292  }
293 
294  return new_comp;
295 }
296 
297 Bcomponent* component_add(Bcomponent** comp, unsigned long number)
298 {
299  Bstring id(number, "%ld");
300  return component_add(comp, id);
301 }
302 
318 Blink* link_add(Blink** link, Bcomponent* comp1, Bcomponent* comp2, double length, double radius)
319 {
320  int i, j;
321  Blink* this_link = *link;
322 
323  for ( i=0; i<MAXLINK && comp1->link[i] && comp1->link[i] != comp2; i++ ) ;
324  for ( j=0; j<MAXLINK && comp2->link[j] && comp2->link[j] != comp1; j++ ) ;
325 
326  if ( comp1->link[i] == comp2 && comp2->link[j] == comp1 ) {
327  if ( verbose & VERB_FULL )
328  cerr << "Error: " << comp1->id << " already linked to " << comp2->id <<
329  "! (" << i << " -" << j << ")" << endl;
330  return this_link;
331  }
332 
333  if ( i<MAXLINK && j<MAXLINK ) {
334  comp1->link[i] = comp2;
335  comp2->link[j] = comp1;
336  comp1->flag[i] = comp2->flag[j] = 1;
337  }
338 
339  Blink* new_link = new Blink;
340  memset(new_link, 0, sizeof(Blink));
341 
342  if ( length < 1e-6 ) length = comp1->loc.distance(comp2->loc);
343 
344  if ( radius < 1e-6 ) radius = (comp1->radius + comp2->radius)/4;
345 
346  new_link->comp[0] = comp1;
347  new_link->comp[1] = comp2;
348  new_link->length = length;
349  new_link->radius = radius;
350  new_link->color = (comp1->color + comp2->color)/2;
351  new_link->sel = 1;
352 
353  if ( verbose & VERB_DEBUG )
354  cout << "DEBUG link_add: " << comp1->id << " - " << comp2->id << endl;
355 
356  if ( !this_link )
357  *link = new_link;
358  else {
359  while ( this_link->next ) this_link = this_link->next;
360  this_link->next = new_link;
361  }
362 
363  return new_link;
364 }
365 
366 Blink* link_add(Blink** link, Bcomponent* comp1, Bcomponent* comp2)
367 {
368  return link_add(link, comp1, comp2, 0, 0);
369 }
370 
381 int link_index(Bcomponent* comp, Bcomponent* comp2)
382 {
383  int i;
384 
385  for ( i=0; i<MAXLINK && comp->link[i] && comp->link[i] != comp2; i++ ) ;
386 
387  if ( !comp->link[i] || i >= MAXLINK ) i = -1;
388 
389  return i;
390 }
391 
399 {
400  Bmodel* mp;
401 
402  for ( mp = model; mp; mp = mp->next )
403  if ( mp->sel ) mp->fmap = mapfile;
404 
405  return 0;
406 }
407 
415 {
416  Bcomptype* ct = NULL;
417 
418  if ( verbose & VERB_DEBUG )
419  cout << "DEBUG model_add_type_by_id: id=" << id << endl;
420 
421  if ( model->type )
422  for ( ct = model->type; ct && id != ct->id; ct = ct->next ) ;
423 
424  if ( !ct )
425  ct = component_type_add(&model->type, id);
426 
427  return ct;
428 }
429 
438 {
439  int i(0);
440  Bstring id("1");
441  Bcomptype* ct = NULL;
442 
443  if ( verbose & VERB_DEBUG )
444  cout << "DEBUG model_add_type_by_filename: filename=" << filename << endl;
445 
446  if ( model->type )
447  for ( i=1, ct = model->type; ct; ct = ct->next, i++ )
448  if ( filename == ct->fmod ) break;
449 
450  if ( !ct ) {
451  ct = component_type_add(&model->type, id);
452  ct->id = Bstring(i, "%d");
453  ct->fmod = filename;
454  ct->num = num;
455  }
456 
457  return ct;
458 }
459 
469 {
470  Bcomptype* ct = NULL;
471 
472  if ( verbose & VERB_DEBUG )
473  cout << "DEBUG model_add_type_by_id_and_filename: id" << id << " filename=" << filename << endl;
474 
475  if ( model->type )
476  for ( ct = model->type; ct; ct = ct->next )
477  if ( id == ct->id && filename == ct->fmod ) break;
478 
479  if ( !ct ) {
480  ct = component_type_add(&model->type, id);
481  ct->fmod = filename;
482  ct->num = num;
483  }
484 
485  return ct;
486 }
487 
495 {
496  if ( !model ) return NULL;
497 
498  Bcomptype* ct = NULL;
499 
500  if ( verbose & VERB_DEBUG )
501  cout << "DEBUG model_get_type: id=" << id << endl;
502 
503  if ( model->type )
504  for ( ct = model->type; ct; ct = ct->next )
505  if ( id == ct->id ) break;
506 
507  return ct;
508 }
509 
520 {
521  if ( !model ) return 0;
522 
523  int n;
524  Bmodel* mp;
525  Bcomponent* comp;
526  Bcomptype* ct;
527 
528  for ( n=0, mp = model; mp; mp = mp->next, n++ ) {
530  mp->type = NULL;
531  ct = model_add_type_by_id(mp, set_type);
532  for ( comp = mp->comp; comp; comp = comp->next )
533  comp->type = ct;
534  }
535 
536  return n;
537 }
538 
549 {
550  if ( !model ) return 0;
551 
552  int n;
553  Bmodel* mp;
554  Bcomptype* ct;
555 
556  Bstring ot(change_type.pre(',')), nt(change_type.post(','));
557 
558  for ( n=0, mp = model; mp; mp = mp->next, n++ ) {
559  for ( ct = mp->type; ct; ct = ct->next )
560  if ( ct->id == ot ) ct->id = nt;
561  }
562 
563  return n;
564 }
565 
572 {
573  Bmodel* mp = NULL;
574  Bcomptype* ct = NULL;
575  Bcomponent* comp = NULL;
576 
577  if ( verbose & VERB_DEBUG )
578  cout << "DEBUG model_count_component_types: " << model->id << endl;
579 
580  for ( mp = model; mp; mp = mp->next ) {
581  for ( ct = mp->type; ct; ct = ct->next ) ct->count = 0;
582  for ( comp = mp->comp; comp; comp = comp->next )
583  comp->type->count++;
584  }
585 
586  return 0;
587 }
588 
596 {
597  if ( !model ) return 0;
598 
599  long nmod(0), ncomp(0), nlink(0);
600  Bmodel* mp = NULL;
601  Bcomptype* ct = NULL;
602  Bcomponent* comp = NULL;
603  Blink* link = NULL;
604  Bstring nutype("UNK");
605 
606 
607  for ( mp = model; mp; mp = mp->next, nmod++ ) {
608  if ( mp->fmap.empty() ) mp->fmap = "?";
609  else mp->fmap = find_file(mp->fmap, path);
610  for ( comp = mp->comp; comp; comp = comp->next, ncomp++ ) {
611  comp->view.normalize();
612  if ( comp->radius < 1e-6 ) comp->radius = 1;
613  if ( !comp->type ) {
614  cerr << "Component " << comp->id << " has no type assigned" << endl;
615  comp->type = model_add_type_by_id(mp, nutype);
616  }
617  }
618  for ( ct = mp->type; ct; ct = ct->next ) {
619  if ( ct->fmod.empty() ) ct->fmod = "?";
620  if ( ct->mass < 1 ) ct->mass = 1;
621  }
622  for ( link = mp->link; link; link = link->next, nlink++ ) {
623  if ( link->length < 1e-6 ) link->length = link->comp[0]->loc.distance(link->comp[1]->loc);
624  if ( link->radius < 1e-6 ) link->radius = 0.1*link->length;
625  }
626  }
627 
629 
630  return 0;
631 }
632 
639 {
640  if ( !model ) return 0;
641 
642  int ncomp;
643  Bmodel* mp;
644  Bcomponent* comp;
645 
646  for ( ncomp=0, mp = model; mp; mp = mp->next )
647  for ( comp = mp->comp; comp; comp = comp->next, ncomp++ ) ;
648 
649  return ncomp;
650 }
651 
661 {
662  if ( !model ) return NULL;
663 
664  Bmodel* model_new = NULL;
665  Bmodel* mp;
666  Bmodel* mp_new;
667 
668  for ( mp = model; mp; mp = mp->next ) {
669  if ( model_new ) {
670  mp_new->next = model_copy(mp);
671  mp_new = mp_new->next;
672  } else {
673  model_new = mp_new = model_copy(mp);
674  }
675  }
676 
677  return model_new;
678 }
679 
689 {
690  if ( !model ) return NULL;
691 
692  int i;
693 
694  Bcomptype* type;
695  Bcomponent* comp;
696  Blink* link;
697  Bpolygon* poly;
698 
699  Bcomptype* type_new = NULL;
700  Bcomponent* comp_new = NULL;
701  Blink* link_new = NULL;
702  Bpolygon* poly_new = NULL;
703 
704  Bmodel* model_new = model_init(model->id);
705 
706  model_new->type_id = model->type_id;
707  model_new->comment = model->comment;
708  model_new->symmetry = model->symmetry;
709  model_new->fmap = model->fmap;
710  model_new->img_num = model->img_num;
711  model_new->sel = model->sel;
712  model_new->fom = model->fom;
713  model_new->split = model->split;
714  model_new->hand = model->hand;
715 
716  for ( type = model->type; type; type = type->next ) {
717  type_new = model_add_type_by_id_and_filename(model_new, type->id, type->fmod, type->num);
718  type_new->count = type->count;
719  type_new->mass = type->mass;
720  type_new->fom = type->fom;
721  type_new->sel = type->sel;
722  }
723 
724  for ( comp = model->comp; comp; comp = comp->next ) {
725  comp_new = component_add(&comp_new, comp->id);
726  if ( !model_new->comp ) model_new->comp = comp_new;
727  component_copy(comp, comp_new);
728  comp_new->type = model_add_type_by_id(model_new, comp->type->id);
729  }
730 
731  for ( link = model->link; link; link = link->next ) {
732  link_new = (Blink *) add_item((char **) &link_new, sizeof(Blink));
733  if ( !model_new->link ) model_new->link = link_new;
734  for ( comp = model->comp, comp_new = model_new->comp; comp; comp = comp->next, comp_new = comp_new->next ) {
735  if ( link->comp[0] == comp ) link_new->comp[0] = comp_new;
736  if ( link->comp[1] == comp ) link_new->comp[1] = comp_new;
737  }
738  link_new->length = link->length;
739  link_new->radius = link->radius;
740  link_new->color = link->color;
741  }
742 
743  for ( poly = model->poly; poly; poly = poly->next ) {
744  poly_new = (Bpolygon *) add_item((char **) &poly_new, sizeof(Bpolygon));
745  if ( !model_new->poly ) model_new->poly = poly_new;
746  poly_new->number = poly->number;
747  poly_new->normal = poly->normal;
748  poly_new->closed = poly->closed;
749  for ( comp = model->comp, comp_new = model_new->comp; comp; comp = comp->next, comp_new = comp_new->next ) {
750  for ( i=0; poly->comp[i]; i++ )
751  if ( poly->comp[i] == comp ) poly_new->comp[i] = comp_new;
752  }
753  }
754 
755  model_setup_links(model_new);
756 
757  return model_new;
758 }
759 
767 {
768  toct->id = fromct->id;
769  toct->index = fromct->index;
770  toct->fmod = fromct->fmod;
771  toct->num = fromct->num;
772  toct->count = fromct->count;
773  toct->mass = fromct->mass;
774  toct->fom = fromct->fom;
775  toct->sel = fromct->sel;
776 
777  return 0;
778 }
779 
786 int component_copy(Bcomponent* fromcomp, Bcomponent* tocomp)
787 {
788  tocomp->type = fromcomp->type;
789  tocomp->id = fromcomp->id;
790  tocomp->loc = fromcomp->loc;
791  tocomp->view = fromcomp->view;
792  tocomp->vec = fromcomp->vec;
793  tocomp->vel = fromcomp->vel;
794  tocomp->radius = fromcomp->radius;
795  tocomp->color = fromcomp->color;
796  tocomp->density = fromcomp->density;
797  tocomp->fom = fromcomp->fom;
798  tocomp->sel = fromcomp->sel;
799 
800  return 0;
801 }
802 
809 {
810  if ( !comp ) return 0;
811 
812  long ncomp(0);
813 
814  for ( ; comp; comp = comp->next, ncomp++ ) ;
815 
816  return ncomp;
817 }
818 
826 {
827  for ( ; comp; comp = comp->next )
828  if ( comp->id == id ) return comp;
829 
830  return NULL;
831 }
832 
839 int link_copy(Blink* fromlink, Blink* tolink)
840 {
841  tolink->comp[0] = fromlink->comp[0];
842  tolink->comp[1] = fromlink->comp[1];
843  tolink->angle = fromlink->angle;
844  tolink->length = fromlink->length;
845  tolink->radius = fromlink->radius;
846  tolink->color = fromlink->color;
847  tolink->fom = fromlink->fom;
848  tolink->sel = fromlink->sel;
849 
850  return 0;
851 }
852 
860 Blink* link_find(Blink* link, Bcomponent* comp1, Bcomponent* comp2)
861 {
862  for ( ; link; link = link->next ) {
863  if ( link->comp[0] == comp1 )
864  if ( link->comp[1] == comp2 ) return link;
865  if ( link->comp[1] == comp1 )
866  if ( link->comp[0] == comp2 ) return link;
867  }
868 
869  cerr << "Error: Link not found!" << endl;
870 
871  return link;
872 }
873 
874 
881 {
882  comp->id = 0;
883  comp->type = NULL;
884  delete comp;
885 
886  return 0;
887 }
888 
895 {
896  int n(0);
897  Bcomponent* c = NULL;
898  Bcomponent* c2 = NULL;
899 
900  for ( c = comp; c; ) {
901  c2 = c->next;
902  component_kill(c);
903  c = c2;
904  n++;
905  }
906 
907  return n;
908 }
909 
916 {
917  type->id = 0;
918  type->fmod = 0;
919  delete type;
920 
921  return 0;
922 }
923 
930 {
931  int n(0);
932  Bcomptype* ct = NULL;
933  Bcomptype* ct2 = NULL;
934 
935  for ( ct = type; ct; ) {
936  ct2 = ct->next;
937  comp_type_kill(ct);
938  ct = ct2;
939  n++;
940  }
941 
942  return n;
943 }
944 
954 {
955  if ( !model ) return 0;
956 
957  int i, n(0);
958  Bcomponent* comp;
959  Blink* link = NULL;
960  Blink* link2 = NULL;
961 
962  for ( comp = model->comp; comp; comp = comp->next ) {
963  for ( i=0; i<MAXLINK; i++ ) {
964  comp->link[i] = NULL;
965  comp->flag[i] = 0;
966  }
967  }
968 
969  for ( link = model->link; link; ) {
970  link2 = link->next;
971  delete link;
972  link = link2;
973  n++;
974  }
975 
976  return n;
977 }
978 
991 int link_kill(Blink** link_list, Bcomponent* comp, int i)
992 {
993  int j, k;
994  Blink* link, *plink;
995  Bcomponent* comp2 = comp->link[i];
996 
997  j = link_index(comp2, comp);
998 
999  if ( j < 0 ) {
1000  cerr << "Error: Component " << comp->id << " is not linked to component " << comp2->id << endl << endl;
1001  return -1;
1002  }
1003 
1004  if ( verbose & VERB_FULL )
1005  cout << "Deleting: " << comp->id << " (" << comp->sel << ") " << comp2->id << " (" << comp2->sel << ")" << endl;
1006 
1007  for ( k=i; k+1<MAXLINK && comp->link[k+1]; k++ ) {
1008  comp->link[k] = comp->link[k+1];
1009  comp->flag[k] = comp->flag[k+1];
1010  }
1011  comp->link[k] = NULL;
1012  comp->flag[k] = 0;
1013 
1014  for ( k=j; k+1<MAXLINK && comp2->link[k+1]; k++ ) {
1015  comp2->link[k] = comp2->link[k+1];
1016  comp2->flag[k] = comp2->flag[k+1];
1017  }
1018  comp2->link[k] = NULL;
1019  comp2->flag[k] = 0;
1020 
1021  for ( link = plink = *link_list; link; ) {
1022  if ( ( link->comp[0] == comp && link->comp[1] == comp2 ) ||
1023  ( link->comp[1] == comp && link->comp[0] == comp2 ) ) {
1024  if ( link == plink ) {
1025  *link_list = plink = link->next;
1026  delete link;
1027  link = plink;
1028  } else {
1029  plink->next = link->next;
1030  delete link;
1031  link = plink->next;
1032  }
1033  } else {
1034  plink = link;
1035  link = link->next;
1036  }
1037  }
1038 
1039  return 0;
1040 }
1041 
1054 int link_kill(Blink** link_list, Bcomponent* comp, Bcomponent* comp2)
1055 {
1056  int i = link_index(comp, comp2);
1057 
1058  if ( !comp->link[i] ) {
1059  cerr << "Error: Component " << comp->id << " is not linked to component " << comp2->id << endl << endl;
1060  return -1;
1061  }
1062 
1063  link_kill(link_list, comp, i);
1064 
1065  return 0;
1066 }
1067 
1074 {
1075  int n(0);
1076  Bpolygon* p = NULL;
1077  Bpolygon* p2 = NULL;
1078 
1079  for ( p = poly; p; ) {
1080  p2 = p->next;
1081  delete p;
1082  p = p2;
1083  n++;
1084  }
1085 
1086  return n;
1087 }
1088 
1096 {
1097  int n(0);
1098  Blink* l = *link;
1099  Blink* lp = NULL;
1100 
1101  while ( l ) {
1102  if ( l->comp[0] == comp || l->comp[1] == comp ) {
1103  if ( lp ) {
1104  lp->next = l->next;
1105  delete l;
1106  l = lp->next;
1107  } else {
1108  *link = l->next;
1109  delete l;
1110  l = *link;
1111  }
1112  n++;
1113  } else {
1114  lp = l;
1115  l = l->next;
1116  }
1117  }
1118 
1119  return n;
1120 }
1121 
1128 {
1129  Bmodel* mp = NULL;
1130  Bmodel* mp2 = NULL;
1131 
1132  for ( mp = model; mp; ) {
1133  mp2 = mp->next;
1137  poly_list_kill(mp->poly);
1138  mp->id = 0;
1139  mp->comment = 0;
1140  mp->type_id = 0;
1141  mp->symmetry = 0;
1142  mp->fmap = 0;
1143  delete mp;
1144  mp = mp2;
1145  }
1146 
1147  return 0;
1148 }
1149 
1160 int model_associate(Bmodel* model, Bstring& associate_type, Bstring& associate_file)
1161 {
1162  if ( !model ) return 0;
1163 
1164  int n(0);
1165  Bmodel* mp = NULL;
1166  Bcomptype* ct = NULL;
1167 
1168  if ( verbose & VERB_PROCESS )
1169  cout << "Associating component " << associate_type << " with file " << associate_file << endl << endl;
1170 
1171  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
1172  for ( ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1173  if ( ct->id == associate_type ) {
1174  ct->fmod = associate_file;
1175  n++;
1176  }
1177  }
1178  }
1179 
1180  return n;
1181 }
1182 
1190 int model_associate_mass(Bmodel* model, Bstring& associate_type, double mass)
1191 {
1192  if ( !model ) return 0;
1193 
1194  int n(0);
1195  Bmodel* mp = NULL;
1196  Bcomptype* ct = NULL;
1197 
1198  if ( verbose & VERB_PROCESS )
1199  cout << "Associating component " << associate_type << " with mass = " << mass << endl << endl;
1200 
1201  for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
1202  for ( ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1203  if ( ct->id == associate_type ) {
1204  ct->mass = mass;
1205  n++;
1206  }
1207  }
1208  }
1209 
1210  return n;
1211 }
1212 
1223 {
1224  if ( !model ) return 0;
1225 
1226  int n(0);
1227  Bmodel* mp;
1228  Bcomptype* ct;
1229 
1230  for ( mp = model; mp; mp = mp->next ) if ( mp->sel )
1231  for ( n=0, ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1232  ct->fmod = filename;
1233  ct->num = n;
1234  n++;
1235  }
1236 
1237  return n;
1238 }
1239 
1240 
1248 {
1249  if ( !model ) return 0;
1250 
1251  long nsel(0);
1252  Bcomponent* comp = NULL;
1253 
1254  for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1255  comp->radius = comprad;
1256  nsel++;
1257  }
1258 
1259  return nsel;
1260 }
1261 
1268 long model_set_density(Bmodel* model, double density)
1269 {
1270  if ( !model ) return 0;
1271 
1272  long nsel(0);
1273  Bcomponent* comp = NULL;
1274 
1275  for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1276  comp->density = density;
1277  nsel++;
1278  }
1279 
1280  return nsel;
1281 }
1282 
1289 long model_set_fom(Bmodel* model, double fom)
1290 {
1291  if ( !model ) return 0;
1292 
1293  long nsel(0);
1294  Bcomponent* comp = NULL;
1295 
1296  for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1297  comp->fom = fom;
1298  nsel++;
1299  }
1300 
1301  return nsel;
1302 }
1303 
model_set_fom
long model_set_fom(Bmodel *model, double fom)
Set the FOM of selected components to a specific value.
Definition: rwmodel.cpp:1289
read_model_star
Bmodel * read_model_star(Bstring *file_list)
Reads STAR model parameters.
Definition: rwmodel_star.cpp:26
read_model_molecule
Bmodel * read_model_molecule(Bstring *file_list, Bstring &paramfile)
Reads molecular model parameters.
Definition: rwmodel_mol.cpp:25
Bmodel::fom
float fom
Definition: rwmodel.h:128
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
component_count
long component_count(Bcomponent *comp)
Counts the total number of components.
Definition: rwmodel.cpp:808
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:270
Bcomponent
Definition: rwmodel.h:51
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
component_list_kill
int component_list_kill(Bcomponent *comp)
Deallocates memory for a list of components.
Definition: rwmodel.cpp:894
Bpolygon::next
Bpolygon * next
Definition: rwmodel.h:103
write_model_bild
int write_model_bild(Bstring &filename, Bmodel *model)
Writes Chimera BILD model parameters.
Definition: rwmodel_bild.cpp:232
Bmodel::hand
int hand
Definition: rwmodel.h:123
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
link_add
Blink * link_add(Blink **link, Bcomponent *comp1, Bcomponent *comp2, double length, double radius)
Adds a component link to a linked list.
Definition: rwmodel.cpp:318
Bcomptype::fmod
Bstring fmod
Definition: rwmodel.h:29
rwmodel.h
Header file for reading and writing atomic model files.
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
file_util.h
Header file for file checking functions.
Bcomptype::sel
int sel
Definition: rwmodel.h:34
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
link_copy
int link_copy(Blink *fromlink, Blink *tolink)
Copies all elements from one link to another.
Definition: rwmodel.cpp:839
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
rwmodel_xml.h
Read and write models in XML format.
model_associate
int model_associate(Bmodel *model, Bstring &associate_type, Bstring &associate_file)
Associates a model file with a component type.
Definition: rwmodel.cpp:1160
write_model_molecule
int write_model_molecule(Bstring &filename, Bmodel *model)
Writes molecular model parameters.
Definition: rwmodel_mol.cpp:100
Bcomptype
Definition: rwmodel.h:25
model_init
Bmodel * model_init(Bstring &id)
Initializes a model structure.
Definition: rwmodel.cpp:147
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
component_copy
int component_copy(Bcomponent *fromcomp, Bcomponent *tocomp)
Copies all elements from one component to another.
Definition: rwmodel.cpp:786
component_type_copy
int component_type_copy(Bcomptype *fromct, Bcomptype *toct)
Copies all elements from one component to another.
Definition: rwmodel.cpp:766
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
comp_associated_links_kill
int comp_associated_links_kill(Bcomponent *comp, Blink **link)
Deallocates memory for links associated with a component.
Definition: rwmodel.cpp:1095
Bstring::empty
bool empty()
Definition: Bstring.h:71
Bcomptype::index
int index
Definition: rwmodel.h:28
component_type_add
Bcomptype * component_type_add(Bcomptype **type, Bstring &id)
Adds a component type to a linked list.
Definition: rwmodel.cpp:233
component_find
Bcomponent * component_find(Bcomponent *comp, Bstring &id)
Finds a component in a component list.
Definition: rwmodel.cpp:825
Bpolygon::normal
Vector3< float > normal
Definition: rwmodel.h:106
model_associate_mass
int model_associate_mass(Bmodel *model, Bstring &associate_type, double mass)
Associates a mass with a component type.
Definition: rwmodel.cpp:1190
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:402
write_model_star
int write_model_star(Bstring &filename, Bmodel *model)
Writes STAR model parameters.
Definition: rwmodel_star.cpp:248
Bcomptype::mass
float mass
Definition: rwmodel.h:32
Bmodel::link
Blink * link
Definition: rwmodel.h:133
length
double length(vector< T > v)
Definition: Vector3.h:530
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:1247
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
read_model_chimera
Bmodel * read_model_chimera(Bstring *file_list)
Reads Chimera marker model parameters.
Definition: rwmodel_cmm.cpp:72
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
model_set_type
int model_set_type(Bmodel *model, Bstring &set_type)
Reset the component types.
Definition: rwmodel.cpp:519
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:29
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Color.h
Classes for color objects.
Bpolygon::closed
int closed
Definition: rwmodel.h:107
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
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
Bcomponent::vec
Vector3< float > vec
Definition: rwmodel.h:60
Bcomponent::vel
Vector3< float > vel
Definition: rwmodel.h:61
link_index
int link_index(Bcomponent *comp, Bcomponent *comp2)
Returns the index of a linked component.
Definition: rwmodel.cpp:381
command_line_time
Bstring command_line_time()
Returns the command line and time in a string.
Definition: utilities.cpp:71
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:389
Bmodel::id
Bstring id
Definition: rwmodel.h:121
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bmodel::split
int split
Definition: rwmodel.h:130
link_kill
int link_kill(Blink **link_list, Bcomponent *comp, int i)
Deletes a link.
Definition: rwmodel.cpp:991
rwmodel_cmm.h
Header file for reading and writing Chimera marker model parameters.
comp_type_kill
int comp_type_kill(Bcomptype *type)
Deallocates memory for one component type.
Definition: rwmodel.cpp:915
model_count_component_types
int model_count_component_types(Bmodel *model)
Counts the number of components for each type.
Definition: rwmodel.cpp:571
model_component_count
int model_component_count(Bmodel *model)
Counts the total number of components.
Definition: rwmodel.cpp:638
Bmodel::sel
int sel
Definition: rwmodel.h:129
View::normalize
double normalize()
Definition: View.h:109
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:92
Bcomponent::flag
int flag[MAXLINK]
Definition: rwmodel.h:57
rwmodel_bild.h
Header file for reading and writing Chimera BILD files.
Bmodel
Definition: rwmodel.h:119
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
read_model_bild
Bmodel * read_model_bild(Bstring *file_list)
Reads Chimera BILD model parameters.
Definition: rwmodel_bild.cpp:43
Bcomponent::color
RGBA< float > color
Definition: rwmodel.h:63
command
string command
Definition: utilities.cpp:20
utilities.h
Header file for general utilities.
RGBA< float >
read_model_xml
Bmodel * read_model_xml(Bstring *file_list)
Reads XML model parameters.
Definition: rwmodel_xml.cpp:185
model_set_comptype_filenames
int model_set_comptype_filenames(Bmodel *model, Bstring &filename)
Sets the filenames of all selected component types to the given string.
Definition: rwmodel.cpp:1222
Bmodel::img_num
int img_num
Definition: rwmodel.h:127
write_model_chimera
int write_model_chimera(Bstring &filename, Bmodel *model)
Writes Chimera marker model parameters.
Definition: rwmodel_cmm.cpp:198
Bpolygon::comp
Bcomponent * comp[MAXLINK]
Definition: rwmodel.h:105
component_kill
int component_kill(Bcomponent *comp)
Deallocates memory for one component.
Definition: rwmodel.cpp:880
Bcomponent::view
View view
Definition: rwmodel.h:59
Bcomptype::num
int num
Definition: rwmodel.h:30
Bcomponent::fom
float fom
Definition: rwmodel.h:65
model_get_type
Bcomptype * model_get_type(Bmodel *model, Bstring &id)
Return the type corresponding to an identifier.
Definition: rwmodel.cpp:494
model_copy
Bmodel * model_copy(Bmodel *model)
Copies a model.
Definition: rwmodel.cpp:688
Bpolygon
Definition: rwmodel.h:102
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
model_add_type_by_filename
Bcomptype * model_add_type_by_filename(Bmodel *model, Bstring &filename, int num)
Add a type to a model if the type with the given file name does not exist already.
Definition: rwmodel.cpp:437
model
Bmodel * model
Definition: bshow.cpp:34
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1127
model_check
int model_check(Bmodel *model, Bstring path)
Checks model properties.
Definition: rwmodel.cpp:595
link_find
Blink * link_find(Blink *link, Bcomponent *comp1, Bcomponent *comp2)
Finds a link in a link list.
Definition: rwmodel.cpp:860
comp_type_list_kill
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
Definition: rwmodel.cpp:929
verbose
int verbose
model_set_map_filenames
int model_set_map_filenames(Bmodel *model, Bstring &mapfile)
Sets all the map file names of selected models.
Definition: rwmodel.cpp:398
model_set_density
long model_set_density(Bmodel *model, double density)
Set the density of selected components to a specific value.
Definition: rwmodel.cpp:1268
find_file
Bstring find_file(Bstring filename, Bstring path, int flag=0)
Searches for a file within or without the given path.
Definition: file_util.cpp:54
model_list_copy
Bmodel * model_list_copy(Bmodel *model)
Copies a model.
Definition: rwmodel.cpp:660
linked_list.h
Header file for generalized linked list functions.
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
rwmodel_mol.h
Header file for reading and writing molecular model parameters.
Bpolygon::number
int number
Definition: rwmodel.h:104
Bmodel::type
Bcomptype * type
Definition: rwmodel.h:131
Bcomptype::next
Bcomptype * next
Definition: rwmodel.h:26
Bcomponent::radius
float radius
Definition: rwmodel.h:62
model_add
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Definition: rwmodel.cpp:181
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
write_model_xml
int write_model_xml(Bstring &filename, Bmodel *model)
Writes XML model parameters.
Definition: rwmodel_xml.cpp:298
MAXLINK
#define MAXLINK
Definition: rwmodel.h:14
Bcomptype::fom
float fom
Definition: rwmodel.h:33
model_link_list_kill
int model_link_list_kill(Bmodel *model)
Deallocates memory for a list of component links.
Definition: rwmodel.cpp:953
write_model_vega
int write_model_vega(Bstring &filename, Bmodel *model)
Writes Vega model parameters.
Definition: rwmodel_vega.cpp:96
model_change_type
int model_change_type(Bmodel *model, Bstring &change_type)
Change a component type name.
Definition: rwmodel.cpp:548
Bcomponent::link
Bcomponent * link[MAXLINK]
Definition: rwmodel.h:55
Bcomponent::density
float density
Definition: rwmodel.h:64
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bcomptype::count
int count
Definition: rwmodel.h:31
poly_list_kill
int poly_list_kill(Bpolygon *poly)
Deallocates memory for a list of polygons.
Definition: rwmodel.cpp:1073
rwmodel_vega.h
Header file for reading and writing Vega model parameters.
Bmodel::comment
Bstring comment
Definition: rwmodel.h:126
read_model_vega
Bmodel * read_model_vega(Bstring *file_list)
Reads Vega model parameters.
Definition: rwmodel_vega.cpp:21
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
rwmodel_star.h
Header file for reading and writing STAR model parameters.
Bmodel::type_id
Bstring type_id
Definition: rwmodel.h:122
Bcomponent::sel
int sel
Definition: rwmodel.h:66