723 int h, i, j, k, l, m, n, o, p, q, r, s, t;
726 gboolean * taken_pos = NULL;
727 gboolean ** holes_pos = NULL;
728 int * pos_order = NULL;
729 int * site_pos = NULL;
731 int pos_bs, num_bs, site_bs;
734 gboolean low_occ = FALSE;
735 gboolean with_holes = FALSE;
736 gboolean occ_sym = (occupying == 0 || occupying > 2) ? TRUE : FALSE;
741 for (k=0; k<cryst ->
objects; k++)
743 if (cryst -> holes[k])
746 j =
max (j, cryst -> pos_by_object[i]);
755 for (j=0; j<cryst ->
objects; j++)
757 if (! cryst -> holes[j])
764 for (h=0; h<cryst ->
objects; h++)
768 g_debug (
"i= %d, occ[%d]= %f, pbo[%d]= %d", i+1, i+1, cryst ->
occupancy[i], i+1, cryst -> pos_by_object[i]);
770 if (cryst -> sites[i][0] > 0 && cryst ->
occupancy[i]*cryst -> pos_by_object[i] < 1.0 && ! cryst -> holes[i]) low_occ = TRUE;
772 if (cryst -> sites[i][0] > 0 && cryst ->
occupancy[i] < 1.0 && cryst -> pos_by_object[i] > 1)
775 pos_bs = cryst -> pos_by_object[i];
776 site_bs = (cryst -> holes[i]) ? 1 : cryst -> sites[i][0];
777 num_bs = cryst -> sites[i][0];
780 g_debug (
"i= %d, site[%d][0]= %d, pos_bs= %d, num_bs= %d", i+1, i+1, cryst -> sites[i][0], pos_bs, num_bs);
782 for (j=0; j<cryst -> sites[i][0]; j++)
784 k = cryst -> sites[i][j+1];
790 for (j=0; j<site_bs; j++)
792 if (holes_pos[i][j]) l ++;
795 for (j=0; j<site_bs; j++)
797 k = cryst -> sites[i][j+1];
799 g_debug (
"\tj= %d, k= %d, sites[%d][0]= %d, occ[%d]= %f, pos_by_objects[%d]= %d",
800 j+1, k+1, k+1, cryst -> sites[k][0], k+1, cryst ->
occupancy[k], k+1, cryst -> pos_by_object[k]);
802 if (cryst -> sites[k][0] > -1)
810 g_debug (
"\tnum_to_save= %d, l= %d", num_to_save, l);
814 if ((v == 1.0 && l != pos_bs) || l > pos_bs) num_to_save += (pos_bs-l);
818 while (m < num_to_save)
824 n = (CPU_time - (k+17)*pos_bs) + (3*cryst -> at_by_object[i]);
826 p = round (prob * (pos_bs-1));
829 pick_it = (taken_pos[p] || holes_pos[i][p]) ? FALSE : TRUE;
833 pick_it = ! taken_pos[p];
836 else if (occupying == 3)
841 while (taken_pos[p] || holes_pos[i][p]) p ++;
845 while (taken_pos[p]) p ++;
851 g_debug (
"\t\tp= %d, m= %d, sites[i][0]= %d", p, m, cryst -> sites[k][0]);
853 p = j + m*cryst -> sites[k][0];
854 if (p > cryst -> pos_by_object[k]-1)
856 p -= (cryst -> pos_by_object[k]-1);
859 g_debug (
"\t\tp= %d", p);
863 if (site_pos[n] == p)
866 if (n == cryst -> pos_by_object[k]) n = 0;
873 if (site_pos[o] == n)
892 sort (num_to_save, site_pos);
894 for (m=0; m<num_to_save; m++)
896 g_debug (
"\t\tm= %d, site_pos[%d]= %d", m+1, m+1, site_pos[m]);
900 for (m=0; m<num_to_save; m++)
903 cryst -> coord[k][m] = cryst -> coord[k][n];
904 if (occ_sym && tot_cell > 1)
906 for (o=1; o<tot_cell; o++)
908 p = k+o*(cryst ->
objects/tot_cell);
909 cryst -> coord[p][m] = cryst -> coord[p][n];
914 cryst -> pos_by_object[k] = num_to_save;
915 cryst -> sites[k][0] = -1;
916 if (occ_sym && tot_cell > 1)
918 for (o=1; o<tot_cell; o++)
920 p = k+o*(cryst ->
objects/tot_cell);
921 cryst -> pos_by_object[p] = num_to_save;
922 cryst -> sites[p][0] = -1;
925 if (cryst -> holes[i])
927 for (o=0; o<num_bs; o++)
929 p = cryst -> sites[i][o+1];
930 for (q=0; q<num_to_save; q++)
933 holes_pos[p][r] = TRUE;
934 if (occ_sym && tot_cell > 1)
936 for (s=1; s<tot_cell; s++)
938 t = p+s*(cryst ->
objects/tot_cell);
939 holes_pos[t][r] = TRUE;
951 if (holes_pos) g_free (holes_pos);
974 int h, i, j, k, l, m, n, o, p, q;
979 mat4_t ** wyckpos = g_malloc0 (sp_group -> numw*
sizeof*wyckpos);
983 wyckpos[i] = g_malloc0 (sp_group -> wyckoff[i].
multi*
sizeof*wyckpos[i]);
984 for (j=0; j<sp_group -> wyckoff[i].multi; j++)
988 tmp_pos = g_strdup_printf (
"%s", sp_group -> wyckoff[i].pos[j][k]);
1005 wyckpos[i][j] = mat4 (spgpos[0][0], spgpos[0][1], spgpos[0][2], spgpos[0][3],
1006 spgpos[1][0], spgpos[1][1], spgpos[1][2], spgpos[1][3],
1007 spgpos[2][0], spgpos[2][1], spgpos[2][2], spgpos[2][3],
1008 0.0, 0.0, 0.0, 1.0);
1009 wyckpos[i][j] = m43_mul(sp_group -> wyck_origin, wyckpos[i][j]);
1019 h = sp_group -> sid;
1020 if (sp_group -> settings[h].nump)
1022 points = g_malloc0(sp_group -> settings[h].nump*
sizeof*points);
1023 for (i=0; i<sp_group -> settings[h].nump; i++)
1027 tmp_pos = g_strdup_printf (
"%s", sp_group -> settings[h].points[i][j]);
1032 points[i] = vec3(copos[0], copos[1], copos[2]);
1038 npoints = sp_group -> settings[h].nump;
1042 points = g_malloc0(1*
sizeof*points);
1043 points[0] = vec3(0.0, 0.0, 0.0);
1054 for (i=1; i<3; i++) amin =
min(amin,
box ->
param[0][i]);;
1058 point.
a = this_proj -> id;
1059 point.
b = point.
c = 0;
1060 if (! this_proj -> modelgl) this_proj -> modelgl = g_malloc0(
sizeof*this_proj -> modelgl);
1080 object = this_proj -> modelgl -> atom_win -> to_be_inserted[2];
1092 this_proj -> modelgl -> search_widg[7] -> todo[i] = 1;
1095 object = this_proj -> modelgl -> atom_win -> to_be_inserted[2];
1099 object =
object -> next;
1102 for (j=0; j<3; j++)
object -> baryc[j] =
this_reader -> coord[i][j];
1110 rounding = this_proj -> modelgl ->
builder_win -> rounding;
1114 object = this_proj -> modelgl -> atom_win -> to_be_inserted[2];
1119 if (this_proj -> modelgl -> search_widg[7] -> todo[l])
1123 for (m=0; m<
object -> species; m++)
1128 if (
object -> old_z[m] == cdata ->
z[l])
1134 if (! done &&
object -> old_z[m] > 0.0)
1136 cdata ->
z[k] =
object -> old_z[m];
1139 if (
object -> old_z[m] == 0.0)
1141 cdata -> holes[i] = TRUE;
1142 cdata -> with_holes = TRUE;
1145 n = sp_group -> wyckoff[0].multi*npoints;
1147 cdata -> coord[i] = g_malloc0(n*
sizeof*cdata -> coord[i]);
1148 cdata -> insert[i] = m4_mul_coord (sp_group -> coord_origin, vec3(
object -> baryc[0],
object -> baryc[1],
object -> baryc[2]));
1154 for (o=0; o<npoints; o++)
1156 for (p=0; p<sp_group -> wyckoff[0].multi; p++)
1158 pos = v3_add (m4_mul_coord (wyckpos[0][p], cdata -> insert[i]), points[o]);
1162 cdata -> coord[i][n].x = pos.
x;
1163 cdata -> coord[i][n].y = pos.
y;
1164 cdata -> coord[i][n].
z = pos.
z;
1168 cdata -> at_type[i][n] = 1;
1173 cdata -> at_type[i][-(q+1)] ++;
1177 cdata -> pos_by_object[i] = n;
1179 if (! cdata -> holes[i]) cdata -> lot[i] =
allocint(
object ->
atoms);
1181 for (l=0; l<
object ->
atoms; l++)
1183 n =
object -> at_list[l].sp;
1184 cdata ->
position[i][l].x =
object -> at_list[l].x;
1185 cdata ->
position[i][l].y =
object -> at_list[l].y;
1186 cdata ->
position[i][l].
z =
object -> at_list[l].z;
1187 if (! cdata -> holes[i])
1191 if (cdata ->
z[o] ==
object -> old_z[n])
1193 cdata -> lot[i][l] = o;
1199 cdata -> at_by_object[i] =
object ->
atoms;
1204 if (
object -> dim > amin)
1208 str = g_strdup_printf (
"%s size (%f Å) is bigger than the min(<b><i>a,b,c</i></b>)\n"
1209 "If you build the crystal the final structure is likely to be crowded !\n"
1210 "Continue anyway ?",
object -> name,
object -> dim);
1216 if (points) g_free (points);
1217 if (wyckpos) g_free (wyckpos);
1221 this_proj -> modelgl -> search_widg[7] =
free_this_search_data (this_proj -> modelgl -> search_widg[7]);
1222 g_free (this_proj -> modelgl);
1223 this_proj -> modelgl = NULL;
1232 j +=
object -> species;
1233 k +=
object ->
atoms;
1236 object =
object -> next;
1243 cdata -> overlapping = (visible) ? this_proj -> modelgl ->
builder_win -> overlapping : FALSE;
1247 if (points) g_free (points);
1248 if (wyckpos) g_free (wyckpos);
1252 this_proj -> modelgl -> search_widg[7] =
free_this_search_data (this_proj -> modelgl -> search_widg[7]);
1253 g_free (this_proj -> modelgl);
1254 this_proj -> modelgl = NULL;
1262 if (points) g_free (points);
1263 if (wyckpos) g_free (wyckpos);
1269 for (i=0; i<cdata ->
objects; i++)
1271 m += (cdata -> holes[i]) ? 1 : 0;
1276 if (! cdata -> overlapping || cdata -> holes[i])
1284 if (u+v > 1.0 || u+v < 0.0)
1287 show_warning (
"Impossible to build crystal: check occupancy !", widg);
1290 else if (cdata -> overlapping && ! cdata -> with_holes)
1292 if (j) cdata -> sites[i][k] = i;
1296 for (l=0; l<cdata ->
objects; l++)
1300 if (cdata -> insert[i].
x == cdata -> insert[l].
x
1301 && cdata -> insert[i].
y == cdata -> insert[l].
y
1302 && cdata -> insert[i].
z == cdata -> insert[l].
z)
1306 if (! cdata -> overlapping || cdata -> holes[i])
1309 cdata -> sites[i][k] = l;
1314 if (! cdata -> overlapping || cdata -> holes[i]) k ++;
1315 if (! cdata -> overlapping || cdata -> holes[l])
1325 show_warning (
"Impossible to build crystal: site total occupancy > 1.0", widg);
1336 cdata -> sites[i] =
allocint (k+1);
1337 cdata -> sites[i][0] = k;
1338 cdata -> sites[i][1] = i;
1339 if (k > 1) cdata -> shared_sites = TRUE;
1357 show_warning (
"Impossible to build crystal: empty site(s) only !", widg);
1360 gboolean new_proj = (this_proj -> natomes && visible) ? TRUE : FALSE;
1380 active_box -> vect[i][j] *= cell -> cextra[i];
1389 tot_cell *= cell -> cextra[i];
1393 i = (occupying == 2) ? 0 : 1;
1394 j = (occupying == 2) ? 1 : tot_cell;
1396 g_free (cryst ->
z);
1398 cryst -> shared_sites = cdata -> shared_sites;
1399 cryst -> overlapping = cdata -> overlapping;
1400 cryst -> with_holes = cdata -> with_holes;
1403 for (k=0; k<cdata ->
objects; k++)
1405 cryst -> pos_by_object[k] = tot_cell*cdata -> pos_by_object[k];
1406 cryst -> at_by_object[k] = cdata -> at_by_object[k];
1407 cryst -> at_type[k] =
duplicate_int (sp_group -> wyckoff[0].
multi*npoints, cdata -> at_type[k]);
1409 if (! cdata -> holes[k]) cryst -> lot[k] =
duplicate_int (cdata -> at_by_object[k], cdata -> lot[k]);
1411 cryst -> sites[k] =
duplicate_int (cdata -> sites[k][0]+1, cdata -> sites[k]);
1412 cryst ->
position[k] = g_malloc0 (cdata -> at_by_object[k]*
sizeof*cryst ->
position[k]);
1413 for (l=0; l<cdata -> at_by_object[k]; l++) cryst ->
position[k][l] = cdata ->
position[k][l];
1414 cryst -> coord[k] = g_malloc0(cryst -> pos_by_object[k]*
sizeof*cryst -> coord[k]);
1418 for (k=0; k<cell -> cextra[0]; k++)
1420 vx = v3_muls(vec3(
box -> vect[0][0],
box -> vect[0][1],
box -> vect[0][2]), k);
1421 for (l=0; l<cell -> cextra[1]; l++)
1423 vy = v3_muls(vec3(
box -> vect[1][0],
box -> vect[1][1],
box -> vect[1][2]), l);
1424 for (m=0; m<cell -> cextra[2]; m++)
1426 vz = v3_muls(vec3(
box -> vect[2][0],
box -> vect[2][1],
box -> vect[2][2]), m);
1427 shift = v3_add (vx, v3_add(vy, vz));
1428 for (n=0; n<cdata ->
objects; n++)
1432 cryst -> coord[n+h] = g_malloc0(cdata -> pos_by_object[n]*
sizeof*cryst -> coord[n+h]);
1433 cryst -> pos_by_object[n+h] = cdata -> pos_by_object[n];
1434 cryst -> at_by_object[n+h] = cdata -> at_by_object[n];
1435 cryst -> holes[n+h] = cdata -> holes[n];
1436 cryst -> at_type[n+h] =
duplicate_int (sp_group -> wyckoff[0].
multi*npoints, cdata -> at_type[n]);
1437 if (! cdata -> holes[n]) cryst -> lot[n+h] =
duplicate_int (cdata -> at_by_object[n], cdata -> lot[n]);
1439 cryst -> sites[n+h] =
duplicate_int (cdata -> sites[n][0]+1, cdata -> sites[n]);
1440 for (o=0; o<cryst -> sites[n+h][0]; o++) cryst -> sites[n+h][o+1] += h;
1441 cryst ->
position[n+h] = g_malloc0 (cdata -> at_by_object[n]*
sizeof*cryst ->
position[n+h]);
1442 for (o=0; o<cdata -> at_by_object[n]; o++) cryst ->
position[n+h][o] = cdata ->
position[n][o];
1444 o = cdata -> pos_by_object[n];
1447 cryst -> coord[n+i*h][p+(!i)*h*o] = v3_add(m4_mul_coord (
box -> frac_to_cart, cdata -> coord[n][p]),
shift);
1450 h += (occupying != 2) ? cdata ->
objects : 1;
1459 if (! cryst -> overlapping)
1461 for (i=0; i<cryst ->
objects; i++)
1463 if (! cryst -> holes[i])
1465 for (j=0; j<cryst -> pos_by_object[i]; j++)
1467 at.
x = cryst -> coord[i][j].x;
1468 at.
y = cryst -> coord[i][j].y;
1469 at.
z = cryst -> coord[i][j].
z;
1470 for (k=i; k<cryst ->
objects; k++)
1472 if (! cryst -> holes[k])
1474 if (k != i || j < cryst -> pos_by_object[i]-1)
1476 l = (k == i) ? j+1 : 0;
1477 for (m=l; m<cryst -> pos_by_object[k]; m++)
1479 bt.
x = cryst -> coord[k][m].x;
1480 bt.
y = cryst -> coord[k][m].y;
1481 bt.
z = cryst -> coord[k][m].
z;
1483 if (
dist.length < 0.5)
1489 if (
ask_yes_no (
"Inter-object distance(s) < 0.5 Ang. !",
1490 "Inter-object distance(s) < 0.5 Ang. !\n\n\t\tContinue and leave a single object at each position ?", GTK_MESSAGE_WARNING, widg))
1503 if (
dist.length < 0.1)
1505 cryst -> at_type[i][j] += cryst -> at_type[k][m];
1506 for (n=m; n<cryst -> pos_by_object[k]-1; n++)
1508 cryst -> coord[k][n].x = cryst -> coord[k][n+1].x;
1509 cryst -> coord[k][n].y = cryst -> coord[k][n+1].y;
1510 cryst -> coord[k][n].
z = cryst -> coord[k][n+1].
z;
1511 cryst -> at_type[k][n] += cryst -> at_type[k][n+1];
1513 cryst -> pos_by_object[k] --;
1528 for (i=0; i<cryst ->
objects; i++)
1530 if (! cryst -> holes[i]) tot_new_at += cryst -> pos_by_object[i]*cryst -> at_by_object[i];
1532 int * tot_new_lot =
allocint(tot_new_at);
1533 vec3_t * ncc = g_malloc0(tot_new_at*
sizeof*ncc);
1535 for (j=0; j<cryst ->
objects; j++)
1537 if (! cryst -> holes[j])
1539 for (k=0; k<cryst -> at_by_object[j]; k++)
1541 for (l=0; l<cryst -> pos_by_object[j]; l++)
1543 ncc[i] = v3_add (cryst -> coord[j][l], cryst ->
position[j][k]);
1544 m = tot_new_lot[i] = cryst -> lot[j][k];
1545 cryst -> nsps[m] ++;
1555 for (j=0; j<cryst -> spec; j++)
1557 if (cryst -> nsps[j]) i ++;
1575 g_debug (
"CRYSTAL:: number of atoms changes between configurations");
1582 g_debug (
"CRYSTAL:: number of chemical species changes between configurations");
1590 for (i=0; i<cryst -> spec; i++)
1592 if (! cryst -> nsps[i])
1596 if (ncc) g_free (ncc);
1597 if (tot_new_lot) g_free (tot_new_lot);
1606 j = (int)cryst ->
z[i];
1626 g_debug (
"CRYSTAL:: number of atoms for chemical species %d changes between configurations", k+1);
1633 g_debug (
"CRYSTAL:: atomic number for chemical species %d changes between configurations", k+1);
1638 for (m=0; m<tot_new_at;m++)
1640 if (tot_new_lot[m] == i) tot_new_lot[m] = k;
1646 copos[0] = copos[1] = copos[2] = 0.0;
1647 if (visible && ! new_proj)
1651 for (j=0; j<3; j++) copos[i] -=
active_box -> vect[j][i]/2.0;
1654 for (i=0; i<tot_new_at; i++)
1672 if (ncc) g_free (ncc);
1673 if (tot_new_lot) g_free (tot_new_lot);
1723 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)
active_glwin -> ogl_mode[0], TRUE);
1755 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)
active_glwin -> ogl_rep[0], TRUE);
1773 gchar * low_warning =
"The crystal will be created however some objects might be missing,\n"
1774 "Occupancy is too low compared to the number of site(s) per cell.\n\n"
1775 "<b>To build a crystal matching the defined occupancy</b>:\n"
1776 "\t <b>1)</b> If you are trying to read a CIF file, use the crystal builder instead.\n"
1777 "\t <b>2)</b> Modify the occupancy set-up to 'Completely random'.\n"
1778 "\t <b>3)</b> Increase the number of unit cells up to get rid of this message.";