parameters: (boxes)
return_statement: return True
docstring: Perform a random move in log(V_1/V_2)
docstring_summary: Perform a random move in log(V_1/V_2)
docstring_tokens: Perform a random move in log ( V_1 / V_2 )
function: def perform_volume_change(boxes):
      """ Perform a random move in log(V_1/V_2) """
  
      # Store old box length, old volumes
      for box in boxes:
          box.old_box_length = box.box_length
      old_volume_1 = boxes[0].volume
      old_volume_2 = boxes[1].volume
  
      # Debugging purposes
      if args.debug:
          np.testing.assert_almost_equal(
              GLOBAL_VOLUME, old_volume_1 + old_volume_2)
  
      # Random move in log(V_1/V_2) (See Algorithm 18 in Frenkel, Smit)
      lnvn = np.log(old_volume_1 / old_volume_2) + \
          (np.random.random() - 0.5) * DV_MAX
  
      # Calculate new box lengths
      new_volume_1 = GLOBAL_VOLUME * np.exp(lnvn) / (1 + np.exp(lnvn))
      new_volume_2 = GLOBAL_VOLUME - new_volume_1
      boxes[0].box_length = np.cbrt(new_volume_1)
      boxes[1].box_length = np.cbrt(new_volume_2)
  
      # Debug
      logging.debug("Perform volume change:"
                    f" {boxes[0].box_name}: {old_volume_1} -> {new_volume_1};"
                    f" {boxes[1].box_name}: {old_volume_2} -> {new_volume_2}.")
  
      # Send new box lengths, recv new energies
      [box.send_data([MessageID.CHANGE_VOLUME, box.box_length]) for box in boxes]
      [box.recv_energy() for box in boxes]
  
      # ---- Check move ----
  
      # Calculate acceptance probability (See (8.3.3) in Frenkel, Smit)
      acc = np.power(new_volume_1 / old_volume_1, boxes[0].num_part + 1) * \
          np.power(new_volume_2 / old_volume_2, boxes[1].num_part + 1) * \
          np.exp(- 1. / kT * (boxes[0].diff_energy + boxes[1].diff_energy))
  
      # Draw random number
      rand = np.random.random()
  
      # Check if move was valid
      if rand > acc:
          # Reject move, restore old configuration
          for box in boxes:
              box.send_data([MessageID.CHANGE_VOLUME_REVERT])
              box.box_length = box.old_box_length
              box.energy = box.old_energy
          return False
  
      # Debug
      logging.debug("Volume change accepted.")
  
      # Only if rand < acc:
      return True
function_tokens: def perform_volume_change ( boxes ) : # Store old box length, old volumes for box in boxes : box . old_box_length = box . box_length old_volume_1 = boxes [ 0 ] . volume old_volume_2 = boxes [ 1 ] . volume # Debugging purposes if args . debug : np . testing . assert_almost_equal ( GLOBAL_VOLUME , old_volume_1 + old_volume_2 ) # Random move in log(V_1/V_2) (See Algorithm 18 in Frenkel, Smit) lnvn = np . log ( old_volume_1 / old_volume_2 ) + ( np . random . random ( ) - 0.5 ) * DV_MAX # Calculate new box lengths new_volume_1 = GLOBAL_VOLUME * np . exp ( lnvn ) / ( 1 + np . exp ( lnvn ) ) new_volume_2 = GLOBAL_VOLUME - new_volume_1 boxes [ 0 ] . box_length = np . cbrt ( new_volume_1 ) boxes [ 1 ] . box_length = np . cbrt ( new_volume_2 ) # Debug logging . debug ( "Perform volume change:" f" {boxes[0].box_name}: {old_volume_1} -> {new_volume_1};" f" {boxes[1].box_name}: {old_volume_2} -> {new_volume_2}." ) # Send new box lengths, recv new energies [ box . send_data ( [ MessageID . CHANGE_VOLUME , box . box_length ] ) for box in boxes ] [ box . recv_energy ( ) for box in boxes ] # ---- Check move ---- # Calculate acceptance probability (See (8.3.3) in Frenkel, Smit) acc = np . power ( new_volume_1 / old_volume_1 , boxes [ 0 ] . num_part + 1 ) * np . power ( new_volume_2 / old_volume_2 , boxes [ 1 ] . num_part + 1 ) * np . exp ( - 1. / kT * ( boxes [ 0 ] . diff_energy + boxes [ 1 ] . diff_energy ) ) # Draw random number rand = np . random . random ( ) # Check if move was valid if rand > acc : # Reject move, restore old configuration for box in boxes : box . send_data ( [ MessageID . CHANGE_VOLUME_REVERT ] ) box . box_length = box . old_box_length box . energy = box . old_energy return False # Debug logging . debug ( "Volume change accepted." ) # Only if rand < acc: return True