deeporigin.drug_discovery.Ligand
¶
Bases: Entity
A class representing a ligand molecule in drug discovery workflows. The Ligand class provides functionality to create, manipulate, and analyze small molecules (ligands) in computational drug discovery. It supports various input formats and provides methods for property prediction, visualization, and file operations.
Attributes:
Name | Type | Description |
---|---|---|
identifier |
Optional[str]
|
Ligand identifier (e.g., PubChem ID) |
file_path |
Optional[str]
|
Path to the ligand file |
smiles |
Optional[str]
|
SMILES string representing the ligand |
block_type |
Optional[str]
|
Format of the block content ('mol', 'mol2', 'sdf', 'pdb') |
block_content |
Optional[str]
|
String containing the molecule data |
name |
Optional[str]
|
Optional name of the ligand |
seed |
Optional[int]
|
Random seed for coordinate generation |
xref_protein |
Optional[str]
|
Cross-reference to protein |
xref_ins_code |
Optional[str]
|
Cross-reference insertion code |
xref_residue_id |
Optional[str]
|
Cross-reference residue ID |
xref_protein_chain_id |
Optional[str]
|
Cross-reference protein chain ID |
save_to_file |
bool
|
Whether to save the ligand to file |
properties |
dict
|
Dictionary of ligand properties |
mol |
Optional[Molecule]
|
Direct Molecule object initialization |
Examples:
>>> # Create from SMILES
>>> ligand = Ligand.from_smiles("CCO", name="Ethanol")
>>> # Create from SDF file
>>> ligand = Ligand.from_sdf("ligand.sdf")
>>> # Get properties
>>> center = ligand.get_center()
>>> props = ligand.admet_properties()
>>> # Visualize
>>> ligand.visualize()
>>> # Save to file
>>> ligand.write_to_file("output.pdb")
Attributes¶
available_for_docking
class-attribute
instance-attribute
¶
available_for_docking: bool = field(
init=False, default=True
)
protonated_smiles
class-attribute
instance-attribute
¶
protonated_smiles: str | None = field(
init=False, default=None
)
Functions¶
admet_properties
¶
admet_properties(use_cache: bool = True) -> dict
Predict ADMET properties for the ligand using DO's molprops model.
convert_to_sdf
classmethod
¶
convert_to_sdf(block_content: str, block_type: str) -> str
Convert a ligand block content to SDF format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_content
|
str
|
The block content of the ligand. |
required |
block_type
|
str
|
The type of the block content. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The ligand block content in SDF format. |
from_block_content
classmethod
¶
from_block_content(
block_content: str,
block_type: str,
name: str = "",
save_to_file: bool = False,
**kwargs: Any
) -> Ligand
Create a Ligand instance from block content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_content
|
str
|
String containing the molecule data |
required |
block_type
|
str
|
Format of the block content ('mol', 'mol2', 'sdf', 'pdb') |
required |
name
|
str
|
Name of the ligand. Defaults to "". |
''
|
save_to_file
|
bool
|
Whether to save the ligand to file. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional arguments to pass to the constructor |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Ligand |
Ligand
|
A new Ligand instance |
from_identifier
classmethod
¶
from_identifier(
identifier: str,
name: Optional[str] = None,
save_to_file: bool = False,
**kwargs: Any
) -> Ligand
Create a Ligand instance from a chemical identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
identifier
|
str
|
Chemical identifier (e.g., common name, PubChem name, drug name) |
required |
name
|
str
|
Name of the ligand. If not provided, uses the identifier. Defaults to "". |
None
|
save_to_file
|
bool
|
Whether to save the ligand to file. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional arguments to pass to the constructor |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Ligand |
Ligand
|
A new Ligand instance initialized from the chemical identifier |
Raises:
Type | Description |
---|---|
DeepOriginException
|
If the identifier cannot be resolved to a valid molecule |
from_rdkit_mol
classmethod
¶
from_rdkit_mol(
mol: Mol,
name: str = "",
save_to_file: bool = False,
**kwargs: Any
)
Create a Ligand instance from an RDKit Mol object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
RDKit molecule object to convert to a Ligand |
required |
name
|
str
|
Name of the ligand. Defaults to "". |
''
|
save_to_file
|
bool
|
Whether to save the ligand to file. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional arguments to pass to the constructor |
{}
|
from_sdf
classmethod
¶
from_sdf(
file_path: str,
*,
sanitize: bool = True,
removeHs: bool = False
) -> Ligand
Create a single Ligand instance from an SDF file containing exactly one molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the SDF file. |
required |
sanitize
|
bool
|
Whether to sanitize molecules. Defaults to True. |
True
|
removeHs
|
bool
|
Whether to remove hydrogens. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Ligand |
Ligand
|
The Ligand instance created from the SDF file. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the file cannot be parsed correctly or contains more than one molecule. |
from_smiles
classmethod
¶
from_smiles(
smiles: str,
name: str = "",
save_to_file: bool = False,
**kwargs: Any
) -> Ligand
Create a Ligand instance from a SMILES string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles
|
str
|
SMILES string representing the ligand |
required |
name
|
str
|
Name of the ligand. Defaults to "". |
''
|
save_to_file
|
bool
|
Whether to save the ligand to file. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional arguments to pass to the constructor |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Ligand |
Ligand
|
A new Ligand instance |
Example
ligand = Ligand.from_smiles( ... smiles="CCO", # Ethanol ... name="Ethanol", ... save_to_file=False ... ) print(ligand.smiles) CCO
get_center
¶
get_center() -> Optional[list[float]]
Get the center of the ligand based on its coordinates.
Returns: - list: The center coordinates of the ligand. - None: If coordinates are not available.
get_property
¶
get_property(prop_name: str)
Get the value of a property for the ligand molecule.
Parameters: - prop_name (str): Name of the property to retrieve.
Returns: - The value of the property if it exists, otherwise None.
set_property
¶
set_property(prop_name: str, prop_value)
Set a property for the ligand molecule.
Parameters: - prop_name (str): Name of the property. - prop_value: Value of the property.
show
¶
show() -> str
Visualize the current state of the ligand molecule.
Returns: - str: HTML representation of the visualization.
Raises: - Exception: If visualization fails.
write_to_file
¶
write_to_file(
output_path: Optional[str] = None,
output_format: Literal["mol", "sdf", "pdb"] = "sdf",
)
Writes the ligand molecule to a file, including all properties.
Parameters: - output_path (str): Path where the ligand will be written. - output_format (Literal[".mol", ".sdf", ".pdb", "mol", "sdf", "pdb"]): Format to write the ligand in.
Raises: - ValueError: If the file extension is unsupported. - Exception: If writing to the file fails.