Skip to content

Commit

Permalink
This PR reflects an old change in the data model, where material iden…
Browse files Browse the repository at this point in the history
…tifiers become attributes instead of a list of subnodes. (#434)

* first steps to fix identifier

* making progress

* fix the problems

* fixing pytest tests

* fix spelling

* working through doctest

* fix CI

* fix doctests

* fix notebooks

* another fix

* fix simulation
  • Loading branch information
InnocentBug authored Mar 11, 2024
1 parent e3b76bb commit be6091d
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 305 deletions.
3 changes: 2 additions & 1 deletion .trunk/configs/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"doctest",
"Doctest",
"Doctests",
"linenums"
"linenums",
"XLYOFNOQVPJJNP"
]
}
14 changes: 2 additions & 12 deletions docs/examples/simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,13 @@ bulk.output_data = [final_data]

## Create a virtual Material

First, we'll create a virtual material and add some
[`Identifiers`](../../nodes/primary_nodes/material/#cript.nodes.primary_nodes.material.Material.identifier)
to the material to make it easier to identify and search.
First, we'll create a virtual material with identifiers to make it easier to search for.

```python
# create identifier dictionaries and put it in `identifiers` variable
identifiers = [{"names": ["poly(styrene)", "poly(vinylbenzene)"]}]
identifiers += [{"bigsmiles": "[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC"}]
identifiers += [{"chem_repeat": ["C8H8"]}]

# create a material node object with identifiers
polystyrene = cript.Material(name="virtual polystyrene", identifier=identifiers)
polystyrene = cript.Material(name="virtual polystyrene", bigsmiles="[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC", names = ["poly(styrene)", "poly(vinylbenzene)"], chem_repeat= ["C8H8"])
```

!!! note "Identifier keys"
The allowed [`Identifiers`](../../nodes/primary_nodes/material/#cript.nodes.primary_nodes.material.Material.identifier) keys are listed in the [material identifier keys](https://app.criptapp.org/vocab/material_identifier_key) in the CRIPT controlled vocabulary.

## Add [`Property`](../../nodes/subobjects/property) sub-objects
Let's also add some [`Property`](../../nodes/subobjects/property) nodes to the [`Material`](../../nodes/primary_nodes/material), which represent its physical or virtual (in the case of a simulated material) properties.

Expand Down
25 changes: 7 additions & 18 deletions docs/examples/synthesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,20 @@ They are for example the chemical you buy commercially and use as input into you
For this we create this inventory by adding the [Material](../../nodes/primary_nodes/material) we need one by one.

```python
# create a list of identifiers as dictionaries to
# identify your material to the community and your team
my_solution_material_identifiers = [
{"chemical_id": "598-30-1"}
]

solution = cript.Material(
name="SecBuLi solution 1.4M cHex",
identifier=my_solution_material_identifiers
chemical_id = "598-30-1",
)
```

These materials are simple, notice how we use the SMILES notation here as an identifier for the material.
Similarly, we can create more initial materials.

```python
toluene = cript.Material(name="toluene", identifier=[{"smiles": "Cc1ccccc1"}, {"pubchem_cid": 1140}])
styrene = cript.Material(name="styrene", identifier=[{"smiles": "c1ccccc1C=C"}, {"inchi": "InChI=1S/C8H8/c1-2-8-6-4-3-5-7-8/h2-7H,1H2"}])
butanol = cript.Material(name="1-butanol", identifier=[{"smiles": "OCCCC"}, {"inchi_key": "InChIKey=LRHPLDYGYMQRHN-UHFFFAOYSA-N"}])
methanol = cript.Material(name="methanol", identifier=[{"smiles": "CO"}, {"names": ["Butan-1-ol", "Butyric alcohol", "Methylolpropane", "n-Butan-1-ol", "methanol"]}])
toluene = cript.Material(name="toluene", smiles="Cc1ccccc1", pubchem_cid = 1140)
styrene = cript.Material(name="styrene", smiles = "c1ccccc1C=C", inchi = "InChI=1S/C8H8/c1-2-8-6-4-3-5-7-8/h2-7H,1H2")
butanol = cript.Material(name="1-butanol", smiles = "OCCCC", inchi_key = "InChIKey=LRHPLDYGYMQRHN-UHFFFAOYSA-N")
methanol = cript.Material(name="methanol", smiles = "CO", names = ["Butan-1-ol", "Butyric alcohol", "Methylolpropane", "n-Butan-1-ol", "methanol"])
```

Now that we defined those materials, we can combine them into an inventory
Expand Down Expand Up @@ -250,20 +244,15 @@ that will serve as our product. We give the material a `name` attribute and add
[Project]((../../nodes/primary_nodes/project).

```python
polystyrene = cript.Material(name="polystyrene", identifier=[])
polystyrene = cript.Material(name="polystyrene", bigsmiles="[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC")
project.material += [polystyrene]
```

Let's add some `Identifiers` to the material to make it easier to identify and search.

```python
# create a name identifier
polystyrene.identifier += [{"names": ["poly(styrene)", "poly(vinylbenzene)"]}]

# create a BigSMILES identifier
polystyrene.identifier += [{"bigsmiles": "[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC"}]
# create a chemical repeat unit identifier
polystyrene.identifier += [{"chem_repeat": ["C8H8"]}]
polystyrene.chem_repeat = ["C8H8"]
```

Next, we'll add some [Property](../../nodes/subobjects/property) nodes to the
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ nav:
- Computational Forcefield: nodes/subobjects/computational_forcefield.md
- Condition: nodes/subobjects/condition.md
- Equipment: nodes/subobjects/equipment.md
# - Identifier: nodes/subobjects/identifier.md
- Ingredient: nodes/subobjects/ingredient.md
- Parameter: nodes/subobjects/parameter.md
- Property: nodes/subobjects/property.md
Expand Down
2 changes: 1 addition & 1 deletion src/cript/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def delete(self, node) -> None:
>>> import cript
>>> my_material_node = cript.Material(
... name="my component material 1",
... identifier=[{"amino_acid": "component 1 alternative name"}],
... names = ["component 1 alternative name"],
... )
>>> api.delete(node=my_material_node) # doctest: +SKIP
Expand Down
2 changes: 1 addition & 1 deletion src/cript/api/valid_search_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SearchModes(Enum):
UUID : str
Search by node UUID.
BIGSMILES: str
search materials by bigsmiles identifier.
search materials by bigsmiles.
Examples
-------
Expand Down
8 changes: 4 additions & 4 deletions src/cript/nodes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ def get_expanded_json(self, **kwargs) -> str:
>>> my_project = cript.Project(name=f"my_Project")
>>> my_collection = cript.Collection(name="my collection")
>>> my_material_1 = cript.Material(
... name="my material 1", identifier=[{"bigsmiles": "my material 1 bigsmiles"}]
... name="my material 1", bigsmiles = "my material 1 bigsmiles"
... )
>>> my_material_2 = cript.Material(
... name="my material 2", identifier=[{"bigsmiles": "my material 2 bigsmiles"}]
... name="my material 2", bigsmiles = "my material 2 bigsmiles"
... )
>>> my_inventory = cript.Inventory(
... name="my inventory", material=[my_material_1, my_material_2]
Expand Down Expand Up @@ -511,10 +511,10 @@ def find_children(self, search_attr: dict, search_depth: int = -1, handled_nodes
>>> my_project = cript.Project(name=f"my_Project")
>>> my_collection = cript.Collection(name="my collection")
>>> my_material_1 = cript.Material(
... name="my material 1", identifier=[{"bigsmiles": "my material 1 bigsmiles"}]
... name="my material 1", bigsmiles = "my material 1 bigsmiles"
... )
>>> my_material_2 = cript.Material(
... name="my material 2", identifier=[{"bigsmiles": "my material 2 bigsmiles"}]
... name="my material 2", bigsmiles = "my material 2 bigsmiles"
... )
>>> my_inventory = cript.Inventory(
... name="my inventory", material=[my_material_1, my_material_2]
Expand Down
13 changes: 13 additions & 0 deletions src/cript/nodes/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def __str__(self) -> str:
return error_message


class CRIPTMaterialIdentifierError(CRIPTException):
"""Every material node needs to have at least one identifier set."""

def __init__(self, material_node):
self.material_node = material_node

def __str__(self) -> str:
error_message = "Every Material node needs at least one identifier from "
error_message += " [ 'amino_acid', 'bigsmiles', 'chem_formula', 'chem_repeat', 'chemical_id', 'inchi', 'lot_number', 'names', 'pubchem_cid', 'smiles','vendor'] set."
error_message += f" This node {self.material_node} has none set."
return error_message


class CRIPTJsonDeserializationError(CRIPTException):
"""
## Definition
Expand Down
4 changes: 2 additions & 2 deletions src/cript/nodes/primary_nodes/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ def inventory(self) -> List[Any]:
>>> my_collection = cript.Collection(name="my collection name")
>>> material_1 = cript.Material(
... name="material 1",
... identifier=[{"bigsmiles": "material 1 bigsmiles"}],
... bigsmiles = "material 1 bigsmiles",
... )
>>> material_2 = cript.Material(
... name="material 2",
... identifier=[{"bigsmiles": "material 2 bigsmiles"}],
... bigsmiles = "material 2 bigsmiles",
... )
>>> my_inventory = cript.Inventory(
... name="my inventory name", material=[material_1, material_2]
Expand Down
4 changes: 2 additions & 2 deletions src/cript/nodes/primary_nodes/computation_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(
>>> input_data = cript.Data(name="my data name", type="afm_amp", file=[data_files])
>>> my_material = cript.Material(
... name="my material",
... identifier=[{"names": ["my material alternative name"]}]
... names = ["my material alternative name"]
... )
>>> my_quantity = cript.Quantity(key="mass", value=1.23, unit="kg")
>>> ingredient = cript.Ingredient(
Expand Down Expand Up @@ -368,7 +368,7 @@ def ingredient(self) -> List[Any]:
Examples
--------
>>> import cript
>>> my_material = cript.Material(name="my material", identifier=[{"bigsmiles": "123456"}])
>>> my_material = cript.Material(name="my material", bigsmiles = "my bigsmiles")
>>> my_quantity = cript.Quantity(
... key="mass", value=11.2, unit="kg", uncertainty=0.2, uncertainty_type="stdev"
... )
Expand Down
4 changes: 2 additions & 2 deletions src/cript/nodes/primary_nodes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def computation_process(self) -> Union[Any, None]:
... )
>>> my_material = cript.Material(
... name="my material name",
... identifier=[{"bigsmiles": "123456"}]
... bigsmiles = "123456"
... )
>>> my_quantity = cript.Quantity(
... key="mass", value=11.2, unit="kg", uncertainty=0.2, uncertainty_type="stdev"
Expand Down Expand Up @@ -459,7 +459,7 @@ def material(self) -> List[Any]:
... data_dictionary="my file's data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_material = cript.Material(name="my material name", identifier=[{"bigsmiles": "123456"}])
>>> my_material = cript.Material(name="my material name", bigsmiles = "123456")
>>> my_data.material = [my_material]
Returns
Expand Down
2 changes: 1 addition & 1 deletion src/cript/nodes/primary_nodes/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def computation_process(self) -> List[Any]:
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_material = cript.Material(
... name="my material name", identifier=[{"bigsmiles": "123456"}]
... name="my material name", bigsmiles = "123456"
... )
>>> my_quantity = cript.Quantity(
... key="mass", value=11.2, unit="kg", uncertainty=0.2, uncertainty_type="stdev"
Expand Down
8 changes: 4 additions & 4 deletions src/cript/nodes/primary_nodes/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def __init__(self, name: str, material: List[Material], notes: str = "", **kwarg
>>> import cript
>>> material_1 = cript.Material(
... name="material 1",
... identifier=[{"bigsmiles": "material 1 bigsmiles"}],
... bigsmiles = "material 1 bigsmiles",
... )
>>> material_2 = cript.Material(
... name="material 2",
... identifier=[{"bigsmiles": "material 2 bigsmiles"}],
... bigsmiles = "material 2 bigsmiles",
... )
>>> my_inventory = cript.Inventory(
... name="my inventory name", material=[material_1, material_2]
Expand Down Expand Up @@ -113,12 +113,12 @@ def material(self) -> List[Material]:
>>> import cript
>>> my_material = cript.Material(
... name="my material",
... identifier=[{"bigsmiles": "my bigsmiles"}],
... bigsmiles = "my bigsmiles",
... )
>>> my_inventory = cript.Inventory(name="my inventory", material=[my_material])
>>> new_material = cript.Material(
... name="new material",
... identifier=[{"bigsmiles": "my bigsmiles"}],
... bigsmiles = "my bigsmiles",
... )
>>> my_inventory.material = [new_material]
Expand Down
Loading

0 comments on commit be6091d

Please sign in to comment.