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

Replace site.species_and_occu with site.species property for compatible pymatgen versions #3480

Conversation

astamminger
Copy link
Contributor

Fixes #3297

Added check for the used pymatgen version and dynamically switch to Site.species property if applicable (i.e. pymatgen>=2019.3.13). Prior to 2019.3.13 the old Site.species_and_occu property is used.

use site.species for pymatgen versions >= 2019.3.13 and keep
backward compatability by falling back to the old site.species_and_occu
for versions < 2019.3.13.
Copy link
Member

@greschd greschd left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this! 😃 Looks good overall.

for site in struct.sites:

# site.species property first introduced in pymatgen version 2019.3.13
if pymatgen_version < (2019, 3, 13):
Copy link
Member

Choose a reason for hiding this comment

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

I think here it'd be better to just do plain string comparison - something like "2019.3.13b2" would also be a legal version string (although pymatgen doesn't seem to use it). That would break the int conversion above.

Sorry for the nit-pick 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

Better still I would say is to use something like:

from distutils.version import StrictVersion
current_version = StrictVersion(get_pymatgen_version())
required_version = StrictVersion('2019.3.13')
if current_version < required_version:
    species_and_occu = site.species_and_occu

Copy link
Member

@greschd greschd Oct 29, 2019

Choose a reason for hiding this comment

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

Nice 👍

Btw, do we want to bump the pymatgen version in setup.json? It's currently at "pymatgen<=2018.12.12". Not sure what the differences are though, tbh.

This issue came up because some dependency of mine changed the pymatgen version.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can't unfortunately because they dropped python 2 support after that.

Copy link
Member

Choose a reason for hiding this comment

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

Soon... 😎

@greschd
Copy link
Member

greschd commented Oct 29, 2019

I think you can ignore the coverall failure, but I'll leave that to @sphuber to confirm.

@@ -18,6 +18,7 @@
import itertools
import copy
from functools import reduce
from packaging import version
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the update @astamminger . One question: is there a reason you prefer the dependency packaging over the standard library distutils?

Copy link
Contributor Author

@astamminger astamminger Oct 30, 2019

Choose a reason for hiding this comment

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

Was about to write a comment on that but you were too fast :D Mainly the reason was that AFAIK StrictVersion provided by distutils does not comply to PEP440 so I thoughtpackaging might be a better alternative (But I'm happy to change that if you prefer to use distutils)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I didn't know that. It seems indeed that packaging seems the more reliable option. I was just worried about it being third-party and therefore adding an implicit dependency, but since it gets installed by setuptools that is ok

Copy link
Member

Choose a reason for hiding this comment

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

From looking at the list of maintainers on PyPI, packaging seems pretty solid. We should add it as an explicit dependency in setup.json if we use it explicitly, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add the dependency to the atomic_tools extra @astamminger ? Since it is only used in combination with pymatgen I think it is ok to just put it in that extra

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we move the import to the function itself then? Might be easier to just put it in the general dependencies.

Copy link
Contributor Author

@astamminger astamminger Oct 30, 2019

Choose a reason for hiding this comment

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

We could also use pkg_resources.parse_version() which is distributed with setuptools so we can avoid adding an additional dependency plus being PEP440 conform. What do you think?

// EDIT: No idea what's going on with the coveralls, though!

Copy link
Member

Choose a reason for hiding this comment

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

Go for it 👍 Let's try not to bike-shed too hard here..

I have a feeling the coveralls can be a bit flaky sometimes.

greschd
greschd previously approved these changes Oct 30, 2019
@sphuber
Copy link
Contributor

sphuber commented Nov 8, 2019

@astamminger if you can move the pkg_resources import within the pymatgen function, we do not have to add it to the explicit dependencies. If you can do that final thing I will approve and merge this, thanks!

@sphuber sphuber self-requested a review November 9, 2019 11:31
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 @astamminger

@sphuber sphuber merged commit 93f56a9 into aiidateam:develop Nov 9, 2019
@sphuber sphuber modified the milestone: v1.0.1 Nov 22, 2019
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.

Pymatgen interface: species_and_occu deprecated
3 participants