Skip to content

Commit

Permalink
[FIX] Fix type Hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
PauAndrio committed May 29, 2024
1 parent 0c92541 commit 7c27aa0
Show file tree
Hide file tree
Showing 48 changed files with 99 additions and 59 deletions.
2 changes: 1 addition & 1 deletion biobb_gromacs/gromacs/editconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def launch(self) -> int:
self.copy_to_host()

# Remove temporal files
self.tmp_files.append(str(self.stage_io_dict.get("unique_dir")))
self.tmp_files.append(str(self.stage_io_dict.get("unique_dir", "")))
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
Expand Down
6 changes: 3 additions & 3 deletions biobb_gromacs/gromacs/genion.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def launch(self) -> int:
top_dir = str(Path(top_file).parent)

if self.container_path:
shutil.copytree(top_dir, Path(str(self.stage_io_dict.get("unique_dir"))).joinpath(Path(top_dir).name))
shutil.copytree(top_dir, Path(str(self.stage_io_dict.get("unique_dir", ""))).joinpath(Path(top_dir).name))
top_file = str(Path(self.container_volume_path).joinpath(Path(top_dir).name, Path(top_file).name))

self.cmd = [str(self.binary_path), 'genion',
Expand Down Expand Up @@ -156,15 +156,15 @@ def launch(self) -> int:
self.copy_to_host()

if self.container_path:
top_file = str(Path(str(self.stage_io_dict.get("unique_dir"))).joinpath(Path(top_dir).name, Path(top_file).name))
top_file = str(Path(str(self.stage_io_dict.get("unique_dir", ""))).joinpath(Path(top_dir).name, Path(top_file).name))

# zip topology
fu.log('Compressing topology to: %s' % self.stage_io_dict["out"]["output_top_zip_path"],
self.out_log, self.global_log)
fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=top_file, out_log=self.out_log)

# Remove temporal files
self.tmp_files.extend([str(self.stage_io_dict.get("unique_dir")), top_dir, str(self.io_dict['in'].get("stdin_file_path"))])
self.tmp_files.extend([str(self.stage_io_dict.get("unique_dir", "")), top_dir, str(self.io_dict['in'].get("stdin_file_path"))])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=True)
Expand Down
2 changes: 1 addition & 1 deletion biobb_gromacs/gromacs/genrestr.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def launch(self) -> int:
self.copy_to_host()

# Remove temporal files
self.tmp_files.extend([str(self.stage_io_dict.get("unique_dir")), str(self.io_dict['in'].get("stdin_file_path"))])
self.tmp_files.extend([str(self.stage_io_dict.get("unique_dir", "")), str(self.io_dict['in'].get("stdin_file_path"))])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
Expand Down
11 changes: 6 additions & 5 deletions biobb_gromacs/gromacs/gmxselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Module containing the Select class and the command line interface."""
import argparse
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -53,8 +54,8 @@ class Gmxselect(BiobbObject):
* schema: http://edamontology.org/EDAM.owl
"""

