text: import numpy as np
  import unittest as ut
  from pymatgen.core import Structure
  
  from gulpy.parser import PropertyParser
  from gulpy.tests.test_files import get_jobs_path
  
  
  class TestParser(ut.TestCase):
      def setUp(self):
          self.parser = PropertyParser.from_file(get_jobs_path("opti/opti.out"))
  
      def test_energy(self):
          energy = self.parser.get_total_energy()
          self.assertAlmostEqual(energy, 64.96556639)
  
      def test_gnorm(self):
          gnorm = self.parser.get_gnorm()
          self.assertAlmostEqual(gnorm, 0.06196731)
  
      def test_forces(self):
          forces = self.parser.get_forces()
          expected = np.array(
              [
                  [0.0, 0.0, 0.0],
                  [-0.387258, 0.093689, 0.394395],
                  [-0.896822, -0.12375, 1.453414],
                  [1.618065, -0.326868, -0.452557],
                  [1.105003, -0.032019, -0.439538],
                  [-0.759763, -0.719213, 1.581617],
                  [-0.955828, 1.2576, 0.231461],
                  [1.757391, 0.262405, -0.594044],
                  [0.295398, 0.211838, -0.663752],
                  [0.610843, 0.118788, 0.36887],
                  [0.55901, 0.408809, -0.227457],
                  [0.858013, 0.713356, -0.421261],
                  [0.114318, -0.202245, 0.468065],
                  [0.83848, -0.266996, 0.099431],
                  [0.463503, 1.568871, 0.45566],
                  [1.156542, -2.230208, -0.451059],
                  [-0.448934, -0.004926, 1.324632],
                  [-1.750594, 0.408236, 0.490186],
                  [0.606139, -0.464203, 1.040305],
                  [0.050715, 2.563783, -0.211531],
                  [1.519719, 2.36851, -0.773054],
                  [-2.099729, -0.783024, -0.413724],
                  [-1.163505, 2.125563, 0.890413],
                  [-2.04974, -0.81819, 0.275395],
                  [0.55874, 0.274417, -0.890798],
                  [1.664559, -0.01941, 0.803535],
                  [-0.048858, -0.990278, 0.072035],
                  [0.834273, 1.119567, 0.87864],
                  [0.324585, 1.361399, -0.88704],
                  [1.03088, 0.298807, -0.084887],
                  [-1.265051, 0.223289, -0.227219],
                  [0.463642, -0.424615, -0.453406],
                  [0.249503, -0.007009, -1.076549],
                  [-1.149132, 0.73669, 0.967303],
                  [0.268017, -1.123431, 0.996581],
                  [0.556217, -0.154014, -1.53402],
                  [-0.437601, 1.244243, 1.095098],
                  [1.829769, 0.005225, -1.622051],
                  [-0.330368, 1.29028, -0.144306],
                  [-2.27066, -0.175534, 0.051256],
                  [-0.05703, -0.044373, -0.080505],
                  [0.416234, -0.199574, 0.653428],
                  [-1.55323, -0.12434, 0.084707],
                  [-0.433382, 0.4281, -0.13505],
                  [1.35876, -0.797423, -0.245319],
                  [1.834978, -0.265982, -0.537853],
                  [-1.421389, -1.032188, -0.040865],
                  [-0.625389, 0.986259, -0.459034],
                  [0.240487, 0.014509, -0.576225],
                  [0.445477, -1.81194, -0.445743],
                  [1.007841, -1.382439, 0.447577],
                  [-0.617767, 0.001238, 0.551667],
                  [-0.663682, -2.399935, 1.636502],
                  [0.28817, 0.89075, 0.191394],
                  [1.266309, -1.767119, -3.043321],
                  [-1.969741, 0.283925, 0.353232],
                  [-0.990191, 0.533348, 0.838281],
                  [0.116768, -2.039235, 0.628164],
                  [0.091945, 0.75052, -0.090315],
                  [-0.315935, -2.956508, -0.596073],
                  [0.654498, -2.201653, -0.998757],
                  [0.623819, 2.721624, 1.638445],
                  [-0.705262, -1.370562, 0.673264],
                  [-1.681741, 1.36346, -0.58843],
                  [-0.068993, 1.756455, -0.253828],
                  [-0.76088, -1.061419, -0.23681],
                  [-0.881444, -0.721499, 1.678562],
                  [-0.117748, 0.743562, -0.20098],
                  [0.587609, 0.920006, 0.160085],
                  [-0.187421, -0.457742, -0.199789],
                  [0.311244, 0.126507, 0.355203],
                  [1.120808, 0.53584, 0.136662],
                  [0.342458, 0.164921, -0.772853],
                  [-0.003866, 1.063254, -0.256374],
                  [0.455563, 0.5808, 0.976658],
                  [0.273035, -1.532881, 0.40261],
                  [0.584145, -1.647421, -0.64688],
                  [1.869665, 1.584083, 0.81767],
                  [-2.14088, 0.440547, 0.159171],
                  [0.590435, 0.915912, -0.511554],
                  [-0.501098, -1.502683, -0.34358],
                  [3.468161, 3.837232, 0.45792],
                  [0.460531, 1.97354, -0.281651],
                  [0.585463, 0.055554, 0.938356],
                  [0.8791, -1.056964, -1.442219],
                  [-0.559255, 1.030603, 0.397851],
                  [0.461654, 0.037181, 0.410091],
                  [0.604035, 1.025312, -0.18418],
                  [0.384341, 0.081009, 0.744512],
                  [1.02119, 0.252009, -0.522866],
                  [-0.702947, 0.254653, -0.070509],
                  [-0.792489, 0.546119, 0.065616],
                  [1.027064, -0.036685, -0.233605],
                  [1.674752, 0.029745, 0.27757],
                  [3.108625, -0.136837, 0.130762],
                  [-0.782352, 0.532902, 0.182889],
                  [0.307184, -0.063277, -0.309267],
                  [-0.185505, -0.675936, 0.0228],
                  [-0.154145, -0.234811, 0.218195],
                  [-1.248542, -3.696221, 0.224338],
                  [-0.210572, 0.845342, -0.627673],
                  [-1.244547, 4.015659, -1.584986],
                  [-1.331348, -3.325653, -1.169705],
                  [-0.65521, 3.5257, -0.015439],
                  [0.002675, 0.745161, -0.576127],
                  [1.206908, 3.841573, -0.464306],
                  [-0.099767, 1.117261, -0.730944],
                  [-0.477405, -3.637131, 0.394661],
                  [-0.33896, -2.161714, 0.421189],
                  [0.087939, 2.397557, -0.470203],
                  [-4.69355, -7.849701, 1.691899],
                  [-1.959175, -0.178852, 0.305573],
                  [-1.668907, 1.18954, 0.380527],
                  [-0.544313, 0.209037, -1.173295],
                  [-2.055495, -0.117865, 0.102083],
                  [-0.288384, 1.374266, 1.788399],
                  [-0.593341, 1.580728, 0.126094],
                  [-0.284464, 0.185639, -1.967671],
                  [-0.828095, 0.214388, 0.012714],
                  [1.765819, -1.46505, -2.530304],
                  [-0.413248, 0.011866, 0.390915],
                  [-0.625163, 1.977248, -0.139662],
                  [0.753556, -0.090044, 0.158027],
                  [-1.292191, 3.05782, 0.774564],
                  [-1.973741, 0.198268, -1.052683],
                  [1.185924, 0.347183, -0.484726],
                  [-0.63072, 0.032331, -0.299781],
                  [-0.483476, -1.171825, 0.237545],
                  [3.223745, 3.422334, 1.168072],
                  [0.306475, 1.109381, 0.090098],
              ]
          )
          self.assertIsNone(
              np.testing.assert_almost_equal(np.array(forces), expected, decimal=5)
          )
  
  
  class TestMoleculeParser(ut.TestCase):
      def setUp(self):
          self.parser = PropertyParser.from_file(get_jobs_path("opti/molecule.out"))
  
      def test_energy(self):
          energy = self.parser.get_total_energy()
          self.assertAlmostEqual(energy, 2.91123336)
  
      def test_gnorm(self):
          gnorm = self.parser.get_gnorm()
          self.assertAlmostEqual(gnorm, 0.00005011)
  
      def test_forces(self):
          forces = self.parser.get_forces()
          expected = np.array(
              [
                  [-0.000292, -0.000816, -0.000127],
                  [-0.000291, 0.000225, -0.000349],
                  [0.000673, 0.000628, 0.000538],
                  [0.00126, 0.000221, 0.001868],
                  [0.0, 0.0, 0.0],
                  [-0.000169, -9.9e-05, -0.000341],
                  [-1.6e-05, 3.8e-05, -8.3e-05],
                  [8.3e-05, 9e-06, -0.000147],
                  [0.00013, 0.001458, -9.6e-05],
                  [-7.8e-05, 2e-06, -9.6e-05],
                  [-0.001363, -6.8e-05, 0.000149],
                  [-0.000151, -1.3e-05, -0.00017],
                  [5.8e-05, -0.000332, 1e-05],
                  [-3.9e-05, 0.000198, -0.000434],
                  [-0.000182, 0.000627, -0.000116],
                  [-0.001143, -0.000644, -0.000636],
                  [0.000693, 9.6e-05, 0.001044],
                  [-0.000315, 0.000586, 0.001007],
                  [0.001345, -0.000708, -0.000678],
                  [-0.000798, -0.00118, -9.5e-05],
                  [0.000252, 0.000439, -0.001153],
                  [-0.000874, 0.001046, -0.000392],
                  [-0.000473, -0.000191, 0.001084],
                  [0.000186, 1.1e-05, -0.000201],
                  [-0.000106, -0.000101, -0.000215],
                  [0.000368, -0.000196, 3.5e-05],
                  [8.5e-05, -4e-06, -3.7e-05],
                  [9.1e-05, -0.000242, 0.000201],
                  [-0.000169, -0.001045, 0.000271],
                  [-0.000343, 8.6e-05, -7.4e-05],
                  [0.000157, 4e-06, 5.8e-05],
                  [0.00093, 0.000185, 0.000311],
                  [0.000246, -7.8e-05, 0.000329],
                  [8e-06, -0.000136, -1e-06],
                  [0.000223, -0.000103, -0.000414],
                  [-5e-06, 0.000208, -0.000106],
                  [0.000202, -7.8e-05, -0.00031],
                  [-0.000136, -2.8e-05, -0.000384],
              ]
          )
          self.assertIsNone(
              np.testing.assert_almost_equal(np.array(forces), expected, decimal=5)
          )
  
  
  if __name__ == "__main__":
      ut.main()
  