# Design of the Algorithm for Packaging of Water Molecules in a Fixed Volume

^{1}

^{2}

^{3}

^{*}

^{†}

## Abstract

**:**

## 1. Introduction

## 2. Algorithm

**Definition 1.**

- 1.
- Firstly, it is necessary to specify a volume that is available for completion.
- 2.
- Then, we form a matrix that will contain information about the coordinates of the vertices of all added molecules.
- 3.
- In accordance with the representation of the water molecule, we need to determine the coordinates of the vertices of the tetrahedron for the first molecule.
- 4.
- The coordinates of the nodes of the molecule are recorded in the matrix formed in step 2.
- 5.
- Afterwards, it is reasonable to apply the image of the tetrahedron corresponding to the added molecule to the graph.
- 6.
- Two variables are defined that store the position of the last added tetrahedron. One of them represents the coordinates of the tetrahedron vertex with the largest abscissa and another one is the number of vertices with the largest abscissa (1 or 2). It is essential to update these variables after each new molecule is added.
- 7.
- Similarly, we define two variables that store the position of the first tetrahedron in a row. It is important to update them after moving to the new line.
- 8.
- The cycle of molecular attachment is carried out. Firstly, it is necessary to check the ability to include a new molecule in one row with the previous one. If it is possible, we add the molecule using the function that defines vertex coordinates. Steps 4–6 are repeated. Otherwise, the molecule enters the next row. Steps 4–7 are repeated. If in this instance it exceeds the allowable volume as well, the algorithm has to attach the molecule in the first row of a new layer. In this case, steps 4–7 are repeated.

## 3. Procedure in MATLAB Language

`function [] = DrawTriangle(new_a,new_b,new_c,new_d)`

`plot3(new_a(1),new_a(2),new_a(3),‘∗b’,’MarkerSize’,8);`

`plot3(new_b(1),new_b(2),new_b(3),‘∗b’,’MarkerSize’,8);`

`line([new_a(1),new_b(1)],[new_a(2),new_b(2)],[new_a(3),new_b(3)]);`

`line([new_c(1),new_b(1)],[new_c(2),new_b(2)],[new_c(3),new_b(3)]);`

`line([new_a(1),new_c(1)],[new_a(2),new_c(2)],[new_a(3),new_c(3)]);`

`line([new_a(1),new_d(1)],[new_a(2),new_d(2)],[new_a(3),new_d(3)]);`

`line([new_b(1),new_d(1)],[new_b(2),new_d(2)],[new_b(3),new_d(3)]);`

`line([new_c(1),new_d(1)],[new_c(2),new_d(2)],[new_c(3),new_d(3)]);`

`end`

`function [a,b,c,d,rightest,type] = NewPutTriangle(type, rightest,`

`step_x, step_y, step_z,h_x)`

`if type == 1`

`b = rightest;`

`b(1) = b(1) + h_x;`

`c = [b(1) + 3 ∗ step_x, b(2) + step_y, b(3)];`

`d = [c(1), b(2)- step_y, b(3)];`

`a = [b(1) + 2 ∗ step_x, b(2), b(3) + step_z];`

`rightest = d;`

`type = 2;`

`else`

`a = rightest;`

`a(1) = a(1) + h_x;`

`b = [a(1), a(2) + 2 ∗ step_y, a(3)];`

`c = [a(1) + 3 ∗ step_x, a(2) + step_y, a(3)];`

`d = [a(1) + step_x, a(2) + step_y, a(3) + step_z];`

`rightest = c;`

`type = 1;`

`end`

`DrawTriangle(a,b,c,d);`

`end`

`tic;`

`grid on; hold on; axis equal;`

`alph = 104.25 ∗ pi /180; % angle in radians between two hydrogen atoms`

`HO = 95.84; % distance between oxygen and hydrogen`

`AB = sqrt(2 ∗ HO^2 - 2 ∗ HO^2 ∗ cos(alph)); % cosine theorem`

`step_y = AB/2; % 1/2 the length of the side of the tetrahedron`

`step_x = AB ∗ sqrt(3)/6; % 1/3 of the height of the triangle`

`step_z = AB ∗ sqrt(6)/3; % height of the tetrahedron`

`stop_x = 600; % space where molecules can be`

`stop_y = 500;`

`stop_z = 300;`

`v = AB^3 ∗ sqrt(2)/12; % volume of the tetrahedron`

`space = stop_x ∗ stop_y ∗ stop_z;`

