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

Develop #76

Merged
merged 10 commits into from
Jun 5, 2024
Merged

Develop #76

merged 10 commits into from
Jun 5, 2024

Conversation

kavanase
Copy link
Member

@kavanase kavanase commented Jun 5, 2024

No description provided.

Copy link

coderabbitai bot commented Jun 5, 2024

Walkthrough

The recent updates primarily focus on improving oxidation state handling, enhancing defect concentration calculations, and ensuring compatibility with the latest releases of pymatgen and ASE. Key changes include the addition of new properties and functions for better oxidation state guessing, refactoring of VASP input sets, and updates to documentation and testing to reflect these improvements. Overall, these modifications aim to streamline defect analysis and thermodynamic calculations.

Changes

Files/Directories Change Summary
CHANGELOG.rst, pyproject.toml Updated version to 2.4.4 and summarized changes.
docs/Dev_ToDo.md, docs/Troubleshooting.rst Documentation updates for dependency management and troubleshooting.
doped/analysis.py, doped/core.py, doped/generation.py, doped/thermodynamics.py Refactored oxidation state handling, defect concentration calculations, and VASP input set management.
doped/vasp.py Renamed and refactored classes/methods for VASP input sets, enhancing compatibility and functionality.
examples/GGA_workflow_tutorial.ipynb Updated import statements and function signatures for better clarity and functionality.
tests/... Expanded and updated test cases to cover new functionalities and ensure robustness.
tests/data/VO2_POSCAR Updated atomic coordinates for V2O4.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant DopedAnalysis
    participant DopedCore
    participant Pymatgen

    User->>DopedAnalysis: Initialize defect analysis
    DopedAnalysis->>DopedCore: Request oxidation state guess
    DopedCore->>Pymatgen: Use BVAnalyzer for oxidation state
    Pymatgen-->>DopedCore: Return oxidation state
    DopedCore-->>DopedAnalysis: Set oxidation state
    DopedAnalysis-->>User: Provide defect analysis results
Loading

Poem

In code so bright, with states to guess,
Defects align, no more a mess.
Pymatgen aids with bond and hue,
VASP sets now clear and true.
Docs refined, tests robust,
In version 2.4.4, we trust.
🌟✨🐇

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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.

@kavanase kavanase merged commit b61e93d into main Jun 5, 2024
1 of 6 checks passed
Copy link

@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: 9

Outside diff range and nitpick comments (6)
docs/Dev_ToDo.md (4)

Line range hint 6-6: Consider adding a comma after "Also".


Line range hint 15-15: Consider replacing "outside of" with "outside" to avoid redundancy.


Line range hint 16-16: Incomplete sentence detected. Consider revising to include a subject.

- Would be easy to implement if auto degeneracy...
+ It would be easy to implement if auto degeneracy...

Line range hint 19-19: The phrase "want plotting tools like this" seems to be missing a verb. Consider revising for clarity.

- want plotting tools like this
+ we want plotting tools like this
tests/test_analysis.py (2)

Line range hint 2694-2735: Consider refactoring the repeated code for file operations and XML modifications into helper functions.

To improve code maintainability and reduce redundancy, consider creating helper functions for common operations like moving files, modifying XML content, and setting up test environments. This will make the test cases cleaner and easier to understand.


Line range hint 2763-2795: Ensure consistent error handling for file operations.

The code performs file operations (like moving and copying files) without explicit error handling. It's recommended to add error handling to prevent the test from failing unexpectedly in cases where file operations do not succeed.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7299a0a and ff209d3.

Files selected for processing (16)
  • CHANGELOG.rst (1 hunks)
  • docs/Dev_ToDo.md (1 hunks)
  • docs/Troubleshooting.rst (1 hunks)
  • doped/analysis.py (3 hunks)
  • doped/core.py (9 hunks)
  • doped/generation.py (6 hunks)
  • doped/thermodynamics.py (16 hunks)
  • doped/vasp.py (33 hunks)
  • examples/GGA_workflow_tutorial.ipynb (5 hunks)
  • pyproject.toml (1 hunks)
  • tests/data/VO2_POSCAR (1 hunks)
  • tests/test_analysis.py (8 hunks)
  • tests/test_corrections.py (2 hunks)
  • tests/test_generation.py (6 hunks)
  • tests/test_thermodynamics.py (4 hunks)
  • tests/test_vasp.py (2 hunks)
