-
Notifications
You must be signed in to change notification settings - Fork 33
chore: deprecated addNewAtom #157
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ed7fc6
build: deprecate addNewItem
stevenhua0320 6e99082
build: change body of deprecated function
stevenhua0320 95138f7
build: add test cases for addNewAtom to test it & show deprecation me…
stevenhua0320 3f285b6
fix: refine test code to avoid if logic
stevenhua0320 1fc8a34
test: add docstring and comments to the test.
stevenhua0320 cb7aec0
fix: add more test cases and refine behavior of add_new_atom
stevenhua0320 114f3d6
fix: add docstring for hyperparamter for add_new_atom
stevenhua0320 40e8773
fix: fix comment with syntax error
stevenhua0320 8f8253c
fix: change behavior to warning and use pytest parametrize to test it.
stevenhua0320 15ccba1
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] 52c99e6
fix: fix comment for UserWarning.
stevenhua0320 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * Added `diffpy.structure.Structure.add_new_atom` in replace of `addNewAtom` | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * Deprecated `diffpy.structure.Structure.addNewAtom` method for removal in version 4.0.0 | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| numpy | ||
| pycifrw | ||
| diffpy.utils |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| numpy | ||
| pycifrw | ||
| diffpy.utils |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,59 @@ def test___copy__(self): | |
| # """check Structure.getLastAtom()""" | ||
| # return | ||
|
|
||
| def test_add_new_atom(self): | ||
| """Check Structure.add_new_item()""" | ||
| # Case 1: valid atom added to an empty structure. | ||
| # Expect the atom list length to go from 0 to 1. | ||
| # Expect the atom attributes are successfully loaded. | ||
| s_lat = Lattice() | ||
| structure = Structure(lattice=s_lat) | ||
| length = len(structure) | ||
| structure.add_new_atom(atype="C", xyz=[0.1, 0.2, 0.3]) | ||
| expected = len(structure) | ||
| actual = length + 1 | ||
| assert expected == actual | ||
| atom_object = structure[-1] | ||
| assert atom_object.element == "C" | ||
| assert numpy.allclose(atom_object.xyz, [0.1, 0.2, 0.3]) | ||
|
|
||
| # Case 2: valid atom added to existing atom list. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is lots of copy-pasted code here. I think using parametrize is better |
||
| # Expect the atom list length to go from 1 to 2. | ||
| # Expect the atom attributes are successfully loaded. | ||
| length = len(structure) | ||
| structure.add_new_atom(atype="Ni", xyz=[0.8, 1.2, 0.9]) | ||
| expected = len(structure) | ||
| actual = length + 1 | ||
| assert expected == actual | ||
| atom_object = structure[-1] | ||
| assert atom_object.element == "Ni" | ||
| assert numpy.allclose(atom_object.xyz, [0.8, 1.2, 0.9]) | ||
|
|
||
| # Case 3: duplicated atom added to the existing atom list. | ||
| # Expect the atom not to be added and gives a ValueError. | ||
| with pytest.raises(ValueError, match=r"Duplicate atom C already exists at array\(\[0\.1, 0\.2, 0\.3\]\)"): | ||
| structure.add_new_atom(atype="C", xyz=[0.1, 0.2, 0.3]) | ||
| actual = len(structure) | ||
| expected = 2 | ||
| assert expected == actual | ||
|
|
||
| def test_addNewAtom(self): | ||
| """Duplicate test for the deprecated addNewAtom method. | ||
|
|
||
| Remove this test in version 4.0.0 | ||
| """ | ||
| s_lat = Lattice() | ||
| structure = Structure(lattice=s_lat) | ||
|
|
||
| length = len(structure) | ||
| structure.addNewAtom(atype="C", xyz=[0.1, 0.2, 0.3]) | ||
| expected = len(structure) | ||
| actual = length + 1 | ||
| assert expected == actual | ||
| atom_object = structure[-1] | ||
| assert atom_object.element == "C" | ||
| assert numpy.allclose(atom_object.xyz, [0.1, 0.2, 0.3]) | ||
|
|
||
| def test_assignUniqueLabels(self): | ||
| """Check Structure.assignUniqueLabels()""" | ||
| self.assertEqual("", "".join([a.label for a in self.stru])) | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is undesirable behavior. Let's allow the atom to be added. We could raise a warning. But I think it is on the user to get this how they want it. So I would be inclined to simply allow it.