Chemistry Workflows¶
A chemistry workflow¶
The add
workflow was super basic, so now let's try a more advanced workflow involving a crystal structure.
Here, we will make a workflow that (i) converts a structure to a primitive unitcell and (ii) writes it to a CIF file:
from simmate.engine import workflow
@workflow
def write_primitive(structure, directory, **kwargs):
new_structure = structure.get_primitive_structure()
new_structure.to(directory / "primitive.cif", fmt="cif")
status = write_primitive.run(structure="POSCAR")
result = status.result()
Note
Make sure you run this in the same folder that contains the POSCAR
file from earlier tutorials.
There are several advanced things going in this workflow.
- We provided
POSCAR
filename (as a python string) -- However, our function is usingstructure
as if it was atoolkit
object (because it callsget_primitive_structure
). Behind the scenes, Simmate took ourPOSCAR
input, decided it was a structure file, and converted it to atoolkit.Structure
object for us! - We didn't provide a
directory
but Simmate built one for us. This is why we can have the codedirectory / "primitive.cif"
actually write the file to our new folder.
These advanced feature work let's us run our workflow in new ways. For example, we could run the workflow like so:
status = write_primitive.run(
structure={
"database_table": "MatprojStructure",
"database_id": "mp-123",
},
directory="MyNewFolder",
compress_output=True,
)
result = status.result()
This time, we pulled our structure from the database, specified the name of the folder we wanted to make, and that we wanted the final folder converted to a zip
file once it's done.
So we have lots of new functionality, and all we had to do was add @workflow
Tip
There are plenty of trick that empower how you run workflows, so be sure to read through our Parameters
and Full Guides
section.