geom.functions.rdkit_module

Functions

select_case(inp)

Selects the appropriate RDKit-related function based on user input.

visualize(inp)

Visualizes a molecule in 2D or 3D using RDKit.

file_conversion(inp)

Converts a molecular file from one format to another using RDKit.

force_field_optimization(inp)

Performs force field optimization on a molecule using RDKit.

generate_conformers(inp)

Generates multiple conformers for a molecule using RDKit's ETKDG method.

conformers_force_field_optimization(mol, inp[, ...])

Optimizes multiple conformers using force field methods with retry for non-converged structures.

save_rdkit_file(mol, out_file)

Saves an RDKit molecule to a file with the specified extension.

save_rdkit_conformers(mol, inp[, out_dir, max_digits])

Saves each conformer of a molecule to separate files with appropriate naming.

embed_3d(mol)

Ensures the given RDKit molecule has hydrogens and a 3D conformer.

load_rdkit_file(inp)

Load a single RDKit Mol and keep only the first conformer.

keep_first_conformer(mol)

Return a copy of the molecule keeping only conformer 0 (if multiple exist).

plot_2d_molecule(mol, inp[, size])

Computes 2D coordinates and renders a molecule as an image.

plot_3d_molecule(mol[, style, width, height, background])

Creates an interactive 3D visualization of a molecule using py3Dmol.

xyz_to_pdb(inp)

Converts an XYZ file to PDB format using RDKit's bond determination.

match_substructure(mol, pattern)

Finds and highlights substructure matches in a molecule.

_merge_highlights(a_atoms, a_bonds, a_atomCols, ...)

Merges two highlight sets for molecular visualization.

find_aromatic_highlights(m)

Finds and highlights aromatic atoms and bonds in a molecule.

_draw_gnuplot_legend_pillow(img, entries[, corner, ...])

Draws a gnuplot-like legend onto a PIL image.

Module Contents

geom.functions.rdkit_module.select_case(inp)[source]

Selects the appropriate RDKit-related function based on user input.

Parameters:

inp (input_class) – An instance of the input class containing user-defined parameters.

Returns:

Executes the corresponding geometry generation function.

Return type:

None

geom.functions.rdkit_module.visualize(inp)[source]

Visualizes a molecule in 2D or 3D using RDKit.

Parameters:

inp (input_class) – Input parameters containing visualization options.

Returns:

Displays the molecule visualization.

Return type:

None

geom.functions.rdkit_module.file_conversion(inp)[source]

Converts a molecular file from one format to another using RDKit.

Parameters:

inp (input_class) – Input parameters containing file conversion options.

Returns:

Saves the converted file to the results folder.

Return type:

None

geom.functions.rdkit_module.force_field_optimization(inp)[source]

Performs force field optimization on a molecule using RDKit.

Parameters:

inp (input_class) – Input parameters containing optimization options.

Returns:

Saves the optimized geometry to the results folder.

Return type:

None

geom.functions.rdkit_module.generate_conformers(inp)[source]

Generates multiple conformers for a molecule using RDKit’s ETKDG method.

Parameters:

inp (input_class) – Input parameters containing conformer generation options.

Returns:

Saves the generated conformers to the results folder.

Return type:

None

geom.functions.rdkit_module.conformers_force_field_optimization(mol, inp, retry_factor=2)[source]

Optimizes multiple conformers using force field methods with retry for non-converged structures.

Parameters:
  • mol (Chem.Mol) – RDKit molecule with multiple conformers.

  • inp (input_class) – Input parameters containing optimization options.

  • retry_factor (int) – Factor to multiply max iterations for non-converged conformers.

Returns:

Updates the molecule with optimized conformers and metadata.

Return type:

None

geom.functions.rdkit_module.save_rdkit_file(mol, out_file)[source]

Saves an RDKit molecule to a file with the specified extension.

Parameters:
  • mol (Chem.Mol) – RDKit molecule to save.

  • out_file (str) – Output file path.

Returns:

Saves the molecule to the specified file format.

Return type:

None

geom.functions.rdkit_module.save_rdkit_conformers(mol, inp, out_dir='results_geom', max_digits=7)[source]

Saves each conformer of a molecule to separate files with appropriate naming.

