geom.functions.rdkit_module =========================== .. py:module:: geom.functions.rdkit_module Functions --------- .. autoapisummary:: geom.functions.rdkit_module.select_case geom.functions.rdkit_module.visualize geom.functions.rdkit_module.file_conversion geom.functions.rdkit_module.force_field_optimization geom.functions.rdkit_module.generate_conformers geom.functions.rdkit_module.conformers_force_field_optimization geom.functions.rdkit_module.save_rdkit_file geom.functions.rdkit_module.save_rdkit_conformers geom.functions.rdkit_module.embed_3d geom.functions.rdkit_module.load_rdkit_file geom.functions.rdkit_module.keep_first_conformer geom.functions.rdkit_module.plot_2d_molecule geom.functions.rdkit_module.plot_3d_molecule geom.functions.rdkit_module.xyz_to_pdb geom.functions.rdkit_module.match_substructure geom.functions.rdkit_module._merge_highlights geom.functions.rdkit_module.find_aromatic_highlights geom.functions.rdkit_module._draw_gnuplot_legend_pillow Module Contents --------------- .. py:function:: select_case(inp) Selects the appropriate RDKit-related function based on user input. :param inp: An instance of the input class containing user-defined parameters. :type inp: input_class :returns: Executes the corresponding geometry generation function. :rtype: None .. py:function:: visualize(inp) Visualizes a molecule in 2D or 3D using RDKit. :param inp: Input parameters containing visualization options. :type inp: input_class :returns: Displays the molecule visualization. :rtype: None .. py:function:: file_conversion(inp) Converts a molecular file from one format to another using RDKit. :param inp: Input parameters containing file conversion options. :type inp: input_class :returns: Saves the converted file to the results folder. :rtype: None .. py:function:: force_field_optimization(inp) Performs force field optimization on a molecule using RDKit. :param inp: Input parameters containing optimization options. :type inp: input_class :returns: Saves the optimized geometry to the results folder. :rtype: None .. py:function:: generate_conformers(inp) Generates multiple conformers for a molecule using RDKit's ETKDG method. :param inp: Input parameters containing conformer generation options. :type inp: input_class :returns: Saves the generated conformers to the results folder. :rtype: None .. py:function:: conformers_force_field_optimization(mol, inp, retry_factor=2) Optimizes multiple conformers using force field methods with retry for non-converged structures. :param mol: RDKit molecule with multiple conformers. :type mol: Chem.Mol :param inp: Input parameters containing optimization options. :type inp: input_class :param retry_factor: Factor to multiply max iterations for non-converged conformers. :type retry_factor: int :returns: Updates the molecule with optimized conformers and metadata. :rtype: None .. py:function:: save_rdkit_file(mol, out_file) Saves an RDKit molecule to a file with the specified extension. :param mol: RDKit molecule to save. :type mol: Chem.Mol :param out_file: Output file path. :type out_file: str :returns: Saves the molecule to the specified file format. :rtype: None .. py:function:: save_rdkit_conformers(mol, inp, out_dir='results_geom', max_digits=7) Saves each conformer of a molecule to separate files with appropriate naming. :param mol: RDKit molecule with multiple conformers. :type mol: Chem.Mol :param inp: Input parameters containing output options. :type inp: input_class :param out_dir: Output directory for conformer files. :type out_dir: str :param max_digits: Maximum digits for conformer numbering. :type max_digits: int :returns: Saves each conformer to separate files. :rtype: None .. py:function:: embed_3d(mol) Ensures the given RDKit molecule has hydrogens and a 3D conformer. :param mol: Input RDKit molecule. :type mol: Chem.Mol :returns: Molecule with hydrogens added and 3D conformer embedded. :rtype: Chem.Mol .. py:function:: load_rdkit_file(inp) Load a single RDKit Mol and keep only the first conformer. Supports .smi, .sdf, .mol, .pdb, and .xyz (converted to PDB). :param inp: Object with: - ``rdkit_mol_file`` (str): Path to the input file. - ``remove_H`` (bool): Whether to remove explicit hydrogens. :returns: Loaded molecule (trimmed to a single conformer if needed), or triggers an error if loading fails. :rtype: Chem.Mol | None .. py:function:: keep_first_conformer(mol) Return a copy of the molecule keeping only conformer 0 (if multiple exist). :param mol: RDKit molecule. :returns: The same molecule if it has ≤1 conformer; otherwise a copy containing only conformer 0. .. py:function:: plot_2d_molecule(mol, inp, size=(800, 700)) Computes 2D coordinates and renders a molecule as an image. :param mol: RDKit molecule to visualize. :type mol: Chem.Mol :param inp: Input parameters containing visualization options. :type inp: input_class :param size: Image size in pixels (width, height). :type size: tuple :returns: Displays the 2D molecular visualization. :rtype: None .. py:function:: plot_3d_molecule(mol, style='ballstick', width=1600, height=900, background='1xFFFFFF') Creates an interactive 3D visualization of a molecule using py3Dmol. :param mol: RDKit molecule to visualize. :type mol: Chem.Mol :param style: Visualization style for the molecule. :type style: str :param width: Width of the visualization window in pixels. :type width: int :param height: Height of the visualization window in pixels. :type height: int :param background: Background color for the visualization. :type background: str :returns: Opens an interactive 3D visualization in the web browser. :rtype: None .. py:function:: xyz_to_pdb(inp) Converts an XYZ file to PDB format using RDKit's bond determination. :param inp: Input parameters containing XYZ file path. :type inp: input_class :returns: Updated input object with PDB file path. :rtype: input_class .. py:function:: match_substructure(mol, pattern) Finds and highlights substructure matches in a molecule. :param mol: Target molecule to search in. :type mol: Chem.Mol :param pattern: SMARTS or SMILES pattern to match. :type pattern: str :returns: (highlightAtoms, highlightBonds, highlightAtomColors, highlightBondColors) :rtype: tuple .. py:function:: _merge_highlights(a_atoms, a_bonds, a_atomCols, a_bondCols, b_atoms, b_bonds, b_atomCols, b_bondCols) Merges two highlight sets for molecular visualization. :param a_*: First set of highlight information. :param b_*: Second set of highlight information. :returns: Merged (atoms, bonds, atomColors, bondColors) :rtype: tuple .. py:function:: find_aromatic_highlights(m) Finds and highlights aromatic atoms and bonds in a molecule. :param m: Input molecule. :type m: Chem.Mol :returns: (aromatic_atoms, aromatic_bonds, atom_colors, bond_colors) :rtype: tuple .. py:function:: _draw_gnuplot_legend_pillow(img, entries, corner='bottom_right', box_alpha=180, pad=14, swatch_size=(28, 28), row_gap=12, font_name_candidates=('Times New Roman', 'Times.ttf', 'Times', 'DejaVuSerif.ttf')) Draws a gnuplot-like legend onto a PIL image. :param img: Input image to draw legend on. :type img: PIL.Image :param entries: List of (label, rgb_tuple) pairs. :type entries: list :param corner: Corner position for the legend. :type corner: str :param box_alpha: Alpha value for legend background. :type box_alpha: int :param pad: Padding around legend content. :type pad: int :param swatch_size: Size of color swatches. :type swatch_size: tuple :param row_gap: Gap between rows in the legend. :type row_gap: int :param font_name_candidates: Font names to try. :type font_name_candidates: tuple :returns: Image with legend added. :rtype: PIL.Image