@@ -35,7 +35,8 @@ Let us improve the previously created *InitializeSimulation* class:
3535 ):
3636 super ().__init__ (* args, ** kwargs)
3737 self .box_dimensions = box_dimensions
38- self .dimensions = len (box_dimensions)
38+ # If a box dimension was entered as 0, dimensions will be 2
39+ self .dimensions = len (list (filter (lambda x : x > 0 , box_dimensions)))
3940 self .seed = seed
4041 self .initial_positions = initial_positions
4142 self .thermo_period = thermo_period
@@ -137,11 +138,16 @@ method to the *InitializeSimulation* class:
137138.. code-block :: python
138139
139140 def define_box (self ):
140- box_boundaries = np.zeros((self .dimensions, 2 ))
141- for dim, L in zip (range (self .dimensions), self .box_dimensions):
141+ """ Define the simulation box.
142+ For 2D simulations, the third dimensions only contains 0.
143+ """
144+ box_boundaries = np.zeros((3 , 2 ))
145+ dim = 0
146+ for L in self .box_dimensions:
142147 box_boundaries[dim] = - L/ 2 , L/ 2
148+ dim += 1
143149 self .box_boundaries = box_boundaries
144- box_size = np.diff(self .box_boundaries).reshape(3 )
150+ box_size = np.diff(self .box_boundaries).reshape(self .dimension )
145151 box_geometry = np.array([90 , 90 , 90 ])
146152 self .box_size = np.array(box_size.tolist()+ box_geometry.tolist())
147153
@@ -183,9 +189,8 @@ case, the array must be of size 'number of atoms' times 'number of dimensions'.
183189
184190 def populate_box (self ):
185191 if self .initial_positions is None :
186- atoms_positions = np.zeros((self .total_number_atoms,
187- self .dimensions))
188- for dim in np.arange(self .dimensions):
192+ atoms_positions = np.zeros((self .total_number_atoms, 3 ))
193+ for dim in np.arange(3 ):
189194 diff_box = np.diff(self .box_boundaries[dim])
190195 random_pos = np.random.random(self .total_number_atoms)
191196 atoms_positions[:, dim] = random_pos* diff_box- diff_box/ 2
0 commit comments