def __init__(self, input_structure_path: str, output_ndx_path: str, input_ndx_path: str = None,
properties: dict = None, **kwargs) -> None:
def __init__(self, input_structure_path: str, output_ndx_path: str, input_ndx_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -123,20 +124,20 @@ def launch(self) -> int:
fu.log(f"Appending {self.io_dict['in'].get('input_ndx_path')} to {self.io_dict['out']['output_ndx_path']}", self.out_log, self.global_log)
with open(self.io_dict["out"]["output_ndx_path"], 'a') as out_ndx_file:
out_ndx_file.write('\n')
with open(self.io_dict["in"].get("input_ndx_path")) as in_ndx_file:
with open(self.io_dict["in"].get("input_ndx_path", '')) as in_ndx_file:
for line in in_ndx_file:
out_ndx_file.write(line)

# Remove temporal files
self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
self.tmp_files.append(self.stage_io_dict.get("unique_dir", ''))
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
return self.return_code


def gmxselect(input_structure_path: str, output_ndx_path: str,
input_ndx_path: str = None, properties: dict = None,
input_ndx_path: Optional[str] = None, properties: Optional[Dict] = None,
**kwargs) -> int:
"""Create :class:`Gmxselect <gromacs.gmxselect.Gmxselect>` class and
execute the :meth:`launch() <gromacs.gmxselect.Gmxselect.launch>` method."""
Expand Down
18 changes: 9 additions & 9 deletions biobb_gromacs/gromacs/grompp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Module containing the Grompp class and the command line interface."""
import argparse
import shutil
from typing import Optional
from typing import Optional, Dict
from pathlib import Path
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
Expand Down Expand Up @@ -69,7 +69,7 @@ class Grompp(BiobbObject):

def __init__(self, input_gro_path: str, input_top_zip_path: str, output_tpr_path: str,
input_cpt_path: Optional[str] = None, input_ndx_path: Optional[str] = None, input_mdp_path: Optional[str] = None,
properties: dict = None, **kwargs) -> None:
properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -120,12 +120,12 @@ def launch(self) -> int:
self.stage_files()

# Unzip topology to topology_out
top_file = fu.unzip_top(zip_file=self.input_top_zip_path, out_log=self.out_log, unique_dir=self.stage_io_dict.get("unique_dir"))
top_file = fu.unzip_top(zip_file=self.input_top_zip_path, out_log=self.out_log, unique_dir=self.stage_io_dict.get("unique_dir", ""))

# Create MDP file
self.output_mdp_path = create_mdp(output_mdp_path=str(Path(self.stage_io_dict.get("unique_dir")).joinpath(self.output_mdp_path)),
self.output_mdp_path = create_mdp(output_mdp_path=str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(self.output_mdp_path)),
input_mdp_path=self.io_dict["in"]["input_mdp_path"],
preset_dict=mdp_preset(self.simulation_type),
preset_dict=mdp_preset(str(self.simulation_type)),
mdp_properties_dict=self.mdp)

# Copy extra files to container: MDP file and topology folder
Expand All @@ -145,15 +145,15 @@ def launch(self) -> int:
if self.stage_io_dict["in"].get("input_cpt_path") and Path(self.stage_io_dict["in"]["input_cpt_path"]).exists():
self.cmd.append('-t')
if self.container_path:
shutil.copy2(self.stage_io_dict["in"]["input_cpt_path"], self.stage_io_dict.get("unique_dir"))
shutil.copy2(self.stage_io_dict["in"]["input_cpt_path"], self.stage_io_dict.get("unique_dir", ""))
self.cmd.append(str(Path(self.container_volume_path).joinpath(Path(self.stage_io_dict["in"]["input_cpt_path"]).name)))
else:
self.cmd.append(self.stage_io_dict["in"]["input_cpt_path"])
if self.stage_io_dict["in"].get("input_ndx_path") and Path(self.stage_io_dict["in"]["input_ndx_path"]).exists():
self.cmd.append('-n')
if self.container_path:
shutil.copy2(self.stage_io_dict["in"]["input_ndx_path"], self.stage_io_dict.get("unique_dir"))
self.cmd.append(Path(self.container_volume_path).joinpath(Path(self.stage_io_dict["in"]["input_ndx_path"]).name))
shutil.copy2(self.stage_io_dict["in"]["input_ndx_path"], self.stage_io_dict.get("unique_dir", ""))
self.cmd.append(str(Path(self.container_volume_path).joinpath(Path(self.stage_io_dict["in"]["input_ndx_path"]).name)))
else:
self.cmd.append(self.stage_io_dict["in"]["input_ndx_path"])

Expand All @@ -167,7 +167,7 @@ def launch(self) -> int:
self.copy_to_host()

# Remove temporal files
self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), 'mdout.mdp'])
self.tmp_files.extend([self.stage_io_dict.get("unique_dir", ''), 'mdout.mdp'])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
Expand Down
10 changes: 5 additions & 5 deletions biobb_gromacs/gromacs/grompp_mdrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""Module containing the GromppMDrun class and the command line interface."""
import argparse
from typing import Optional
from typing import Optional, Dict
from pathlib import Path
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
Expand Down Expand Up @@ -137,14 +137,14 @@ def launch(self) -> int:

fu.log('Calling Grompp class', self.out_log, self.global_log)
grompp_return_code = grompp(input_gro_path=self.input_gro_path, input_top_zip_path=self.input_top_zip_path,
output_tpr_path=self.output_tpr_path, input_cpt_path=self.input_cpt_path,
output_tpr_path=self.output_tpr_path, input_cpt_path=self.input_cpt_path, # type: ignore
input_ndx_path=self.input_ndx_path, input_mdp_path=self.input_mdp_path,
properties=self.properties_grompp)
fu.log(f'Grompp return code: {grompp_return_code}', self.out_log, self.global_log)

if not grompp_return_code:
fu.log('Grompp return code is correct. Calling MDRun class', self.out_log, self.global_log)
mdrun_return_code = mdrun(input_tpr_path=self.output_tpr_path, output_trr_path=self.output_trr_path,
mdrun_return_code = mdrun(input_tpr_path=self.output_tpr_path, output_trr_path=self.output_trr_path, # type: ignore
output_gro_path=self.output_gro_path, output_edr_path=self.output_edr_path,
output_log_path=self.output_log_path, output_xtc_path=self.output_xtc_path,
output_cpt_path=self.output_cpt_path, output_dhdl_path=self.output_dhdl_path,
Expand All @@ -154,7 +154,7 @@ def launch(self) -> int:
return 1

# Remove temporal files
self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), Path(self.output_tpr_path).parent])
self.tmp_files.extend([self.stage_io_dict.get("unique_dir", ''), Path(str(self.output_tpr_path)).parent])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
Expand All @@ -165,7 +165,7 @@ def grompp_mdrun(input_gro_path: str, input_top_zip_path: str, output_trr_path:
output_gro_path: str, output_edr_path: str, output_log_path: str,
input_cpt_path: Optional[str] = None, input_ndx_path: Optional[str] = None, input_mdp_path: Optional[str] = None,
output_xtc_path: Optional[str] = None, output_cpt_path: Optional[str] = None, output_dhdl_path: Optional[str] = None,
output_tpr_path: Optional[str] = None, properties: dict = None, **kwargs) -> int:
output_tpr_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> int:
return GromppMdrun(input_gro_path=input_gro_path, input_top_zip_path=input_top_zip_path,
output_trr_path=output_trr_path, output_gro_path=output_gro_path,
output_edr_path=output_edr_path, output_log_path=output_log_path,
Expand Down
9 changes: 5 additions & 4 deletions biobb_gromacs/gromacs/make_ndx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Module containing the MakeNdx class and the command line interface."""
import argparse
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -52,8 +53,8 @@ class MakeNdx(BiobbObject):
* schema: http://edamontology.org/EDAM.owl
"""

def __init__(self, input_structure_path: str, output_ndx_path: str, input_ndx_path: str = None,
properties: dict = None, **kwargs) -> None:
def __init__(self, input_structure_path: str, output_ndx_path: str, input_ndx_path: Optional[str] = None,
properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -122,15 +123,15 @@ def launch(self) -> int:
self.copy_to_host()

# Remove temporal files
self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), self.io_dict['in'].get("stdin_file_path")])
self.tmp_files.extend([self.stage_io_dict.get("unique_dir", ""), self.io_dict['in'].get("stdin_file_path", '')])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
return self.return_code


