Fix for correct bonds_broken in slab generation #2105
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SlabGenerator._get_c_ranges()
takes in abonds
dictionary and returns a set of tuples of fractional z-coordinates of neighboring (nearest) atoms if they have distinct z-coordinates. This set is then used in theSlabGenerator.get_slabs()
method in order to calculate the total number of broken bonds. The issue with the current version is that the tuples are stored in aset()
which can only have unique elements so all but one of the bonds between say z_coord1 and z_coord2 are ignored.I tested this by simply generating Si(111) slabs, calculating the number of bonds broken reported by pymatgen, and comparing them by what I expect from looking at the slabs in VESTA.
Here's the code I used to generate the slabs;
This prints 0.5 for both terminations whereas looking at the slabs in VESTA, one expects 2 and 6.
By changing c_ranges from a set() to an empty list instead and appending to it, tuples for all the bonds are preserved and the above script prints 2 and 6.
For consistency, I also changed c_ranges to an empty list if
bonds
isNone
inget_slabs()
.