Files skipped from review due to trivial changes (4)
  • CHANGELOG.rst
  • docs/Troubleshooting.rst
  • pyproject.toml
  • tests/data/VO2_POSCAR
Additional context used
LanguageTool
docs/Dev_ToDo.md

[uncategorized] ~3-~3: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: .... Proper vasp_std setup (with NKRED folders like for defect calcs) and vasp_ncl g...


[uncategorized] ~6-~6: A comma may be missing after the conjunctive/linking adverb ‘Also’. (SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)
Context: ...of code out of interface subpackage?) Also can see https://github.com/materialspro...


[style] ~7-~7: Two successive sentences begin with the same adverb. Consider rewording the sentence or use a thesaurus to find a synonym. (ENGLISH_WORD_REPEAT_BEGINNING_RULE)
Context: .../phases.py for 2D chempot plotting. - Also see Cs2SnTiI6 notebooks for template ...


[style] ~15-~15: This phrase is redundant. Consider using “outside”. (OUTSIDE_OF)
Context: ...e plot - Don't show transition levels outside of the bandgap (or within a certain range ...


[style] ~16-~16: To form a complete sentence, be sure to include a subject. (MISSING_IT_THERE)
Context: ...iscussion and CdTe pyscfermi notebooks. Would be easy to implement if auto degeneracy...


[grammar] ~19-~19: If ‘want’ is used as a verb, it usually requires the infinitive. (AFFORD_VBG)
Context: ...a of the AiiDA-defects preprint, want plotting tools like this - Can we add an option ...


[typographical] ~20-~20: Except for inverted sentences, ‘Can we’ requires a question mark at the end of the sentence. (MD_PRP_QUESTION_MARK)
Context: ...defect-structures) – seems quite useful tbf ## Housekeeping - Tutorials general st...


[style] ~33-~33: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...state behaviour being a bit more common etc). If the user wants to add bandfilling ...


[grammar] ~33-~33: Modal verbs like ‘can’ or ‘will’ require the following verb to be in its base form. (MD_BASEFORM)
Context: ...bandfilling corrections, they can still doing this by calculating it themselves and a...


[style] ~40-~40: Although a hyphen is possible, it is not necessary in a compound modifier in which the first word is an adverb that ends in ‘ly’. (HYPHENATED_LY_ADVERB_ADJECTIVE)
Context: ... of a VASP dielectric calculation if an oddly-defined primitive cell is used) - vasp_ncl ...


[formatting] ~42-~42: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause. (COMMA_BEFORE_BECAUSE)
Context: ... Often can't use NKRED with vasp_std, because we don't know beforehand the kpts in th...


[style] ~44-~44: Although a hyphen is possible, it is not necessary in a compound modifier in which the first word is an adverb that ends in ‘ly’. (HYPHENATED_LY_ADVERB_ADJECTIVE)
Context: ...kpoints, due to memory limitations. - Readily-usable in conjunction with atomate, AiiDA(...


[style] ~44-~44: ‘in conjunction with’ might be wordy. Consider a shorter alternative. (EN_WORDINESS_PREMIUM_IN_CONJUNCTION_WITH)
Context: ... memory limitations. - Readily-usable in conjunction with atomate, AiiDA(-defects), vise, `...


[typographical] ~46-~46: Do not use a colon (:) before a series that is introduced by a preposition (‘with’). Remove the colon or add a noun or a noun phrase after the preposition. (RP_COLON)
Context: ...onal dependencies. - Workflow diagram with: https://twitter.com/Andrew_S_Rosen/stat...


[style] ~47-~47: As an alternative to the over-used intensifier ‘very’, consider replacing this phrase. (EN_WEAK_ADJECTIVE)
Context: ...an sometimes be worth doing if you have a very large supercell for speed up, but it's impo...


[style] ~47-~47: As an alternative to the over-used intensifier ‘very’, consider replacing this phrase. (EN_WEAK_ADJECTIVE)
Context: ...only do if you're a power user and have a very large supercell. - Show usage of `get_conv_...


[style] ~51-~51: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...put structure, generate_supercell etc), but conventional cell should always b...


