import math


def calculate_distance(coord1, coord2, box_length = None):
    """
    Calculate the distance between two points. When box_length is set, we use the the minimum image convention to calculate.
    
    Parameters:
    ```````````
    coord1, coord2 : list
        The atomic coordinates [x, y, z]
        
    box_length : float, optional
        The box length. The function assumes the box is a cube.
    
    Returns:
    ````````
    distance : float
        The distance between the two atoms.
    """
    distance = 0
    for i in range(len(coord1)):
        coord_dist = coord1[i] - coord2[i]
        if box_length:
            if abs(coord_dist) > box_length / 2:
                coord_dist = coord_dist - (box_length * round(coord_dist / box_length))
        distance += coord_dist**2
        
    distance = math.sqrt(distance)
    
    return distance