Skip to content

Commit

Permalink
Refactor Reference schema to be based on a basesection
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianschoeppach committed Oct 17, 2024
1 parent ffffd24 commit 915f53d
Showing 1 changed file with 6 additions and 75 deletions.
81 changes: 6 additions & 75 deletions src/perovskite_tandem_database/schema_sections/ref.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import numpy as np
from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.basesections import PublicationReference
from nomad.metainfo import Datetime, Quantity, Section


class Reference(ArchiveSection):
class Reference(PublicationReference):
"""Information about the source of the data. It describes who curated the data,
the journal in which the data was published,
the DOI number of the publication, the lead author and the publication date."""

m_def = Section(a_eln=dict(lane_width='800px'))

# custom fields for the tandem database

ID_temp = Quantity(
type=np.dtype(np.int64),
shape=[],
Expand All @@ -35,7 +38,6 @@ class Reference(ArchiveSection):
a_eln=dict(component='RichTextEditQuantity'),
)

# Add in the future auto filling from metadata.author
name_of_person_entering_the_data = Quantity(
type=str,
shape=[],
Expand All @@ -53,77 +55,6 @@ class Reference(ArchiveSection):
a_eln=dict(component='BoolEditQuantity'),
)

DOI_number = Quantity(
type=str,
shape=[],
description="""
The DOI number referring to the published paper or dataset where the data can be found. If the data is unpublished, enter “Unpublished”
Examples:
10.1021/jp5126624
10.1016/j.electacta.2017.06.032
Unpublished
""",
a_eln=dict(component='EnumEditQuantity', props=dict(suggestions=[])),
)

lead_author = Quantity(
type=str,
shape=[],
description="""
The surname of the first author. If several authors, end with et al. If the DOI number is given correctly, this will be extracted automatically from www.crossref.org
""",
a_eln=dict(component='EnumEditQuantity', props=dict(suggestions=[])),
)

publication_date = Quantity(
type=Datetime,
shape=[],
description="""
Publication date. If the DOI number is given correctly, this will be extracted automatically from www.crossref.org
""",
)

# journal = Quantity(
# type=str,
# shape=[],
# description="""
# nan
# """,
# )

def normalize(self, archive, logger):
import dateutil.parser
import requests
from nomad.datamodel.datamodel import EntryMetadata

# Parse journal name, lead author and publication date from crossref
if self.DOI_number:
if not self.ID_temp:
r = requests.get(f'https://api.crossref.org/works/{self.DOI_number}')
temp_dict = r.json()
# make sure the doi has the prefix https://doi.org/
if self.DOI_number.startswith('10.'):
self.DOI_number = 'https://doi.org/' + self.DOI_number
given_name = temp_dict['message']['author'][0]['given']
familiy_name = temp_dict['message']['author'][0]['family']
self.journal = temp_dict['message']['container-title'][0]
self.publication_date = dateutil.parser.parse(
temp_dict['message']['created']['date-time']
)
self.lead_author = given_name + ' ' + familiy_name
if not archive.metadata:
archive.metadata = EntryMetadata()
if not archive.metadata.references:
archive.metadata.references = []
archive.metadata.references.append(self.DOI_number)
if self.ID_temp is not None:
archive.metadata.references.append(
'https://doi.org/10.1038/s41560-021-00941-3'
)
archive.metadata.references.append(
'https://www.perovskitedatabase.com/'
)
archive.metadata.external_db = 'The Perovskite Database Project'
for i, ref in enumerate(archive.metadata.references):
if ref.startswith('10.'):
archive.metadata.references[i] = 'https://doi.org/' + ref
"""Normalize the reference section."""
super(PublicationReference, self).normalize(archive, logger)

0 comments on commit 915f53d

Please sign in to comment.