nomad-coe / electronic-parsers

Apache License 2.0
18 stars 7 forks source link

Parsing of magres files #193

Closed JosePizarro3 closed 7 months ago

JosePizarro3 commented 8 months ago

I still need to do:

Related with the magres MR in Gitlab.

JosePizarro3 commented 8 months ago

@ladinesa here you have the changes. Bear in mind I defined magres_workflow.py in the utils, so it can be used (if I define it in the metainfo folder of magres I got a circular import problem).

Let me know what you think, I need still to parse the SpinSpinCoupling section, but I wanted to show you this first.

Thanks!

ladinesa commented 8 months ago

(if I define it in the metainfo folder of magres I got a circular import problem)

can you paste the error here?

JosePizarro3 commented 8 months ago

(if I define it in the metainfo folder of magres I got a circular import problem)

can you paste the error here?

This is it (again, only when defining in /magres/metainfo/magres.py and importing them in the utils.py using ..magres.metainfo.magres import NMRMagRes, NMRMagResMethod, NMRMagResResults:

ERROR    nomad.client         2024-01-17T14:05:29 parsing was not successful
  - exception: Traceback (most recent call last):
      File "/home/josepizarro/nomad/nomad/parsing/parsers.py", line 215, in run_parser
        parser.parse(mainfile_path, entry_archive, logger=logger, **kwargs)
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 460, in parse
        self.mainfile_parser.parse(mainfile, archive, logger)
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 451, in mainfile_parser
        raise e
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 446, in mainfile_parser
        Parser = self.import_parser_class()
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 463, in import_parser_class
        return import_class(self._parser_class_name, 'parser')
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 419, in import_class
        raise e
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 412, in import_class
        module = importlib.import_module(module_path)
      File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 850, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/fhiaims/__init__.py", line 19, in <module>
        from .parser import FHIAimsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/fhiaims/parser.py", line 59, in <module>
        from ..utils import BeyondDFTWorkflowsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/__init__.py", line 19, in <module>
        from .utils import get_files, numpy_type_to_json_serializable, BeyondDFTWorkflowsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/utils.py", line 51, in <module>
        from ..magres.metainfo.magres import (
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/magres/__init__.py", line 19, in <module>
        from .parser import MagresParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/magres/parser.py", line 48, in <module>
        from ..utils import BeyondDFTWorkflowsParser
    ImportError: cannot import name 'BeyondDFTWorkflowsParser' from partially initialized module 'electronicparsers.utils' (most likely due to a circular import) (/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/__init__.py)
  - exception_hash: 1zAJbjhQvtS4kVzlN_6ggqkidb9j
  - nomad.client.parser: parsers/fhi-aims
  - nomad.commit: 
  - nomad.deployment: devel
  - nomad.service: cli
  - nomad.version: 1.2.2.dev304+g663ab7d9d.d20240117
ladinesa commented 8 months ago

NMRMagResResults

This is expected and implies that we perhaps need to put the

(if I define it in the metainfo folder of magres I got a circular import problem)

can you paste the error here?

This is it (again, only when defining in /magres/metainfo/magres.py and importing them in the utils.py using ..magres.metainfo.magres import NMRMagRes, NMRMagResMethod, NMRMagResResults:

ERROR    nomad.client         2024-01-17T14:05:29 parsing was not successful
  - exception: Traceback (most recent call last):
      File "/home/josepizarro/nomad/nomad/parsing/parsers.py", line 215, in run_parser
        parser.parse(mainfile_path, entry_archive, logger=logger, **kwargs)
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 460, in parse
        self.mainfile_parser.parse(mainfile, archive, logger)
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 451, in mainfile_parser
        raise e
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 446, in mainfile_parser
        Parser = self.import_parser_class()
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 463, in import_parser_class
        return import_class(self._parser_class_name, 'parser')
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 419, in import_class
        raise e
      File "/home/josepizarro/nomad/nomad/parsing/parser.py", line 412, in import_class
        module = importlib.import_module(module_path)
      File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 850, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/fhiaims/__init__.py", line 19, in <module>
        from .parser import FHIAimsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/fhiaims/parser.py", line 59, in <module>
        from ..utils import BeyondDFTWorkflowsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/__init__.py", line 19, in <module>
        from .utils import get_files, numpy_type_to_json_serializable, BeyondDFTWorkflowsParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/utils.py", line 51, in <module>
        from ..magres.metainfo.magres import (
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/magres/__init__.py", line 19, in <module>
        from .parser import MagresParser
      File "/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/magres/parser.py", line 48, in <module>
        from ..utils import BeyondDFTWorkflowsParser
    ImportError: cannot import name 'BeyondDFTWorkflowsParser' from partially initialized module 'electronicparsers.utils' (most likely due to a circular import) (/home/josepizarro/nomad/dependencies/parsers/electronic/electronicparsers/utils/__init__.py)
  - exception_hash: 1zAJbjhQvtS4kVzlN_6ggqkidb9j
  - nomad.client.parser: parsers/fhi-aims
  - nomad.commit: 
  - nomad.deployment: devel
  - nomad.service: cli
  - nomad.version: 1.2.2.dev304+g663ab7d9d.d20240117

can you remove all under utils/init.py and use the absolute path.

JosePizarro3 commented 8 months ago

can you remove all under utils/init.py and use the absolute path.

How do you mean? Do you mean:

  1. Add NMRMagRes workflow in magres/metainfo/magres.py.
  2. Delete ALL imports in utils/__init__.py?
  3. Import NMRMagRes in utils/utils.py with ..magres.metainfo.magres?
ladinesa commented 8 months ago

can you remove all under utils/init.py and use the absolute path.

How do you mean? Do you mean:

  1. Add NMRMagRes workflow in magres/metainfo/magres.py.
  2. Delete ALL imports in utils/__init__.py?
  3. Import NMRMagRes in utils/utils.py with ..magres.metainfo.magres?

Do number 2 and do the utils imports as from electronicparsers.utils import. Then perhaps you can have NMRMagRes in magres/metainfo

JosePizarro3 commented 8 months ago

can you remove all under utils/init.py and use the absolute path.

How do you mean? Do you mean:

  1. Add NMRMagRes workflow in magres/metainfo/magres.py.
  2. Delete ALL imports in utils/__init__.py?
  3. Import NMRMagRes in utils/utils.py with ..magres.metainfo.magres?

Do number 2 and do the utils imports as from electronicparsers.utils import. Then perhaps you can have NMRMagRes in magres/metainfo

Ok, I managed to make it work. You will see a lot of files changed so now I am using the abs path for the utils in other parsers. Let me know what you think.

If this is ready then, I will focus on finishing today / tomorrow the Gitlab side.

JosePizarro3 commented 8 months ago

Ok, it seems that, even tho the pathing is working in Github, it is completely broken from the central nomad (you can see the testing here).

I guess one has to write the whole path, but the it brokes the local github testing.

I will leave it to how it was: define utils/magres_workflow.py and import it in utils/__init__.py.