Parameters:
  • mol (Chem.Mol) – RDKit molecule with multiple conformers.

  • inp (input_class) – Input parameters containing output options.

  • out_dir (str) – Output directory for conformer files.

  • max_digits (int) – Maximum digits for conformer numbering.

Returns:

Saves each conformer to separate files.

Return type:

None

geom.functions.rdkit_module.embed_3d(mol)[source]

Ensures the given RDKit molecule has hydrogens and a 3D conformer.

Parameters:

mol (Chem.Mol) – Input RDKit molecule.

Returns:

Molecule with hydrogens added and 3D conformer embedded.

Return type:

Chem.Mol

geom.functions.rdkit_module.load_rdkit_file(inp)[source]

Load a single RDKit Mol and keep only the first conformer.

Supports .smi, .sdf, .mol, .pdb, and .xyz (converted to PDB).

Parameters:

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.

Return type:

Chem.Mol | None

geom.functions.rdkit_module.keep_first_conformer(mol)[source]

Return a copy of the molecule keeping only conformer 0 (if multiple exist).

Parameters:

mol – RDKit molecule.

Returns:

The same molecule if it has ≤1 conformer; otherwise a copy containing only conformer 0.

geom.functions.rdkit_module.plot_2d_molecule(mol, inp, size=(800, 700))[source]

Computes 2D coordinates and renders a molecule as an image.

Parameters:
  • mol (Chem.Mol) – RDKit molecule to visualize.

  • inp (input_class) – Input parameters containing visualization options.

  • size (tuple) – Image size in pixels (width, height).

Returns:

Displays the 2D molecular visualization.

Return type:

None

geom.functions.rdkit_module.plot_3d_molecule(mol, style='ballstick', width=1600, height=900, background='1xFFFFFF')[source]

Creates an interactive 3D visualization of a molecule using py3Dmol.

Parameters:
  • mol (Chem.Mol) – RDKit molecule to visualize.

  • style (str) – Visualization style for the molecule.

  • width (int) – Width of the visualization window in pixels.

  • height (int) – Height of the visualization window in pixels.

  • background (str) – Background color for the visualization.

Returns:

Opens an interactive 3D visualization in the web browser.

Return type:

None

geom.functions.rdkit_module.xyz_to_pdb(inp)[source]

Converts an XYZ file to PDB format using RDKit’s bond determination.

Parameters:

inp (input_class) – Input parameters containing XYZ file path.

Returns:

Updated input object with PDB file path.

Return type:

input_class

geom.functions.rdkit_module.match_substructure(mol, pattern)[source]

Finds and highlights substructure matches in a molecule.

Parameters:
  • mol (Chem.Mol) – Target molecule to search in.

  • pattern (str) – SMARTS or SMILES pattern to match.

Returns:

(highlightAtoms, highlightBonds, highlightAtomColors, highlightBondColors)

Return type:

tuple

geom.functions.rdkit_module._merge_highlights(a_atoms, a_bonds, a_atomCols, a_bondCols, b_atoms, b_bonds, b_atomCols, b_bondCols)[source]

Merges two highlight sets for molecular visualization.

Parameters:
  • a_* – First set of highlight information.

  • b_* – Second set of highlight information.

Returns:

Merged (atoms, bonds, atomColors, bondColors)

Return type:

tuple

geom.functions.rdkit_module.find_aromatic_highlights(m)[source]

Finds and highlights aromatic atoms and bonds in a molecule.

Parameters:

m (Chem.Mol) – Input molecule.

Returns:

(aromatic_atoms, aromatic_bonds, atom_colors, bond_colors)

Return type:

tuple

geom.functions.rdkit_module._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'))[source]

Draws a gnuplot-like legend onto a PIL image.

Parameters:
  • img (PIL.Image) – Input image to draw legend on.

  • entries (list) – List of (label, rgb_tuple) pairs.

  • corner (str) – Corner position for the legend.

  • box_alpha (int) – Alpha value for legend background.

  • pad (int) – Padding around legend content.

  • swatch_size (tuple) – Size of color swatches.

  • row_gap (int) – Gap between rows in the legend.

  • font_name_candidates (tuple) – Font names to try.

Returns:

Image with legend added.

Return type:

PIL.Image