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

Add oxidation states option to SMACT validity function #282

Merged
merged 7 commits into from
Jul 8, 2024

Conversation

AntObi
Copy link
Collaborator

@AntObi AntObi commented Jul 8, 2024

Pull Request Template

Description

  • This PR adds the option to select the oxidation states to be considered when using the smact_validity function.

Fixes #281

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Test Configuration:

  • Python version: 3.10
  • Operating System: Windows 11

Reviewers

N/A

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Summary by CodeRabbit

  • New Features

    • Enhanced smact_validity function to include an oxidation_states_set parameter for more flexible charge-balancing options.
    • Introduced new test methods in DopantPredictionTest to ensure robustness in dopant prediction features.
  • Updates

    • Updated installation command in README.md to use https:// instead of git://.
    • Included additional data files in setup configuration and updated numpy requirement to <2.
  • Documentation

    • Added "tabulate" module to imported modules list in documentation configuration.
  • Bug Fixes

    • Improved Doper class with additional parameters and methods for better performance and accuracy.
  • Tests

    • Expanded test cases in test_core.py for smact_validity function.

@AntObi AntObi self-assigned this Jul 8, 2024
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

Significant changes include updating the Doper class to implement new parameters like embedding and use_probability, and updating smact_validity to allow for different oxidation state sets. Enhancements were also made to various test cases and documentation.

Changes

Files Change Summary
docs/conf.py Added "tabulate" to the list of imported modules.
setup.py Included "data/species_rep/*.json" in data files and updated numpy requirement to be less than version 2.
smact/dopant_prediction/doper.py Updated Doper class with new parameters (embedding, use_probability), added SKIPSSPECIES_COSINE_SIM_PATH, and new methods.
smact/screening.py Added oxidation_states_set parameter to smact_validity function.
README.md Updated installation command for SMACT to use https:// instead of git://.
smact/tests/test_doper.py Added imports for os, renamed test class to DopantPredictionTest, and added new test methods.
smact/tests/test_core.py Added new tests for smact_validity with different oxidation state sets.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant smact_validity
    participant OxidationStatesSet

    User->>smact_validity: Call smact_validity(composition, oxidation_states_set)
    smact_validity->>OxidationStatesSet: Select appropriate set based on parameter
    OxidationStatesSet-->>smact_validity: Return oxidation states based on selection
    smact_validity-->>User: Return validity result
Loading

Assessment against linked issues