[uncategorized] ~54-~54: Possible missing article found. (AI_HYDRA_LEO_MISSING_AN)
Context: ... CarrierCapture.jl and nonrad. Show example of using sumo to get the DOS plot...


[style] ~57-~57: This phrase is redundant. Consider writing “cancel”. (CANCEL_OUT)
Context: ...ts that the SOC effects on total energy cancel out for chemical potential calculations...


[uncategorized] ~66-~66: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: ...he parsed defect data in a lean format. Also using the get_formation_energies etc....


[style] ~69-~69: Qualifiers like “somewhat” can weaken your message and make your writing sound uncertain. Consider removing it or choosing an alternative to sound more confident. (SOMEWHAT)
Context: ...ral, the correction terms should follow somewhat consistent trends (for a given charge s...


[grammar] ~69-~69: It appears that only one verb is needed. (THIS_IS_HAVE)
Context: ... something odd is happening there. This is can be fairly easily scanned with `get_form...


[uncategorized] ~70-~70: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE_2)
Context: ...The Wyckoff analysis code is very useful and no other package can do this afaik. See...


[typographical] ~75-~75: Consider adding a comma here. (PLEASE_COMMA)
Context: ...s and can fail in weird cases. As always please consider if these charge states are ...


[style] ~76-~76: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...mmetry, amphoteric, mixed-valence cases etc!) - Note cases where we expect defa...


[style] ~77-~77: Consider changing the order of words to improve your wording. (TO_NOT_VB)
Context: ...s where we expect default charge states to not be appropriate (e.g. mixed ionic-covale...


[style] ~82-~82: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...tum/magnetic defects, d-orbital defects etc), in which case you can manually adjust...


[style] ~84-~84: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...lay around with probability_threshold etc). - Should flick through other defect c...


[style] ~93-~93: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ...lso group defects for the concentration etc functions, currently doesn't (e.g. `CdT...

Additional comments not posted (49)
tests/test_corrections.py (2)

17-17: Updated imports to reflect changes in the main codebase.


32-32: Class inheritance changed to unittest.TestCase to standardize testing framework usage.

docs/Dev_ToDo.md (1)

Line range hint 3-3: Consider adding a comma after "NKRED folders like for defect calcs".

#!/bin/bash
# Description: Verify if the comma is necessary.
# Test: Check grammar rules for lists in technical documentation.
echo "Grammar check completed."
tests/test_vasp.py (21)

Line range hint 27-32: Method _potcars_available correctly checks for the availability of POTCARs.


Line range hint 34-42: Method _check_potcar_dir_not_setup_warning_error correctly constructs and checks warning messages.


Line range hint 44-51: Method _check_no_potcar_available_warning_error correctly checks for specific substrings in a warning message.


Line range hint 53-57: Method _check_nelect_nupdown_error correctly checks for a specific error message.


Line range hint 59-67: Method _check_nupdown_neutral_cell_warning correctly checks for specific substrings in a warning message.


Line range hint 69-92: Method setUp correctly initializes the test environment for DefectDictSetTest.


Line range hint 94-97: Method tearDown correctly cleans up the test environment after tests are run.


Line range hint 99-141: Method _general_defect_dict_set_check correctly implements comprehensive checks on a DefectDictSet instance.


Line range hint 143-150: Method _check_potcar_nupdown_dds_warnings correctly checks for specific warnings in a DefectDictSet.


Line range hint 152-192: Method _check_dds_incar correctly checks the INCAR settings of a DefectDictSet.


Line range hint 194-206: Method _check_dds_incar_and_writing_warnings correctly checks for warnings during INCAR writing in a DefectDictSet.


Line range hint 208-234: Method _check_dds correctly implements comprehensive checks on a DefectDictSet.


Line range hint 236-250: Method _generate_and_check_dds correctly generates and checks a DefectDictSet.


Line range hint 252-261: Method kpts_nelect_nupdown_check correctly checks the k-points, NELECT, and NUPDOWN settings of a DefectDictSet.


Line range hint 263-277: Method test_neutral_defect_dict_set correctly tests the behavior of a DefectDictSet with a neutral defect.


Line range hint 279-293: Method test_charged_defect_incar correctly tests the behavior of a DefectDictSet with a charged defect.


Line range hint 295-314: Method test_user_settings_defect_incar correctly tests the behavior of a DefectDictSet with custom user INCAR settings.


Line range hint 316-332: Method test_bad_incar_setting correctly tests the behavior of a DefectDictSet when incorrect INCAR settings are provided.


Line range hint 334-365: Method test_initialisation_for_all_structs correctly tests the initialization of a DefectDictSet for various structures.


Line range hint 367-385: Method test_file_writing_with_without_POTCARs correctly tests the file writing behavior of a DefectDictSet when POTCARs are and are not available.


Line range hint 387-457: Method _write_and_check_dds_files correctly writes files for a DefectDictSet and performs checks on the written files.

doped/core.py (3)

10-10: Update to SimpleQueue from Queue should be verified for compatibility.

#!/bin/bash
# Description: Verify that SimpleQueue is used appropriately throughout the codebase.

# Test: Search for the usage of SimpleQueue. Expect: Proper usage without issues.
rg --type python 'SimpleQueue'

1273-1294: Ensure proper error handling when guessing oxidation states.

#!/bin/bash
# Description: Verify that error handling for oxidation state guessing is robust.

# Test: Search for the usage of `guess_and_set_struct_oxi_states`. Expect: Proper error handling.
rg --type python 'guess_and_set_struct_oxi_states'

1369-1416: Verify the implementation of timeouts in oxidation state guessing.

#!/bin/bash
# Description: Verify the implementation of timeouts in oxidation state guessing.

# Test: Search for the usage of `guess_and_set_oxi_states_with_timeout`. Expect: Proper implementation of timeouts.
rg --type python 'guess_and_set_oxi_states_with_timeout'
doped/generation.py (3)

43-43: Updated import to use the new function name guess_and_set_oxi_states_with_timeout.

This change aligns with the refactoring noted in the PR summary, ensuring consistency across the codebase.


1344-1345: Implementation of guess_and_set_oxi_states_with_timeout to handle oxidation states.

This update is part of the refactoring efforts to improve the handling of oxidation states, making the process potentially more robust and efficient by incorporating a timeout mechanism.


1333-1333: Change in default behavior for _bulk_oxi_states from True to False.

- False  # to check if pymatgen can guess the bulk oxidation states
+ True  # to check if pymatgen can guess the bulk oxidation states

This change might affect the default behavior of oxidation state handling in various parts of the code. It's crucial to ensure that this change is intentional and documented, especially if it affects public APIs or expected outputs.

Likely invalid or redundant comment.

doped/analysis.py (2)

29-29: Updated import to use the public version of guess_and_set_oxi_states_with_timeout.


709-716: Correctly implemented oxidation state setup with timeout handling.

Consider adding error handling or logging to capture and respond to potential failures in the oxidation state guessing process.

#!/bin/bash
# Description: Verify error handling in oxidation state setup.

# Test: Search for error handling related to oxidation state setup. Expect: Some form of error handling or logging.
rg --type python 'error handling|logging' 'doped/analysis.py'
doped/vasp.py (10)

23-23: The import of VaspInputSet from pymatgen.io.vasp.sets has been updated to reflect the changes in the underlying library or to simplify the import structure. This change should be cross-verified with the pymatgen library's latest documentation to ensure compatibility.


139-139: The parameter user_potcar_functional in the __init__ method of DopedDictSet is now explicitly typed as str. This is a good practice as it enhances code readability and type safety.


320-320: In DefectDictSet, the user_potcar_functional parameter is consistently typed as str across different classes, which maintains consistency and type safety in the codebase.


72-72: The function _test_potcar_functional_choice has been updated to handle RuntimeError, which is a change in the pymatgen library version 2024.5.1. Ensure that this version or higher of pymatgen is specified in the project dependencies to avoid runtime issues.

#!/bin/bash
# Ensure the correct pymatgen version is installed
pip show pymatgen | grep "Version: 2024.5.1"

126-126: The class DopedDictSet has been updated to inherit from VaspInputSet instead of DictSet. This change likely aligns with updates in the pymatgen library. Confirm that all methods and properties of DictSet that are used in DopedDictSet are compatible or appropriately overridden.

#!/bin/bash
# Check for any missing methods or properties in VaspInputSet that are used in DopedDictSet
grep -R "DictSet" ./src | grep -v "DopedDictSet"

208-208: The method __init__ in DopedDictSet now includes a more structured approach to handling POTCAR settings, which improves the flexibility and maintainability of the code. This change should be tested to ensure that it does not affect the expected behavior of the system.

#!/bin/bash
# Run unit tests related to POTCAR settings
pytest -k "test_potcar_settings"

224-224: The method incar in DopedDictSet now includes logic to handle KPAR settings based on the number of k-points. This is a significant enhancement for performance optimization in VASP calculations. Ensure that this logic is covered by unit tests to prevent regressions in future changes.

#!/bin/bash
# Verify the KPAR settings logic with unit tests
pytest -k "test_kpar_settings"

252-252: The method potcar in DopedDictSet now dynamically adjusts the POTCAR functional based on availability, which is a robust enhancement. It's crucial to ensure that this functionality is compatible with all expected use cases in the project.

#!/bin/bash
# Check compatibility of dynamic POTCAR functional adjustment
pytest -k "test_dynamic_potcar_functional"

310-310: The class DefectDictSet extends DopedDictSet to handle VASP defect calculations. This structural change should be reviewed to ensure that it correctly implements all necessary modifications for defect-specific calculations.

#!/bin/bash
# Review the implementation of DefectDictSet for correctness
grep -R "DefectDictSet" ./src

494-494: The method write_input in DefectDictSet has been refactored to better handle POTCAR setup checks. This is a critical update that enhances the robustness of the input file generation process. It's important to ensure that these changes are well-documented and tested.

#!/bin/bash
# Ensure the new POTCAR setup checks are functioning as expected
pytest -k "test_write_input_potcar_checks"
doped/thermodynamics.py (1)

1297-1298: Verify the aggregation logic in _group_defect_charge_state_concentrations.

The method _group_defect_charge_state_concentrations is used here to aggregate concentrations. Ensure that this method correctly handles different cases, especially edge cases where defects might not be grouped as expected.

#!/bin/bash
# Description: Verify the aggregation logic by checking the method's handling of edge cases.

# Test: Run unit tests related to this method. Expect: All tests pass.
pytest tests/test_thermodynamics.py -k test_group_defect_charge_state_concentrations
tests/test_generation.py (6)

Line range hint 1-6: The updated import statements are appropriate for the file's functionality.


297-297: Correct usage of Structure.from_ase_atoms to convert ASE atoms to a pymatgen structure.


608-629: The defect generation information is detailed and correctly formatted.


1010-1022: Robust handling of warnings and assertions related to structure dimensions during defect generation.


1773-1779: Assertions correctly check the bulk_site_concentration against expected values, ensuring the accuracy of defect calculations.


3212-3216: The assertion ensures that the output contains the expected defect information, validating the test results.

Comment on lines +1834 to +1842
# test per_site and bulk_site_concentration attributes:
new_conc = random_defect_entry.equilibrium_concentration(
chempots=self.CdTe_chempots,
limit="Cd-rich",
fermi_level=fermi_level,
temperature=temperature,
per_site=True,
)
assert np.isclose(orig_conc, new_conc * random_defect_entry.bulk_site_concentration)
Copy link

Choose a reason for hiding this comment

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

Consider adding a unit test for the per_site parameter in equilibrium_concentration.

It seems that the per_site parameter's effect on the output is not directly tested. Would you like me to help by writing a unit test for this scenario?

@@ -2669,6 +2825,7 @@ def test_bulk_defect_compatibility_checks(self):
charge_state=+1, # manually specify charge state here, as our edited POTCAR doesn't exist
parse_projected_eigen=False,
)
print([str(warning.message) for warning in w]) # for debugging
Copy link

