Part 2 - Core Query Builder Functions

[1]:
from mdf_forge.forge import Forge
[2]:
mdf = Forge()

Query builders

match_field

Forge has many helper functions to make constructing queries easier. The simplest of the helpers is match_field().

To use match_field(), provide it with the field and value to match on.

[3]:
mdf.match_field("material.elements", "Al")
[3]:
<mdf_forge.forge.Forge at 0x7f26257f1630>

You can use match_field() as many times as you like to add more fields and values. (This applies to all of the query builder helpers.)

[4]:
mdf.match_field("mdf.source_name", "oqmd*")
[4]:
<mdf_forge.forge.Forge at 0x7f26257f1630>

Once you’re done adding fields, use the search() method to execute your search. You don’t need to specify the advanced argument; when using the query builder functions it is always set to True.

After you execute a search, the query is cleared from memory.

[5]:
res = mdf.search(limit=10)
res[0]
[5]:
{'crystal_structure': {'cross_reference': {'icsd': 43492},
  'number_of_atoms': 1,
  'space_group_number': 225,
  'volume': 16.4826},
 'dft': {'converged': True,
  'cutoff_energy': 520.0,
  'exchange_correlation_functional': 'PBE'},
 'files': [{'data_type': 'ASCII text, with very long lines, with no line terminators',
   'filename': '17.json',
   'globus': 'globus://e38ee745-6d04-11e5-ba46-22000b92c6ec/MDF/mdf_connect/prod/data/oqmd_v13/17.json',
   'length': 11769,
   'mime_type': 'text/plain',
   'sha512': '153783912c0dacf4d21f5d452a0568c39e4d175ca701d7fe49fd7a6fb8208dd986f167ee4b88534fb475c6cd30842c71cf4f00b9594ef94e888f7c79a182dbb7',
   'url': 'https://e38ee745-6d04-11e5-ba46-22000b92c6ec.e.globus.org/MDF/mdf_connect/prod/data/oqmd_v13/17.json'}],
 'material': {'composition': 'Al1', 'elements': ['Al']},
 'mdf': {'ingest_date': '2018-11-09T19:44:43.687681Z',
  'mdf_id': '5be5e6632ef388650e01442b',
  'parent_id': '5be5e3ab2ef388650efd6704',
  'resource_type': 'record',
  'scroll_id': 253222,
  'source_id': 'oqmd_v13',
  'source_name': 'oqmd',
  'version': 13},
 'oqmd': {'band_gap': {'units': 'eV', 'value': 0.0},
  'configuration': 'static',
  'delta_e': {'units': 'eV/atom', 'value': 0.000788779999999711},
  'magnetic_moment': {'units': 'bohr/atom'},
  'stability': {'units': 'eV/atom', 'value': 0.00157755999999942},
  'total_energy': {'units': 'eV/atom', 'value': -3.74495068},
  'volume_pa': {'units': 'angstrom^3/atom', 'value': 16.4826}}}

exclude_field

exclude_field() is the opposite of match_field(); it excludes results with the specified value.

[6]:
mdf.exclude_field("material.elements", "Cu")
[6]:
<mdf_forge.forge.Forge at 0x7f26257f1630>

You can chain calls together if you want.

[7]:
mdf.exclude_field("mdf.source_name", "sluschi").match_field("material.elements", "Al").exclude_field("mdf.source_name", "oqmd")
[7]:
<mdf_forge.forge.Forge at 0x7f26257f1630>
[8]:
res = mdf.search(limit=10)
res[0]
[8]:
{'cip': {'bv': '79.0',
  'energy': '-3.36',
  'forcefield': 'Al99.eam.alloy',
  'gv': '29.4',
  'mpid': 'mp-134',
  'totenergy': '-107.52'},
 'files': [{'data_type': 'ASCII text, with very long lines, with no line terminators',
   'filename': 'classical_interatomic_potentials.json',
   'globus': 'globus://e38ee745-6d04-11e5-ba46-22000b92c6ec/MDF/mdf_connect/prod/data/cip_v1/classical_interatomic_potentials.json',
   'length': 1841203,
   'mime_type': 'text/plain',
   'sha512': '96635ee0c15d1d0187b18805653a02b1a6dfa5648db82153467045de18adcc08c753e2897d2b48a78a2167a442219e9aeff6b1103732c2158facac8fa4911b33',
   'url': 'https://e38ee745-6d04-11e5-ba46-22000b92c6ec.e.globus.org/MDF/mdf_connect/prod/data/cip_v1/classical_interatomic_potentials.json'}],
 'material': {'composition': 'Al32', 'elements': ['Al']},
 'mdf': {'ingest_date': '2018-10-29T17:47:57.468388Z',
  'mdf_id': '5bd747cf2ef3880b0f213904',
  'parent_id': '5bd747cd2ef3880b0f2135d1',
  'resource_type': 'record',
  'scroll_id': 819,
  'source_id': 'cip_v1',
  'source_name': 'cip',
  'version': 1}}
[ ]: