def build_db(session): mdf = Forge("mdf-test") mdf.match_field("projects.nanomfg.catalyst", "*") rslt = mdf.search() def safe_get_recipe_value(recipe, property): if property in recipe and recipe[property]: return recipe[property] else: return None for recipe in rslt: r = MdfForge() r.mdf_id = recipe["mdf"]["mdf_id"] r.title = recipe["dc"]["titles"][0]["title"] recipe_data = recipe["projects"]["nanomfg"] r.base_pressure = recipe_data["base_pressure"] r.carbon_source = recipe_data["carbon_source"] r.catalyst = recipe_data["catalyst"] r.grain_size = safe_get_recipe_value(recipe_data, "grain_size") r.max_temperature = recipe_data["max_temperature"] r.orientation = safe_get_recipe_value(recipe_data, "orientation") r.sample_surface_area = safe_get_recipe_value(recipe_data, "sample_surface_area") r.sample_thickness = safe_get_recipe_value(recipe_data, "sample_thickness") session.add(r) session.commit()
def __init__(self, anonymous=False, **kwargs): """ Args: anonymous (bool): whether to use anonymous login (i. e. no globus authentication) **kwargs: kwargs for Forge, including index (globus search index to search on), local_ep, anonymous """ self.forge = Forge(anonymous=anonymous, **kwargs)
# -*- coding: utf-8 -*- """ @Project : matminer @Author : Xu-Shan Zhao @Filename: mdfsearch202004252216.py @IDE : PyCharm @Time1 : 2020-04-25 22:16:41 @Time2 : 2020/4/25 10:16 下午 @Month1 : 4月 @Month2 : 四月 """ from mdf_forge.forge import Forge mdf = Forge() res = mdf.search_by_elements(elements=['Fe', 'H', 'Zr']) for i in res: print(i['material']['composition']) print(len(res)) print(res[0])
from mdf_forge.forge import Forge # You don't have to use the name "mdf" but we do for consistency. mdf = Forge("mdf-test") def catalysts(datasets): return set( map(lambda dataset: dataset["projects"]["nanomfg"]["catalyst"], datasets)) mdf.match_field("projects.nanomfg.catalyst", "*") rslt = mdf.search() print(len(rslt)) print("Unique catalysts: " + str(catalysts(rslt))) mdf.match_range("projects.nanomfg.max_temperature", 0, 1000) res = mdf.search() print(len(res))
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import time from mdf_forge.forge import Forge # You don't have to use the name "mdf" but we do for consistency. from gresq.util.mdf_adaptor import MDFAdaptor source_id = '_test_nanohub_gresq_id_19_v1.1' mdf = MDFAdaptor() active = True while active: s = mdf.get_status(source_id, raw=True) print(s) active = s['status']['active'] if active: time.sleep(10) forge = Forge("mdf-test") titles = forge.match_source_names(source_id).search() # titles = forge.match_titles(['Graphene Synthesis Raman Analysis']).search() for title in titles: print(title)