Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 40 additions & 48 deletions chemlite/Compound.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A class to represent a chemical species."""

# The MIT License (MIT)
#
# Copyright (c) 2018 Institute for Molecular Systems Biology, ETH Zurich.
Expand Down Expand Up @@ -26,10 +27,7 @@
from typing import (
Dict,
)
from logging import (
Logger,
getLogger
)
from logging import Logger, getLogger
from brs_utils import Cache
from chemlite.Object import Object

Expand All @@ -39,17 +37,14 @@ class Compound(Object):
def __init__(
self,
id: str,
smiles: str = '',
inchi: str = '',
inchikey: str = '',
formula: str = '',
name: str = '',
logger: Logger = getLogger(__name__)
smiles: str = "",
inchi: str = "",
inchikey: str = "",
formula: str = "",
name: str = "",
logger: Logger = getLogger(__name__),
):
super().__init__(
id=id,
logger=logger
)
super().__init__(id=id, logger=logger)
self.set_smiles(smiles)
self.set_inchi(inchi)
self.set_inchikey(inchikey)
Expand All @@ -62,11 +57,11 @@ def __init__(
# return f'Compound {self.get_id()}'

@staticmethod
def from_dict(compound: Dict) -> 'Compound':
def from_dict(compound: Dict) -> "Compound":
return Compound(**compound)

def _to_dict(self) -> Dict:
'''Return a dictionary with all (with legacy) attributes of the object:
"""Return a dictionary with all (with legacy) attributes of the object:
- id (legacy)
- name
- smiles
Expand All @@ -78,14 +73,11 @@ def _to_dict(self) -> Dict:
-------
obj_dict: Dict[str, TypeVar]
A dictionary with all (with legacy) attributes
'''
return {
**super()._to_dict(),
**self.__to_dict()
}
"""
return {**super()._to_dict(), **self.__to_dict()}

def __to_dict(self) -> Dict:
'''Return a dictionary with (specific) attributes:
"""Return a dictionary with (specific) attributes:
- name
- smiles
- inchi
Expand All @@ -96,113 +88,113 @@ def __to_dict(self) -> Dict:
-------
obj_dict: Dict[str, TypeVar]
A dictionary with (specific) attributes of the object
'''
"""
return {
'name': self.get_name(),
'smiles': self.get_smiles(),
'inchi': self.get_inchi(),
'inchikey': self.get_inchikey(),
'formula': self.get_formula(),
"name": self.get_name(),
"smiles": self.get_smiles(),
"inchi": self.get_inchi(),
"inchikey": self.get_inchikey(),
"formula": self.get_formula(),
}

## READ METHODS
def get_name(self) -> str:
'''Returns the name of the compound
"""Returns the name of the compound

Returns
-------
name: str
Name of the compound
'''
"""
return self.__name

def get_smiles(self) -> str:
'''Returns the SMILES string of the compound
"""Returns the SMILES string of the compound

Returns
-------
smiles: str
SMILES of the compound
'''
"""
return self.__smiles

def get_inchi(self) -> str:
'''Returns the InChI of the compound
"""Returns the InChI of the compound

Returns
-------
inchi: str
Inchi of the compound
'''
"""
return self.__inchi

def get_inchikey(self) -> str:
'''Returns the InChIKey of the compound
"""Returns the InChIKey of the compound

Returns
-------
inchikey: str
InChIKey of the compound
'''
"""
return self.__inchikey

def get_formula(self) -> str:
'''Returns the formula of the compound
"""Returns the formula of the compound

Returns
-------
formula: str
Formula of the compound
'''
"""
return self.__formula

## WRITE METHODS
def set_name(self, name: str) -> None:
'''Set the name of the compound
"""Set the name of the compound

Parameters
----------
name: str
String to set the compound's name to
'''
"""
self.__name = name

def set_smiles(self, smiles: str) -> None:
'''Set the SMILES string of the compound
"""Set the SMILES string of the compound

Parameters
----------
smiles: str
String to set the compound's SMILES string to
'''
"""
self.__smiles = smiles

def set_inchi(self, inchi: str) -> None:
'''Set the InChI of the compound
"""Set the InChI of the compound

Parameters
----------
inchi: str
String to set the compound's InChI to
'''
"""
self.__inchi = inchi

def set_inchikey(self, inchikey: str) -> None:
'''Set the InChIKey of the compound
"""Set the InChIKey of the compound

Parameters
----------
inchikey: str
String to set the compound's InChIKey to
'''
"""
self.__inchikey = inchikey

def set_formula(self, formula: str) -> None:
'''Set the formula of the compound
"""Set the formula of the compound

Parameters
----------
formula: str
String to set the compound's formula to
'''
"""
self.__formula = formula
58 changes: 23 additions & 35 deletions chemlite/Object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A class to represent a basic object."""

# The MIT License (MIT)
#
# Copyright (c) 2018 Institute for Molecular Systems Biology, ETH Zurich.
Expand All @@ -23,62 +24,49 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from typing import (
Dict,
Union,
TypeVar
)
from logging import (
Logger,
getLogger
)
from typing import Dict, Union, TypeVar
from logging import Logger, getLogger


class Object:

def __init__(
self,
id: str,
logger: Logger = getLogger(__name__)
):
def __init__(self, id: str, logger: Logger = getLogger(__name__)):
self.__logger = logger
self.set_id(id)

def to_string(self) -> str:
'''Returns a string representation of the object
"""Returns a string representation of the object

Returns
-------
string: str
The string representation of the object
'''
return f'{type(self).__name__} {self.get_id()}'
"""
return f"{type(self).__name__} {self.get_id()}"

def __str__(self) -> str:
'''Prints a string representation of the object (called by print())
"""Prints a string representation of the object (called by print())

Returns
-------
string: str
The string representation of the object
'''
"""
return self.to_string()

def _to_dict(self, full=False) -> Dict[str, TypeVar]:
'''Return a dictionary with the attributes of the object:
"""Return a dictionary with the attributes of the object:
- id

Returns
-------
obj_dict: Dict[str, TypeVar]
A dictionary with the attributes of the object
'''
return {
'id': self.get_id()
}
"""
return {"id": self.get_id()}

def __eq__(self, other) -> bool:
'''Return the equality status of two Object objects
"""Return the equality status of two Object objects

Parameters
----------
Expand All @@ -89,44 +77,44 @@ def __eq__(self, other) -> bool:
-------
equal: bool
Return true if the two objects are equal, False otherwise
'''
"""
if isinstance(self, other.__class__):
return self._to_dict() == other._to_dict()
return False

## READ METHODS
def get_id(self) -> str:
'''Return the ID of the object
"""Return the ID of the object

Returns
-------
id: str
ID of the object
'''
"""
return self.__id

def get_logger(self) -> Logger:
'''Return the object's logger
"""Return the object's logger

Returns
-------
logger: Logger
The object's logger
'''
"""
return self.__logger

## WRITE METHODS
def set_id(self, id: str) -> Union[str, None]:
'''Set the object's id
"""Set the object's id

Parameters
----------
id: str
String to set the object's ID to
'''
"""
if id is None:
raise ValueError('id argument must be different to None for an Object')
elif id == '':
raise ValueError('id argument must not be empty for an Object')
raise ValueError("id argument must be different to None for an Object")
elif id == "":
raise ValueError("id argument must not be empty for an Object")
else:
self.__id = id
Loading
Loading