Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Elastic Tensors

Let’s do something more interesting that normally takes quite a bit of work in DFT: calculating an elastic constant! Elastic properties are important to understand how strong or easy to deform a material is, or how a material might change if compressed or expanded in specific directions (i.e. the Poisson ratio!).

We don’t have to change much code from above, we just use a built-in recipe to calculate the elastic tensor from quacc. This recipe

  1. (optionally) Relaxes the unit cell using the MLIP

  2. Generates a number of deformed unit cells by applying strains

  3. For each deformation, a relaxation using the MLIP and (optionally) a single point calculation is run

  4. Finally, all of the above calculations are used to calculate the elastic properties of the material

For more documentation, see the quacc docs for quacc.recipes.mlp.elastic_tensor_flow

from __future__ import annotations

from ase.build import bulk
from quacc.recipes.mlp.elastic import elastic_tensor_flow

# Make an Atoms object of a bulk Cu structure
atoms = bulk("Cu")

# Run an elastic property calculation with our favorite MLP potential
result = elastic_tensor_flow(
    atoms,
    job_params={
        "all": dict(
            method="fairchem",
            name_or_path="uma-s-1p2",
            task_name="omat",
        ),
    },
)
/tmp/ipykernel_9717/2729024292.py:4: DeprecationWarning: quacc.recipes.mlp is deprecated. Use quacc.recipes.mlip instead.
  from quacc.recipes.mlp.elastic import elastic_tensor_flow
/tmp/ipykernel_9717/2729024292.py:4: DeprecationWarning: quacc.recipes.mlp.elastic is deprecated. Use quacc.recipes.mlip.elastic instead.
  from quacc.recipes.mlp.elastic import elastic_tensor_flow
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 10
      6 # Make an Atoms object of a bulk Cu structure
      7 atoms = bulk("Cu")
      8 
      9 # Run an elastic property calculation with our favorite MLP potential
---> 10 result = elastic_tensor_flow(
     11     atoms,
     12     job_params={
     13         "all": dict(

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:148, in tracked.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    146 @wraps(func)
    147 def wrapper(*args, **kwargs):
--> 148     return _tracked_call(func, node_type, args, kwargs)

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:169, in _tracked_call(func, node_type, args, kwargs)
    166 # When NESTED_RESULTS is off, skip all context tracking and just
    167 # delegate to the original function directly.
    168 if not settings.NESTED_RESULTS:
--> 169     return func(*args, **kwargs)
    171 # Create a unique name we can use at this level.
    172 name = make_unique_name(prefix=f"{func.__name__}-")

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/recipes/mlip/elastic.py:82, in elastic_tensor_flow(atoms, pre_relax, run_static, deform_kwargs, job_params, job_decorators)
     30 """
     31 Workflow consisting of:
     32 
   (...)     73     See the return type-hint for the data structure.
     74 """
     75 relax_job_, static_job_ = customize_funcs(
     76     ["relax_job", "static_job"],
     77     [relax_job, static_job],
     78     param_swaps=job_params,
     79     decorators=job_decorators,
     80 )  # type: ignore
---> 82 return elastic_tensor_flow_(
     83     atoms=atoms,
     84     relax_job=relax_job_,
     85     static_job=static_job_,
     86     pre_relax=pre_relax,
     87     run_static=run_static,
     88     deform_kwargs=deform_kwargs,
     89 )

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:148, in tracked.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    146 @wraps(func)
    147 def wrapper(*args, **kwargs):
--> 148     return _tracked_call(func, node_type, args, kwargs)

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:169, in _tracked_call(func, node_type, args, kwargs)
    166 # When NESTED_RESULTS is off, skip all context tracking and just
    167 # delegate to the original function directly.
    168 if not settings.NESTED_RESULTS:
--> 169     return func(*args, **kwargs)
    171 # Create a unique name we can use at this level.
    172 name = make_unique_name(prefix=f"{func.__name__}-")

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/recipes/common/elastic.py:60, in elastic_tensor_flow(atoms, relax_job, static_job, pre_relax, run_static, deform_kwargs)
     35 """
     36 Common workflow for calculating elastic tensors.
     37 
   (...)     57     See the return type-hint for the data structure.
     58 """
     59 if pre_relax:
---> 60     undeformed_result = relax_job(atoms, relax_cell=True)
     61     if run_static:
     62         undeformed_result = static_job(undeformed_result["atoms"])

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:148, in tracked.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    146 @wraps(func)
    147 def wrapper(*args, **kwargs):
--> 148     return _tracked_call(func, node_type, args, kwargs)

File ~/work/_tool/Python/3.12.13/x64/lib/python3.12/site-packages/quacc/wflow_tools/context.py:169, in _tracked_call(func, node_type, args, kwargs)
    166 # When NESTED_RESULTS is off, skip all context tracking and just
    167 # delegate to the original function directly.
    168 if not settings.NESTED_RESULTS:
--> 169     return func(*args, **kwargs)
    171 # Create a unique name we can use at this level.
    172 name = make_unique_name(prefix=f"{func.__name__}-")

TypeError: relax_job() missing 1 required positional argument: 'library'
result["elasticity_doc"].bulk_modulus

Congratulations, you ran your first elastic tensor calculation!