Skip to content

Commit 28397bc

Browse files
authored
Merge pull request #102 from CitrineInformatics/mols-2-cake
Add molecular structure types to cake example
2 parents 79a5aea + 8e8ba68 commit 28397bc

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

gemd/demo/cake.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
import random
55

66
from gemd.entity.attribute import Condition, Parameter, Property, PropertyAndConditions
7-
from gemd.entity.bounds import IntegerBounds, RealBounds, CategoricalBounds, CompositionBounds
7+
from gemd.entity.bounds import IntegerBounds, RealBounds, CategoricalBounds, CompositionBounds, \
8+
MolecularStructureBounds
89
from gemd.entity.object import ProcessSpec, ProcessRun, MaterialSpec, MaterialRun, \
910
MeasurementSpec, MeasurementRun, IngredientSpec, IngredientRun
1011
from gemd.entity.template import ProcessTemplate, MaterialTemplate, MeasurementTemplate, \
1112
PropertyTemplate, ParameterTemplate, ConditionTemplate
1213
from gemd.entity.value import NominalInteger, UniformInteger, \
1314
NominalReal, NormalReal, UniformReal, \
1415
NominalCategorical, DiscreteCategorical, \
15-
NominalComposition, EmpiricalFormula
16+
NominalComposition, EmpiricalFormula, \
17+
Smiles, InChI
1618
from gemd.enumeration.origin import Origin
1719

1820
from gemd.entity.util import complete_material_history, make_instance
@@ -113,6 +115,11 @@ def make_cake_templates():
113115
description="The chemical formula of a material",
114116
bounds=CompositionBounds(components=EmpiricalFormula.all_elements())
115117
)
118+
tmpl["Molecular Structure"] = PropertyTemplate(
119+
name="Molecular Structure",
120+
description="The molecular structure of the material",
121+
bounds=MolecularStructureBounds()
122+
)
116123

117124
# Objects
118125
tmpl["Baking in an oven"] = ProcessTemplate(
@@ -165,7 +172,8 @@ def make_cake_templates():
165172
name="Formulaic Material",
166173
description="A material with chemical characterization",
167174
properties=[
168-
tmpl["Chemical Formula"]
175+
tmpl["Chemical Formula"],
176+
tmpl["Molecular Structure"]
169177
]
170178
)
171179
tmpl["Icing"] = ProcessTemplate(name="Icing",
@@ -431,7 +439,12 @@ def ingredient_kwargs(material):
431439
],
432440
notes='Plain old NaCl',
433441
properties=[
434-
PropertyAndConditions(Property(name='Formula', value=EmpiricalFormula("NaCl")))
442+
PropertyAndConditions(Property(name='Formula', value=EmpiricalFormula("NaCl"))),
443+
PropertyAndConditions(
444+
Property(name='InChI',
445+
value=InChI("InChI=1S/ClH.Na/h1H;/q;+1/p-1"),
446+
template=tmpl["Molecular Structure"])
447+
)
435448
]
436449
)
437450
IngredientSpec(
@@ -456,7 +469,13 @@ def ingredient_kwargs(material):
456469
],
457470
notes='Sugar',
458471
properties=[
459-
PropertyAndConditions(Property(name="Formula", value=EmpiricalFormula("C12H22O11")))
472+
PropertyAndConditions(Property(name="Formula", value=EmpiricalFormula("C12H22O11"))),
473+
PropertyAndConditions(
474+
Property(name='SMILES',
475+
value=Smiles("C(C1C(C(C(C(O1)OC2(C(C(C(O2)CO)O)O)CO)O)O)O)O"),
476+
template=tmpl["Molecular Structure"]
477+
)
478+
)
460479
]
461480
)
462481
IngredientSpec(
@@ -670,9 +689,10 @@ def make_cake(seed=None, tmpl=None, cake_spec=None):
670689
std=0.05 * item.spec.absolute_quantity.nominal,
671690
units=item.spec.absolute_quantity.units)
672691
if item.spec.volume_fraction is not None:
692+
# The only element here is dry mix, and it's almost entirely flour
673693
item.volume_fraction = \
674-
NormalReal(mean=fuzz * item.spec.volume_fraction.nominal,
675-
std=0.05 * item.spec.volume_fraction.nominal,
694+
NormalReal(mean=0.01 * (fuzz - 0.5) + item.spec.volume_fraction.nominal,
695+
std=0.005,
676696
units=item.spec.volume_fraction.units)
677697
if item.spec.mass_fraction is not None:
678698
item.mass_fraction = \

gemd/demo/tests/test_cake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def increment(dummy):
3939
tot_count += 1
4040

4141
recursive_foreach(cake, increment)
42-
assert tot_count == 130
42+
assert tot_count == 131
4343

4444
# And make sure nothing was lost
4545
tot_count = 0
4646
recursive_foreach(loads(dumps(complete_material_history(cake))), increment)
47-
assert tot_count == 130
47+
assert tot_count == 131
4848

4949
# Check that no UIDs collide
5050
uid_seen = dict()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636

3737

3838
setup(name='gemd',
39-
version='0.7.1',
39+
version='0.7.2',
4040
url='http://github.com/CitrineInformatics/gemd-python',
4141
description="Python binding for Citrine's GEMD data model",
4242
author='Max Hutchinson',

0 commit comments

Comments
 (0)