# Path: pyoptools/raytrace/mat_lib/mat_eq.py
# def from_yml(filename):
#     """Create a material instance from a YML file as defined at
#        https://refractiveindex.info/about
#     """
#     with open(filename) as f:
#         mat = yaml.load(f, Loader=yaml.FullLoader)
# 
#     for c in mat["DATA"]:
#         if "formula" in c["type"]:
#             break
#     else:
#         # The else belongs to the for, and is used to check the break was
#         # not used
#         raise ModelNotImplemented
# 
#     fn = int(c["type"].split()[1]) - 1
# 
#     coef = numpy.fromiter(c["coefficients"].split(), dtype=numpy.float)
# 
#     # Sometimes SPECS does not exists
#     nd = mat.get("SPECS", {}).get("nd", None)
#     vd = mat.get("SPECS", {}).get("Vd", None)
#     return __models__[fn](coef, nd, vd)
# 
# class ModelNotImplemented(Exception):
#     """Indicates that the model to calculate the index of refraction is not
#     implemented yet"""
#     pass


from os import walk
from os.path import join, expanduser, relpath
from pkg_resources import resource_filename
from .mat_eq import from_yml, ModelNotImplemented
from configparser import ConfigParser

# Note: If a home library has the same name as a system library, all the
# glasses defined will be merged in the same library

libset = list(set(libnames+["main"]+homelibnames))
liblist = []

for libname in libset:
    # Create the dictionaries where the materials will be saved. One dictionary
    # per library,
    globals()[libname] = {}
    liblist.append((libname, globals()[libname]))

liblist.sort()

# Fill the dictionaries with the current materials system wide, and then with
# the materials defined in the home of the user

for npath in [libpath, homelibpath]:

    for (dirpath, dirnames, filenames) in walk(npath):
        library = (relpath(dirpath, npath)).replace("/","_")
        # Exclude some names that are not libraries
        if library in [".", ]:
            continue

        for name in filenames:
            try:
                matname = name.split(".")[0]
                globals()[library][matname] = from_yml(join(dirpath, name))

# Path: pyoptools/raytrace/mat_lib/mat_eq.py
# def from_yml(filename):
#     """Create a material instance from a YML file as defined at
#        https://refractiveindex.info/about
#     """
#     with open(filename) as f:
#         mat = yaml.load(f, Loader=yaml.FullLoader)
# 
#     for c in mat["DATA"]:
#         if "formula" in c["type"]:
#             break
#     else:
#         # The else belongs to the for, and is used to check the break was
#         # not used
#         raise ModelNotImplemented
# 
#     fn = int(c["type"].split()[1]) - 1
# 
#     coef = numpy.fromiter(c["coefficients"].split(), dtype=numpy.float)
# 
#     # Sometimes SPECS does not exists
#     nd = mat.get("SPECS", {}).get("nd", None)
#     vd = mat.get("SPECS", {}).get("Vd", None)
#     return __models__[fn](coef, nd, vd)
# 
# class ModelNotImplemented(Exception):
#     """Indicates that the model to calculate the index of refraction is not
#     implemented yet"""
#     pass


# Path: pyoptools/raytrace/mat_lib/material.py
from os import walk
from os.path import join, expanduser, relpath
from pkg_resources import resource_filename
from .mat_eq import from_yml, ModelNotImplemented
from configparser import ConfigParser


# Note: If a home library has the same name as a system library, all the
# glasses defined will be merged in the same library

libset = list(set(libnames+["main"]+homelibnames))
liblist = []

for libname in libset:
    # Create the dictionaries where the materials will be saved. One dictionary
    # per library,
    globals()[libname] = {}
    liblist.append((libname, globals()[libname]))

liblist.sort()

# Fill the dictionaries with the current materials system wide, and then with
# the materials defined in the home of the user

for npath in [libpath, homelibpath]:

    for (dirpath, dirnames, filenames) in walk(npath):
        library = (relpath(dirpath, npath)).replace("/","_")
        # Exclude some names that are not libraries
        if library in [".", ]:
            continue

        for name in filenames:
            try:
                matname = name.split(".")[0]
                globals()[library][matname] = from_yml(join(dirpath, name))

            except ModelNotImplemented: