Lomap API guide#
- class lomap.LomapAtomMapper(*, time: int = 20, threed: bool = True, max3d: float = 1.0, element_change: bool = True, seed: str = '', shift: bool = False)#
Wraps the MCS atom mapper from Lomap.
Kwargs are passed directly to the MCS class from Lomap for each mapping created
- Parameters:
time (int, optional) – timeout of MCS algorithm, passed to RDKit default 20
threed (bool, optional) – if true, positional info is used to choose between symmetrically equivalent mappings and prune the mapping, default True
max3d (float, optional) – maximum discrepancy in Angstroms between atoms before mapping is not allowed, default 1000.0, which effectively trims no atoms
element_change (bool, optional) – whether to allow element changes in the mappings, default True
seed (str, optional) – SMARTS string to use as seed for MCS searches. When used across an entire set of ligands, this can speed up calculations considerably
shift (bool, optional) – when determining 3D overlap, if to translate the two molecules MCS to minimise RMSD to boost potential alignment.
- copy_with_replacements(**replacements)#
Make a modified copy of this object.
Since GufeTokenizables are immutable, this is essentially a shortcut to mutate the object. Note that the keyword arguments it takes are based on keys of the dictionaries used in the the
_to_dict
/_from_dict
cycle for this object; in most cases that is the same as parameters to__init__
, but not always.This will always return a new object in memory. So using
obj.copy_with_replacements()
(with no keyword arguments) is a way to create a shallow copy: the object is different in memory, but its attributes will be the same objects in memory as the original.- Parameters:
replacements (Dict) – keyword arguments with keys taken from the keys given by the output of this object’s
to_dict
method.
- classmethod defaults()#
Dict of default key-value pairs for this GufeTokenizable object.
These defaults are stripped from the dict form of this object produced with
to_dict(include_defaults=False)
where default values are present.
- classmethod from_dict(dct: dict)#
Generate an instance from full dict representation.
- Parameters:
dct (Dict) – A dictionary produced by to_dict to instantiate from. If an identical instance already exists in memory, it will be returned. Otherwise, a new instance will be returned.
- classmethod from_json(file: PathLike | TextIO | None = None, content: str | None = None)#
Generate an instance from JSON keyed chain representation.
Can provide either a filepath/filelike as file, or JSON content via content.
- Parameters:
file – A filepath or filelike object to read JSON data from.
content – A string to read JSON data from.
See also
- classmethod from_keyed_chain(keyed_chain: list[tuple[str, dict]])#
Generate an instance from keyed chain representation.
- Parameters:
keyed_chain (List[Tuple[str, Dict]]) – The keyed_chain representation of the GufeTokenizable.
See also
KeyedChain
- classmethod from_keyed_dict(dct: dict)#
Generate an instance from keyed dict representation.
- Parameters:
dct (Dict) – A dictionary produced by to_keyed_dict to instantiate from. If an identical instance already exists in memory, it will be returned. Otherwise, a new instance will be returned.
- classmethod from_shallow_dict(dct: dict)#
Generate an instance from shallow dict representation.
- Parameters:
dct (Dict) – A dictionary produced by to_shallow_dict to instantiate from. If an identical instance already exists in memory, it will be returned. Otherwise, a new instance will be returned.
- property logger#
Return logger adapter for this instance
- classmethod serialization_migration(old_dict: dict, version: int) dict #
Migrate old serialization dicts to the current form.
The input dict
old_dict
comes from some previous serialization version, given byversion
. The output dict should be in the format of the current serialization dict.The recommended pattern to use looks like this:
def serialization_migration(cls, old_dict, version): if version == 1: ... # do things for migrating version 1->2 if version <= 2: ... # do things for migrating version 2->3 if version <= 3: ... # do things for migrating version 3->4 # etc
This approach steps through each old serialization model on its way to the current version. It keeps code relatively minimal and readable.
As a convenience, the following functions are available to simplify the various kinds of changes that are likely to occur in as serializtion versions change:
new_key_added()
old_key_removed()
key_renamed()
nested_key_moved()
- suggest_mappings(componentA: SmallMoleculeComponent, componentB: SmallMoleculeComponent) Iterable[LigandAtomMapping] #
Generate one or more mappings between two small molecules
- Parameters:
componentA (gufe.SmallMoleculeComponent)
componentB (gufe.SmallMoleculeComponent)
- Returns:
mapping – potential mappings
- Return type:
Iterable[LigandAtomMapping]
- to_dict(include_defaults=True) dict #
Generate full dict representation, with all referenced GufeTokenizable objects also given in full dict representations.
- Parameters:
include_defaults (bool) – If False, strip keys from dict representation with values equal to those in defaults.
See also
GufeTokenizable.to_shallow_dict()
,GufeTokenizable.to_keyed_dict()
- to_json(file: PathLike | TextIO | None = None) None | str #
Generate a JSON keyed chain representation.
This will be writen to the filepath or filelike object if passed.
- Parameters:
file – A filepath or filelike object to write the JSON to.
- Returns:
A minimal JSON representation of the object if file is None; else None.
- Return type:
See also
- to_keyed_chain() list[tuple[str, dict]] #
Generate a keyed chain representation of the object.
See also
KeyedChain
- to_keyed_dict(include_defaults=True) dict #
Generate keyed dict representation, with all referenced GufeTokenizable objects given in keyed representations.
A keyed representation of an object is a dict of the form:
{‘:gufe-key:’: <GufeTokenizable.key>}
These function as stubs to allow for serialization and storage of GufeTokenizable objects with minimal duplication.
The original object can be re-assembled with from_keyed_dict.
See also
GufeTokenizable.to_dict()
,GufeTokenizable.to_shallow_dict()
- lomap.generate_lomap_network(ligands: list[SmallMoleculeComponent], mappers: AtomMapper | list[AtomMapper], scorer: Callable, distance_cutoff: float = 0.4, max_path_length=6, actives: list[bool] | None = None, max_dist_from_active=2, require_cycle_covering: bool = True, radial: bool = False, fast: bool = False, hub: SmallMoleculeComponent | None = None) LigandNetwork #
Generate a LigandNetwork according to Lomap’s network creation rules
- Parameters:
ligands (list[SmallMoleculeComponent]) – molecules to map
mappers (list[AtomMapper] or AtomMapper) – one or more Mapper functions to use to propose edges
scorer (function) – scoring function for edges. Should be a function which takes an AtomMapping and returns a value from 1.0 (best) to 0.0 (worst). These values are use as the “distance” between two molecules, and compared against the ‘distance_cutoff’ parameter
distance_cutoff (float) – the maximum distance/dissimilarity between two molecules for an edge to be accepted
max_path_length (int) – maximum distance between any two molecules in the resulting network
actives (list[bool]) – for each molecule, if it is tagged as an active molecule
max_dist_from_active – when ‘actives’ is given, constrains the resulting map to
require_cycle_covering (bool) – add cycles into the network
radial (bool) – construct a radial/starmap network. Note that this the map will not necessarily be a true radial map; edges will still obey the distance_cutoff and if ‘require_cycle_covering’ is true, this radial map will still feature cycles, default False
fast (bool) – hmmm…
hub (SmallMoleculeComponent, optional) – if radial, force this ligand to be the centre/hub of the radial graph