diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9313058..eb3e2a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: - workflow_dispatch jobs: - test: + test-linux: runs-on: ubuntu-latest strategy: @@ -26,3 +26,44 @@ jobs: run: pip install tox tox-gh-actions - name: Test with tox run: tox -r + + test-windows: + + runs-on: windows-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version}} + architecture: x64 + - name: Install pandoc + run: choco install pandoc + - name: Install tox + run: pip install tox tox-gh-actions + - name: Test with tox + run: tox -r + + test-macos: + + runs-on: macOS-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version}} + - name: Install pandoc + run: brew install pandoc + - name: Install tox + run: pip install tox tox-gh-actions + - name: Test with tox + run: tox -r \ No newline at end of file diff --git a/tests/writers/test_to_clapeyron.py b/tests/writers/test_to_clapeyron.py index 0b578a9..f6085f9 100644 --- a/tests/writers/test_to_clapeyron.py +++ b/tests/writers/test_to_clapeyron.py @@ -10,18 +10,18 @@ from ugropy.writers.clapeyron_writers import write_molar_mass -here = Path(__file__).parent.resolve() -path_db = f"{here}/test_expected_result" +here = Path(__file__).parent +path_db = here / "test_expected_result" def test_to_clapeyron(): - with open(f"{path_db}/molarmass.csv", mode="r") as f: + with open(path_db / "molarmass.csv", mode="r") as f: df_molarmass = pd.read_csv(f, sep="|", index_col=None) - with open(f"{path_db}/ogUNIFAC_groups.csv", mode="r") as f: + with open(path_db / "ogUNIFAC_groups.csv", mode="r") as f: df_unifac = pd.read_csv(f, sep="|", index_col=None) - with open(f"{path_db}/PSRK_groups.csv", mode="r") as f: + with open(path_db / "PSRK_groups.csv", mode="r") as f: df_psrk = pd.read_csv(f, sep="|", index_col=None) limonene = Groups("CC1=CCC(CC1)C(=C)C", "smiles") @@ -32,19 +32,21 @@ def test_to_clapeyron(): [limonene.unifac.subgroups, ethanol.unifac.subgroups], [limonene.psrk.subgroups, ethanol.psrk.subgroups], [limonene.joback, ethanol.joback], - f"{here}/database", + (here / "database").resolve(), ) - with open(f"{here}/database/critical.csv", mode="r") as f: + with open(here / "database" / "critical.csv", mode="r") as f: df_critical_ugropy = pd.read_csv(f, sep="|", index_col=None) - with open(f"{here}/database/molarmass.csv", mode="r") as f: + with open(here / "database" / "molarmass.csv", mode="r") as f: df_molarmass_ugropy = pd.read_csv(f, sep="|", index_col=None) - with open(f"{here}/database/ogUNIFAC/ogUNIFAC_groups.csv", mode="r") as f: + with open( + here / "database" / "ogUNIFAC" / "ogUNIFAC_groups.csv", mode="r" + ) as f: df_unifac_ugropy = pd.read_csv(f, sep="|", index_col=None) - with open(f"{here}/database/PSRK/PSRK_groups.csv", mode="r") as f: + with open(here / "database" / "PSRK/PSRK_groups.csv", mode="r") as f: df_psrk_ugropy = pd.read_csv(f, sep="|", index_col=None) assert df_unifac.equals(df_unifac_ugropy) @@ -72,23 +74,23 @@ def test_to_clapeyron(): == "ethanol,,519.5440517502864,5756641.437226128,0.00016649999999999998,0.5610678012451401" # noqa ) - os.remove(f"{here}/database/critical.csv") - os.remove(f"{here}/database/molarmass.csv") - os.remove(f"{here}/database/ogUNIFAC/ogUNIFAC_groups.csv") - os.remove(f"{here}/database/PSRK/PSRK_groups.csv") - os.rmdir(f"{here}/database/ogUNIFAC") - os.rmdir(f"{here}/database/PSRK") - os.rmdir(f"{here}/database") + os.remove(here / "database" / "critical.csv") + os.remove(here / "database" / "molarmass.csv") + os.remove(here / "database" / "ogUNIFAC" / "ogUNIFAC_groups.csv") + os.remove(here / "database" / "PSRK" / "PSRK_groups.csv") + os.rmdir(here / "database" / "ogUNIFAC") + os.rmdir(here / "database/PSRK") + os.rmdir(here / "database") def test_to_clapeyron_batch_name(): - with open(f"{path_db}/molarmass.csv", mode="r") as f: + with open(path_db / "molarmass.csv", mode="r") as f: df_molarmass = pd.read_csv(f, sep="|", index_col=None) - with open(f"{path_db}/ogUNIFAC_groups.csv", mode="r") as f: + with open(path_db / "ogUNIFAC_groups.csv", mode="r") as f: df_unifac = pd.read_csv(f, sep="|", index_col=None) - with open(f"{path_db}/PSRK_groups.csv", mode="r") as f: + with open(path_db / "PSRK_groups.csv", mode="r") as f: df_psrk = pd.read_csv(f, sep="|", index_col=None) limonene = Groups("CC1=CCC(CC1)C(=C)C", "smiles") @@ -99,22 +101,24 @@ def test_to_clapeyron_batch_name(): [limonene.unifac.subgroups, ethanol.unifac.subgroups], [limonene.psrk.subgroups, ethanol.psrk.subgroups], [limonene.joback, ethanol.joback], - f"{here}/database", + (here / "database").resolve(), "otacon", ) - with open(f"{here}/database/otacon_critical.csv", mode="r") as f: + with open(here / "database" / "otacon_critical.csv", mode="r") as f: df_critical_ugropy = pd.read_csv(f, sep="|", index_col=None) - with open(f"{here}/database/otacon_molarmass.csv", mode="r") as f: + with open(here / "database" / "otacon_molarmass.csv", mode="r") as f: df_molarmass_ugropy = pd.read_csv(f, sep="|", index_col=None) with open( - f"{here}/database/ogUNIFAC/otacon_ogUNIFAC_groups.csv", mode="r" + here / "database" / "ogUNIFAC" / "otacon_ogUNIFAC_groups.csv", mode="r" ) as f: df_unifac_ugropy = pd.read_csv(f, sep="|", index_col=None) - with open(f"{here}/database/PSRK/otacon_PSRK_groups.csv", mode="r") as f: + with open( + here / "database" / "PSRK" / "otacon_PSRK_groups.csv", mode="r" + ) as f: df_psrk_ugropy = pd.read_csv(f, sep="|", index_col=None) assert df_unifac.equals(df_unifac_ugropy) @@ -142,13 +146,13 @@ def test_to_clapeyron_batch_name(): == "ethanol,,519.5440517502864,5756641.437226128,0.00016649999999999998,0.5610678012451401" # noqa ) - os.remove(f"{here}/database/otacon_critical.csv") - os.remove(f"{here}/database/otacon_molarmass.csv") - os.remove(f"{here}/database/ogUNIFAC/otacon_ogUNIFAC_groups.csv") - os.remove(f"{here}/database/PSRK/otacon_PSRK_groups.csv") - os.rmdir(f"{here}/database/ogUNIFAC") - os.rmdir(f"{here}/database/PSRK") - os.rmdir(f"{here}/database") + os.remove(here / "database" / "otacon_critical.csv") + os.remove(here / "database" / "otacon_molarmass.csv") + os.remove(here / "database" / "ogUNIFAC" / "otacon_ogUNIFAC_groups.csv") + os.remove(here / "database" / "PSRK" / "otacon_PSRK_groups.csv") + os.rmdir(here / "database" / "ogUNIFAC") + os.rmdir(here / "database" / "PSRK") + os.rmdir(here / "database") def test_molar_mass_csv(): @@ -161,22 +165,22 @@ def test_molar_mass_csv(): ["limonene", "ethanol"], unifac_groups=[limonene.unifac.subgroups, ethanol.unifac.subgroups], psrk_groups=[limonene.psrk.subgroups, ethanol.psrk.subgroups], - path=f"{here}/database", + path=(here / "database").resolve(), ) - with open(f"{here}/database/molarmass.csv", mode="r") as f: + with open(here / "database" / "molarmass.csv", mode="r") as f: df_molarmass_unifac = pd.read_csv(f, sep="|", index_col=None) - os.remove(f"{here}/database/molarmass.csv") + os.remove(here / "database" / "molarmass.csv") # PSRK molar mass to_clapeyron( ["limonene", "ethanol"], psrk_groups=[limonene.psrk.subgroups, ethanol.psrk.subgroups], - path=f"{here}/database", + path=(here / "database").resolve(), ) - with open(f"{here}/database/molarmass.csv", mode="r") as f: + with open(here / "database" / "molarmass.csv", mode="r") as f: df_molarmass_psrk = pd.read_csv(f, sep="|", index_col=None) assert ( @@ -192,17 +196,17 @@ def test_molar_mass_csv(): assert df_molarmass_unifac.iloc[3].to_numpy()[0] == "ethanol,,46.069" assert df_molarmass_unifac.equals(df_molarmass_psrk) - os.remove(f"{here}/database/molarmass.csv") - os.remove(f"{here}/database/ogUNIFAC/ogUNIFAC_groups.csv") - os.remove(f"{here}/database/PSRK/PSRK_groups.csv") - os.rmdir(f"{here}/database/ogUNIFAC") - os.rmdir(f"{here}/database/PSRK") - os.rmdir(f"{here}/database") + os.remove(here / "database" / "molarmass.csv") + os.remove(here / "database" / "ogUNIFAC" / "ogUNIFAC_groups.csv") + os.remove(here / "database" / "PSRK" / "PSRK_groups.csv") + os.rmdir(here / "database" / "ogUNIFAC") + os.rmdir(here / "database" / "PSRK") + os.rmdir(here / "database") # Making it fail with pytest.raises(ValueError): write_molar_mass( - path=f"{here}/database", + path=(here / "database").resolve(), batch_name=None, molecules_names=["limonene", "ethanol"], ) diff --git a/ugropy/constants.py b/ugropy/constants.py index 659c57a..51f8029 100644 --- a/ugropy/constants.py +++ b/ugropy/constants.py @@ -10,10 +10,10 @@ # constants.py path -_here = Path(__file__).parent.resolve() +_here = Path(__file__).parent # CSVs path -_csvs = f"{_here}/groupscsv" +_csvs = _here / "groupscsv" # Gas constant [J/mol/K] R = 8.31446261815324 diff --git a/ugropy/fragmentation_models/models.py b/ugropy/fragmentation_models/models.py index 27969bb..4526f7a 100644 --- a/ugropy/fragmentation_models/models.py +++ b/ugropy/fragmentation_models/models.py @@ -22,7 +22,7 @@ def _rd(file_path: str, index_col: str = None) -> pd.DataFrame: Parameters ---------- - file_path : str + file_path : str or pathlib Path to csv file. index_col : str, optional Name of the index column, by default None. @@ -39,13 +39,13 @@ def _rd(file_path: str, index_col: str = None) -> pd.DataFrame: # ============================================================================= # LV-UNIFAC # ============================================================================= -_uni = f"{_csvs}/unifac" +_uni = _csvs / "unifac" -_uni_sg = _rd(f"{_uni}/unifac_subgroups.csv", "group") -_uni_mg = _rd(f"{_uni}/unifac_maingroups.csv", "no.") -_uni_info = _rd(f"{_uni}/unifac_info.csv", "group") -_uni_problems = _rd(f"{_csvs}/problematic_structures.csv", "smarts") -_uni_hide = _rd(f"{_uni}/hideouts.csv", "group") +_uni_sg = _rd(_uni / "unifac_subgroups.csv", "group") +_uni_mg = _rd(_uni / "unifac_maingroups.csv", "no.") +_uni_info = _rd(_uni / "unifac_info.csv", "group") +_uni_problems = _rd(_csvs / "problematic_structures.csv", "smarts") +_uni_hide = _rd(_uni / "hideouts.csv", "group") unifac = GibbsModel( subgroups=_uni_sg, @@ -60,13 +60,13 @@ def _rd(file_path: str, index_col: str = None) -> pd.DataFrame: # ============================================================================= # PSRK # ============================================================================= -_psrk = f"{_csvs}/psrk" +_psrk = _csvs / "psrk" -_psrk_sg = _rd(f"{_psrk}/psrk_subgroups.csv", "group") -_psrk_mg = _rd(f"{_psrk}/psrk_maingroups.csv", "no.") -_psrk_info = _rd(f"{_psrk}/psrk_info.csv", "group") -_psrk_problems = _rd(f"{_csvs}/problematic_structures.csv", "smarts") -_psrk_hide = _rd(f"{_psrk}/hideouts.csv", "group") +_psrk_sg = _rd(_psrk / "psrk_subgroups.csv", "group") +_psrk_mg = _rd(_psrk / "psrk_maingroups.csv", "no.") +_psrk_info = _rd(_psrk / "psrk_info.csv", "group") +_psrk_problems = _rd(_csvs / "problematic_structures.csv", "smarts") +_psrk_hide = _rd(_psrk / "hideouts.csv", "group") psrk = GibbsModel( subgroups=_psrk_sg, @@ -97,11 +97,11 @@ def _rd(file_path: str, index_col: str = None) -> pd.DataFrame: # ============================================================================= # Joback # ============================================================================= -_jo = f"{_csvs}/joback" +_jo = _csvs / "joback" -_jo_sg = _rd(f"{_jo}/joback_subgroups.csv", "group") -_jo_problems = _rd(f"{_jo}/joback_problematics.csv", "smarts") -_jo_props = _rd(f"{_jo}/properties_contrib.csv", "group") +_jo_sg = _rd(_jo / "joback_subgroups.csv", "group") +_jo_problems = _rd(_jo / "joback_problematics.csv", "smarts") +_jo_props = _rd(_jo / "properties_contrib.csv", "group") joback = PropertiesEstimator( subgroups=_jo_sg, @@ -114,12 +114,12 @@ def _rd(file_path: str, index_col: str = None) -> pd.DataFrame: # Constantinou and Gani # ============================================================================= # Primary structures -_cg = f"{_csvs}/constantinou_gani" +_cg_p = _csvs / "constantinou_gani" / "primary" -_cg_sg = _rd(f"{_cg}/primary/c_g_prymary_subgroups.csv", "group") -_cg_problems = _rd(f"{_cg}/primary/cg_problematics.csv", "smarts") -_cg_hide = _rd(f"{_cg}/primary/hideouts.csv", "group") -_cg_props = _rd(f"{_cg}/primary/properties_prymary_contrib.csv", "group") +_cg_sg = _rd(_cg_p / "c_g_prymary_subgroups.csv", "group") +_cg_problems = _rd(_cg_p / "cg_problematics.csv", "smarts") +_cg_hide = _rd(_cg_p / "hideouts.csv", "group") +_cg_props = _rd(_cg_p / "properties_prymary_contrib.csv", "group") constantinou_gani_primary = PropertiesEstimator( subgroups=_cg_sg, diff --git a/ugropy/writers/clapeyron.py b/ugropy/writers/clapeyron.py index f01f71a..4910555 100644 --- a/ugropy/writers/clapeyron.py +++ b/ugropy/writers/clapeyron.py @@ -18,7 +18,7 @@ def to_clapeyron( unifac_groups: List[dict] = [], psrk_groups: List[dict] = [], joback_objects: List[JobackProperties] = [], - path: str = "./database", + path: str = "database", batch_name: str = "", ) -> None: """Write the .csv input files for Clapeyron.jl. @@ -51,9 +51,6 @@ def to_clapeyron( if len(molecules_names) == 0: raise ValueError("No names provided for the molecules.") - if not path_pathlib.is_dir(): - path_pathlib.mkdir(parents=True) - if unifac_groups and len(unifac_groups) != len(molecules_names): raise ValueError( "UNIFAC groups list must have the same amount of elements than" @@ -72,6 +69,10 @@ def to_clapeyron( "the molecules name list." ) + # Create dir if not created + if not path_pathlib.is_dir(): + path_pathlib.mkdir(parents=True) + # Molar mass write_molar_mass( path_pathlib,