import numpy as np
import escape as esc
esc.require("0.9.8")
Loading material database from C:\dev\escape-core\notebooks\repository\scattering\materials.db
Overview of the Material Database Module¶
The material database in ESCAPE stores reusable information about common materials: their names, chemical composition, density, and scattering-related constants. Instead of redefining that information in every notebook, you can load it from the database and focus on the actual model you want to build.
This notebook explains how the database is organized, how to inspect records, and how to add your own entries when needed.
esc.copy_db(overwrite=True)
Material database file materials.yaml has been successfully copied to C:\dev\escape-core\notebooks\repository\scattering
The copy of the material database file is stored in the current working directory.
In order to compile the new material database, the user should create an instance of the new material database using
mdb method. This method will look for the YAML material database file in the current working directory and will
compile the material database from the YAML file. The compiled material database is stored in the current working
directory and is used by default. If the local MDB file is not found, the method will look for the MDB file in the
specific folder of the package.
In the newly created materials.yaml file, the user can add new material records or edit existing ones.
As an example we add a new record:
---
name: Polybutadiene_custom
type: amorphous
density: 0.436
atoms:
- C:
repeat: 4
- H:
repeat: 6
In order to use it, we need to create a new instance of the material database:
custom_mdb = esc.mdb()
mat = esc.amorphous("Polybutadiene_custom", density="mdb", mdb=custom_mdb)
print(mat)
Loading material database from C:\dev\escape-core\notebooks\repository\scattering\materials.db
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[3], line 2 1 custom_mdb = esc.mdb() ----> 2 mat = esc.amorphous("Polybutadiene_custom", density="mdb", mdb=custom_mdb) 3 print(mat) File src/escape/scattering/material.pyx:971, in escape.scattering.material.amorphous() File src/escape/scattering/material.pyx:640, in escape.scattering.material.__amorphous_by_density() File src/escape/scattering/mdb.pyx:771, in escape.scattering.mdb.mdb_obj.amorph_density() RuntimeError: Material record not found: Polybutadiene_custom
The new material records can be added inline to the default or custom material database using the :meth:add_material method.
In this case the new material record is not stored in the YAML file, but is added to the material database instance.
It is useful for testing purposes or if the user prefers to work with temporary material records only.
The information about new material records is lost when the material database instance is deleted.
from escape.scattering.mdb import default_mdb
rec = {
"name": "Polybutadiene_custom",
"type": "amorphous",
"density": 0.436,
"atoms": [
{"C": {"repeat": 4}},
{"H": {"repeat": 6}},
],
}
default_mdb.add(rec)
# mdb=default_mdb by default
mat = esc.amorphous("Polybutadiene_custom", density="mdb")
print(mat)