Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #21

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: AtomicEmbeddings CI

on: [push]

jobs:

qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pre-commit/action@v2.0.2

test:
needs: qa
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Run tests
run: python -m pytest -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ cython_debug/

# mkdocs
site/
examples/test.ipynb
Empty file.
233 changes: 233 additions & 0 deletions AtomicEmbeddings/tests/test_embeddings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import unittest

import numpy as np

from AtomicEmbeddings import Atomic_Embeddings


class TestSequenceFunctions(unittest.TestCase):
# High Level functions

def test_Atomic_Embeddings_class_magpie(self):
magpie = Atomic_Embeddings.from_json("magpie")
# Check if the embeddings attribute is a dict
self.assertIsInstance(magpie.embeddings, dict)
# Check if the embedding vector is a numpy array
self.assertIsInstance(magpie.embeddings["H"], np.ndarray)
# Check if H is present in the embedding keys
self.assertIn("H", magpie.embeddings.keys())
# Check dimensions
self.assertEqual(magpie.dim, 21)
# Check that a list is returned
self.assertIsInstance(magpie.element_list, list)
# Check that the correct list is returned
el_list = [
"H",
"He",
"Li",
"Be",
"B",
"C",
"N",
"O",
"F",
"Ne",
"Na",
"Mg",
"Al",
"Si",
"P",
"S",
"Cl",
"Ar",
"K",
"Ca",
"Sc",
"Ti",
"V",
"Cr",
"Mn",
"Fe",
"Co",
"Ni",
"Cu",
"Zn",
"Ga",
"Ge",
"As",
"Se",
"Br",
"Kr",
"Rb",
"Sr",
"Y",
"Zr",
"Nb",
"Mo",
"Tc",
"Ru",
"Rh",
"Pd",
"Ag",
"Cd",
"In",
"Sn",
"Sb",
"Te",
"I",
"Xe",
"Cs",
"Ba",
"La",
"Ce",
"Pr",
"Nd",
"Pm",
"Sm",
"Eu",
"Gd",
"Tb",
"Dy",
"Ho",
"Er",
"Tm",
"Yb",
"Lu",
"Hf",
"Ta",
"W",
"Re",
"Os",
"Ir",
"Pt",
"Au",
"Hg",
"Tl",
"Pb",
"Bi",
"Po",
"At",
"Rn",
"Fr",
"Ra",
"Ac",
"Th",
"Pa",
"U",
"Np",
"Pu",
"Am",
"Cm",
"Bk",
]
self.assertEqual(magpie.element_list, el_list)
# Check that a dictionary is returned
self.assertIsInstance(magpie.element_groups_dict, dict)
# Check that the correct dictionary is returned
group_dict = {
"H": "Others",
"He": "Noble gas",
"Li": "Alkali",
"Be": "Alkaline",
"B": "Metalloid",
"C": "Others",
"N": "Others",
"O": "Chalcogen",
"F": "Halogen",
"Ne": "Noble gas",
"Na": "Alkali",
"Mg": "Alkaline",
"Al": "Post-TM",
"Si": "Metalloid",
"P": "Others",
"S": "Chalcogen",
"Cl": "Halogen",
"Ar": "Noble gas",
"K": "Alkali",
"Ca": "Alkaline",
"Sc": "TM",
"Ti": "TM",
"V": "TM",
"Cr": "TM",
"Mn": "TM",
"Fe": "TM",
"Co": "TM",
"Ni": "TM",
"Cu": "TM",
"Zn": "TM",
"Ga": "Post-TM",
"Ge": "Metalloid",
"As": "Metalloid",
"Se": "Chalcogen",
"Br": "Halogen",
"Kr": "Noble gas",
"Rb": "Alkali",
"Sr": "Alkaline",
"Y": "TM",
"Zr": "TM",
"Nb": "TM",
"Mo": "TM",
"Tc": "TM",
"Ru": "TM",
"Rh": "TM",
"Pd": "TM",
"Ag": "TM",
"Cd": "TM",
"In": "Post-TM",
"Sn": "Post-TM",
"Sb": "Metalloid",
"Te": "Chalcogen",
"I": "Halogen",
"Xe": "Noble gas",
"Cs": "Alkali",
"Ba": "Alkaline",
"La": "Lanthanoid",
"Ce": "Lanthanoid",
"Pr": "Lanthanoid",
"Nd": "Lanthanoid",
"Pm": "Lanthanoid",
"Sm": "Lanthanoid",
"Eu": "Lanthanoid",
"Gd": "Lanthanoid",
"Tb": "Lanthanoid",
"Dy": "Lanthanoid",
"Ho": "Lanthanoid",
"Er": "Lanthanoid",
"Tm": "Lanthanoid",
"Yb": "Lanthanoid",
"Lu": "Lanthanoid",
"Hf": "TM",
"Ta": "TM",
"W": "TM",
"Re": "TM",
"Os": "TM",
"Ir": "TM",
"Pt": "TM",
"Au": "TM",
"Hg": "TM",
"Tl": "Post-TM",
"Pb": "Post-TM",
"Bi": "Post-TM",
"Po": "Chalcogen",
"At": "Halogen",
"Rn": "Noble gas",
"Fr": "Alkali",
"Ra": "Alkaline",
"Ac": "Actinoid",
"Th": "Actinoid",
"Pa": "Actinoid",
"U": "Actinoid",
"Np": "Actinoid",
"Pu": "Actinoid",
"Am": "Actinoid",
"Cm": "Actinoid",
"Bk": "Actinoid",
}
self.assertEqual(magpie.element_groups_dict, group_dict)
# Check pair creation
self.assertEqual(
len(list(magpie.create_pairs())), 4753, "Incorrect number of pairs returned"
)

# TO-DO
# Create tests for checking dataframes and plotting functions
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
numpy
scipy
pymatgen
seaborn
matplotlib
scikit-learn
pandas
pytest
pytest-subtests
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

from setuptools import find_packages, setup

VERSION = "0.0.3"
Expand All @@ -14,6 +16,7 @@
long_description=LONG_DESCRIPTION,
packages=find_packages(),
package_data={"AtomicEmbeddings": ["data/*.json", "data/*.csv"]},
test_suite="AtomicEmbeddings.tests.test",
install_requires=[
"numpy",
"scipy",
Expand Down