Ejemplo n.º 1
0
 def test_int_creation(self):
     """
     Test that strings of ints are recreated as ints
     """
     obj = recursive_make_object('5', self.class_dictionary)
     self.assertEqual(obj, 5)
     self.assertEqual(type(obj), int)
Ejemplo n.º 2
0
 def test_float_creation(self):
     """
     Test that strings of floats are recreated as floats
     """
     obj = recursive_make_object('5.0', self.class_dictionary)
     self.assertEqual(obj, 5.0)
     self.assertEqual(type(obj), float)
Ejemplo n.º 3
0
    def test_make_object_from_dict(self):
        """
        Test that RMGObjects can be recreated from their dictionary representation
        """
        created_from_function = recursive_make_object(
            self.highly_nest_dictionary, self.class_dictionary)
        created_from_object = PseudoRMGObject.__new__(PseudoRMGObject)
        created_from_object.make_object(self.highly_nest_dictionary,
                                        self.class_dictionary)
        orig_obj = self.highly_nested_object

        for obj in (created_from_function, created_from_object):
            self.assertEqual(orig_obj.b, obj.b)
            self.assertEqual(type(orig_obj.a), type(obj.a))
            self.assertEqual(type(orig_obj.a.a), type(obj.a.a))
            self.assertTrue(np.array_equal(orig_obj.a.a.b, obj.a.a.b))
            self.assertEqual(type(orig_obj.a.a.c), type(obj.a.a.c))
            self.assertEqual(orig_obj.a.a.c.c.units, obj.a.a.c.c.units)
            self.assertTrue(
                np.array_equal(orig_obj.a.a.c.c.value, obj.a.a.c.c.value))
            self.assertEqual(type(orig_obj.a.a.c.d), type(obj.a.a.c.d))
            self.assertEqual(orig_obj.a.a.c.d.a.units, obj.a.a.c.d.a.units)
            self.assertTrue(orig_obj.a.a.c.d.a.value, obj.a.a.c.d.a.value)
            self.assertEqual(type(orig_obj.a.a.c.d.b),
                             type(orig_obj.a.a.c.d.b))
Ejemplo n.º 4
0
 def test_np_array_creation(self):
     """
     Test that numpy arrays can be recreated from their dictionary representation
     """
     self.assertTrue(
         np.array_equal(
             recursive_make_object(self.np_dict, self.class_dictionary),
             self.np_array))
Ejemplo n.º 5
0
 def test_make_all_but_final_object_from_dict(self):
     """
     Test the `make_final_object=False` option for the recursive_make_object function
     """
     final_obj_dict = recursive_make_object(self.input_dict,
                                            self.class_dictionary,
                                            make_final_object=False)
     self.assertTrue(
         np.array_equal(final_obj_dict['a'].b, self.final_obj_dict['a'].b))
Ejemplo n.º 6
0
    def test_hashable_class_key_creation(self):
        """
        Test that dictionaries with hashable class instances as keys can be recreated
        """
        @dataclass(frozen=True)
        class Data:
            arg: str

        input_dict = {"Data(arg='test')": 'test'}
        class_dictionary = {'Data': Data}
        key, val = list(
            recursive_make_object(input_dict, class_dictionary).items())[0]

        self.assertIsInstance(key, Data)
        self.assertEqual(key, Data('test'))
        self.assertEqual(val, 'test')
Ejemplo n.º 7
0
from arkane.encorr.reference import ReferenceSpecies, ReferenceDatabase
from arkane.exceptions import BondAdditivityCorrectionError
from arkane.modelchem import LevelOfTheory, CompositeLevelOfTheory

# ######## Database loading ##########
quantum_corrections_path = os.path.join(settings['database.directory'],
                                        'quantum_corrections', 'data.py')
spec = importlib.util.spec_from_file_location("quantum_calculations",
                                              quantum_corrections_path)
data = importlib.util.module_from_spec(spec)
spec.loader.exec_module(data)

# Convert module to dictionary and create level of theory objects from their string representations
data_dict = recursive_make_object(
    {k: v
     for k, v in vars(data).items() if not k.startswith('__')}, {
         'LevelOfTheory': LevelOfTheory,
         'CompositeLevelOfTheory': CompositeLevelOfTheory
     })

# Assign the data here so that it can be imported
for k, v in data_dict.items():
    vars()[k] = v
######################################

# ########## Data classes ############
BOND_SYMBOLS = {1: '-', 2: '=', 3: '#'}


class Molecule(RMGMolecule):
    """Wrapper for RMG Molecule to add ID attribute"""
    def __init__(self, *args, mol_id=None, **kwargs):