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

Importing StructureData with kind masses of None #3525

Open
CasperWA opened this issue Nov 8, 2019 · 1 comment
Open

Importing StructureData with kind masses of None #3525

CasperWA opened this issue Nov 8, 2019 · 1 comment

Comments

@CasperWA
Copy link
Contributor

CasperWA commented Nov 8, 2019

It seems in an alpha release that I was "allowed" to import StructureData containing kinds having mass = None.

Since we do not allow nan, inf or -inf anymore, this should not be allowed.
If it has not already been fixed, it should be checked upon import and a solution should be found - either to discard the whole import or simply warn the user and skip the violating nodes?

@CasperWA CasperWA added this to the v1.0.1 milestone Nov 8, 2019
@CasperWA CasperWA self-assigned this Nov 8, 2019
@sphuber
Copy link
Contributor

sphuber commented Nov 9, 2019

Do you still have the export file and if so can you share the content of the offending structure data, i.e. its attributes? Also, can you share the attributes of the imported StructureData node. Because I am a bit surprised, if you try to forcefully store a structure with a kind that has an invalid mass, i.e. None, it will raise. Demonstration:

from aiida.orm import StructureData

cell = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
structure = StructureData(cell=cell)
structure.append_atom(position=(0., 0., 0.), symbols='Si', name='Si')
attributes structure.attributes
attributes['kinds'][0]['mass'] = None
structure.reset_attributes(attributes)
structure.store()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-a288378b5e1a> in <module>()
----> 1 structure.store()

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/node.py in store(self, with_transaction, use_cache)
   1010         if not self.is_stored:
   1011 
-> 1012             self._validate()
   1013 
   1014             # Verify that parents are already stored. Raises if this is not the case.

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/data/structure.py in _validate(self)
    936         try:
    937             # This will try to create the kinds objects
--> 938             kinds = self.kinds
    939         except ValueError as exc:
    940             raise ValidationError('Unable to validate the kinds: {}'.format(exc))

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/data/structure.py in kinds(self)
   1506         except AttributeError:
   1507             raw_kinds = []
-> 1508         return [Kind(raw=i) for i in raw_kinds]
   1509 
   1510     def get_kind(self, kind_name):

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/data/structure.py in <listcomp>(.0)
   1506         except AttributeError:
   1507             raw_kinds = []
-> 1508         return [Kind(raw=i) for i in raw_kinds]
   1509 
   1510     def get_kind(self, kind_name):

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/data/structure.py in __init__(self, **kwargs)
   1952                 raise ValueError("You didn't specify either 'symbols' or 'weights' in the raw site data.")
   1953             try:
-> 1954                 self.mass = raw['mass']
   1955             except KeyError:
   1956                 raise ValueError("You didn't specify the site mass in the raw site data.")

/home/sphuber/code/aiida/env/dev/aiida-core/aiida/orm/nodes/data/structure.py in mass(self, value)
   2142     @mass.setter
   2143     def mass(self, value):
-> 2144         the_mass = float(value)
   2145         if the_mass <= 0:
   2146             raise ValueError('The mass must be positive.')

TypeError: float() argument must be a string or a number, not 'NoneType'

If there was a bug that allowed storing this in alpha, I don't think we have to do something about it now, since it was an alpha and now it is no longer possible in any case.

@sphuber sphuber modified the milestones: v1.0.1, v1.1.1 Nov 22, 2019
@sphuber sphuber removed this from the v1.1.1 milestone Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants