parsing
parsing
All read_<…> and write_<…> functions.
Attributes
Name | Description |
---|---|
TopologyDict | A raw representation of a topology file returned by read_top . |
Classes
Name | Description |
---|---|
JSONEncoder | Encoder that enables writing JSONs with numpy types. |
Plumed_dict | Dict representation of a plumed.dat file. |
JSONEncoder
parsing.JSONEncoder()
Encoder that enables writing JSONs with numpy types.
Plumed_dict
parsing.Plumed_dict()
Dict representation of a plumed.dat file.
Functions
Name | Description |
---|---|
is_not_comment | Returns whether a string is not a comment. |
read_distances_dat | Read a distances.dat plumed output file. |
read_edissoc | Reads a edissoc file and turns it into a dict. |
read_json | Return JSON file content as dict. |
read_plumed | Read a plumed.dat configuration file. |
read_top | Read a topology file (.top,.itp,*.rtp) into a raw TopologyDict represenation. |
resolve_includes | Resolve #include statements in a (top/itp) file. |
write_json | Write dict to file according to JSON format. |
write_plumed | Write a plumed.dat configuration file. |
write_top | Write a TopologyDict to a topology file. |
is_not_comment
parsing.is_not_comment(c)
Returns whether a string is not a comment.
Used for topology like files that use ‘;’ for comments.
read_distances_dat
parsing.read_distances_dat(distances_dat)
Read a distances.dat plumed output file.
A typical file looks like this:
#! FIELDS time d0 d1 d2 d3 d4 d5 d6 ...
0.000000 0.153211 0.157662 0.139923 ...
read_edissoc
parsing.read_edissoc(path)
Reads a edissoc file and turns it into a dict.
The dissociation energy is assigned per pair of atom names. Atom names are unique to a residue, and the dict is nested by residues. The set of bond atoms make up the key, the dissociation energy E_dissoc [kJ mol-1] is the value.
Parameters
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the file. E.g. Path(“edissoc.dat”) | required |
read_json
parsing.read_json(path)
Return JSON file content as dict.
read_plumed
parsing.read_plumed(path)
Read a plumed.dat configuration file.
Follows the plumed naming scheme of label, keyword, action.
Parameters
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the file. E.g. “plumed.dat” | required |
Returns
Name | Type | Description |
---|---|---|
dict | Plumed_dict | dict with keys: ‘distances’ and ‘prints’ Each is a dict/list of dicts containing plumed keywords |
read_top
=None, use_gmx_dir=True) parsing.read_top(path, ffdir
Read a topology file (.top,.itp,*.rtp) into a raw TopologyDict represenation.
Assumptions and limitation:
#include
statements will be resolved- comments will be removed
- all lines are stripped of leading and trailing whitespace
#undef
is not supported- a section within
ifdef
may be a subsection of a section that was started outside of theifdef
#if..#endif
statements only surround a full section or subsection, not individual lines within a section and a section may either be contained within if … else or it may not be, but it can not be duplicated with one part inside and one outside.if .. else
can’t be nested#include
s that don’t resolve to a valid file path are silently dropped- sections that can have subsections can also exist multiple, separate times e.g. moleculetype will appear multiple times and they should not be merged
Parameters
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the topology file. | required |
Returns
Name | Type | Description |
---|---|---|
Every section, apart from ffdir and define , |
||
comes with a condition that can be checked against the | ||
define s by the helper functions to determine if the content |
||
(a list of lists) should come from content or else_content . |
||
Some sections such as moleculetype also come with subsections . |
Examples
=
raw_top 'ffdir': PosixPath('/usr/share/gromacs/top/amber99.ff'),
{'define': {'_FF_AMBER': [], '_FF_AMBER99': []},
'defaults': {'content': [['1', '2', 'yes', '0.5', '0.8333']],
'else_content': [],
'extra': [],
'condition': None},
'atomtypes': {'content': [
'C', '6', '12.01', '0.0000', 'A', '3.39967e-01', '3.59824e-01'],
['MNH3', '0', '0.0000', '0.0000', 'A', '0.00000e+00', '0.00000e+00']],
['else_content': [],
'extra': [],
'condition': None},
'moleculetype_Urea': {'content': [['Urea', '3']],
'else_content': [],
'extra': [],
'condition': None,
'subsections': {'atoms': {'content': [['1',
'C',
'1',
'URE',
'C',
'1',
'0.880229',
'12.01000'],
'2', 'O', '1', 'URE', 'O', '2', '-0.613359', '16.00000'],
['3', 'N', '1', 'URE', 'N1', '3', '-0.923545', '14.01000'],
['4', 'H', '1', 'URE', 'H11', '4', '0.395055', '1.00800'],
['5', 'H', '1', 'URE', 'H12', '5', '0.395055', '1.00800'],
['6', 'N', '1', 'URE', 'N2', '6', '-0.923545', '14.01000'],
['7', 'H', '1', 'URE', 'H21', '7', '0.395055', '1.00800'],
['8', 'H', '1', 'URE', 'H22', '8', '0.395055', '1.00800']],
['else_content': [],
'extra': [],
'condition': None},
'bonds': {'content': [['1', '2'],
'1', '3'],
['1', '6'],
['3', '4'],
['3', '5'],
['6', '7'],
['6', '8']],
['else_content': [],
'extra': [],
'condition': None},
'dihedrals': {'content': [['2', '1', '3', '4', '9'],
'2', '1', '3', '5', '9'],
['2', '1', '6', '7', '9'],
['2', '1', '6', '8', '9'],
['3', '1', '6', '7', '9'],
['3', '1', '6', '8', '9'],
['6', '1', '3', '4', '9'],
['6', '1', '3', '5', '9'],
['3', '6', '1', '2', '4'],
['1', '4', '3', '5', '4'],
['1', '7', '6', '8', '4']],
['else_content': [],
'extra': [],
'condition': None},
'position_restraints': {'content': [['1', '1', '1000', '1000', '1000'],
'2', '1', '1000', '0', '1000'],
['3', '1', '1000', '0', '0']],
['else_content': [],
'extra': [],
'condition': None},
'dihedral_restraints': {'content': [['3',
'6',
'1',
'2',
'1',
'180',
'0',
'10'],
'1', '4', '3', '5', '1', '180', '0', '10']],
['else_content': [],
'extra': [],
'condition': None}}},
}
resolve_includes
=None) parsing.resolve_includes(path, gmx_builtin_ffs
Resolve #include statements in a (top/itp) file.
Parameters
Name | Type | Description | Default |
---|---|---|---|
path | Path | Filepath to read. | required |
Returns
Name | Type | Description |
---|---|---|
lines | list[str] | List of lines. |
ffdir | Optional[Path] | Path to the ff directory if one of the includes used a file from it. |
write_json
parsing.write_json(d, path)
Write dict to file according to JSON format.
write_plumed
parsing.write_plumed(d, path)
Write a plumed.dat configuration file.
Parameters
Name | Type | Description | Default |
---|---|---|---|
d | Plumed_dict | Dictionary containing ‘labeled_action’, ‘other’ and ‘prints’ | required |
path | Path | Path to the file. E.g. “plumed.dat” | required |
write_top
parsing.write_top(top, outfile)
Write a TopologyDict to a topology file.
Parameters
Name | Type | Description | Default |
---|---|---|---|
top | TopologyDict | Raw dictionary represenation of the topology. | required |
outfile | Path | Path to the topology file to write to. | required |