Skip to content

Commit

Permalink
Added new workflow from nomad_simulations and changed pyproject toml
Browse files Browse the repository at this point in the history
Deleted copyright comment at the beginning of the files

Defined workflow_dft_files in Wannier90Parser
  • Loading branch information
JosePizarro3 committed Sep 23, 2024
1 parent 96beebe commit 35a7957
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 488 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maintainers = [
license = { file = "LICENSE" }
dependencies = [
"nomad-lab>=1.3.0",
"nomad-simulations>=0.0.3",
"nomad-simulations@git+https://github.com/nomad-coe/nomad-simulations.git@64ae0efb323cf17b20651f9a9a50864832db9a71",
]

[project.urls]
Expand All @@ -40,7 +40,6 @@ dev = [
"pytest-timeout",
"pytest-cov",
"structlog",
"nomad-lab[infrastructure]", # for search and MetadataRequired to work
]

[tool.ruff]
Expand Down
19 changes: 0 additions & 19 deletions src/nomad_parser_wannier90/parsers/band_parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
Expand Down
19 changes: 0 additions & 19 deletions src/nomad_parser_wannier90/parsers/dos_parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import Optional

import numpy as np
Expand Down
19 changes: 0 additions & 19 deletions src/nomad_parser_wannier90/parsers/hr_parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
Expand Down
110 changes: 65 additions & 45 deletions src/nomad_parser_wannier90/parsers/parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -49,14 +30,14 @@
KMesh as ModelKMesh,
)
from nomad_simulations.schema_packages.outputs import Outputs
from nomad_simulations.schema_packages.workflow import SinglePoint

# from nomad_simulations.schema_packages.utils import check_simulation_cell
from nomad_parser_wannier90.parsers.band_parser import Wannier90BandParser
from nomad_parser_wannier90.parsers.dos_parser import Wannier90DosParser
from nomad_parser_wannier90.parsers.hr_parser import Wannier90HrParser
from nomad_parser_wannier90.parsers.utils import get_files, parse_dft_plus_tb_workflow
from nomad_parser_wannier90.parsers.win_parser import Wannier90WInParser
from nomad_parser_wannier90.schema_packages.package import SinglePoint

re_n = r'[\n\r]'

Expand Down Expand Up @@ -449,16 +430,51 @@ def parse_outputs(self, simulation: Simulation, logger: 'BoundLogger') -> Output

return outputs

def workflow_dft_files(self, **kwargs) -> list[str]:
"""
Check if in the upload of the Wannier90 mainfile, there are the corresponding DFT files to create the
DFT+TB workflow, and returns them if so. Implemented only for VASP DFT files.
Returns:
list[str]: Returns a list containing the DFT files if they are present, otherwise an empty list.
"""
# Wannier90 file
wannier90_mainfile = kwargs.get('filename')
wannier90_basename = os.path.basename(wannier90_mainfile)

# DFT files
dft_files = []

# VASP DFT files
vasprun_files = get_files(
pattern='*vasprun.xml',
filepath=wannier90_mainfile,
stripname=wannier90_basename,
deep=False,
)
outcar_files = get_files(
pattern='*OUTCAR',
filepath=wannier90_mainfile,
stripname=wannier90_basename,
deep=False,
)
if not vasprun_files:
dft_files = outcar_files
else:
dft_files = vasprun_files

# TODO extend to other DFT codes

return dft_files

def get_mainfile_keys(self, **kwargs):
"""
Generates extra `child_archives` to create the DFT+TB workflow if some conditions are met.
Generates extra `child_archives` to create the DFT+TB workflow if the conditions in `workflow_dft_files` are met.
"""
filepath = kwargs.get('filename')
mainfile = os.path.basename(filepath)
wannier90_files = get_files('*.wout', filepath, mainfile, deep=False)
if len(wannier90_files) == 1:
return ['DMFT_workflow']
return True
dft_files = self.workflow_dft_files(**kwargs)
if not dft_files:
return True
return ['DFTPlusTB_workflow']

def parse(
self, filepath: str, archive: EntryArchive, logger: 'BoundLogger'
Expand Down Expand Up @@ -512,23 +528,7 @@ def parse(
# TODO extend to handle DFT+TB workflows using `self._dft_codes`
# Checking if other mainfiles are present, if the closest is a DFT code, tries to create the
# DFT+TB workflow and link it with the corresponding Wannier90 entry
vasprun_files = get_files(
pattern='*vasprun.xml',
filepath=self.mainfile,
stripname=self.basename,
deep=False,
)
outcar_files = get_files(
pattern='*OUTCAR',
filepath=self.mainfile,
stripname=self.basename,
deep=False,
)
dft_files = []
if len(vasprun_files) == 0:
dft_files = outcar_files
elif len(outcar_files) == 0:
dft_files = vasprun_files
dft_files = self.workflow_dft_files(filename=self.mainfile)
if len(dft_files) == 1:
dft_path = dft_files[-1].split('raw/')[-1]
filepath_stripped = self.filepath.split('raw/')[-1]
Expand Down Expand Up @@ -556,8 +556,28 @@ def parse(
)
if dft_path == mainfile:
dft_archive = entry_archive

# check if the simulation cell is the same
dft_cell = dft_archive.m_xpath(
'data.model_system[-1].cell[0]'
)
tb_cell = self.archive.m_xpath(
'data.model_system[-1].cell[0]'
)
if dft_cell is not None and tb_cell is not None:
if dft_cell != tb_cell:
logger.warning(
'The DFT and TB cells do not coincide. We might be connecting wrongly the DFT and TB tasks.'
)
else:
logger.warning(
'Could not resolve the DFT and TB cells.'
)
return

# Parse the workflow information
dft_plus_tb_archive = self._child_archives.get(
'DFT_plus_TB_workflow'
'DFTPlusTB_workflow'
)
dft_plus_tb = parse_dft_plus_tb_workflow(
dft_archive=dft_archive, tb_archive=self.archive
Expand Down
3 changes: 1 addition & 2 deletions src/nomad_parser_wannier90/parsers/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from glob import glob

from nomad.datamodel.metainfo.workflow import TaskReference

from nomad_parser_wannier90.schema_packages.package import DFTPlusTB
from nomad_simulations.schema_packages.workflow import DFTPlusTB


def get_files(pattern: str, filepath: str, stripname: str = '', deep: bool = True):
Expand Down
19 changes: 0 additions & 19 deletions src/nomad_parser_wannier90/parsers/win_parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional, Union

if TYPE_CHECKING:
Expand Down
Loading

1 comment on commit 35a7957

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_parser_wannier90
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_parser_wannier90/parsers
   __init__.py8275%9–11
   band_parser.py511571%4, 24, 50–51, 73–74, 77–78, 85–89, 98–99, 104–105
   dos_parser.py18194%13
   hr_parser.py48981%4, 28, 46–47, 59–60, 94–96
   parser.py2244580%8, 214, 268–269, 309, 327, 366–367, 384, 401, 418, 464, 474–477, 507, 533–588
   win_parser.py973168%4, 35, 92–98, 119, 121–123, 127–128, 160–163, 168, 177–179, 189–191, 212–215, 222, 224–225, 229, 246–250
src/nomad_parser_wannier90/parsers/utils
   utils.py291355%4, 35–37, 56–71
src/nomad_parser_wannier90/schema_packages
   __init__.py8275%9–11
   package.py550%1–11
TOTAL50412775% 

Tests Skipped Failures Errors Time
1 0 💤 0 ❌ 0 🔥 14.082s ⏱️

Please sign in to comment.