Exemplo n.º 1
0
 def test_area(self):
     # Test areas when radius >= 0
     self.assertTrue(
         np.array(qmech.Qmech().angular_momentum(0.5)['x'] == np.matrix(
             '0,.5;.5,0')).all())
     self.assertTrue(
         np.array(qmech.Qmech().angular_momentum(0.5)['y'] == 1j *
                  np.matrix('0.,.5;0-.5,0')).all())
     self.assertTrue(
         np.array(qmech.Qmech().angular_momentum(0.5)['z'] == np.matrix(
             '.5,0;0,-0.5')).all())
Exemplo n.º 2
0
    def __init__(self, species):
        """ Constructor method """
        if type(species) not in [str]:
            raise TypeError("Species must be a string")

        self.__ub = spc["Bohr magneton"][0]
        self.__un = spc["nuclear magneton"][0]
        self.__h = spc["Planck constant"][0]

        #try:
        #   with open('../../species.json', 'r') as f:
        #      species_string = f.read()
        # sp = json.loads(species_string)
        #except FileNotFoundError:
        #   "The species json file is not present in the package directory"
        with open('../../species.json', 'r') as f:
            species_string = f.read()
        sp = json.loads(species_string)
        self.__ss = sp[species]

        self.__MJ = int((self.__ss['J'] * 2) + 1)
        self.__MI = int((self.__ss['I'] * 2) + 1)

        self.__qm = qm.Qmech()

        # self.__logger = logger.Logger().logger('../../spinhamiltonianlog')
        # print(self.__logger)
        return
Exemplo n.º 3
0
    def __init__(self,species):
        """ Constructor method """
        if type(species) not in [str]:
            raise TypeError("Species must be a string")

        self.ub = spc["Bohr magneton"][0]
        self.un = spc["nuclear magneton"][0]
        self.h = spc["Planck constant"][0]
        
        try:
           with open('../../species.json', 'r') as f:
               species_string = f.read()    
           sp = json.loads(species_string)
        except FileNotFoundError:
           "The species json file is not present in the package directory"
        self.ss = sp[species]
        
        self.MJ = int((self.ss['J']*2)+1)
        self.MI = int((self.ss['I']*2)+1)
        
        self.qm = qm.Qmech()
        
        return
Exemplo n.º 4
0
 def test_types(self):
     # Make sure type errors are raised when necessary
     self.assertRaises(TypeError, qmech.Qmech().enlarge_matrix, 'm', 'j')
     self.assertRaises(TypeError, qmech.Qmech().enlarge_matrix, True, True)
     self.assertRaises(TypeError, qmech.Qmech().enlarge_matrix, None, None)
Exemplo n.º 5
0
 def test_expand(self):
     # Test size of expanded matrices is correct
     sx = qmech.Qmech().angular_momentum(.5)['x']
     self.assertTrue(np.shape(qmech.Qmech().enlarge_matrix(1, sx)), (2, 2))
     self.assertTrue(np.shape(qmech.Qmech().enlarge_matrix(2, sx)), (4, 4))
     self.assertTrue(np.shape(qmech.Qmech().enlarge_matrix(3, sx)), (6, 6))
Exemplo n.º 6
0
 def test_types(self):
     # Make sure type errors are raised when necessary
     self.assertRaises(TypeError, qmech.Qmech().angular_momentum, 1j)
     self.assertRaises(TypeError, qmech.Qmech().angular_momentum, "J")
     self.assertRaises(TypeError, qmech.Qmech().angular_momentum, True)
     self.assertRaises(TypeError, qmech.Qmech().angular_momentum, None)
Exemplo n.º 7
0
 def test_values(self):
     # Make sure errors are raised when necessary
     self.assertRaises(ValueError, qmech.Qmech().angular_momentum, -1)