nodes: 0, module; 1, function_definition; 2, function_name:get_inertia; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, function_definition; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""Calculate the inertia tensor and transforms along
          rotation axes.
  
          This function calculates the inertia tensor and returns
          a 4-tuple.
  
          The unit is ``amu * length-unit-of-xyz-file**2``
  
          Args:
              None
  
          Returns:
              dict: The returned dictionary has four possible keys:
  
              ``transformed_Cartesian``:
              A :class:`~chemcoord.Cartesian`
              that is transformed to the basis spanned by
              the eigenvectors of the inertia tensor. The x-axis
              is the axis with the lowest inertia moment, the
              z-axis the one with the highest. Contains also a
              column for the mass
  
              ``diag_inertia_tensor``:
              A vector containing the ascendingly sorted inertia moments after
              diagonalization.
  
              ``inertia_tensor``:
              The inertia tensor in the old basis.
  
              ``eigenvectors``:
              The eigenvectors of the inertia tensor in the old basis.
              Since the inertia_tensor is hermitian, they are orthogonal and
              are returned as an orthonormal righthanded basis.
              The i-th eigenvector corresponds to the i-th eigenvalue in
              ``diag_inertia_tensor``.
          """; 15, function_name:calculate_inertia_tensor; 16, parameters; 17, block; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, dictionary; 24, identifier:molecule; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, return_statement; 33, identifier:molecule; 34, call; 35, identifier:molecule; 36, binary_operator:molecule - molecule.get_barycenter(); 37, pattern_list; 38, call; 39, identifier:eig_v; 40, call; 41, identifier:molecule; 42, call; 43, pair; 44, pair; 45, pair; 46, pair; 47, assignment; 48, assignment; 49, assignment; 50, assignment; 51, assignment; 52, assignment; 53, assignment; 54, expression_list; 55, attribute; 56, argument_list; 57, identifier:molecule; 58, call; 59, identifier:inertia; 60, identifier:eig_v; 61, identifier:diag_inertia; 62, identifier:calculate_inertia_tensor; 63, argument_list; 64, attribute; 65, argument_list; 66, attribute; 67, argument_list; 68, string; 69, identifier:molecule; 70, string; 71, identifier:eig_v; 72, string; 73, identifier:diag_inertia; 74, string; 75, identifier:inertia; 76, identifier:masses; 77, attribute; 78, identifier:pos; 79, attribute; 80, identifier:inertia; 81, call; 82, pattern_list; 83, call; 84, identifier:sorted_index; 85, call; 86, identifier:diag_inertia; 87, subscript; 88, identifier:eig_v; 89, subscript; 90, identifier:inertia; 91, identifier:eig_v; 92, identifier:diag_inertia; 93, identifier:self; 94, identifier:add_data; 95, string; 96, attribute; 97, argument_list; 98, identifier:molecule; 99, identifier:xyz_functions; 100, identifier:orthonormalize_righthanded; 101, identifier:eig_v; 102, identifier:molecule; 103, identifier:basistransform; 104, identifier:eig_v; 105, string_content:transformed_Cartesian; 106, string_content:eigenvectors; 107, string_content:diag_inertia_tensor; 108, string_content:inertia_tensor; 109, subscript; 110, identifier:values; 111, subscript; 112, identifier:values; 113, attribute; 114, argument_list; 115, identifier:diag_inertia; 116, identifier:eig_v; 117, attribute; 118, argument_list; 119, attribute; 120, argument_list; 121, identifier:diag_inertia; 122, identifier:sorted_index; 123, identifier:eig_v; 124, slice; 125, identifier:sorted_index; 126, string_content:mass; 127, identifier:molecule; 128, identifier:get_barycenter; 129, attribute; 130, slice; 131, string; 132, attribute; 133, slice; 134, list; 135, identifier:np; 136, identifier:sum; 137, binary_operator:masses[:, None, None]
                  * ((pos**2).sum(axis=1)[:, None, None]
                     * np.identity(3)[None, :, :]
                     - pos[:, :, None] * pos[:, None, :]); 138, keyword_argument; 139, attribute; 140, identifier:eig; 141, identifier:inertia; 142, identifier:np; 143, identifier:argsort; 144, identifier:diag_inertia; 145, identifier:molecule; 146, identifier:loc; 147, string_content:mass; 148, identifier:molecule; 149, identifier:loc; 150, string; 151, string; 152, string; 153, subscript; 154, parenthesized_expression; 155, identifier:axis; 156, integer:0; 157, identifier:np; 158, identifier:linalg; 159, string_content:x; 160, string_content:y; 161, string_content:z; 162, identifier:masses; 163, slice; 164, None; 165, None; 166, binary_operator:(pos**2).sum(axis=1)[:, None, None]
                     * np.identity(3)[None, :, :]
                     - pos[:, :, None] * pos[:, None, :]; 167, binary_operator:(pos**2).sum(axis=1)[:, None, None]
                     * np.identity(3)[None, :, :]; 168, binary_operator:pos[:, :, None] * pos[:, None, :]; 169, subscript; 170, subscript; 171, subscript; 172, subscript; 173, call; 174, slice; 175, None; 176, None; 177, call; 178, None; 179, slice; 180, slice; 181, identifier:pos; 182, slice; 183, slice; 184, None; 185, identifier:pos; 186, slice; 187, None; 188, slice; 189, attribute; 190, argument_list; 191, attribute; 192, argument_list; 193, parenthesized_expression; 194, identifier:sum; 195, keyword_argument; 196, identifier:np; 197, identifier:identity; 198, integer:3; 199, binary_operator:pos**2; 200, identifier:axis; 201, integer:1; 202, identifier:pos; 203, integer:2
code: def get_inertia(self):
          """Calculate the inertia tensor and transforms along
          rotation axes.
  
          This function calculates the inertia tensor and returns
          a 4-tuple.
  
          The unit is ``amu * length-unit-of-xyz-file**2``
  
          Args:
              None
  
          Returns:
              dict: The returned dictionary has four possible keys:
  
              ``transformed_Cartesian``:
              A :class:`~chemcoord.Cartesian`
              that is transformed to the basis spanned by
              the eigenvectors of the inertia tensor. The x-axis
              is the axis with the lowest inertia moment, the
              z-axis the one with the highest. Contains also a
              column for the mass
  
              ``diag_inertia_tensor``:
              A vector containing the ascendingly sorted inertia moments after
              diagonalization.
  
              ``inertia_tensor``:
              The inertia tensor in the old basis.
  
              ``eigenvectors``:
              The eigenvectors of the inertia tensor in the old basis.
              Since the inertia_tensor is hermitian, they are orthogonal and
              are returned as an orthonormal righthanded basis.
              The i-th eigenvector corresponds to the i-th eigenvalue in
              ``diag_inertia_tensor``.
          """
          def calculate_inertia_tensor(molecule):
              masses = molecule.loc[:, 'mass'].values
              pos = molecule.loc[:, ['x', 'y', 'z']].values
              inertia = np.sum(
                  masses[:, None, None]
                  * ((pos**2).sum(axis=1)[:, None, None]
                     * np.identity(3)[None, :, :]
                     - pos[:, :, None] * pos[:, None, :]),
                  axis=0)
              diag_inertia, eig_v = np.linalg.eig(inertia)
              sorted_index = np.argsort(diag_inertia)
              diag_inertia = diag_inertia[sorted_index]
              eig_v = eig_v[:, sorted_index]
              return inertia, eig_v, diag_inertia
  
          molecule = self.add_data('mass')
          molecule = molecule - molecule.get_barycenter()
          inertia, eig_v, diag_inertia = calculate_inertia_tensor(molecule)
          eig_v = xyz_functions.orthonormalize_righthanded(eig_v)
          molecule = molecule.basistransform(eig_v)
          return {'transformed_Cartesian': molecule, 'eigenvectors': eig_v,
                  'diag_inertia_tensor': diag_inertia, 'inertia_tensor': inertia}