def make_ndx(input_structure_path: str, output_ndx_path: str,
input_ndx_path: str = None, properties: dict = None, **kwargs) -> int:
input_ndx_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`MakeNdx <gromacs.make_ndx.MakeNdx>` class and
execute the :meth:`launch() <gromacs.make_ndx.MakeNdx.launch>` method."""
return MakeNdx(input_structure_path=input_structure_path,
Expand Down
2 changes: 1 addition & 1 deletion biobb_gromacs/gromacs/mdrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def launch(self) -> int:
self.copy_to_host()

# Remove temporal files
self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
self.tmp_files.append(self.stage_io_dict.get("unique_dir", ""))
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
Expand Down
8 changes: 4 additions & 4 deletions biobb_gromacs/gromacs/pdb2gmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""Module containing the Pdb2gmx class and the command line interface."""
import os
import argparse
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
from biobb_common.tools.file_utils import launchlogger
from biobb_gromacs.gromacs.common import get_gromacs_version
from typing import Optional, Dict


class Pdb2gmx(BiobbObject):
Expand Down Expand Up @@ -141,23 +141,23 @@ def launch(self) -> int:
self.copy_to_host()

if self.container_path:
internal_top_name = os.path.join(self.stage_io_dict.get("unique_dir"), internal_top_name)
internal_top_name = os.path.join(self.stage_io_dict.get("unique_dir", ""), internal_top_name)

