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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FIX: Add __str__ method to Orbital Class #4829

Merged
merged 5 commits into from Mar 31, 2021
Merged

馃悰 FIX: Add __str__ method to Orbital Class #4829

merged 5 commits into from Mar 31, 2021

Conversation

NinadBhat
Copy link
Contributor

@NinadBhat NinadBhat commented Mar 20, 2021

Fixes #4347

The absence of str was leading to recursion RecursionError #4347. So have added a str method.

@codecov
Copy link

codecov bot commented Mar 20, 2021

Codecov Report

Merging #4829 (0a54de3) into develop (d35a9d7) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4829      +/-   ##
===========================================
+ Coverage    79.54%   79.54%   +0.01%     
===========================================
  Files          519      519              
  Lines        37088    37092       +4     
===========================================
+ Hits         29497    29502       +5     
+ Misses        7591     7590       -1     
Flag Coverage 螖
django 74.28% <100.00%> (+0.01%) 猬嗭笍
sqlalchemy 73.19% <100.00%> (+0.01%) 猬嗭笍

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage 螖
aiida/tools/data/orbital/orbital.py 85.19% <100.00%> (+0.77%) 猬嗭笍
aiida/transports/plugins/local.py 81.80% <0.00%> (+0.26%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update d35a9d7...0a54de3. Read the comment docs.

@greschd
Copy link
Member

greschd commented Mar 22, 2021

I don't know our convention for what the result of __str__ should look like, maybe @ltalirz or @chrisjsewell can review this?

@sphuber
Copy link
Contributor

sphuber commented Mar 22, 2021

There isn't a well defined convention yet, other than the Python standard that __str__ should be human readable for users and __repr__ is meant for debugging. For node instances (where there is little difference in the two cases I would say), we have been slowly converging on a format like:

NodeClass<IDENTIFIER>: CONTENT

so for this case, we could do something like

Orbital<1533>: [x, y, z](theta, phi, sigma)

For the identifier we typically take the PK. It is less transferable than the UUID, but the UUID is often very long and not always needed. I am not too familiar with the class itself, so the CONTENT I proposed is really just a rough idea adding the position vector and the angles and spin orientation in a separate vector. Feel free to adapt this as needed.

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @NinadBhat . I responded in a separate comment on the suggested format of the string returned by __str__. Let's wait to see if we can get confirmation from someone else. If they do, please change to that suggested format. Then simply add a test. As @greschd suggested, a simple test that just calls str(Orbital()) should be sufficient.

Comment on lines 119 to 121
out_string = f' orbital @ {position_string}'

return out_string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
out_string = f' orbital @ {position_string}'
return out_string
return f' orbital @ {position_string}'

@ltalirz
Copy link
Member

ltalirz commented Mar 22, 2021

See also #3087

@NinadBhat
Copy link
Contributor Author

@ltalirz I have made the changes.

@chrisjsewell
Copy link
Member

this looks good to me, @ltalirz will merge later today unless you have any objections?

@sphuber
Copy link
Contributor

sphuber commented Mar 30, 2021

@chrisjsewell in my review I suggested to change the output to Orbital<1533>: [x, y, z](theta, phi, sigma), or at the very least include the identifier of the node. Right now it is impossible to figure out which node is concerned

@chrisjsewell
Copy link
Member

in my review I suggested to change the output

Ah fair, I missed that had not been addressed yet

@NinadBhat
Copy link
Contributor Author

@chrisjsewell I am not sure how to access (theta, phi, sigma) and node in the Orbital class.

@greschd
Copy link
Member

greschd commented Mar 31, 2021

@sphuber note that this is the Orbital class, not OrbitalData - so these instances won't have a pk as far as I understand.

@sphuber
Copy link
Contributor

sphuber commented Mar 31, 2021

@sphuber note that this is the Orbital class, not OrbitalData - so these instances won't have a pk as far as I understand.

Ah my bad! I completely missed this, I was indeed thinking of the OrbitalData. In that case maybe the current proposal is fine. @greschd as a user of the Orbital class, if you think the current __str__ format is fine, let's merge it.

@chrisjsewell chrisjsewell changed the title Adds __str__ method to Orbital Class 馃悰 FIX: Add __str__ method to Orbital Class Mar 31, 2021
@chrisjsewell chrisjsewell merged commit 0772129 into aiidateam:develop Mar 31, 2021
@greschd
Copy link
Member

greschd commented Mar 31, 2021

@greschd as a user of the Orbital class

I'm not really using it directly, but it's definitely better than having #4347.

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.

RecursionError for instances of Orbital class
5 participants