nodes: 0, module; 1, function_definition; 2, function_name:fit_heptad_register; 3, parameters; 4, block; 5, identifier:crangles; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# This is dirty, too long but trimmed with zip; 13, expression_statement; 14, for_statement; 15, return_statement; 16, comment:"""Attempts to fit a heptad repeat to a set of Crick angles.
  
      Parameters
      ----------
      crangles: [float]
          A list of average Crick angles for the coiled coil.
  
      Returns
      -------
      fit_data: [(float, float, float)]
          Sorted list of fits for each heptad position.
      """; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, identifier:i; 24, call; 25, block; 26, call; 27, identifier:crangles; 28, list_comprehension; 29, identifier:hept_p; 30, list_comprehension; 31, identifier:ideal_crangs; 32, list; 33, identifier:full_hept; 34, binary_operator:len(crangles) // 7; 35, identifier:ideal_crang_list; 36, binary_operator:ideal_crangs * (full_hept + 2); 37, identifier:fitting; 38, list; 39, identifier:range; 40, argument_list; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, identifier:sorted; 45, argument_list; 46, conditional_expression:x if x > 0 else 360 + x; 47, for_in_clause; 48, binary_operator:x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0); 49, for_in_clause; 50, subscript; 51, subscript; 52, subscript; 53, subscript; 54, subscript; 55, subscript; 56, subscript; 57, call; 58, integer:7; 59, identifier:ideal_crangs; 60, parenthesized_expression; 61, integer:7; 62, assignment; 63, assignment; 64, call; 65, identifier:fitting; 66, keyword_argument; 67, identifier:x; 68, comparison_operator:x > 0; 69, binary_operator:360 + x; 70, identifier:x; 71, identifier:crangles; 72, binary_operator:x * (360.0 / 7.0); 73, parenthesized_expression; 74, identifier:x; 75, call; 76, identifier:hept_p; 77, integer:0; 78, identifier:hept_p; 79, integer:2; 80, identifier:hept_p; 81, integer:4; 82, identifier:hept_p; 83, integer:6; 84, identifier:hept_p; 85, integer:1; 86, identifier:hept_p; 87, integer:3; 88, identifier:hept_p; 89, integer:5; 90, identifier:len; 91, argument_list; 92, binary_operator:full_hept + 2; 93, identifier:ang_pairs; 94, call; 95, identifier:ang_diffs; 96, list_comprehension; 97, attribute; 98, argument_list; 99, identifier:key; 100, lambda; 101, identifier:x; 102, integer:0; 103, integer:360; 104, identifier:x; 105, identifier:x; 106, parenthesized_expression; 107, binary_operator:(360.0 / 7.0) / 2.0; 108, identifier:range; 109, argument_list; 110, identifier:crangles; 111, identifier:full_hept; 112, integer:2; 113, identifier:zip; 114, argument_list; 115, call; 116, for_in_clause; 117, identifier:fitting; 118, identifier:append; 119, tuple; 120, lambda_parameters; 121, subscript; 122, binary_operator:360.0 / 7.0; 123, parenthesized_expression; 124, float:2.0; 125, integer:7; 126, identifier:crangles; 127, subscript; 128, identifier:abs; 129, argument_list; 130, pattern_list; 131, identifier:ang_pairs; 132, identifier:i; 133, call; 134, call; 135, identifier:x; 136, identifier:x; 137, integer:1; 138, float:360.0; 139, float:7.0; 140, binary_operator:360.0 / 7.0; 141, identifier:ideal_crang_list; 142, slice; 143, binary_operator:y - x; 144, identifier:x; 145, identifier:y; 146, attribute; 147, argument_list; 148, attribute; 149, argument_list; 150, float:360.0; 151, float:7.0; 152, identifier:i; 153, identifier:y; 154, identifier:x; 155, identifier:numpy; 156, identifier:mean; 157, identifier:ang_diffs; 158, identifier:numpy; 159, identifier:std; 160, identifier:ang_diffs
code: def fit_heptad_register(crangles):
      """Attempts to fit a heptad repeat to a set of Crick angles.
  
      Parameters
      ----------
      crangles: [float]
          A list of average Crick angles for the coiled coil.
  
      Returns
      -------
      fit_data: [(float, float, float)]
          Sorted list of fits for each heptad position.
      """
      crangles = [x if x > 0 else 360 + x for x in crangles]
      hept_p = [x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0) for x in range(7)]
      ideal_crangs = [
          hept_p[0],
          hept_p[2],
          hept_p[4],
          hept_p[6],
          hept_p[1],
          hept_p[3],
          hept_p[5]
      ]
      full_hept = len(crangles) // 7
      ideal_crang_list = ideal_crangs * (full_hept + 2)  # This is dirty, too long but trimmed with zip
      fitting = []
      for i in range(7):
          ang_pairs = zip(crangles, ideal_crang_list[i:])
          ang_diffs = [abs(y - x) for x, y in ang_pairs]
          fitting.append((i, numpy.mean(ang_diffs), numpy.std(ang_diffs)))
      return sorted(fitting, key=lambda x: x[1])