WMD-group / SMACT

Python package to aid materials design and informatics
https://smact.readthedocs.io
MIT License
100 stars 22 forks source link

VEC function integration into smact.properties with a test file to serve as an example for its use. #305

Closed ryannduma closed 3 months ago

ryannduma commented 3 months ago

VEC function Pull Request

Description

Hey, I hope this PR finds you well, I have now completed the integration of the VEC function succintly into the smact.properties.py module and attached a relevant example of it's use. I would also like to indicate that the function takes two arguments - the compound in question and a valence file - allowing for the user to select any file say magpie, or any existing valence file that they would like to use, in this case the example uses the modified file you shared.

I would like to highlight that this is a New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Test Configuration: VECexample.py

Reviewers

@AntObi - Admin and Maintainer

Checklist:

Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

[!WARNING]

Rate limit exceeded

@ryannduma has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 36 seconds before requesting another review.

How to resolve this issue? After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work? CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our [FAQ](https://coderabbit.ai/docs/faq) for further information.
Commits Files that changed from the base of the PR and between f8b7a8aec513830870e987f19df1e93998c8e153 and 55ba0db43bdfd38e5c8388a6921e874791ca9b3d.

Walkthrough

The changes introduce two new scripts, VECexample.py and examples/vec_example.py, for calculating the Valence Electron Count (VEC) of different chemical compounds. This functionality is facilitated by the new valence_electron_count function in the smact/properties.py module, which includes parsing capabilities and error handling. Test coverage is enhanced with a new test function in the smact/tests/test_core.py file, ensuring proper validation of the new functionality.

Changes

Files Change Summary
VECexample.py, examples/vec_example.py Introduced scripts for VEC calculation for "Ba5In4Bi5" and "Fe2O3" using the valence_electron_count function from smact.properties.
smact/properties.py Added valence_electron_count function for computing VEC with parsing and error handling.
smact/tests/test_core.py Added test_valence_electron_count to validate the functionality of the valence_electron_count function, including expected outputs and error handling.
.pre-commit-config.yaml Updated pre-commit hooks, modifying nbQA version and Python compatibility argument.
examples/Crystal_Space/1_reduction.ipynb Changed import of Iterable from typing to collections.abc for better compatibility.

Poem

In a garden of formulas, oh what a sight,
A rabbit hops joyfully, under moonlight.
Valence counts dancing, a new script in play,
For compounds and elements, come join the fray!
With data from CSV, the VEC's now bright,
A leap for the science, oh what pure delight! šŸ‡āœØ


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 Configuration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
AntObi commented 3 months ago

Thank you for submitting this PR @ryannduma . A few things before I can accept this PR.

ryannduma commented 3 months ago

Hey Anthony,

I have resolved all conflicts and the code now passes the qa stage of the CI except its failing all the other tests of the CI, how can I resolve that?

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.67%. Comparing base (f7a72b7) to head (55ba0db). Report is 206 commits behind head on develop.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #305 +/- ## =========================================== + Coverage 75.47% 75.67% +0.19% =========================================== Files 24 24 Lines 2361 2183 -178 =========================================== - Hits 1782 1652 -130 + Misses 579 531 -48 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


šŸšØ Try these New Features:

AntObi commented 3 months ago

Merged!

ryannduma commented 3 months ago

Hey @AntObi , the code passed the tests after a bunch of minor tweaks here and there to the types of errors raised, I noticed the Lr0 element check passed as a ValueError when passed to the function instead of a TypeError as presumed so I edited that part of the test to match, and it passed, though I dont know if thats exactly right, same to the Xx which isnt a valid element but I guess when parsed over is accepted because of the following codeblock, which ofc down the line, is found to not have a Valence number and then returns a ValueError instead of a NameError - please let me know what your thoughts are on this and whether additional tweaks need to be made.

Thank you and have a good evening

def parse_formula(formula): pattern = re.compile(r'([A-Z][a-z]*)(\d*)') elements = pattern.findall(formula) element_stoich = defaultdict(int) for (element, count) in elements: count = int(count) if count else 1 element_stoich[element] += count return element_stoich