34 if ( !
model )
return NULL;
40 if ( mp->
id ==
id )
break;
41 if ( !mp ) mp =
model;
54 for ( n=0, comp = mp->
comp; comp; comp = comp->
next ) n++;
101 model->
id =
"Truncated octahedron";
113 model->
id =
"Truncated icosahedron";
125 cerr <<
"Error: Symmetry " << sym->
label <<
" not supported!" << endl;
131 cout <<
"Generating a " <<
model->
id <<
":" << endl;
133 cout <<
"Radius: " << radius << endl << endl;
156 double start = -(ncomp/2.0 - 0.5)*helix_rise;
166 comp->
loc[0] = radius;
167 comp->
loc[2] = start;
171 cout <<
"Generating a " <<
model->
id <<
":" << endl;
172 cout <<
"Radius: " << radius << endl;
173 cout <<
"Helical rise and rotation: " << helix_rise <<
" " << helix_angle*180.0/
M_PI << endl;
174 cout <<
"Number of components: " << ncomp << endl << endl;
177 for ( i=1; i<ncomp; i++ ) {
181 comp->
loc[0] = radius*cos(i*helix_angle);
182 comp->
loc[1] = radius*sin(i*helix_angle);
183 comp->
loc[2] = start + i*helix_rise;
204 double R = ncomp * pow(comp_radius/max_radius, 3);
207 cout <<
"Generating a random model: " <<
id << endl;
208 cout <<
"Number of components: " << ncomp << endl;
209 cout <<
"Component radius: " << comp_radius << endl;
210 cout <<
"Maximum model radius: " << max_radius << endl;
211 cout <<
"Packing density: " << R << endl << endl;
215 cerr <<
"Error: The packing density is too high!" << endl << endl;
222 double inner_radius(max_radius - comp_radius);
230 for ( i=1; i<=ncomp; i++ ) {
235 for ( d = 0; d < 2*comp_radius; ) {
237 for ( d = 4*comp_radius, comp2 =
model->
comp;
238 comp2 != comp && d >= 2*comp_radius; comp2 = comp2->
next )
242 comp->
radius = comp_radius;
265 double R(ncomp * (4.0*
M_PI/3.0)*comp_radius*comp_radius*comp_radius/(max - min).
volume());
268 cout <<
"Generating a random model: " <<
id << endl;
269 cout <<
"Number of components: " << ncomp << endl;
270 cout <<
"Component radius: " << comp_radius << endl;
271 cout <<
"Minimum coordinates: " << cmin << endl;
272 cout <<
"Maximum coordinates: " << cmax << endl;
273 cout <<
"Packing density: " << R << endl << endl;
277 cerr <<
"Error: The packing density is too high!" << endl << endl;
291 for ( i=1; i<=ncomp; i++ ) {
296 for ( d = 0; d < 2*comp_radius; ) {
298 for ( d = 4*comp_radius, comp2 =
model->
comp;
299 comp2 != comp && d >= 2*comp_radius; comp2 = comp2->
next )
303 comp->
radius = comp_radius;
323 cout <<
"Generating a random gaussian model: " <<
id << endl;
324 cout <<
"Number of components: " << ncomp << endl;
335 for ( i=1; i<=ncomp; i++ ) {
347 cout <<
"Radius of gyration: " << R <<
" A" << endl << endl;
366 cout <<
"Generating a random shell model: " <<
id << endl;
367 cout <<
"Number of components: " << ncomp << endl;
368 cout <<
"Radius: " << radius << endl;
379 for ( i=1; i<=ncomp; i++ ) {
392 cout <<
"Radius of gyration: " << R <<
" A" << endl << endl;
420 cout <<
"Generating a random shell model: " <<
id << endl;
421 cout <<
"Number of components: " << ncomp << endl;
422 cout <<
"Radius: " << radius << endl;
423 cout <<
"Separation: " << separation << endl;
429 double d, pd(ncomp*separation*separation/(radius*radius));
431 if ( pd > 8 ) ncomp = 8*radius*radius/(separation*separation);
439 for ( i=1; i<=ncomp; i++ ) {
444 comp->
radius = separation/10;
445 for ( d = 0; d < separation; ) {
448 for ( d = 2*separation, comp2 =
model->
comp;
449 comp2 != comp && d >= separation; comp2 = comp2->
next )
478 if ( radius <= 0 ) flag = 1;
480 if ( number <= 0 )
distance = radius/10;
491 long i(number), n, t;
493 double theta_step, theta, phi, phi_step, rad_sin_theta;
501 if ( flag == 1 ) radius =
distance*sqrt(number/12.5L);
502 else distance = radius/sqrt(number/12.5L);
503 for ( t=i=0; t<1000 && i != number; t++ ) {
504 theta_step = sqrt(3.0/4.0)*
distance/radius;
505 for ( i=0, theta = 0; theta <=
M_PI; theta += theta_step ) {
506 rad_sin_theta = radius*sin(theta);
508 phi_step = 1.5*
TWOPI;
509 if ( theta > 0 && theta <
TWOPI )
510 phi_step =
TWOPI*1.0L/n;
511 for ( phi = 0; phi <
TWOPI - phi_step/2; phi += phi_step, i++ ) ;
515 if ( flag == 1 ) radius *= 1 + (number - i)*rn/number;
516 else distance *= 1 + (i - number)*rn/number;
521 theta_step = sqrt(3.0/4.0)*
distance/radius;
523 double cr(radius/sqrt(number));
526 cout <<
"DEBUG model_create_shell: number=" << number <<
" distance=" <<
527 distance <<
" radius=" << radius <<
" theta_step=" << theta_step << endl;
529 for ( i=0, theta = 0; theta <=
M_PI; theta += theta_step ) {
530 z = radius*cos(theta);
531 rad_sin_theta = radius*sin(theta);
533 phi_step = 1.5*
TWOPI;
534 if ( theta > 0 && theta <
TWOPI )
535 phi_step =
TWOPI*1.0L/n;
536 for ( phi = 0; phi <
TWOPI - phi_step/2; phi += phi_step ) {
537 x = cos(phi)*rad_sin_theta;
538 y = sin(phi)*rad_sin_theta;
551 cout <<
"Generating a sphere:" << endl;
552 cout <<
"Number of components: " << i << endl;
553 cout <<
"Separation distance: " <<
distance << endl;
554 cout <<
"Radius: " << radius << endl << endl;
571 if ( radius <= 0 ) radius = 1;
572 if ( number <= 0 ) number = 20;
582 double x, y, z, st, phi;
583 double ga(4*
M_PI/(sqrt(5.0)+1.0));
584 double cr(radius/sqrt(number));
589 cout <<
"DEBUG model_create_fibonacci_sphere: number=" << number <<
590 " radius=" << radius << endl;
592 for ( i=0; i<number; ) {
593 z = 1 - (2.0*i + 1.0)/number;
611 cout <<
"Generating a Fibonacci sphere:" << endl;
612 cout <<
"Number of components: " << i << endl;
613 cout <<
"Radius: " << radius << endl << endl;
624 for ( ncomp=0, comp =
model->
comp; comp; comp = comp->
next, ncomp++ ) ;
626 if ( division < 1 )
return ncomp;
628 double search_radius = 1/pow(2.0,division - 1.0);
635 for ( i=0, n=ncomp, comp =
model->
comp; comp && i<ncomp; comp = comp->next, i++ ) {
636 for ( j=i, comp2 = comp; comp2 && j<ncomp; comp2=comp2->
next, j++ ) {
637 if ( comp != comp2 ) {
654 if ( fabs(sphere_fraction) < 1e-3 )
return 0;
660 v = 1/(1-sphere_fraction*(1-comp->
loc.
length()));
683 if ( divisions < 1 ) divisions = 1;
684 if ( divisions > 4 ) {
685 cout <<
"Warning: Divisions bigger than 4 cannot be tesselated!" << endl;
686 cout <<
" Divisions reset to 4" << endl << endl;
691 cout <<
"Generating a dodecahedral sphere:" << endl;
692 cout <<
"Radius: " << radius << endl;
693 cout <<
"Divisions: " << divisions << endl << endl;
701 for ( i=0; i<divisions; i++ ) {
707 cout <<
"Division " << i+1 <<
": " << n <<
" components" << endl;
737 if ( divisions < 1 ) divisions = 1;
738 if ( divisions > 4 ) {
739 cout <<
"Warning: Divisions bigger than 4 cannot be tesselated!" << endl;
740 cout <<
" Divisions reset to 4" << endl << endl;
745 cout <<
"Generating an icosahedral sphere:" << endl;
746 cout <<
"Radius: " << radius << endl;
747 cout <<
"Divisions: " << divisions << endl << endl;
754 for ( i=0; i<divisions; i++ ) {
757 cout <<
"Division " << i+1 <<
": " << n <<
" components" << endl;
790 double temp1 = z1/axes[2], temp2 = z2/axes[2];
791 double a1 = sqrt(1 - temp1*temp1);
792 double a2 = sqrt(1 - temp2*temp2);
809 if ( z2 < -axes[2] ) z2 = -axes[2];
811 double epsilon(0.0001);
820 while (fabs(z3 - z2) > 2 * epsilon
822 midpoint = (z3 + z2) / 2;
849 double temp = axes[1] * x1 / axes[0];
850 double y1 = sqrt(axes[1]*axes[1] - temp*temp);
855 if (
Vector3<double>(-axes[0],0,0).distance2(old) < distance2 )
return x1;
858 double left = fmax(-axes[0], x1 -
distance);
859 temp = axes[1] * left / axes[0];
860 double f_left = sqrt(axes[1]*axes[1] - temp*temp);
864 double epsilon(0.0001);
870 while ( fabs((right - left) / right) > 2 * epsilon
872 mid[0] = (right + left) / 2.0;
873 temp = axes[1] * mid[0] / axes[0];
874 mid[1] = sqrt(axes[1]*axes[1] - temp*temp);
876 if ( d2 > distance2 ) {
878 }
else if ( d2 < distance2 ) {
900 cerr <<
"Error: The circle radius must given!" << endl;
907 cout <<
"Creating a circle of radius " << radius <<
" at z=" << z <<
908 " with separation " <<
distance << endl << endl;
919 double angle = acos(1 - temp*temp/2);
921 long numpts = (long) (
TWOPI / angle + 0.5);
922 angle =
TWOPI / numpts;
928 for( i = 0; i < numpts; i++ ){
949 if (fabs((axes[0] - axes[1]) / axes[1]) < 0.001)
972 while ( loc_old[0] > -axes[0] ) {
974 temp = axes[1] * loc_new[0] / axes[0];
975 loc_new[1] = sqrt(axes[1]*axes[1] - temp*temp);
977 && 2 * loc_new[1] > lastpair) {
982 comp->
loc[1] = -comp->
loc[1];
990 if ( loc_new.
distance(loc_old) > enderror ) {
1013 long swap_yx(0), swap_zx(0), swap_zy(0), swap_slice(0);
1017 cout <<
"Generating an ellipsoid:" << endl;
1018 cout <<
"Axes: " << axes << endl;
1019 cout <<
"Separation: " <<
distance << endl;
1023 if (axes[1] > axes[0]) {axes =
Vector3<double>(axes[1],axes[0],axes[2]); swap_yx = 1;}
1024 if (axes[2] > axes[0]) {axes =
Vector3<double>(axes[2],axes[1],axes[0]); swap_zx = 1;}
1025 if (axes[2] > axes[1]) {axes =
Vector3<double>(axes[0],axes[2],axes[1]); swap_zy = 1;}
1028 if (axes[1] * axes[1] < axes[0] * axes[2]) {
1035 double zend = -axes[2], dz = 2*axes[2], temp(0);
1042 comp->
loc[2] = -zend;
1044 while ( ell_axis[1]*ell_axis[1] + dz*dz > distance2 ) {
1046 temp = ell_axis[2]/axes[2];
1047 temp = sqrt(1 - temp*temp);
1048 ell_axis[0] = temp * axes[0];
1049 ell_axis[1] = temp * axes[1];
1051 current = current->
next;
1052 dz = ell_axis[2] - zend;
1056 if (
verbose ) cout <<
"Ellipses Generated: " << nellipse << endl << endl;
1058 double derror(0.9*distance2);
1060 if ( ( ell_axis[0]*ell_axis[0] + dz*dz > derror ) && ( ell_axis[1]*ell_axis[1] + dz*dz > derror ) ) {
1063 comp->
loc[2] = zend;
1077 if(swap_slice) { mat =
Matrix3(y,x) * mat; mat =
Matrix3(x,z) * mat;}
1078 if(swap_zy) mat =
Matrix3(z,y) * mat;
1079 if(swap_zx) mat =
Matrix3(z,x) * mat;
1080 if(swap_yx) mat =
Matrix3(y,x) * mat;
1082 cout << mat << endl;
1104 if ( radius <= 0 ) {
1105 cerr <<
"Error: The cylinder radius must given!" << endl;
1110 cerr <<
"Error: The cylinder length must given!" << endl;
1114 if ( distance <= 0 || distance > radius )
distance = radius/10;
1116 if ( direction.
length() < 0.5 )
1122 cout <<
"Creating a cylinder in direction " << direction <<
", radius "
1123 << radius <<
" and length " <<
length <<
1124 " with separation " <<
distance << endl << endl;
1134 double a, z, dz(
distance/sqrt(2.0));
1136 double da(acos(1 - temp*temp/2));
1137 long numpts = (long) (
TWOPI / da + 0.5);
1138 da =
TWOPI / numpts;
1142 for( i = 0; i < numpts; i++, a += da ){
1172 if (
length <= 0 || width <= 0 ) {
1173 cerr <<
"Error: The plane length and width must given!" << endl;
1180 cout <<
"Creating a plane:" << endl;
1181 cout <<
"Size: " <<
length <<
" x " << width << endl;
1182 cout <<
"Height: " << z << endl;
1183 cout <<
"Separation: " <<
distance << endl;
1198 for ( y = -hw; y <= hw; y += dy ) {
1200 for ( x = (t)? -hl: -hl+dx/2; x < hl; x += dx ) {
1211 cout <<
"Number of components created: " << n << endl << endl;
1230 double separation,
double packing)
1232 if ( radius <= 0 ) {
1233 cerr <<
"Error: The sphere radius must given!" << endl;
1237 if ( separation <= 0 ) {
1238 cerr <<
"Error: The component separation distance must given!" << endl;
1242 if ( packing <= 0 ) {
1243 cerr <<
"Error: The packing distance must given!" << endl;
1247 if ( direction.
length() < 0.5 )
1253 cout <<
"Creating a spindle in direction " << direction <<
", radius "
1254 << radius <<
" with separation " << separation <<
1255 " and packing " << packing << endl << endl;
1269 for ( ; radius > packing; radius -= packing ) {
1270 amax = 3*
M_PI*
M_PI*radius/(2*packing);
1271 for ( a=0; a<amax; a+=da ) {
1272 b =
M_PI*(a/amax - 0.5);
1273 loc =
Vector3<double>(cos(a) * cos(b), sin(a) * cos(b), sin(b)) * radius;
1278 cout << loc << endl;
1279 rp = sqrt(loc[0]*loc[0] + loc[1]*loc[1]);
1280 if ( rp > 0.1 ) da = separation/rp;