# Path: server/materialsdatabank/server/constants.py
# ELEMENT_SYMBOLS_LOWER = [x.lower() for x in ELEMENT_SYMBOLS]
# 
# ELEMENT_SYMBOLS = [
#   'Xx', 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F',
#   'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K',
#   'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu',
#   'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y',
#   'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In',
#   'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr',
#   'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm',
#   'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au',
#   'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac',
#   'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es',
#   'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt',
#   'Ds', 'Rg', 'Cn', 'Uut', 'Uuq', 'Uup', 'Uuh', 'Uus', 'Uuo'
# ]


import re
import datetime
from bson.objectid import ObjectId, InvalidId
from girder.models.model_base import AccessControlledModel
from girder.constants import AccessType
from girder.models.model_base import ValidationException
from girder.models.group import Group
from girder.models.item import Item
from girder.models.file import File
from girder import events
from girder.plugins.materialsdatabank.models.slug import Slug, SlugUpdateException
from girder.plugins.materialsdatabank.models.reconstruction import Reconstruction as ReconstructionModel
from girder.plugins.materialsdatabank.models.structure import Structure as StructureModel
from girder.plugins.materialsdatabank.models.projection import Projection as ProjectionModel
from ..constants import ELEMENT_SYMBOLS_LOWER, ELEMENT_SYMBOLS
        if atomic_species is not None:
            new_atomic_species = set(dataset.get('atomicSpecies', {}))
            new_atomic_species.update(atomic_species)
            if atomic_species is not None:
                updates.setdefault('$set', {})['atomicSpecies'] = list(new_atomic_species)
            self.ensure_mdb_id(dataset, new_atomic_species, updates)

        if public is not None:
            updates.setdefault('$set', {})['public'] = public
            # Trigger event if this dataset is being approved ( being made public )
            if public and not dataset.get('public', False):
                events.trigger('mdb.dataset.approved', {
                    'dataset': dataset,
                    'approver': user
                })
                updates.setdefault('$set', {})['released'] = datetime.datetime.utcnow()

        if validation is not None:
            updates.setdefault('$set', {})['validation'] = validation

        if updates:
            updates.setdefault('$set', {})['updated'] = datetime.datetime.utcnow()
            super(Dataset, self).update(query, update=updates, multi=False)
            return self.load(dataset['_id'], user=user, level=AccessType.READ)

        return dataset

    def _normalize_element(self, element):
        # Try looking up element
        try:

# Path: server/materialsdatabank/server/constants.py
# ELEMENT_SYMBOLS_LOWER = [x.lower() for x in ELEMENT_SYMBOLS]
# 
# ELEMENT_SYMBOLS = [
#   'Xx', 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F',
#   'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K',
#   'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu',
#   'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y',
#   'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In',
#   'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr',
#   'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm',
#   'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au',
#   'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac',
#   'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es',
#   'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt',
#   'Ds', 'Rg', 'Cn', 'Uut', 'Uuq', 'Uup', 'Uuh', 'Uus', 'Uuo'
# ]


# Path: server/materialsdatabank/server/models/dataset.py
import re
import datetime
from bson.objectid import ObjectId, InvalidId
from girder.models.model_base import AccessControlledModel
from girder.constants import AccessType
from girder.models.model_base import ValidationException
from girder.models.group import Group
from girder.models.item import Item
from girder.models.file import File
from girder import events
from girder.plugins.materialsdatabank.models.slug import Slug, SlugUpdateException
from girder.plugins.materialsdatabank.models.reconstruction import Reconstruction as ReconstructionModel
from girder.plugins.materialsdatabank.models.structure import Structure as StructureModel
from girder.plugins.materialsdatabank.models.projection import Projection as ProjectionModel
from ..constants import ELEMENT_SYMBOLS_LOWER, ELEMENT_SYMBOLS

        if atomic_species is not None:
            new_atomic_species = set(dataset.get('atomicSpecies', {}))
            new_atomic_species.update(atomic_species)
            if atomic_species is not None:
                updates.setdefault('$set', {})['atomicSpecies'] = list(new_atomic_species)
            self.ensure_mdb_id(dataset, new_atomic_species, updates)

        if public is not None:
            updates.setdefault('$set', {})['public'] = public
            # Trigger event if this dataset is being approved ( being made public )
            if public and not dataset.get('public', False):
                events.trigger('mdb.dataset.approved', {
                    'dataset': dataset,
                    'approver': user
                })
                updates.setdefault('$set', {})['released'] = datetime.datetime.utcnow()

        if validation is not None:
            updates.setdefault('$set', {})['validation'] = validation

        if updates:
            updates.setdefault('$set', {})['updated'] = datetime.datetime.utcnow()
            super(Dataset, self).update(query, update=updates, multi=False)
            return self.load(dataset['_id'], user=user, level=AccessType.READ)

        return dataset

    def _normalize_element(self, element):
        # Try looking up element
        try:

            atomic_number = ELEMENT_SYMBOLS_LOWER.index(element.lower())