Choose a reason for hiding this comment

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

Add cleanup procedures in tests to ensure no side effects for subsequent tests.

The test modifies global state (e.g., moving and editing files) but does not include cleanup code to restore the original state after the test completes. This can affect other tests that rely on the same files. Consider using setUp and tearDown methods or Python's with statement to manage resources safely.

Comment on lines +1154 to +1155
return self.bulk_site_concentration * degeneracy_factor * exp_factor

Copy link

Choose a reason for hiding this comment

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

Consider adding a default value for bulk_site_concentration to handle potential None values.

- return self.bulk_site_concentration * degeneracy_factor * exp_factor
+ return (self.bulk_site_concentration or 0) * degeneracy_factor * exp_factor
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.

Suggested change
return self.bulk_site_concentration * degeneracy_factor * exp_factor
return (self.bulk_site_concentration or 0) * degeneracy_factor * exp_factor

Comment on lines +1230 to +1234
Whether to return the concentrations as percent concentrations per site,
rather than the default of per cm^3. (default: False)
skip_formatting (bool):
Whether to skip formatting the defect charge states and concentrations as
strings (and keep as ints and floats instead). (default: False)
strings (and keep as ``int``\s and ``float``\s instead). (default: False)
Copy link

Choose a reason for hiding this comment

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

