-
Notifications
You must be signed in to change notification settings - Fork 845
Fix guess_TopologyAttrs for empty Elements and Atomtypes #5416
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
| import pytest | ||
| from MDAnalysis import _GUESSERS, _TOPOLOGY_ATTRS | ||
| from MDAnalysis.core.topology import Topology | ||
| from MDAnalysis.core.topologyattrs import Atomnames, Atomtypes, Masses | ||
| from MDAnalysis.core.topologyattrs import Atomnames, Atomtypes, Elements, Masses | ||
| from MDAnalysis.exceptions import NoDataError | ||
| from MDAnalysis.guesser.base import GuesserBase, get_guesser | ||
| from numpy.testing import assert_allclose, assert_equal | ||
|
|
@@ -58,16 +58,13 @@ class TestGuesser1(GuesserBase): | |
| def test_guess_invalid_attribute(self): | ||
| with pytest.raises( | ||
| ValueError, | ||
| match="default guesser can not guess " | ||
| "the following attribute: foo", | ||
| match="default guesser can not guess " "the following attribute: foo", | ||
| ): | ||
| mda.Universe(datafiles.PDB_xsmall, to_guess=["foo"]) | ||
|
|
||
| def test_guess_attribute_with_missing_parent_attr(self): | ||
| names = Atomnames(np.array(["C", "HB", "HA", "O"], dtype=object)) | ||
| masses = Masses( | ||
| np.array([np.nan, np.nan, np.nan, np.nan], dtype=np.float64) | ||
| ) | ||
| masses = Masses(np.array([np.nan, np.nan, np.nan, np.nan], dtype=np.float64)) | ||
| top = Topology(4, 1, 1, attrs=[names, masses]) | ||
| u = mda.Universe(top, to_guess=["masses"]) | ||
| assert_allclose( | ||
|
|
@@ -88,9 +85,7 @@ def test_partial_guessing(self): | |
| masses = Masses(np.array([0, np.nan, np.nan, 0], dtype=np.float64)) | ||
| top = Topology(4, 1, 1, attrs=[types, masses]) | ||
| u = mda.Universe(top, to_guess=["masses"]) | ||
| assert_allclose( | ||
| u.atoms.masses, np.array([0, 1.00800, 1.00800, 0]), atol=0 | ||
| ) | ||
| assert_allclose(u.atoms.masses, np.array([0, 1.00800, 1.00800, 0]), atol=0) | ||
|
|
||
| def test_force_guess_priority(self): | ||
| "check that passing the attribute to force_guess have higher power" | ||
|
|
@@ -104,14 +99,21 @@ def test_force_guess_priority(self): | |
| atol=0, | ||
| ) | ||
|
|
||
| def test_partial_guess_attr_with_unknown_no_value_label(self): | ||
|
Member
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. The fact that there's a test that checks for the behavior that you're changing should at least give pause for thought. Why are you changing the name and the outcome for this test? |
||
| "trying to partially guess attribute tha doesn't have declared" | ||
| "no_value_label should gives no effect" | ||
| def test_partial_guess_types_with_missing_value_label(self): | ||
| """Atomtypes with empty string values are guessed because | ||
| missing_value_label is defined as an empty string.""" | ||
| names = Atomnames(np.array(["C", "H", "H", "O"], dtype=object)) | ||
| types = Atomtypes(np.array(["", "", "", ""], dtype=object)) | ||
| top = Topology(4, 1, 1, attrs=[names, types]) | ||
| u = mda.Universe(top, to_guess=["types"]) | ||
| assert_equal(u.atoms.types, ["", "", "", ""]) | ||
| assert_equal(u.atoms.types, ["C", "H", "H", "O"]) | ||
|
|
||
| def test_partial_guess_elements_with_missing_value_label(self): | ||
|
Member
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. Adding this test that checks for your functionality is ok. |
||
| names = Atomnames(np.array(["C1", "N1"], dtype=object)) | ||
| elements = Elements(np.array(["C", ""], dtype=object)) | ||
| top = Topology(2, 1, 1, attrs=[names, elements]) | ||
| u = mda.Universe(top, to_guess=["elements"]) | ||
| assert_equal(u.atoms.elements, ["C", "N"]) | ||
|
|
||
| def test_guess_topology_objects_existing_read(self): | ||
| u = mda.Universe(datafiles.CONECT) | ||
|
|
@@ -185,9 +187,7 @@ def test_guess_topology_objects_out_of_order_guess(self): | |
| with pytest.raises(NoDataError): | ||
| u.atoms.angles | ||
|
|
||
| u.guess_TopologyAttrs( | ||
| "default", to_guess=["dihedrals", "angles", "bonds"] | ||
| ) | ||
| u.guess_TopologyAttrs("default", to_guess=["dihedrals", "angles", "bonds"]) | ||
| assert len(u.atoms.angles) == 290 | ||
| assert len(u.atoms.dihedrals) == 411 | ||
|
|
||
|
|
@@ -249,9 +249,7 @@ def test_guess_singular(self): | |
|
|
||
|
|
||
| def test_Universe_guess_bonds_deprecated(): | ||
| with pytest.warns( | ||
| DeprecationWarning, match="`guess_bonds` keyword is deprecated" | ||
| ): | ||
| with pytest.warns(DeprecationWarning, match="`guess_bonds` keyword is deprecated"): | ||
| u = mda.Universe(datafiles.PDB_xsmall, guess_bonds=True) | ||
|
|
||
|
|
||
|
|
||
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.
There are a lot of formatting changes in the file that make the diff hard to read. Why did you change the formatting?