def calculate_selection_distances(distance_selection_objects, data_handler):
    """
    "distances":  {
           "dist_id_1":   {
                           "from": STRING::SELECTION,
                           "to": STRING::SELECTION,
                           "cutoff": FLOAT
                        },
                        ...
    }
    if cutoff is defined, only distances lower than this cutoff will be stored
    """
    distances = {}
    ensemble = data_handler.get_data().get_all_elements()
    
    for distance_id in distance_selection_objects:

        # Get selections for all frames
        try:
            from_selection = ensemble.select(distance_selection_objects[distance_id]["from"]) 
            to_selection = ensemble.select(distance_selection_objects[distance_id]["to"])
        except KeyError:
            print '[Error calculate_selection_distances ] "from" and "to" properties are mandatory. Skipping %s calculation...'%distance_id
            break
        
        # Check selections were ok
        if from_selection is None:
            print '"[Error calculate_selection_distances ] Unproductive "from" selection. Skipping %s calculation...'%distance_id
            break
        
        if to_selection is None:
            print '"[Error calculate_selection_distances ] Unproductive "to" selection. Skipping %s calculation...'%distance_id
            break
        
        distances[distance_id] = calcDistance(calcCenter(from_selection.getCoordsets()), 
                                              calcCenter(to_selection.getCoordsets()))
    
    return distances
dataset/ETHPy150Open victor-gil-sepulveda/pyProCT/pyproct/postprocess/actions/proteinAtomDistances.py/calculate_selection_distances/original