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

Chloe lee doper #264

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
20 changes: 11 additions & 9 deletions smact/dopant_prediction/doper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from itertools import groupby
from typing import List, Optional, Tuple, Type
from typing import List, Optional, Tuple

import numpy as np
from pymatgen.util import plotting
Expand Down Expand Up @@ -289,11 +289,6 @@ def get_dopants(
groupby_lists[i] = grouped_top_data
del grouped_data

# select top n elements
dopants_lists = [
dopants_list[:num_dopants] for dopants_list in dopants_lists
]

keys = [
"n-type cation substitutions",
"p-type cation substitutions",
Expand All @@ -304,7 +299,10 @@ def get_dopants(
self.results = self._merge_dicts(keys, dopants_lists, groupby_lists)

# return the top (num_dopants) results for each case
return self.results
return {
key: value.get("sorted")[:num_dopants]
for key, value in self.results.items()
}

def plot_dopants(self) -> None:
"""
Expand Down Expand Up @@ -332,8 +330,12 @@ def plot_dopants(self) -> None:
}
plotting.periodic_table_heatmap(
elemental_data=dict_results,
cmap="rainbow",
blank_color="gainsboro",
cmap="Reds",
cmap_range=(
min(dict_results.values()),
max(dict_results.values()),
),
blank_color="#D4D4D4",
edge_color="white",
)

Expand Down
10 changes: 5 additions & 5 deletions smact/tests/test_doper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import os
import unittest

import smact
from smact.dopant_prediction import doper
from smact.structure_prediction import mutation, utilities
from smact.structure_prediction import utilities

files_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files")
TEST_LAMBDA_JSON = os.path.join(files_dir, "test_lambda_tab.json")


class DopantPredictionTest(unittest.TestCase):
def test_dopant_prediction(self):
num_dopants = 10
test_specie = ("Cu+", "Ga3+", "S2-")
test = doper.Doper(test_specie)

Expand All @@ -25,7 +23,8 @@ def test_dopant_prediction(self):
_, an_charge = utilities.parse_spec(anion_min_charge)

# Assert: Length of the list and return type (dictionary: list)
result = test.get_dopants()
dopants = test.get_dopants()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove assignment to unused variable dopants.

- dopants = test.get_dopants()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dopants = test.get_dopants()
Tools
Ruff

26-26: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants

result = test.results
self.assertIs(type(result), dict)
for d in result.values():
self.assertIn("sorted", d)
Expand Down Expand Up @@ -59,7 +58,8 @@ def test_dopant_prediction_skipspecies(self):
test = doper.Doper(
test_specie, embedding="skipspecies", use_probability=False
)
result = test.get_dopants()
dopants = test.get_dopants()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove assignment to unused variable dopants.

- dopants = test.get_dopants()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dopants = test.get_dopants()
Tools
Ruff

61-61: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants

result = test.results

n_sub_list_cat = result.get("n-type cation substitutions").get("sorted")
p_sub_list_cat = result.get("p-type cation substitutions").get("sorted")
Expand Down
Loading