# zip topology
fu.log('Compressing topology to: %s' % self.io_dict["out"]["output_top_zip_path"], self.out_log,
self.global_log)
fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=internal_top_name, out_log=self.out_log)

# Remove temporal files
self.tmp_files.extend([self.internal_top_name, self.internal_itp_name, self.stage_io_dict.get("unique_dir"), self.io_dict['in'].get("stdin_file_path")])
self.tmp_files.extend([self.internal_top_name, self.internal_itp_name, self.stage_io_dict.get("unique_dir", ""), self.io_dict['in'].get("stdin_file_path", "")])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
return self.return_code


def pdb2gmx(input_pdb_path: str, output_gro_path: str, output_top_zip_path: str,
properties: dict = None, **kwargs) -> int:
properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`Pdb2gmx <gromacs.pdb2gmx.Pdb2gmx>` class and
execute the :meth:`launch() <gromacs.pdb2gmx.Pdb2gmx.launch>` method."""

Expand Down
11 changes: 6 additions & 5 deletions biobb_gromacs/gromacs/solvate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import argparse
from pathlib import Path
from typing import Optional, Dict
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
Expand Down Expand Up @@ -59,7 +60,7 @@ class Solvate(BiobbObject):
"""

def __init__(self, input_solute_gro_path: str, output_gro_path: str, input_top_zip_path: str,
output_top_zip_path: str, input_solvent_gro_path: str = None, properties: dict = None, **kwargs) -> None:
output_top_zip_path: str, input_solvent_gro_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> None:
properties = properties or {}

# Call parent class constructor
Expand Down Expand Up @@ -110,7 +111,7 @@ def launch(self) -> int:
top_dir = str(Path(top_file).parent)

if self.container_path:
shutil.copytree(top_dir, str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(top_dir).name)))
shutil.copytree(top_dir, str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(top_dir).name)))
top_file = str(Path(self.container_volume_path).joinpath(Path(top_dir).name, Path(top_file).name))

self.cmd = [self.binary_path, 'solvate',
Expand All @@ -133,23 +134,23 @@ def launch(self) -> int:
self.copy_to_host()

if self.container_path:
top_file = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(top_dir).name, Path(top_file).name))
top_file = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath(Path(top_dir).name, Path(top_file).name))

# zip topology
fu.log('Compressing topology to: %s' % self.stage_io_dict["out"]["output_top_zip_path"], self.out_log,
self.global_log)
fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=top_file, out_log=self.out_log)

# Remove temporal files
self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), top_dir])
self.tmp_files.extend([self.stage_io_dict.get("unique_dir", ""), top_dir])
self.remove_tmp_files()

self.check_arguments(output_files_created=True, raise_exception=False)
return self.return_code


def solvate(input_solute_gro_path: str, output_gro_path: str, input_top_zip_path: str,
output_top_zip_path: str, input_solvent_gro_path: str = None, properties: dict = None, **kwargs) -> int:
output_top_zip_path: str, input_solvent_gro_path: Optional[str] = None, properties: Optional[Dict] = None, **kwargs) -> int:
"""Create :class:`Solvate <gromacs.solvate.Solvate>` class and
execute the :meth:`launch() <gromacs.solvate.Solvate.launch>` method."""

Expand Down
Loading

0 comments on commit 7c27aa0

Please sign in to comment.