findMCS#
- nvmolkit.mcs.findMCS(
- mols: Sequence[Mol],
- *,
- mode: str = 'all_pairs',
- pairs: Sequence[Sequence[int]] | None = None,
- mols_b: Sequence[Mol] | None = None,
- upper_triangle: bool = True,
- include_diagonal: bool = True,
- atom_compare: str = 'elements',
- bond_compare: str = 'order',
- match_valences: bool = False,
- match_formal_charge: bool = False,
- ring_matches_ring_only: bool | None = None,
- atom_ring_matches_ring_only: bool | None = None,
- bond_ring_matches_ring_only: bool | None = None,
- match_isotope: bool = False,
- maximize_bonds: bool = True,
- connected_only: bool = True,
- require_gpu: bool = False,
- timeout_seconds: int = 0,
- config: MCSConfig | None = None,
- batch_size: int = 0,
- worker_threads: int = -1,
- preprocessing_threads: int = -1,
- executors_per_runner: int = -1,
- gpu_ids: Sequence[int] | None = None,
Find maximum common substructures for a batch of molecule pairs.
- Input modes:
mode="all_pairs"usesmolsas a single indexed table. The default generates(i, j)in upper-triangle row-major order fori <= j, including self-pairs. Setinclude_diagonal=Falseto omit self-pairs. Setupper_triangle=Falseto generate the full row-major Cartesian square instead;include_diagonalstill controls self-pairs.mode="pairs"also uses onemolstable.pairsis a sequence of index pairs such as[(i, j), (i, j), ...]; the search processes exactly those entries in their given order. Repeated, reversed, and self-pairs are retained, and both indices in every pair addressmols.mode="paired_lists"zips two equally sized lists, searchingmols[i]againstmols_b[i]. Internally the lists are combined, soresult.pairscontains(i, len(mols) + i). The first and second columns of each atom or bond mapping still refer to the corresponding molecules frommolsandmols_b, respectively.
Results are flat and follow the generated pair order.
result[k]materializes the MCS forresult.pairs[k]; it does not index results by molecule ID. Mapping arrays contain(first_molecule_index, second_molecule_index)atom or bond index pairs.- Fallback behavior:
Molecule pairs outside the native GPU limits (currently 128 or more atoms or bonds, or atom degree greater than 8), and pairs whose GPU search queue overflows, transparently use RDKit on the CPU. Set
require_gpu=Trueto raise instead. This fallback is pair-specific; unsupported search options listed below raise for the whole call and do not trigger fallback.- Timeouts:
timeout_secondsis an independent budget for each generated pair, not one deadline shared by the batch. A timed-out pair hascanceled=Trueand may contain the best valid partial MCS found so far; other pairs continue independently. GPU timing starts when that pair’s kernel block begins and therefore excludes host preprocessing and dispatch time. A pair routed to RDKit receives the same timeout. Zero disables the timeout.- Unsupported features:
The interface currently supports exact, connected, bond-maximizing two-molecule MCS searches only.
connected_only=Falseandmaximize_bonds=FalseraiseValueError.atom_compare="any_heavy_atom"andmatch_isotope=Trueare not implemented and also raise. Useatom_compare="isotopes"for isotope-based atom comparison.Other RDKit fMCS features are not exposed: disconnected results,
StoreAll, thresholds other than 1.0, initial SMARTS seeds, custom atom/bond typers or callbacks, chirality and bond-stereo matching, complete-ring and fused-ring constraints, atom maximum-distance constraints, and verbose progress output.
- Parameters:
mols – Primary molecule table. In
pairsandall_pairsmodes, generated pair indices refer to this table.mode – Dispatch shape.
"all_pairs"builds square pair specs frommols."pairs"uses explicitpairsovermols."paired_lists"pairsmols[i]withmols_b[i].pairs – For
mode="pairs", a sequence of molecule-index pairs such as[(0, 1), (2, 3)]. Each(i, j)searchesmols[i]againstmols[j], and results preserve the sequence order.mols_b – Second molecule list for
mode="paired_lists".upper_triangle – For
mode="all_pairs", generate only upper-triangle pairs when true, otherwise generate full row-major square pairs.include_diagonal – Include
(i, i)all-pairs entries.atom_compare –
"any","elements", or"isotopes"."any_heavy_atom"is recognized but not implemented and raises.bond_compare –
"any","order", or"order_exact".match_valences – Match atom total valence.
match_formal_charge – Match atom formal charge.
ring_matches_ring_only – Convenience value applied to both atom and bond ring matching unless the axis-specific arguments are supplied.
atom_ring_matches_ring_only – Match ring atoms only to ring atoms.
bond_ring_matches_ring_only – Match ring bonds only to ring bonds.
match_isotope – Not currently implemented;
Trueraises. Useatom_compare="isotopes"for isotope-based comparison.maximize_bonds – Maximize bonds, matching RDKit’s default fMCS objective.
Falseis not currently supported and raises.connected_only – Require connected MCS.
Falseis not currently supported and raises.require_gpu – Raise instead of using per-pair RDKit fallback for native GPU size, degree, or queue-capacity limits.
timeout_seconds – Per-pair timeout in seconds. GPU results canceled by timeout return the best partial MCS found so far; RDKit fallback receives the same timeout.
config – Optional
MCSConfigwith GPU execution settings. Cannot be combined with explicit GPU execution keyword options.batch_size – Optional GPU batch chunk size.
0processes each nonempty size tier as one chunk.worker_threads – GPU runner threads per GPU.
-1autoselects.preprocessing_threads – CPU threads for pair preprocessing.
-1autoselects.executors_per_runner – Number of asynchronous GPU executor streams used for chunked fMCS tier dispatch.
-1autoselects.gpu_ids – GPU device IDs to use.
Noneor empty uses the current device only, not all available devices.
- Returns:
MCSBatchResultin generated-pair order.