vermouth.processors.do_mapping module

Provides a processor that can perform a resolution transformation on a molecule.

class vermouth.processors.do_mapping.DoMapping(mappings, to_ff, delete_unknown=False, attribute_keep=(), attribute_must=())[source]

Bases: vermouth.processors.processor.Processor

run_molecule(molecule)[source]
run_system(system)[source]
vermouth.processors.do_mapping.apply_block_mapping(match, molecule, graph_out, mol_to_out, out_to_mol)[source]

Performs a mapping operation for a “block”. match is a tuple of 3 elements that describes what nodes in molecule should correspond to a vermouth.molecule.Block that should be added to graph_out, and any atoms that should be used a references. Add the required vermouth.molecule.Block to graph_out, and updates mol_to_out and out_to_mol in-place.

Parameters
Returns

  • set – A set of all overlapping nodes that were already mapped before.

  • set – A set of none-to-one mappings. I.e. nodes that were created without nodes mapping to them.

  • dict – A dict of reference atoms, mapping graph_out nodes to nodes in molecule.

vermouth.processors.do_mapping.apply_mod_mapping(match, molecule, graph_out, mol_to_out, out_to_mol)[source]

Performs the mapping operation for a modification.

Parameters
Returns

  • dict[str, dict[tuple, vermouth.molecule.Link]] – A dict of all modifications that have been applied by this modification mapping operations. Maps interaction type to involved atoms to the modification responsible.

  • dict – A dict of reference atoms, mapping graph_out nodes to nodes in molecule.

vermouth.processors.do_mapping.attrs_from_node(node, attrs)[source]

Helper function that applies a “replace” operations on the node if required, and then returns a dict of the attributes listed in attrs.

Parameters
Returns

Return type

dict

vermouth.processors.do_mapping.build_graph_mapping_collection(from_ff, to_ff, mappings)[source]

Function that produces a collection of vermouth.map_parser.Mapping objects. Hereby deprecated.

Parameters
Returns

A collection of mappings that map from from_ff to to_ff.

Return type

collections.abc.Iterable

vermouth.processors.do_mapping.cover(to_cover, options)[source]

Implements a recursive backtracking algorithm to cover all elements of to_cover with the elements from options that have the lowest index. In this context “to cover” means that all items in an element of options must be in to_cover. Elements in to_cover can only be covered once.

Parameters
Returns

None if no covering can be found, or the list of items from options with the lowest indices that exactly covers to_cover.

Return type

None or list

vermouth.processors.do_mapping.do_mapping(molecule, mappings, to_ff, attribute_keep=(), attribute_must=())[source]

Creates a new Molecule in force field to_ff from molecule, based on mappings. It does this by doing a subgraph isomorphism of all blocks in mappings and molecule. Will issue warnings if there’s atoms not contibuting to the new molecule, or if there’s overlapping blocks. Node attributes in the new molecule will come from the blocks constructing it, except for those in attribute_keep, which lists the attributes that will be kept from molecule.

Parameters
  • molecule (Molecule) – The molecule to transform.

  • mappings (dict[str, dict[str, dict[str, tuple]]]) – {ff_name: {ff_name: {block_name: (mapping, weights, extra)}}} A collection of mappings, as returned by e.g. read_mapping_directory().

  • to_ff (ForceField) – The force field to transform to.

  • attribute_keep (Iterable) – The attributes that will always be transferred from molecule to the produced graph.

  • attribute_must (Iterable) – The attributes that the nodes in the output graph must have. If they’re not provided by the mappings/blocks they’re taken from molecule.

Returns

A new molecule, created by transforming molecule to to_ff according to mappings.

Return type

Molecule

vermouth.processors.do_mapping.edge_matcher(graph1, graph2, node11, node12, node21, node22)[source]

Checks whether the resids for node11 and node12 in graph1 are the same, and whether that’s also true for node21 and node22 in graph2.

Parameters
Returns

Return type

bool

vermouth.processors.do_mapping.get_mod_mappings(mappings)[source]

Returns a dict of all known modification mappings.

Parameters

mappings (collections.abc.Iterable[vermouth.map_parser.Mapping]) – All known mappings.

Returns

All mappings that describe a modification mapping.

Return type

dict[tuple[str], vermouth.map_parser.Mapping]

vermouth.processors.do_mapping.modification_matches(molecule, mappings)[source]

Returns a minimal combination of modification mappings and where they should be applied that describes all modifications in molecule.

Parameters
Returns

A list with the following items:
Dict describing the correspondence of node keys in molecule to

node keys in the modification.

The modification.

Dict with all reference atoms, mapping modification nodes to

nodes in molecule.

Return type

list[tuple[dict, vermouth.molecule.Link, dict]]

vermouth.processors.do_mapping.node_matcher(node1, node2)[source]

Checks whether nodes should be considered equal for isomorphism. Takes all attributes in node2 into account, except for the attributes “atype”, “charge”, “charge_group”, “resid”, “replace”, and “_old_atomname”.

Parameters
Returns

Return type

bool

vermouth.processors.do_mapping.node_should_exist(modification, node_idx)[source]

Returns True if the node with index node_idx in modification should already exist in the parent molecule.

Parameters
Returns

True iff the node node_idx in modification should already exist in the parent molecule.

Return type

bool

vermouth.processors.do_mapping.ptm_resname_match(mol_node, map_node)[source]

As node_matcher(), except that empty resname and false PTM_atom attributes from node2 are removed.