`N = ceil(space/v);`

`% remember coordinates of tetrahedron points A; B; C; D respectively`

`in matrix where A and B has hydrogen and C and D not`

`% put that matrix in one big matrix`

`a = [0, 0, 0];`

`b = [0, 2 ∗ step_y, 0];`

`c = [3 ∗ step_x, step_y, 0];`

`d = [step_x, step_y, step_z];`

`M = zeros(4 ∗ N, 3);`

`M(1,:) = a;`

`M(2,:) = b;`

`M(3,:) = c;`

`M(4,:) = d;`

`DrawTriangle(a,b,c,d);`

`type = 1; % refer to number of dots with max x`

`rightest = c; % dot with max x and min y if there are two of them`

`type1str = 1; % to remember type of first molecule in the last string`

`r1s = c; % to remember dot from first molecule`

`stop = 0;`

`h_x = 10;`

`h_y = 45; % distance which we left between lines !=0`

`h_z = 30; % distance which we left between layers`

`k = 1; % to count molecules`

`while (stop == 0)`

`if (rightest(1)+ 3 ∗ step_x + h_x) <= stop_x`

`k = k + 1;`

`[M(4 ∗ k - 3,:), M(4 ∗ k - 2,:), M(4 ∗ k - 1,:), M(4 ∗ k,:), rightest,`

`type] = NewPutTriangle(type,rightest, step_x, step_y,`

`step_z,h_x);`

`elseif ((type == 1)&&((h_y + 3 ∗ step_y + rightest(2)) <= stop_y))||`

`((type==2)&&((h_y + 4 ∗ step_y +rightest(2))<= stop_y))`

`k = k + 1;`

`if type1str == 1`

`b2 = [r1s(1) - 3 ∗ step_x, r1s(2) + h_y + step_y, r1s(3)];`

`c2 = [b2(1) + 3 ∗ step_x, b2(2) + step_y, b2(3)];`

`d2 = [c2(1), b2(2) - step_y, b2(3)];`

`a2 = [b2(1) + 2 ∗ step_x, b2(2), b2(3) + step_z];`

`rightest = d2;`

`type = 2;`

`else`

`a2 = [r1s(1)- 3 ∗ step_x, r1s(2) + h_y + step_y, r1s(3)];`

`b2 = [a2(1), a2(2) + 2 ∗ step_y, a2(3)];`

`c2 = [a2(1) + 3 ∗ step_x, a2(2) + step_y, a2(3)];`

`d2 = [a2(1) + step_x, a2(2) + step_y, a2(3) + step_z];`

`rightest = c2;`

`type = 1;`

`end`

`type1str = type;`

`r1s = rightest;`

`M(4 ∗ k - 3,:) = a2;`

`M(4 ∗ k - 2,:) = b2;`

`M(4 ∗ k - 1,:) = c2;`

`M(4 ∗ k,:) = d2;`

`DrawTriangle(a2,b2,c2,d2);`

`elseif (rightest(3) + h_z + 2 ∗ step_z) <= stop_z`

`k = k + 1;`

`a3 = [0, 0, rightest(3) + step_z + h_z];`

`b3 = [a3(1), a3(2) + 2 ∗ step_y, a3(3)];`

`c3 = [a3(1) + 3 ∗ step_x, a3(2) + step_y, a3(3)];`

`d3 = [a3(1) + step_x, a3(2) + step_y, a3(3) + step_z];`

`rightest = c3;`

`type = 1;`

`type1str = type;`

`r1s = rightest;`

`M(4 ∗ k - 3,:) = a3;`

`M(4 ∗ k - 2,:) = b3;`

`M(4 ∗ k - 1,:) = c3;`

`M(4 ∗ k,:) = d3;`

`DrawTriangle(a3,b3,c3,d3);`

`else`

`stop = 1;`

`end`

`end`

`y = 4 ∗ k;`

`while y < size(M,1)`

`M(4 ∗ k + 1,:) = [];`

`end`

`t_End = toc;`

`disp(t_End);`

`s1=sprintf(‘%d molecules were placed’, k);`

`disp(s1);`

## 4. Conclusions

## Author Contributions

## Funding

## Data Availability Statement

## Conflicts of Interest

## References

