Skip to content

Example workflow for a synthesis project

Refer to Quickstart for installation instructions.

Connect to the public API

import cript

host = "criptapp.org"
token = "<your_api_token>"
cript.API(host, token)

Note

Your API token can be found in the UI under Account Settings.

Create a Project node

proj = cript.Project(name="<your_project_name>")
proj.save()

Note

Project names are globally unique.

Create a Collection node

coll = cript.Collection.create(project=proj, name="Synthesis Tutorial")

Note

Notice the use of create() here, which instantiates and saves the object in one go.

Create an Experiment node

expt = cript.Experiment(
    collection=coll,
    name="Anionic Polymerization of Styrene with SecBuLi"
)
expt.save()

Get Material nodes

For this tutorial, we will get an existing Inventory node from the database.
This contains all of the Material nodes we will be using.

uid = "134f2658-6245-42d8-a47e-6424aa3472b4"
inv = cript.Inventory.get(uid=uid)

Notice that the Material node objects have been auto-generated.

type(inv.materials[0])
# <class 'cript.data_model.nodes.material.Material'>

Create a Process node

prcs = cript.Process(
    experiment=expt,
    name="Anionic of Styrene",
    type = "multistep",
    description = "In an argon filled glovebox, a round bottom flask was filled with 216 ml of dried toluene. The "
                  "solution of secBuLi (3 ml, 3.9 mmol) was added next, followed by styrene (22.3 g, 176 mmol) to "
                  "initiate the polymerization. The reaction mixture immediately turned orange. After 30 min, "
                  "the reaction was quenched with the addition of 3 ml of methanol. The polymer was isolated by "
                  "precipitation in methanol 3 times and dried under vacuum."
)
prcs.save()

Add Ingredient nodes to the Process node

First, let's grab the Material nodes we need from the Inventory node.

solution = inv['SecBuLi solution 1.4M cHex']
toluene = inv['toluene']
styrene = inv['styrene']
butanol = inv['1-butanol']
methanol = inv['methanol']

Next, we'll define Quantity nodes indicating the amount of each Ingredient.

initiator_qty = cript.Quantity(key="volume", value=0.017, unit="ml")
solvent_qty = cript.Quantity(key="volume", value=10, unit="ml")
monomer_qty = cript.Quantity(key="mass", value=0.455, unit="g")
quench_qty = cript.Quantity(key="volume", value=5, unit="ml")
workup_qty = cript.Quantity(key="volume", value=100, unit="ml")

Next, we'll create Ingredient nodes for each.

initiator = cript.Ingredient(
    keyword="initiator",
    material=solution,
    quantities=[initiator_qty]
)
solvent = cript.Ingredient(
    keyword="solvent",
    material=toluene,
    quantities=[solvent_qty]
)
monomer = cript.Ingredient(
    keyword="monomer",
    material=styrene,
    quantities=[monomer_qty]
)
quench = cript.Ingredient(
    keyword="quench",
    material=butanol,
    quantities=[quench_qty]
)
workup = cript.Ingredient(
    keyword="workup",
    material=methanol,
    quantities=[workup_qty]
)

Last, we'll add the Ingredient nodes to the Process node.

prcs.add_ingredient(initiator)
prcs.add_ingredient(solvent)
prcs.add_ingredient(monomer)
prcs.add_ingredient(quench)
prcs.add_ingredient(workup)

Add Condition nodes to the Process node

temp = cript.Condition(key="temperature", value=25, unit="celsius")
time = cript.Condition(key="time_duration", value=60, unit="min")
prcs.add_condition(temp)
prcs.add_condition(time)

Add a Property node to the Process node

yield_mass = cript.Property(
    key="yield_mass",
    value=0.47,
    unit="g",
    method="scale"
)
prcs.add_property(yield_mass)

Create a Material node (process product)

First, we'll instantiate the node.

polystyrene = cript.Material(project=proj, name="polystyrene")

Next, we'll add some Identifier nodes.

names = cript.Identifier(
    key="names",
    value=["poly(styrene)", "poly(vinylbenzene)"]
)
bigsmiles = cript.Identifier(
    key="bigsmiles",
    value="[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC"
)
chem_repeat = cript.Identifier(key="chem_repeat", value="C8H8")

polystyrene.add_identifier(names)
polystyrene.add_identifier(chem_repeat)
polystyrene.add_identifier(bigsmiles)

Next, we'll add some Property nodes.

phase = cript.Property(key="phase", value="solid")
color = cript.Property(key="color", value="white")

polystyrene.add_property(phase)
polystyrene.add_property(color)

Now we can save the Material and add it to the Process node as a product.

polystyrene.save()
prcs.add_product(polystyrene)

Last, we can save the Process node.

prcs.save()

Create a File node and upload a file

First, we'll instantiate a File node and associate it with the Data node created above.

path = "path/to/local/file"
f = cript.File(project=proj, source=path)

Note

The source field should point to a file on your local filesystem.

Info

Depending on the file size, there could be a delay while the checksum is generated.

Next, we'll upload the local file by saving the File node. Follow all prompts that appear.

api.save(f)

Create a Data node

sec = cript.Data(
    experiment=expt,
    name="Crude SEC of polystyrene",
    type="sec_trace",
)

.. then add the uploaded File to it:

sec.add_file(f)
sec.save()

Associate a Data node with a Property node

First, we'll create one more Property node for polystyrene.

mw_n = cript.Property(key="mw_n", value=5200, unit="g/mol")

Next, we'll add the Data node to the new Property node.

mw_n.data = sec

Last, we'll add the new Property node to polystyrene and then save it.

polystyrene.add_property(mw_n)
polystyrene.save()

Conclusion

You made it! We hope this tutorial has been helpful.

Please let us know how you think it could be improved.