Пример #1
0
 def __init__(self, f_path: str, unit: str = 'kJ/mol'):
     super().__init__(f_path)
     self.unit = unit
     self.energies = []
     with open(f_path) as f:
         for line in f:
             stripped = line.strip()
             if stripped:
                 self.energies.append(EnergyUnitConverter(float(stripped), unit))
Пример #2
0
class TestEnergyUnitConverter(unittest.TestCase):
    def setUp(self):
        self.converter = EnergyUnitConverter(4.0)

    def test_creation_wrong_units(self):
        with self.assertRaises(AssertionError):
            EnergyUnitConverter(5, 'j/mol')

    def test_creation_wrong_value_type(self):
        with self.assertRaises(AssertionError):
            EnergyUnitConverter([])

    def test_creation_float_kj(self):
        self.assertEqual(EnergyUnitConverter(5.), 5)

    def test_creation_float_kcal(self):
        self.assertAlmostEqual(EnergyUnitConverter(5., 'kcal/mol'),
                               20.934,
                               places=3)

    def test_creation_int_kj(self):
        self.assertEqual(EnergyUnitConverter(5), 5)

    def test_creation_int_kcal(self):
        self.assertAlmostEqual(EnergyUnitConverter(5, 'kcal/mol'),
                               20.934,
                               places=3)

    def test_get_energy_in_unit_kj_per_mol(self):
        self.assertAlmostEqual(4.0,
                               self.converter.get_energy_in_unit('kJ/mol'))

    def test_get_energy_in_unit_kcal_per_mol(self):
        self.assertAlmostEqual(0.95538358,
                               self.converter.get_energy_in_unit('kcal/mol'))

    def test_get_energy_in_unit_unsupported(self):
        with self.assertRaises(NotImplementedError):
            self.converter.get_energy_in_unit('cal/mol')
Пример #3
0
 def read(self):
     with open(self.path) as f:
         data = yaml.safe_load(f)
     energy_unit = data[-1]['energy_unit']
     angle_unit = data[-1]['angle_unit']
     assert angle_unit == 'degree'  # todo support for radian
     energies = [{
         'energy':
         EnergyUnitConverter(energy_dict['energy'],
                             energy_unit).get_energy_in_unit('kJ/mol'),
         'dihedrals':
         energy_dict['dihedrals']
     } for energy_dict in data[:-1]]
     return energies
Пример #4
0
 def test_energy_values(self):
     self.assertListEqual(
         [EnergyUnitConverter(3.93),
          EnergyUnitConverter(3.86)], self.reader.energies)
Пример #5
0
 def setUp(self):
     self.converter = EnergyUnitConverter(4.0)
Пример #6
0
 def test_creation_int_kcal(self):
     self.assertAlmostEqual(EnergyUnitConverter(5, 'kcal/mol'),
                            20.934,
                            places=3)
Пример #7
0
 def test_creation_int_kj(self):
     self.assertEqual(EnergyUnitConverter(5), 5)
Пример #8
0
 def test_creation_wrong_value_type(self):
     with self.assertRaises(AssertionError):
         EnergyUnitConverter([])
Пример #9
0
 def test_creation_wrong_units(self):
     with self.assertRaises(AssertionError):
         EnergyUnitConverter(5, 'j/mol')