- Novikov, A.C. Symmetry in quantum and computational chemistry. Symmetry
**2020**, 12, 2028. [Google Scholar] [CrossRef] - Fischer, C.C. A Machine Learning Approach to Crystal Structure Prediction. Ph.D. Thesis, MIT, Cambridge, MA, USA, 16 August 2007. [Google Scholar]
- Braun, N.; Huttner, G. Packing and molecular shape: Layers of centred hexagons as a guiding principle. Acta Cryst.
**2005**, B61, 174–184. [Google Scholar] [CrossRef] [PubMed] - Thomasr, N.W. A novel characterization of organic molecular crystal structures for the purpose of crystal engineering. Acta Cryst.
**2015**, B71, 463–477. [Google Scholar] - Falls, Z.; Avery, P.; Wang, X.; Hilleke, K.P.; Zurek, E. The XtalOpt evolutionary algorithm for crystal structure prediction. J. Phys. Chem.
**2021**, 125, 1601–1620. [Google Scholar] [CrossRef] - Oganov, A.R.; Glass, C.W. Crystal structure prediction using evolutionary algorithms: Principles and applications. J. Chem. Phys.
**2006**, 124, 24470. [Google Scholar] - Lyakhov, A.O.; Oganov, A.R.; Stokes, H.T.; Zhu, Q. New developments in evolutionary structure prediction algorithm USPEX. Comput. Phys. Commun.
**2013**, 184, 1172–1182. [Google Scholar] [CrossRef] - Peresypkina, E.V.; Blatov, V.A. Topology of molecular packings in organic crystals. Acta Cryst.
**2000**, B56, 1035–1045. [Google Scholar] [CrossRef] [PubMed] [Green Version] - Gavezzotti, A.; Lo Presti, L. Molecular dynamics simulation of organic crystals: Introducing the CLP-dyncry environment. J. Appl. Cryst.
**2019**, 52, 1253–1263. [Google Scholar] [CrossRef] - Nekrasov, B.V. The Basics of General Chemistry. T.1, 3rd ed.; Chemistry: Moscow, Russia, 1973; pp. 131–134. [Google Scholar]

**Figure 1.**Representation of water molecule. Dotted circles refer to hydrogen atoms, while continuous one depicts oxygen atom.

**Figure 2.**Illustration of the result of the algorithm for 8 molecules. The asterisks mark the vertices of type A.

**Figure 3.**Illustration of the result of the algorithm for 24 molecules. The asterisks mark the vertices of type A.

X, pm | Y, pm | Z, pm | Volume, pm${}^{\mathbf{3}}$ | Number of Molecules | Time, s |
---|---|---|---|---|---|

130 | 150 | 130 | 2.535 × 10^{6} | 1 | 0.075858 |

290 | 330 | 290 | 2.7753 × 10^{7} | 8 | 0.11618 |

290 | 330 | 550 | 5.2635 × 10^{7} | 16 | 0.17162 |

290 | 690 | 550 | 1.1006 × 10^{8} | 48 | 0.30239 |

570 | 690 | 550 | 2.1632 × 10^{8} | 96 | 0.47833 |

980 | 980 | 980 | 9.4119 × 10^{8} | 441 | 2.1261 |

1270 | 980 | 980 | 1.2197 × 10^{9} | 567 | 2.8386 |

1270 | 980 | 1250 | 1.5558 × 10^{9} | 729 | 3.6441 |

1550 | 1150 | 1250 | 2.2281 × 10^{9} | 1089 | 5.6193 |

2550 | 1150 | 1250 | 3.6656 × 10^{9} | 1782 | 10.339 |

2550 | 1750 | 1250 | 5.5781 × 10^{9} | 2754 | 21.02 |

2550 | 1750 | 1850 | 8.2556 × 10^{9} | 3978 | 45.271 |

2550 | 2550 | 2550 | 1.6581 × 10^{10} | 8424 | 201.57 |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Lorits, E.M.; Gubar, E.A.; Novikov, A.S.
Design of the Algorithm for Packaging of Water Molecules in a Fixed Volume. *Symmetry* **2022**, *14*, 2453.
https://doi.org/10.3390/sym14112453

**AMA Style**

Lorits EM, Gubar EA, Novikov AS.
Design of the Algorithm for Packaging of Water Molecules in a Fixed Volume. *Symmetry*. 2022; 14(11):2453.
https://doi.org/10.3390/sym14112453

**Chicago/Turabian Style**

Lorits, Ekaterina M., Elena A. Gubar, and Alexander S. Novikov.
2022. "Design of the Algorithm for Packaging of Water Molecules in a Fixed Volume" *Symmetry* 14, no. 11: 2453.
https://doi.org/10.3390/sym14112453