# general module imports
import glob, sys, os, shutil, math
from pathlib import Path
import numpy as np
import ase.io
import ase.spacegroup
from ase import neighborlist, build
import itertools
from collections import namedtuple

# Plotting specific settings
import matplotlib
import matplotlib.pyplot as plt

plt.style.use("seaborn-ticks")
plt.rcParams["legend.handlelength"] = 0.8
plt.rcParams["legend.framealpha"] = 0.8
font_size = 8.5
plt.rcParams.update({"font.size": font_size})


# Logging settings
import logging
import time

logging.basicConfig(format="{levelname:8s}│ {message:s}", style="{", level=logging.INFO)


# color dictionary
color_dict = {
    "H": (1, 1, 1),
    "He": (0.850980392, 1, 1),
    "Li": (0.8, 0.501960784, 1),
    "Be": (0.760784314, 1, 0),
    "B": (1, 0.709803922, 0.709803922),
    "C": (0.564705882, 0.564705882, 0.564705882),
    "N": (0.188235294, 0.31372549, 0.97254902),
    "O": (1, 0.050980392, 0.050980392),
    "F": (0.564705882, 0.878431373, 0.31372549),
    "Ne": (0.701960784, 0.890196078, 0.960784314),
    "Na": (0.670588235, 0.360784314, 0.949019608),
    "Mg": (0.541176471, 1, 0),
    "Al": (0.749019608, 0.650980392, 0.650980392),
    "Si": (0.941176471, 0.784313725, 0.62745098),
    "P": (1, 0.501960784, 0),
    "S": (1, 1, 0.188235294),
    "Cl": (0.121568627, 0.941176471, 0.121568627),
    "Ar": (0.501960784, 0.819607843, 0.890196078),
    "K": (0.560784314, 0.250980392, 0.831372549),
    "Ca": (0.239215686, 1, 0),
    "Sc": (0.901960784, 0.901960784, 0.901960784),
    "Ti": (0.749019608, 0.760784314, 0.780392157),
    "V": (0.650980392, 0.650980392, 0.670588235),
    "Cr": (0.541176471, 0.6, 0.780392157),
    "Mn": (0.611764706, 0.478431373, 0.780392157),
    "Fe": (0.878431373, 0.4, 0.2),
    "Co": (0.941176471, 0.564705882, 0.62745098),
    "Ni": (0.31372549, 0.815686275, 0.31372549),
    "Cu": (0.784313725, 0.501960784, 0.2),
    "Zn": (0.490196078, 0.501960784, 0.690196078),
    "Ga": (0.760784314, 0.560784314, 0.560784314),
    "Ge": (0.4, 0.560784314, 0.560784314),
    "As": (0.741176471, 0.501960784, 0.890196078),
    "Se": (1, 0.631372549, 0),
    "Br": (0.650980392, 0.160784314, 0.160784314),
    "Kr": (0.360784314, 0.721568627, 0.819607843),
    "Rb": (0.439215686, 0.180392157, 0.690196078),
    "Sr": (0, 1, 0),
    "Y": (0.580392157, 1, 1),
    "Zr": (0.580392157, 0.878431373, 0.878431373),
    "Nb": (0.450980392, 0.760784314, 0.788235294),
    "Mo": (0.329411765, 0.709803922, 0.709803922),
    "Tc": (0.231372549, 0.619607843, 0.619607843),
    "Ru": (0.141176471, 0.560784314, 0.560784314),
    "Rh": (0.039215686, 0.490196078, 0.549019608),
    "Pd": (0, 0.411764706, 0.521568627),
    "Ag": (0.752941176, 0.752941176, 0.752941176),
    "Cd": (1, 0.850980392, 0.560784314),
    "In": (0.650980392, 0.458823529, 0.450980392),
    "Sn": (0.4, 0.501960784, 0.501960784),
    "Sb": (0.619607843, 0.388235294, 0.709803922),
    "Te": (0.831372549, 0.478431373, 0),
    "I": (0.580392157, 0, 0.580392157),
    "Xe": (0.258823529, 0.619607843, 0.690196078),
    "Cs": (0.341176471, 0.090196078, 0.560784314),
    "Ba": (0, 0.788235294, 0),
    "La": (0.439215686, 0.831372549, 1),
    "Ce": (1, 1, 0.780392157),
    "Pr": (0.850980392, 1, 0.780392157),
    "Nd": (0.780392157, 1, 0.780392157),
    "Pm": (0.639215686, 1, 0.780392157),
    "Sm": (0.560784314, 1, 0.780392157),
    "Eu": (0.380392157, 1, 0.780392157),
    "Gd": (0.270588235, 1, 0.780392157),
    "Tb": (0.188235294, 1, 0.780392157),
    "Dy": (0.121568627, 1, 0.780392157),
    "Ho": (0, 1, 0.611764706),
    "Er": (0, 0.901960784, 0.458823529),
    "Tm": (0, 0.831372549, 0.321568627),
    "Yb": (0, 0.749019608, 0.219607843),
    "Lu": (0, 0.670588235, 0.141176471),
    "Hf": (0.301960784, 0.760784314, 1),
    "Ta": (0.301960784, 0.650980392, 1),
    "W": (0.129411765, 0.580392157, 0.839215686),
    "Re": (0.149019608, 0.490196078, 0.670588235),
    "Os": (0.149019608, 0.4, 0.588235294),
    "Ir": (0.090196078, 0.329411765, 0.529411765),
    "Pt": (0.815686275, 0.815686275, 0.878431373),
    "Au": (1, 0.819607843, 0.137254902),
    "Hg": (0.721568627, 0.721568627, 0.815686275),
    "Tl": (0.650980392, 0.329411765, 0.301960784),
    "Pb": (0.341176471, 0.349019608, 0.380392157),
    "Bi": (0.619607843, 0.309803922, 0.709803922),
    "Po": (0.670588235, 0.360784314, 0),
    "At": (0.458823529, 0.309803922, 0.270588235),
    "Rn": (0.258823529, 0.509803922, 0.588235294),
    "Fr": (0.258823529, 0, 0.4),
    "Ra": (0, 0.490196078, 0),
    "Ac": (0.439215686, 0.670588235, 0.980392157),
    "Th": (0, 0.729411765, 1),
    "Pa": (0, 0.631372549, 1),
    "U": (0, 0.560784314, 1),
    "Np": (0, 0.501960784, 1),
    "Pu": (0, 0.419607843, 1),
    "Am": (0.329411765, 0.360784314, 0.949019608),
    "Cm": (0.470588235, 0.360784314, 0.890196078),
    "Bk": (0.541176471, 0.309803922, 0.890196078),
    "Cf": (0.631372549, 0.211764706, 0.831372549),
    "Es": (0.701960784, 0.121568627, 0.831372549),
    "Fm": (0.701960784, 0.121568627, 0.729411765),
    "Md": (0.701960784, 0.050980392, 0.650980392),
    "No": (0.741176471, 0.050980392, 0.529411765),
    "Lr": (0.780392157, 0, 0.4),
    "Rf": (0.8, 0, 0.349019608),
    "Db": (0.819607843, 0, 0.309803922),
    "Sg": (0.850980392, 0, 0.270588235),
    "Bh": (0.878431373, 0, 0.219607843),
    "Hs": (0.901960784, 0, 0.180392157),
    "Mt": (0.921568627, 0, 0.149019608),
}
