コード例 #1
0
def add_builtin_symbols_to_registry():
    for f in _DEFAULT_SYMBOL_TYPE_FILES:
        d = loadfn(f)
        d['is_builtin'] = True
        d['overwrite_registry'] = True
        symbol_type = Symbol.from_dict(d)
        if "{}.yaml".format(symbol_type.name) not in f:
            raise ValueError('Name/filename mismatch in {}'.format(f))

    # This is just to enable importing this module
    for name, symbol in Registry("symbols").items():
        if symbol.is_builtin:
            globals()[name] = symbol
コード例 #2
0
ファイル: test_symbols.py プロジェクト: yoshida-lab/propnet
    def test_property_construction(self):
        sample_symbol_type_dict = {
            'name': 'youngs_modulus',
            'units': [1.0, [["gigapascal", 1.0]]],
            'display_names': ["Young's modulus", "Elastic modulus"],
            'display_symbols': ["E"],
            'shape': 1,
            'comment': ""
        }

        sample_symbol_type = Symbol(
            name='youngs_modulus',  #
            units=[1.0, [["gigapascal", 1.0]]],  #ureg.parse_expression("GPa"),
            display_names=["Young's modulus", "Elastic modulus"],
            display_symbols=["E"],
            shape=1,
            comment="")

        self.assertEqual(sample_symbol_type,
                         Symbol.from_dict(sample_symbol_type_dict))
コード例 #3
0
ファイル: __init__.py プロジェクト: yoshida-lab/propnet
from glob import glob
from monty.serialization import loadfn

from propnet.core.symbols import Symbol

# Auto loading of all allowed properties

# stores all loaded properties as PropertyMetadata instances in a dictionary,
# mapped to their names
DEFAULT_SYMBOLS = {}
DEFAULT_SYMBOL_VALUES = {}

_DEFAULT_SYMBOL_TYPE_FILES = glob(
    os.path.join(os.path.dirname(__file__), '../symbols/**/*.yaml'),
    recursive=True)

for f in _DEFAULT_SYMBOL_TYPE_FILES:
    symbol_type = Symbol.from_dict(loadfn(f))
    DEFAULT_SYMBOLS[symbol_type.name] = symbol_type
    if symbol_type.default_value is not None:
        DEFAULT_SYMBOL_VALUES[symbol_type] = symbol_type.default_value
    if "{}.yaml".format(symbol_type.name) not in f:
        raise ValueError('Name/filename mismatch in {}'.format(f))

# Stores all loaded properties' names in a tuple in the global scope.
DEFAULT_UNITS = {name: symbol.units
                 for name, symbol in DEFAULT_SYMBOLS.items()}
DEFAULT_SYMBOL_TYPE_NAMES = tuple(DEFAULT_SYMBOLS.keys())

for name, symbol in DEFAULT_SYMBOLS.items():
    globals()[name] = symbol