You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* migration to mkdocs materials
* adding temporarily actions for mkdocs branch
* fix to github action
* fixing the github action and adding deps
* fixing action
* new path for build
* removing strict parameter in docs build
@@ -43,16 +44,14 @@ Now you can make changes and they'll be immediately reflected in your Python env
43
44
### 5. Create a Pull Request
44
45
45
46
Go to your fork on GitHub and click "New Pull Request". Provide a clear description of:
47
+
46
48
- What property you're adding
47
49
- Why it's useful
48
50
- Any relevant scientific context
49
51
- Link to related issues (if any)
50
52
51
-
:::{tip}
52
-
Before creating a PR, it's a good idea to open an issue on the main repository to discuss whether the property should be added. The maintainers can provide guidance on the best implementation approach.
53
-
:::
54
-
55
-
---
53
+
!!! tip
54
+
Before creating a PR, it's a good idea to open an issue on the main repository to discuss whether the property should be added. The maintainers can provide guidance on the best implementation approach.
56
55
57
56
## Adding a Site Property
58
57
@@ -76,43 +75,44 @@ class Site(BaseModel):
76
75
)
77
76
```
78
77
79
-
:::{important}
80
-
**Why `default=None` in Field and `"default"` in `json_schema_extra`?**
78
+
!!! note "**Why `default=None` in Field and `"default"` in `json_schema_extra`?**"
81
79
82
-
We use a two-level default system:
80
+
We use a two-level default system:
83
81
84
-
1.**Field `default=None`**: This is the Pydantic field default. Setting it to `None` means:
85
-
- When you create a site without specifying `property_A`, the field is truly undefined (`None`)
86
-
- This lets us distinguish between "property not set" vs "property set to zero"
87
-
- Without this, if we used `default=0.0`, every site would appear to have `property_A` defined, even when unset
82
+
1. **Field `default=None`**: This is the Pydantic field default. Setting it to `None` means:
88
83
89
-
2.**`json_schema_extra["default"]`**: This is used when expanding arrays:
90
-
- When one site has `property_A=2.5` but another has `property_A=None`
91
-
- The array needs a concrete value for the undefined site, if the above condition is verified
92
-
- We use `Site.get_default_values()['property_A']` to get `0.0` as the fill value
1. **Check for all None first**: If all sites have `property_A=None`, return `None` for the entire array. This indicates the property is truly undefined for the structure.
163
164
164
-
1.**Check for all None first**: If all sites have `property_A=None`, return `None` for the entire array. This indicates the property is truly undefined for the structure.
165
+
2. **Use `Site.get_default_values()`**: Instead of hardcoding defaults, retrieve them from the Site field metadata:
Site properties in the `Site` model are singular (`charge`, `mass`), but they're accessed as arrays through computed fields with plural names (`charges`, `masses`). The validation checks for the array forms since that's what your plugin actually uses:
137
+
Site properties in the `Site` model are singular (`charge`, `mass`), but they're accessed as arrays through computed fields with plural names (`charges`, `masses`). The validation checks for the array forms since that's what your plugin actually uses:
138
+
139
+
```python
140
+
# In your plugin, you access:
141
+
structure.properties.charges # Array of all charges, what you will use
142
+
# Not:
143
+
structure.properties.sites[0].charge # Individual site charge (you don't validate this)
144
+
```
139
145
140
-
```python
141
-
# In your plugin, you access:
142
-
structure.properties.charges # Array of all charges, what you will use
143
-
# Not:
144
-
structure.properties.sites[0].charge # Individual site charge (you don't validate this)
145
-
```
146
-
:::
147
146
148
147
#### Step 2: Add Validation Logic
149
148
@@ -201,13 +200,13 @@ class MyCalculation(CalcJob):
201
200
)
202
201
```
203
202
204
-
:::{note}
205
-
You can also put the validation in the WorkChains using the given CalcJob, to stop prematurely instead of performing some steps and then exit only when trying to submit with the wrong structure.
206
-
:::
203
+
!!! tip
204
+
You can also put the validation in the WorkChains using the given CalcJob, to stop prematurely instead of performing some steps and then exit only when trying to submit with the wrong structure.
205
+
206
+
207
+
!!! tip
208
+
Of course, you will also need to add the logic to write your input file starting from the structure properties, which before were defined in the `parameters` input `orm.Dict` (at least in the aiida-quantumespresso plugin).
207
209
208
-
:::{note}
209
-
Of course, you will also need to add the logic to write your input file starting from the structure properties, which before were defined in the `parameters` input `orm.Dict` (at least in the aiida-quantumespresso plugin).
0 commit comments