Skip to content

Commit

Permalink
CAT 0.8.8 (#114)
Browse files Browse the repository at this point in the history
* Fixed a bug where ligands weren't properly rotated when using ``optional.ligand.optimize = False``.
* Added tests for ``CAT.utils.SetAttr``.
  • Loading branch information
BvB93 authored May 20, 2020
1 parent c0de1eb commit 0b17e4b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CAT/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.8.7'
__version__ = '0.8.8'
9 changes: 8 additions & 1 deletion CAT/_setattr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
"""A module for containing the :class:`SetAttr` class."""
"""A module for containing the :class:`SetAttr` class.
Notes
-----
:class:`SetAttr` should be imported from :mod:`CAT.utils`.
"""

import reprlib
from threading import RLock
Expand Down Expand Up @@ -87,6 +93,7 @@ def __init__(self, obj: T1, name: str, value: T2) -> None:
self._value_old = self.attr
self._lock = RLock()

@reprlib.recursive_repr()
def __repr__(self) -> str:
"""Implement :func:`str(self)<str>` and :func:`repr(self)<repr>`."""
obj = object.__repr__(self.obj)
Expand Down
2 changes: 1 addition & 1 deletion CAT/attachment/optimize_rotmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _minimize_func(vec1: np.ndarray, vec2: np.ndarray, xyz: np.ndarray, anchor:
xyz_new = xyz@rotmat
xyz_new -= xyz_new[anchor]

# Apply the cost function: e^(|yz|)
# Apply the cost function: e^(||yz||)
yz = xyz_new[:, 1:]
distance = np.linalg.norm(yz, axis=1)
return np.exp(distance).sum()
Expand Down
5 changes: 4 additions & 1 deletion CAT/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

from .multi_ligand import init_multi_ligand
from .attachment.qd_opt import init_qd_opt
from .attachment.ligand_opt import init_ligand_opt
from .attachment.ligand_opt import init_ligand_opt, allign_axis
from .attachment.distribution import distribute_idx
from .attachment.ligand_attach import init_qd_construction
from .attachment.ligand_anchoring import init_ligand_anchoring
Expand Down Expand Up @@ -295,6 +295,9 @@ def prep_ligand(ligand_df: SettingsDataFrame) -> SettingsDataFrame:
# Optimize the ligands
if optimize:
init_ligand_opt(ligand_df)
else:
for lig in ligand_df[MOL]:
allign_axis(lig, lig.properties.dummies)

# Perform a COSMO-RS calculation on the ligands
if crs:
Expand Down
10 changes: 5 additions & 5 deletions CAT/settings_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""

from typing import Optional
from typing import Optional, Callable

import pandas as pd

Expand Down Expand Up @@ -59,14 +59,14 @@ def __init__(self, data=None, index=None, dtype=None, name=None, copy=False, fas
super().__init__(data, index, dtype, name, copy, fastpath)

@property
def _constructor(self) -> 'SettingsSeries':
def _constructor(self) -> Callable[..., 'SettingsSeries']:
"""Construct a :class:`.SettingsSeries` instance."""
def _series(*args, **kwargs) -> SettingsSeries:
return SettingsSeries(*args, **kwargs).__finalize__(self)
return _series

@property
def _constructor_expanddim(self) -> 'SettingsDataFrame':
def _constructor_expanddim(self) -> Callable[..., 'SettingsDataFrame']:
"""Construct a :class:`.SettingsDataFrame` instance."""
def _df(*args, **kwargs) -> SettingsDataFrame:
return SettingsDataFrame(*args, **kwargs).__finalize__(self)
Expand Down Expand Up @@ -109,14 +109,14 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False,
super().__init__(data, index, columns, dtype, copy)

@property
def _constructor(self) -> 'SettingsDataFrame':
def _constructor(self) -> Callable[..., 'SettingsDataFrame']:
"""Construct a :class:`.SettingsDataFrame` instance."""
def _df(*args, **kwargs) -> SettingsDataFrame:
return SettingsDataFrame(*args, **kwargs).__finalize__(self)
return _df

@property
def _constructor_sliced(self) -> 'SettingsSeries':
def _constructor_sliced(self) -> Callable[..., 'SettingsSeries']:
"""Construct a :class:`.SettingsSeries` instance."""
def _series(*args, **kwargs) -> SettingsSeries:
return SettingsSeries(*args, **kwargs).__finalize__(self)
Expand Down
10 changes: 7 additions & 3 deletions CAT/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def restart_init(path: str, folder: str, hashing: str = 'input') -> None:
@overload
def cycle_accumulate(iterable: Iterable[T1]) -> Generator[T1, None, None]: ...
@overload
def cycle_accumulate(iterable: Iterable[T1], start: T1 = ...) -> Generator[T1, None, None]: ...
def cycle_accumulate(iterable: Iterable[T1], start: T1) -> Generator[T1, None, None]: ...
def cycle_accumulate(iterable, start=0): # noqa: E302
"""Accumulate and return elements from **iterable** until it is exhausted.
Expand Down Expand Up @@ -547,5 +547,9 @@ def from_str(cls, version: str) -> 'VersionInfo':
cls_name = version.__class__.__name__
raise TypeError(f"'version' expected a string; observed type: {cls_name!r}")

args = (int(i) for i in version.split('.'))
return cls(*args)
try:
major, minor, micro = (int(i) for i in version.split('.'))
except (ValueError, TypeError) as ex:
raise ValueError("'version' expected a string consisting of three '.'-separated "
f"integers (e.g. '0.8.2'); observed value: {version!r}") from ex
return cls(major=major, minor=minor, micro=micro)
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
* WiP: Added an option the import pre-built quantum dots.


0.8.8
*****
* Fixed a bug where ligands weren't properly rotated when
using ``optional.ligand.optimize = False``.
* Added tests for ``CAT.utils.SetAttr``.


0.8.7
*****
* Replaced ``print()`` calls with ``logger.warning()`` in all dye-related functions.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


##############################
Compound Attachment Tool 0.8.7
Compound Attachment Tool 0.8.8
##############################

**CAT** is a collection of tools designed for the construction of various chemical compounds.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the built documents.
release = '0.8.7' # The full version, including alpha/beta/rc tags.
release = '0.8.8' # The full version, including alpha/beta/rc tags.
version = release.rsplit('.', maxsplit=1)[0]


Expand Down
49 changes: 49 additions & 0 deletions tests/test_setattr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Tests for :class:`CAT._setattr.SetAttr`."""

import copy
import reprlib
from assertionlib import assertion

from CAT.utils import SetAttr


class _Test:
a = True


OBJ = SetAttr(_Test, 'a', False)


def test_setattr() -> None:
"""Test :class:`CAT._setattr.SetAttr`."""
assertion.is_(OBJ.obj, _Test)
assertion.eq(OBJ.name, 'a')
assertion.is_(OBJ.value, False)

assertion.is_(OBJ.attr, _Test.a)
try:
OBJ.attr = False
assertion.is_(OBJ.attr, False)
finally:
OBJ.attr = True

assertion.contains(repr(OBJ), SetAttr.__name__)
assertion.contains(repr(OBJ), object.__repr__(OBJ.obj))
assertion.contains(repr(OBJ), reprlib.repr(OBJ.value))
assertion.contains(repr(OBJ), 'a')

obj2 = SetAttr(_Test, 'a', False)
obj3 = SetAttr(_Test, 'a', True)
assertion.eq(OBJ, obj2)
assertion.ne(OBJ, obj3)
assertion.ne(OBJ, 0)

assertion.assert_(OBJ.__reduce__, exception=TypeError)
assertion.is_(copy.copy(OBJ), OBJ)
assertion.is_(copy.deepcopy(OBJ), OBJ)
assertion.truth(hash(OBJ))
assertion.eq(hash(OBJ), OBJ._hash)

with OBJ:
assertion.is_(_Test.a, False)
assertion.is_(_Test.a, True)

0 comments on commit 0b17e4b

Please sign in to comment.