def test_set_radial_none(self): rf = r_f(6) o = SphericalOrbital(1, rf) o.set_radial() r = np.linspace(0, 6, 400) r0 = o.radial(r) assert np.allclose(r0, 0)
def read_basis(self): """ Returns data associated with the ion.xml file """ # Get the element-tree ET = ElementTree(None, self.file) root = ET.getroot() # Get number of orbitals label = root.find('label').text.strip() Z = int(root.find('z').text) # atomic number mass = float(root.find('mass').text) # Read in the PAO's paos = root.find('paos') # Now loop over all orbitals orbital = [] # All orbital data Bohr2Ang = unit_convert('Bohr', 'Ang') for orb in paos: n = int(orb.get('n')) l = int(orb.get('l')) z = int(orb.get('z')) # zeta q0 = float(orb.get('population')) P = not int(orb.get('ispol')) == 0 # Radial components rad = orb.find('radfunc') npts = int(rad.find('npts').text) # Grid spacing in Bohr (conversion is done later # because the normalization is easier) delta = float(rad.find('delta').text) # Read in data to a list dat = list(map(float, rad.find('data').text.split())) # Since the readed data has fewer significant digits we # might as well re-create the table of the radial component. r = aranged(npts) * delta # To get it per Ang**3 # TODO, check that this is correct. # The fact that we have to have it normalized means that we need # to convert psi /sqrt(Bohr**3) -> /sqrt(Ang**3) # \int psi^\dagger psi == 1 psi = arrayd(dat[1::2]) * r**l / Bohr2Ang**(3. / 2.) # Create the sphericalorbital and then the atomicorbital sorb = SphericalOrbital(l, (r * Bohr2Ang, psi), q0) # This will be -l:l (this is the way siesta does it) orbital.extend(sorb.toAtomicOrbital(n=n, Z=z, P=P)) # Now create the atom and return return Atom(Z, orbital, mass=mass, tag=label)
def test_phi1(self): rf = r_f(6) r = np.linspace(0, 6, 999).reshape(-1, 3) for l in range(5): so = SphericalOrbital(l, rf) for m in range(-l, l + 1): o = AtomicOrbital(l=l, m=m, spherical=rf) assert np.allclose(so.psi(r, m), o.psi(r))
def test_radial1(self): rf = r_f(6) r = np.linspace(0, 6, 100) for l in range(5): so = SphericalOrbital(l, rf) sor = so.radial(r) for m in range(-l, l + 1): o = AtomicOrbital(l=l, m=m, spherical=rf) assert np.allclose(sor, o.radial(r)) o.set_radial(rf[0], rf[1]) assert np.allclose(sor, o.radial(r))
def read_basis(self): """ Returns data associated with the ion.xml file """ no = len(self._dimension('norbs')) # Get number of orbitals label = self.Label.strip() Z = int(self.Atomic_number) mass = float(self.Mass) # Retrieve values orb_l = self._variable('orbnl_l')[:] # angular quantum number orb_n = self._variable('orbnl_n')[:] # principal quantum number orb_z = self._variable('orbnl_z')[:] # zeta orb_P = self._variable( 'orbnl_ispol')[:] > 0 # polarization shell, or not orb_q0 = self._variable('orbnl_pop')[:] # q0 for the orbitals orb_delta = self._variable('delta')[:] # delta for the functions orb_psi = self._variable('orb')[:, :] # Now loop over all orbitals orbital = [] # All orbital data Bohr2Ang = unit_convert('Bohr', 'Ang') for io in range(no): n = orb_n[io] l = orb_l[io] z = orb_z[io] P = orb_P[io] # Grid spacing in Bohr (conversion is done later # because the normalization is easier) delta = orb_delta[io] # Since the readed data has fewer significant digits we # might as well re-create the table of the radial component. r = aranged(orb_psi.shape[1]) * delta # To get it per Ang**3 # TODO, check that this is correct. # The fact that we have to have it normalized means that we need # to convert psi /sqrt(Bohr**3) -> /sqrt(Ang**3) # \int psi^\dagger psi == 1 psi = orb_psi[io, :] * r**l / Bohr2Ang**(3. / 2.) # Create the sphericalorbital and then the atomicorbital sorb = SphericalOrbital(l, (r * Bohr2Ang, psi), orb_q0[io]) # This will be -l:l (this is the way siesta does it) orbital.extend(sorb.toAtomicOrbital(n=n, Z=z, P=P)) # Now create the atom and return return Atom(Z, orbital, mass=mass, tag=label)
def test_pickle1(self): rf = r_f(6) import pickle as p o0 = SphericalOrbital(1, rf) o1 = SphericalOrbital(2, rf) p0 = p.dumps(o0) p1 = p.dumps(o1) l0 = p.loads(p0) l1 = p.loads(p1) assert o0 == l0 assert o1 == l1 assert o0 != l1 assert o1 != l0
def test_init1(self): n = 6 rf = np.arange(n) rf = (rf, rf) assert SphericalOrbital(1, rf) == SphericalOrbital(1, rf) f = interp.interp1d(rf[0], rf[1], fill_value=(0., 0.), bounds_error=False, kind='cubic') rf = [rf[0], rf[0]] assert SphericalOrbital(1, rf) == SphericalOrbital(1, f) assert SphericalOrbital(1, rf, tag='none') != SphericalOrbital(1, rf) SphericalOrbital(5, rf) for l in range(10): o = SphericalOrbital(l, rf) assert l == o.l assert o == o.copy()
def test_radial1(self): rf = r_f(6) orb0 = SphericalOrbital(0, rf) orb1 = SphericalOrbital(1, rf) r = np.linspace(0, 6, 400) # Note r > n - 1 should be zero, regardless of the fill-value r0 = orb0.radial(r) r1 = orb1.radial(r) rr = np.stack((r, np.zeros(len(r)), np.zeros(len(r))), axis=1) r2 = orb1.radial(rr, is_radius=False) assert np.allclose(r0, r1) assert np.allclose(r0, r2) r[r >= rf[0].max()] = 0. assert np.allclose(r0, r) assert np.allclose(r1, r)
def test_toatomicorbital_q0(self): rf = r_f(6) orb = SphericalOrbital(0, rf, 2.) ao = orb.toAtomicOrbital() assert len(ao) == 1 assert ao[0].q0 == 2. # Check m and l for l in range(1, 5): orb = SphericalOrbital(l, rf, 2.) ao = orb.toAtomicOrbital() assert ao[0].q0 == pytest.approx(2. / (2 * l + 1))
def test_radial_func1(self): r = np.linspace(0, 4, 300) f = np.exp(-r) o = SphericalOrbital(1, (r, f)) str(o) def i_univariate(r, f): return interp.UnivariateSpline(r, f, k=5, s=0, ext=1, check_finite=False) def i_interp1d(r, f): return interp.interp1d(r, f, kind='cubic', fill_value=(f[0], 0.), bounds_error=False) def i_spline(r, f): from functools import partial tck = interp.splrep(r, f, k=5, s=0) return partial(interp.splev, tck=tck, der=0, ext=1) # Interpolation radius R = np.linspace(0, 5, 400) assert np.allclose(o.f(r), f) f_default = o.f(R) o.set_radial(r, f, interp=i_univariate) assert np.allclose(o.f(r), f) f_univariate = o.f(R) o.set_radial(r, f, interp=i_interp1d) assert np.allclose(o.f(r), f) f_interp1d = o.f(R) o.set_radial(r, f, interp=i_spline) assert np.allclose(o.f(r), f) f_spline = o.f(R) # Checks that they are equal assert np.allclose(f_univariate, f_interp1d) assert np.allclose(f_univariate, f_spline) assert np.allclose(f_univariate, f_default)
def test_set_radial1(self): rf = r_f(6) o = SphericalOrbital(1, rf) o.set_radial(1.)
def test_toatomicorbital2(self): rf = r_f(6) orb = SphericalOrbital(1, rf) ao = orb.toAtomicOrbital(2)
def test_togrid2(self): o = SphericalOrbital(1, r_f(6)) with pytest.raises(ValueError): o.toGrid(R=-1)
def test_togrid1(self): o = SphericalOrbital(1, r_f(6)) o.toGrid() o.toGrid(R=10)
def test_togrid2(self): o = SphericalOrbital(1, r_f(6)) o.toGrid(R=-1)
def test_toatomicorbital2(self): rf = r_f(6) orb = SphericalOrbital(1, rf) with pytest.raises(ValueError): ao = orb.toAtomicOrbital(2)
def test_toatomicorbital1(self): rf = r_f(6) orb = SphericalOrbital(0, rf) ao = orb.toAtomicOrbital() assert len(ao) == 1 assert ao[0].l == orb.l assert ao[0].m == 0 # Check m and l for l in range(1, 5): orb = SphericalOrbital(l, rf) ao = orb.toAtomicOrbital() assert len(ao) == 2 * l + 1 m = -l for a in ao: assert a.l == orb.l assert a.m == m m += 1 orb = SphericalOrbital(1, rf) ao = orb.toAtomicOrbital(1) assert ao.l == orb.l assert ao.m == 1 ao = orb.toAtomicOrbital(-1) assert ao.l == orb.l assert ao.m == -1 ao = orb.toAtomicOrbital(0) assert ao.l == orb.l assert ao.m == 0 ao = orb.toAtomicOrbital([0, -1, 1]) for a in ao: assert a.l == orb.l assert ao[0].m == 0 assert ao[1].m == -1 assert ao[2].m == 1
def test_same1(self): rf = r_f(6) o0 = SphericalOrbital(0, rf) o1 = Orbital(5.0) assert o0.equal(o1) assert not o0.equal(Orbital(3.))
def test_basic1(self): rf = r_f(6) orb = SphericalOrbital(1, rf) str(orb) orb = SphericalOrbital(1, rf, tag='none') str(orb)
def test_psi1(self): rf = r_f(6) orb0 = SphericalOrbital(0, rf) orb1 = SphericalOrbital(1, rf) r = np.linspace(0, 6, 333 * 3).reshape(-1, 3) p0 = orb0.psi(r) p1 = orb1.psi(r) assert not np.allclose(p0, p1) orb0 = SphericalOrbital(1, rf) assert orb0.equal(orb1, radial=True, psi=True) for m in range(orb0.l, orb0.l + 1): p0 = orb0.psi(r, -1) p1 = orb1.psi(r, -1) assert np.allclose(p0, p1) p0 = orb0.psi(r, -1) p1 = orb1.psi(r, 1) assert not np.allclose(p0, p1)
def test_set_radial1(self): rf = r_f(6) o = SphericalOrbital(1, rf) with pytest.raises(ValueError): o.set_radial(1.)