Skip to content

Commit 88a7064

Browse files
committed
improved pressure calculation in 2D
1 parent 4d39713 commit 88a7064

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/source/chapters/chapter7.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ Let us add the following method to the *Utilities* class.
3939
def calculate_pressure(self):
4040
"""Evaluate p based on the Virial equation (Eq. 4.4.2 in Frenkel-Smit,
4141
Understanding molecular simulation: from algorithms to applications, 2002)"""
42-
# Ideal contribution
42+
# Compute the ideal contribution
4343
Ndof = self.dimensions*self.total_number_atoms-self.dimensions
44-
volume = np.prod(self.box_size[:3])
44+
volume = np.prod(self.box_size[:self.dimensions])
4545
try:
4646
self.calculate_temperature() # this is for later on, when velocities are computed
4747
temperature = self.temperature
4848
except:
4949
temperature = self.desired_temperature # for MC, simply use the desired temperature
5050
p_ideal = Ndof*temperature/(volume*self.dimensions)
51-
# Non-ideal contribution
51+
# Compute the non-ideal contribution
5252
distances_forces = np.sum(self.compute_potential(output="force-matrix")*self.evaluate_rij_matrix())
5353
p_nonideal = distances_forces/(volume*self.dimensions)
5454
# Final pressure
@@ -73,7 +73,8 @@ To evaluate all the vectors between all the particles, let us also add the
7373
position_i = self.atoms_positions[Ni]
7474
rij_xyz = (np.remainder(position_i - positions_j + half_box_size, box_size) - half_box_size)
7575
rij_matrix[Ni] = rij_xyz
76-
return rij_matrix
76+
# use nan_to_num to avoid "nan" values in 2D
77+
return np.nan_to_num(rij_matrix)
7778
7879
.. label:: end_Utilities_class
7980

0 commit comments

Comments
 (0)