Skip to content

Commit

Permalink
Blackified
Browse files Browse the repository at this point in the history
  • Loading branch information
dotsdl committed Jan 17, 2022
1 parent 40560dd commit 56a50f1
Show file tree
Hide file tree
Showing 11 changed files with 813 additions and 534 deletions.
344 changes: 220 additions & 124 deletions fah_xchem/cli.py

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions fah_xchem/compute/compound_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@ class CompoundSeriesUpdate(BaseModel):
Can include any set of fields as needed to update a CompoundSeries.
"""

metadata: CompoundSeriesMetadata = None
compounds: List[Compound] = None
transformations: List[Transformation] = None


class CompoundSeries(BaseModel):
"""A compound series; the core object of operation in fah-xchem.
"""A compound series; the core object of operation in fah-xchem."""

"""
metadata: CompoundSeriesMetadata = Field(
...,
description="Metadata for the whole compound series"
..., description="Metadata for the whole compound series"
)
compounds: List[Compound] = Field(
...,
description="List of compounds comprising the compound series"
..., description="List of compounds comprising the compound series"
)
transformations: List[Transformation] = Field(
...,
description="List of transformations performed between compounds within the compound series"
description="List of transformations performed between compounds within the compound series",
)

def update_experimental_data(
self,
metadata: List[CompoundMetadata],
) -> None:
self,
metadata: List[CompoundMetadata],
) -> None:
"""Update experimental data for compounds in the CompoundSeries.
Compound instances in `self.compounds` will be replaced as necessary.
Expand All @@ -54,12 +52,14 @@ def update_experimental_data(
for compound in self.compounds:
metadata_update = metadata_d.get(compound.metadata.compound_id)

if metadata_update:
if metadata_update:
metadata_current = compound.metadata.dict()
metadata_current['experimental_data'].update(metadata_update.experimental_data)
metadata_current["experimental_data"].update(
metadata_update.experimental_data
)

compound_current = compound.dict()
compound_current['metadata'] = metadata_current
compound_current["metadata"] = metadata_current

new_compounds.append(Compound(**compound_current))
else:
Expand Down
18 changes: 9 additions & 9 deletions fah_xchem/external/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@


class ExternalData(BaseModel):
"""Mixin class for external data interfaces.
"""Mixin class for external data interfaces."""

"""
data_dir: Path = Field(
...,
description="Data directory; retrieved data will be deposited here, can be pre-existing")
description="Data directory; retrieved data will be deposited here, can be pre-existing",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# create data directory if not present
self.data_dir.mkdir(parents=True, exist_ok=True)


@staticmethod
def _download_url(url, save_path, headers=None, chunk_size=128, message=None):
"""
Expand All @@ -29,10 +28,11 @@ def _download_url(url, save_path, headers=None, chunk_size=128, message=None):
# Create directory
base_path, filename = os.path.split(save_path)
os.makedirs(base_path, exist_ok=True)

r = requests.get(url, stream=True, headers=headers)
with open(save_path, 'wb') as fd:
nchunks = int(int(r.headers['Content-Length'])/chunk_size)
for chunk in track(r.iter_content(chunk_size=chunk_size), message,
total=nchunks):
with open(save_path, "wb") as fd:
nchunks = int(int(r.headers["Content-Length"]) / chunk_size)
for chunk in track(
r.iter_content(chunk_size=chunk_size), message, total=nchunks
):
fd.write(chunk)
Loading

0 comments on commit 56a50f1

Please sign in to comment.