vermouth.map_input module¶
Read force field to force field mappings.
-
vermouth.map_input.
combine_mappings
(known_mappings, partial_mapping)[source]¶ Update a collection of mappings.
Add the mappings from the ‘partial_mapping’ argument into the ‘known_mappings’ collection. Both arguments are collections of mappings similar to the output of the
read_mapping_directory()
function. They are dictionary with 3 levels of keys: the name of the initial force field, the name of the target force field, and the name of the block. The values in the third level dictionary are tuples of (mapping, weights, extra).If a force field appears in ‘partial_mapping’ that is not in ‘known_mappings’, then it is added. For existing pairs of initial and target force fields, the blocks are updated and the version in ‘partial_mapping’ is kept in priority.
Parameters:
-
vermouth.map_input.
generate_all_self_mappings
(force_fields)[source]¶ Generate self mappings for a list of force fields.
Parameters: force_fields (collections.abc.Iterable) – List of instances of ForceField
.Returns: A collection of mappings formatted as the output of the read_mapping_directory()
function.Return type: dict
-
vermouth.map_input.
generate_self_mappings
(blocks)[source]¶ Generate self mappings from a collection of blocks.
A self mapping is a mapping that maps a force field to itself. Applying such mapping is applying a neutral transformation.
Parameters: blocks (dict[str, networkx.Graph]) – A dictionary of blocks with block names as keys and the blocks themselves as values. The blocks must be instances of networkx.Graph
with each node having an ‘atomname’ attribute.Returns: mappings – A dictionary of mappings where the keys are the names of the blocks, and the values are tuples like (mapping, weights, extra). Return type: dict[str, tuple] Raises: KeyError
– Raised if a node does not have am ‘atomname’ attribute.See also
read_mapping_file()
- Read a mapping from a file.
generate_all_self_mappings()
- Generate self mappings for a list of force fields.
-
vermouth.map_input.
make_mapping_object
(from_block, to_block, mapping, weights, extra, name_to_index)[source]¶ Convenience method for creating modern
vermouth.map_parser.Mapping
objects from old style mapping information.Parameters: - from_blocks (collections.abc.Iterable[vermouth.molecule.Block]) –
- to_blocks (collections.abc.Iterable[vermouth.molecule.Block]) –
- mapping (dict[tuple[int, str], list[tuple[int, str]]]) – Old style mapping describing what (resid, atomname) maps to what (resid, atomname)
- weights (dict[tuple[int, str], dict[tuple[int, str], float]]) – Old style weights, mapping (resid, atomname), (resid, atomname) to a weight.
- extra (tuple) –
- name_to_index (dict[str, dict[str, dict[str, collections.abc.Hashable]]]) – Dict force field names, block names, atomnames to node indices.
Returns: The created mapping.
Return type:
-
vermouth.map_input.
read_backmapping_file
(lines, force_fields)[source]¶ Partial reader for modified Backward mapping files.
Read mappings from a Backward mapping file. Not all fields are supported, only the “molecule” and the “atoms” fields are read. If not explicitly specified, the origin force field for a molecule is assumed to be “universal”, and the destination force field is assumed to be “martini22”.
The mapping collection is a 3 level dictionary where the first key is the name of the initial force field, the second key is the name of the destination force field, and the third key is the name of the molecule.
Parameters: - lines (collections.abc.Iterable[str]) – Collection of lines to read.
- force_fields (dict[str, vermouth.forcefield.ForceField]) – Dict of known force fields.
Returns: Return type:
-
vermouth.map_input.
read_mapping_directory
(directory, force_fields)[source]¶ Read all the mapping files in a directory.
The resulting mapping collection is a 3-level dict where the keys are: * the name of the origin force field * the name of the destination force field * the name of the residue
The values after these 3 levels is a mapping dict where the keys are the atom names in the origin force field and the values are lists of names in the destination force field.
Parameters: - directory (str) – The path to the directory to search. Files with a ‘.backmap’ extension will be read. There is no recursive search.
- force_fields (dict[str, ForceField]) – Dict of known forcefields
Returns: A collection of mappings.
Return type: