vermouth.ffinput module

Read .ff files.

The FF file format describes molecule components for a given force field. It is a test format devised for quick prototyping.

The format is built on top of a subset of the ITP format. Describing a block is done in the same way an ITP file describes a molecule.

class vermouth.ffinput.FFDirector(force_field)[source]

Bases: SectionLineParser

COMMENT_CHAR = ';'
METH_DICT = {('citations',): (<function FFDirector._pase_ff_citations>, {}), ('link',): (<function FFDirector._link>, {'context_type': 'link'}), ('link', '!SETTLE'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!angle_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!angle_restraints_z'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!angles'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!bonds'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!constraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!dihedral_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!dihedrals'): (<function FFDirector._dih_interactions>, {'context_type': 'link'}), ('link', '!distance_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!exclusions'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!impropers'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!orientation_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!pairs'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!pairs_nb'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!position_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!virtual_sites2'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!virtual_sites3'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!virtual_sites4'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', '!virtual_sitesn'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'SETTLE'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'angle_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'angle_restraints_z'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'angles'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'atoms'): (<function FFDirector._link_atoms>, {}), ('link', 'bonds'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'citation'): (<function FFDirector._parse_citation>, {'context_type': 'link'}), ('link', 'constraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'debug'): (<function FFDirector._parse_log_entry>, {'context_type': 'link'}), ('link', 'dihedral_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'dihedrals'): (<function FFDirector._dih_interactions>, {'context_type': 'link'}), ('link', 'distance_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'edges'): (<function FFDirector._edges>, {'context_type': 'link', 'negate': False}), ('link', 'error'): (<function FFDirector._parse_log_entry>, {'context_type': 'link'}), ('link', 'exclusions'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'features'): (<function FFDirector._link_features>, {'context_type': 'link'}), ('link', 'impropers'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'info'): (<function FFDirector._parse_log_entry>, {'context_type': 'link'}), ('link', 'molmeta'): (<function FFDirector._link>, {'context_type': 'molmeta'}), ('link', 'non-edges'): (<function FFDirector._edges>, {'context_type': 'link', 'negate': True}), ('link', 'orientation_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'pairs'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'pairs_nb'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('link', 'patterns'): (<function FFDirector._link_patterns>, {'context_type': 'link'}), ('link', 'position_restraints'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'virtual_sites2'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'virtual_sites3'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'virtual_sites4'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'virtual_sitesn'): (<function FFDirector._interactions>, {'context_type': 'link'}), ('link', 'warning'): (<function FFDirector._parse_log_entry>, {'context_type': 'link'}), ('macros',): (<function SectionLineParser._macros>, {}), ('modification',): (<function FFDirector._modification>, {}), ('modification', 'SETTLE'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'angle_restraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'angle_restraints_z'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'angles'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'atoms'): (<function FFDirector._modification_atoms>, {}), ('modification', 'bonds'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'citation'): (<function FFDirector._parse_citation>, {'context_type': 'modification'}), ('modification', 'constraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'debug'): (<function FFDirector._parse_log_entry>, {'context_type': 'modification'}), ('modification', 'dihedral_restraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'dihedrals'): (<function FFDirector._dih_interactions>, {'context_type': 'modification'}), ('modification', 'distance_restraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'edges'): (<function FFDirector._edges>, {'context_type': 'modification', 'negate': False}), ('modification', 'error'): (<function FFDirector._parse_log_entry>, {'context_type': 'modification'}), ('modification', 'exclusions'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'features'): (<function FFDirector._link_features>, {'context_type': 'modification'}), ('modification', 'impropers'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'info'): (<function FFDirector._parse_log_entry>, {'context_type': 'modification'}), ('modification', 'non-edge'): (<function FFDirector._invalid_out_of_link>, {}), ('modification', 'orientation_restraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'pairs'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'pairs_nb'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'patterns'): (<function FFDirector._link_patterns>, {'context_type': 'modification'}), ('modification', 'position_restraints'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'virtual_sites2'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'virtual_sites3'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'virtual_sites4'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'virtual_sitesn'): (<function FFDirector._interactions>, {'context_type': 'modification'}), ('modification', 'warning'): (<function FFDirector._parse_log_entry>, {'context_type': 'modification'}), ('moleculetype',): (<function FFDirector._block>, {}), ('moleculetype', 'SETTLE'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'angle_restraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'angle_restraints_z'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'angles'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'atoms'): (<function FFDirector._block_atoms>, {}), ('moleculetype', 'bonds'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'citation'): (<function FFDirector._parse_citation>, {'context_type': 'block'}), ('moleculetype', 'constraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'debug'): (<function FFDirector._parse_log_entry>, {'context_type': 'block'}), ('moleculetype', 'dihedral_restraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'dihedrals'): (<function FFDirector._dih_interactions>, {'context_type': 'block'}), ('moleculetype', 'distance_restraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'edges'): (<function FFDirector._edges>, {'context_type': 'block', 'negate': False}), ('moleculetype', 'error'): (<function FFDirector._parse_log_entry>, {'context_type': 'block'}), ('moleculetype', 'exclusions'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'features'): (<function FFDirector._invalid_out_of_link>, {}), ('moleculetype', 'impropers'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'info'): (<function FFDirector._parse_log_entry>, {'context_type': 'block'}), ('moleculetype', 'meta'): (<function FFDirector._parse_block_meta>, {}), ('moleculetype', 'non-edge'): (<function FFDirector._invalid_out_of_link>, {}), ('moleculetype', 'non-edges'): (<function FFDirector._edges>, {'context_type': 'block', 'negate': True}), ('moleculetype', 'orientation_restraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'pairs'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'pairs_nb'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'patterns'): (<function FFDirector._invalid_out_of_link>, {}), ('moleculetype', 'position_restraints'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'virtual_sites2'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'virtual_sites3'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'virtual_sites4'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'virtual_sitesn'): (<function FFDirector._interactions>, {'context_type': 'block'}), ('moleculetype', 'warning'): (<function FFDirector._parse_log_entry>, {'context_type': 'block'}), ('variables',): (<function FFDirector._variables>, {})}

A dict of all known parser methods, mapping section names to the function to be called and the associated keyword arguments.

finalize_section(previous_section, ended_section)[source]

Called once a section is finished. It appends the current_links list to the links and update the block dictionary with current_block. Thereby it finishes the reading a given section.

Parameters:
  • previous_section (list[str]) – The last parsed section.

  • ended_section (list[str]) – The sections that have been ended.

get_context(context_type='')[source]
has_context()[source]
interactions_natoms = {'SETTLE': 1, 'angle_restraints': 4, 'angle_restraints_z': 2, 'angles': 3, 'bonds': 2, 'constraints': 2, 'dihedral_restraints': 4, 'dihedrals': 4, 'distance_restraints': 2, 'impropers': 4, 'orientation_restraints': 2, 'pairs': 2, 'pairs_nb': 2, 'position_restraints': 1, 'virtual_sites2': 3, 'virtual_sites3': 4, 'virtual_sites4': 5}
parse_header(line, lineno=0)[source]

Parses a section header with line number lineno. Sets vermouth.parser_utils.SectionLineParser.section when applicable. Does not check whether line is a valid section header.

Parameters:
Returns:

The result of calling finalize_section(), which is called if a section ends.

Return type:

object

Raises:

KeyError – If the section header is unknown.

vermouth.ffinput.read_ff(lines, force_field)[source]