Skip to content

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

atom_types property

atom_types

available_for_docking class-attribute instance-attribute

available_for_docking: bool = field(
    init=False, default=True
)

block_content class-attribute instance-attribute

block_content: str | None = None

block_type class-attribute instance-attribute

block_type: str | None = None

coordinates property

coordinates

file_path class-attribute instance-attribute

file_path: str | None = None

hac class-attribute instance-attribute

hac: int = field(init=False, default=0)

identifier class-attribute instance-attribute

identifier: str | None = None

mol class-attribute instance-attribute

mol: Molecule | None = None

name class-attribute instance-attribute

name: str | None = None

properties class-attribute instance-attribute

properties: dict = field(default_factory=dict)

protonated_smiles class-attribute instance-attribute

protonated_smiles: str | None = field(
    init=False, default=None
)

save_to_file class-attribute instance-attribute

save_to_file: bool = False

seed class-attribute instance-attribute

seed: int | None = None

smiles class-attribute instance-attribute

smiles: str | None = None

xref_ins_code class-attribute instance-attribute

xref_ins_code: str | None = None

xref_protein class-attribute instance-attribute

xref_protein: str | None = None

xref_protein_chain_id class-attribute instance-attribute

xref_protein_chain_id: str | None = None

xref_residue_id class-attribute instance-attribute

xref_residue_id: str | None = 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.

draw

draw()

Draw the ligand molecule.

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.

minimize

minimize()

embed and optimize ligand in 3d space

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.

to_mol

to_mol(output_path: Optional[str] = None) -> str | Path

Write the ligand to a MOL file.

to_pdb

to_pdb(output_path: Optional[str] = None) -> str | Path

Write the ligand to a PDB file.

to_sdf

to_sdf(output_path: Optional[str] = None) -> str | Path

Write the ligand to an SDF file.

update_coordinates

update_coordinates(coords: ndarray)

update coordinates of the ligand structure

upload

upload()

Upload the entity to the remote server.

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.