Consider adding a more detailed docstring for the get_equilibrium_concentrations method.

The method get_equilibrium_concentrations lacks a detailed explanation of its parameters and return type in the docstring. This could lead to confusion for future developers or users of the code. Consider adding a more detailed description, including the types and purposes of each parameter and what the method returns.

@@ -1252,7 +1252,7 @@
fermi_level=fermi_level,
vbm=defect_entry.calculation_metadata.get("vbm", self.vbm),
)
concentration = defect_entry.equilibrium_concentration(
raw_concentration = defect_entry.equilibrium_concentration(
Copy link

Choose a reason for hiding this comment

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

Ensure consistent naming for concentration-related variables.

The variable raw_concentration is used here, but similar variables in other parts of the code use different naming conventions (e.g., Raw Concentration). It's important to maintain consistent naming conventions to improve code readability and maintainability.

Comment on lines +1275 to +1278
"Raw Concentration": raw_concentration,
(
"Concentration (per site)" if per_site else "Concentration (cm^-3)"
): _format_concentration(
Copy link

Choose a reason for hiding this comment

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

Optimize the concentration formatting logic.

The current implementation for formatting concentrations is somewhat repetitive and could be simplified. Consider creating a helper function that handles the formatting based on the per_site and skip_formatting flags. This would make the code cleaner and reduce redundancy.

- "Concentration (per site)" if per_site else "Concentration (cm^-3)"
+ format_concentration_label(per_site)

And define format_concentration_label as:

def format_concentration_label(per_site):
    return "Concentration (per site)" if per_site else "Concentration (cm^-3)"

Comment on lines +1345 to +1367
def guess_and_set_struct_oxi_states(structure, try_without_max_sites=False):
"""
Tries to guess (and set) the oxidation states of the input structure, first
using the ``pymatgen`` ``BVAnalyzer`` class, and if that fails, using the
ICSD oxidation state probabilities to guess.

Args:
structure (Structure): The structure for which to guess the oxidation states.
try_without_max_sites (bool):
Whether to try to guess the oxidation states
without using the ``max_sites=-1`` argument (``True``)(which attempts
to use the reduced composition for guessing oxi states) or not (``False``),
when using the ICSD oxidation state probability guessing.

Returns:
Structure: The structure with oxidation states guessed and set, or ``False``
if oxidation states could not be guessed.
"""
if structure_with_oxi := _guess_and_set_struct_oxi_states(structure):
return structure_with_oxi

return _guess_and_set_struct_oxi_states_icsd_prob(structure, try_without_max_sites)

Copy link

Choose a reason for hiding this comment

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

Refactor to combine similar functions for setting oxidation states.

- def guess_and_set_struct_oxi_states(structure, try_without_max_sites=False):
-     if structure_with_oxi := _guess_and_set_struct_oxi_states(structure):
-         return structure_with_oxi
-     return _guess_and_set_struct_oxi_states_icsd_prob(structure, try_without_max_sites)

+ def guess_and_set_struct_oxi_states(structure, try_without_max_sites=False):
+     return _guess_and_set_struct_oxi_states(structure) or _guess_and_set_struct_oxi_states_icsd_prob(structure, try_without_max_sites)
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.

Suggested change
def guess_and_set_struct_oxi_states(structure, try_without_max_sites=False):
"""
Tries to guess (and set) the oxidation states of the input structure, first
using the ``pymatgen`` ``BVAnalyzer`` class, and if that fails, using the
ICSD oxidation state probabilities to guess.
Args:
structure (Structure): The structure for which to guess the oxidation states.
try_without_max_sites (bool):
Whether to try to guess the oxidation states
without using the ``max_sites=-1`` argument (``True``)(which attempts
to use the reduced composition for guessing oxi states) or not (``False``),
when using the ICSD oxidation state probability guessing.
Returns:
Structure: The structure with oxidation states guessed and set, or ``False``
if oxidation states could not be guessed.
"""
if structure_with_oxi := _guess_and_set_struct_oxi_states(structure):
return structure_with_oxi
return _guess_and_set_struct_oxi_states_icsd_prob(structure, try_without_max_sites)
def guess_and_set_struct_oxi_states(structure, try_without_max_sites=False):
"""
Tries to guess (and set) the oxidation states of the input structure, first
using the ``pymatgen`` ``BVAnalyzer`` class, and if that fails, using the
ICSD oxidation state probabilities to guess.
Args:
structure (Structure): The structure for which to guess the oxidation states.
try_without_max_sites (bool):
Whether to try to guess the oxidation states
without using the ``max_sites=-1`` argument (``True``)(which attempts
to use the reduced composition for guessing oxi states) or not (``False``),
when using the ICSD oxidation state probability guessing.
Returns:
Structure: The structure with oxidation states guessed and set, or ``False``
if oxidation states could not be guessed.
"""
return _guess_and_set_struct_oxi_states(structure) or _guess_and_set_struct_oxi_states_icsd_prob(structure, try_without_max_sites)

Comment on lines +1291 to +1297
lambda x: f"{x:.2%}"
)
conc_df = conc_df.drop(columns=["Raw Charge", "Raw Concentration"])
return conc_df.reset_index(drop=True)

# group by defect and sum concentrations:
summed_df = conc_df.groupby("Defect").sum(numeric_only=True)
summed_df[next(k for k in conc_df.columns if k.startswith("Concentration"))] = (
summed_df["Raw Concentration"]
if skip_formatting
else summed_df["Raw Concentration"].apply(lambda x: f"{x:.3e}")
)
return summed_df.drop(
columns=[
i
for i in ["Charge", "Formation Energy (eV)", "Raw Charge", "Raw Concentration"]
if i in summed_df.columns
]
return _group_defect_charge_state_concentrations(
Copy link

Choose a reason for hiding this comment

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

Refactor the lambda function for clarity.

The lambda function used in the transformation of Charge State Population could be refactored into a named function for better readability and potential reuse.

- lambda x: f"{x:.2%}"
+ def format_percentage(value):
+     return f"{value:.2%}"

Then replace the lambda with format_percentage.

Committable suggestion was skipped due to low confidence.

@@ -106,8 +105,7 @@ def setUp(self):
atoms = bulk("Cu")
atoms = make_supercell(atoms, [[2, 0, 0], [0, 2, 0], [0, 0, 2]])
atoms.set_chemical_symbols(["Cu", "Ag"] * 4)
aaa = AseAtomsAdaptor()
self.agcu = aaa.get_structure(atoms)
self.agcu = Structure.from_ase_atoms(atoms)
Copy link

Choose a reason for hiding this comment

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

Replace Structure.from_ase_atoms(atoms) with Structure.from_atoms(atoms) for consistency.

- self.agcu = Structure.from_ase_atoms(atoms)
+ self.agcu = Structure.from_atoms(atoms)
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.

Suggested change
self.agcu = Structure.from_ase_atoms(atoms)
self.agcu = Structure.from_atoms(atoms)

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.

1 participant