Skip to content

Running MatterSim and other Python-based Machine Learning Models

Using MatterSim bank workflow

Copy bank workflow

The easiest way to run MatterSim calculations is to use an existing bank workflow. Before we can use a workflow to create a job, we need to copy it to to our own account.

  1. Navigate to the workflows bank from the left sidebar.
  2. Search for "MatterSim" and click "Copy" in the action column on the workflow you want to use. Copy bank workflow
  3. Now the workflow will appear in your own workflows list, and will be available for selection in job creation process.
  4. We can open the workflow for inspection and further modification if needed. The workflow is consists of three units:
    • Input/Output unit: This unit is used to fetch materials data from the job context. The response is an array of materials.
    • Assignment unit: This unit is takes the first item of the above array and assigns a new variable named MATERIAL in the global scope.
    • MatterSim unit: Creates ASE material definition from MATERIAL and runs the MatterSim calculation to predict various material properties.

MatteSim workflow units

Create and submit job

  1. Navigate to the jobs designer page from the left sidebar.
  2. Click "Create New Job".
  3. Click on the "Select Job Actions" drop-down menu, and select the material and workflow you want to use.
  4. We will proceed with the default material, which is Silicon, and select "MatterSim Python Workflow" that we just imported.
  5. Save and exit the job designer. MatteSim Job creation
  6. Now the job is ready for submission. Click on the "Run" button in the "Actions" column.
  7. Once the job is completed, we can open job viewer page to see the results. We can open the MatterSim unit under workflow tab to see the standard output. All the input and outputs are available under the "Files" tab.

Creating MatterSim workflow

In this section, we will describe how to create a new workflow and use MatterSim flavor/template.

  1. Navigate to the workflows page, and click on the "Create" new workflow button.
  2. Expand the "Details" section, select "Python Script" as application.
  3. Add a "executable" unit, and click "EDIT" unit button. MatteSim add unit
  4. Expand the "Details" section, and select "mlff: mattersim" as flavor. MatteSim edit unit
  5. Scroll down and edit the Python script if necessary. In this case, we want to use ASE library to create a material definition, instead of getting material from the job context.
SCRIPT.PY
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import torch
from ase.units import GPa
from mat3ra.made.tools.convert import to_ase
from mattersim.forcefield import MatterSimCalculator

device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Running MatterSim on {device}")

from ase.build import bulk
material = bulk("Si", "diamond", a=5.43)

material.calc = MatterSimCalculator(device=device)
print(f"Energy (eV)                 = {material.get_potential_energy()}")
print(f"Energy per atom (eV/atom)   = {material.get_potential_energy()/len(material)}")
print(f"Forces of first atom (eV/A) = {material.get_forces()[0]}")
print(f"Stress[0][0] (eV/A^3)       = {material.get_stress(voigt=False)[0][0]}")
print(f"Stress[0][0] (GPa)          = {material.get_stress(voigt=False)[0][0] / GPa}")
  1. Close unit modal by clicking on the "X" button in the top right.
  2. Save and exit the workflow editor.
  3. Now we can create a new job using this workflow, as we did in the previous section.

Running other Python-based Machine Learning Models

If you want to run other Python-based Machine Learning Models, you can create a new workflow and use the same approach. In this case, select default "Python" flavor/template, add python dependencies to the "requirements.txt" tab, and write your Python script to the "script.py" tab.

General Python template

Step-by-step Video Tutorial

In the below animation, we walk you through the whole process.

References