def atom_distance_func()

in source/src/molecule-unfolding/utility/MolGeoCalc.py [0:0]


def atom_distance_func(rotate_values, mol_data, var_rb_map, theta_option, M):
    # save temp results for pts
    temp_pts_dict = {}

    tor_len = len(rotate_values)
    tor_last_idx = get_idx(rotate_values[tor_len-1], var_rb_map)

    # initial points for distance calculation
    tor_name = rot_pts_name(rotate_values, var_rb_map)
    f_0 = mol_data.bond_graph.sort_ris_data[str(M)][tor_name]['f_0_set']
    f_0_mid = calc_mid_pts(f_0, mol_data)
    f_1 = mol_data.bond_graph.sort_ris_data[str(M)][tor_name]['f_1_set']
    f_1_mid = calc_mid_pts(f_1, mol_data)
    f_1_name = transfer_pts_name(f_1)
    temp_pts_dict[f_1_name] = {}
    temp_pts_dict[f_1_name]['pts'] = f_1_mid
    temp_pts_dict[f_1_name]['idx'] = ([0, 0, 0], [0, 0, 0])

    for left_idx in range(tor_len):
        # get rotate theta
        # e.g. ['x_3_2', 'x_4_7'] -> 'x_3_2'
        tor_start_value = rotate_values[left_idx]
        # e.g. 'x_3_2' -> ['4','5']
        tor_start_idx = get_idx(tor_start_value, var_rb_map)
#         # ??
#         tor_start = sort_torsion_group[tor_start_idx]
        # e.g. 'x_3_2' -> 2*pi/D * (2-1)
        rotate_theta = get_theta(tor_start_value, theta_option)
        # rotate points
        # e.g. '4' -> [x,y,z]
        start_name = tor_start_idx[0]
        start_pts = get_current_pts([start_name], temp_pts_dict, mol_data)

        end_name = tor_start_idx[1]
        end_pts = get_current_pts([end_name], temp_pts_dict, mol_data)
        logging.debug("current tor {} with base_idx {} rotate_theta {}".format(
            tor_start_value, tor_start_idx, rotate_theta))

        rot_bond = (start_pts[0]['pts'], end_pts[0]['pts'])

        for right_idx in range(left_idx, tor_len):
            tor_end_value = rotate_values[right_idx]
            tor_end_idx = get_idx(tor_end_value, var_rb_map)
#             tor_end = sort_torsion_group[tor_end_idx]
            logging.debug("update tor {}".format(tor_end_idx))
#             only update min/max pts

            # rotate target min/max pts
            if right_idx != left_idx:
                target_start_name = tor_end_idx[0]
                target_start_pts = get_current_pts(
                    [target_start_name], temp_pts_dict, mol_data)

                target_end_name = tor_end_idx[1]
                target_end_pts = get_current_pts(
                    [target_end_name], temp_pts_dict, mol_data)

                rotate_start_pts = update_pts(
                    start_pts, end_pts, target_start_pts, rotate_theta)
                update_pts_dict([target_start_name],
                                temp_pts_dict, rotate_start_pts, rot_bond)

                rotate_end_pts = update_pts(
                    start_pts, end_pts, target_end_pts, rotate_theta)
                update_pts_dict([target_end_name], temp_pts_dict,
                                rotate_end_pts, rot_bond)

            if int(tor_end_idx[1]) == int(tor_last_idx[1]):
                # update all the pts
                logging.debug("update all pts!!!!!!!!")
                f_1_rotate_pts = get_current_pts(f_1, temp_pts_dict, mol_data)

                end_mid_rotate_pts = update_pts(
                    start_pts, end_pts, f_1_rotate_pts, rotate_theta)
                update_pts_dict(f_1, temp_pts_dict,
                                end_mid_rotate_pts, rot_bond)

#                 fragment_group[target_pts_name]['mid_pts'] = target_mid_rotate_pts

            logging.debug("#########pts_dict {}".format(temp_pts_dict))

    base_pts = []
    base_pts = get_current_pts(f_0, temp_pts_dict, mol_data)

    target_pts = []
    for pt in f_1:
        target_pts.append(temp_pts_dict[pt])
    logging.debug("base pts {}".format(base_pts))
    logging.debug("target pts {} ".format(target_pts))
    distance = calc_distance_between_pts(
        pts_pos_list(base_pts), pts_pos_list(target_pts))

    return distance