 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
51 cout <<
"DEBUG model_select: selstr=" << selstr << endl;
53 if ( selstr[0] ==
'#' ) {
56 comp_id = selstr.
post(
'@');
59 comp_type_id = selstr.
post(
'%');
63 }
else if ( selstr[0] ==
'^' ) {
65 mod_type_id = selstr.
substr(1, selstr.
index(
'@')-1);
66 comp_id = selstr.
post(
'@');
68 mod_type_id = selstr.
substr(1, selstr.
index(
'%')-1);
69 comp_type_id = selstr.
post(
'%');
73 }
else if ( selstr[0] ==
'@' ) {
75 }
else if ( selstr[0] ==
'%' ) {
80 cout <<
"Selection identifiers:" << endl;
82 cout <<
"Model: " << mod_id << endl;
83 if ( mod_type_id.
length() )
84 cout <<
"Model type: " << mod_type_id << endl;
86 cout <<
"Component: " << comp_id << endl;
87 if ( comp_type_id.
length() )
88 cout <<
"Component type: " << comp_type_id << endl;
92 if ( mod_id ==
"." || mod_type_id ==
"." ) {
96 list = mod_id.
split(
",");
98 for ( one = list; one && mp->
id != *one; one = one->
next ) ;
99 if ( !one ) mp->
sel = 0;
103 if ( mod_type_id.
length() ) {
104 list = mod_type_id.
split(
",");
106 for ( one = list; one && mp->
type_id != *one; one = one->
next ) ;
107 if ( !one ) mp->
sel = 0;
113 if ( comp_type_id ==
"." ) {
115 for ( type = mp->
type; type; type = type->
next ) type->
sel = 1;
116 for ( comp = mp->
comp; comp; comp = comp->
next ) comp->
sel = 1;
118 }
else if ( comp_type_id.
length() ) {
119 list = comp_type_id.
split(
",");
121 for ( type = mp->
type; type; type = type->
next )
if ( type->
sel ) {
122 for ( one = list; one && type->
id != *one; one = one->
next ) ;
123 if ( !one ) type->
sel = 0;
125 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
134 if ( comp_id ==
"." ) {
136 for ( comp = mp->
comp; comp; comp = comp->
next ) comp->
sel = 1;
137 }
else if ( comp_id.
length() ) {
138 list = comp_id.
split(
",");
140 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
141 for ( one = list; one && comp->
id != *one; one = one->
next ) ;
142 if ( !one ) comp->
sel = 0;
149 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) n++;
150 for ( link = mp->
link; link; link = link->
next )
165 long nsel(0), ntot(0);
170 cout <<
"Selecting components with selection number " << number << endl;
173 for ( comp = mp->
comp; comp; comp = comp->
next ) ntot++;
176 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel ) {
177 if ( comp->
sel != number ) comp->
sel = 0;
178 nsel += ( comp->
sel > 0 );
183 cout <<
"Number of components selected: " << nsel <<
" (" << nsel*100.0/ntot <<
" %)" << endl << endl;
198 for ( nsel=0, mp =
model; mp; mp = mp->
next, nsel++ ) mp->
sel = 1;
213 for ( nsel=0, mp =
model; mp; mp = mp->
next ) {
241 cout <<
"Model " <<
model->
id <<
": reset selection" << endl;
292 if ( comp->
sel ) comp->
sel = 0;
314 if ( !
model || size <= 0 )
return 0;
316 long nsel(0), count(0), number(0), ntot(0);
322 cout <<
"Generating sets of " << size <<
" components each" << endl;
324 for ( nsel=0, mp =
model; mp; mp = mp->
next ) {
325 if ( flag && count ) {
329 for ( comp = mp->
comp; comp; comp = comp->
next, ntot++ ) {
330 if ( comp->
sel > 0 ) {
331 if ( count >= size ) {
335 if ( number < 1 ) number = 1;
344 cout <<
"Number of sets generated: " << number << endl;
345 cout <<
"Number of components selected: " << nsel <<
" (" << nsel*100.0/ntot <<
" %)" << endl << endl;
361 if ( ncomp_min < 1 )
return 0;
362 if ( ncomp_min > ncomp_max ) ncomp_max = ncomp_min;
369 for ( n=0, comp = mp->
comp; comp; comp = comp->
next ) n++;
370 if ( n >= ncomp_min && n <= ncomp_max ) {
377 cout <<
"Models with " << ncomp_min <<
" to " << ncomp_max <<
" components selected: " << nsel << endl << endl;
407 cout <<
"Selecting models based on fixed ";
408 if ( closure_rule == 1 ) cout <<
"valency of " << val_order << endl << endl;
409 else cout <<
"polygon order of " << val_order << endl << endl;
414 if ( closure_rule == 1 ) {
415 for ( comp = mp->
comp; comp && mp->
sel; comp = comp->
next ) {
418 if ( i != val_order ) mp->
sel = 0;
423 }
else if ( closure_rule == 2 ) {
424 for ( poly = mp->
poly; poly && mp->
sel; poly = poly->
next ) {
427 if ( i != val_order ) mp->
sel = 0;
457 cout <<
"Selecting fullerene models" << endl << endl;
460 for ( poly = mp->
poly; poly && mp->
sel; poly = poly->
next )
486 cout <<
"Selecting non-fullerene models" << endl << endl;
490 for ( poly = mp->
poly; poly && mp->
sel == 0; poly = poly->
next )
515 cout <<
"Selecting components with valency " << valence << endl << endl;
518 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
521 if ( v == valence ) comp->
sel = 1;
537 if ( order < 1 )
return 0;
547 cout <<
"Selecting polygons with order " << order << endl << endl;
550 for ( comp = mp->
comp; comp; comp = comp->
next ) comp->
sel = 0;
551 for ( poly = mp->
poly; poly; poly = poly->
next )
if ( poly->
number == order ) {
572 for ( n=0, mp =
model; mp; mp = mp->
next ) {
573 for ( comp = mp->
comp; comp; comp = comp->
next, n++ ) {
574 if ( comp->
sel > 0 && n < first ) {
577 }
else comp->
sel = 0;
592 long nsel(0), ntot(0);
598 cout <<
"Deselecting components outside mask " << pmask->
file_name() << endl;
600 for ( ntot=0, mp =
model; mp; mp = mp->
next ) {
601 for ( comp = mp->
comp; comp; comp = comp->
next, ntot++ ) {
604 if ( pmask->
get(0, loc) < 0.5 ) comp->
sel = 0;
605 else nsel += (comp->
sel > 0);
610 cout <<
"Number of components selected: " << nsel <<
" (" << nsel*100.0/ntot <<
" %)" << endl << endl;
625 long nmod(0), ncomp(0), nlink(0), nmdel(0), ncdel(0), nldel(0);
634 cout <<
"Deleting models and model elements" << endl << endl;
636 for ( mp = mp_prev = *
model; mp; ) {
640 if ( mp == *
model ) {
662 for ( link = link_prev = mp->
link; link; ) {
664 if ( link == mp->
link ) {
667 link = link_prev->
next;
671 link = link_prev->
next;
680 for ( comp = comp_prev = mp->
comp; comp; ) {
681 if ( comp->
sel < 0 ) {
682 if ( comp == mp->
comp ) {
689 comp = comp_prev->
next;
705 if ( nmod ) cout <<
"Number of models deleted: " << nmdel <<
" (" << nmdel*100.0/nmod <<
" %)" << endl;
706 if ( ncomp ) cout <<
"Number of components deleted: " << ncdel <<
" (" << ncdel*100.0/ncomp <<
" %)" << endl;
707 if ( nlink ) cout <<
"Number of links deleted: " << nldel <<
" (" << nldel*100.0/nlink <<
" %)" << endl;
711 return ncomp - ncdel;
730 for ( link = mp->
link; link; ) {
736 for ( comp = comp_prev = mp->
comp; comp; ) {
737 if ( comp->
type == ct ) {
738 if ( comp == mp->
comp ) {
745 comp = comp_prev->
next;
753 for ( ct = ctp = mp->
type; ct; ) {
755 cout <<
"DEBUG model_delete_comp_type: type=" << ct->
id << endl;
756 if ( ct->
id == comptype ) {
757 if ( ct == mp->
type ) {
783 long nmod(0), ncomp(0), nlink(0), nmdel(0), ncdel(0), nldel(0);
792 cout <<
"Deleting non-selected components" << endl;
794 for ( mp = mp_prev = *
model; mp; ) {
796 cout <<
"Model: " << mp->
id << endl;
798 if ( mp == *
model ) {
811 for ( link = link_prev = mp->
link; link; ) {
814 if ( link_prev == link ) mp->
link = link;
822 for ( comp = comp_prev = mp->
comp; comp; ) {
823 if ( comp->
sel < 1 ) {
824 if ( comp == mp->
comp ) {
831 comp = comp_prev->
next;
853 if ( nmod ) cout <<
"Number of models deleted: " << nmdel <<
" (" << nmdel*100.0/nmod <<
" %)" << endl;
854 if ( ncomp ) cout <<
"Number of components deleted: " << ncdel <<
" (" << ncdel*100.0/ncomp <<
" %)" << endl;
855 if ( nlink ) cout <<
"Number of links deleted: " << nldel <<
" (" << nldel*100.0/nlink <<
" %)" << endl;
859 return ncomp - ncdel;
873 cout <<
"DEBUG model_selection_stats: " <<
model->
id << endl;
876 long nmod(0), ncomp(0), nlink(0), npoly(0);
877 long nmods(0), ncomps(0), nlinks(0), npolys(0);
878 long n, nmt(0), nct(0), nv[1000];
880 double fomavg(0), fomstd(0), fmin(1e30), fmax(-1e30);
881 Vector3<double> cmin(1e10, 1e10, 1e10), cmax(-1e10, -1e10, -1e10), com;
895 for ( i=0; i<
MAXLINK; i++ ) val[i] = 0;
896 for ( i=0; i<1000; i++ ) nv[i] = 0;
898 for ( mp =
model; mp; mp = mp->
next, nmod++ ) {
899 for ( comp = mp->
comp; comp; comp = comp->
next ) ncomp++;
900 for ( link = mp->
link; link; link = link->
next ) nlink++;
901 for ( poly = mp->
poly; poly; poly = poly->
next ) npoly++;
905 cout <<
"DEBUG model_selection_stats: nmod=" << nmod <<
" ncomp=" << ncomp
906 <<
" nlink=" << nlink <<
" npoly=" << npoly << endl;
912 for ( temptype = modtypelist; temptype && *temptype != mp->
type_id; temptype = temptype->
next ) ;
915 if ( !modtypelist ) modtypelist = modtype;
918 for ( type = mp->
type; type; type = type->
next ) {
919 for ( temptype = comptypelist; temptype && *temptype != type->
id; temptype = temptype->
next ) ;
922 if ( !comptypelist ) comptypelist = comptype;
924 if ( !typefilelist ) typefilelist = typefile;
931 cout <<
"DEBUG model_selection_stats: nmods=" << nmods <<
" nmt=" << nmt <<
" nct=" << nct << endl;
934 cerr <<
"No models selected!" << endl << endl;
938 if ( nmt < 3 ) nmt = 3;
939 if ( nct < 1 ) nct = 1;
943 if ( comptypelist )
string_sort(comptypelist, 0, 1);
946 for ( temptype = comptypelist, typefile = typefilelist; temptype && typefile; temptype = temptype->
next, typefile = typefile->
next ) {
948 for ( type = mp->
type; type && *temptype != type->
id; type = type->
next ) ;
949 if ( type ) *typefile = type->
fmod;
953 int* nvert =
new int[nmt];
954 int* nmodtype =
new int[nmt];
955 double* modfom =
new double[nmt];
956 int* ncomptype =
new int[nct];
957 double* compfom =
new double[nct];
959 for ( i=0; i<nmt; i++ ) modfom[i] = nvert[i] = nmodtype[i] = 0;
960 for ( i=0; i<nct; i++ ) compfom[i] = ncomptype[i] = 0;
964 cout <<
"DEBUG model_selection_stats: model id=" << mp->
id << endl;
965 for ( n=0, comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) n++;
966 if ( n < 1000 ) nv[n]++;
967 for ( i=0, temptype = modtypelist; temptype && *temptype != mp->
type_id; temptype = temptype->
next, i+=3 ) ;
972 modfom[i] += mp->
fom;
974 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
976 cout <<
"DEBUG model_selection_stats: component id=" << comp->
id <<
" ncomps=" << ncomps << endl;
977 for ( i=0, temptype = comptypelist; temptype && *temptype != comp->
type->
id; temptype = temptype->
next, i++ ) ;
980 compfom[i] += comp->
fom;
983 cmin = cmin.
min(comp->
loc);
984 cmax = cmax.max(comp->
loc);
985 if ( fmin > comp->
fom ) fmin = comp->
fom;
986 if ( fmax < comp->fom ) fmax = comp->
fom;
988 fomstd += comp->
fom*comp->
fom;
993 for ( link = mp->
link; link; link = link->
next )
994 if ( link->
sel ) nlinks++;
995 for ( poly = mp->
poly; poly; poly = poly->
next )
996 if ( poly->
sel ) npolys++;
1002 fomstd = fomstd/ncomps - fomavg*fomavg;
1003 if ( fomstd > 0 ) fomstd = sqrt(fomstd);
1008 cout <<
"Models: " << nmod <<
" (" << nmods <<
")" << endl;
1009 cout <<
"Components: " << ncomp <<
" (" << ncomps <<
")" << endl;
1010 cout <<
"Links: " << nlink <<
" (" << nlinks <<
")" << endl;
1011 cout <<
"Polygons: " << npoly <<
" (" << npolys <<
")" << endl << endl;
1013 cout <<
"Center-of-mass: " << com << endl;
1014 cout <<
"Coordinate minima: " << cmin << endl;
1015 cout <<
"Coordinate maxima: " << cmax << endl;
1016 cout <<
"Selected FOM minimum & maximum: " << fmin <<
" " << fmax << endl;
1017 cout <<
"Selected FOM average & stdev: " << fomavg <<
" " << fomstd << endl << endl;
1019 cout <<
"Model sizes:\nVert\tCount" << endl;
1020 for ( i=n=0; i<1000; i++ )
if ( nv[i] ) {
1021 cout << i <<
tab << nv[i] << endl;
1024 cout <<
"Total\t" << n << endl << endl;
1025 cout <<
"Model types:\nType\tVert\tHand\tCount\tFOM" << endl;
1026 for ( i=0, modtype = modtypelist; i<nmt && modtype; modtype = modtype->
next, i+=3 )
1027 for ( h=i; h<i+3; h++ )
1028 if ( nmodtype[h] ) cout << *modtype <<
tab << nvert[h] <<
tab
1029 << h%3 - 1 <<
tab << nmodtype[h] <<
tab << modfom[h]/nmodtype[h] << endl;
1031 cout <<
"Component types:\nType\tHand\tCount\tFOM\tFile" << endl;
1032 for ( i=0, comptype = comptypelist, typefile = typefilelist;
1033 i<nct && comptype && typefile; comptype = comptype->
next, typefile = typefile->
next, i++ ) {
1034 if ( ncomptype[i] ) compfom[i] /= ncomptype[i];
1036 ncomptype[i] <<
tab << compfom[i] <<
tab << *typefile << endl;
1039 cout <<
"Valence\tCount" << endl;
1040 for ( i=0; i<
MAXLINK; i++ )
if ( val[i] ) cout << i <<
tab << val[i] << endl;
1065 long i, nname, nselnum, ntype;
1073 for ( nname = 0, ct_name = comp_type; ct_name; ct_name = ct_name->
next )
1074 if ( ct_name->
length() > 0 ) nname++;
1076 for ( ntype = 0, mp =
model; mp; mp = mp->
next ) {
1077 for ( i=0, ct = mp->
type; ct; ct = ct->
next ) i++;
1078 if ( ntype < i ) ntype = i;
1081 for ( nselnum = 0, mp =
model; mp; mp = mp->
next )
1082 for ( comp = mp->
comp; comp; comp = comp->
next )
1083 if ( nselnum < comp->sel ) nselnum = comp->
sel;
1086 cout <<
"Creating %d component types" << nselnum << endl << endl;
1088 if ( ntype != nselnum ) {
1089 if ( nname == nselnum ) {
1094 cout <<
"Model: " << mp->
id << endl;
1095 for ( i=0, ct_name = comp_type; i<nselnum && ct_name; i++, ct_name = ct_name->
next ) {
1101 cout <<
"\tType: " << ct->
id << endl;
1105 if ( comp_type && comp_type->
length() )
base = *comp_type;
1110 cout <<
"Model: " << mp->
id << endl;
1111 for ( i=0; i<nselnum; i++ ) {
1118 cout <<
"\tType: " << ct->
id << endl;
1122 }
else if ( nname == ntype ) {
1124 for ( ct = mp->
type, ct_name = comp_type; ct && ct_name; ct = ct->
next, ct_name = ct_name->
next )
1129 for ( i=0, ct = mp->
type; ct; ct = ct->
next, i++ ) {
1130 ct->
fmod = filename;
1135 for ( comp = mp->
comp; comp; comp = comp->
next ) {
1136 for ( i=1, ct = mp->
type; i<nselnum && i<comp->sel && ct; i++, ct = ct->
next ) ;
1137 if ( ct ) comp->
type = ct;
1160 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1161 for ( comp = mp->
comp; comp; comp = comp->
next ) {
1162 if ( comp->
fom < fom_cutoff ) comp->
sel = 0;
1163 if ( comp->
sel > 0 ) nsel++;
1182 if ( fom_fraction > 1 ) fom_fraction = 0.5;
1185 double fom_max = 1e-6, fom_cut;
1189 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel )
1190 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 )
1191 if ( fom_max < comp->fom ) fom_max = comp->
fom;
1193 fom_cut = fom_fraction*fom_max;
1195 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1196 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1197 if ( comp->
fom < fom_cut ) comp->
sel = 0;
1198 if ( comp->
sel > 0 ) nsel++;
1217 if ( maxrad < 1e-3 ) maxrad = 1e30;
1219 long nsel(0), ntot(0);
1225 cout <<
"Deselecting components outside " << minrad <<
" - " << maxrad <<
" A" << endl;
1227 for ( ntot=0, mp =
model; mp; mp = mp->
next )
1228 for ( comp = mp->
comp; comp; comp = comp->
next ) ntot++;
1230 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1231 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1233 if ( len < minrad || len > maxrad ) comp->
sel = -1;
1234 if ( comp->
sel > 0 ) nsel++;
1239 cout <<
"Number of components selected: " << nsel <<
" (" << nsel*100.0/ntot <<
" %)" << endl << endl;
1256 if ( fom_step < 0.001 ) fom_step = 0.001;
1259 double fmin = 1e30, fmax = -1e30, pc;
1263 for ( n=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1264 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1265 if ( comp->
fom < fmin ) fmin = comp->
fom;
1266 if ( comp->
fom > fmax ) fmax = comp->
fom;
1271 int i, sum, nhc(0), nh = (int) ((fmax - fmin)/fom_step + 1);
1272 int* hist =
new int[nh];
1273 for ( i=0; i<nh; i++ ) hist[i] = 0;
1276 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1277 i = (int) ((comp->
fom - fmin)/fom_step);
1278 if ( i >= 0 && i < nh ) {
1285 cout <<
"FOM histogram:\nBin\tValue\tCount\tSum\t%" << endl;
1286 for ( i=0, sum=0; i<nh; i++ ) {
1289 cout << i <<
tab << (i+0.5)*fom_step + fmin <<
tab << hist[i] <<
tab << sum <<
tab << pc << endl;
1309 if ( nrank < 2 ) nrank = 2;
1318 cout <<
"Ranking selection into %d levels" << nrank << endl << endl;
1322 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel )
1323 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) nsel++;
1327 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1328 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1329 rank[nsel].
i = nsel;
1330 rank[nsel].
f = comp->
fom;
1335 qsort((
void *) rank, nsel,
sizeof(
int_float),
1338 int* sel =
new int[nsel];
1339 for ( i=0; i<nsel; i++ ) sel[i] = 0;
1341 for ( i=0; i<nsel; i++ ) {
1342 n = nrank - (i*nrank)/nsel;
1346 for ( nsel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1348 cout <<
"DEBUG model_fom_ranking: model=" << mp->
id <<
" map=" << mp->
fmap << endl;
1349 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1350 comp->
sel = sel[nsel];
1360 for ( ct = ctp = mp->
type; ct; ) {
1362 cout <<
"DEBUG model_fom_ranking: type=" << ct->
id <<
" num=" << ct->
count << endl;
1363 if ( ct->
count < 1 ) {
1364 if ( ct == mp->
type ) {
1401 for ( mp = *
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1402 for ( comp1 = mp->
comp; comp1->
next; comp1 = comp1->
next )
if ( comp1->
sel ) {
1403 for ( comp2 = comp1->
next; comp2; comp2 = comp2->
next )
if ( comp2->
sel ) {
1430 cout <<
"Consolidating components:" << endl;
1431 cout <<
"Distance criterion: " <<
distance << endl;
1432 cout <<
"Number of components: " << dm.
rows() << endl << endl;
1439 for ( i=0, comp =
model->
comp; comp; comp = comp->
next, i++ )
if ( comp->
sel ) {
1441 for ( j=0, comp2 =
model->
comp; comp2; comp2 = comp2->
next, j++ )
if ( i != j ) {
1470 long n, ns, ndel(0);
1475 for ( n=ns=0, comp =
model->
comp; comp; comp = comp->
next, n++ )
if ( comp->
sel > 0 ) ns++;
1478 cout <<
"Pruning a set of solutions based on distance:" << endl;
1479 cout <<
"Number of components: " << n << endl;
1480 cout <<
"Number selected: " << ns << endl;
1481 cout <<
"Overlap distance: " << mindist << endl << endl;
1484 for ( ndel=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
1485 for ( comp = mp->
comp; comp->
next; comp = comp->
next )
if ( comp->
sel > 0 ) {
1486 for ( comp2 = comp->
next; comp2; comp2 = comp2->
next )
if ( comp2->
sel > 0 ) {
1496 cout <<
"Number of components deleted: " << ndel <<
" (" << ndel*100.0/n <<
" %)" << endl;
1520 int h, i, j, k, n, ns, nsel, imax;
1521 double fom_max, fom;
1525 for ( n=ns=0, comp =
model->
comp; comp; comp = comp->
next, n++ )
if ( comp->
sel > 0 ) ns++;
1528 cout <<
"Pruning a set of solutions based on distance and FOM:" << endl;
1529 cout <<
"Number of components: " << n << endl;
1530 cout <<
"Number selected: " << ns << endl;
1531 cout <<
"Overlap distance: " <<
distance << endl << endl;
1534 int* sol =
new int[ns];
1535 char* a =
new char[ns*ns];
1536 double* f =
new double[ns];
1538 for ( i=0; i<ns; i++ ) f[i] = sol[i] = 0;
1539 for ( i=0; i<ns*ns; i++ ) a[i] = 0;
1542 for ( i=k=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1543 for ( comp2 =
model->
comp; comp2; comp2 = comp2->
next )
if ( comp2->
sel > 0 ) {
1544 if ( comp != comp2 )
1553 for ( h=0, imax = 0; h<ns && imax > -1; h++ ) {
1554 for ( i=0, imax = -1, fom_max = -1; i<ns; i++ ) {
1555 if ( fom_max < f[i] ) {
1564 for ( j=0; j<ns; j++ )
if ( a[i+j] ) {
1571 for ( i=nsel=0, fom=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1572 comp->
sel = sol[i++];
1573 if ( comp->
sel > 0 ) {
1579 if ( nsel ) fom /= nsel;
1582 cout <<
"Components selected:" << endl;
1583 cout <<
"ID\tType\tFOM\tDist" << endl;
1586 cout <<
"Number selected: " << nsel <<
" (" << nsel*100.0/n <<
" )" << endl;
1587 cout <<
"Average FOM: " << fom << endl << endl;
1612 long i, j, n, ns, c(0);
1619 for ( n=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1626 for ( j=i+1, comp1 = comp->
next; comp1; comp1 = comp1->
next )
if ( comp1->
sel > 0 ) {
1627 if ( dmat[i][j] < 0.1 ) {
1628 if ( comp->
sel < 1 ) comp->
sel = ++c;
1637 cout <<
"Number of clusters: " << c << endl;
1638 cout <<
"Averaging similar components:" << endl << endl;
1642 if ( ns < comp->sel ) ns = comp->
sel;
1644 for ( i=1; i<=ns; i++ ) {
1645 for ( n=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel == i ) {
1661 comp1->
view[0] /= n;
1662 comp1->
view[1] /= n;
1663 comp1->
view[2] /= n;
1664 comp1->
view[3] /= n;
1678 if ( sampling[0] <= 0) sampling = sampling.
max(1);
1687 if ( origin[0] == 0 && origin[1] == 0 && origin[2] == 0 )
1688 origin = p->
size()/2;
1695 cout <<
"Assembling a model map:" << endl;
1696 cout <<
"Size: " << p->
size() << endl;
1698 cout <<
"Sampling: " << p->
sampling(0) <<
" A/voxel" << endl;
1702 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
1711 for ( i=0, v=t=0; i<datasize; i++ ) {
1712 if ( (*p)[i] > 0.5 ) v += 1;
1717 cout <<
"Assembled map volume: " << v * sampling.
volume() <<
" A3" << endl;
1718 cout <<
"Assembled map integral: " << t * sampling.
volume() << endl;
1719 cout <<
"Integral volume ratio: " << t/v << endl << endl;
1732 for ( j=i+1, k=i*n+j, comp = comp->
next; j<n && comp; j++, k++, comp = comp->next )
if ( comp->
sel > 0 ) {
1733 if ( ovm[k] > 0 ) comp->
sel = 0;
1737 for ( j=0; comp2; j++, comp2 = comp2->
next ) cout <<
" " << j+1 <<
":" << comp2->sel;
1755 for ( n=0, comp = mp->
comp; comp; comp = comp->
next ) n++;
1758 cout <<
"Calculating an overlap matrix:" << endl;
1759 cout <<
"Distance criterion: " <<
distance << endl;
1760 cout <<
"Number of components: " << n << endl << endl;
1763 double* ovm =
new double[n*n];
1764 for ( i=0; i<n*n; i++ ) ovm[i] = 0;
1768 for ( i=0, comp = mp->
comp; comp->
next; comp = comp->
next, i++ ) {
1769 for ( j=i+1, comp2 = comp->
next; comp2; comp2 = comp2->
next, j++ ) {
1772 ovm[i*n+j] = ovm[j*n+i] = 1 - (d/4)*(3-d*d/4);
1778 for ( i=0; i<n; i++ ) {
1779 for ( j=0; j<n; j++ )
1780 cout <<
tab << ovm[i*n+j];
1807 long n, ns, nsel(0);
1814 for ( n=ns=0, comp =
model->
comp; comp; comp = comp->
next, n++ )
if ( comp->
sel > 0 ) {
1816 min = min.
min(comp->
loc);
1817 max = max.
max(comp->
loc);
1821 max = max.
max(-min);
1825 Vector3<int> size((
int) (2*max[0]), (
int) (2*max[1]), (
int) (2*max[2]));
1940 long i, ii, x, y, z, xx, yy, zz, imax, n, ng, np, nsel, vol;
1947 for ( n=nsel=0, comp =
model->
comp; comp; comp = comp->
next, n++ )
if ( comp->
sel > 0 ) nsel++;
1950 cout <<
"Pruning a set of solutions based on grid sampling and FOM:" << endl;
1951 cout <<
"Number of components: " << n << endl;
1952 cout <<
"Number selected: " << nsel << endl;
1953 cout <<
"Grid sampling: " << sampling << endl;
1957 min = min.
min(comp->
loc);
1958 max = max.
max(comp->
loc);
1962 for ( i=0; i<3; i++ ) size[i] = (
int) ((max[i] - min[i])/sampling);
1963 vol = (long) size.
volume();
1965 double* grid =
new double[vol];
1966 double* peak =
new double[vol];
1967 for ( i=0; i<vol; i++ ) grid[i] = peak[i] = 0;
1970 cout <<
"Grid volume: " << vol << endl << endl;
1974 x = (long) ((comp->
loc[0] - min[0])/sampling);
1975 y = (long) ((comp->
loc[1] - min[1])/sampling);
1976 z = (long) ((comp->
loc[2] - min[2])/sampling);
1977 i = (z*size[1] + y)*size[0] + x;
1978 if ( i >= vol ) cerr <<
"Volume exceeded: " << i << endl;
1979 if ( grid[i] < comp->
fom ) grid[i] = comp->
fom;
1983 cout <<
"Find peaks in grid" << endl;
1986 for ( ng=np=0, z=1; z<size[2]-1; z++ ) {
1987 for ( y=1; y<size[1]-1; y++ ) {
1988 for ( x=1; x<size[0]-1; x++ ) {
1989 i = (z*size[1] + y)*size[0] + x;
1990 if ( grid[i] > 0 ) {
1993 for ( zz=z-1; zz<=z+1; zz++ ) {
1994 for ( yy=y-1; yy<=y+1; yy++ ) {
1995 for ( xx=x-1; xx<=x+1; xx++ ) {
1996 ii = (zz*size[1] + yy)*size[0] + xx;
1997 if ( dmax < grid[ii] ) {
2015 cout <<
"Find components associated with peaks" << endl;
2018 for ( nsel=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
2019 x = (long) ((comp->
loc[0] - min[0])/sampling);
2020 y = (long) ((comp->
loc[1] - min[1])/sampling);
2021 z = (long) ((comp->
loc[2] - min[2])/sampling);
2022 i = (z*size[1] + y)*size[0] + x;
2023 if ( i >= vol ) cerr <<
"Volume exceeded: " << i << endl;
2025 if ( peak[i] > 0 )
if ( fabs(peak[i] - comp->
fom) < 1e-10 ) {
2032 cout <<
"Points placed on grid: " << ng << endl;
2033 cout <<
"Peaks: " << np << endl;
2034 cout <<
"Components selected: " << nsel << endl << endl;
2067 cout <<
"Deselecting components:" << endl;
2068 cout <<
"Reference model: " << reffile << endl;
2069 cout <<
"Distance criterion: " <<
distance << endl;
2073 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel > 0 ) {
2074 for ( mpr = modref; mpr && comp->
sel; mpr = mpr->
next ) {
2075 for ( compr = mpr->
comp; compr && comp->
sel; compr = compr->
next ) {
2079 if ( comp->
sel > 0 ) nsel++;
2086 cout <<
"Number of components retained: " << nsel << endl << endl;
Header file for utility functions for use in qsort calls.
long model_select_polygons(Bmodel *model, int order)
Selects model polygons with a given order.
int comp_type_kill(Bcomptype *type)
Deallocates memory for one component type.
long model_select_valence(Bmodel *model, int valence)
Selects fullerene type models.
Bimage * model_composite_map(Bmodel *model, Vector3< int > size, Vector3< double > origin, Vector3< double > sampling)
long model_prune_simple(Bmodel *model, double mindist)
Prunes overlapping components based on a distance criterion.
long model_fom_histogram(Bmodel *model, double fom_step)
Selects components based on the FOM.
long model_selection_stats(Bmodel *model)
Calculates selection statistics.
int string_kill(Bstring *list)
Kills a string linked list.
long model_prune_fom(Bmodel *model, double distance)
Deselects components based on overlap distance and the FOM.
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
Header file for reading and writing atomic model files.
long model_reset_selection(Bmodel *model)
Resets the selection to all components.
int model_count_component_types(Bmodel *model)
Counts the number of components for each type.
string base(string &filename)
long model_find_overlap(Bmodel *model, Bstring &reffile, double distance)
Finds the components that overlap with the reference.
double * model_overlap_matrix(Bmodel *model, double distance)
long model_delete_overlapped_components(Bmodel **model, double distance)
Deletes components that are too close to others.
Vector3< long > size() const
long model_select(Bmodel *model, Bstring &selstr)
Selects models, components and component types.
long model_prune_fit(Bmodel *model, double distance)
Deselects components based on overlap distance and the FOM.
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
Functions to compare models and components.
long model_select_first(Bmodel *model, int first)
Selects the first number of components.
long models_radius_deselect(Bmodel *model, double minrad, double maxrad)
Deselects components based on the distance from the origin.
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
long model_average_overlapped_components(Bmodel *model, double distance)
Averages components within a distance.
double distance(const Vector3 &v)
long model_select_number_of_components(Bmodel *model, int ncomp_min, int ncomp_max)
Selects models within a range of the number of components.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
long model_select_non_fullerene(Bmodel *model)
Selects non-fullerene type models.
int component_hand(Bstring &s)
Determines the hand of a component.
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.
long model_prune_large(Bmodel *model, double sampling)
Deselects components based on overlap distance and the FOM.
long model_fom_deselect(Bmodel *model, double fom_cutoff)
Deselects components based on the FOM.
int model_kill(Bmodel *model)
Deallocates all memory in the list.
General image parameter class.
long model_select_sets(Bmodel *model, int size, int flag)
Selects sets of components, each set with the same size.
long model_select_all(Bmodel *model)
Resets the selection to all models.
Bcomptype * model_get_type(Bmodel *model, Bstring &id)
Return the type corresponding to an identifier.
char * remove_item(char **list, char *item, unsigned long size)
Finds the given item and deletes it from the linked list.
long model_delete_comp_type(Bmodel *model, Bstring &comptype)
Deletes components based on their types.
double distance(vector< T1 > &v1, vector< T2 > &v2)
long model_fom_max_fraction_deselect(Bmodel *model, double fom_fraction)
Deselects components based on the FOM relative to the maximum FOM.
long model_select_fullerene(Bmodel *model)
Selects fullerene type models.
int component_kill(Bcomponent *comp)
Deallocates memory for one component.
long model_select_in_mask(Bmodel *model, Bimage *pmask)
Selects components within a mask.
Header file for general utilities.
long model_delete_non_selected(Bmodel **model)
Deletes selected components and associated links from the model.
ostream & tab(ostream &out)
Bstring substr(long start, long len)
long model_select_closed(Bmodel *model, int closure_rule, int val_order)
Determines if a polyhedron is closed given a rule.
Bcomponent * comp[MAXLINK]
long comp_select_one(Bcomponent *comp, long i, long n, double *ovm)
Library routines used for analysing model component views.
void origin(double ox, double oy, double oz)
Matrix model_distance_matrix(Bmodel *model, int view_flag)
Calculates the distance matrix for a model.
long model_unset_selection(Bmodel *model)
Unsets the selection to all components but not models.
Header file for 2D and 3D image I/O.
long model_type_from_selection(Bmodel *model, Bstring *comp_type, Bstring &filename)
Converts selection numbers to different types.
Header file for generalized linked list functions.
Functions to manipulate polyhedral coordinate files.
long model_select_unknowns(Bmodel *model)
Resets the selection to all unknown models.
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Library routines used for model processing.
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Bmodel * read_model(Bstring &filename)
long model_prune_similar(Bmodel *model)
Averages similar components and reduces redundancy.
void sampling(long nn, Vector3< double > u)
int QsortLargeToSmallIntFloat(const void *x, const void *y)
Utility function for sorting int float pairs in qsort.
int string_sort(Bstring *slist, int descending, int value)
Sorts a list of strings in ascending (descending) lexical or value order.
bool contains(const Bstring &s)
long model_delete(Bmodel **model)
Deletes tagged models, components and links.
long model_invert_selection(Bmodel *model)
Inverts the selection of all components.
Bcomponent * link[MAXLINK]
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
long model_fom_ranking(Bmodel *model, int nrank)
Ranks components based on the FOM.
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.