| Bsoft 2.0.5 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
25 // Internal function prototypes
26
27
28 Bmodel* read_model(Bstring& filename)
29 {
30 return read_model(&filename);
31 }
32
33 Bmodel* read_model(Bstring* file_list)
34 {
35 Bstring paramfile;
36 return read_model(file_list, paramfile);
37 }
38
39 Bmodel* read_model(Bstring& filename, Bstring& paramfile)
40 {
41 return read_model(&filename, paramfile);
42 }
43
50 Bmodel* read_model(Bstring* file_list, Bstring& paramfile)
51 {
52 Bstring ext = file_list->extension();
53
54 if ( verbose & VERB_DEBUG )
55 cout << "DEBUG read_model: extension=" << ext << endl;
56
57 Bmodel* model = NULL;
58 Bstring path;
59
60 if ( ext.contains("star") || ext.contains("cif") )
61 model = read_model_star(file_list);
62 else if ( ext.contains("xml") )
63 model = read_model_xml(file_list);
64 else if ( ext.contains("cmm") )
65 model = read_model_chimera(file_list);
66 else if ( ext.contains("bld") || ext.contains("bild") )
67 model = read_model_bild(file_list);
68 else if ( ext.contains("v3d") )
69 model = read_model_vega(file_list);
70 else
71 model = read_model_molecule(file_list, paramfile);
72
73 if ( !model ) {
74 cerr << "Error: File with extension " << ext << " not read!" << endl;
75 error_show(file_list->c_str(), __FILE__, __LINE__);
76 } else {
77 // if ( !model->link ) model_list_setup_links(model);
78 path = file_list->pre_rev('/');
79 model_check(model, path);
80 }
81
82 return model;
83 }
84
91 int write_model(Bstring& filename, Bmodel* model)
92 {
93 if ( !model ) return 0;
94
95 int n(0);
96
97 if ( model->split == 9 ) {
98 n = write_model_star(filename, model);
99 return n;
100 }
101
102 if ( filename.empty() ) {
103 cerr << "Error: No model filename!" << endl;
104 return -1;
105 }
106
107 Bstring ext = filename.extension();
108
109 if ( verbose & VERB_DEBUG )
110 cout << "DEBUG write_model: extension=" << ext << endl;
111
112 if ( verbose & VERB_LABEL )
113 cout << "Writing file: " << filename << endl;
114
115 // Bstring path = filename.pre_rev('/');
116 // model_check(model, path);
117
118 if ( ext.contains("star") || ext.contains("cif") )
119 n = write_model_star(filename, model);
120 else if ( ext.contains("xml") )
121 n = write_model_xml(filename, model);
122 else if ( ext.contains("cmm") )
123 n = write_model_chimera(filename, model);
124 else if ( ext.contains("bld") || ext.contains("bild") )
125 n = write_model_bild(filename, model);
126 else if ( ext.contains("v3d") )
127 n = write_model_vega(filename, model);
128 else
129 n = write_model_molecule(filename, model);
130
131 if ( n < 0 ) {
132 cerr << "Error: File with extension " << ext << " not written!" << endl;
133 error_show(filename.c_str(), __FILE__, __LINE__);
134 }
135
136 return n;
137 }
138
144 Bmodel* model_init(Bstring& id)
145 {
146 Bmodel* model = new Bmodel;
147 memset(model, 0, sizeof(Bmodel));
148
149 model->id = id;
150 model->type_id = "?";
151 model->symmetry = "C1";
152 model->sel = 1;
153
154 return model;
155 }
156
157 Bmodel* model_init(const char* cid)
158 {
159 Bstring id(cid);
160 Bmodel* model = model_init(id);
161 id = 0;
162
163 return model;
164 }
165
178 Bmodel* model_add(Bmodel** model, Bstring& id)
179 {
180 Bmodel* this_model = *model;
181 Bmodel* new_model = model_init(id);
182
183 if ( verbose & VERB_DEBUG )
184 cout << "DEBUG model_add: type=" << new_model->id << endl;
185
186 if ( !this_model )
187 *model = new_model;
188 else {
189 while ( this_model->next ) this_model = this_model->next;
190 this_model->next = new_model;
191 }
192
193 return new_model;
194 }
195
196 Bmodel* model_add(Bmodel** model, const char* cid)
197 {
198 Bstring id(cid);
199 Bmodel* new_model = model_add(model, id);
200 id = 0;
201
202 return new_model;
203 }
204
205 Bmodel* model_add(Bmodel** model, Bmodel* model_nu)
206 {
207 Bmodel* mp = NULL;
208
209 if ( *model )
210 for ( mp = *model; mp->next; mp = mp->next ) ; // Pointer to last model
211
212 if ( mp ) mp->next = model_nu;
213 else *model = model_nu;
214
215 return model_nu;
216 }
217
230 Bcomptype* component_type_add(Bcomptype** type, Bstring& id)
231 {
232 Bcomptype* this_type = *type;
233 Bcomptype* new_type = new Bcomptype;
234 memset(new_type, 0, sizeof(Bcomptype));
235
236 new_type->id = id;
237 new_type->fmod = "?";
238 new_type->mass = 1;
239 new_type->fom = 1;
240 new_type->sel = 1;
241
242 if ( verbose & VERB_DEBUG )
243 cout << "DEBUG component_type_add: type=" << new_type->id << endl;
244
245 if ( !this_type )
246 *type = new_type;
247 else {
248 while ( this_type->next ) this_type = this_type->next;
249 this_type->next = new_type;
250 }
251
252 return new_type;
253 }
254
267 Bcomponent* component_add(Bcomponent** comp, Bstring& id)
268 {
269 Bcomponent* this_comp = *comp;
270 Bcomponent* new_comp = new Bcomponent;
271 memset(new_comp, 0, sizeof(Bcomponent));
272
273 new_comp->id = id;
274 new_comp->view[2] = 1;
275 new_comp->radius = 1;
276 new_comp->color = RGBA<float>(1,1,1,1);
277 new_comp->density = 1;
278 new_comp->fom = 1;
279 new_comp->sel = 1;
280
281 if ( verbose & VERB_DEBUG )
282 cout << "DEBUG component_add: id=" << new_comp->id << endl;
283
284 if ( !this_comp )
285 *comp = new_comp;
286 else {
287 while ( this_comp->next ) this_comp = this_comp->next;
288 this_comp->next = new_comp;
289 }
290
291 return new_comp;
292 }
293
294 Bcomponent* component_add(Bcomponent** comp, unsigned long number)
295 {
296 Bstring id(number, "%ld");
297 return component_add(comp, id);
298 }
299
315 Blink* link_add(Blink** link, Bcomponent* comp1, Bcomponent* comp2, double length, double radius)
316 {
317 int i, j;
318 Blink* this_link = *link;
319
320 for ( i=0; i<MAXLINK && comp1->link[i] && comp1->link[i] != comp2; i++ ) ;
321 for ( j=0; j<MAXLINK && comp2->link[j] && comp2->link[j] != comp1; j++ ) ;
322
323 if ( comp1->link[i] == comp2 && comp2->link[j] == comp1 ) {
324 if ( verbose & VERB_FULL )
325 cerr << "Error: " << comp1->id << " already linked to " << comp2->id <<
326 "! (" << i << " -" << j << ")" << endl;
327 return this_link;
328 }
329
330 if ( i<MAXLINK && j<MAXLINK ) {
331 comp1->link[i] = comp2;
332 comp2->link[j] = comp1;
333 comp1->flag[i] = comp2->flag[j] = 1;
334 }
335
336 Blink* new_link = new Blink;
337 memset(new_link, 0, sizeof(Blink));
338
339 if ( length < 1e-6 ) length = comp1->loc.distance(comp2->loc);
340
341 if ( radius < 1e-6 ) radius = (comp1->radius + comp2->radius)/4;
342
343 new_link->comp[0] = comp1;
344 new_link->comp[1] = comp2;
345 new_link->length = length;
346 new_link->radius = radius;
347 new_link->color = (comp1->color + comp2->color)/2;
348 new_link->sel = 1;
349
350 if ( verbose & VERB_DEBUG )
351 cout << "DEBUG link_add: " << comp1->id << " - " << comp2->id << endl;
352
353 if ( !this_link )
354 *link = new_link;
355 else {
356 while ( this_link->next ) this_link = this_link->next;
357 this_link->next = new_link;
358 }
359
360 return new_link;
361 }
362
363 Blink* link_add(Blink** link, Bcomponent* comp1, Bcomponent* comp2)
364 {
365 return link_add(link, comp1, comp2, 0, 0);
366 }
367
378 int link_index(Bcomponent* comp, Bcomponent* comp2)
379 {
380 int i;
381
382 for ( i=0; i<MAXLINK && comp->link[i] && comp->link[i] != comp2; i++ ) ;
383
384 if ( !comp->link[i] || i >= MAXLINK ) i = -1;
385
386 return i;
387 }
388
395 int model_set_map_filenames(Bmodel* model, Bstring& mapfile)
396 {
397 Bmodel* mp;
398
399 for ( mp = model; mp; mp = mp->next )
400 if ( mp->sel ) mp->fmap = mapfile;
401
402 return 0;
403 }
404
411 Bcomptype* model_add_type_by_id(Bmodel* model, Bstring& id)
412 {
413 Bcomptype* ct = NULL;
414
415 if ( verbose & VERB_DEBUG )
416 cout << "DEBUG model_add_type_by_id: id=" << id << endl;
417
418 if ( model->type )
419 for ( ct = model->type; ct && id != ct->id; ct = ct->next ) ;
420
421 if ( !ct )
422 ct = component_type_add(&model->type, id);
423
424 return ct;
425 }
426
434 Bcomptype* model_add_type_by_filename(Bmodel* model, Bstring& filename, int num)
435 {
436 int i(0);
437 Bstring id("1");
438 Bcomptype* ct = NULL;
439
440 if ( verbose & VERB_DEBUG )
441 cout << "DEBUG model_add_type_by_filename: filename=" << filename << endl;
442
443 if ( model->type )
444 for ( i=1, ct = model->type; ct; ct = ct->next, i++ )
445 if ( filename == ct->fmod ) break;
446
447 if ( !ct ) {
448 ct = component_type_add(&model->type, id);
449 ct->id = Bstring(i, "%d");
450 ct->fmod = filename;
451 ct->num = num;
452 }
453
454 return ct;
455 }
456
465 Bcomptype* model_add_type_by_id_and_filename(Bmodel* model, Bstring& id, Bstring& filename, int num)
466 {
467 Bcomptype* ct = NULL;
468
469 if ( verbose & VERB_DEBUG )
470 cout << "DEBUG model_add_type_by_id_and_filename: id" << id << " filename=" << filename << endl;
471
472 if ( model->type )
473 for ( ct = model->type; ct; ct = ct->next )
474 if ( id == ct->id && filename == ct->fmod ) break;
475
476 if ( !ct ) {
477 ct = component_type_add(&model->type, id);
478 ct->fmod = filename;
479 ct->num = num;
480 }
481
482 return ct;
483 }
484
491 Bcomptype* model_get_type(Bmodel* model, Bstring& id)
492 {
493 if ( !model ) return NULL;
494
495 Bcomptype* ct = NULL;
496
497 if ( verbose & VERB_DEBUG )
498 cout << "DEBUG model_get_type: id=" << id << endl;
499
500 if ( model->type )
501 for ( ct = model->type; ct; ct = ct->next )
502 if ( id == ct->id ) break;
503
504 return ct;
505 }
506
516 int model_set_type(Bmodel* model, Bstring& set_type)
517 {
518 if ( !model ) return 0;
519
520 int n;
521 Bmodel* mp;
522 Bcomponent* comp;
523 Bcomptype* ct;
524
525 for ( n=0, mp = model; mp; mp = mp->next, n++ ) {
526 comp_type_list_kill(mp->type);
527 mp->type = NULL;
528 ct = model_add_type_by_id(mp, set_type);
529 for ( comp = mp->comp; comp; comp = comp->next )
530 comp->type = ct;
531 }
532
533 return n;
534 }
535
545 int model_change_type(Bmodel* model, Bstring& change_type)
546 {
547 if ( !model ) return 0;
548
549 int n;
550 Bmodel* mp;
551 Bcomptype* ct;
552
553 Bstring ot(change_type.pre(',')), nt(change_type.post(','));
554
555 for ( n=0, mp = model; mp; mp = mp->next, n++ ) {
556 for ( ct = mp->type; ct; ct = ct->next )
557 if ( ct->id == ot ) ct->id = nt;
558 }
559
560 return n;
561 }
562
568 int model_count_component_types(Bmodel* model)
569 {
570 Bmodel* mp = NULL;
571 Bcomptype* ct = NULL;
572 Bcomponent* comp = NULL;
573
574 if ( verbose & VERB_DEBUG )
575 cout << "DEBUG model_count_component_types: " << model->id << endl;
576
577 for ( mp = model; mp; mp = mp->next ) {
578 for ( ct = mp->type; ct; ct = ct->next ) ct->count = 0;
579 for ( comp = mp->comp; comp; comp = comp->next )
580 comp->type->count++;
581 }
582
583 return 0;
584 }
585
592 int model_check(Bmodel* model, Bstring path)
593 {
594 if ( !model ) return 0;
595
596 long nmod(0), ncomp(0), nlink(0);
597 Bmodel* mp = NULL;
598 Bcomptype* ct = NULL;
599 Bcomponent* comp = NULL;
600 Blink* link = NULL;
601 Bstring nutype("UNK");
602
603
604 for ( mp = model; mp; mp = mp->next, nmod++ ) {
605 if ( mp->fmap.empty() ) mp->fmap = "?";
606 else mp->fmap = find_file(mp->fmap, path);
607 for ( comp = mp->comp; comp; comp = comp->next, ncomp++ ) {
608 comp->view.normalize();
609 if ( comp->radius < 1e-6 ) comp->radius = 1;
610 if ( !comp->type ) {
611 cerr << "Component " << comp->id << " has no type assigned" << endl;
612 comp->type = model_add_type_by_id(mp, nutype);
613 }
614 }
615 for ( ct = mp->type; ct; ct = ct->next ) {
616 if ( ct->fmod.empty() ) ct->fmod = "?";
617 if ( ct->mass < 1 ) ct->mass = 1;
618 }
619 for ( link = mp->link; link; link = link->next, nlink++ ) {
620 if ( link->length < 1e-6 ) link->length = link->comp[0]->loc.distance(link->comp[1]->loc);
621 if ( link->radius < 1e-6 ) link->radius = 0.1*link->length;
622 }
623 }
624
625 model_count_component_types(model);
626
627 return 0;
628 }
629
635 int model_component_count(Bmodel* model)
636 {
637 if ( !model ) return 0;
638
639 int ncomp;
640 Bmodel* mp;
641 Bcomponent* comp;
642
643 for ( ncomp=0, mp = model; mp; mp = mp->next )
644 for ( comp = mp->comp; comp; comp = comp->next, ncomp++ ) ;
645
646 return ncomp;
647 }
648
657 Bmodel* model_list_copy(Bmodel* model)
658 {
659 if ( !model ) return NULL;
660
661 Bmodel* model_new = NULL;
662 Bmodel* mp;
663 Bmodel* mp_new;
664
665 for ( mp = model; mp; mp = mp->next ) {
666 if ( model_new ) {
667 mp_new->next = model_copy(mp);
668 mp_new = mp_new->next;
669 } else {
670 model_new = mp_new = model_copy(mp);
671 }
672 }
673
674 return model_new;
675 }
676
685 Bmodel* model_copy(Bmodel* model)
686 {
687 if ( !model ) return NULL;
688
689 int i;
690
691 Bcomptype* type;
692 Bcomponent* comp;
693 Blink* link;
694 Bpolygon* poly;
695
696 Bcomptype* type_new = NULL;
697 Bcomponent* comp_new = NULL;
698 Blink* link_new = NULL;
699 Bpolygon* poly_new = NULL;
700
701 Bmodel* model_new = model_init(model->id);
702
703 model_new->type_id = model->type_id;
704 model_new->comment = model->comment;
705 model_new->symmetry = model->symmetry;
706 model_new->fmap = model->fmap;
707 model_new->img_num = model->img_num;
708 model_new->sel = model->sel;
709 model_new->fom = model->fom;
710 model_new->split = model->split;
711 model_new->hand = model->hand;
712
713 for ( type = model->type; type; type = type->next ) {
714 type_new = model_add_type_by_id_and_filename(model_new, type->id, type->fmod, type->num);
715 type_new->count = type->count;
716 type_new->mass = type->mass;
717 type_new->fom = type->fom;
718 type_new->sel = type->sel;
719 }
720
721 for ( comp = model->comp; comp; comp = comp->next ) {
722 comp_new = component_add(&comp_new, comp->id);
723 if ( !model_new->comp ) model_new->comp = comp_new;
724 component_copy(comp, comp_new);
725 comp_new->type = model_add_type_by_id(model_new, comp->type->id);
726 }
727
728 for ( link = model->link; link; link = link->next ) {
729 link_new = (Blink *) add_item((char **) &link_new, sizeof(Blink));
730 if ( !model_new->link ) model_new->link = link_new;
731 for ( comp = model->comp, comp_new = model_new->comp; comp; comp = comp->next, comp_new = comp_new->next ) {
732 if ( link->comp[0] == comp ) link_new->comp[0] = comp_new;
733 if ( link->comp[1] == comp ) link_new->comp[1] = comp_new;
734 }
735 link_new->length = link->length;
736 link_new->radius = link->radius;
737 link_new->color = link->color;
738 }
739
740 for ( poly = model->poly; poly; poly = poly->next ) {
741 poly_new = (Bpolygon *) add_item((char **) &poly_new, sizeof(Bpolygon));
742 if ( !model_new->poly ) model_new->poly = poly_new;
743 poly_new->number = poly->number;
744 poly_new->normal = poly->normal;
745 poly_new->closed = poly->closed;
746 for ( comp = model->comp, comp_new = model_new->comp; comp; comp = comp->next, comp_new = comp_new->next ) {
747 for ( i=0; poly->comp[i]; i++ )
748 if ( poly->comp[i] == comp ) poly_new->comp[i] = comp_new;
749 }
750 }
751
752 model_setup_links(model_new);
753
754 return model_new;
755 }
756
763 int component_type_copy(Bcomptype* fromct, Bcomptype* toct)
764 {
765 toct->id = fromct->id;
766 toct->index = fromct->index;
767 toct->fmod = fromct->fmod;
768 toct->num = fromct->num;
769 toct->count = fromct->count;
770 toct->mass = fromct->mass;
771 toct->fom = fromct->fom;
772 toct->sel = fromct->sel;
773
774 return 0;
775 }
776
783 int component_copy(Bcomponent* fromcomp, Bcomponent* tocomp)
784 {
785 tocomp->type = fromcomp->type;
786 tocomp->id = fromcomp->id;
787 tocomp->loc = fromcomp->loc;
788 tocomp->view = fromcomp->view;
789 tocomp->vec = fromcomp->vec;
790 tocomp->vel = fromcomp->vel;
791 tocomp->radius = fromcomp->radius;
792 tocomp->color = fromcomp->color;
793 tocomp->density = fromcomp->density;
794 tocomp->fom = fromcomp->fom;
795 tocomp->sel = fromcomp->sel;
796
797 return 0;
798 }
799
805 long component_count(Bcomponent* comp)
806 {
807 if ( !comp ) return 0;
808
809 long ncomp(0);
810
811 for ( ; comp; comp = comp->next, ncomp++ ) ;
812
813 return ncomp;
814 }
815
822 Bcomponent* component_find(Bcomponent* comp, Bstring& id)
823 {
824 for ( ; comp; comp = comp->next )
825 if ( comp->id == id ) return comp;
826
827 return NULL;
828 }
829
836 int link_copy(Blink* fromlink, Blink* tolink)
837 {
838 tolink->comp[0] = fromlink->comp[0];
839 tolink->comp[1] = fromlink->comp[1];
840 tolink->angle = fromlink->angle;
841 tolink->length = fromlink->length;
842 tolink->radius = fromlink->radius;
843 tolink->color = fromlink->color;
844 tolink->fom = fromlink->fom;
845 tolink->sel = fromlink->sel;
846
847 return 0;
848 }
849
857 Blink* link_find(Blink* link, Bcomponent* comp1, Bcomponent* comp2)
858 {
859 for ( ; link; link = link->next ) {
860 if ( link->comp[0] == comp1 )
861 if ( link->comp[1] == comp2 ) return link;
862 if ( link->comp[1] == comp1 )
863 if ( link->comp[0] == comp2 ) return link;
864 }
865
866 cerr << "Error: Link not found!" << endl;
867
868 return link;
869 }
870
871
877 int component_kill(Bcomponent* comp)
878 {
879 comp->id = 0;
880 comp->type = NULL;
881 delete comp;
882
883 return 0;
884 }
885
891 int component_list_kill(Bcomponent* comp)
892 {
893 int n(0);
894 Bcomponent* c = NULL;
895 Bcomponent* c2 = NULL;
896
897 for ( c = comp; c; ) {
898 c2 = c->next;
899 component_kill(c);
900 c = c2;
901 n++;
902 }
903
904 return n;
905 }
906
912 int comp_type_kill(Bcomptype* type)
913 {
914 type->id = 0;
915 type->fmod = 0;
916 delete type;
917
918 return 0;
919 }
920
926 int comp_type_list_kill(Bcomptype* type)
927 {
928 int n(0);
929 Bcomptype* ct = NULL;
930 Bcomptype* ct2 = NULL;
931
932 for ( ct = type; ct; ) {
933 ct2 = ct->next;
934 comp_type_kill(ct);
935 ct = ct2;
936 n++;
937 }
938
939 return n;
940 }
941
950 int model_link_list_kill(Bmodel* model)
951 {
952 if ( !model ) return 0;
953
954 int i, n(0);
955 Bcomponent* comp;
956 Blink* link = NULL;
957 Blink* link2 = NULL;
958
959 for ( comp = model->comp; comp; comp = comp->next ) {
960 for ( i=0; i<MAXLINK; i++ ) {
961 comp->link[i] = NULL;
962 comp->flag[i] = 0;
963 }
964 }
965
966 for ( link = model->link; link; ) {
967 link2 = link->next;
968 delete link;
969 link = link2;
970 n++;
971 }
972
973 return n;
974 }
975
988 int link_kill(Blink** link_list, Bcomponent* comp, int i)
989 {
990 int j, k;
991 Blink* link, *plink;
992 Bcomponent* comp2 = comp->link[i];
993
994 j = link_index(comp2, comp);
995
996 if ( j < 0 ) {
997 cerr << "Error: Component " << comp->id << " is not linked to component " << comp2->id << endl << endl;
998 return -1;
999 }
1000
1001 if ( verbose & VERB_FULL )
1002 cout << "Deleting: " << comp->id << " (" << comp->sel << ") " << comp2->id << " (" << comp2->sel << ")" << endl;
1003
1004 for ( k=i; k+1<MAXLINK && comp->link[k+1]; k++ ) {
1005 comp->link[k] = comp->link[k+1];
1006 comp->flag[k] = comp->flag[k+1];
1007 }
1008 comp->link[k] = NULL;
1009 comp->flag[k] = 0;
1010
1011 for ( k=j; k+1<MAXLINK && comp2->link[k+1]; k++ ) {
1012 comp2->link[k] = comp2->link[k+1];
1013 comp2->flag[k] = comp2->flag[k+1];
1014 }
1015 comp2->link[k] = NULL;
1016 comp2->flag[k] = 0;
1017
1018 for ( link = plink = *link_list; link; ) {
1019 if ( ( link->comp[0] == comp && link->comp[1] == comp2 ) ||
1020 ( link->comp[1] == comp && link->comp[0] == comp2 ) ) {
1021 if ( link == plink ) {
1022 *link_list = plink = link->next;
1023 delete link;
1024 link = plink;
1025 } else {
1026 plink->next = link->next;
1027 delete link;
1028 link = plink->next;
1029 }
1030 } else {
1031 plink = link;
1032 link = link->next;
1033 }
1034 }
1035
1036 return 0;
1037 }
1038
1051 int link_kill(Blink** link_list, Bcomponent* comp, Bcomponent* comp2)
1052 {
1053 int i = link_index(comp, comp2);
1054
1055 if ( !comp->link[i] ) {
1056 cerr << "Error: Component " << comp->id << " is not linked to component " << comp2->id << endl << endl;
1057 return -1;
1058 }
1059
1060 link_kill(link_list, comp, i);
1061
1062 return 0;
1063 }
1064
1070 int poly_list_kill(Bpolygon* poly)
1071 {
1072 int n(0);
1073 Bpolygon* p = NULL;
1074 Bpolygon* p2 = NULL;
1075
1076 for ( p = poly; p; ) {
1077 p2 = p->next;
1078 delete p;
1079 p = p2;
1080 n++;
1081 }
1082
1083 return n;
1084 }
1085
1092 int comp_associated_links_kill(Bcomponent* comp, Blink** link)
1093 {
1094 int n(0);
1095 Blink* l = *link;
1096 Blink* lp = NULL;
1097
1098 while ( l ) {
1099 if ( l->comp[0] == comp || l->comp[1] == comp ) {
1100 if ( lp ) {
1101 lp->next = l->next;
1102 delete l;
1103 l = lp->next;
1104 } else {
1105 *link = l->next;
1106 delete l;
1107 l = *link;
1108 }
1109 n++;
1110 } else {
1111 lp = l;
1112 l = l->next;
1113 }
1114 }
1115
1116 return n;
1117 }
1118
1124 int model_kill(Bmodel* model)
1125 {
1126 Bmodel* mp = NULL;
1127 Bmodel* mp2 = NULL;
1128
1129 for ( mp = model; mp; ) {
1130 mp2 = mp->next;
1131 model_link_list_kill(mp);
1132 component_list_kill(mp->comp);
1133 comp_type_list_kill(mp->type);
1134 poly_list_kill(mp->poly);
1135 mp->id = 0;
1136 mp->comment = 0;
1137 mp->type_id = 0;
1138 mp->symmetry = 0;
1139 mp->fmap = 0;
1140 delete mp;
1141 mp = mp2;
1142 }
1143
1144 return 0;
1145 }
1146
1158 int model_update_comment(Bmodel* model, int n, char** strings)
1159 {
1160 if ( !model ) return 0;
1161
1162 model->comment += command_line_time(n, strings);
1163
1164 return model->comment.length();
1165 }
1166
1177 int model_associate(Bmodel* model, Bstring& associate_type, Bstring& associate_file)
1178 {
1179 if ( !model ) return 0;
1180
1181 int n(0);
1182 Bmodel* mp = NULL;
1183 Bcomptype* ct = NULL;
1184
1185 if ( verbose & VERB_PROCESS )
1186 cout << "Associating component " << associate_type << " with file " << associate_file << endl << endl;
1187
1188 for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
1189 for ( ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1190 if ( ct->id == associate_type ) {
1191 ct->fmod = associate_file;
1192 n++;
1193 }
1194 }
1195 }
1196
1197 return n;
1198 }
1199
1207 int model_associate_mass(Bmodel* model, Bstring& associate_type, double mass)
1208 {
1209 if ( !model ) return 0;
1210
1211 int n(0);
1212 Bmodel* mp = NULL;
1213 Bcomptype* ct = NULL;
1214
1215 if ( verbose & VERB_PROCESS )
1216 cout << "Associating component " << associate_type << " with mass = " << mass << endl << endl;
1217
1218 for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
1219 for ( ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1220 if ( ct->id == associate_type ) {
1221 ct->mass = mass;
1222 n++;
1223 }
1224 }
1225 }
1226
1227 return n;
1228 }
1229
1239 int model_set_comptype_filenames(Bmodel* model, Bstring& filename)
1240 {
1241 if ( !model ) return 0;
1242
1243 int n(0);
1244 Bmodel* mp;
1245 Bcomptype* ct;
1246
1247 for ( mp = model; mp; mp = mp->next ) if ( mp->sel )
1248 for ( n=0, ct = mp->type; ct; ct = ct->next ) if ( ct->sel ) {
1249 ct->fmod = filename;
1250 ct->num = n;
1251 n++;
1252 }
1253
1254 return n;
1255 }
1256
1257
1264 long model_set_component_radius(Bmodel* model, double comprad)
1265 {
1266 if ( !model ) return 0;
1267
1268 long nsel(0);
1269 Bcomponent* comp = NULL;
1270
1271 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1272 comp->radius = comprad;
1273 nsel++;
1274 }
1275
1276 return nsel;
1277 }
1278
1285 long model_set_density(Bmodel* model, double density)
1286 {
1287 if ( !model ) return 0;
1288
1289 long nsel(0);
1290 Bcomponent* comp = NULL;
1291
1292 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1293 comp->density = density;
1294 nsel++;
1295 }
1296
1297 return nsel;
1298 }
1299
1306 long model_set_fom(Bmodel* model, double fom)
1307 {
1308 if ( !model ) return 0;
1309
1310 long nsel(0);
1311 Bcomponent* comp = NULL;
1312
1313 for ( comp = model->comp; comp; comp = comp->next ) if ( comp->sel ) {
1314 comp->fom = fom;
1315 nsel++;
1316 }
1317
1318 return nsel;
1319 }
1320
comp_associated_links_kill
int comp_associated_links_kill(Bcomponent *comp, Blink **link)
Deallocates memory for links associated with a component.
Definition: rwmodel.cpp:1092
Bmodel::img_num
int img_num
Definition: rwmodel.h:127
MAXLINK
#define MAXLINK
Definition: rwmodel.h:14
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
link_kill
int link_kill(Blink **link_list, Bcomponent *comp, int i)
Deletes a link.
Definition: rwmodel.cpp:988
write_model_vega
int write_model_vega(Bstring &filename, Bmodel *model)
Writes Vega model parameters.
Definition: rwmodel_vega.cpp:96
Blink
Definition: rwmodel.h:82
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
read_model_star
Bmodel * read_model_star(Bstring *file_list)
Reads STAR model parameters.
Definition: rwmodel_star.cpp:26
Bmodel::id
Bstring id
Definition: rwmodel.h:121
model_set_component_radius
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
Definition: rwmodel.cpp:1264
model_add
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Definition: rwmodel.cpp:178
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
component_count
long component_count(Bcomponent *comp)
Counts the total number of components.
Definition: rwmodel.cpp:805
write_model_bild
int write_model_bild(Bstring &filename, Bmodel *model)
Writes Chimera BILD model parameters.
Definition: rwmodel_bild.cpp:232
model_count_component_types
int model_count_component_types(Bmodel *model)
Counts the number of components for each type.
Definition: rwmodel.cpp:568
verbose
int verbose
utilities.h
Header file for general utilities.
Blink::color
RGBA< float > color
Definition: rwmodel.h:88
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
model_associate
int model_associate(Bmodel *model, Bstring &associate_type, Bstring &associate_file)
Associates a model file with a component type.
Definition: rwmodel.cpp:1177
Bcomptype::fmod
Bstring fmod
Definition: rwmodel.h:29
RGBA< float >
Bcomponent::flag
int flag[MAXLINK]
Definition: rwmodel.h:57
Bpolygon::comp
Bcomponent * comp[MAXLINK]
Definition: rwmodel.h:105
Bmodel::split
int split
Definition: rwmodel.h:130
Bpolygon
Definition: rwmodel.h:102
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Blink::sel
int sel
Definition: rwmodel.h:90
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmodel::comment
Bstring comment
Definition: rwmodel.h:126
write_model_xml
int write_model_xml(Bstring &filename, Bmodel *model)
Writes XML model parameters.
Definition: rwmodel_xml.cpp:298
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
rwmodel_cmm.h
Header file for reading and writing Chimera marker model parameters.
model_set_fom
long model_set_fom(Bmodel *model, double fom)
Set the FOM of selected components to a specific value.
Definition: rwmodel.cpp:1306
comp_type_kill
int comp_type_kill(Bcomptype *type)
Deallocates memory for one component type.
Definition: rwmodel.cpp:912
Bcomponent::vel
Vector3< float > vel
Definition: rwmodel.h:61
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:267
Bcomptype::sel
int sel
Definition: rwmodel.h:34
read_model_xml
Bmodel * read_model_xml(Bstring *file_list)
Reads XML model parameters.
Definition: rwmodel_xml.cpp:185
model_links.h
Library routines used for model link processing.
Blink::comp
Bcomponent * comp[2]
Definition: rwmodel.h:84
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
model_associate_mass
int model_associate_mass(Bmodel *model, Bstring &associate_type, double mass)
Associates a mass with a component type.
Definition: rwmodel.cpp:1207
model_copy
Bmodel * model_copy(Bmodel *model)
Copies a model.
Definition: rwmodel.cpp:685
write_model_chimera
int write_model_chimera(Bstring &filename, Bmodel *model)
Writes Chimera marker model parameters.
Definition: rwmodel_cmm.cpp:198
Bmodel::hand
int hand
Definition: rwmodel.h:123
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
Bpolygon::number
int number
Definition: rwmodel.h:104
Bcomptype::index
int index
Definition: rwmodel.h:28
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
linked_list.h
Header file for generalized linked list functions.
Blink::length
float length
Definition: rwmodel.h:86
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
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:411
component_copy
int component_copy(Bcomponent *fromcomp, Bcomponent *tocomp)
Copies all elements from one component to another.
Definition: rwmodel.cpp:783
Bcomponent::view
View view
Definition: rwmodel.h:59
Blink::next
Blink * next
Definition: rwmodel.h:83
Bcomponent::fom
float fom
Definition: rwmodel.h:65
model_init
Bmodel * model_init(Bstring &id)
Initializes a model structure.
Definition: rwmodel.cpp:144
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:1239
write_model_star
int write_model_star(Bstring &filename, Bmodel *model)
Writes STAR model parameters.
Definition: rwmodel_star.cpp:248
Bmodel::type
Bcomptype * type
Definition: rwmodel.h:131
Bmodel::type_id
Bstring type_id
Definition: rwmodel.h:122
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:381
Blink::radius
float radius
Definition: rwmodel.h:87
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:434
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:515
length
double length(vector< T > v)
Definition: Vector3.h:528
rwmodel_xml.h
Read and write models in XML format.
model_setup_links
long model_setup_links(Bmodel *model)
Set up the link list for each component.
Definition: model_links.cpp:28
read_model_bild
Bmodel * read_model_bild(Bstring *file_list)
Reads Chimera BILD model parameters.
Definition: rwmodel_bild.cpp:43
Blink::angle
float angle
Definition: rwmodel.h:85
Bcomponent::density
float density
Definition: rwmodel.h:64
model_update_comment
int model_update_comment(Bmodel *model, int n, char **strings)
Puts a set of strings and time in the comment of a model.
Definition: rwmodel.cpp:1158
Bpolygon::next
Bpolygon * next
Definition: rwmodel.h:103
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
file_util.h
Header file for file checking functions.
comp_type_list_kill
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
Definition: rwmodel.cpp:926
View::normalize
double normalize()
Definition: View.h:106
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
link_index
int link_index(Bcomponent *comp, Bcomponent *comp2)
Returns the index of a linked component.
Definition: rwmodel.cpp:378
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
Bcomponent::sel
int sel
Definition: rwmodel.h:66
Bcomponent::radius
float radius
Definition: rwmodel.h:62
model
Bmodel * model
Definition: bshow.cpp:32
model_change_type
int model_change_type(Bmodel *model, Bstring &change_type)
Change a component type name.
Definition: rwmodel.cpp:545
Bmodel::fom
float fom
Definition: rwmodel.h:128
Bstring
Definition: Bstring.h:29
poly_list_kill
int poly_list_kill(Bpolygon *poly)
Deallocates memory for a list of polygons.
Definition: rwmodel.cpp:1070
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
read_model_molecule
Bmodel * read_model_molecule(Bstring *file_list, Bstring &paramfile)
Reads molecular model parameters.
Definition: rwmodel_mol.cpp:25
Bcomptype::num
int num
Definition: rwmodel.h:30
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:315
Bcomponent::vec
Vector3< float > vec
Definition: rwmodel.h:60
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
Bpolygon::normal
Vector3< float > normal
Definition: rwmodel.h:106
rwmodel.h
Header file for reading and writing atomic model files.
rwmodel_vega.h
Header file for reading and writing Vega model parameters.
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
model_check
int model_check(Bmodel *model, Bstring path)
Checks model properties.
Definition: rwmodel.cpp:592
model_set_density
long model_set_density(Bmodel *model, double density)
Set the density of selected components to a specific value.
Definition: rwmodel.cpp:1285
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:395
rwmodel_mol.h
Header file for reading and writing molecular model parameters.
command_line_time
Bstring command_line_time(int n, char **strings)
Returns a set of strings and time in a string.
Definition: utilities.cpp:60
model_list_copy
Bmodel * model_list_copy(Bmodel *model)
Copies a model.
Definition: rwmodel.cpp:657
Color.h
Classes for color objects.
component_list_kill
int component_list_kill(Bcomponent *comp)
Deallocates memory for a list of components.
Definition: rwmodel.cpp:891
component_type_add
Bcomptype * component_type_add(Bcomptype **type, Bstring &id)
Adds a component type to a linked list.
Definition: rwmodel.cpp:230
Bmodel
Definition: rwmodel.h:119
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
component_type_copy
int component_type_copy(Bcomptype *fromct, Bcomptype *toct)
Copies all elements from one component to another.
Definition: rwmodel.cpp:763
component_kill
int component_kill(Bcomponent *comp)
Deallocates memory for one component.
Definition: rwmodel.cpp:877
write_model_molecule
int write_model_molecule(Bstring &filename, Bmodel *model)
Writes molecular model parameters.
Definition: rwmodel_mol.cpp:100
component_find
Bcomponent * component_find(Bcomponent *comp, Bstring &id)
Finds a component in a component list.
Definition: rwmodel.cpp:822
Bcomptype
Definition: rwmodel.h:25
model_link_list_kill
int model_link_list_kill(Bmodel *model)
Deallocates memory for a list of component links.
Definition: rwmodel.cpp:950
link_find
Blink * link_find(Blink *link, Bcomponent *comp1, Bcomponent *comp2)
Finds a link in a link list.
Definition: rwmodel.cpp:857
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
read_model_vega
Bmodel * read_model_vega(Bstring *file_list)
Reads Vega model parameters.
Definition: rwmodel_vega.cpp:21
Bstring::empty
bool empty()
Definition: Bstring.h:71
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:465
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
model_set_type
int model_set_type(Bmodel *model, Bstring &set_type)
Reset the component types.
Definition: rwmodel.cpp:516
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bcomptype::fom
float fom
Definition: rwmodel.h:33
Blink::fom
float fom
Definition: rwmodel.h:89
rwmodel_star.h
Header file for reading and writing STAR model parameters.
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:28
model_component_count
int model_component_count(Bmodel *model)
Counts the total number of components.
Definition: rwmodel.cpp:635
Bcomptype::count
int count
Definition: rwmodel.h:31
Bcomponent::color
RGBA< float > color
Definition: rwmodel.h:63
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
link_copy
int link_copy(Blink *fromlink, Blink *tolink)
Copies all elements from one link to another.
Definition: rwmodel.cpp:836
rwmodel_bild.h
Header file for reading and writing Chimera BILD files.
Bcomptype::next
Bcomptype * next
Definition: rwmodel.h:26
Bpolygon::closed
int closed
Definition: rwmodel.h:107
model_get_type
Bcomptype * model_get_type(Bmodel *model, Bstring &id)
Return the type corresponding to an identifier.
Definition: rwmodel.cpp:491
Bcomponent
Definition: rwmodel.h:51