code: def test_base_xc():
      """Test BaseXC."""
      from deepchem.utils.dft_utils import ValGrad, SpinParam
      from deepchem.utils.dft_utils import BaseXC
  
      class MyXC(BaseXC):
          @property
          def family(self) -> int:
              return 1
  
          def get_edensityxc(
              self, densinfo: Union[ValGrad, SpinParam[ValGrad]]
          ) -> torch.Tensor:
              if isinstance(densinfo, ValGrad):
                  return densinfo.value.pow(2)
              else:
                  return densinfo.u.value.pow(2) + densinfo.d.value.pow(
                      2
                  )
  
          def get_vxc(
              self, densinfo: Union[ValGrad, SpinParam[ValGrad]]
          ) -> Union[ValGrad, SpinParam[ValGrad]]:
              if isinstance(densinfo, ValGrad):
                  return ValGrad(value=2 * densinfo.value)
              else:
                  return SpinParam(
                      u=ValGrad(value=2 * densinfo.u.value),
                      d=ValGrad(value=2 * densinfo.d.value),
                  )
  
      xc = MyXC()
      densinfo_v = ValGrad(
          value=torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
      )
      assert torch.allclose(
          xc.get_edensityxc(densinfo_v), torch.tensor([1.0, 4.0, 9.0])
      )
      assert xc.get_vxc(densinfo_v) == ValGrad(
          value=torch.tensor([2.0, 4.0, 6.0])
      )
  
      densinfo_s = SpinParam(
          u=ValGrad(
              value=torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
          ),
          d=ValGrad(
              value=torch.tensor([4.0, 5.0, 6.0], requires_grad=True)
          ),
      )
      assert torch.allclose(
          xc.get_edensityxc(densinfo_s),
          torch.tensor([17.0, 29.0, 45.0]),
      )
      assert xc.get_vxc(densinfo_s) == SpinParam(
          u=ValGrad(value=torch.tensor([2.0, 4.0, 6.0])),
          d=ValGrad(value=torch.tensor([8.0, 10.0, 12.0])),
      )
  
file_path: deepchem/deepchem/utils/test/test_dft_utils.py
imports: import pytest
  import numpy
  from typing import Union
label_desc: Use image node_id 8 for calling a global function with example usage: test_base_xc() and returns: int, densinfo, unknown, ValGrad, SpinParam