Skip to content

Commit

Permalink
Fixing the to_mutable and to_immutable names.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Jul 19, 2024
1 parent 735f064 commit bb64eac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions docs/docs/source/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Two main rules: (i) immutability, and (ii) site-based. This means that our node will be just a container of the crystal structure + properties, and it cannot really be modified in any way.
We will only provide `from_*`, `get_*` and `to_*` methods. Each site property will be defined as site-based and not kind-based, at variance with the old `orm.StructureData`. Kinds now can be defined as a property of each site (`kind_name`).

The idea is to provide another python class which is just the mutable version of the `atomistic.StructureData` used to build, manipulate the crystal structure before the effective AiiDA node initialization. For now, let's call this class `StructureDataMutable`. This two classes have the same data structure, i.e. the same `properties` and the same `from_*`, `get_*` and `to_*` methods. The only difference is that the `atomistic.StructureDataMutable` has also `set_*` methods which can be used to mutate the properties. **Rule**: no property can be modified directly (i.e. accessing it); this is useful to avoid the introduction of inconsistencies in the structure instance.
The idea is to provide another python class which is just the mutable version of the `atomistic.StructureData` used to build, manipulate the crystal structure before the effective AiiDA node initialization. For now, let's call this class `StructureDataMutable`. This two classes have the same data structure, i.e. the same `properties` and the same `from_*`, `get_*` and `to_*` methods. The only difference is that the `atomistic.StructureDataMutable` has also `set_*` methods which can be used to mutate the properties.
TODO: properties can also be modified directly, and then the validation will happen only if we initialise the immutable `StructureData`.


## How to initialize the `StructureData`(s)
Expand Down Expand Up @@ -186,12 +187,12 @@ from aiida import orm
structure = orm.load_node(<StructureData pk>)


mutable_structure = structure.to_mutable()
mutable_structure = structure.to_immutable()
mutable_structure.set_charges([1, 0])

mutable_structure.set_kind_names(['Si2','Si1'])

new_structure = mutable_structure.to_immutable()
new_structure = mutable_structure.to_mutable()
```

Other available methods are `add_atom`, `pop_atom`, `update_site` and so on.
Expand Down
6 changes: 3 additions & 3 deletions src/aiida_atomistic/data/structure/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,11 +1444,11 @@ def __init__(self,
self.base.attributes.set(prop, value)

global_properties = self.get_global_properties()
#for prop, value in global_properties.items():
# self.base.attributes.set(prop, value)
for prop, value in global_properties.items():
self.base.attributes.set(prop, value)


def to_immutable(self):
def to_mutable(self):
from .mutable import StructureDataMutable

return StructureDataMutable(**self.to_dict())

0 comments on commit bb64eac

Please sign in to comment.