Objective Addressed Explanation
Add oxidation states choice to smact_validity (#281)

Poem

In the land where codes do dwell,
Doper's learned to cast a spell.
With smact_validity so vast,
Choosing states, it’s done at last.
Data files, they now include,
Changes here to set the mood.
A rabbit hops with glee,
For SMACT now sets you free! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@AntObi AntObi changed the base branch from master to develop July 8, 2024 15:10
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.65%. Comparing base (a8047e6) to head (cbf7515).
Report is 1 commits behind head on develop.

Files Patch % Lines
smact/screening.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #282      +/-   ##
===========================================
+ Coverage    74.50%   74.65%   +0.14%     
===========================================
  Files           24       24              
  Lines         2083     2099      +16     
===========================================
+ Hits          1552     1567      +15     
- Misses         531      532       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (6)
smact/tests/test_doper.py (3)

1-1: Remove unused import: smact.

The smact module is imported but not used in this file. Removing unused imports helps keep the code clean and maintainable.

- import smact

6-6: Remove unused import: smact.structure_prediction.mutation.

The mutation module from smact.structure_prediction is imported but not used in this file.

- from smact.structure_prediction import mutation, utilities
+ from smact.structure_prediction import utilities
Tools
Ruff

6-6: smact.structure_prediction.mutation imported but unused

Remove unused import: smact.structure_prediction.mutation

(F401)


14-14: Remove assignment to unused variable num_dopants.

The variable num_dopants is assigned but never used in the test_dopant_prediction method.

- num_dopants = 10
Tools
Ruff

14-14: Local variable num_dopants is assigned to but never used

Remove assignment to unused variable num_dopants

(F841)

smact/dopant_prediction/doper.py (3)

3-3: Remove unused import: typing.Type.

The Type class from the typing module is imported but not used in this file.

- from typing import List, Optional, Tuple, Type
+ from typing import List, Optional, Tuple
Tools
Ruff

3-3: typing.Type imported but unused

Remove unused import: typing.Type

(F401)


46-49: Improve error message for mutually exclusive parameters.

The error message could be more informative by specifying the conflicting parameters.

- raise ValueError("Only one of filepath or embedding should be provided")
+ raise ValueError("The parameters 'filepath' and 'embedding' are mutually exclusive. Please provide only one of them.")

50-51: Add supported embeddings to the error message.

The error message for unsupported embeddings should list the supported options.

- raise ValueError(f"Embedding {embedding} is not supported")
+ raise ValueError(f"Embedding {embedding} is not supported. Supported embeddings: 'skipspecies'")
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0866db0 and b45603f.

Files selected for processing (5)
  • docs/conf.py (1 hunks)
  • setup.py (1 hunks)
  • smact/dopant_prediction/doper.py (11 hunks)
  • smact/screening.py (2 hunks)
  • smact/tests/test_doper.py (2 hunks)
Files skipped from review due to trivial changes (2)
  • docs/conf.py
  • setup.py
Additional context used
Ruff
smact/tests/test_doper.py

4-4: smact imported but unused

Remove unused import: smact

(F401)


6-6: smact.structure_prediction.mutation imported but unused

Remove unused import: smact.structure_prediction.mutation

(F401)


14-14: Local variable num_dopants is assigned to but never used

Remove assignment to unused variable num_dopants

(F841)

smact/dopant_prediction/doper.py

3-3: typing.Type imported but unused

Remove unused import: typing.Type

(F401)

GitHub Check: codecov/patch
smact/screening.py

[warning] 474-479: smact/screening.py#L474-L479
Added lines #L474 - L479 were not covered by tests


[warning] 482-483: smact/screening.py#L482-L483
Added lines #L482 - L483 were not covered by tests


[warning] 487-487: smact/screening.py#L487
Added line #L487 was not covered by tests


[warning] 490-490: smact/screening.py#L490
Added line #L490 was not covered by tests

Additional comments not posted (3)
smact/dopant_prediction/doper.py (2)

143-157: Ensure consistency in similarity/probability calculation.

The _calculate_species_sim_prob method correctly differentiates between probability and similarity score. Ensure that the method is used consistently throughout the class.


Line range hint 158-288:
Validate logic in get_dopants method.

The get_dopants method includes new parameters and logic for calculating dopants. Ensure that the method is thoroughly tested, especially the new logic paths.

smact/screening.py (1)

472-494: Ensure coverage for new oxidation states logic.

The new logic for handling different oxidation states sets should be thoroughly tested to ensure correctness.

Tools
GitHub Check: codecov/patch

[warning] 474-479: smact/screening.py#L474-L479
Added lines #L474 - L479 were not covered by tests


[warning] 482-483: smact/screening.py#L482-L483
Added lines #L482 - L483 were not covered by tests


[warning] 487-487: smact/screening.py#L487
Added line #L487 was not covered by tests


[warning] 490-490: smact/screening.py#L490
Added line #L490 was not covered by tests

Comment on lines 433 to 445
oxidation_states_set: Union[str, bytes, os.PathLike] = "default",
) -> bool:
"""Check if a composition is valid according to the SMACT rules.

Args:
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check
use_pauling_test (bool): Whether to use the Pauling electronegativity test
include_alloys (bool): If True, compositions of metal elements will be considered valid
oxidation_states_set (Union[str, bytes, os.PathLike]): A string to choose which set of
oxidation states should be chosen for charge-balancing. Options are 'default', 'icsd',
'pymatgen' and 'wiki' for the default, icsd, pymatgen structure predictor and Wikipedia
(https://en.wikipedia.org/wiki/Template:List_of_oxidation_states_of_the_elements) oxidation states respectively.
A filepath to an oxidation states text file can also be supplied.
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Add tests for the new oxidation_states_set parameter.

The smact_validity function includes a new parameter oxidation_states_set. Ensure that this parameter is thoroughly tested, as it is not currently covered in the test suite.

  • Add test cases in smact/tests/test_core.py to cover different values of the oxidation_states_set parameter.
Analysis chain

Add tests for the new oxidation_states_set parameter.

The smact_validity function includes a new parameter oxidation_states_set. Ensure that this parameter is thoroughly tested.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new parameter `oxidation_states_set` in the `smact_validity` function is tested.

# Test: Ensure that the new parameter is covered in the test suite.
rg --type python 'smact_validity'

Length of output: 64


Script:

#!/bin/bash
# Description: Verify the new parameter `oxidation_states_set` in the `smact_validity` function is tested.

# Test: Ensure that the new parameter is covered in the test suite.
rg 'smact_validity' --type py

Length of output: 600


Script:

#!/bin/bash
# Description: Verify the new parameter `oxidation_states_set` in the `smact_validity` function is tested.

# Test: Ensure that the new parameter is covered in the test suite.
rg 'smact_validity' smact/tests/test_core.py

Length of output: 425

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c9dccb1 and daa9ff0.

Files selected for processing (1)
  • smact/screening.py (2 hunks)
Additional comments not posted (1)
smact/screening.py (1)

441-445: Document the new parameter clearly.

The new parameter oxidation_states_set is well-documented, but ensure that the documentation is updated in all relevant places, including user guides and API references.

@@ -430,13 +430,19 @@ def smact_validity(
composition: Union[pymatgen.core.Composition, str],
use_pauling_test: bool = True,
include_alloys: bool = True,
oxidation_states_set: Union[str, bytes, os.PathLike] = "default",
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for new parameter.

The smact_validity function includes a new parameter oxidation_states_set. Ensure that this parameter is thoroughly tested, as it is not currently covered in the test suite.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between daa9ff0 and cbf7515.

Files selected for processing (4)
  • README.md (1 hunks)
  • setup.py (1 hunks)
  • smact/screening.py (2 hunks)
  • smact/tests/test_core.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • setup.py
Additional context used
Markdownlint
README.md

104-104: null
Bare URL used

(MD034, no-bare-urls)

GitHub Check: codecov/patch
smact/screening.py

[warning] 492-492: smact/screening.py#L492
Added line #L492 was not covered by tests

Additional comments not posted (2)
README.md (1)

101-101: Use HTTPS URL for installation.

The change to use https:// instead of git:// for the installation command is appropriate and enhances security.

smact/tests/test_core.py (1)

414-431: Add tests for new parameter.

The added test cases for the smact_validity function with different oxidation state sets are necessary and well-implemented. Ensure that these tests cover all relevant scenarios for the new parameter.

Comment on lines +433 to +447
oxidation_states_set: Union[str, bytes, os.PathLike] = "default",
) -> bool:
"""Check if a composition is valid according to the SMACT rules.

