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.

  • known_mappings (dict) – Collection of mapping to update in-place.
  • partial_mapping (dict) – Collection of mappings to update from.

Generate self mappings for a list of force fields.

Parameters:force_fields ( – List of instances of ForceField.
Returns:A collection of mappings formatted as the output of the read_mapping_directory() function.
Return type:dict

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 a mapping from a file.
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.


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.


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.

  • 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

A collection of mappings.

Return type:


vermouth.map_input.read_mapping_file(lines, force_fields)[source]