Commits (1)
# Copyright 2016-2018 Markus Scheidgen
# Copyright 2016-2020 Florian , Markus Scheidgen
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
......@@ -22,12 +22,10 @@ import ast
import logging
import re
from .metainfo import eels as meels
from nomad.datamodel.metainfo.general_experimental import (
section_experiment as Experiment,
section_sample as Sample,
section_method as Method,
section_data as Data)
from nomad.datamodel import Author
from nomad.datamodel.metainfo.common_experimental import (
Experiment, Sample, Method, Data, Material)
from nomad.parsing.parser import FairdiParser
......@@ -37,7 +35,7 @@ logger = logging.getLogger(__name__)
class EELSApiJsonConverter(FairdiParser):
def __init__(self):
super().__init__(
name='parsers/eelsdb', code_name='eels', code_homepage='https://eelsdb.eu/',
name='parsers/eels', code_name='eels', code_homepage='https://eelsdb.eu/',
domain='ems',
mainfile_mime_re=r'application/json',
mainfile_contents_re=(r'https://eelsdb.eu/spectra')
......@@ -54,14 +52,20 @@ class EELSApiJsonConverter(FairdiParser):
data.get('published'), '%Y-%m-%d %H:%M:%S')
sample = experiment.m_create(Sample)
sample.sample_chemical_formula = data.get('formula')
sample.sample_atom_labels = data.get('elements')
sample.sample_chemical_name = data.get('title')
material = sample.m_create(Material)
material.chemical_formula = data.get('formula')
elements = data.get('elements')
if elements is not None:
if isinstance(elements, str):
elements = json.loads(elements)
material.atom_labels = elements
material.chemical_name = data.get('title')
experiment.m_create(
Method,
experiment_method_name='electron energy loss spectroscopy',
experiment_method_abbreviation='EELS')
data_type='spectrum',
method_name='electron energy loss spectroscopy',
method_abbreviation='EELS')
section_data = experiment.m_create(Data)
......@@ -70,7 +74,7 @@ class EELSApiJsonConverter(FairdiParser):
author = data.get('author')['name']
author = re.sub(r'\(.*\)', '', author).strip()
archive.section_metadata.coauthors = [dict(
archive.section_metadata.coauthors = [Author(
first_name=' '.join(author.split(' ')[0:-1]),
last_name=author.split(' ')[-1])]
archive.section_metadata.comment = data.get('description')
......@@ -93,6 +97,6 @@ class EELSApiJsonConverter(FairdiParser):
str(value).strip() for value in reference.values()
]))
section_data.data_repository_name = 'Electron Energy Loss Spectroscopy (EELS) database'
section_data.data_repository_url = 'https://eelsdb.eu'
section_data.repository_name = 'Electron Energy Loss Spectroscopy (EELS) database'
section_data.repository_url = 'https://eelsdb.eu'
section_data.entry_repository_url = data.get('permalink')
......@@ -14,8 +14,9 @@
import sys
import json
from eelsdbconverter import EELSApiJsonParser
from eelsdbconverter import EELSApiJsonConverter
if __name__ == "__main__":
archive = EELSApiJsonParser.main(sys.argv[1])
archive = EELSApiJsonConverter.main(sys.argv[1])
print(json.dumps(archive.m_to_dict(), indent=2))
......@@ -23,6 +23,7 @@ def download_eels(max: int = 1000):
eelsdb = requests.get('https://api.eelsdb.eu/spectra?per_page=%d' % max).json()
for entry in eelsdb:
print('add %s' % entry['permalink'])
path = entry['permalink'].strip('https://').strip('/')
with zf.open(os.path.join(path, 'metadata.json'), mode='w') as f:
f.write(json.dumps(entry, indent=2).encode('utf-8'))
......@@ -39,4 +40,4 @@ def download_eels(max: int = 1000):
if __name__ == '__main__':
download_eels(max=10)
download_eels()
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import eelsparser.metainfo.eels
import nomad.datamodel.metainfo.general
import nomad.datamodel.metainfo.general_experimental
m_env = LegacyMetainfoEnvironment()
m_env.m_add_sub_section(Environment.packages, sys.modules['eelsparser.metainfo.eels'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.general'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.general_experimental'].m_package) # type: ignore
import numpy as np # pylint: disable=unused-import
import typing # pylint: disable=unused-import
from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference
)
m_package = Package(
name='eelsdb',
description='Metadata for the EELS database (https://eelsdb.eu)')
m_package.__init_metainfo__()