Composition is considered valid if it passes the charge neutrality test and the Pauling electronegativity test.

Args:
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check. This can be a pymatgen Composition object or a string.
use_pauling_test (bool): Whether to use the Pauling electronegativity test
include_alloys (bool): If True, compositions of metal elements will be considered valid
include_alloys (bool): If True, compositions which only contain metal elements will be considered valid without further checks.
oxidation_states_set (Union[str, bytes, os.PathLike]): A string to choose which set of
oxidation states should be chosen for charge-balancing. Options are 'default', 'icsd',
'pymatgen' and 'wiki' for the default, icsd, pymatgen structure predictor and Wikipedia
(https://en.wikipedia.org/wiki/Template:List_of_oxidation_states_of_the_elements) oxidation states respectively.
A filepath to an oxidation states text file can also be supplied.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for the new oxidation_states_set parameter.

The smact_validity function includes a new parameter oxidation_states_set. Ensure that this parameter is thoroughly tested, as it is not currently covered in the test suite.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Comment on lines +474 to +496
if oxidation_states_set == "default" or oxidation_states_set is None:
ox_combos = [e.oxidation_states for e in smact_elems]
elif oxidation_states_set == "icsd":
ox_combos = [e.oxidation_states_icsd for e in smact_elems]
elif oxidation_states_set == "pymatgen":
ox_combos = [e.oxidation_states_sp for e in smact_elems]
elif os.path.exists(oxidation_states_set):
ox_combos = [
oxi_custom(e.symbol, oxidation_states_set) for e in smact_elems
]
elif oxidation_states_set == "wiki":
warnings.warn(
"This set of oxidation states is sourced from Wikipedia. The results from using this set could be questionable and should not be used unless you know what you are doing and have inspected the oxidation states.",
stacklevel=2,
)
ox_combos = [e.oxidation_states_wiki for e in smact_elems]

else:
raise (
Exception(
f'{oxidation_states_set} is not valid. Enter either "default", "icsd", "pymatgen","wiki" or a filepath to a textfile of oxidation states.'
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to reduce redundancy.

The code for handling different oxidation_states_set options is repetitive. Consider refactoring to improve maintainability and readability.

oxi_set = {
    "default": [e.oxidation_states for e in smact_elems],
    "icsd": [e.oxidation_states_icsd for e in smact_elems],
    "pymatgen": [e.oxidation_states_sp for e in smact_elems],
    "wiki": [e.oxidation_states_wiki for e in smact_elems],
}

if oxidation_states_set in oxi_set:
    ox_combos = oxi_set[oxidation_states_set]
    if oxidation_states_set == "wiki":
        warnings.warn(
            "This set of oxidation states is sourced from Wikipedia. The results from using this set could be questionable and should not be used unless you know what you are doing and have inspected the oxidation states.",
            stacklevel=2,
        )
elif os.path.exists(oxidation_states_set):
    ox_combos = [
        oxi_custom(e.symbol, oxidation_states_set) for e in smact_elems
    ]
else:
    raise Exception(
        f'{oxidation_states_set} is not valid. Enter either "default", "icsd", "pymatgen","wiki" or a filepath to a textfile of oxidation states.'
    )
Tools
GitHub Check: codecov/patch

[warning] 492-492: smact/screening.py#L492
Added line #L492 was not covered by tests

@AntObi AntObi merged commit 5d75a82 into WMD-group:develop Jul 8, 2024
16 checks passed
@AntObi AntObi deleted the smact_validity_updates branch July 8, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add oxidation states choice to smact_validity
1 participant