meeko.chemtempgen module#

meeko.chemtempgen.mol_contains_unexpected_element(mol, allowed_elements=[1, 5, 6, 7, 8, 9, 12, 14, 15, 16, 17, 20, 25, 26, 30, 35, 53])[source]#

Check if mol contains unexpected elements

Parameters:
  • mol (Chem.Mol) – Input molecule

  • allowed_elements (list[str]) – List of allowed elements (atomic numbers)

Returns:

True if mol contains unexpected elements, False otherwise

Return type:

bool

meeko.chemtempgen.get_atom_idx_by_names(mol, wanted_names={})[source]#

Get atom idx by atom names

Parameters:
  • mol (Chem.Mol) – Input molecule

  • wanted_names (set[str]) – Set of atom names to search for

Returns:

Set of atom indices that match the wanted names

Return type:

set[int]

meeko.chemtempgen.get_atom_idx_by_patterns(mol, allowed_smarts, wanted_smarts_loc=None, allow_multiple=False)[source]#

Get atom idx by patterns

Parameters:
  • mol (Chem.Mol) – Input molecule

  • allowed_smarts (str) – Allowed SMARTS pattern

  • wanted_smarts_loc (dict[str, set[int]]) – Dictionary mapping SMARTS patterns to sets of atom indices

  • allow_multiple (bool) – Flag to allow multiple matches

Returns:

Set of atom indices that match the wanted patterns

Return type:

set[int]

meeko.chemtempgen.embed(mol, allowed_smarts, leaving_names=None, leaving_smarts_loc=None, alsoHs=True)[source]#

Remove atoms from the molecule based the union of (a) leaving_names: list of atom IDs (names), and (b) leaving_smarts_loc: dict to map substructure SMARTS patterns with tuple of 0-based indicies for atoms to delete (restricted by allowed_smarts)

Parameters:
  • mol (Chem.Mol) – Input molecule

  • allowed_smarts (str) – Allowed SMARTS pattern

  • leaving_names (set[str]) – Set of atom names to remove

  • leaving_smarts_loc (dict[str, set[int]]) – Dictionary mapping SMARTS patterns to sets of atom indices

  • alsoHs (bool) – Flag to also remove H atoms bonded to the leaving atoms

Returns:

Modified molecule with specified atoms removed

Return type:

Chem.Mol

meeko.chemtempgen.cap(mol, allowed_smarts, capping_names=None, capping_smarts_loc=None, protonate=False)[source]#

Add hydrogens to atoms with implicit hydrogens based on the union of (a) capping_names: list of atom IDs (names), and (b) capping_smarts_loc: dict to map substructure SMARTS patterns with tuple of 0-based indicies for atoms.

Parameters:
  • mol (Chem.Mol) – Input molecule

  • allowed_smarts (str) – Allowed SMARTS pattern

  • capping_names (set[str]) – Set of atom names to cap

  • capping_smarts_loc (dict[str, set[int]]) – Dictionary mapping SMARTS patterns to sets of atom indices

  • protonate (bool) – Flag to add a proton to the atom’s formal charge

Returns:

Modified molecule with specified atoms capped

Return type:

Chem.Mol

meeko.chemtempgen.deprotonate(mol, acidic_proton_loc=None)[source]#

Remove acidic protons from the molecule based on acidic_proton_loc

Parameters:
  • mol (Chem.Mol) – Input molecule

  • acidic_proton_loc (dict[str, int]) – Dictionary mapping SMARTS patterns to indices of acidic protons to remove keys: smarts pattern of a fragment value: the index (order in smarts) of the leaving proton

Returns:

Modified molecule with specified protons removed

Return type:

Chem.Mol

meeko.chemtempgen.recharge(rwmol)[source]#

Recharges the molecule by adjusting the formal charges of metal complexes and their coordinated atoms

Parameters:

rwmol (Chem.RWMol) – Input molecule

Returns:

Modified molecule with adjusted formal charges

Return type:

Chem.RWMol

meeko.chemtempgen.get_smiles_with_atom_names(mol)[source]#

Generate SMILES with atom names in the order of SMILES output

Parameters:

mol (Chem.Mol) – Input molecule

Returns:

Tuple containing the SMILES string and a list of atom names in the order of SMILES output

Return type:

tuple[str, list[str]]

meeko.chemtempgen.get_pretty_smiles(smi)[source]#

Convert Smiles with allHsExplicit to pretty Smiles to be put on chem templates

Parameters:

smi (str) – Input SMILES string

Returns:

Pretty SMILES string with implicit Hs removed

Return type:

str

class meeko.chemtempgen.ChemicalComponent_LoggingControler[source]#

Bases: object

Context manager to control logging level for RDKit and Meeko during the creation of chemical components.

class meeko.chemtempgen.ChemicalComponent(rdkit_mol, resname, smiles_exh, atom_name)[source]#

Bases: object

Class representing a chemical component with its properties and methods for manipulation.

rdkit_mol#

The RDKit molecule object representing the chemical component.

Type:

Chem.Mol

resname#

The residue name of the chemical component.

Type:

str

parent#

The name of its parent chemical component (default is the same as resname).

Type:

str

smiles_exh#

The SMILES representation of the chemical component with explicit hydrogens.

Type:

str

atom_name#

A list of atom names in the order of SMILES output.

Type:

list[str]

A dictionary mapping atom indices to link labels (default is empty).

Type:

dict

classmethod from_cif(source_cif, resname)[source]#

Create ChemicalComponent from a chemical component dict file and a searchable residue name in file.

Parameters:
  • source_cif (str) – Path to the CIF file containing the chemical component data.

  • resname (str) – The residue name to search for in the CIF file.

Returns:

An instance of the ChemicalComponent class.

Return type:

ChemicalComponent

make_canonical(acidic_proton_loc)[source]#

Deprotonate acidic groups til the canonical (most deprotonated) state.

Parameters:

acidic_proton_loc (dict[str, int]) – Dictionary mapping SMARTS patterns to indices of acidic protons to remove keys: smarts pattern of a fragment value: the index (order in smarts) of the leaving proton

Returns:

The modified ChemicalComponent instance with the canonicalized molecule.

Return type:

ChemicalComponent

make_embedded(allowed_smarts, leaving_names=None, leaving_smarts_loc=None)[source]#

Remove leaving atoms from the molecule by atom names and/or patterns.

Parameters:
  • allowed_smarts (str) – Allowed SMARTS pattern

  • leaving_names (set[str]) – Set of atom names to remove

  • leaving_smarts_loc (dict[str, set[int]]) – Dictionary mapping SMARTS patterns to sets of atom indices

Returns:

The modified ChemicalComponent instance with the embedded molecule.

Return type:

ChemicalComponent

make_capped(allowed_smarts, capping_names=None, capping_smarts_loc=None, protonate=None)[source]#

Build and name explicit hydrogens for atoms with implicit Hs by atom names and/or patterns.

Parameters:
  • allowed_smarts (str) – Allowed SMARTS pattern

  • capping_names (set[str]) – Set of atom names to cap

  • capping_smarts_loc (dict[str, set[int]]) – Dictionary mapping SMARTS patterns to sets of atom indices

  • protonate (bool) – Flag to add a proton to the atom’s formal charge

Returns:

The modified ChemicalComponent instance with the capped molecule.

Return type:

ChemicalComponent

make_pretty_smiles()[source]#

Build and name explicit hydrogens for atoms with implicit Hs by atom names and/or patterns.

Map patterns to link labels based on a given mapping.

Parameters:

pattern_to_label_mapping (dict[str, str]) – Dictionary mapping patterns to link labels keys: pattern to search for in the molecule values: label to assign to the atom matching the pattern

Map atom names to link labels based on a given mapping.

Parameters:

name_to_label_mapping (dict[str, str]) – Dictionary mapping atom names to link labels keys: atom names to search for in the molecule values: label to assign to the atom matching the name

Returns:

The modified ChemicalComponent instance with updated link labels.

Return type:

ChemicalComponent

ResidueTemplate_check()[source]#

Check if the chemical component is a valid residue template.

This is the same ResidueTemplate.check from meeko.polymer

Return type:

bool

meeko.chemtempgen.export_chem_templates_to_json(cc_list, json_fname='')[source]#

Export list of chem templates to json

Parameters:
  • cc_list (list[ChemicalComponent]) – List of ChemicalComponent instances to export

  • json_fname (str) – Filename for the output JSON file (default is empty string, which prints to console)

Returns:

JSON string representation of the chemical templates

Return type:

str

meeko.chemtempgen.fetch_from_pdb(resname, max_retries=5, backoff_factor=2)[source]#

Fetch a CIF file from the RCSB PDB website for a given residue name.

Parameters:
  • resname (str) – The residue name to fetch from the PDB.

  • max_retries (int) – Maximum number of retries for downloading the file (default is 5).

  • backoff_factor (int) – Factor to increase the wait time between retries (default is 2).

Returns:

Path to the downloaded CIF file.

Return type:

str

Raises:

RuntimeError – If the ligand is not available from rcsb.org or if the maximum number of retries is reached.

meeko.chemtempgen.build_noncovalent_CC(basename)[source]#

Build a noncovalent chemical component from a CIF file.

Parameters:

basename (str) – The name of the chemical component to build.

Returns:

The constructed ChemicalComponent instance.

Return type:

ChemicalComponent

meeko.chemtempgen.add_variants(cc_orig, cc_list=[], embed_allowed_smarts=None, cap_allowed_smarts=None, cap_protonate=False, pattern_to_label_mapping_standard=dict[str, str], variant_dict=dict[str, tuple])[source]#

Add variants to a chemical component based on the provided variant dictionary.

Parameters:
  • cc_orig (ChemicalComponent) – The original chemical component to which variants will be added.

  • cc_list (list[ChemicalComponent]) – List of existing chemical components to check for redundancy (default is empty list).

  • embed_allowed_smarts (str) – Allowed SMARTS pattern for embedding (default is None).

  • cap_allowed_smarts (str) – Allowed SMARTS pattern for capping (default is None).

  • cap_protonate (bool) – Flag to add a proton to the atom’s formal charge (default is False).

  • pattern_to_label_mapping_standard (dict[str, str]) – Dictionary mapping patterns to link labels (default is empty dictionary).

  • variant_dict (dict[str, tuple]) – Dictionary mapping suffixes to tuples of embedding and capping SMARTS patterns. keys: suffixes for the variants values: tuples containing the embedding and capping SMARTS patterns (embedding smarts, capping smarts)

Returns:

List of ChemicalComponent instances with the added variants.

Return type:

list[ChemicalComponent]

class meeko.chemtempgen.AA_recipe[source]#

Bases: object

Class representing the recipe for amino acids

embed_allowed_smarts = '[NX3]([H])([H])[CX4][CX3](=O)[O]'#
cap_allowed_smarts = '[NX3][CX4][CX3](=O)'#
cap_protonate = True#
pattern_to_label_mapping_standard = {'[CX3h1]': 'C-term', '[NX3h1]': 'N-term'}#
variant_dict = {'': ({'[NX3]([H])([H])[CX4][CX3](=O)[O]': {1, 6}}, None), '_C': ({'[NX3]([H])([H])[CX4][CX3](=O)[O]': {1}}, None), '_N': ({'[NX3]([H])([H])[CX4][CX3](=O)[O]': {6}}, {'[NX3][CX4][CX3](=O)': {0}})}#
class meeko.chemtempgen.NA_recipe[source]#

Bases: object

Class representing the recipe for nucleic acids

embed_allowed_smarts = '[O][PX4](=O)([O])[OX2][CX4][CX4]1[OX2][CX4][CX4][CX4]1[OX2][H]'#
cap_allowed_smarts = '[OX2][CX4][CX4]1[OX2][CX4][CX4][CX4]1[OX2]'#
cap_protonate = False#
pattern_to_label_mapping_standard = {'[O+0X2h1]': '3-prime', '[PX4h1]': '5-prime'}#
variant_dict = {'_': ({'[CX4]1[OX2][CX4][CX4][CX4]1[OX2][H]': {6}, '[O][PX4](=O)([O])[OX2][CX4]': {0}}, None), '_3': ({'[O][PX4](=O)([O])[OX2][CX4]': {0}}, None), '_5': ({'[CX4]1[OX2][CX4][CX4][CX4]1[OX2][H]': {6}, '[O][PX4](=O)([O])[OX2][CX4]': {0, 1, 2, 3}}, {'[OX2][CX4][CX4]1[OX2][CX4][CX4][CX4]1[OX2]': {0}}), '_5p': ({'[CX4]1[OX2][CX4][CX4][CX4]1[OX2][H]': {6}}, None)}#
meeko.chemtempgen.build_linked_CCs(basename, embed_allowed_smarts=None, cap_allowed_smarts=None, cap_protonate=False, pattern_to_label_mapping_standard=dict[str, str], variant_dict=dict[str, tuple])[source]#

Build a linked chemical component from a CIF file.

Parameters:
  • basename (str) – The name of the chemical component to build.

  • embed_allowed_smarts (str) – Allowed SMARTS pattern for embedding (default is None).

  • cap_allowed_smarts (str) – Allowed SMARTS pattern for capping (default is None).

  • cap_protonate (bool) – Flag to add a proton to the atom’s formal charge (default is False).

  • pattern_to_label_mapping_standard (dict[str, str]) – Dictionary mapping patterns to link labels (default is empty dictionary).

  • variant_dict (dict[str, tuple]) – Dictionary mapping suffixes to tuples of embedding and capping SMARTS patterns. keys: suffixes for the variants values: tuples containing the embedding and capping SMARTS patterns (embedding smarts, capping smarts)

Returns:

List of ChemicalComponent instances with the added variants.

Return type:

list[ChemicalComponent]