ForceBalance API
1.3
Automated optimization of force fields and empirical potentials
|
Finite state machine for parsing GROMACS force field files. More...
Public Member Functions | |
def | __init__ (self, fnm) |
def | feed (self, line) |
Given a line, determine the interaction type and the atoms involved (the suffix). More... | |
Public Attributes | |
sec | |
The current section that we're in. More... | |
nbtype | |
Nonbonded type. More... | |
mol | |
The current molecule (set by the moleculetype keyword) More... | |
pdict | |
The parameter dictionary (defined in this file) More... | |
atomnames | |
Listing of all atom names in the file, (probably unnecessary) More... | |
atomtypes | |
Listing of all atom types in the file, (probably unnecessary) More... | |
atomtype_to_mass | |
A dictionary of atomic masses. More... | |
itype | |
overpfx | |
oversfx | |
suffix | |
molatom | |
Finite state machine for parsing GROMACS force field files.
We open the force field file and read all of its lines. As we loop through the force field file, we look for two types of tags: (1) section markers, in GMX indicated by [ section_name ], which allows us to determine the section, and (2) parameter tags, indicated by the 'PRM' or 'RPT' keywords.
As we go through the file, we figure out the atoms involved in the interaction described on each line.
When a 'PRM' keyword is indicated, it is followed by a number which is the field in the line to be modified, starting with zero. Based on the field number and the section name, we can figure out the parameter type. With the parameter type and the atoms in hand, we construct a 'parameter identifier' or pid which uniquely identifies that parameter. We also store the physical parameter value in an array called 'pvals0' and the precise location of that parameter (by filename, line number, and field number) in a list called 'pfields'.
An example: Suppose in 'my_ff.itp' I encounter the following on lines 146 and 147:
From reading [ angletypes ]
I know I'm in the 'angletypes' section.
On the next line, I notice two parameters on fields 4 and 5.
From the atom types, section type and field number I know the parameter IDs are 'ANGLESBCACBO'
and 'ANGLESKCACBO'
.
After building map={'ANGLESBCACBO':1,'ANGLESKCACBO':2}
, I store the values in an array: pvals0=array([109.47,350.00])
, and I put the parameter locations in pfields: pfields=[['my_ff.itp',147,4,1.0],['my_ff.itp',146,5,1.0]]
. The 1.0 is a 'multiplier' and I will explain it below.
Note that in the creation of parameter IDs, we run into the issue that the atoms involved in the interaction may be labeled in reverse order (e.g. OCACB
). Thus, we store both the normal and the reversed parameter ID in the map.
Parameter repetition and multiplier:
If 'RPT'
is encountered in the line, it is always in the syntax: 'RPT 4 ANGLESBCACAH 5 MINUS_ANGLESKCACAH /RPT'
. In this case, field 4 is replaced by the stored parameter value corresponding to ANGLESBCACAH
and field 5 is replaced by -1 times the stored value of ANGLESKCACAH
. Now I just picked this as an example, I don't think people actually want a negative angle force constant .. :) the MINUS
keyword does come in handy for assigning atomic charges and virtual site positions. In order to achieve this, a multiplier of -1.0 is stored into pfields instead of 1.0.
def src.gmxio.ITP_Reader.feed | ( | self, | |
line | |||
) |
Given a line, determine the interaction type and the atoms involved (the suffix).
For example, we want
H O H 5 1.231258497536e+02 4.269161426840e+02 -1.033397697685e-02 1.304674117410e+04 ; PRM 4 5 6 7
to give us itype = 'UREY_BRADLEY' and suffix = 'HOH'
If we are in a TypeSection, it returns a list of atom types;
If we are in a TopolSection, it returns a list of atom names.
The section is essentially a case statement that picks out the appropriate interaction type and makes a list of the atoms involved
Note that we can call gmxdump for this as well, but I prefer to read the force field file directly.
ToDo: [ atoms ] section might need to be more flexible to accommodate optional fields
src.gmxio.ITP_Reader.atomnames |
src.gmxio.ITP_Reader.atomtype_to_mass |
src.gmxio.ITP_Reader.atomtypes |
src.gmxio.ITP_Reader.mol |
src.gmxio.ITP_Reader.pdict |
src.gmxio.ITP_Reader.sec |