besmarts.core.mapper module¶
besmarts.core.mapper
Functions for mapping between two structures of arbitrary size
- besmarts.core.mapper.align_score(G: structure, H: structure)[source]¶
Return the number of overlapping bits after mapping two structures
- Parameters:
G (graphs.structure) – The first input structure
H (graphs.structure) – The second input structure
Returns
int – The number of overlapping bits
- besmarts.core.mapper.difference(cg: subgraph, o: subgraph, config: mapper_config = None, map=None, pool=None)[source]¶
Calculate the difference of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.dispatch_boolean_op(cg, o, fn, config: mapper_config, map=None, pool=None) structure[source]¶
Perform a bitwise operation across the nodes and edges of pair of structures, adding or subtracting nodes as necessary.
- Parameters:
cg (graphs.structure) – The input structure that defines the domain of the map
o (graphs.structure) – The input second input structures
fn (Callable) – The bitwise operation
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.group_by_isomorphism(structures: List[structure], mapping_cache=None)[source]¶
Group structures that are isomorphic (equal).
- Parameters:
structures (List[graphs.structure]) – The structures to extend.
mapping_cache (Dict[(int, int), Dict[node_id, node_id]]) – Precalculated maps for each pair of structures. Useful when you mapped at one depth, then extend and need to map at the next depth.
- Returns:
A list of groups of structures that are isomorphic (equal).
- Return type:
List[List[graphs.structure]]
- besmarts.core.mapper.intersection(cg: structure, o: structure, config: mapper_config = None, map=None, pool=None)[source]¶
Calculate the intersection of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.intersection_conditional(cg: structure, o: structure, config: mapper_config = None, map=None, pool=None)[source]¶
Calculate the intersection of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.intersection_list(A: Sequence[structure], config: mapper_config = None, max_depth=None, reference=None, sort=True, executor=None, verbose=False) structure[source]¶
- besmarts.core.mapper.intersection_list_parallel(A: Sequence[structure], config: mapper_config = None, max_depth=None, reference=None, sort=True, executor=None) structure[source]¶
- besmarts.core.mapper.is_isomorphic(G: structure, H: structure) bool[source]¶
Determine a mapping between G and H where G is isomorphic, or equal to, H
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
- Return type:
bool
- besmarts.core.mapper.isomorphic(G: structure, H: structure) mapped_type[source]¶
Determine a mapping between G and H where G is isomorphic, or equal to, H
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
- Returns:
The mapping
- Return type:
- besmarts.core.mapper.map_to(cg: structure, o: structure, strict=False, equality=False, skip=None, return_all=False, add_nodes=0, fill=0, mode='high', pool=None) mapped_type[source]¶
Return the node mapping of one structure to another
- Parameters:
cg (graphs.structure) – The structure to map from
o (graphs.structure) – The structure to map to
strict (bool) – Whether the map must satisfy that G is a subset of H
equality (bool) – Whether the map must satisfy that G is equal to H
skip (Dict[node_id, node_id]) – A set of mapped nodes that should be held constant. The mapper will try to map any remaining nodes.
add_nodes (0|1|2|3) –
- The mode for adding nodes.
0 means MCS 1 means add/remove G 2 means add/remove H 3 means add to both
fill=0,
mode (str, “high” or “low”) – Whether the mapper should prefer to map nodes with “high” overlap or “low” overlap.
- Returns:
A node mapping
- Return type:
Dict[node_id, node_id]
- besmarts.core.mapper.map_to_descend(cg, o, mappings, scores, lvl, nbr_cg, nbr_o, score_cache, cg_depth_cache, o_depth_cache, skip=None, strict=False, equality=False, add_nodes=0, fill=0, mode='high', return_all=False, pool=None)[source]¶
Find the mappings between a subset of nodes at a certain depth from each structure.
- Parameters:
cg (graphs.structure) – The structure to map from
o (graphs.structure) – The structure to map to
scores – The scores of mappings already completed
scores – The scores of mappings already completed
nbr_cg – The adjacency map of cg
nbr_o – The adjacency map of o
score_cache – The score cache
cg_depth_cache – The precalculated depths of the nodes of cg
o_depth_cache – The precalculated depths of the nodes of o
strict (bool) – Whether the map must satsify that cg is a subset to o
equality (bool) – Whether the map must satsify that cg is equal to o
skip (Dict[node_id, node_id]) – A set of mapped nodes that should be held constant. The mapper will try to map any remaining nodes.
- Returns:
best_s – The score of the best mapping
best_mapping – The score of best mapping
- besmarts.core.mapper.map_vertices(cg, o, a, b, scores, lvl, neighbors_cg, neighbors_o, score_cache, cg_depth_cache=None, o_depth_cache=None, skip=None, strict=False, equality=False, add_nodes=0, fill=0, mode='high', pool=None)[source]¶
Return the scores of all possible mappings of given set of nodes
- Parameters:
cg (graphs.structure) – The structure to map from
o (graphs.structure) – The structure to map to
a (node_id) – The node of cg to to get neighbors from
b (node_id) – The node of o to to get neighbors from
scores – The scores of mappings already completed
lvl (int) – The depth
nbr_cg – The adjacency map of cg
nbr_o – The adjacency map of o
score_cache – The score cache
cg_depth_cache – The precalculated depths of the nodes of cg
o_depth_cache – The precalculated depths of the nodes of o
strict (bool) – Whether the map must satsify that cg is a subset to o
equality (bool) – Whether the map must satsify that cg is equal to o
skip (Dict[node_id, node_id]) – A set of mapped nodes that should be held constant. The mapper will try to map any remaining nodes.
- Returns:
A mapping of scores to node maps
- Return type:
Dict[int, Dict[node_id, node_id]]
- class besmarts.core.mapper.map_vertices_ctx[source]¶
Bases:
object- H = None¶
- a = None¶
- b = None¶
- cg = None¶
- equality = False¶
- o = None¶
- strict = False¶
- class besmarts.core.mapper.mapped_type(G: subgraph, H: subgraph, map: Dict[int, int])[source]¶
Bases:
objectA pair of graphs with an associated node mapping between them
- besmarts.core.mapper.mapper(G: structure, H: structure, strict=False, equality=False, skip=None, add_nodes=0, fill=0, mode='high', return_all=False, pool=None) mapped_type[source]¶
Determine the mapping between two graphs G and H
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
strict (bool) – Whether the map must satsify that G is a subset of H
equality (bool) – Whether the map must satsify that G is equal to H
skip (Dict[node_id, node_id]) – A set of mapped nodes that should be held constant. The mapper will try to map any remaining nodes.
mode (“high” or “low”) – Whether the mapper should prefer to map nodes with “high” overlap or “low” overlap.
- Returns:
A new mapped type
- Return type:
- besmarts.core.mapper.mapper_compose(T1: mapped_type, T2: mapped_type) mapped_type[source]¶
Transform the map from G -> H to G <- H
- Parameters:
T (mapped_type) – The input map
- Return type:
A new mapped type
- besmarts.core.mapper.mapper_compose_graphs(cg, o, map, add_nodes=False, fill_new_nodes=False) Tuple[structure, structure, dict][source]¶
Perform a bitwise operation across the nodes and edges of pair of structures, adding or subtracting nodes as necessary.
- Parameters:
cg (graphs.structure) – The input structure that defines the domain of the map
o (graphs.structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.mapper_force_equality(G, H, pool=None) mapped_type[source]¶
Determine the mapping between two graphs G and H where G must be equal to H
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
- Returns:
A new mapped type
- Return type:
- besmarts.core.mapper.mapper_force_subset(G, H) mapped_type[source]¶
Determine the mapping between two graphs G and H where G must be a subset of H
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
- Returns:
A new mapped type
- Return type:
- besmarts.core.mapper.mapper_invert(T: mapped_type) mapped_type[source]¶
Transform the map from G -> H to G <- H
- Parameters:
T (mapped_type) – The input map
- Return type:
A new mapped type
- besmarts.core.mapper.mapper_match(G, H, pool=None) bool[source]¶
Determine whether G is a subset of H, where missing nodes in H are assumed to exist but unknown, and as such are treated as full (~[*]). This allows a SMARTS pattern such as [#6]~[*] to be a subset of [#6]. Coincidentally, the opposite is true as well for this case, but wouldn’t be the case for e.g. [#6]-[#1].
- Parameters:
G (graphs.structure) – The first input structure that defines the domain of the map
H (graphs.structure) – The second input structure the defines the range of the map
- Returns:
Whether G matches H
- Return type:
bool
- besmarts.core.mapper.neg(self)[source]¶
Calculate the negation of a structure
- Parameters:
cg (structure) – The input structure that defines the domain of the map
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.overlap_scores(cg, o, skip=None, cg_depth_cache=None, o_depth_cache=None)[source]¶
- besmarts.core.mapper.subtract(self: structure, o: structure, config: mapper_config = None, map=None)[source]¶
Calculate the exclusive or (symmetric difference) of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.subtract_conditional(g: structure, h: structure, config: mapper_config = None, map=None)[source]¶
Calculate the exclusive or (symmetric difference) of two structures
- Parameters:
g (structure) – The input structure that defines the domain of the map
h (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.subtract_conditional_left(g: structure, h: structure, config: mapper_config = None, map=None, pool=None)[source]¶
Calculate the exclusive or (symmetric difference) of two structures
- Parameters:
g (structure) – The input structure that defines the domain of the map
h (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.subtract_conditional_right(self: structure, o: structure, config: mapper_config = None, map=None, pool=None)[source]¶
Calculate the exclusive or (symmetric difference) of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- besmarts.core.mapper.union(cg: structure, o: structure, config: mapper_config = None, map=None, pool=None) structure[source]¶
Calculate the union of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type:
- class besmarts.core.mapper.union_ctx[source]¶
Bases:
object- A = None¶
- config = None¶
- icd = None¶
- reference = None¶
- topology = None¶
- besmarts.core.mapper.union_list(A: Sequence[structure], config: mapper_config = None, max_depth=None, reference=None, sort=True, executor=None, verbose=False) structure[source]¶
- besmarts.core.mapper.union_list_dispatch_distributed(indices: List[int], shm=None) structure[source]¶
- besmarts.core.mapper.union_list_distributed(G: Sequence[graph], selections, topo, wq, config: mapper_config = None, max_depth=None, reference=None, sort=True, executor=None, icd=None) structure[source]¶
- besmarts.core.mapper.union_list_parallel(G: Sequence[graph], selections, topo, config: mapper_config = None, max_depth=None, reference=None, sort=True, executor=None, icd=None, verbose=True) structure[source]¶
- besmarts.core.mapper.xor(self, o, config: mapper_config = None, map=None)[source]¶
Calculate the exclusive or (symmetric difference) of two structures
- Parameters:
cg (structure) – The input structure that defines the domain of the map
o (structure) – The input second input structures
config (configs.mapper_config) – The configuration for mapping new nodes
map (Dict[node_id, node_id]) – A precalculated map to use
- Returns:
The result of the operation
- Return type: