Scaffold
API¶
rdworks.scaffold.scaffold
¶
This module provides functions to break a molecule into scaffolds.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Functions:¶
BRICS_fragment_indices(rdmol)
¶
Returns BRICS fragment/scaffold atom indices.
Parameters:
-
rdmol(Mol) –input molecule.
Returns:
-
list[list[int]]–list[list[int]]: fragment/scaffold atom indices.
BRICS_fragmented(rdmol, min_atoms=None, max_atoms=None)
¶
Perform BRICKS decomposition and returns fragmented molecules.
Parameters:
-
rdmol(Mol) –input molecule.
-
min_atoms(int, default:None) –min number of atoms for a fragment. Defaults to None.
-
max_atoms(int, default:None) –max number of atoms for a fragment. Defaults to None.
Returns:
-
list[Mol]–list[Chem.Mol]: a list of fragmented molecules.
breakup(parents, maxChildren=None, verbose=False)
¶
Breaks up parents recursively and return a list of scaffolds.
Examples:
>>> [(rdmol, 'O=C(CCCc1ccccc1)N1CCn2cnnc2C1', 3, ((6, 7, 8, 9, 10, 5), (12, 13, 14, 18, 19, 11), (15, 14, 18, 17, 16)), ()), ..]
Parameters:
-
parents(Any) –Chem.Mol object at first but changes during recursive calls
-
maxChildren(int, default:None) –max number of children maxChildren = None --> scaffold network methods maxChildren = 1 --> scaffold tree methods
-
verbose(bool, default:False) –print out children info
Returns:
-
list–[(rdmol, smiles, nr, rings_indices, other_info), ... ]
connected_components(rdmol, cut_bonds)
¶
Returns atom indices of connected components after cutting the given bonds.
The atoms at both ends of a cut bond stay in the component they are connected to, so every atom belongs to exactly one component.
Parameters:
-
rdmol(Mol) –input molecule.
-
cut_bonds(list[tuple[int, int]]) –bonds (tuple of two indexes) to cut.
Returns:
-
list[list[int]]–list[list[int]]: atom indices of each connected component.
get_attached_linkers(mol)
¶
Get linkers (connected non-ring atoms) between rings.
Parameters:
-
mol(Mol) –input molecule.
Returns:
-
Any(Any) –linkers.
remove_exocyclic(rdmol)
¶
Removes exocyclic chains or all terminal side chains.
It is equivalent to the MurckoScaffold.GetScaffoldForMol(mol).
Args:
rdmol (Chem.Mol): input molecule.
Returns:
-
Mol–Chem.Mol: output molecule.
rigid_fragment_indices(rdmol)
¶
Breaks a molecule at each rotatable bond and returns atom indices of fragments. Args: rdmol (Chem.Mol) : input molecule
Returns:
-
list[list[int]]–list of list (atom indices)
scaffold_network(rdmol)
¶
Returns scaffold network.
Parameters:
-
rdmol(Mol) –input molecule.
Returns:
-
list[Mol]–list[Chem.Mol]: scaffold network.
scaffold_tree(rdmol)
¶
Returns scaffold tree.
Parameters:
-
rdmol(Mol) –input molecule.
Returns:
-
list[Mol]–list[Chem.Mol]: scaffold tree.
rdworks.scaffold.matchedseries
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
MatchedSeries
¶
Attributes¶
core_max = core_max
instance-attribute
¶
core_min = core_min
instance-attribute
¶
mollibr = copy.deepcopy(mollibr)
instance-attribute
¶
series = self.libr_to_series()
instance-attribute
¶
size_min = size_min
instance-attribute
¶
sort_props = sort_props
instance-attribute
¶
template_coords2D = None
instance-attribute
¶
template_pattern = None
instance-attribute
¶
Methods:¶
count()
¶
Returns the count of series.
Returns:
-
int(int) –count of series.
depict(smiles)
¶
Draws a molecule according to self.template in a consistent way.
Parameters:
-
smiles(str) –input molecule.
Returns:
-
Mol–Chem.Mol: 2D coordinated Chem.Mol for depiction.
libr_to_series()
¶
Returns a list of molecular series.
Raises:
-
RuntimeError–if a molecular cut cannot be defined.
Returns:
-
List[Tuple]–List[Tuple]: [ (scaffold_SMILES, [(r-group_SMILES, rdworks.Mol, *sort_props_values), ...,]), ..., ]
report(workdir=pathlib.Path('.'), prefix='mmseries', num_columns=5, rgroup_width=200, rgroup_height=200, rgroup_max=None, scaffold_width=300, scaffold_height=300)
¶
Writes individual series and an overview of series as HTML files.
Parameters:
-
workdir(PathLike, default:Path('.')) –working directory. Defaults to pathlib.Path(".").
-
prefix(str, default:'mmseries') –prefix of output files. Defaults to "mmseries".
-
num_columns(int, default:5) –number of molecules per row. Defaults to 5.
-
rgroup_width(int, default:200) –width. Defaults to 200.
-
rgroup_height(int, default:200) –height. Defaults to 200.
-
rgroup_max(int, default:None) –max number of R-group molecules. Defaults to None.
-
scaffold_width(int, default:300) –width. Defaults to 300.
-
scaffold_height(int, default:300) –height. Defaults to 300.
template(SMARTS, rdmol)
¶
Sets drawing layout template.
Parameters:
-
SMARTS(str) –SMARTS for template pattern.
-
rdmol(Mol) –template molecule.
Functions:¶
calculate_bond_length(mol, atom1_idx, atom2_idx)
¶
Calculate the 2D distance between two bonded atoms.
Parameters:
-
mol(Mol) –RDKit molecule
-
atom1_idx(int) –Index of first atom
-
atom2_idx(int) –Index of second atom
Returns:
-
float–Bond length in 2D coordinates
create_uniform_grid_image(molecules, legends=None, mols_per_row=4, sub_img_size=(300, 300), target_bond_length=None, reference_bond_type='C-C')
¶
Create a grid image of molecules with uniform scaling.
Parameters:
-
molecules(list[Mol]) –List of RDKit molecules
-
legends(list[str] | None, default:None) –Optional list of molecule names/labels
-
mols_per_row(int, default:4) –Number of molecules per row
-
sub_img_size(tuple[int, int], default:(300, 300)) –Size of each molecule image
-
target_bond_length(float | None, default:None) –Target bond length for scaling
-
reference_bond_type(str, default:'C-C') –Bond type to use as reference
Returns:
-
Image–PIL Image object
get_attachment_orientation(mol, dummy_atom_idx=None)
¶
Get the orientation of attachment points (dummy atoms) in a molecule.
Parameters:
-
mol(Mol) –RDKit molecule object
-
dummy_atom_idx(int | None, default:None) –Index of specific dummy atom (if None, finds all dummy atoms)
Returns:
-
dict–Dictionary with dummy atom indices as keys and orientation info as values
get_average_bond_length(mol, bond_type='C-C')
¶
Calculate the average bond length for a specific bond type in a molecule.
Parameters:
-
mol(Mol) –RDKit molecule
-
bond_type(str, default:'C-C') –Type of bond to measure (e.g., "C-C", "C-N", "any")
Returns:
-
float–Average bond length
orient_rgroup_to_attachment(rgroup_mol, scaffold_orientations)
¶
Orient an R-group molecule to match the attachment point orientation of a scaffold.
Parameters:
-
rgroup_mol(Mol) –R-group molecule with dummy atom
-
scaffold_orientations(dict) –orientations of the scaffold attachment points, as returned by
get_attachment_orientation()(dummy atom index -> orientation info)
Returns:
-
Mol–Oriented R-group molecule
scale_molecule_coordinates(mol, target_bond_length, reference_bond_type='any')
¶
Scale molecule coordinates to achieve a target bond length.
Parameters:
-
mol(Mol) –RDKit molecule to scale
-
target_bond_length(float) –Desired bond length
-
reference_bond_type(str, default:'any') –Bond type to use as reference for scaling
Returns:
-
Mol–New molecule with scaled coordinates
standardize_rgroup_scales(molecules, target_bond_length=None, reference_bond_type='C-C')
¶
Standardize the scale of multiple R-group molecules to have identical bond lengths.
Parameters:
-
molecules(list[Mol]) –List of RDKit molecules
-
target_bond_length(float | None, default:None) –Target bond length (if None, uses average across all molecules)
-
reference_bond_type(str, default:'C-C') –Bond type to use as reference
Returns:
-
list[Mol]–List of molecules with standardized scales
rdworks.scaffold.rgroup
¶
This module provides functions to create molecules from core and R-groups.
Attributes:
-
most_common(List[str]) –a list of the most common R-groups, lazily loaded from data/Rgroups.json.
-
most_common_in_NP(List[str]) –a list of the most common R-groups in natural products, lazily loaded from data/Rgroups.json.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
connect_core_and_chains(combi_smiles)
¶
Connects scaffold core and chains(R-groups).
combi_smiles has [expr:n] format where expr is an expression of atom mapping
and n is the atom map number.
It is modified from the Patrick Walters' work,
Re: [Rdkit-discuss] reassembling a molecule from R-groups.
Examples:
>>> combi_smiles = "CN(C)CC(Br)c1cc([*:2])c([*:1])cn1.[H]C([H])([H])[*:1].[H][*:2]"
>>> m = connect_core_and_chains(combi_smiles)
Parameters:
-
combi_smiles(str) –concatenated SMILES containing core followed by chains.
Returns:
-
Mol | None–Union[Mol, None]: connected rdworks.Mol object.
expand_rgroup(core, r, prefix='RGX', start=1, **kwargs)
¶
Expands or enumerates the core with R groups.
core SMILES has [#0:n] where n is the attachment index. All attachments are enumerated.
Examples:
>>> core = "[#0:1]C1C([#0:4])C([#0:3])CN2[C@@H]([C@H](C3=CC=C(C#CC4=CC=CC=C4)C=C3)[C@]2([H])CN1C(NC5=CC=C(C=C5)OC)=O)[#0:2]"
>>> V = "[*]C#N.[*]C(O)=O.[*]CO.[*]C(NC)=O.[*]CNC(C)=O.[*]CC=C.[*][H]".split(".")
>>> W = "[*][H].[*]COC".split(".")
>>> X = "[*][H].[*]CC(F)(F)F.[*]OCCOC".split(".")
>>> Y = "[*][H].[*]O.[*]OC".split(".")
>>> output = expand_rgroup(core=core, r={1:V, 2:W, 3:X, 4:Y})
Parameters:
-
core(str) –SMILES for the core.
-
r(Dict[int, List[str]]) –dictionary of {atom mapping number: list of SMILES for R groups}.
-
prefix(str, default:'RGX') –name prefix of generated molecules. Defaults to 'RGX'.
-
start(int, default:1) –start number for serial numbers. Defaults to 1.
Returns:
-
MolLibr(MolLibr) –a library of generated molecules.
fragmented(rdmol, min_atoms=5, max_atoms=17)
¶
BRICS decompose and returns fragments