Skip to content

Commit

Permalink
chore: bump pydantic to >2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisborn committed Jun 9, 2024
1 parent daae05b commit 607c0d7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ numpy>=1.16.5,<1.24.0
pandas<=2.0.3
protobuf<3.20
pyarrow>=8.0.0
pydantic>=1.7.3,<2.0.0
pydantic>=2.0.0
pymatgen>=2022.11.7
PyTDC==0.3.7
pytorch_lightning<=1.7.7
Expand Down
8 changes: 2 additions & 6 deletions src/gt4sd/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
from functools import lru_cache
from typing import Dict, Optional, Set

from pydantic import BaseSettings

from .s3 import GT4SDS3Client, S3SyncError, sync_folder_with_s3, upload_file_to_s3
from pydantic_settings import BaseSettings, SettingsConfigDict

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
Expand Down Expand Up @@ -65,10 +64,7 @@ class GT4SDConfiguration(BaseSettings):
gt4sd_s3_secure_hub: bool = True
gt4sd_s3_bucket_hub_algorithms: str = "gt4sd-cos-hub-algorithms-artifacts"
gt4sd_s3_bucket_hub_properties: str = "gt4sd-cos-hub-properties-artifacts"

class Config:
# immutable and in turn hashable, that is required for lru_cache
frozen = True
model_config = SettingsConfigDict(frozen=True)

@staticmethod
@lru_cache(maxsize=None)
Expand Down
12 changes: 6 additions & 6 deletions src/gt4sd/properties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ class S3Parameters(PropertyPredictorParameters):
algorithm_type: str = "prediction"

domain: DomainSubmodule = Field(
..., example="molecules", description="Submodule of gt4sd.properties"
..., examples=["molecules"], description="Submodule of gt4sd.properties"
)
algorithm_name: str = Field(..., example="MCA", description="Name of the algorithm")
algorithm_name: str = Field(..., examples=["MCA"], description="Name of the algorithm")
algorithm_version: str = Field(
..., example="v0", description="Version of the algorithm"
..., examples=["v0"], description="Version of the algorithm"
)
algorithm_application: str = Field(..., example="Tox21")
algorithm_application: str = Field(..., examples=["Tox21"])


class ApiTokenParameters(PropertyPredictorParameters):
api_token: str = Field(
...,
example="apk-c9db......",
examples=["apk-c9db......"],
description="The API token/key to access the service",
)

Expand All @@ -68,7 +68,7 @@ class IpAdressParameters(PropertyPredictorParameters):

host_ip: str = Field(
...,
example="xx.xx.xxx.xxx",
examples=["xx.xx.xxx.xxx"],
description="The host IP address to access the service",
)

Expand Down
25 changes: 11 additions & 14 deletions src/gt4sd/properties/molecules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from paccmann_generator.drug_evaluators import OrganDB as _OrganTox
from paccmann_generator.drug_evaluators import SCScore
from paccmann_generator.drug_evaluators import Tox21 as _Tox21
from pydantic import Field
from pydantic import ConfigDict, Field
from tdc import Oracle
from tdc.metadata import download_receptor_oracle_name

Expand Down Expand Up @@ -119,12 +119,12 @@ class ScscoreConfiguration(PropertyPredictorParameters):


class SimilaritySeedParameters(PropertyPredictorParameters):
smiles: str = Field(..., example="c1ccccc1")
smiles: str = Field(..., examples=["c1ccccc1"])
fp_key: str = "ECFP4"


class ActivityAgainstTargetParameters(PropertyPredictorParameters):
target: str = Field(..., example="drd2", description="name of the target.")
target: str = Field(..., examples=["drd2"], description="name of the target.")


class AskcosParameters(IpAdressParameters):
Expand All @@ -136,7 +136,7 @@ class Output(str, Enum):

output: Output = Field(
default=Output.plausability,
example=Output.synthesizability,
examples=[Output.synthesizability],
description="Main output return type from ASKCOS",
options=["plausibility", "num_step", "synthesizability", "price"],
)
Expand All @@ -159,10 +159,7 @@ class Output(str, Enum):
min_chempop_products: int = Field(default=5)
filter_threshold: float = Field(default=0.1)
return_first: str = Field(default="true")

# Convert enum items back to strings
class Config:
use_enum_values = True
model_config = ConfigDict(use_enum_values=True)


class MoleculeOneParameters(ApiTokenParameters):
Expand All @@ -174,7 +171,7 @@ class DockingTdcParameters(PropertyPredictorParameters):
# To dock against a receptor defined via TDC
target: str = Field(
...,
example="1iep_docking",
examples=["1iep_docking"],
description="Target for docking, provided via TDC",
options=download_receptor_oracle_name,
)
Expand All @@ -184,12 +181,12 @@ class DockingParameters(PropertyPredictorParameters):
# To dock against a user-provided receptor
name: str = Field(default="pyscreener")
receptor_pdb_file: str = Field(
example="/tmp/2hbs.pdb", description="Path to receptor PDB file"
examples=["/tmp/2hbs.pdb"], description="Path to receptor PDB file"
)
box_center: List[int] = Field(
example=[15.190, 53.903, 16.917], description="Docking box center"
examples=[[15.190, 53.903, 16.917]], description="Docking box center"
)
box_size: List[float] = Field(example=[20, 20, 20], description="Docking box size")
box_size: List[float] = Field(examples=[[20, 20, 20]], description="Docking box size")


class S3ParametersMolecules(S3Parameters):
Expand Down Expand Up @@ -265,12 +262,12 @@ class ToxType(str, Enum):
algorithm_application: str = "OrganTox"
site: Organs = Field(
...,
example=Organs.kidney,
examples=[Organs.kidney],
description="name of the target site of interest.",
)
toxicity_type: ToxType = Field(
default=ToxType.all,
example=ToxType.chronic,
examples=[ToxType.chronic],
description="type of toxicity for which predictions are made.",
options=["chronic", "subchronic", "multigenerational", "all"],
)
Expand Down
4 changes: 2 additions & 2 deletions src/gt4sd/properties/proteins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
class AmideConfiguration(PropertyPredictorParameters):
amide: bool = Field(
False,
example=False,
examples=[False],
description="whether the sequences are C-terminally amidated.",
)

Expand All @@ -58,7 +58,7 @@ class PhConfiguration(PropertyPredictorParameters):
class AmidePhConfiguration(PropertyPredictorParameters):
amide: bool = Field(
False,
example=False,
examples=[False],
description="whether the sequences are C-terminally amidated.",
)
ph: float = 7.0
Expand Down
7 changes: 2 additions & 5 deletions src/gt4sd/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pathlib import PosixPath

import importlib_resources
from pydantic import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict


class GT4SDTestSettings(BaseSettings):
Expand All @@ -40,10 +40,7 @@ class GT4SDTestSettings(BaseSettings):
gt4sd_s3_secret_key: str = "5748375c761a4f09c30a68cd15e218e3b27ca3e2aebd7726"
gt4sd_s3_secure: bool = True
gt4sd_ci: bool = False

class Config:
# immutable and in turn hashable, that is required for lru_cache
frozen = True
model_config = SettingsConfigDict(frozen=True)

@staticmethod
@lru_cache(maxsize=None)
Expand Down

0 comments on commit 607c0d7

Please sign in to comment.