ForceBalance API  1.3
Automated optimization of force fields and empirical potentials
List of all members | Public Member Functions | Public Attributes
src.gmxio.ITP_Reader Class Reference

Finite state machine for parsing GROMACS force field files. More...

Inheritance diagram for src.gmxio.ITP_Reader:
[legend]
Collaboration diagram for src.gmxio.ITP_Reader:
[legend]

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
 

Detailed Description

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:

[ angletypes ]
CA CB O 1 109.47 350.00 ; PRM 4 5

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.

Todo:
Note that I can also create the opposite virtual site position by changing the atom labeling, woo!

Definition at line 362 of file gmxio.py.

Constructor & Destructor Documentation

◆ __init__()

def src.gmxio.ITP_Reader.__init__ (   self,
  fnm 
)

Definition at line 365 of file gmxio.py.

Member Function Documentation

◆ feed()

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

Definition at line 403 of file gmxio.py.

Member Data Documentation

◆ atomnames

src.gmxio.ITP_Reader.atomnames

Listing of all atom names in the file, (probably unnecessary)

Definition at line 377 of file gmxio.py.

◆ atomtype_to_mass

src.gmxio.ITP_Reader.atomtype_to_mass

A dictionary of atomic masses.

Definition at line 381 of file gmxio.py.

◆ atomtypes

src.gmxio.ITP_Reader.atomtypes

Listing of all atom types in the file, (probably unnecessary)

Definition at line 379 of file gmxio.py.

◆ itype

src.gmxio.ITP_Reader.itype

Definition at line 406 of file gmxio.py.

◆ mol

src.gmxio.ITP_Reader.mol

The current molecule (set by the moleculetype keyword)

Definition at line 373 of file gmxio.py.

◆ molatom

src.gmxio.ITP_Reader.molatom

Definition at line 522 of file gmxio.py.

◆ nbtype

src.gmxio.ITP_Reader.nbtype

Nonbonded type.

Definition at line 371 of file gmxio.py.

◆ overpfx

src.gmxio.ITP_Reader.overpfx

Definition at line 412 of file gmxio.py.

◆ oversfx

src.gmxio.ITP_Reader.oversfx

Definition at line 413 of file gmxio.py.

◆ pdict

src.gmxio.ITP_Reader.pdict

The parameter dictionary (defined in this file)

Definition at line 375 of file gmxio.py.

◆ sec

src.gmxio.ITP_Reader.sec

The current section that we're in.

Definition at line 369 of file gmxio.py.

◆ suffix

src.gmxio.ITP_Reader.suffix

Definition at line 517 of file gmxio.py.


The documentation for this class was generated from the following file: