Skip to content

Commit

Permalink
API docs as jn
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci committed Feb 8, 2024
1 parent 6a9daeb commit ed97029
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Charge(BaseProperty):
"""
The charge property.
"""
domain = "per-site"
domain = "intra-site"
default_kind_threshold = 0.45
# units... maybe specify in the docs.
value: List[float] = Field(default=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Mass(BaseProperty):
"""
The mass property.
"""
domain = "per-site"
domain = "intra-site"
default_kind_threshold = 1e-3
# units... maybe specify in the docs.
value: List[float] = Field(default=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Positions(BaseProperty):
"""
The sites property.
"""
domain = "per-site"
domain = "intra-site"
#kind_threshold: float = Field(default=1e-3)
value: List[Tuple[float,float,float]] = Field(default=None)
kind_tags: List[str] = Field(default=None) # thgis should be in position class? Unified, I think so. tipo alla fine del to kind fai un check e resetti.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Symbols(BaseProperty):
"""
The symbols property, intended as the chemical symbols for each atom(site).
"""
domain = "per-site"
domain = "intra-site"
# units... maybe specify in the docs.
value: List[Literal[_valid_symbols]]

Expand Down
19 changes: 10 additions & 9 deletions aiida_atomistic/data/structure/properties/property_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from aiida_atomistic.data.structure.properties.globals.cell import Cell
from aiida_atomistic.data.structure.properties.globals.pbc import Pbc

from aiida_atomistic.data.structure.properties.per_site.position import Positions
from aiida_atomistic.data.structure.properties.per_site.symbols import Symbols
from aiida_atomistic.data.structure.properties.per_site.mass import Mass
from aiida_atomistic.data.structure.properties.per_site.charge import Charge
from aiida_atomistic.data.structure.properties.intra_site.position import Positions
from aiida_atomistic.data.structure.properties.intra_site.symbols import Symbols
from aiida_atomistic.data.structure.properties.intra_site.mass import Mass
from aiida_atomistic.data.structure.properties.intra_site.charge import Charge

from aiida_atomistic.data.structure.properties.custom import CustomProperty

Expand Down Expand Up @@ -72,8 +72,9 @@ def __init__(
self._inspect_properties(properties)


def get_valid_properties(self,):
"""def get_supported_properties(self,):
return list(typing.get_type_hints(self.__class__).keys())
"""

def get_property_attribute(self, key):
# In AiiDA this could be self.base.attrs['properties'][key] or similar
Expand All @@ -86,11 +87,11 @@ def _inspect_properties(self,properties):
have a defined prefix.
"""
for pname,pvalue in properties.items():
if pname not in self.get_valid_properties():
raise NotImplementedError(f"Property '{pname}' is not yet supported.\nSupported properties are: {self.get_valid_properties()}")
if pname not in self.get_supported_properties():
raise NotImplementedError(f"Property '{pname}' is not yet supported.\nSupported properties are: {self.get_supported_properties()}")
# custom properties:
#elif pname in self.get_valid_properties():
# raise NotImplementedError(f"Property '{pname}' is not yet supported.\nSupported properties are: {self.get_valid_properties()}")
#elif pname in self.get_supported_properties():
# raise NotImplementedError(f"Property '{pname}' is not yet supported.\nSupported properties are: {self.get_supported_properties()}")
elif not pvalue:
raise ValueError(f"Property '{pname}' has not value provided.")
elif len(pvalue)==0:
Expand Down
8 changes: 4 additions & 4 deletions aiida_atomistic/data/structure/properties/property_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ def _database_wise_setter(self, pname, pvalue):
self._parent.base.attributes.set("_property_attributes",property_attributes)
return

def get_valid_properties(self):
def get_supported_properties(self):
# Get the implemented properties
return self._valid_properties.copy()
return list(self._valid_properties.copy())

def get_defined_properties(self):
def get_stored_properties(self):
# Get the properties that you already set
property_attributes = self._parent.base.attributes.get("_property_attributes")
return list(set(self.get_valid_properties()).intersection(
return list(set(self.get_supported_properties()).intersection(
property_attributes.keys()
))

Expand Down
9 changes: 4 additions & 5 deletions aiida_atomistic/data/structure/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,14 +783,13 @@ def properties(self):
@properties.setter
def properties(self,value):
raise AttributeError("After the initialization, `properties` is a read-only attribute")



def to_dict(self):
"""
Returns a dictionary with the properties defined.
Used to generate new StructureData with some changed/updated properties.
"""
return self.base.attributes.get('_property_attributes')
return copy.deepcopy(self.base.attributes.get('_property_attributes'))


def get_kinds(self, use_kind_tag = False, use_kind_name = True):
Expand Down Expand Up @@ -830,9 +829,9 @@ def get_kinds(self, use_kind_tag = False, use_kind_name = True):
# Step 1:
kind_properties = []
kinds_values = {}
for single_property in self.properties.get_defined_properties():
for single_property in self.properties.get_stored_properties():
prop = getattr(self.properties,single_property)
if prop.domain == "per-site" and not single_property in ["symbols","positions"]:
if prop.domain == "intra-site" and not single_property in ["symbols","positions"]:
kinds_per_property = prop.to_kinds()
kind_properties.append(kinds_per_property[0])
kinds_values[single_property] = kinds_per_property[1]
Expand Down
Loading

0 comments on commit ed97029

Please sign in to comment.