Exemple #1
0
 def test_length(self):
     """
     Similar to FloatWithUnitTest.test_time.
     Check whether EnergyArray and FloatWithUnit have same behavior.
     """
     x = LengthArray(4.2, "ang")
     self.assertAlmostEqual(float(x.to("cm")), 4.2e-08)
     self.assertEqual(float(x.to("pm")), 420)
     self.assertEqual(str(x / 2), "2.1 ang")
Exemple #2
0
 def test_length(self):
     """
     Similar to FloatWithUnitTest.test_time.
     Check whether EnergyArray and FloatWithUnit have same behavior.
     """
     x = LengthArray(4.2, "ang")
     self.assertAlmostEqual(x.to("cm"), 4.2e-08)
     self.assertEqual(x.to("pm"), 420)
     self.assertEqual(str(x / 2), "2.1 ang")
Exemple #3
0
 def test_factors(self):
     e = EnergyArray([27.21138386, 1], "eV").to("Ha")
     self.assertTrue(str(e).endswith("Ha"))
     l = LengthArray([1.0], "ang").to("bohr")
     self.assertTrue(str(l).endswith(" bohr"))
     v = ArrayWithUnit([1, 2, 3], "bohr^3").to("ang^3")
     self.assertTrue(str(v).endswith(' ang^3'))
Exemple #4
0
def from_file(name):
    # ---------- last structure
    with open(name, 'r') as f:
        lines = f.readlines()
    lines = lines[-(rin.natot + 5):]

    # ---------- lattice
    lattice = [[float(x) for x in line.split()] for line in lines[1:4]
               ]  # in Bohr, each column is a lattice vector
    lattice = np.array(LengthArray(lattice, 'bohr').to('ang'))  # Bohr --> Ang
    lattice = lattice.T  # each row is a lattice vector

    # ---------- internal coordinates
    coords = [[float(x) for x in line.split()] for line in lines[5:]]

    # ---------- species
    species = [
        itertools.repeat(typ, times=num)
        for typ, num in zip(rin.atype, rin.nat)
    ]
    species = list(itertools.chain.from_iterable(species))

    structure = Structure(lattice, species, coords)

    return structure
Exemple #5
0
 def test_factors(self):
     e = EnergyArray([27.21138386, 1], "eV").to("Ha")
     self.assertTrue(str(e) == "[ 0.99999996  0.03674932] Ha")
     l = LengthArray([1.0], "ang").to("bohr")
     self.assertTrue(str(l) == "[ 1.88972612] bohr")
     v = ArrayWithUnit([1, 2, 3], "bohr^3").to("ang^3")
     self.assertTrue(str(v) == '[ 0.14818471  0.29636942  0.44455413] ang^3')