def test_element_input_equivalence(): """Test that the constructor for `Element` supports atomic numbers, strings, and other `Element`s""" expected = Element("H") assert Element("H") == expected assert Element("Hydrogen") == expected assert Element("hydrogen") == expected # not case sensitive assert Element(1) == expected assert Element(expected) == expected
def test_input_equivalence(self): """ Test that the constructor for `Element` supports atomic numbers, strings, and other `Element`s """ expected = Element("H") self.assertEqual(Element("H"), expected) self.assertEqual(Element("Hydrogen"), expected) self.assertEqual(Element("hydrogen"), expected) # not case sensitive self.assertEqual(Element(1), expected) self.assertEqual(Element(expected), expected)
def affe(atom, nG): """ Atomic form factors for electrons, for neutral atoms. Parameters ---------- atom : skued.Atom, int, or str Atomic number, atomic symbol, or Atom instance. Atomic symbols are expected to be properly capitalized, e.g. ``As`` or ``W``. nG : array_like Scattering vector norm, in units of Angstroms:math:`^{-1}`. (:math:`|G| = 4 \pi s`). Returns ------- eff : `~numpy.ndarray`, dtype float Atomic form factor for electron scattering. Raises ------ ValueError : scattering information is not available, for example if the atomic number is larger than 103 """ if isinstance(atom, (int, str)): atom = Element(atom) atomic_number = atom.atomic_number try: _, a1, b1, a2, b2, a3, b3, c1, d1, c2, d2, c3, d3 = scattering_params[ atomic_number ] except KeyError: raise ValueError( "Scattering information for element Z={} is unavailable.".format( atomic_number ) ) # Parametrization of form factors is done in terms of q = 2 s = 2 pi |G| q = nG / (2 * np.pi) q2 = np.square(q) sum1 = a1 / (q2 + b1) + a2 / (q2 + b2) + a3 / (q2 + b3) sum2 = c1 * np.exp(-d1 * q2) + c2 * np.exp(-d2 * q2) + c3 * np.exp(-d3 * q2) return sum1 + sum2
def aspherical_affe(atom, s): """ Aspherical atomic form factors for electron scattering. Only atoms lighter than Xe (and including) are supported (Z <= 54). Parameters ---------- atom : skued.Atom, int, or str Atomic number, atomic symbol, or Atom instance. Atomic symbols are expected to be properly capitalized, e.g. ``As`` or ``W``. s : array_like Scattering vector norm Returns ------- eff : `~numpy.ndarray`, dtype float Atomic form factor for electron scattering. Raises ------ ValueError : scattering information is not available, for example if the atomic number is larger than 54 References ---------- .. [#] Jin-Cheng Zheng, Lijun Wu and Yimei Zhu. "Aspherical electron scattering factors and their parameterizations for elements from H to Xe" (2009). J. Appl. Cryst. vol 42, pp. 1043 - 1053. """ if isinstance(atom, (int, str)): atom = Element(atom) element = atom.element params_a = aspherical_ff[element]["total"]["a"] params_b = aspherical_ff[element]["total"]["b"] s2 = np.square(np.asfarray(s)) result = np.zeros_like(s2) for a, b in zip(params_a, params_b): result += a * np.exp(-b * s2) return result
nat = ntype(my_crystal) print (" ntyp= ",nat,",",sep="") print (" ecutwfc=80.0,") print (" ecutrho=800.0,") print (' xdm=.true.,') print (" xdm_a1=0.6512,") print (" xdm_a2=1.4633,\n/") print ("&electrons") print (" conv_thr = 1d-8\n/\n&ions\n/\n&cell\n/") print ("ATOMIC_SPECIES") for atm in my_crystal.chemical_composition: ELE = str(atm) ele = ELE.lower() mass_number = Element(ele).mass print (ele, " ",mass_number," ",ele,'.UPF',sep="") print('\nATOMIC_POSITIONS crystal') #print('\nATOMIC_POSITIONS angstrom') ################### loops for bottom layer ################## ############################################################# bt0 = time.time() bt1 = time.time() tt1 = [] tt2 = []
def test_init_with_atomic_number(self): """ Test that constructing an Element from a symbol or atomic number results in the same element """ for symbol in chemical_symbols: from_symbol = Element(symbol) from_number = Element(from_symbol.atomic_number) self.assertEqual(from_number, from_symbol)
def test_invalid_element(self): """ Test that an invalid chemical symbol will raise an error """ with self.assertRaises(ValueError): Element("montreal")
def test_build(self): """ Test that all valid chemical symbols can be used to create an Element instance """ for symbol in chemical_symbols: Element(symbol)
def test_atomic_number_out_of_range(self): """ Test that constructing an Element from an atomic number out-of-range raises a ValueError """ with self.assertRaises(ValueError): Element(256)
def test_element_atomic_number_out_of_range(): """Test that constructing an Element from an atomic number out-of-range raises a ValueError""" with pytest.raises(ValueError): Element(256)
def test_element_init_with_atomic_number(symbol): """Test that constructing an Element from a symbol or atomic number results in the same element""" from_symbol = Element(symbol) from_number = Element(from_symbol.atomic_number) assert from_number == from_symbol
def test_element_invalid_element(): """Test that an invalid chemical symbol will raise an error""" with pytest.raises(ValueError): Element("montreal")
def test_element_build(symbol): """Test that all valid chemical symbols can be used to create an Element instance""" Element(symbol)