Module deeporigin.src.utilities.props
Functions
def predict_properties(smiles: str) ‑> Dict[str, Any] | None
-
Expand source code
def predict_properties(smiles: str,) -> Optional[Dict[str, Any]]: """Predicts chemical properties for a given SMILES string. This function sends a request to predict various chemical properties including hERG, logD, logP, logS, ames test results, and cytochrome P450 interactions for a given chemical compound represented by its SMILES notation. Args: smiles (str): A SMILES (Simplified Molecular Input Line Entry System) string representing the chemical compound. Returns: Optional[Dict[str, Any]]: A dictionary containing the predicted properties if successful, with property names as keys and their predicted values as values. Returns None if the prediction fails for any reason (network error, invalid response, etc.). Example: >>> properties = predict_properties("CC(=O)OC1=CC=CC=C1C(=O)O") >>> if properties: ... print(properties["logP"]) Raises: No explicit raises, but handles various exceptions internally and returns None on failure. Note: The function logs its progress and any errors through DEFAULT_LOGGER. """ DEFAULT_LOGGER.log_info("Starting property prediction process.") properties_to_predict = { "hERG": True, "logD": True, "logP": True, "logS": True, "ames": True, "cyp": True } DEFAULT_LOGGER.log_info(f"Properties to predict: {list(properties_to_predict.keys())}") request_body = { "smiles": smiles, "predict": properties_to_predict } DEFAULT_LOGGER.log_info("Prepared request body for property prediction.") client = Client() try: DEFAULT_LOGGER.log_info("Sending property prediction request.") response = client.post_request( endpoint="properties", logger=DEFAULT_LOGGER, data=request_body ) DEFAULT_LOGGER.log_info("Received response from property prediction request.") except Exception as e: DEFAULT_LOGGER.log_error(f"Failed to send property prediction request: {e}") return None if response.status_code == 200: try: response_data = response.json() DEFAULT_LOGGER.log_info("Property prediction successful.") return response_data except ValueError: DEFAULT_LOGGER.log_error("Failed to parse JSON response.") return None else: try: error_message = response.json().get("msg", "Unknown error occurred.") DEFAULT_LOGGER.log_error(f"Property prediction failed: {error_message}") except ValueError: DEFAULT_LOGGER.log_error("Failed to parse error message from response.") return None
Predicts chemical properties for a given SMILES string.
This function sends a request to predict various chemical properties including hERG, logD, logP, logS, ames test results, and cytochrome P450 interactions for a given chemical compound represented by its SMILES notation.
Args
smiles
:str
- A SMILES (Simplified Molecular Input Line Entry System) string representing the chemical compound.
Returns
Optional[Dict[str, Any]]
- A dictionary containing the predicted properties if successful, with property names as keys and their predicted values as values. Returns None if the prediction fails for any reason (network error, invalid response, etc.).
Example
>>> properties = predict_properties("CC(=O)OC1=CC=CC=C1C(=O)O") >>> if properties: ... print(properties["logP"])
Raises
No explicit raises, but handles various exceptions internally and returns None on failure.
Note
The function logs its progress and any errors through DEFAULT_LOGGER.
def protonate(smiles: str, pH: float = 7.4, filter_percentage: float = 1)
-
Expand source code
def protonate(smiles: str, pH: float=7.4, filter_percentage: float=1): """Predicts the protonation state of a molecule at a given pH. This function takes a SMILES string representation of a molecule and predicts its protonation state at the specified pH using a molecular properties client. Args: smiles (str): SMILES string representation of the input molecule pH (float, optional): The pH value at which to predict protonation. Defaults to 7.4 filter_percentage (float, optional): Filter threshold for protonation prediction. Defaults to 1.0 Returns: str or None: SMILES string of the protonated molecule if successful, None if failed Raises: Exception: If the protonation prediction request fails Example: >>> protonated_smiles = protonate("CC(=O)O", pH=7.4) """ from deeporigin.src.properties import MolecularPropertiesClient try: client = MolecularPropertiesClient() DEFAULT_LOGGER.log_info("Protonation prediction process started.") protonation_output = client.protonate( entry=[smiles], pH=pH, filter_percentage=filter_percentage, html_output=False )[0] smiles = protonation_output["protonation"]["smiles_list"][0] return smiles except Exception as e: DEFAULT_LOGGER.log_error(f"Failed to send property prediction request: {e}") return None
Predicts the protonation state of a molecule at a given pH. This function takes a SMILES string representation of a molecule and predicts its protonation state at the specified pH using a molecular properties client.
Args
smiles
:str
- SMILES string representation of the input molecule
pH
:float
, optional- The pH value at which to predict protonation. Defaults to 7.4
filter_percentage
:float
, optional- Filter threshold for protonation prediction. Defaults to 1.0
Returns
str
orNone
- SMILES string of the protonated molecule if successful, None if failed
Raises
Exception
- If the protonation prediction request fails
Example
>>> protonated_smiles = protonate("CC(=O)O", pH=7.4)