Source code for ccdc.minor_component_knowledge_banks

#
# This code is Copyright (C) 2026 The Cambridge Crystallographic Data Centre
# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC.
# This code may not be used, reproduced, translated, modified, disassembled or
# copied, except in accordance with a valid licence agreement with CCDC and may
# not be disclosed or redistributed in any form, either in whole or in part, to
# any third party. All copies of this code made in accordance with a valid
# licence agreement as referred to above must contain this copyright notice.
#
# No representations, warranties, or liabilities are expressed or implied in the
# supply of this code by CCDC, its servants or agents, except where such
# exclusion or limitation is prohibited, void or unenforceable under governing
# law.
#
'''
The :mod:`ccdc.minor_component_knowledge_banks` module contains classes for Minor Component Knowledge Bank objects.

The main classes in the :mod:`ccdc.minor_component_knowledge_banks` module are:

- :class:`ccdc.minor_component_knowledge_banks.SolventKnowledgeBank`.
- :class:`ccdc.minor_component_knowledge_banks.MinorComponentKnowledgeBankEntry`.
- :class:`ccdc.minor_component_knowledge_banks.CoformerKnowledgeBank` and alike in the future.
'''

from ccdc.utilities import _import_ccdc_modules

_import_ccdc_modules([
    'MinorComponentKnowledgeBanksLib',
    'UtilitiesLib'
])


#################################################################################################
#   MinorComponentKnowledgeBankEntry class
#   To wrap the MinorComponentKnowledgeBanksLib.SolventKnowledgeBankEntry and its properties
#################################################################################################

[docs] class MinorComponentKnowledgeBankEntry(): '''The Minor Component knowledge bank entry class. It wraps the MinorComponentKnowledgeBanksLib.SolventKnowledgeBankEntry and its properties. ''' _telemetry = 0 def __init__(self, _kb_entry=None): '''Initialise the minor component knowledge bank entry with a MinorComponentKnowledgeBanksLib.SolventKnowledgeBankEntry. If no entry is provided, the properties will return None.''' if type(self)._telemetry == 0: UtilitiesLib.ccdc_minor_component_knowledge_banks_telemetry() type(self)._telemetry = 1 self._kb_entry = _kb_entry @property def name(self): '''Returns the name of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.name() @property def hits(self): '''Returns the total molecule hits in the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().total_mols_ @property def minimum(self): '''Returns the minimum of occupied space of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().min_ @property def maximum(self): '''Returns the maximum of occupied space of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().max_ @property def mean(self): '''Returns the mean of occupied space of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().mean_ @property def standard_deviation(self): '''Returns the standard deviation of the occupied space in the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().std_dev_ @property def quantile_low(self): '''Returns the 0.05 quantile of the occupied space of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().low_quantile_ @property def quantile_high(self): '''Returns the 0.95 quantile of the occupied space in the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.occupied_volume_stats().high_quantile_ @property def hbond_motifs(self): '''Returns the popular intermolecular hydrogen bond motifs (percentage) of the minor component knowledge bank entry''' if self._kb_entry is None: return None return self._kb_entry.popular_hbond_motifs_string()
################################################################################################# # SolventKnowledgeBank class #################################################################################################
[docs] class SolventKnowledgeBank(): '''A class to read and contain the solvent knowledge bank entries. Occupied space data is available for a range of probe radius values (with grid spacing 0.3 Angstroms). ''' def __init__(self, skb_directory=None, probe_radius=1.2): '''Based on the probe radius, get the MinorComponentKnowledgeBank entries from the database. skb_directory: The directory in which to find the Solvent Knowledge Bank. If not provided, the default CCDC Solvent Knowledge Bank will be used. probe_radius: the probe radius in Angstroms to measure the occupied space. It can be set to 1.2, 1.1, 1.0, 0.9 or 0.8 (default is 1.2). ''' if skb_directory is not None: skb = MinorComponentKnowledgeBanksLib.SolventsKnowledgeBank.skb_from_directory(skb_directory) else: skb = MinorComponentKnowledgeBanksLib.SolventsKnowledgeBank.csd_skb() if skb is None or skb.entries() is None or len(skb.entries()) == 0: raise RuntimeError("Solvent Knowledge Bank data not found. Please install the CSD Knowledge Bank Data via the CCDC Maintenance Tool.") try: skb.set_current_probe_radius(probe_radius) except RuntimeError: raise RuntimeError(f"probe_radius must be one of the following values: {skb.probe_radii()}") self._entries = [MinorComponentKnowledgeBankEntry(_kb_entry=entry) for entry in skb.entries()] @property def entries(self): '''return all the minor component knowledge bank entries''' return self._entries