Skip to content
Snippets Groups Projects

Resolve "Adding reduce and descriptive formula to the GUI search"

2 unresolved threads
@@ -1560,7 +1560,7 @@ Ozone
def normalize(self, archive, logger):
from .formula_normalizer import PerovskiteFormulaNormalizer
from ase.formula import Formula
from ase import Atoms
addSolarCell(archive)
@@ -1603,14 +1603,15 @@ Ozone
if archive.results.material.functional_type is None:
archive.results.material.functional_type = ['semiconductor', 'solar cell']
if archive.results.material.chemical_formula_reduced is None:
if self.composition_long_form:
formula_cleaner = PerovskiteFormulaNormalizer(self.composition_long_form)
final_formula = formula_cleaner.clean_formula()
archive.results.material.chemical_formula_reduced = final_formula[0]
chemical_formula_reduced = archive.results.material.chemical_formula_reduced
chemical_formula_reduced = final_formula[0]
archive.results.material.elements = final_formula[1]
try:
archive.results.material.chemical_formula_hill = Formula(chemical_formula_reduced).format('hill')
atoms = Atoms(chemical_formula_reduced)
archive.results.material.chemical_formula_hill = atoms.get_chemical_formula(mode='hill')
archive.results.material.chemical_formula_reduced = atoms.get_chemical_formula(mode='reduce')
    • Comment on lines +1612 to +1614

      Could you try here if our custom formula class (atomutils.Formula) does the job correctly? It is designed to write the formulas in a way where they are compatible with our metainfo definitions. I think it would be good if we used the same implementation everywhere where we need these formulas. So simply try:

      try:
          formula = atomutils.Formula(chemical_formula_reduced)
          archive.results.material.chemical_formula_hill = formula.format('hill')
          archive.results.material.chemical_formula_reduced = formula.format('reduce')
          ...
      • I would say we do this merge as it is. Then, when we correct the Formula class from atomutils we also correct all the normalizers with formulas. Maybe we even need a Formula normalizer inside all the normalizers getting formulas in the system?

        To document the current problem, three different ways to get the formulas in the "correct" formats:

        from nomad.atomutils import Formula
        from pymatgen.core import Composition
        from ase import Atoms
        
        formula = 'H12C2I6N2Pb2'
        
        print('nomad atomutils')
        print('Hill: ' + Formula(formula).format('hill'))
        print('reduced: ' + Formula(formula).format('reduce'))
        
        print('pymatgen')
        composition = Composition(formula)
        print('Hill: ' + composition.hill_formula)
        print('reduced: ' + composition.reduced_formula)
        
        print('ASE')
        atoms = Atoms(formula)
        print('Hill: ' + atoms.get_chemical_formula(mode='hill'))
        print('reduced: ' + atoms.get_chemical_formula(mode='reduce'))

        Returns

        nomad atomutils
        Hill: C2H12I6N2Pb2
        reduced: C2H12I6N2Pb2
        pymatgen
        Hill: C2 H12 I6 N2 Pb2
        reduced: H6PbCI3N
        ASE
        Hill: C2H12I6N2Pb2
        reduced: H12C2I6N2Pb2
        Edited by Jose Marquez Prieto
      • Please register or sign in to reply
Please register or sign in to reply
archive.results.material.chemical_formula_descriptive = self.composition_long_form
except Exception as e:
logger.warn('could not analyse chemical formula', exc_info=e)
Loading